1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133
  134
  135
  136
  137
  138
  139
  140
  141
  142
  143
  144
  145
  146
  147

android_webview / browser / gfx / skia_output_surface_dependency_webview.cc [blame]

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "android_webview/browser/gfx/skia_output_surface_dependency_webview.h"

#include "android_webview/browser/gfx/aw_vulkan_context_provider.h"
#include "android_webview/browser/gfx/gpu_service_webview.h"
#include "android_webview/browser/gfx/task_forwarding_sequence.h"
#include "android_webview/browser/gfx/task_queue_webview.h"
#include "base/functional/callback_helpers.h"
#include "base/logging.h"
#include "gpu/command_buffer/service/gpu_task_scheduler_helper.h"
#include "ui/gl/gl_surface.h"

namespace android_webview {

SkiaOutputSurfaceDependencyWebView::SkiaOutputSurfaceDependencyWebView(
    TaskQueueWebView* task_queue,
    GpuServiceWebView* gpu_service,
    gpu::SharedContextState* shared_context_state,
    gl::GLSurface* gl_surface,
    AwVulkanContextProvider* vulkan_context_provider)
    : gl_surface_(gl_surface),
      vulkan_context_provider_(vulkan_context_provider),
      task_queue_(task_queue),
      gpu_service_(gpu_service),
      workarounds_(
          gpu_service_->gpu_feature_info().enabled_gpu_driver_bug_workarounds),
      shared_context_state_(shared_context_state) {
  DCHECK(!(shared_context_state_ && vulkan_context_provider_) ||
         shared_context_state_->vk_context_provider() ==
             vulkan_context_provider);
}

SkiaOutputSurfaceDependencyWebView::~SkiaOutputSurfaceDependencyWebView() =
    default;

std::unique_ptr<gpu::SingleTaskSequence>
SkiaOutputSurfaceDependencyWebView::CreateSequence() {
  return std::make_unique<TaskForwardingSequence>(task_queue_);
}

gpu::SharedImageManager*
SkiaOutputSurfaceDependencyWebView::GetSharedImageManager() {
  return gpu_service_->shared_image_manager();
}

gpu::SyncPointManager*
SkiaOutputSurfaceDependencyWebView::GetSyncPointManager() {
  return gpu_service_->sync_point_manager();
}

const gpu::GpuDriverBugWorkarounds&
SkiaOutputSurfaceDependencyWebView::GetGpuDriverBugWorkarounds() {
  return workarounds_;
}

scoped_refptr<gpu::SharedContextState>
SkiaOutputSurfaceDependencyWebView::GetSharedContextState() {
  return shared_context_state_.get();
}

gpu::raster::GrShaderCache*
SkiaOutputSurfaceDependencyWebView::GetGrShaderCache() {
  return nullptr;
}

viz::VulkanContextProvider*
SkiaOutputSurfaceDependencyWebView::GetVulkanContextProvider() {
  return shared_context_state_->vk_context_provider();
}

gpu::DawnContextProvider*
SkiaOutputSurfaceDependencyWebView::GetDawnContextProvider() {
  return nullptr;
}

const gpu::GpuPreferences&
SkiaOutputSurfaceDependencyWebView::GetGpuPreferences() const {
  return gpu_service_->gpu_preferences();
}

const gpu::GpuFeatureInfo&
SkiaOutputSurfaceDependencyWebView::GetGpuFeatureInfo() {
  return gpu_service_->gpu_feature_info();
}

void SkiaOutputSurfaceDependencyWebView::ScheduleGrContextCleanup() {
  shared_context_state_->ScheduleSkiaCleanup();
}

scoped_refptr<base::SingleThreadTaskRunner>
SkiaOutputSurfaceDependencyWebView::GetClientTaskRunner() {
  return task_queue_->GetClientTaskRunner();
}

bool SkiaOutputSurfaceDependencyWebView::IsOffscreen() {
  return false;
}

gpu::SurfaceHandle SkiaOutputSurfaceDependencyWebView::GetSurfaceHandle() {
  return gpu::kNullSurfaceHandle;
}

scoped_refptr<gl::Presenter>
SkiaOutputSurfaceDependencyWebView::CreatePresenter() {
  return nullptr;
}
scoped_refptr<gl::GLSurface>
SkiaOutputSurfaceDependencyWebView::CreateGLSurface(
    gl::GLSurfaceFormat format) {
  return gl_surface_.get();
}

base::ScopedClosureRunner SkiaOutputSurfaceDependencyWebView::CachePresenter(
    gl::Presenter* presenter) {
  NOTREACHED();
}

base::ScopedClosureRunner SkiaOutputSurfaceDependencyWebView::CacheGLSurface(
    gl::GLSurface* surface) {
  NOTREACHED();
}

void SkiaOutputSurfaceDependencyWebView::DidLoseContext(
    gpu::error::ContextLostReason reason,
    const GURL& active_url) {
  // No GpuChannelManagerDelegate here, so leave it no-op for now.
  LOG(ERROR) << "SkiaRenderer detected lost context.";
}

void SkiaOutputSurfaceDependencyWebView::ScheduleDelayedGPUTaskFromGPUThread(
    base::OnceClosure task) {
  task_queue_->ScheduleIdleTask(std::move(task));
}

bool SkiaOutputSurfaceDependencyWebView::NeedsSupportForExternalStencil() {
  return true;
}

bool SkiaOutputSurfaceDependencyWebView::IsUsingCompositorGpuThread() {
  // Webview never uses CompositorGpuThread aka DrDc thread.
  return false;
}

}  // namespace android_webview