From ec84f26d469cd2f5333ba59bba0cad9c161d61e1 Mon Sep 17 00:00:00 2001 From: Kevin Lubick Date: Mon, 24 Jul 2023 08:54:25 -0400 Subject: [PATCH] Remove more calls to SkCanvas::flush() and SkSurface::flush() (flutter/engine#43902) Skia has removed flushing from both [SkCanvas](https://skia-review.googlesource.com/c/skia/+/716476) and [SkSurface](https://skia-review.googlesource.com/c/skia/+/698237). This migrates the calls to use GrDirectContext directly (or removing no-op flushes for Raster canvases/surfaces). ## 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]. - [ ] 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 --- .../testing/dl_rendering_unittests.cc | 16 ++++++++++------ engine/src/flutter/lib/web_ui/skwasm/surface.cpp | 3 ++- .../flutter/flatland_external_view_embedder.cc | 7 ++++++- .../flutter/gfx_external_view_embedder.cc | 7 ++++++- 4 files changed, 24 insertions(+), 9 deletions(-) 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 af6b0cf868..4e1b9752fe 100644 --- a/engine/src/flutter/display_list/testing/dl_rendering_unittests.cc +++ b/engine/src/flutter/display_list/testing/dl_rendering_unittests.cc @@ -4141,8 +4141,6 @@ class DisplayListNopTest : public DisplayListCanvas { auto surface = SkSurfaces::Raster(SkImageInfo::MakeN32Premul(w, h)); SkCanvas* canvas = surface->getCanvas(); renderer(canvas); - canvas->flush(); - surface->flushAndSubmit(true); return std::make_unique(surface, snapshot); } @@ -4258,8 +4256,11 @@ class DisplayListNopTest : public DisplayListCanvas { result_canvas->clear(SK_ColorTRANSPARENT); result_canvas->drawImage(test_image.get(), 0, 0); result_canvas->drawRect(test_bounds, sk_paint); - result_canvas->flush(); - result_surface->sk_surface()->flushAndSubmit(true); + if (GrDirectContext* direct_context = GrAsDirectContext( + result_surface->sk_surface()->recordingContext())) { + return direct_context->flushAndSubmit(result_surface->sk_surface(), + true); + } auto result_pixels = std::make_unique(result_surface->sk_surface()); @@ -4316,8 +4317,11 @@ class DisplayListNopTest : public DisplayListCanvas { result_canvas->drawImage(test_image_dst_data->image(), 0, 0); result_canvas->drawImage(test_image_src_data->image(), 0, 0, SkSamplingOptions(), &sk_paint); - result_canvas->flush(); - result_surface->sk_surface()->flushAndSubmit(true); + if (GrDirectContext* direct_context = GrAsDirectContext( + result_surface->sk_surface()->recordingContext())) { + return direct_context->flushAndSubmit(result_surface->sk_surface(), + true); + } auto result_pixels = std::make_unique(result_surface->sk_surface()); diff --git a/engine/src/flutter/lib/web_ui/skwasm/surface.cpp b/engine/src/flutter/lib/web_ui/skwasm/surface.cpp index 99811dcd40..834131f8bc 100644 --- a/engine/src/flutter/lib/web_ui/skwasm/surface.cpp +++ b/engine/src/flutter/lib/web_ui/skwasm/surface.cpp @@ -5,6 +5,7 @@ #include "surface.h" #include "third_party/skia/include/gpu/GrBackendSurface.h" +#include "third_party/skia/include/gpu/GrDirectContext.h" using namespace Skwasm; @@ -171,7 +172,7 @@ void Surface::_renderPicture(const SkPicture* picture) { makeCurrent(_glContext); auto canvas = _surface->getCanvas(); canvas->drawPicture(picture); - _surface->flush(); + _grContext->flush(_surface); } void Surface::_rasterizeImage(SkImage* image, diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/flatland_external_view_embedder.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/flatland_external_view_embedder.cc index 3823e672b2..7281d471f0 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/flatland_external_view_embedder.cc +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/flatland_external_view_embedder.cc @@ -9,6 +9,8 @@ #include "flutter/fml/trace_event.h" #include "third_party/skia/include/core/SkPicture.h" #include "third_party/skia/include/core/SkSurface.h" +#include "third_party/skia/include/gpu/GrDirectContext.h" +#include "third_party/skia/include/gpu/GrRecordingContext.h" namespace flutter_runner { namespace { @@ -487,7 +489,10 @@ void FlatlandExternalViewEmbedder::SubmitFrame( canvas->setMatrix(SkMatrix::I()); canvas->clear(SK_ColorTRANSPARENT); canvas->drawPicture(layer->second.picture); - canvas->flush(); + if (GrDirectContext* direct_context = + GrAsDirectContext(canvas->recordingContext())) { + return direct_context->flushAndSubmit(); + } } } diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/gfx_external_view_embedder.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/gfx_external_view_embedder.cc index 37e8d6a474..aeba9b76de 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/gfx_external_view_embedder.cc +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/gfx_external_view_embedder.cc @@ -14,6 +14,8 @@ #include "flutter/fml/trace_event.h" #include "third_party/skia/include/core/SkPicture.h" #include "third_party/skia/include/core/SkSurface.h" +#include "third_party/skia/include/gpu/GrDirectContext.h" +#include "third_party/skia/include/gpu/GrRecordingContext.h" namespace flutter_runner { namespace { @@ -617,7 +619,10 @@ void GfxExternalViewEmbedder::SubmitFrame( canvas->setMatrix(SkMatrix::I()); canvas->clear(SK_ColorTRANSPARENT); canvas->drawPicture(layer->second.picture); - canvas->flush(); + if (GrDirectContext* direct_context = + GrAsDirectContext(canvas->recordingContext())) { + return direct_context->flushAndSubmit(); + } } }