Commit eb61ee64 authored by Peng Huang's avatar Peng Huang Committed by Commit Bot

SkiaOutputSurface: Move GPU related code into SkiaOutputSurfaceImplOnGpu

This CL moves GPU related code in SkiaOutputSurfaceImpl into a new class
SkiaOutputSurfaceImplOnGpu. This new class is created, used and destroyed
on the GPU thread.

Bug: 824382
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel
Change-Id: Ib5809b1b42b73e296344be4459058b52b36fee6a
Reviewed-on: https://chromium-review.googlesource.com/1017237
Commit-Queue: Peng Huang <penghuang@chromium.org>
Reviewed-by: default avatarRobert Kroeger <rjkroege@chromium.org>
Cr-Commit-Position: refs/heads/master@{#556851}
parent b24aa115
...@@ -105,6 +105,8 @@ viz_component("service") { ...@@ -105,6 +105,8 @@ viz_component("service") {
"display_embedder/server_shared_bitmap_manager.h", "display_embedder/server_shared_bitmap_manager.h",
"display_embedder/skia_output_surface_impl.cc", "display_embedder/skia_output_surface_impl.cc",
"display_embedder/skia_output_surface_impl.h", "display_embedder/skia_output_surface_impl.h",
"display_embedder/skia_output_surface_impl_on_gpu.cc",
"display_embedder/skia_output_surface_impl_on_gpu.h",
"display_embedder/software_output_surface.cc", "display_embedder/software_output_surface.cc",
"display_embedder/software_output_surface.h", "display_embedder/software_output_surface.h",
"display_embedder/viz_process_context_provider.cc", "display_embedder/viz_process_context_provider.cc",
......
...@@ -11,39 +11,33 @@ ...@@ -11,39 +11,33 @@
#include "gpu/command_buffer/common/sync_token.h" #include "gpu/command_buffer/common/sync_token.h"
#include "gpu/ipc/common/surface_handle.h" #include "gpu/ipc/common/surface_handle.h"
#include "gpu/ipc/in_process_command_buffer.h" #include "gpu/ipc/in_process_command_buffer.h"
#include "gpu/ipc/service/image_transport_surface_delegate.h"
#include "third_party/skia/include/core/SkDeferredDisplayListRecorder.h" #include "third_party/skia/include/core/SkDeferredDisplayListRecorder.h"
#include "third_party/skia/include/core/SkSurface.h" #include "third_party/skia/include/core/SkSurfaceCharacterization.h"
namespace base { namespace base {
class WaitableEvent; class WaitableEvent;
} }
namespace gl {
class GLSurface;
}
namespace gpu {
class SyncPointClientState;
class TextureBase;
}
namespace viz { namespace viz {
class GpuServiceImpl; class GpuServiceImpl;
class VizProcessContextProvider; class VizProcessContextProvider;
class SkiaOutputSurfaceImplOnGpu;
class SyntheticBeginFrameSource; class SyntheticBeginFrameSource;
class YUVResourceMetadata;
// The SkiaOutputSurface implementation. It is the output surface for // The SkiaOutputSurface implementation. It is the output surface for
// SkiaRenderer. It lives on the compositor thread, but it will post tasks // SkiaRenderer. It lives on the compositor thread, but it will post tasks
// to the GPU thread for initializing, reshaping and swapping buffers, etc. // to the GPU thread for initializing. Currently, SkiaOutputSurfaceImpl
// Currently, SkiaOutputSurfaceImpl sets up SkSurface from the default GL // create a SkiaOutputSurfaceImplOnGpu on the GPU thread. It will be used
// framebuffer, creates SkDeferredDisplayListRecorder and SkCanvas for // for creating a SkSurface from the default framebuffer and providing the
// SkiaRenderer to render into. In SwapBuffers, it detaches a // SkSurfaceCharacterization for the SkSurface. And then SkiaOutputSurfaceImpl
// SkDeferredDisplayList from the recorder and plays it back on the framebuffer // will create SkDeferredDisplayListRecorder and SkCanvas for SkiaRenderer to
// SkSurface on the GPU thread. // render into. In SwapBuffers, it detaches a SkDeferredDisplayList from the
class SkiaOutputSurfaceImpl : public SkiaOutputSurface, // recorder and plays it back on the framebuffer SkSurface on the GPU thread
public gpu::ImageTransportSurfaceDelegate { // through SkiaOutputSurfaceImpleOnGpu.
class SkiaOutputSurfaceImpl : public SkiaOutputSurface {
public: public:
SkiaOutputSurfaceImpl( SkiaOutputSurfaceImpl(
GpuServiceImpl* gpu_service, GpuServiceImpl* gpu_service,
...@@ -93,80 +87,23 @@ class SkiaOutputSurfaceImpl : public SkiaOutputSurface, ...@@ -93,80 +87,23 @@ class SkiaOutputSurfaceImpl : public SkiaOutputSurface,
bool mipmap) override; bool mipmap) override;
void RemoveRenderPassResource(std::vector<RenderPassId> ids) override; void RemoveRenderPassResource(std::vector<RenderPassId> ids) override;
// gpu::ImageTransportSurfaceDelegate implementation:
void DidSwapBuffersComplete(gpu::SwapBuffersCompleteParams params) override;
const gpu::gles2::FeatureInfo* GetFeatureInfo() const override;
const gpu::GpuPreferences& GetGpuPreferences() const override;
void SetSnapshotRequestedCallback(const base::Closure& callback) override;
void UpdateVSyncParameters(base::TimeTicks timebase,
base::TimeDelta interval) override;
void BufferPresented(const gfx::PresentationFeedback& feedback) override;
void AddFilter(IPC::MessageFilter* message_filter) override;
int32_t GetRouteID() const override;
private: private:
class YUVResourceMetadata; template <class T>
class PromiseTextureHelper;
void InitializeOnGpuThread(base::WaitableEvent* event); void InitializeOnGpuThread(base::WaitableEvent* event);
void DestroyOnGpuThread(base::WaitableEvent* event);
void ReshapeOnGpuThread(const gfx::Size& size,
float device_scale_factor,
const gfx::ColorSpace& color_space,
bool has_alpha,
bool use_stencil,
SkSurfaceCharacterization* characterization,
base::WaitableEvent* event);
void SwapBuffersOnGpuThread(
OutputSurfaceFrame frame,
std::unique_ptr<SkDeferredDisplayList> ddl,
std::vector<YUVResourceMetadata*> yuv_resource_metadatas,
uint64_t sync_fence_release);
void FinishPaintRenderPassOnGpuThread(
RenderPassId id,
std::unique_ptr<SkDeferredDisplayList> ddl,
std::vector<YUVResourceMetadata*> yuv_resource_metadatas,
uint64_t sync_fence_release);
void RemoveRenderPassResourceOnGpuThread(std::vector<RenderPassId> ids);
void RecreateRecorder(); void RecreateRecorder();
void PreprocessYUVResources( void DidSwapBuffersComplete(gpu::SwapBuffersCompleteParams params);
std::vector<YUVResourceMetadata*> yuv_resource_metadatas); void UpdateVSyncParameters(base::TimeTicks timebase,
void BindOrCopyTextureIfNecessary(gpu::TextureBase* texture_base); base::TimeDelta interval);
void DidSwapBuffersCompleteOnClientThread( void BufferPresented(uint64_t swap_id,
gpu::SwapBuffersCompleteParams params); const gfx::PresentationFeedback& feedback);
void UpdateVSyncParametersOnClientThread(base::TimeTicks timebase,
base::TimeDelta interval);
void BufferPresentedOnClientThread(uint64_t swap_id,
const gfx::PresentationFeedback& feedback);
template <class T>
class PromiseTextureHelper;
// Fullfill callback for promise SkImage created from a resource.
void OnPromiseTextureFullfill(const ResourceMetadata& metadata,
GrBackendTexture* backend_texture);
// Fullfill callback for promise SkImage created from YUV resources.
void OnPromiseTextureFullfill(const YUVResourceMetadata& metadata,
GrBackendTexture* backend_texture);
// Fullfill callback for promise SkImage created from a render pass.
void OnPromiseTextureFullfill(const RenderPassId id,
GrBackendTexture* backend_texture);
// Generage the next swap ID and push it to our pending swap ID queues.
void OnSwapBuffers();
const gpu::CommandBufferId command_buffer_id_;
uint64_t sync_fence_release_ = 0; uint64_t sync_fence_release_ = 0;
GpuServiceImpl* const gpu_service_; GpuServiceImpl* const gpu_service_;
const gpu::SurfaceHandle surface_handle_; const gpu::SurfaceHandle surface_handle_;
SyntheticBeginFrameSource* const synthetic_begin_frame_source_; SyntheticBeginFrameSource* const synthetic_begin_frame_source_;
OutputSurfaceClient* client_ = nullptr; OutputSurfaceClient* client_ = nullptr;
scoped_refptr<gpu::SyncPointClientState> sync_point_client_state_;
gpu::GpuPreferences gpu_preferences_;
scoped_refptr<gl::GLSurface> surface_;
sk_sp<SkSurface> sk_surface_;
SkSurfaceCharacterization characterization_; SkSurfaceCharacterization characterization_;
std::unique_ptr<SkDeferredDisplayListRecorder> recorder_; std::unique_ptr<SkDeferredDisplayListRecorder> recorder_;
...@@ -178,10 +115,6 @@ class SkiaOutputSurfaceImpl : public SkiaOutputSurface, ...@@ -178,10 +115,6 @@ class SkiaOutputSurfaceImpl : public SkiaOutputSurface,
// the GPU thread. // the GPU thread.
std::unique_ptr<SkDeferredDisplayListRecorder> offscreen_surface_recorder_; std::unique_ptr<SkDeferredDisplayListRecorder> offscreen_surface_recorder_;
// Offscreen surfaces for render passes. It must be accessed on the GPU
// thread.
base::flat_map<RenderPassId, sk_sp<SkSurface>> offscreen_surfaces_;
// Sync tokens for resources which are used for the current frame. // Sync tokens for resources which are used for the current frame.
std::vector<gpu::SyncToken> resource_sync_tokens_; std::vector<gpu::SyncToken> resource_sync_tokens_;
...@@ -191,21 +124,16 @@ class SkiaOutputSurfaceImpl : public SkiaOutputSurface, ...@@ -191,21 +124,16 @@ class SkiaOutputSurfaceImpl : public SkiaOutputSurface,
// directly. // directly.
std::vector<YUVResourceMetadata*> yuv_resource_metadatas_; std::vector<YUVResourceMetadata*> yuv_resource_metadatas_;
// ID is pushed each time we begin a swap, and popped each time we present or
// complete a swap.
base::circular_deque<uint64_t> pending_presented_ids_;
base::circular_deque<uint64_t> pending_swap_completed_ids_;
uint64_t swap_id_ = 0;
// The task runner for running task on the client (compositor) thread. // The task runner for running task on the client (compositor) thread.
scoped_refptr<base::SingleThreadTaskRunner> client_thread_task_runner_; scoped_refptr<base::SingleThreadTaskRunner> client_thread_task_runner_;
THREAD_CHECKER(client_thread_checker_); // |impl_on_gpu| is created and destroyed on the GPU thread.
THREAD_CHECKER(gpu_thread_checker_); std::unique_ptr<SkiaOutputSurfaceImplOnGpu> impl_on_gpu_;
THREAD_CHECKER(thread_checker_);
base::WeakPtr<SkiaOutputSurfaceImpl> client_thread_weak_ptr_; base::WeakPtr<SkiaOutputSurfaceImpl> weak_ptr_;
base::WeakPtrFactory<SkiaOutputSurfaceImpl> gpu_thread_weak_ptr_factory_; base::WeakPtrFactory<SkiaOutputSurfaceImpl> weak_ptr_factory_;
base::WeakPtrFactory<SkiaOutputSurfaceImpl> client_thread_weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(SkiaOutputSurfaceImpl); DISALLOW_COPY_AND_ASSIGN(SkiaOutputSurfaceImpl);
}; };
......
// Copyright 2018 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 COMPONENTS_VIZ_SERVICE_DISPLAY_EMBEDDER_SKIA_OUTPUT_SURFACE_IMPL_ON_GPU_H_
#define COMPONENTS_VIZ_SERVICE_DISPLAY_EMBEDDER_SKIA_OUTPUT_SURFACE_IMPL_ON_GPU_H_
#include "base/containers/circular_deque.h"
#include "base/macros.h"
#include "base/threading/thread_checker.h"
#include "build/build_config.h"
#include "components/viz/common/quads/render_pass.h"
#include "components/viz/common/resources/resource_metadata.h"
#include "components/viz/service/display/output_surface.h"
#include "components/viz/service/display/output_surface_frame.h"
#include "gpu/command_buffer/common/sync_token.h"
#include "gpu/ipc/common/surface_handle.h"
#include "gpu/ipc/in_process_command_buffer.h"
#include "gpu/ipc/service/image_transport_surface_delegate.h"
#include "third_party/skia/include/core/SkSurface.h"
class SkDeferredDisplayList;
namespace base {
class WaitableEvent;
}
namespace gl {
class GLSurface;
}
namespace gpu {
class SyncPointClientState;
}
namespace viz {
class GpuServiceImpl;
// Metadata for YUV promise SkImage.
class YUVResourceMetadata {
public:
YUVResourceMetadata(std::vector<ResourceMetadata> metadatas,
SkYUVColorSpace yuv_color_space);
YUVResourceMetadata(YUVResourceMetadata&& other);
~YUVResourceMetadata();
YUVResourceMetadata& operator=(YUVResourceMetadata&& other);
const std::vector<ResourceMetadata>& metadatas() const { return metadatas_; }
SkYUVColorSpace yuv_color_space() const { return yuv_color_space_; }
const sk_sp<SkImage> image() const { return image_; }
void set_image(sk_sp<SkImage> image) { image_ = image; }
const gfx::Size size() const { return metadatas_[0].size; }
private:
// Metadatas for YUV planes.
std::vector<ResourceMetadata> metadatas_;
SkYUVColorSpace yuv_color_space_;
// The image copied from YUV textures, it is for fullfilling the promise
// image.
// TODO(penghuang): Remove it when Skia supports drawing YUV textures
// directly.
sk_sp<SkImage> image_;
DISALLOW_COPY_AND_ASSIGN(YUVResourceMetadata);
};
// The SkiaOutputSurface implementation running on the GPU thread. This class
// should be created, used and destroyed on the GPU thread.
class SkiaOutputSurfaceImplOnGpu : public gpu::ImageTransportSurfaceDelegate {
public:
using DidSwapBufferCompleteCallback =
base::RepeatingCallback<void(gpu::SwapBuffersCompleteParams)>;
using UpdateVSyncParametersCallback =
base::RepeatingCallback<void(base::TimeTicks, base::TimeDelta)>;
using BufferPresentedCallback =
base::RepeatingCallback<void(uint64_t swap_id,
const gfx::PresentationFeedback& feedback)>;
SkiaOutputSurfaceImplOnGpu(
GpuServiceImpl* gpu_service,
gpu::SurfaceHandle surface_handle,
const DidSwapBufferCompleteCallback& did_swap_buffer_complete_callback,
const UpdateVSyncParametersCallback& update_vsync_parameters_callback,
const BufferPresentedCallback& buffer_presented_callback);
~SkiaOutputSurfaceImplOnGpu() override;
gpu::CommandBufferId command_buffer_id() const { return command_buffer_id_; }
const OutputSurface::Capabilities capabilities() const {
return capabilities_;
}
const base::WeakPtr<SkiaOutputSurfaceImplOnGpu>& weak_ptr() const {
return weak_ptr_;
}
void Reshape(const gfx::Size& size,
float device_scale_factor,
const gfx::ColorSpace& color_space,
bool has_alpha,
bool use_stencil,
SkSurfaceCharacterization* characterization,
base::WaitableEvent* event);
void SwapBuffers(OutputSurfaceFrame frame,
std::unique_ptr<SkDeferredDisplayList> ddl,
std::vector<YUVResourceMetadata*> yuv_resource_metadatas,
uint64_t sync_fence_release);
void FinishPaintRenderPass(
RenderPassId id,
std::unique_ptr<SkDeferredDisplayList> ddl,
std::vector<YUVResourceMetadata*> yuv_resource_metadatas,
uint64_t sync_fence_release);
void RemoveRenderPassResource(std::vector<RenderPassId> ids);
// Fullfill callback for promise SkImage created from a resource.
void FullfillPromiseTexture(const ResourceMetadata& metadata,
GrBackendTexture* backend_texture);
// Fullfill callback for promise SkImage created from YUV resources.
void FullfillPromiseTexture(const YUVResourceMetadata& metadata,
GrBackendTexture* backend_texture);
// Fullfill callback for promise SkImage created from a render pass.
void FullfillPromiseTexture(const RenderPassId id,
GrBackendTexture* backend_texture);
private:
// gpu::ImageTransportSurfaceDelegate implementation:
#if defined(OS_WIN)
void DidCreateAcceleratedSurfaceChildWindow(
gpu::SurfaceHandle parent_window,
gpu::SurfaceHandle child_window) override;
#endif
void DidSwapBuffersComplete(gpu::SwapBuffersCompleteParams params) override;
const gpu::gles2::FeatureInfo* GetFeatureInfo() const override;
const gpu::GpuPreferences& GetGpuPreferences() const override;
void SetSnapshotRequestedCallback(const base::Closure& callback) override;
void UpdateVSyncParameters(base::TimeTicks timebase,
base::TimeDelta interval) override;
void BufferPresented(const gfx::PresentationFeedback& feedback) override;
void AddFilter(IPC::MessageFilter* message_filter) override;
int32_t GetRouteID() const override;
void BindOrCopyTextureIfNecessary(gpu::TextureBase* texture_base);
void PreprocessYUVResources(
std::vector<YUVResourceMetadata*> yuv_resource_metadatas);
// Generage the next swap ID and push it to our pending swap ID queues.
void OnSwapBuffers();
const gpu::CommandBufferId command_buffer_id_;
GpuServiceImpl* const gpu_service_;
const gpu::SurfaceHandle surface_handle_;
DidSwapBufferCompleteCallback did_swap_buffer_complete_callback_;
UpdateVSyncParametersCallback update_vsync_parameters_callback_;
BufferPresentedCallback buffer_presented_callback_;
scoped_refptr<gpu::SyncPointClientState> sync_point_client_state_;
gpu::GpuPreferences gpu_preferences_;
scoped_refptr<gl::GLSurface> surface_;
sk_sp<SkSurface> sk_surface_;
OutputSurface::Capabilities capabilities_;
// Offscreen surfaces for render passes. It can only be accessed on GPU
// thread.
base::flat_map<RenderPassId, sk_sp<SkSurface>> offscreen_surfaces_;
// ID is pushed each time we begin a swap, and popped each time we present or
// complete a swap.
base::circular_deque<uint64_t> pending_presented_ids_;
base::circular_deque<uint64_t> pending_swap_completed_ids_;
uint64_t swap_id_ = 0;
THREAD_CHECKER(thread_checker_);
base::WeakPtr<SkiaOutputSurfaceImplOnGpu> weak_ptr_;
base::WeakPtrFactory<SkiaOutputSurfaceImplOnGpu> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(SkiaOutputSurfaceImplOnGpu);
};
} // namespace viz
#endif // COMPONENTS_VIZ_SERVICE_DISPLAY_EMBEDDER_SKIA_OUTPUT_SURFACE_IMPL_ON_GPU_H_
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