skia_output_surface_dependency_webview.cc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "android_webview/browser/gfx/skia_output_surface_dependency_webview.h"
  5. #include "android_webview/browser/gfx/aw_vulkan_context_provider.h"
  6. #include "android_webview/browser/gfx/gpu_service_webview.h"
  7. #include "android_webview/browser/gfx/task_forwarding_sequence.h"
  8. #include "android_webview/browser/gfx/task_queue_webview.h"
  9. #include "base/callback_helpers.h"
  10. #include "base/logging.h"
  11. #include "gpu/command_buffer/service/gpu_task_scheduler_helper.h"
  12. #include "ui/gl/gl_surface.h"
  13. namespace android_webview {
  14. SkiaOutputSurfaceDependencyWebView::SkiaOutputSurfaceDependencyWebView(
  15. TaskQueueWebView* task_queue,
  16. GpuServiceWebView* gpu_service,
  17. gpu::SharedContextState* shared_context_state,
  18. gl::GLSurface* gl_surface,
  19. AwVulkanContextProvider* vulkan_context_provider)
  20. : gl_surface_(gl_surface),
  21. vulkan_context_provider_(vulkan_context_provider),
  22. task_queue_(task_queue),
  23. gpu_service_(gpu_service),
  24. workarounds_(
  25. gpu_service_->gpu_feature_info().enabled_gpu_driver_bug_workarounds),
  26. shared_context_state_(shared_context_state) {
  27. DCHECK(!(shared_context_state_ && vulkan_context_provider_) ||
  28. shared_context_state_->vk_context_provider() ==
  29. vulkan_context_provider);
  30. }
  31. SkiaOutputSurfaceDependencyWebView::~SkiaOutputSurfaceDependencyWebView() =
  32. default;
  33. std::unique_ptr<gpu::SingleTaskSequence>
  34. SkiaOutputSurfaceDependencyWebView::CreateSequence() {
  35. return std::make_unique<TaskForwardingSequence>(
  36. this->task_queue_, this->gpu_service_->sync_point_manager());
  37. }
  38. gpu::SharedImageManager*
  39. SkiaOutputSurfaceDependencyWebView::GetSharedImageManager() {
  40. return gpu_service_->shared_image_manager();
  41. }
  42. gpu::SyncPointManager*
  43. SkiaOutputSurfaceDependencyWebView::GetSyncPointManager() {
  44. return gpu_service_->sync_point_manager();
  45. }
  46. const gpu::GpuDriverBugWorkarounds&
  47. SkiaOutputSurfaceDependencyWebView::GetGpuDriverBugWorkarounds() {
  48. return workarounds_;
  49. }
  50. scoped_refptr<gpu::SharedContextState>
  51. SkiaOutputSurfaceDependencyWebView::GetSharedContextState() {
  52. return shared_context_state_.get();
  53. }
  54. gpu::raster::GrShaderCache*
  55. SkiaOutputSurfaceDependencyWebView::GetGrShaderCache() {
  56. return nullptr;
  57. }
  58. viz::VulkanContextProvider*
  59. SkiaOutputSurfaceDependencyWebView::GetVulkanContextProvider() {
  60. return shared_context_state_->vk_context_provider();
  61. }
  62. viz::DawnContextProvider*
  63. SkiaOutputSurfaceDependencyWebView::GetDawnContextProvider() {
  64. return nullptr;
  65. }
  66. const gpu::GpuPreferences&
  67. SkiaOutputSurfaceDependencyWebView::GetGpuPreferences() const {
  68. return gpu_service_->gpu_preferences();
  69. }
  70. const gpu::GpuFeatureInfo&
  71. SkiaOutputSurfaceDependencyWebView::GetGpuFeatureInfo() {
  72. return gpu_service_->gpu_feature_info();
  73. }
  74. gpu::MailboxManager* SkiaOutputSurfaceDependencyWebView::GetMailboxManager() {
  75. return gpu_service_->mailbox_manager();
  76. }
  77. void SkiaOutputSurfaceDependencyWebView::ScheduleGrContextCleanup() {
  78. // There is no way to access the gpu thread here, so leave it no-op for now.
  79. }
  80. scoped_refptr<base::TaskRunner>
  81. SkiaOutputSurfaceDependencyWebView::GetClientTaskRunner() {
  82. return task_queue_->GetClientTaskRunner();
  83. }
  84. gpu::ImageFactory* SkiaOutputSurfaceDependencyWebView::GetGpuImageFactory() {
  85. return nullptr;
  86. }
  87. bool SkiaOutputSurfaceDependencyWebView::IsOffscreen() {
  88. return false;
  89. }
  90. gpu::SurfaceHandle SkiaOutputSurfaceDependencyWebView::GetSurfaceHandle() {
  91. return gpu::kNullSurfaceHandle;
  92. }
  93. scoped_refptr<gl::GLSurface>
  94. SkiaOutputSurfaceDependencyWebView::CreateGLSurface(
  95. base::WeakPtr<gpu::ImageTransportSurfaceDelegate> stub,
  96. gl::GLSurfaceFormat format) {
  97. return gl_surface_.get();
  98. }
  99. base::ScopedClosureRunner SkiaOutputSurfaceDependencyWebView::CacheGLSurface(
  100. gl::GLSurface* surface) {
  101. NOTREACHED();
  102. return base::ScopedClosureRunner();
  103. }
  104. void SkiaOutputSurfaceDependencyWebView::RegisterDisplayContext(
  105. gpu::DisplayContext* display_context) {
  106. // No GpuChannelManagerDelegate here, so leave it no-op for now.
  107. }
  108. void SkiaOutputSurfaceDependencyWebView::UnregisterDisplayContext(
  109. gpu::DisplayContext* display_context) {
  110. // No GpuChannelManagerDelegate here, so leave it no-op for now.
  111. }
  112. void SkiaOutputSurfaceDependencyWebView::DidLoseContext(
  113. gpu::error::ContextLostReason reason,
  114. const GURL& active_url) {
  115. // No GpuChannelManagerDelegate here, so leave it no-op for now.
  116. LOG(ERROR) << "SkiaRenderer detected lost context.";
  117. }
  118. base::TimeDelta
  119. SkiaOutputSurfaceDependencyWebView::GetGpuBlockedTimeSinceLastSwap() {
  120. // WebView doesn't track how long GPU thread was blocked
  121. return base::TimeDelta();
  122. }
  123. void SkiaOutputSurfaceDependencyWebView::ScheduleDelayedGPUTaskFromGPUThread(
  124. base::OnceClosure task) {
  125. task_queue_->ScheduleIdleTask(std::move(task));
  126. }
  127. bool SkiaOutputSurfaceDependencyWebView::NeedsSupportForExternalStencil() {
  128. return true;
  129. }
  130. } // namespace android_webview