Commit a1832cad authored by Weiliang Chen's avatar Weiliang Chen Committed by Commit Bot

viz: In SkiaRenderer remove bool tracking whether is drawing render pass

Remove SkiaRenderer's bool that tracks whether we are drawing root
render pass or child render pass. Also leads to deleting function on
SkiaOutputSurface since it knows the current render pass id and both
functions share majority of code.

Bug: 644851
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel
Change-Id: I332012ed89f5edc825acaee4230f28bdfc271044
Reviewed-on: https://chromium-review.googlesource.com/1241734
Commit-Queue: weiliangc <weiliangc@chromium.org>
Reviewed-by: default avatarPeng Huang <penghuang@chromium.org>
Reviewed-by: default avatarenne <enne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594429}
parent a77a2f59
...@@ -34,15 +34,6 @@ class VIZ_SERVICE_EXPORT SkiaOutputSurface : public OutputSurface { ...@@ -34,15 +34,6 @@ class VIZ_SERVICE_EXPORT SkiaOutputSurface : public OutputSurface {
// called. // called.
virtual SkCanvas* BeginPaintCurrentFrame() = 0; virtual SkCanvas* BeginPaintCurrentFrame() = 0;
// Finish painting the current frame. It should be paired with
// BeginPaintCurrentFrame. This method will schedule a GPU task to play the
// DDL back on GPU thread on the SkSurface for the framebuffer. This method
// returns a sync token which can be waited on in a command buffer to ensure
// the paint operation is completed. This token is released when the GPU ops
// from painting the current frame have been seen and processed by the GPU
// main.
virtual gpu::SyncToken FinishPaintCurrentFrame() = 0;
// Make a promise SkImage from the given |metadata|. The SkiaRenderer can use // Make a promise SkImage from the given |metadata|. The SkiaRenderer can use
// the image with SkCanvas returned by |GetSkCanvasForCurrentFrame|, but Skia // the image with SkCanvas returned by |GetSkCanvasForCurrentFrame|, but Skia
// will not read the content of the resource until the sync token in the // will not read the content of the resource until the sync token in the
...@@ -75,13 +66,13 @@ class VIZ_SERVICE_EXPORT SkiaOutputSurface : public OutputSurface { ...@@ -75,13 +66,13 @@ class VIZ_SERVICE_EXPORT SkiaOutputSurface : public OutputSurface {
ResourceFormat format, ResourceFormat format,
bool mipmap) = 0; bool mipmap) = 0;
// Finish painting a render pass. It should be paired with // Finish painting the current frame or current render pass, depends on which
// BeginPaintRenderPass. This method will schedule a GPU task to play the DDL // BeginPaint function is called last. This method will schedule a GPU task to
// back on GPU thread on a cached SkSurface. This method returns a sync token // play the DDL back on GPU thread on a cached SkSurface. This method returns
// which can be waited on in a command buffer to ensure the paint operation is // a sync token which can be waited on in a command buffer to ensure the paint
// completed. This token is released when the GPU ops from painting the render // operation is completed. This token is released when the GPU ops from
// pass have been seen and processed by the GPU main. // painting the render pass have been seen and processed by the GPU main.
virtual gpu::SyncToken FinishPaintRenderPass() = 0; virtual gpu::SyncToken SubmitPaint() = 0;
// Make a promise SkImage from a render pass id. The render pass has been // Make a promise SkImage from a render pass id. The render pass has been
// painted with BeginPaintRenderPass and FinishPaintRenderPass. The format // painted with BeginPaintRenderPass and FinishPaintRenderPass. The format
......
...@@ -324,7 +324,6 @@ void SkiaRenderer::BindFramebufferToOutputSurface() { ...@@ -324,7 +324,6 @@ void SkiaRenderer::BindFramebufferToOutputSurface() {
// How to setup is in ResourceProvider. (http://crbug.com/644851) // How to setup is in ResourceProvider. (http://crbug.com/644851)
if (is_using_ddl()) { if (is_using_ddl()) {
root_canvas_ = skia_output_surface_->BeginPaintCurrentFrame(); root_canvas_ = skia_output_surface_->BeginPaintCurrentFrame();
is_drawing_render_pass_ = false;
DCHECK(root_canvas_); DCHECK(root_canvas_);
} else { } else {
auto* gr_context = GetGrContext(); auto* gr_context = GetGrContext();
...@@ -405,7 +404,6 @@ void SkiaRenderer::BindFramebufferToTexture(const RenderPassId render_pass_id) { ...@@ -405,7 +404,6 @@ void SkiaRenderer::BindFramebufferToTexture(const RenderPassId render_pass_id) {
current_surface_ = non_root_surface_.get(); current_surface_ = non_root_surface_.get();
current_canvas_ = non_root_surface_->getCanvas(); current_canvas_ = non_root_surface_->getCanvas();
} }
is_drawing_render_pass_ = true;
} }
void SkiaRenderer::SetScissorTestRect(const gfx::Rect& scissor_rect) { void SkiaRenderer::SetScissorTestRect(const gfx::Rect& scissor_rect) {
...@@ -934,8 +932,14 @@ void SkiaRenderer::CopyDrawnRenderPass( ...@@ -934,8 +932,14 @@ void SkiaRenderer::CopyDrawnRenderPass(
} }
if (is_using_ddl()) { if (is_using_ddl()) {
auto render_pass_id = // Root framebuffer uses id 0 in SkiaOutputSurface.
is_drawing_render_pass_ ? current_frame()->current_render_pass->id : 0; RenderPassId render_pass_id = 0;
// If we are in child render pass and we don't have overdraw, copy the
// current render pass.
if (root_canvas_ != current_canvas_ &&
current_canvas_ != nway_canvas_.get()) {
render_pass_id = current_frame()->current_render_pass->id;
}
skia_output_surface_->CopyOutput(render_pass_id, window_copy_rect, skia_output_surface_->CopyOutput(render_pass_id, window_copy_rect,
std::move(request)); std::move(request));
return; return;
...@@ -965,10 +969,7 @@ void SkiaRenderer::DidChangeVisibility() { ...@@ -965,10 +969,7 @@ void SkiaRenderer::DidChangeVisibility() {
void SkiaRenderer::FinishDrawingQuadList() { void SkiaRenderer::FinishDrawingQuadList() {
if (is_using_ddl()) { if (is_using_ddl()) {
gpu::SyncToken sync_token = gpu::SyncToken sync_token = skia_output_surface_->SubmitPaint();
is_drawing_render_pass_
? skia_output_surface_->FinishPaintRenderPass()
: skia_output_surface_->FinishPaintCurrentFrame();
promise_images_.clear(); promise_images_.clear();
yuv_promise_images_.clear(); yuv_promise_images_.clear();
lock_set_for_external_use_.UnlockResources(sync_token); lock_set_for_external_use_.UnlockResources(sync_token);
......
...@@ -125,7 +125,6 @@ class VIZ_SERVICE_EXPORT SkiaRenderer : public DirectRenderer { ...@@ -125,7 +125,6 @@ class VIZ_SERVICE_EXPORT SkiaRenderer : public DirectRenderer {
gfx::Rect scissor_rect_; gfx::Rect scissor_rect_;
bool is_drawing_render_pass_ = false;
sk_sp<SkSurface> root_surface_; sk_sp<SkSurface> root_surface_;
sk_sp<SkSurface> non_root_surface_; sk_sp<SkSurface> non_root_surface_;
sk_sp<SkSurface> overdraw_surface_; sk_sp<SkSurface> overdraw_surface_;
......
...@@ -287,30 +287,6 @@ SkCanvas* SkiaOutputSurfaceImpl::BeginPaintCurrentFrame() { ...@@ -287,30 +287,6 @@ SkCanvas* SkiaOutputSurfaceImpl::BeginPaintCurrentFrame() {
return recorder_->getCanvas(); return recorder_->getCanvas();
} }
gpu::SyncToken SkiaOutputSurfaceImpl::FinishPaintCurrentFrame() {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(recorder_);
gpu::SyncToken sync_token(gpu::CommandBufferNamespace::VIZ_OUTPUT_SURFACE,
impl_on_gpu_->command_buffer_id(),
++sync_fence_release_);
sync_token.SetVerifyFlush();
auto ddl = recorder_->detach();
DCHECK(ddl);
recorder_.reset();
auto sequence_id = gpu_service_->skia_output_surface_sequence_id();
// impl_on_gpu_ is released on the GPU thread by a posted task from
// SkiaOutputSurfaceImpl::dtor. So it is safe to use base::Unretained.
auto callback =
base::BindOnce(&SkiaOutputSurfaceImplOnGpu::FinishPaintCurrentFrame,
base::Unretained(impl_on_gpu_.get()), std::move(ddl),
std::move(yuv_resource_metadatas_), sync_fence_release_);
gpu_service_->scheduler()->ScheduleTask(gpu::Scheduler::Task(
sequence_id, std::move(callback), std::move(resource_sync_tokens_)));
return sync_token;
}
sk_sp<SkImage> SkiaOutputSurfaceImpl::MakePromiseSkImage( sk_sp<SkImage> SkiaOutputSurfaceImpl::MakePromiseSkImage(
ResourceMetadata metadata) { ResourceMetadata metadata) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
...@@ -436,27 +412,39 @@ SkCanvas* SkiaOutputSurfaceImpl::BeginPaintRenderPass( ...@@ -436,27 +412,39 @@ SkCanvas* SkiaOutputSurfaceImpl::BeginPaintRenderPass(
return offscreen_surface_recorder_->getCanvas(); return offscreen_surface_recorder_->getCanvas();
} }
gpu::SyncToken SkiaOutputSurfaceImpl::FinishPaintRenderPass() { gpu::SyncToken SkiaOutputSurfaceImpl::SubmitPaint() {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(current_render_pass_id_); // If current_render_pass_id_ is not 0, we are painting a render pass.
DCHECK(offscreen_surface_recorder_); // Otherwise we are painting a frame.
bool painting_render_pass = current_render_pass_id_ != 0;
auto& current_recorder =
painting_render_pass ? offscreen_surface_recorder_ : recorder_;
DCHECK(current_recorder);
gpu::SyncToken sync_token(gpu::CommandBufferNamespace::VIZ_OUTPUT_SURFACE, gpu::SyncToken sync_token(gpu::CommandBufferNamespace::VIZ_OUTPUT_SURFACE,
impl_on_gpu_->command_buffer_id(), impl_on_gpu_->command_buffer_id(),
++sync_fence_release_); ++sync_fence_release_);
sync_token.SetVerifyFlush(); sync_token.SetVerifyFlush();
auto ddl = offscreen_surface_recorder_->detach(); auto ddl = current_recorder->detach();
offscreen_surface_recorder_.reset();
DCHECK(ddl); DCHECK(ddl);
current_recorder.reset();
auto sequence_id = gpu_service_->skia_output_surface_sequence_id(); auto sequence_id = gpu_service_->skia_output_surface_sequence_id();
// impl_on_gpu_ is released on the GPU thread by a posted task from // impl_on_gpu_ is released on the GPU thread by a posted task from
// SkiaOutputSurfaceImpl::dtor. So it is safe to use base::Unretained. // SkiaOutputSurfaceImpl::dtor. So it is safe to use base::Unretained.
auto callback = base::BindOnce( base::OnceCallback<void()> callback;
&SkiaOutputSurfaceImplOnGpu::FinishPaintRenderPass, if (painting_render_pass) {
base::Unretained(impl_on_gpu_.get()), current_render_pass_id_, callback =
std::move(ddl), std::move(yuv_resource_metadatas_), sync_fence_release_); base::BindOnce(&SkiaOutputSurfaceImplOnGpu::FinishPaintRenderPass,
base::Unretained(impl_on_gpu_.get()),
current_render_pass_id_, std::move(ddl),
std::move(yuv_resource_metadatas_), sync_fence_release_);
} else {
callback =
base::BindOnce(&SkiaOutputSurfaceImplOnGpu::FinishPaintCurrentFrame,
base::Unretained(impl_on_gpu_.get()), std::move(ddl),
std::move(yuv_resource_metadatas_), sync_fence_release_);
}
gpu_service_->scheduler()->ScheduleTask(gpu::Scheduler::Task( gpu_service_->scheduler()->ScheduleTask(gpu::Scheduler::Task(
sequence_id, std::move(callback), std::move(resource_sync_tokens_))); sequence_id, std::move(callback), std::move(resource_sync_tokens_)));
current_render_pass_id_ = 0; current_render_pass_id_ = 0;
......
...@@ -74,7 +74,6 @@ class VIZ_SERVICE_EXPORT SkiaOutputSurfaceImpl : public SkiaOutputSurface { ...@@ -74,7 +74,6 @@ class VIZ_SERVICE_EXPORT SkiaOutputSurfaceImpl : public SkiaOutputSurface {
// SkiaOutputSurface implementation: // SkiaOutputSurface implementation:
SkCanvas* BeginPaintCurrentFrame() override; SkCanvas* BeginPaintCurrentFrame() override;
gpu::SyncToken FinishPaintCurrentFrame() override;
sk_sp<SkImage> MakePromiseSkImage(ResourceMetadata metadata) override; sk_sp<SkImage> MakePromiseSkImage(ResourceMetadata metadata) override;
sk_sp<SkImage> MakePromiseSkImageFromYUV( sk_sp<SkImage> MakePromiseSkImageFromYUV(
std::vector<ResourceMetadata> metadatas, std::vector<ResourceMetadata> metadatas,
...@@ -84,7 +83,7 @@ class VIZ_SERVICE_EXPORT SkiaOutputSurfaceImpl : public SkiaOutputSurface { ...@@ -84,7 +83,7 @@ class VIZ_SERVICE_EXPORT SkiaOutputSurfaceImpl : public SkiaOutputSurface {
const gfx::Size& surface_size, const gfx::Size& surface_size,
ResourceFormat format, ResourceFormat format,
bool mipmap) override; bool mipmap) override;
gpu::SyncToken FinishPaintRenderPass() override; gpu::SyncToken SubmitPaint() override;
sk_sp<SkImage> MakePromiseSkImageFromRenderPass(const RenderPassId& id, sk_sp<SkImage> MakePromiseSkImageFromRenderPass(const RenderPassId& id,
const gfx::Size& size, const gfx::Size& size,
ResourceFormat format, ResourceFormat format,
......
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