From bdc24b3d18812b1da4caf66289ab1c88aca450ea Mon Sep 17 00:00:00 2001 From: Kevin Lubick Date: Fri, 14 Jul 2023 16:34:22 -0400 Subject: [PATCH] Remove calls to SkCanvas::flush() (flutter/engine#43684) In https://skia-review.googlesource.com/c/skia/+/716476, Skia removed calls to SkCanvas::flush(). This replaces those calls that Flutter was making with what had been going on - calling GrDirectContext::flush() if the canvas was backed by a Ganesh backend. Raster-backed canvases did not need flushing. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides]. - [ ] I listed at least one issue that this PR fixes in the description above. - [x] I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See [testing the engine] for instructions on writing and running engine tests. - [ ] I updated/added relevant documentation (doc comments with `///`). - [x] I signed the [CLA]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style [testing the engine]: https://github.com/flutter/flutter/wiki/Testing-the-engine [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat --- engine/src/flutter/display_list/skia/dl_sk_canvas.cc | 8 +++++++- .../display_list/testing/dl_rendering_unittests.cc | 1 - engine/src/flutter/lib/ui/painting/image_encoding_impl.h | 5 ++++- engine/src/flutter/shell/common/rasterizer_unittests.cc | 1 - .../src/flutter/shell/common/snapshot_controller_skia.cc | 5 ++++- engine/src/flutter/shell/gpu/gpu_surface_gl_skia.cc | 4 ++-- .../flutter/shell/platform/fuchsia/flutter/canvas_spy.cc | 2 -- .../flutter/shell/platform/fuchsia/flutter/canvas_spy.h | 3 --- 8 files changed, 17 insertions(+), 12 deletions(-) diff --git a/engine/src/flutter/display_list/skia/dl_sk_canvas.cc b/engine/src/flutter/display_list/skia/dl_sk_canvas.cc index 3a5cb3bdc7..842f459303 100644 --- a/engine/src/flutter/display_list/skia/dl_sk_canvas.cc +++ b/engine/src/flutter/display_list/skia/dl_sk_canvas.cc @@ -9,6 +9,8 @@ #include "flutter/fml/trace_event.h" #include "third_party/skia/include/core/SkColorFilter.h" +#include "third_party/skia/include/gpu/GrDirectContext.h" +#include "third_party/skia/include/gpu/GrRecordingContext.h" namespace flutter { @@ -374,7 +376,11 @@ void DlSkCanvasAdapter::DrawShadow(const SkPath& path, } void DlSkCanvasAdapter::Flush() { - delegate_->flush(); + auto dContext = GrAsDirectContext(delegate_->recordingContext()); + + if (dContext) { + dContext->flushAndSubmit(); + } } } // namespace flutter diff --git a/engine/src/flutter/display_list/testing/dl_rendering_unittests.cc b/engine/src/flutter/display_list/testing/dl_rendering_unittests.cc index 7a1a958160..55afd24d80 100644 --- a/engine/src/flutter/display_list/testing/dl_rendering_unittests.cc +++ b/engine/src/flutter/display_list/testing/dl_rendering_unittests.cc @@ -492,7 +492,6 @@ class RenderEnvironment { renderer.Render(canvas, info); canvas->restoreToCount(restore_count); - canvas->flush(); if (GrDirectContext* dContext = GrAsDirectContext(surface->recordingContext())) { dContext->flushAndSubmit(surface, /*syncCpu=*/true); diff --git a/engine/src/flutter/lib/ui/painting/image_encoding_impl.h b/engine/src/flutter/lib/ui/painting/image_encoding_impl.h index d7248e87b9..595f8276e4 100644 --- a/engine/src/flutter/lib/ui/painting/image_encoding_impl.h +++ b/engine/src/flutter/lib/ui/painting/image_encoding_impl.h @@ -9,6 +9,7 @@ #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkImage.h" #include "third_party/skia/include/core/SkSurface.h" +#include "third_party/skia/include/gpu/GrDirectContext.h" #include "third_party/skia/include/gpu/ganesh/SkSurfaceGanesh.h" namespace flutter { @@ -41,7 +42,9 @@ sk_sp ConvertToRasterUsingResourceContext( } surface->getCanvas()->drawImage(image, 0, 0); - surface->getCanvas()->flush(); + if (resource_context) { + resource_context->flushAndSubmit(); + } auto snapshot = surface->makeImageSnapshot(); diff --git a/engine/src/flutter/shell/common/rasterizer_unittests.cc b/engine/src/flutter/shell/common/rasterizer_unittests.cc index daf3636485..92d23c82dc 100644 --- a/engine/src/flutter/shell/common/rasterizer_unittests.cc +++ b/engine/src/flutter/shell/common/rasterizer_unittests.cc @@ -990,7 +990,6 @@ TEST(RasterizerTest, TeardownFreesResourceCache) { SkPaint paint; sk_surface->getCanvas()->drawPaint(paint); - sk_surface->getCanvas()->flush(); context->flushAndSubmit(true); EXPECT_EQ(context->getResourceCachePurgeableBytes(), 0ul); diff --git a/engine/src/flutter/shell/common/snapshot_controller_skia.cc b/engine/src/flutter/shell/common/snapshot_controller_skia.cc index d39a900305..fe7897f38d 100644 --- a/engine/src/flutter/shell/common/snapshot_controller_skia.cc +++ b/engine/src/flutter/shell/common/snapshot_controller_skia.cc @@ -23,7 +23,10 @@ sk_sp DrawSnapshot( } draw_callback(surface->getCanvas()); - surface->getCanvas()->flush(); + auto dContext = GrAsDirectContext(surface->recordingContext()); + if (dContext) { + dContext->flushAndSubmit(); + } sk_sp device_snapshot; { diff --git a/engine/src/flutter/shell/gpu/gpu_surface_gl_skia.cc b/engine/src/flutter/shell/gpu/gpu_surface_gl_skia.cc index 8285145b4e..9ced169f11 100644 --- a/engine/src/flutter/shell/gpu/gpu_surface_gl_skia.cc +++ b/engine/src/flutter/shell/gpu/gpu_surface_gl_skia.cc @@ -268,8 +268,8 @@ bool GPUSurfaceGLSkia::PresentSurface(const SurfaceFrame& frame, delegate_->GLContextSetDamageRegion(frame.submit_info().buffer_damage); { - TRACE_EVENT0("flutter", "SkCanvas::Flush"); - onscreen_surface_->getCanvas()->flush(); + TRACE_EVENT0("flutter", "GrDirectContext::flushAndSubmit"); + context_->flushAndSubmit(); } GLPresentInfo present_info = { diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/canvas_spy.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/canvas_spy.cc index fe45a8fdeb..75df63a906 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/canvas_spy.cc +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/canvas_spy.cc @@ -267,6 +267,4 @@ void DidDrawCanvas::onDrawEdgeAAImageSet2(const ImageSetEntry set[], did_draw_ = true; } -void DidDrawCanvas::onFlush() {} - } // namespace flutter diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/canvas_spy.h b/engine/src/flutter/shell/platform/fuchsia/flutter/canvas_spy.h index 629538dd83..fa781cbcb3 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/canvas_spy.h +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/canvas_spy.h @@ -248,9 +248,6 @@ class DidDrawCanvas final : public SkCanvasVirtualEnforcer { const SkPaint*, SrcRectConstraint) override; - // |SkCanvasVirtualEnforcer| - void onFlush() override; - void MarkDrawIfNonTransparentPaint(const SkPaint& paint); FML_DISALLOW_COPY_AND_ASSIGN(DidDrawCanvas);