Skip to content

Commit

Permalink
Account for root surface transformation on the surfaces managed by th…
Browse files Browse the repository at this point in the history
…e external view embedder. (flutter#11384)

The earlier design speculated that embedders could affect the same
transformations on the layers post engine compositor presentation but before
final composition.

However, the linked issue points out that this design is not suitable for use
with hardware overlay planes. When rendering to the same, to affect the
transformation before composition, embedders would have to render to an
off-screen render target and then apply the transformation before presentation.
This patch negates the need for that off-screen render pass.

To be clear, the previous architecture is still fully viable. Embedders still
have full control over layer transformations before composition. This is an
optimization for the hardware overlay planes use-case.

Fixes b/139758641
  • Loading branch information
chinmaygarde committed Sep 17, 2019
1 parent f38f3a2 commit 1c7300e
Show file tree
Hide file tree
Showing 32 changed files with 1,175 additions and 292 deletions.
7 changes: 5 additions & 2 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ FILE: ../../../flutter/common/task_runners.cc
FILE: ../../../flutter/common/task_runners.h
FILE: ../../../flutter/flow/compositor_context.cc
FILE: ../../../flutter/flow/compositor_context.h
FILE: ../../../flutter/flow/debug_print.cc
FILE: ../../../flutter/flow/debug_print.h
FILE: ../../../flutter/flow/embedded_views.cc
FILE: ../../../flutter/flow/embedded_views.h
FILE: ../../../flutter/flow/instrumentation.cc
Expand Down Expand Up @@ -849,10 +847,15 @@ FILE: ../../../flutter/shell/platform/embedder/embedder_task_runner.h
FILE: ../../../flutter/shell/platform/embedder/embedder_thread_host.cc
FILE: ../../../flutter/shell/platform/embedder/embedder_thread_host.h
FILE: ../../../flutter/shell/platform/embedder/fixtures/compositor.png
FILE: ../../../flutter/shell/platform/embedder/fixtures/compositor_root_surface_xformation.png
FILE: ../../../flutter/shell/platform/embedder/fixtures/compositor_software.png
FILE: ../../../flutter/shell/platform/embedder/fixtures/compositor_with_platform_layer_on_bottom.png
FILE: ../../../flutter/shell/platform/embedder/fixtures/compositor_with_root_layer_only.png
FILE: ../../../flutter/shell/platform/embedder/fixtures/gradient.png
FILE: ../../../flutter/shell/platform/embedder/fixtures/gradient_xform.png
FILE: ../../../flutter/shell/platform/embedder/fixtures/main.dart
FILE: ../../../flutter/shell/platform/embedder/fixtures/scene_without_custom_compositor.png
FILE: ../../../flutter/shell/platform/embedder/fixtures/scene_without_custom_compositor_with_xform.png
FILE: ../../../flutter/shell/platform/embedder/platform_view_embedder.cc
FILE: ../../../flutter/shell/platform/embedder/platform_view_embedder.h
FILE: ../../../flutter/shell/platform/embedder/vsync_waiter_embedder.cc
Expand Down
2 changes: 0 additions & 2 deletions flow/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ source_set("flow") {
sources = [
"compositor_context.cc",
"compositor_context.h",
"debug_print.cc",
"debug_print.h",
"embedded_views.cc",
"embedded_views.h",
"instrumentation.cc",
Expand Down
84 changes: 0 additions & 84 deletions flow/debug_print.cc

This file was deleted.

29 changes: 0 additions & 29 deletions flow/debug_print.h

This file was deleted.

3 changes: 2 additions & 1 deletion lib/ui/painting/image_decoder_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class TestIOManager final : public IOManager {
public:
TestIOManager(fml::RefPtr<fml::TaskRunner> task_runner,
bool has_gpu_context = true)
: gl_context_(has_gpu_context ? gl_surface_.CreateGrContext() : nullptr),
: gl_surface_(SkISize::Make(1, 1)),
gl_context_(has_gpu_context ? gl_surface_.CreateGrContext() : nullptr),
weak_gl_context_factory_(
has_gpu_context ? std::make_unique<fml::WeakPtrFactory<GrContext>>(
gl_context_.get())
Expand Down
3 changes: 2 additions & 1 deletion shell/common/shell_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ void ShellTest::AddNativeCallback(std::string name,

ShellTestPlatformView::ShellTestPlatformView(PlatformView::Delegate& delegate,
TaskRunners task_runners)
: PlatformView(delegate, std::move(task_runners)) {}
: PlatformView(delegate, std::move(task_runners)),
gl_surface_(SkISize::Make(800, 600)) {}

ShellTestPlatformView::~ShellTestPlatformView() = default;

Expand Down
6 changes: 6 additions & 0 deletions shell/platform/embedder/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,14 @@ test_fixtures("fixtures") {
dart_main = "fixtures/main.dart"
fixtures = [
"fixtures/compositor.png",
"fixtures/gradient.png",
"fixtures/gradient_xform.png",
"fixtures/compositor_software.png",
"fixtures/compositor_with_platform_layer_on_bottom.png",
"fixtures/compositor_with_root_layer_only.png",
"fixtures/compositor_root_surface_xformation.png",
"fixtures/scene_without_custom_compositor.png",
"fixtures/scene_without_custom_compositor_with_xform.png",
]
}

Expand Down Expand Up @@ -119,6 +124,7 @@ if (current_toolchain == host_toolchain) {
"$flutter_root/runtime",
"$flutter_root/testing:dart",
"$flutter_root/testing:opengl",
"$flutter_root/testing:skia",
"//third_party/skia",
"//third_party/tonic",
]
Expand Down
33 changes: 20 additions & 13 deletions shell/platform/embedder/embedder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ InferOpenGLPlatformViewCreationCallback(
transformation.pers2 //
);
};

// If there is an external view embedder, ask it to apply the surface
// transformation to its surfaces as well.
if (external_view_embedder) {
external_view_embedder->SetSurfaceTransformationCallback(
gl_surface_transformation_callback);
}
}

flutter::GPUSurfaceGLDelegate::GLProcResolver gl_proc_resolver = nullptr;
Expand Down Expand Up @@ -296,13 +303,13 @@ static sk_sp<SkSurface> MakeSkSurfaceFromBackingStore(
SkSurfaceProps::InitType::kLegacyFontHost_InitType);

auto surface = SkSurface::MakeFromBackendTexture(
context, // context
backend_texture, // back-end texture
kTopLeft_GrSurfaceOrigin, // surface origin
1, // sample count
kN32_SkColorType, // color type
SkColorSpace::MakeSRGB(), // color space
&surface_properties, // surface properties
context, // context
backend_texture, // back-end texture
kBottomLeft_GrSurfaceOrigin, // surface origin
1, // sample count
kN32_SkColorType, // color type
SkColorSpace::MakeSRGB(), // color space
&surface_properties, // surface properties
static_cast<SkSurface::TextureReleaseProc>(
texture->destruction_callback), // release proc
texture->user_data // release context
Expand Down Expand Up @@ -337,12 +344,12 @@ static sk_sp<SkSurface> MakeSkSurfaceFromBackingStore(
SkSurfaceProps::InitType::kLegacyFontHost_InitType);

auto surface = SkSurface::MakeFromBackendRenderTarget(
context, // context
backend_render_target, // backend render target
kTopLeft_GrSurfaceOrigin, // surface origin
kN32_SkColorType, // color type
SkColorSpace::MakeSRGB(), // color space
&surface_properties, // surface properties
context, // context
backend_render_target, // backend render target
kBottomLeft_GrSurfaceOrigin, // surface origin
kN32_SkColorType, // color type
SkColorSpace::MakeSRGB(), // color space
&surface_properties, // surface properties
static_cast<SkSurface::RenderTargetReleaseProc>(
framebuffer->destruction_callback), // release proc
framebuffer->user_data // release context
Expand Down
8 changes: 8 additions & 0 deletions shell/platform/embedder/embedder.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,14 @@ typedef struct {
bool fbo_reset_after_present;
/// The transformation to apply to the render target before any rendering
/// operations. This callback is optional.
/// @attention When using a custom compositor, the layer offset and sizes
/// will be affected by this transformation. It will be
/// embedder responsibility to render contents at the
/// transformed offset and size. This is useful for embedders
/// that want to render transformed contents directly into
/// hardware overlay planes without having to apply extra
/// transformations to layer contents (which may necessitate
/// an expensive off-screen render pass).
TransformationCallback surface_transformation;
ProcResolver gl_proc_resolver;
/// When the embedder specifies that a texture has a frame available, the
Expand Down

0 comments on commit 1c7300e

Please sign in to comment.