Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit ee53c04

Browse files
authored
Replace SkSurface::flush methods with GrDirectContext methods (#42425)
In https://skia-review.googlesource.com/c/skia/+/698237, Skia moved the SkSurface::flush* methods to GrDirectContext (and skgpu::ganesh::Flush). This updates Flutter to use those versions, which are drop-in replacements for the previous functionality. ## 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]. <!-- Links --> [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
1 parent 682bd0f commit ee53c04

File tree

4 files changed

+36
-18
lines changed

4 files changed

+36
-18
lines changed

display_list/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ if (enable_unittests) {
148148
deps = [
149149
":display_list",
150150
":display_list_fixtures",
151+
"//flutter/common/graphics",
151152
"//flutter/display_list/testing:display_list_surface_provider",
152153
"//flutter/display_list/testing:display_list_testing",
153154
"//flutter/testing",

display_list/benchmarking/dl_benchmarks.cc

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include "third_party/skia/include/core/SkPoint.h"
1313
#include "third_party/skia/include/core/SkSurface.h"
1414
#include "third_party/skia/include/core/SkTextBlob.h"
15+
#include "third_party/skia/include/gpu/GrDirectContext.h"
16+
#include "third_party/skia/include/gpu/GrRecordingContext.h"
1517

1618
namespace flutter {
1719
namespace testing {
@@ -39,6 +41,16 @@ DlPaint GetPaintForRun(unsigned attributes) {
3941
return paint;
4042
}
4143

44+
static void FlushSubmitCpuSync(const sk_sp<SkSurface>& surface) {
45+
if (!surface) {
46+
return;
47+
}
48+
if (GrDirectContext* dContext =
49+
GrAsDirectContext(surface->recordingContext())) {
50+
dContext->flushAndSubmit(surface, /*syncCpu=*/true);
51+
}
52+
}
53+
4254
void AnnotateAttributes(unsigned attributes,
4355
benchmark::State& state,
4456
const DisplayListAttributeFlags flags) {
@@ -100,7 +112,7 @@ void BM_DrawLine(benchmark::State& state,
100112
// We only want to time the actual rasterization.
101113
for ([[maybe_unused]] auto _ : state) {
102114
canvas.DrawDisplayList(display_list);
103-
surface->flushAndSubmit(true);
115+
FlushSubmitCpuSync(surface);
104116
}
105117

106118
auto filename = surface_provider->backend_name() + "-DrawLine-" +
@@ -149,7 +161,7 @@ void BM_DrawRect(benchmark::State& state,
149161
// We only want to time the actual rasterization.
150162
for ([[maybe_unused]] auto _ : state) {
151163
canvas.DrawDisplayList(display_list);
152-
surface->flushAndSubmit(true);
164+
FlushSubmitCpuSync(surface);
153165
}
154166

155167
auto filename = surface_provider->backend_name() + "-DrawRect-" +
@@ -195,7 +207,7 @@ void BM_DrawOval(benchmark::State& state,
195207
// We only want to time the actual rasterization.
196208
for ([[maybe_unused]] auto _ : state) {
197209
canvas.DrawDisplayList(display_list);
198-
surface->flushAndSubmit(true);
210+
FlushSubmitCpuSync(surface);
199211
}
200212

201213
auto filename = surface_provider->backend_name() + "-DrawOval-" +
@@ -243,7 +255,7 @@ void BM_DrawCircle(benchmark::State& state,
243255
// We only want to time the actual rasterization.
244256
for ([[maybe_unused]] auto _ : state) {
245257
canvas.DrawDisplayList(display_list);
246-
surface->flushAndSubmit(true);
258+
FlushSubmitCpuSync(surface);
247259
}
248260

249261
auto filename = surface_provider->backend_name() + "-DrawCircle-" +
@@ -321,7 +333,7 @@ void BM_DrawRRect(benchmark::State& state,
321333
// We only want to time the actual rasterization.
322334
for ([[maybe_unused]] auto _ : state) {
323335
canvas.DrawDisplayList(display_list);
324-
surface->flushAndSubmit(true);
336+
FlushSubmitCpuSync(surface);
325337
}
326338

327339
auto filename = surface_provider->backend_name() + "-DrawRRect-" +
@@ -403,7 +415,7 @@ void BM_DrawDRRect(benchmark::State& state,
403415
// We only want to time the actual rasterization.
404416
for ([[maybe_unused]] auto _ : state) {
405417
canvas.DrawDisplayList(display_list);
406-
surface->flushAndSubmit(true);
418+
FlushSubmitCpuSync(surface);
407419
}
408420

409421
auto filename = surface_provider->backend_name() + "-DrawDRRect-" +
@@ -456,7 +468,7 @@ void BM_DrawArc(benchmark::State& state,
456468
// We only want to time the actual rasterization.
457469
for ([[maybe_unused]] auto _ : state) {
458470
canvas.DrawDisplayList(display_list);
459-
surface->flushAndSubmit(true);
471+
FlushSubmitCpuSync(surface);
460472
}
461473

462474
auto filename = surface_provider->backend_name() + "-DrawArc-" +
@@ -659,7 +671,7 @@ void BM_DrawPath(benchmark::State& state,
659671
// We only want to time the actual rasterization.
660672
for ([[maybe_unused]] auto _ : state) {
661673
canvas.DrawDisplayList(display_list);
662-
surface->flushAndSubmit(true);
674+
FlushSubmitCpuSync(surface);
663675
}
664676

665677
auto filename = surface_provider->backend_name() + "-DrawPath-" + label +
@@ -805,7 +817,7 @@ void BM_DrawVertices(benchmark::State& state,
805817
// We only want to time the actual rasterization.
806818
for ([[maybe_unused]] auto _ : state) {
807819
canvas.DrawDisplayList(display_list);
808-
surface->flushAndSubmit(true);
820+
FlushSubmitCpuSync(surface);
809821
}
810822

811823
auto filename = surface_provider->backend_name() + "-DrawVertices-" +
@@ -901,7 +913,7 @@ void BM_DrawPoints(benchmark::State& state,
901913

902914
for ([[maybe_unused]] auto _ : state) {
903915
canvas.DrawDisplayList(display_list);
904-
surface->flushAndSubmit(true);
916+
FlushSubmitCpuSync(surface);
905917
}
906918

907919
auto filename = surface_provider->backend_name() + "-DrawPoints-" +
@@ -979,7 +991,7 @@ void BM_DrawImage(benchmark::State& state,
979991

980992
for ([[maybe_unused]] auto _ : state) {
981993
canvas.DrawDisplayList(display_list);
982-
surface->flushAndSubmit(true);
994+
FlushSubmitCpuSync(surface);
983995
}
984996

985997
auto filename = surface_provider->backend_name() + "-DrawImage-" +
@@ -1065,7 +1077,7 @@ void BM_DrawImageRect(benchmark::State& state,
10651077

10661078
for ([[maybe_unused]] auto _ : state) {
10671079
canvas.DrawDisplayList(display_list);
1068-
surface->flushAndSubmit(true);
1080+
FlushSubmitCpuSync(surface);
10691081
}
10701082

10711083
auto filename = surface_provider->backend_name() + "-DrawImageRect-" +
@@ -1152,7 +1164,7 @@ void BM_DrawImageNine(benchmark::State& state,
11521164

11531165
for ([[maybe_unused]] auto _ : state) {
11541166
canvas.DrawDisplayList(display_list);
1155-
surface->flushAndSubmit(true);
1167+
FlushSubmitCpuSync(surface);
11561168
}
11571169

11581170
auto filename = surface_provider->backend_name() + "-DrawImageNine-" +
@@ -1198,7 +1210,7 @@ void BM_DrawTextBlob(benchmark::State& state,
11981210

11991211
for ([[maybe_unused]] auto _ : state) {
12001212
canvas.DrawDisplayList(display_list);
1201-
surface->flushAndSubmit(true);
1213+
FlushSubmitCpuSync(surface);
12021214
}
12031215

12041216
auto filename = surface_provider->backend_name() + "-DrawTextBlob-" +
@@ -1263,7 +1275,7 @@ void BM_DrawShadow(benchmark::State& state,
12631275
// We only want to time the actual rasterization.
12641276
for ([[maybe_unused]] auto _ : state) {
12651277
canvas.DrawDisplayList(display_list);
1266-
surface->flushAndSubmit(true);
1278+
FlushSubmitCpuSync(surface);
12671279
}
12681280

12691281
auto filename = surface_provider->backend_name() + "-DrawShadow-" +
@@ -1317,7 +1329,7 @@ void BM_SaveLayer(benchmark::State& state,
13171329
// We only want to time the actual rasterization.
13181330
for ([[maybe_unused]] auto _ : state) {
13191331
canvas.DrawDisplayList(display_list);
1320-
surface->flushAndSubmit(true);
1332+
FlushSubmitCpuSync(surface);
13211333
}
13221334

13231335
auto filename = surface_provider->backend_name() + "-SaveLayer-" +

display_list/testing/dl_rendering_unittests.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include "third_party/skia/include/core/SkSurface.h"
2222
#include "third_party/skia/include/effects/SkGradientShader.h"
2323
#include "third_party/skia/include/effects/SkImageFilters.h"
24+
#include "third_party/skia/include/gpu/GrDirectContext.h"
25+
#include "third_party/skia/include/gpu/GrRecordingContext.h"
2426

2527
namespace flutter {
2628
namespace testing {
@@ -490,7 +492,10 @@ class RenderEnvironment {
490492
canvas->restoreToCount(restore_count);
491493

492494
canvas->flush();
493-
surface->flushAndSubmit(true);
495+
if (GrDirectContext* dContext =
496+
GrAsDirectContext(surface->recordingContext())) {
497+
dContext->flushAndSubmit(surface, /*syncCpu=*/true);
498+
}
494499
return std::make_unique<RenderResult>(surface);
495500
}
496501

vulkan/vulkan_swapchain.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ bool VulkanSwapchain::Submit() {
504504
// Step 0:
505505
// Make sure Skia has flushed all work for the surface to the gpu.
506506
// ---------------------------------------------------------------------------
507-
surface->flushAndSubmit();
507+
skgpu::ganesh::FlushAndSubmit(surface);
508508

509509
// ---------------------------------------------------------------------------
510510
// Step 1:

0 commit comments

Comments
 (0)