Skip to content

Commit

Permalink
Fix damage calculation in embedder gl when populate_existing_damage i…
Browse files Browse the repository at this point in the history
…s not provided
  • Loading branch information
ajihyf committed Sep 13, 2023
1 parent c97ae75 commit 92bb9ae
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 38 deletions.
2 changes: 0 additions & 2 deletions shell/gpu/gpu_surface_gl_delegate.h
Expand Up @@ -27,8 +27,6 @@ struct GLFrameInfo {
struct GLFBOInfo {
// The frame buffer's ID.
uint32_t fbo_id;
// This boolean flags whether the returned FBO supports partial repaint.
const bool partial_repaint_enabled;
// The frame buffer's existing damage (i.e. damage since it was last used).
const std::optional<SkIRect> existing_damage;
};
Expand Down
1 change: 0 additions & 1 deletion shell/platform/android/android_surface_gl_skia.cc
Expand Up @@ -166,7 +166,6 @@ GLFBOInfo AndroidSurfaceGLSkia::GLContextFBO(GLFrameInfo frame_info) const {
// The default window bound framebuffer on Android.
return GLFBOInfo{
.fbo_id = 0,
.partial_repaint_enabled = onscreen_surface_->SupportsPartialRepaint(),
.existing_damage = onscreen_surface_->InitialDamage(),
};
}
Expand Down
11 changes: 2 additions & 9 deletions shell/platform/embedder/embedder.cc
Expand Up @@ -362,38 +362,31 @@ InferOpenGLPlatformViewCreationCallback(
if (!populate_existing_damage) {
return flutter::GLFBOInfo{
.fbo_id = static_cast<uint32_t>(id),
.partial_repaint_enabled = false,
.existing_damage = SkIRect::MakeEmpty(),
.existing_damage = std::nullopt,
};
}

// Given the FBO's ID, get its existing damage.
FlutterDamage existing_damage;
populate_existing_damage(user_data, id, &existing_damage);

bool partial_repaint_enabled = true;
SkIRect existing_damage_rect;
std::optional<SkIRect> existing_damage_rect = std::nullopt;

// Verify that at least one damage rectangle was provided.
if (existing_damage.num_rects <= 0 || existing_damage.damage == nullptr) {
FML_LOG(INFO) << "No damage was provided. Forcing full repaint.";
existing_damage_rect = SkIRect::MakeEmpty();
partial_repaint_enabled = false;
} else if (existing_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.";
existing_damage_rect = SkIRect::MakeEmpty();
partial_repaint_enabled = false;
} else {
existing_damage_rect = FlutterRectToSkIRect(*(existing_damage.damage));
}

// Pass the information about this FBO to the rendering backend.
return flutter::GLFBOInfo{
.fbo_id = static_cast<uint32_t>(id),
.partial_repaint_enabled = partial_repaint_enabled,
.existing_damage = existing_damage_rect,
};
};
Expand Down
22 changes: 22 additions & 0 deletions shell/platform/embedder/fixtures/main.dart
Expand Up @@ -1298,3 +1298,25 @@ void channel_listener_response() async {
});
signalNativeTest();
}

@pragma('vm:entry-point')
void render_gradient_retained() {
OffsetEngineLayer? offsetLayer; // Retain the offset layer.
PlatformDispatcher.instance.onBeginFrame = (Duration duration) {
Size size = Size(800.0, 600.0);

SceneBuilder builder = SceneBuilder();

offsetLayer = builder.pushOffset(0.0, 0.0, oldLayer: offsetLayer);

// display_list_layer will comparing the display_list
// no need to retain the picture
builder.addPicture(
Offset(0.0, 0.0), CreateGradientBox(size)); // gradient - flutter

builder.pop();

PlatformDispatcher.instance.views.first.render(builder.build());
};
PlatformDispatcher.instance.scheduleFrame();
}

0 comments on commit 92bb9ae

Please sign in to comment.