Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
282941c
Create GLFBOInfo.
betrevisan Jul 30, 2022
8f16a16
Update FlutterPresentInfo with frame and buffer damage
betrevisan Jul 30, 2022
a69cc1c
Update GLContextFBO prototype to return a GLFBOInfo.
betrevisan Jul 30, 2022
39b8b9b
Update affected functions by updates to GLPresentInfo
betrevisan Jul 30, 2022
9fac984
Update the behavior of GL Skia to account for dirty region management.
betrevisan Jul 30, 2022
1cfe791
Updated affected functions by the changes to the return value of GLCo…
betrevisan Jul 30, 2022
7ef5882
Create FlutterDamage.
betrevisan Jul 30, 2022
4e606c9
Update FlutterPresentInfo fields.
betrevisan Jul 30, 2022
350e7c8
Add new callback fbo_with_damage_callback.
betrevisan Jul 30, 2022
1634b7e
Update dispatch table.
betrevisan Jul 30, 2022
cb0d8e8
Add check to make sure gl_fbo_with_damage_callback was passed.
betrevisan Jul 30, 2022
ea531b5
Update GLContextPresent and GLContextFBO.
betrevisan Jul 30, 2022
516cf89
Update open gl default renderer config for tests.
betrevisan Jul 30, 2022
6482807
Add GetRendererConfig function.
betrevisan Jul 30, 2022
57d1d29
Update GLPresent used in tests.
betrevisan Jul 30, 2022
90e1da6
Add fbo_with_damage_callback to tests.
betrevisan Jul 30, 2022
2859caa
Add unittests to check valid fbo_with_damage callback.
betrevisan Jul 30, 2022
6c457dd
Add unittests for partial repaint.
betrevisan Jul 30, 2022
bba34a1
Add unittest to make sure fbo with damage receives the correct inform…
betrevisan Jul 30, 2022
bbf0a50
Add log message if the user did not define an fbo_with_damage callback.
betrevisan Jul 30, 2022
ee6eb8b
Add auxiliar functions.
betrevisan Jul 30, 2022
5e2957f
Update behavior of present callback within the embedder.
betrevisan Jul 30, 2022
c638eec
Update behavior of fbo with damage callback within the embedder.
betrevisan Jul 30, 2022
9672853
Formatting.
betrevisan Jul 30, 2022
18ad3e9
Update the fbo_with_damage_callback.
betrevisan Aug 1, 2022
7575433
Documenting.
betrevisan Aug 1, 2022
9a01cb1
Update auxiliary functions as static functions.
betrevisan Aug 1, 2022
37e74e1
Force full repaint when the user tries to do partial repaint with mul…
betrevisan Aug 1, 2022
27b1ce8
Update construction of information passed to the present callback.
betrevisan Aug 1, 2022
02ad377
Fix static function warning.
betrevisan Aug 1, 2022
c18e347
Fix static function error.
betrevisan Aug 1, 2022
582791d
Rename fbo_with_damage_callback to populate_existing_damage_callback.
betrevisan Aug 1, 2022
6a12771
Force full repaint when no existing damage rectangle was given
betrevisan Aug 4, 2022
55628e6
update the GPUMTLTexture struct.
betrevisan Aug 5, 2022
a374004
Update the behavior of the present and get texture callbacks.
betrevisan Aug 5, 2022
35b2356
Update metal texture struct.:
betrevisan Aug 5, 2022
0b1cae9
Formatting.
betrevisan Aug 5, 2022
ec3533c
Update metal gpu to account for drm.
betrevisan Aug 5, 2022
2ffe8af
Documenting.
betrevisan Aug 5, 2022
e9d943b
Fix gpu metal bug.
betrevisan Aug 5, 2022
09c2990
Formatting.
betrevisan Aug 5, 2022
c9e61ca
Merge branch 'main' into drm-embedder-metal
betrevisan Aug 19, 2022
468d9c3
Update gpu_surface_gl_skia.h
betrevisan Aug 19, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions shell/gpu/gpu_surface_metal_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <stdint.h>

#include "flutter/fml/macros.h"
#include "third_party/skia/include/core/SkRect.h"
#include "third_party/skia/include/core/SkSize.h"
#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/include/gpu/mtl/GrMtlTypes.h"
Expand All @@ -29,6 +30,9 @@ typedef const void* GPUMTLTextureHandle;
struct GPUMTLTextureInfo {
int64_t texture_id;
GPUMTLTextureHandle texture;
bool partial_repaint_enabled;
SkIRect texture_damage;
SkIRect frame_damage;
};

enum class MTLRenderTargetType { kMTLTexture, kCAMetalLayer };
Expand Down
19 changes: 16 additions & 3 deletions shell/gpu/gpu_surface_metal_skia.mm
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@
return nullptr;
}

auto submit_callback = [texture = texture, delegate = delegate_](
const SurfaceFrame& surface_frame, SkCanvas* canvas) -> bool {
auto submit_callback = [texture, delegate = delegate_](const SurfaceFrame& surface_frame,
SkCanvas* canvas) -> bool {
TRACE_EVENT0("flutter", "GPUSurfaceMetal::PresentTexture");
if (canvas == nullptr) {
FML_DLOG(ERROR) << "Canvas not available.";
Expand All @@ -222,12 +222,25 @@
canvas->flush();
}

return delegate->PresentTexture(texture);
GPUMTLTextureInfo present_texture = {
.texture_id = texture.texture_id,
.texture = texture.texture,
.partial_repaint_enabled = texture.partial_repaint_enabled,
.texture_damage = *surface_frame.submit_info().buffer_damage,
.frame_damage = *surface_frame.submit_info().frame_damage,
};

return delegate->PresentTexture(present_texture);
};

SurfaceFrame::FramebufferInfo framebuffer_info;
framebuffer_info.supports_readback = true;

if (texture.partial_repaint_enabled) {
framebuffer_info.supports_partial_repaint = true;
framebuffer_info.existing_damage = texture.texture_damage;
}

return std::make_unique<SurfaceFrame>(std::move(surface), std::move(framebuffer_info),
submit_callback);
}
Expand Down
41 changes: 40 additions & 1 deletion shell/platform/embedder/embedder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ static void* DefaultGLProcResolver(const char* name) {
}
#endif // FML_OS_LINUX || FML_OS_WIN

#ifdef SHELL_ENABLE_GL
#if defined(SHELL_ENABLE_GL) || defined(SHELL_ENABLE_METAL)
// Auxiliary function used to translate rectangles of type SkIRect to
// FlutterRect.
static FlutterRect SkIRectToFlutterRect(const SkIRect sk_rect) {
Expand Down Expand Up @@ -465,10 +465,31 @@ InferMetalPlatformViewCreationCallback(
std::function<bool(flutter::GPUMTLTextureInfo texture)> metal_present =
[ptr = config->metal.present_drawable_callback,
user_data](flutter::GPUMTLTextureInfo texture) {
const size_t num_rects = 1;

std::array<FlutterRect, num_rects> texture_damage_rect = {
SkIRectToFlutterRect(texture.texture_damage)};
std::array<FlutterRect, num_rects> frame_damage_rect = {
SkIRectToFlutterRect(texture.frame_damage)};

FlutterDamage texture_damage{
.struct_size = sizeof(FlutterDamage),
.num_rects = texture_damage_rect.size(),
.damage = texture_damage_rect.data(),
};

FlutterDamage frame_damage{
.struct_size = sizeof(FlutterDamage),
.num_rects = frame_damage_rect.size(),
.damage = frame_damage_rect.data(),
};

FlutterMetalTexture embedder_texture;
embedder_texture.struct_size = sizeof(FlutterMetalTexture);
embedder_texture.texture = texture.texture;
embedder_texture.texture_id = texture.texture_id;
embedder_texture.texture_damage = texture_damage;
embedder_texture.frame_damage = frame_damage;
return ptr(user_data, &embedder_texture);
};
auto metal_get_texture =
Expand All @@ -483,6 +504,24 @@ InferMetalPlatformViewCreationCallback(
FlutterMetalTexture metal_texture = ptr(user_data, &frame_info);
texture_info.texture_id = metal_texture.texture_id;
texture_info.texture = metal_texture.texture;
texture_info.partial_repaint_enabled = true;

// Verify that at least one damage rectangle was provided.
if (metal_texture.texture_damage.num_rects <= 0 ||
metal_texture.texture_damage.damage == nullptr) {
FML_LOG(INFO) << "No damage was provided. Forcing full repaint";
texture_info.partial_repaint_enabled = false;
} else if (metal_texture.texture_damage.num_rects > 1) {
// Log message notifying users that multi-damage is not yet available in
// case they try to make use of it.
FML_LOG(INFO) << "Damage with multiple rectangles not yet supported. "
"Repainting the whole frame.";
texture_info.partial_repaint_enabled = false;
} else {
texture_info.texture_damage =
FlutterRectToSkIRect(*(metal_texture.texture_damage.damage));
}

return texture_info;
};

Expand Down
17 changes: 15 additions & 2 deletions shell/platform/embedder/embedder.h
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,13 @@ typedef struct {
/// The callback invoked by the engine when it no longer needs this backing
/// store.
VoidCallback destruction_callback;
// Upon request, it represents the existing damage to the present texture. At
// present time, it represents the regions that need to be rendered.
FlutterDamage texture_damage;
// This field is used at present time to represent the regions that have
// changed between this frame and the previous one. This is important so that
// the user can keep track of texture's existing damage.
FlutterDamage frame_damage;
} FlutterMetalTexture;

/// Callback for when a metal texture is requested.
Expand All @@ -653,10 +660,16 @@ typedef struct {
/// Alias for id<MTLCommandQueue>.
FlutterMetalCommandQueueHandle present_command_queue;
/// The callback that gets invoked when the engine requests the embedder for a
/// texture to render to.
/// texture to render to. If using partial repaint, the user must define this
/// callback to fill in the value of texture_damage of the texture being
/// returned with the texture's existing damage. If no texture_damage is given
/// the Embedder will do a full repaint.
FlutterMetalTextureCallback get_next_drawable_callback;
/// The callback presented to the embedder to present a fully populated metal
/// texture to the user.
/// texture to the user. If using partial repaint, the user must use the
/// texture and frame damages passed through the given FlutterMetalTexture to
/// render only the damage areas of the screen and to keep track of a damage
/// history.
FlutterMetalPresentCallback present_drawable_callback;
/// When the embedder specifies that a texture has a frame available, the
/// engine will call this method (on an internal engine managed thread) so
Expand Down