Skip to content

Commit

Permalink
Use the frame size to cull (flutter#35973)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnfield authored Sep 7, 2022
1 parent 370885a commit fd6410a
Show file tree
Hide file tree
Showing 16 changed files with 103 additions and 54 deletions.
6 changes: 4 additions & 2 deletions flow/surface_frame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include <limits>

#include "flutter/flow/layers/layer.h"
#include "flutter/fml/logging.h"
#include "flutter/fml/trace_event.h"
#include "third_party/skia/include/utils/SkNWayCanvas.h"
Expand All @@ -16,6 +15,7 @@ namespace flutter {
SurfaceFrame::SurfaceFrame(sk_sp<SkSurface> surface,
FramebufferInfo framebuffer_info,
const SubmitCallback& submit_callback,
SkISize frame_size,
std::unique_ptr<GLContextResult> context_result,
bool display_list_fallback)
: surface_(surface),
Expand All @@ -26,7 +26,9 @@ SurfaceFrame::SurfaceFrame(sk_sp<SkSurface> surface,
if (surface_) {
canvas_ = surface_->getCanvas();
} else if (display_list_fallback) {
dl_recorder_ = sk_make_sp<DisplayListCanvasRecorder>(kGiantRect);
FML_DCHECK(!frame_size.isEmpty());
dl_recorder_ =
sk_make_sp<DisplayListCanvasRecorder>(SkRect::Make(frame_size));
canvas_ = dl_recorder_.get();
}
}
Expand Down
1 change: 1 addition & 0 deletions flow/surface_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class SurfaceFrame {
SurfaceFrame(sk_sp<SkSurface> surface,
FramebufferInfo framebuffer_info,
const SubmitCallback& submit_callback,
SkISize frame_size,
std::unique_ptr<GLContextResult> context_result = nullptr,
bool display_list_fallback = false);

Expand Down
7 changes: 5 additions & 2 deletions flow/surface_frame_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ TEST(FlowTest, SurfaceFrameDoesNotSubmitInDtor) {
SurfaceFrame::FramebufferInfo framebuffer_info;
auto surface_frame = std::make_unique<SurfaceFrame>(
/*surface=*/nullptr, framebuffer_info,
/*submit_callback=*/[](const SurfaceFrame&, SkCanvas*) {
/*submit_callback=*/
[](const SurfaceFrame&, SkCanvas*) {
EXPECT_FALSE(true);
return true;
});
},
SkISize::Make(800, 600));
surface_frame.reset();
}

Expand All @@ -25,6 +27,7 @@ TEST(FlowTest, SurfaceFrameDoesNotHaveEmptyCanvas) {
SurfaceFrame frame(
/*surface=*/nullptr, framebuffer_info,
/*submit_callback=*/[](const SurfaceFrame&, SkCanvas*) { return true; },
/*frame_size=*/SkISize::Make(800, 600),
/*context_result=*/nullptr, /*display_list_fallback=*/true);

EXPECT_FALSE(frame.SkiaCanvas()->getLocalClipBounds().isEmpty());
Expand Down
45 changes: 29 additions & 16 deletions shell/common/rasterizer_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ TEST(RasterizerTest,

auto surface_frame = std::make_unique<SurfaceFrame>(
/*surface=*/nullptr, framebuffer_info,
/*submit_callback=*/[](const SurfaceFrame&, SkCanvas*) { return true; });
/*submit_callback=*/[](const SurfaceFrame&, SkCanvas*) { return true; },
/*frame_size=*/SkISize::Make(800, 600));
EXPECT_CALL(*surface, AllowsDrawingWhenGpuDisabled()).WillOnce(Return(true));
EXPECT_CALL(*surface, AcquireFrame(SkISize()))
.WillOnce(Return(ByMove(std::move(surface_frame))));
Expand Down Expand Up @@ -226,7 +227,8 @@ TEST(
framebuffer_info.supports_readback = true;
auto surface_frame = std::make_unique<SurfaceFrame>(
/*surface=*/nullptr, framebuffer_info,
/*submit_callback=*/[](const SurfaceFrame&, SkCanvas*) { return true; });
/*submit_callback=*/[](const SurfaceFrame&, SkCanvas*) { return true; },
/*frame_size=*/SkISize::Make(800, 600));
EXPECT_CALL(*surface, AllowsDrawingWhenGpuDisabled()).WillOnce(Return(true));
EXPECT_CALL(*surface, AcquireFrame(SkISize()))
.WillOnce(Return(ByMove(std::move(surface_frame))));
Expand Down Expand Up @@ -295,7 +297,8 @@ TEST(

auto surface_frame = std::make_unique<SurfaceFrame>(
/*surface=*/nullptr, framebuffer_info,
/*submit_callback=*/[](const SurfaceFrame&, SkCanvas*) { return true; });
/*submit_callback=*/[](const SurfaceFrame&, SkCanvas*) { return true; },
/*frame_size=*/SkISize::Make(800, 600));
EXPECT_CALL(*surface, AllowsDrawingWhenGpuDisabled()).WillOnce(Return(true));
EXPECT_CALL(*surface, AcquireFrame(SkISize()))
.WillOnce(Return(ByMove(std::move(surface_frame))));
Expand Down Expand Up @@ -361,10 +364,12 @@ TEST(RasterizerTest,

auto surface_frame1 = std::make_unique<SurfaceFrame>(
/*surface=*/nullptr, framebuffer_info,
/*submit_callback=*/[](const SurfaceFrame&, SkCanvas*) { return true; });
/*submit_callback=*/[](const SurfaceFrame&, SkCanvas*) { return true; },
/*frame_size=*/SkISize::Make(800, 600));
auto surface_frame2 = std::make_unique<SurfaceFrame>(
/*surface=*/nullptr, framebuffer_info,
/*submit_callback=*/[](const SurfaceFrame&, SkCanvas*) { return true; });
/*submit_callback=*/[](const SurfaceFrame&, SkCanvas*) { return true; },
/*frame_size=*/SkISize::Make(800, 600));
EXPECT_CALL(*surface, AllowsDrawingWhenGpuDisabled())
.WillRepeatedly(Return(true));
// Prepare two frames for Draw() and DrawLastLayerTree().
Expand Down Expand Up @@ -580,7 +585,8 @@ TEST(RasterizerTest,
framebuffer_info.supports_readback = true;
auto surface_frame = std::make_unique<SurfaceFrame>(
/*surface=*/nullptr, /*framebuffer_info=*/framebuffer_info,
/*submit_callback=*/[](const SurfaceFrame&, SkCanvas*) { return true; });
/*submit_callback=*/[](const SurfaceFrame&, SkCanvas*) { return true; },
/*frame_size=*/SkISize::Make(800, 600));
EXPECT_CALL(*surface, AllowsDrawingWhenGpuDisabled()).WillOnce(Return(true));
ON_CALL(delegate, GetIsGpuDisabledSyncSwitch())
.WillByDefault(Return(is_gpu_disabled_sync_switch));
Expand Down Expand Up @@ -636,7 +642,8 @@ TEST(

auto surface_frame = std::make_unique<SurfaceFrame>(
/*surface=*/nullptr, /*framebuffer_info=*/framebuffer_info,
/*submit_callback=*/[](const SurfaceFrame&, SkCanvas*) { return true; });
/*submit_callback=*/[](const SurfaceFrame&, SkCanvas*) { return true; },
/*frame_size=*/SkISize::Make(800, 600));
EXPECT_CALL(*surface, AllowsDrawingWhenGpuDisabled()).WillOnce(Return(true));
ON_CALL(delegate, GetIsGpuDisabledSyncSwitch())
.WillByDefault(Return(is_gpu_disabled_sync_switch));
Expand Down Expand Up @@ -693,7 +700,8 @@ TEST(

auto surface_frame = std::make_unique<SurfaceFrame>(
/*surface=*/nullptr, /*framebuffer_info=*/framebuffer_info,
/*submit_callback=*/[](const SurfaceFrame&, SkCanvas*) { return true; });
/*submit_callback=*/[](const SurfaceFrame&, SkCanvas*) { return true; },
/*frame_size=*/SkISize::Make(800, 600));
EXPECT_CALL(*surface, AllowsDrawingWhenGpuDisabled()).WillOnce(Return(false));
EXPECT_CALL(delegate, GetIsGpuDisabledSyncSwitch())
.WillOnce(Return(is_gpu_disabled_sync_switch));
Expand Down Expand Up @@ -749,7 +757,8 @@ TEST(

auto surface_frame = std::make_unique<SurfaceFrame>(
/*surface=*/nullptr, /*framebuffer_info=*/framebuffer_info,
/*submit_callback=*/[](const SurfaceFrame&, SkCanvas*) { return true; });
/*submit_callback=*/[](const SurfaceFrame&, SkCanvas*) { return true; },
/*frame_size=*/SkISize::Make(800, 600));
EXPECT_CALL(*surface, AllowsDrawingWhenGpuDisabled()).WillOnce(Return(false));
EXPECT_CALL(delegate, GetIsGpuDisabledSyncSwitch())
.WillOnce(Return(is_gpu_disabled_sync_switch));
Expand Down Expand Up @@ -809,9 +818,9 @@ TEST(RasterizerTest,
framebuffer_info.supports_readback = true;
return std::make_unique<SurfaceFrame>(
/*surface=*/nullptr, framebuffer_info,
/*submit_callback=*/[](const SurfaceFrame& frame, SkCanvas*) {
return true;
});
/*submit_callback=*/
[](const SurfaceFrame& frame, SkCanvas*) { return true; },
/*frame_size=*/SkISize::Make(800, 600));
}));
ON_CALL(*surface, MakeRenderContextCurrent())
.WillByDefault(::testing::Invoke(
Expand Down Expand Up @@ -987,15 +996,17 @@ TEST(RasterizerTest, presentationTimeSetWhenVsyncTargetInFuture) {
framebuffer_info.supports_readback = true;
return std::make_unique<SurfaceFrame>(
/*surface=*/nullptr, framebuffer_info,
/*submit_callback=*/[&](const SurfaceFrame& frame, SkCanvas*) {
/*submit_callback=*/
[&](const SurfaceFrame& frame, SkCanvas*) {
const auto pres_time = *frame.submit_info().presentation_time;
const auto diff = pres_time - first_timestamp;
int num_frames_submitted = frames_submitted++;
EXPECT_EQ(diff.ToMilliseconds(),
num_frames_submitted * millis_16.ToMilliseconds());
submit_latch.CountDown();
return true;
});
},
/*frame_size=*/SkISize::Make(800, 600));
}));

ON_CALL(*surface, MakeRenderContextCurrent())
Expand Down Expand Up @@ -1066,13 +1077,15 @@ TEST(RasterizerTest, presentationTimeNotSetWhenVsyncTargetInPast) {
framebuffer_info.supports_readback = true;
return std::make_unique<SurfaceFrame>(
/*surface=*/nullptr, framebuffer_info,
/*submit_callback=*/[&](const SurfaceFrame& frame, SkCanvas*) {
/*submit_callback=*/
[&](const SurfaceFrame& frame, SkCanvas*) {
const std::optional<fml::TimePoint> pres_time =
frame.submit_info().presentation_time;
EXPECT_EQ(pres_time, std::nullopt);
submit_latch.CountDown();
return true;
});
},
/*frame_size=*/SkISize::Make(800, 600));
}));

ON_CALL(*surface, MakeRenderContextCurrent())
Expand Down
3 changes: 2 additions & 1 deletion shell/common/shell_test_platform_view_vulkan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ ShellTestPlatformViewVulkan::OffScreenSurface::AcquireFrame(
framebuffer_info.supports_readback = true;

return std::make_unique<SurfaceFrame>(
std::move(surface), std::move(framebuffer_info), std::move(callback));
std::move(surface), std::move(framebuffer_info), std::move(callback),
/*frame_size=*/SkISize::Make(800, 600));
}

GrDirectContext* ShellTestPlatformViewVulkan::OffScreenSurface::GetContext() {
Expand Down
1 change: 1 addition & 0 deletions shell/gpu/gpu_surface_gl_impeller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceGLImpeller::AcquireFrame(
nullptr, // surface
SurfaceFrame::FramebufferInfo{}, // framebuffer info
submit_callback, // submit callback
size, // frame size
std::move(context_switch), // context result
true // display list fallback
);
Expand Down
5 changes: 3 additions & 2 deletions shell/gpu/gpu_surface_gl_skia.cc
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceGLSkia::AcquireFrame(
nullptr, std::move(framebuffer_info),
[](const SurfaceFrame& surface_frame, SkCanvas* canvas) {
return true;
});
},
size);
}

const auto root_surface_transformation = GetRootTransformation();
Expand All @@ -253,7 +254,7 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceGLSkia::AcquireFrame(
framebuffer_info.existing_damage = existing_damage_;
}
return std::make_unique<SurfaceFrame>(surface, std::move(framebuffer_info),
submit_callback,
submit_callback, size,
std::move(context_switch));
}

Expand Down
1 change: 1 addition & 0 deletions shell/gpu/gpu_surface_metal_impeller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
return std::make_unique<SurfaceFrame>(nullptr, // surface
SurfaceFrame::FramebufferInfo{}, // framebuffer info
submit_callback, // submit callback
frame_info, // frame size
nullptr, // context result
true // display list fallback
);
Expand Down
7 changes: 4 additions & 3 deletions shell/gpu/gpu_surface_metal_skia.mm
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
if (!render_to_surface_) {
return std::make_unique<SurfaceFrame>(
nullptr, SurfaceFrame::FramebufferInfo(),
[](const SurfaceFrame& surface_frame, SkCanvas* canvas) { return true; });
[](const SurfaceFrame& surface_frame, SkCanvas* canvas) { return true; }, frame_size);
}

PrecompileKnownSkSLsIfNecessary();
Expand Down Expand Up @@ -187,7 +187,8 @@
framebuffer_info.supports_partial_repaint = true;
}

return std::make_unique<SurfaceFrame>(std::move(surface), framebuffer_info, submit_callback);
return std::make_unique<SurfaceFrame>(std::move(surface), framebuffer_info, submit_callback,
frame_info);
}

std::unique_ptr<SurfaceFrame> GPUSurfaceMetalSkia::AcquireFrameFromMTLTexture(
Expand Down Expand Up @@ -229,7 +230,7 @@
framebuffer_info.supports_readback = true;

return std::make_unique<SurfaceFrame>(std::move(surface), std::move(framebuffer_info),
submit_callback);
submit_callback, frame_info);
}

// |Surface|
Expand Down
7 changes: 4 additions & 3 deletions shell/gpu/gpu_surface_software.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceSoftware::AcquireFrame(
nullptr, std::move(framebuffer_info),
[](const SurfaceFrame& surface_frame, SkCanvas* canvas) {
return true;
});
},
logical_size);
}

if (!IsValid()) {
Expand Down Expand Up @@ -73,8 +74,8 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceSoftware::AcquireFrame(
return self->delegate_->PresentBackingStore(surface_frame.SkiaSurface());
};

return std::make_unique<SurfaceFrame>(backing_store,
std::move(framebuffer_info), on_submit);
return std::make_unique<SurfaceFrame>(
backing_store, std::move(framebuffer_info), on_submit, logical_size);
}

// |Surface|
Expand Down
8 changes: 5 additions & 3 deletions shell/gpu/gpu_surface_vulkan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceVulkan::AcquireFrame(
nullptr, SurfaceFrame::FramebufferInfo(),
[](const SurfaceFrame& surface_frame, SkCanvas* canvas) {
return true;
});
},
frame_size);
}

FlutterVulkanImage image = delegate_->AcquireImage(frame_size);
Expand Down Expand Up @@ -77,8 +78,9 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceVulkan::AcquireFrame(

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

return std::make_unique<SurfaceFrame>(
std::move(surface), std::move(framebuffer_info), std::move(callback));
return std::make_unique<SurfaceFrame>(std::move(surface),
std::move(framebuffer_info),
std::move(callback), frame_size);
}

SkMatrix GPUSurfaceVulkan::GetRootTransformation() const {
Expand Down
Loading

0 comments on commit fd6410a

Please sign in to comment.