From ecda6a659e1bdbe8a7aea71e0c581b944a486438 Mon Sep 17 00:00:00 2001 From: Kevin Lubick Date: Thu, 3 Aug 2023 15:46:14 -0400 Subject: [PATCH] Migrate GL calls of GrBackend* (flutter/engine#44334) In https://skia-review.googlesource.com/c/skia/+/701398 Skia refactored GrBackend* to not require #ifdefs. This changes callsites in Flutter to use static functions instead of methods that were conditionally compiled on those classes. There should be no functional change with these. As I was updating these callsites, I saw uses of the deprecated GrMipMapped enum and used the updated skgpu::Mipmapped (the former is an alias to the latter). ## 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. - [ ] 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 --- .../flutter/shell/gpu/gpu_surface_gl_skia.cc | 17 +++++++------ .../android/android_external_texture_gl.cc | 5 +++- .../hardware_buffer_external_texture_gl.cc | 5 +++- .../shell/platform/embedder/embedder.cc | 24 ++++++++++--------- .../embedder/embedder_external_texture_gl.cc | 6 +++-- .../embedder_test_backingstore_producer.cc | 7 ++++-- engine/src/flutter/testing/test_gl_surface.cc | 16 +++++++------ 7 files changed, 49 insertions(+), 31 deletions(-) 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 9ced169f11..3118bee005 100644 --- a/engine/src/flutter/shell/gpu/gpu_surface_gl_skia.cc +++ b/engine/src/flutter/shell/gpu/gpu_surface_gl_skia.cc @@ -19,9 +19,11 @@ #include "third_party/skia/include/gpu/GrBackendSurface.h" #include "third_party/skia/include/gpu/GrContextOptions.h" #include "third_party/skia/include/gpu/ganesh/SkSurfaceGanesh.h" +#include "third_party/skia/include/gpu/ganesh/gl/GrGLBackendSurface.h" +#include "third_party/skia/include/gpu/gl/GrGLTypes.h" // These are common defines present on all OpenGL headers. However, we don't -// want to perform GL header reasolution on each platform we support. So just +// want to perform GL header resolution on each platform we support. So just // define these upfront. It is unlikely we will need more. But, if we do, we can // add the same here. #define GPU_GL_RGBA8 0x8058 @@ -138,12 +140,13 @@ static sk_sp WrapOnscreenSurface(GrDirectContext* context, framebuffer_info.fFBOID = static_cast(fbo); framebuffer_info.fFormat = format; - GrBackendRenderTarget render_target(size.width(), // width - size.height(), // height - 0, // sample count - 0, // stencil bits - framebuffer_info // framebuffer info - ); + auto render_target = + GrBackendRenderTargets::MakeGL(size.width(), // width + size.height(), // height + 0, // sample count + 0, // stencil bits + framebuffer_info // framebuffer info + ); sk_sp colorspace = SkColorSpace::MakeSRGB(); SkSurfaceProps surface_props(0, kUnknown_SkPixelGeometry); diff --git a/engine/src/flutter/shell/platform/android/android_external_texture_gl.cc b/engine/src/flutter/shell/platform/android/android_external_texture_gl.cc index 472c426747..4df19aa85c 100644 --- a/engine/src/flutter/shell/platform/android/android_external_texture_gl.cc +++ b/engine/src/flutter/shell/platform/android/android_external_texture_gl.cc @@ -16,6 +16,8 @@ #include "third_party/skia/include/gpu/GrBackendSurface.h" #include "third_party/skia/include/gpu/GrDirectContext.h" #include "third_party/skia/include/gpu/ganesh/SkImageGanesh.h" +#include "third_party/skia/include/gpu/ganesh/gl/GrGLBackendSurface.h" +#include "third_party/skia/include/gpu/gl/GrGLTypes.h" namespace flutter { @@ -60,7 +62,8 @@ void AndroidExternalTextureGL::Paint(PaintContext& context, } GrGLTextureInfo textureInfo = {GL_TEXTURE_EXTERNAL_OES, texture_name_, GL_RGBA8_OES}; - GrBackendTexture backendTexture(1, 1, GrMipMapped::kNo, textureInfo); + auto backendTexture = + GrBackendTextures::MakeGL(1, 1, skgpu::Mipmapped::kNo, textureInfo); sk_sp image = SkImages::BorrowTextureFrom( context.gr_context, backendTexture, kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr); diff --git a/engine/src/flutter/shell/platform/android/hardware_buffer_external_texture_gl.cc b/engine/src/flutter/shell/platform/android/hardware_buffer_external_texture_gl.cc index 1b513917c1..8cb74dccae 100644 --- a/engine/src/flutter/shell/platform/android/hardware_buffer_external_texture_gl.cc +++ b/engine/src/flutter/shell/platform/android/hardware_buffer_external_texture_gl.cc @@ -18,6 +18,8 @@ #include "third_party/skia/include/gpu/GrBackendSurface.h" #include "third_party/skia/include/gpu/GrDirectContext.h" #include "third_party/skia/include/gpu/ganesh/SkImageGanesh.h" +#include "third_party/skia/include/gpu/ganesh/gl/GrGLBackendSurface.h" +#include "third_party/skia/include/gpu/gl/GrGLTypes.h" namespace flutter { @@ -54,7 +56,8 @@ void HardwareBufferExternalTextureGL::Paint(PaintContext& context, } GrGLTextureInfo textureInfo = {GL_TEXTURE_EXTERNAL_OES, texture_.get().texture_name, GL_RGBA8_OES}; - GrBackendTexture backendTexture(1, 1, GrMipMapped::kNo, textureInfo); + auto backendTexture = + GrBackendTextures::MakeGL(1, 1, skgpu::Mipmapped::kNo, textureInfo); sk_sp image = SkImages::BorrowTextureFrom( context.gr_context, backendTexture, kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr); diff --git a/engine/src/flutter/shell/platform/embedder/embedder.cc b/engine/src/flutter/shell/platform/embedder/embedder.cc index 53c71d1c4d..b5a29314bb 100644 --- a/engine/src/flutter/shell/platform/embedder/embedder.cc +++ b/engine/src/flutter/shell/platform/embedder/embedder.cc @@ -68,6 +68,8 @@ extern const intptr_t kPlatformStrongDillSize; // embedder/BUILD.gn variable impeller_supports_rendering is disabled. #ifdef SHELL_ENABLE_GL #include "flutter/shell/platform/embedder/embedder_external_texture_gl.h" +#include "third_party/skia/include/gpu/ganesh/gl/GrGLBackendSurface.h" +#include "third_party/skia/include/gpu/gl/GrGLTypes.h" #ifdef IMPELLER_SUPPORTS_RENDERING #include "flutter/shell/platform/embedder/embedder_render_target_impeller.h" // nogncheck #include "flutter/shell/platform/embedder/embedder_surface_gl_impeller.h" // nogncheck @@ -742,10 +744,10 @@ static sk_sp MakeSkSurfaceFromBackingStore( texture_info.fID = texture->name; texture_info.fFormat = texture->format; - GrBackendTexture backend_texture(config.size.width, // - config.size.height, // - GrMipMapped::kNo, // - texture_info // + auto backend_texture = GrBackendTextures::MakeGL(config.size.width, // + config.size.height, // + skgpu::Mipmapped::kNo, // + texture_info // ); SkSurfaceProps surface_properties(0, kUnknown_SkPixelGeometry); @@ -783,13 +785,13 @@ static sk_sp MakeSkSurfaceFromBackingStore( framebuffer_info.fFormat = framebuffer->target; framebuffer_info.fFBOID = framebuffer->name; - GrBackendRenderTarget backend_render_target( - config.size.width, // width - config.size.height, // height - 1, // sample count - 0, // stencil bits - framebuffer_info // framebuffer info - ); + auto backend_render_target = + GrBackendRenderTargets::MakeGL(config.size.width, // width + config.size.height, // height + 1, // sample count + 0, // stencil bits + framebuffer_info // framebuffer info + ); SkSurfaceProps surface_properties(0, kUnknown_SkPixelGeometry); diff --git a/engine/src/flutter/shell/platform/embedder/embedder_external_texture_gl.cc b/engine/src/flutter/shell/platform/embedder/embedder_external_texture_gl.cc index 01d32b1e9a..bbf30d143d 100644 --- a/engine/src/flutter/shell/platform/embedder/embedder_external_texture_gl.cc +++ b/engine/src/flutter/shell/platform/embedder/embedder_external_texture_gl.cc @@ -15,6 +15,8 @@ #include "third_party/skia/include/gpu/GrBackendSurface.h" #include "third_party/skia/include/gpu/GrDirectContext.h" #include "third_party/skia/include/gpu/ganesh/SkImageGanesh.h" +#include "third_party/skia/include/gpu/ganesh/gl/GrGLBackendSurface.h" +#include "third_party/skia/include/gpu/gl/GrGLTypes.h" namespace flutter { @@ -77,8 +79,8 @@ sk_sp EmbedderExternalTextureGL::ResolveTexture( height = texture->height; } - GrBackendTexture gr_backend_texture(width, height, GrMipMapped::kNo, - gr_texture_info); + auto gr_backend_texture = GrBackendTextures::MakeGL( + width, height, skgpu::Mipmapped::kNo, gr_texture_info); SkImages::TextureReleaseProc release_proc = texture->destruction_callback; auto image = SkImages::BorrowTextureFrom(context, // context diff --git a/engine/src/flutter/shell/platform/embedder/tests/embedder_test_backingstore_producer.cc b/engine/src/flutter/shell/platform/embedder/tests/embedder_test_backingstore_producer.cc index aad4aed957..aa8e47bd22 100644 --- a/engine/src/flutter/shell/platform/embedder/tests/embedder_test_backingstore_producer.cc +++ b/engine/src/flutter/shell/platform/embedder/tests/embedder_test_backingstore_producer.cc @@ -13,6 +13,8 @@ #include "third_party/skia/include/core/SkSurface.h" #include "third_party/skia/include/gpu/GrBackendSurface.h" #include "third_party/skia/include/gpu/ganesh/SkSurfaceGanesh.h" +#include "third_party/skia/include/gpu/ganesh/gl/GrGLBackendSurface.h" +#include "third_party/skia/include/gpu/gl/GrGLTypes.h" #include #include @@ -111,7 +113,8 @@ bool EmbedderTestBackingStoreProducer::CreateFramebuffer( } GrGLFramebufferInfo framebuffer_info = {}; - if (!render_target.getGLFramebufferInfo(&framebuffer_info)) { + if (!GrBackendRenderTargets::GetGLFramebufferInfo(render_target, + &framebuffer_info)) { FML_LOG(ERROR) << "Could not access backend framebuffer info."; return false; } @@ -164,7 +167,7 @@ bool EmbedderTestBackingStoreProducer::CreateTexture( } GrGLTextureInfo texture_info = {}; - if (!render_texture.getGLTextureInfo(&texture_info)) { + if (!GrBackendTextures::GetGLTextureInfo(render_texture, &texture_info)) { FML_LOG(ERROR) << "Could not access backend texture info."; return false; } diff --git a/engine/src/flutter/testing/test_gl_surface.cc b/engine/src/flutter/testing/test_gl_surface.cc index c5343076b4..8c98bacde9 100644 --- a/engine/src/flutter/testing/test_gl_surface.cc +++ b/engine/src/flutter/testing/test_gl_surface.cc @@ -19,7 +19,9 @@ #include "third_party/skia/include/core/SkSurface.h" #include "third_party/skia/include/gpu/GrBackendSurface.h" #include "third_party/skia/include/gpu/ganesh/SkSurfaceGanesh.h" +#include "third_party/skia/include/gpu/ganesh/gl/GrGLBackendSurface.h" #include "third_party/skia/include/gpu/gl/GrGLAssembleInterface.h" +#include "third_party/skia/include/gpu/gl/GrGLTypes.h" namespace flutter { namespace testing { @@ -351,13 +353,13 @@ sk_sp TestGLSurface::GetOnscreenSurface() { framebuffer_info.fFormat = 0x93A1; // GL_BGRA8; #endif - GrBackendRenderTarget backend_render_target( - width, // width - height, // height - 1, // sample count - 8, // stencil bits - framebuffer_info // framebuffer info - ); + auto backend_render_target = + GrBackendRenderTargets::MakeGL(width, // width + height, // height + 1, // sample count + 8, // stencil bits + framebuffer_info // framebuffer info + ); SkSurfaceProps surface_properties(0, kUnknown_SkPixelGeometry);