Skip to content

Commit

Permalink
Use safer GrDirectContext APIs (flutter#45644)
Browse files Browse the repository at this point in the history
In http://review.skia.org/750403 and http://review.skia.org/751523, Skia
modified some `GrDirectContext` APIs to make them less error-prone in
response to https://crbug.com/1475906. This updates Flutter to call
those modified APIs.

## 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].
- [x] 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 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
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
[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
  • Loading branch information
kjlubick authored Sep 11, 2023
1 parent c7cea7b commit add224d
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 9 deletions.
3 changes: 2 additions & 1 deletion display_list/benchmarking/dl_benchmarks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "third_party/skia/include/core/SkTextBlob.h"
#include "third_party/skia/include/gpu/GrDirectContext.h"
#include "third_party/skia/include/gpu/GrRecordingContext.h"
#include "third_party/skia/include/gpu/GrTypes.h"

namespace flutter {
namespace testing {
Expand Down Expand Up @@ -47,7 +48,7 @@ static void FlushSubmitCpuSync(const sk_sp<SkSurface>& surface) {
}
if (GrDirectContext* dContext =
GrAsDirectContext(surface->recordingContext())) {
dContext->flushAndSubmit(surface, /*syncCpu=*/true);
dContext->flushAndSubmit(surface.get(), GrSyncCpu::kYes);
}
}

Expand Down
9 changes: 6 additions & 3 deletions display_list/testing/dl_rendering_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "third_party/skia/include/effects/SkImageFilters.h"
#include "third_party/skia/include/gpu/GrDirectContext.h"
#include "third_party/skia/include/gpu/GrRecordingContext.h"
#include "third_party/skia/include/gpu/GrTypes.h"

namespace flutter {
namespace testing {
Expand Down Expand Up @@ -501,7 +502,7 @@ class RenderEnvironment {

if (GrDirectContext* dContext =
GrAsDirectContext(surface->recordingContext())) {
dContext->flushAndSubmit(surface, /*syncCpu=*/true);
dContext->flushAndSubmit(surface.get(), GrSyncCpu::kYes);
}
return std::make_unique<RenderResult>(surface);
}
Expand Down Expand Up @@ -4203,7 +4204,8 @@ class DisplayListNopTest : public DisplayListCanvas {
if (GrDirectContext* direct_context = GrAsDirectContext(
result_surface->sk_surface()->recordingContext())) {
direct_context->flushAndSubmit();
direct_context->flushAndSubmit(result_surface->sk_surface(), true);
direct_context->flushAndSubmit(result_surface->sk_surface().get(),
GrSyncCpu::kYes);
}
auto result_pixels =
std::make_unique<RenderResult>(result_surface->sk_surface());
Expand Down Expand Up @@ -4264,7 +4266,8 @@ class DisplayListNopTest : public DisplayListCanvas {
if (GrDirectContext* direct_context = GrAsDirectContext(
result_surface->sk_surface()->recordingContext())) {
direct_context->flushAndSubmit();
direct_context->flushAndSubmit(result_surface->sk_surface(), true);
direct_context->flushAndSubmit(result_surface->sk_surface().get(),
GrSyncCpu::kYes);
}
auto result_pixels =
std::make_unique<RenderResult>(result_surface->sk_surface());
Expand Down
3 changes: 2 additions & 1 deletion flow/skia_gpu_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "third_party/skia/include/core/SkRefCnt.h"
#include "third_party/skia/include/gpu/GrBackendSurface.h"
#include "third_party/skia/include/gpu/GrDirectContext.h"
#include "third_party/skia/include/gpu/GrTypes.h"

namespace flutter {

Expand Down Expand Up @@ -129,7 +130,7 @@ class UnrefQueue : public fml::RefCountedThreadSafe<UnrefQueue<T>> {
context->performDeferredCleanup(std::chrono::milliseconds(0));
}

context->flushAndSubmit(true);
context->flushAndSubmit(GrSyncCpu::kYes);
}
}

Expand Down
3 changes: 2 additions & 1 deletion flow/skia_gpu_object_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "flutter/testing/thread_test.h"
#include "gtest/gtest.h"
#include "third_party/skia/include/core/SkRefCnt.h"
#include "third_party/skia/include/gpu/GrTypes.h"

namespace flutter {
namespace testing {
Expand Down Expand Up @@ -43,7 +44,7 @@ class TestResourceContext : public TestSkObject {
~TestResourceContext() = default;
void performDeferredCleanup(std::chrono::milliseconds msNotUsed) {}
void deleteBackendTexture(const GrBackendTexture& texture) {}
void flushAndSubmit(bool syncCpu) {}
void flushAndSubmit(GrSyncCpu sync) {}
};

class SkiaGpuObjectTest : public ThreadTest {
Expand Down
3 changes: 2 additions & 1 deletion shell/common/rasterizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "third_party/skia/include/encode/SkPngEncoder.h"
#include "third_party/skia/include/gpu/GrBackendSurface.h"
#include "third_party/skia/include/gpu/GrDirectContext.h"
#include "third_party/skia/include/gpu/GrTypes.h"
#include "third_party/skia/include/gpu/ganesh/SkSurfaceGanesh.h"
#include "third_party/skia/include/utils/SkBase64.h"

Expand Down Expand Up @@ -111,7 +112,7 @@ void Rasterizer::Teardown() {
if (context_switch->GetResult()) {
compositor_context_->OnGrContextDestroyed();
if (auto* context = surface_->GetContext()) {
context->purgeUnlockedResources(/*scratchResourcesOnly=*/false);
context->purgeUnlockedResources(GrPurgeResourceOptions::kAllResources);
}
}
surface_.reset();
Expand Down
3 changes: 2 additions & 1 deletion shell/common/rasterizer_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "third_party/skia/include/core/SkColorSpace.h"
#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/include/gpu/GrTypes.h"
#include "third_party/skia/include/gpu/ganesh/SkSurfaceGanesh.h"

#include "gmock/gmock.h"
Expand Down Expand Up @@ -1014,7 +1015,7 @@ TEST(RasterizerTest, TeardownFreesResourceCache) {

SkPaint paint;
sk_surface->getCanvas()->drawPaint(paint);
context->flushAndSubmit(true);
context->flushAndSubmit(GrSyncCpu::kYes);

EXPECT_EQ(context->getResourceCachePurgeableBytes(), 0ul);

Expand Down
4 changes: 3 additions & 1 deletion shell/platform/fuchsia/flutter/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "flutter/shell/common/thread_host.h"
#include "third_party/skia/include/core/SkPicture.h"
#include "third_party/skia/include/core/SkSerialProcs.h"
#include "third_party/skia/include/gpu/GrTypes.h"
#include "third_party/skia/include/ports/SkFontMgr_fuchsia.h"

#include "../runtime/dart/utils/files.h"
Expand Down Expand Up @@ -944,7 +945,8 @@ void Engine::WarmupSkps(
};

surface_producer->gr_context()->flush(flush_info);
surface_producer->gr_context()->submit(synchronous);
surface_producer->gr_context()->submit(
synchronous ? GrSyncCpu::kYes : GrSyncCpu::kNo);
}
} else {
if (i == count - 1) {
Expand Down

0 comments on commit add224d

Please sign in to comment.