Commit e9fa52e0 authored by Bo Liu's avatar Bo Liu Committed by Commit Bot

aw: Prepare skia dependnecy for viz

Move SkiaOutputSurfaceDependencyWebView into its own cc/h files, so it
can be shared easily with the new viz code path. Also only hold raw
pointers instead of scoped_refptr to objects, since those objects may
not be thread safe, and DependencyWebView may not be destroyed on render
thread. Re-order header declaration order so that viz classes are
destroyed before the raw pointer dependencies.

Bug: 805739
Change-Id: I06aaecc3aa41a24ae468890f0329499a0723559b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1732744
Commit-Queue: Bo <boliu@chromium.org>
Reviewed-by: default avatarEric Karl <ericrk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#683800}
parent bc1ccff0
...@@ -44,6 +44,8 @@ source_set("gfx") { ...@@ -44,6 +44,8 @@ source_set("gfx") {
"render_thread_manager.h", "render_thread_manager.h",
"scoped_app_gl_state_restore.cc", "scoped_app_gl_state_restore.cc",
"scoped_app_gl_state_restore.h", "scoped_app_gl_state_restore.h",
"skia_output_surface_dependency_webview.cc",
"skia_output_surface_dependency_webview.h",
"surfaces_instance.cc", "surfaces_instance.cc",
"surfaces_instance.h", "surfaces_instance.h",
"task_forwarding_sequence.cc", "task_forwarding_sequence.cc",
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// 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_web_view.h"
#include "android_webview/browser/gfx/parent_output_surface.h"
#include "android_webview/browser/gfx/task_forwarding_sequence.h"
#include "android_webview/browser/gfx/task_queue_web_view.h"
namespace android_webview {
SkiaOutputSurfaceDependencyWebView::SkiaOutputSurfaceDependencyWebView(
TaskQueueWebView* task_queue,
GpuServiceWebView* gpu_service,
gpu::SharedContextState* shared_context_state,
gl::GLSurface* gl_surface)
: gl_surface_(gl_surface),
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) {}
SkiaOutputSurfaceDependencyWebView::~SkiaOutputSurfaceDependencyWebView() =
default;
std::unique_ptr<gpu::SingleTaskSequence>
SkiaOutputSurfaceDependencyWebView::CreateSequence() {
return std::make_unique<TaskForwardingSequence>(
this->task_queue_, this->gpu_service_->sync_point_manager());
}
bool SkiaOutputSurfaceDependencyWebView::IsUsingVulkan() {
return shared_context_state_ && shared_context_state_->GrContextIsVulkan();
}
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_;
}
gpu::raster::GrShaderCache*
SkiaOutputSurfaceDependencyWebView::GetGrShaderCache() {
return nullptr;
}
viz::VulkanContextProvider*
SkiaOutputSurfaceDependencyWebView::GetVulkanContextProvider() {
return shared_context_state_->vk_context_provider();
}
const gpu::GpuPreferences&
SkiaOutputSurfaceDependencyWebView::GetGpuPreferences() {
return gpu_service_->gpu_preferences();
}
const gpu::GpuFeatureInfo&
SkiaOutputSurfaceDependencyWebView::GetGpuFeatureInfo() {
return gpu_service_->gpu_feature_info();
}
gpu::MailboxManager* SkiaOutputSurfaceDependencyWebView::GetMailboxManager() {
return gpu_service_->mailbox_manager();
}
void SkiaOutputSurfaceDependencyWebView::ScheduleGrContextCleanup() {
// There is no way to access the gpu thread here, so leave it no-op for now.
}
void SkiaOutputSurfaceDependencyWebView::PostTaskToClientThread(
base::OnceClosure closure) {
task_queue_->ScheduleClientTask(std::move(closure));
}
bool SkiaOutputSurfaceDependencyWebView::IsOffscreen() {
return false;
}
gpu::SurfaceHandle SkiaOutputSurfaceDependencyWebView::GetSurfaceHandle() {
return gpu::kNullSurfaceHandle;
}
scoped_refptr<gl::GLSurface>
SkiaOutputSurfaceDependencyWebView::CreateGLSurface(
base::WeakPtr<gpu::ImageTransportSurfaceDelegate> stub) {
return gl_surface_;
}
} // namespace android_webview
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ANDROID_WEBVIEW_BROWSER_GFX_SKIA_OUTPUT_SURFACE_DEPENDENCY_WEBVIEW_H_
#define ANDROID_WEBVIEW_BROWSER_GFX_SKIA_OUTPUT_SURFACE_DEPENDENCY_WEBVIEW_H_
#include "components/viz/service/display_embedder/skia_output_surface_dependency.h"
#include "gpu/command_buffer/service/shared_context_state.h"
#include "gpu/config/gpu_driver_bug_workarounds.h"
namespace android_webview {
class TaskQueueWebView;
class GpuServiceWebView;
// Implementation for access to gpu objects and task queue for WebView.
class SkiaOutputSurfaceDependencyWebView
: public viz::SkiaOutputSurfaceDependency {
public:
SkiaOutputSurfaceDependencyWebView(
TaskQueueWebView* task_queue,
GpuServiceWebView* gpu_service,
gpu::SharedContextState* shared_context_state,
gl::GLSurface* gl_surface);
~SkiaOutputSurfaceDependencyWebView() override;
std::unique_ptr<gpu::SingleTaskSequence> CreateSequence() override;
bool IsUsingVulkan() override;
gpu::SharedImageManager* GetSharedImageManager() override;
gpu::SyncPointManager* GetSyncPointManager() override;
const gpu::GpuDriverBugWorkarounds& GetGpuDriverBugWorkarounds() override;
scoped_refptr<gpu::SharedContextState> GetSharedContextState() override;
gpu::raster::GrShaderCache* GetGrShaderCache() override;
viz::VulkanContextProvider* GetVulkanContextProvider() override;
const gpu::GpuPreferences& GetGpuPreferences() override;
const gpu::GpuFeatureInfo& GetGpuFeatureInfo() override;
gpu::MailboxManager* GetMailboxManager() override;
void ScheduleGrContextCleanup() override;
void PostTaskToClientThread(base::OnceClosure closure) override;
bool IsOffscreen() override;
gpu::SurfaceHandle GetSurfaceHandle() override;
scoped_refptr<gl::GLSurface> CreateGLSurface(
base::WeakPtr<gpu::ImageTransportSurfaceDelegate> stub) override;
private:
gl::GLSurface* const gl_surface_;
TaskQueueWebView* task_queue_;
GpuServiceWebView* gpu_service_;
gpu::GpuDriverBugWorkarounds workarounds_;
gpu::SharedContextState* const shared_context_state_;
DISALLOW_COPY_AND_ASSIGN(SkiaOutputSurfaceDependencyWebView);
};
} // namespace android_webview
#endif // ANDROID_WEBVIEW_BROWSER_GFX_SKIA_OUTPUT_SURFACE_DEPENDENCY_WEBVIEW_H_
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#include "android_webview/browser/gfx/deferred_gpu_command_service.h" #include "android_webview/browser/gfx/deferred_gpu_command_service.h"
#include "android_webview/browser/gfx/gpu_service_web_view.h" #include "android_webview/browser/gfx/gpu_service_web_view.h"
#include "android_webview/browser/gfx/parent_output_surface.h" #include "android_webview/browser/gfx/parent_output_surface.h"
#include "android_webview/browser/gfx/task_forwarding_sequence.h" #include "android_webview/browser/gfx/skia_output_surface_dependency_webview.h"
#include "android_webview/browser/gfx/task_queue_web_view.h" #include "android_webview/browser/gfx/task_queue_web_view.h"
#include "android_webview/common/aw_switches.h" #include "android_webview/common/aw_switches.h"
#include "base/command_line.h" #include "base/command_line.h"
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#include "components/viz/common/surfaces/parent_local_surface_id_allocator.h" #include "components/viz/common/surfaces/parent_local_surface_id_allocator.h"
#include "components/viz/service/display/display.h" #include "components/viz/service/display/display.h"
#include "components/viz/service/display/display_scheduler.h" #include "components/viz/service/display/display_scheduler.h"
#include "components/viz/service/display_embedder/skia_output_surface_dependency.h"
#include "components/viz/service/display_embedder/skia_output_surface_impl.h" #include "components/viz/service/display_embedder/skia_output_surface_impl.h"
#include "components/viz/service/frame_sinks/compositor_frame_sink_support.h" #include "components/viz/service/frame_sinks/compositor_frame_sink_support.h"
#include "components/viz/service/frame_sinks/frame_sink_manager_impl.h" #include "components/viz/service/frame_sinks/frame_sink_manager_impl.h"
...@@ -51,136 +50,6 @@ void OnContextLost() { ...@@ -51,136 +50,6 @@ void OnContextLost() {
NOTREACHED() << "Non owned context lost!"; NOTREACHED() << "Non owned context lost!";
} }
// Implementation for access to gpu objects and task queue for WebView.
class SkiaOutputSurfaceDependencyWebView
: public viz::SkiaOutputSurfaceDependency {
public:
SkiaOutputSurfaceDependencyWebView(
TaskQueueWebView* task_queue,
GpuServiceWebView* gpu_service,
scoped_refptr<gpu::SharedContextState> shared_context_state,
scoped_refptr<gl::GLSurface> gl_surface);
~SkiaOutputSurfaceDependencyWebView() override;
std::unique_ptr<gpu::SingleTaskSequence> CreateSequence() override;
bool IsUsingVulkan() override;
gpu::SharedImageManager* GetSharedImageManager() override;
gpu::SyncPointManager* GetSyncPointManager() override;
const gpu::GpuDriverBugWorkarounds& GetGpuDriverBugWorkarounds() override;
scoped_refptr<gpu::SharedContextState> GetSharedContextState() override;
gpu::raster::GrShaderCache* GetGrShaderCache() override;
viz::VulkanContextProvider* GetVulkanContextProvider() override;
const gpu::GpuPreferences& GetGpuPreferences() override;
const gpu::GpuFeatureInfo& GetGpuFeatureInfo() override;
gpu::MailboxManager* GetMailboxManager() override;
void ScheduleGrContextCleanup() override;
void PostTaskToClientThread(base::OnceClosure closure) override;
bool IsOffscreen() override;
gpu::SurfaceHandle GetSurfaceHandle() override;
scoped_refptr<gl::GLSurface> CreateGLSurface(
base::WeakPtr<gpu::ImageTransportSurfaceDelegate> stub) override;
private:
scoped_refptr<gl::GLSurface> gl_surface_;
TaskQueueWebView* task_queue_;
GpuServiceWebView* gpu_service_;
gpu::GpuDriverBugWorkarounds workarounds_;
scoped_refptr<gpu::SharedContextState> shared_context_state_;
DISALLOW_COPY_AND_ASSIGN(SkiaOutputSurfaceDependencyWebView);
};
SkiaOutputSurfaceDependencyWebView::SkiaOutputSurfaceDependencyWebView(
TaskQueueWebView* task_queue,
GpuServiceWebView* gpu_service,
scoped_refptr<gpu::SharedContextState> shared_context_state,
scoped_refptr<gl::GLSurface> gl_surface)
: gl_surface_(std::move(gl_surface)),
task_queue_(task_queue),
gpu_service_(gpu_service),
workarounds_(
gpu_service_->gpu_feature_info().enabled_gpu_driver_bug_workarounds),
shared_context_state_(std::move(shared_context_state)) {}
SkiaOutputSurfaceDependencyWebView::~SkiaOutputSurfaceDependencyWebView() =
default;
std::unique_ptr<gpu::SingleTaskSequence>
SkiaOutputSurfaceDependencyWebView::CreateSequence() {
return std::make_unique<TaskForwardingSequence>(
this->task_queue_, this->gpu_service_->sync_point_manager());
}
bool SkiaOutputSurfaceDependencyWebView::IsUsingVulkan() {
return shared_context_state_ && shared_context_state_->GrContextIsVulkan();
}
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_;
}
gpu::raster::GrShaderCache*
SkiaOutputSurfaceDependencyWebView::GetGrShaderCache() {
return nullptr;
}
viz::VulkanContextProvider*
SkiaOutputSurfaceDependencyWebView::GetVulkanContextProvider() {
return shared_context_state_->vk_context_provider();
}
const gpu::GpuPreferences&
SkiaOutputSurfaceDependencyWebView::GetGpuPreferences() {
return gpu_service_->gpu_preferences();
}
const gpu::GpuFeatureInfo&
SkiaOutputSurfaceDependencyWebView::GetGpuFeatureInfo() {
return gpu_service_->gpu_feature_info();
}
gpu::MailboxManager* SkiaOutputSurfaceDependencyWebView::GetMailboxManager() {
return gpu_service_->mailbox_manager();
}
void SkiaOutputSurfaceDependencyWebView::ScheduleGrContextCleanup() {
// There is no way to access the gpu thread here, so leave it no-op for now.
}
void SkiaOutputSurfaceDependencyWebView::PostTaskToClientThread(
base::OnceClosure closure) {
task_queue_->ScheduleClientTask(std::move(closure));
}
bool SkiaOutputSurfaceDependencyWebView::IsOffscreen() {
return false;
}
gpu::SurfaceHandle SkiaOutputSurfaceDependencyWebView::GetSurfaceHandle() {
return gpu::kNullSurfaceHandle;
}
scoped_refptr<gl::GLSurface>
SkiaOutputSurfaceDependencyWebView::CreateGLSurface(
base::WeakPtr<gpu::ImageTransportSurfaceDelegate> stub) {
return gl_surface_;
}
} // namespace } // namespace
// static // static
...@@ -258,7 +127,7 @@ SurfacesInstance::SurfacesInstance() ...@@ -258,7 +127,7 @@ SurfacesInstance::SurfacesInstance()
} }
auto skia_dependency = std::make_unique<SkiaOutputSurfaceDependencyWebView>( auto skia_dependency = std::make_unique<SkiaOutputSurfaceDependencyWebView>(
TaskQueueWebView::GetInstance(), GpuServiceWebView::GetInstance(), TaskQueueWebView::GetInstance(), GpuServiceWebView::GetInstance(),
shared_context_state_, gl_surface_); shared_context_state_.get(), gl_surface_.get());
output_surface = viz::SkiaOutputSurfaceImpl::Create( output_surface = viz::SkiaOutputSurfaceImpl::Create(
std::move(skia_dependency), settings); std::move(skia_dependency), settings);
DCHECK(output_surface); DCHECK(output_surface);
......
...@@ -97,7 +97,11 @@ class SurfacesInstance : public base::RefCounted<SurfacesInstance>, ...@@ -97,7 +97,11 @@ class SurfacesInstance : public base::RefCounted<SurfacesInstance>,
viz::FrameSinkId frame_sink_id_; viz::FrameSinkId frame_sink_id_;
// These need to outlive viz objects such as |display_| below.
scoped_refptr<AwGLSurface> gl_surface_; scoped_refptr<AwGLSurface> gl_surface_;
scoped_refptr<gl::GLShareGroup> share_group_;
scoped_refptr<gpu::SharedContextState> shared_context_state_;
std::unique_ptr<viz::FrameSinkManagerImpl> frame_sink_manager_; std::unique_ptr<viz::FrameSinkManagerImpl> frame_sink_manager_;
std::unique_ptr<viz::BeginFrameSource> begin_frame_source_; std::unique_ptr<viz::BeginFrameSource> begin_frame_source_;
std::unique_ptr<viz::Display> display_; std::unique_ptr<viz::Display> display_;
...@@ -112,9 +116,6 @@ class SurfacesInstance : public base::RefCounted<SurfacesInstance>, ...@@ -112,9 +116,6 @@ class SurfacesInstance : public base::RefCounted<SurfacesInstance>,
gfx::Size surface_size_; gfx::Size surface_size_;
scoped_refptr<gl::GLShareGroup> share_group_;
scoped_refptr<gpu::SharedContextState> shared_context_state_;
DISALLOW_COPY_AND_ASSIGN(SurfacesInstance); DISALLOW_COPY_AND_ASSIGN(SurfacesInstance);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment