Skip to content

Commit ec8ee91

Browse files
flarreidbaker
authored andcommitted
Migrate surface frame shell code to DisplayList/Impeller geometry classes (flutter#173086)
Converting a large variety of classes involved in tracking surfaces, frames, surface damage, etc. to using the DisplayList/Impeller geometry classes. Addresses a bullet item in flutter#161456 --------- Co-authored-by: Reid Baker <[email protected]>
1 parent 963915c commit ec8ee91

File tree

159 files changed

+881
-830
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

159 files changed

+881
-830
lines changed

engine/src/flutter/display_list/skia/dl_sk_conversions_unittests.cc

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,70 @@ TEST(DisplayListImageFilter, LocalImageSkiaNull) {
2929
ASSERT_EQ(ToSk(dl_local_matrix_filter), nullptr);
3030
}
3131

32+
// This test exists just to confirm and demonstrate how to convert existing
33+
// SkMatrix construction code into the same operations using the replacement
34+
// DlMatrix/impeller::Matrix objects.
35+
//
36+
// To be clear, it verifies:
37+
// SkMatrix.pre<Op>(data) is the same as DlMatrix * DlMatrix::Make<Op>(data).
38+
// SkMatrix1.preConcat(SkMatrix2) is the same as DlMatrix1 * DlMatrix2.
39+
TEST(DisplayListSkConversions, OpOrderPreMethodsVsMatrixMultiply) {
40+
// If you have code like this...
41+
const SkMatrix sk_matrix =
42+
SkMatrix().preTranslate(0, 800).preRotate(-90, 0, 0);
43+
44+
// Convert it to math like this (same order as the pre<Op>() calls)...
45+
const DlMatrix dl_matrix = DlMatrix::MakeTranslation({0, 800}) *
46+
DlMatrix::MakeRotationZ(DlDegrees(-90));
47+
SkPoint sk_result = sk_matrix.mapPoint({10, 10});
48+
DlPoint dl_result = dl_matrix * DlPoint(10, 10);
49+
EXPECT_FLOAT_EQ(sk_result.fX, dl_result.x);
50+
EXPECT_FLOAT_EQ(sk_result.fY, dl_result.y);
51+
52+
// Not like this...
53+
const DlMatrix dl_matrix_2 = DlMatrix::MakeRotationZ(DlDegrees(-90)) *
54+
DlMatrix::MakeTranslation({0, 800});
55+
DlPoint dl_result_2 = dl_matrix_2 * DlPoint(10, 10);
56+
EXPECT_FALSE(impeller::ScalarNearlyEqual(sk_result.fX, dl_result_2.x));
57+
EXPECT_FALSE(impeller::ScalarNearlyEqual(sk_result.fY, dl_result_2.y));
58+
59+
// -------------------------------------------------------------------
60+
61+
// And if you have this...
62+
SkMatrix sk_matrix_2;
63+
sk_matrix_2.preConcat(SkMatrix::Translate(0, 800));
64+
sk_matrix_2.preConcat(SkMatrix::RotateDeg(-90));
65+
66+
// It's really the same as the above case, btw...
67+
SkPoint sk_result_2 = sk_matrix_2.mapPoint({10, 10});
68+
EXPECT_FLOAT_EQ(sk_result.fX, sk_result_2.fX);
69+
EXPECT_FLOAT_EQ(sk_result.fY, sk_result_2.fY);
70+
71+
// Convert it to math like this (same order as the pre<Op>() calls)...
72+
DlMatrix dl_matrix_3;
73+
dl_matrix_3 = dl_matrix_3 * DlMatrix::MakeTranslation({0, 800});
74+
dl_matrix_3 = dl_matrix_3 * DlMatrix::MakeRotationZ(DlDegrees(-90));
75+
DlPoint dl_result_3 = dl_matrix_3 * DlPoint(10, 10);
76+
EXPECT_FLOAT_EQ(sk_result_2.fX, dl_result_3.x);
77+
EXPECT_FLOAT_EQ(sk_result_2.fY, dl_result_3.y);
78+
79+
// Which is also the same result as the first case above...
80+
EXPECT_FLOAT_EQ(dl_result_3.x, dl_result.x);
81+
EXPECT_FLOAT_EQ(dl_result_3.y, dl_result.y);
82+
83+
// Not like this...
84+
DlMatrix dl_matrix_4;
85+
dl_matrix_4 = dl_matrix_4 * DlMatrix::MakeRotationZ(DlDegrees(-90));
86+
dl_matrix_4 = dl_matrix_4 * DlMatrix::MakeTranslation({0, 800});
87+
DlPoint dl_result_4 = dl_matrix_4 * DlPoint(10, 10);
88+
EXPECT_FALSE(impeller::ScalarNearlyEqual(sk_result_2.fX, dl_result_4.x));
89+
EXPECT_FALSE(impeller::ScalarNearlyEqual(sk_result_2.fY, dl_result_4.y));
90+
91+
// Which is also the same result as the second case above...
92+
EXPECT_FLOAT_EQ(dl_result_4.x, dl_result_2.x);
93+
EXPECT_FLOAT_EQ(dl_result_4.y, dl_result_2.y);
94+
}
95+
3296
TEST(DisplayListSkConversions, ToSkColor) {
3397
// Red
3498
ASSERT_EQ(ToSkColor(DlColor::kRed()), SK_ColorRED);

engine/src/flutter/display_list/testing/dl_test_snippets.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "flutter/display_list/effects/dl_image_filters.h"
1313
#include "flutter/testing/testing.h"
1414

15-
#include "third_party/skia/include/core/SkCanvas.h"
1615
#include "third_party/skia/include/core/SkPath.h"
1716
#include "third_party/skia/include/core/SkRRect.h"
1817
#include "third_party/skia/include/core/SkSurface.h"

engine/src/flutter/display_list/testing/dl_test_surface_gl.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#include "flutter/display_list/testing/dl_test_surface_gl.h"
66

7-
#include "third_party/skia/include/core/SkCanvas.h"
87
#include "third_party/skia/include/core/SkSurface.h"
98
#include "third_party/skia/include/gpu/ganesh/SkSurfaceGanesh.h"
109

@@ -16,7 +15,7 @@ using PixelFormat = DlSurfaceProvider::PixelFormat;
1615
bool DlOpenGLSurfaceProvider::InitializeSurface(size_t width,
1716
size_t height,
1817
PixelFormat format) {
19-
gl_surface_ = std::make_unique<TestGLSurface>(SkISize::Make(width, height));
18+
gl_surface_ = std::make_unique<TestGLSurface>(DlISize(width, height));
2019
gl_surface_->MakeCurrent();
2120

2221
primary_ = MakeOffscreenSurface(width, height, format);

engine/src/flutter/display_list/testing/dl_test_surface_metal.mm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "flutter/impeller/display_list/dl_image_impeller.h"
88
#include "flutter/impeller/typographer/backends/skia/typographer_context_skia.h"
99

10-
#include "third_party/skia/include/core/SkCanvas.h"
1110
#include "third_party/skia/include/core/SkSurface.h"
1211

1312
namespace flutter {
@@ -48,7 +47,7 @@ explicit DlMetalSurfaceInstance(std::unique_ptr<TestMetalSurface> metal_surface)
4847
size_t width,
4948
size_t height,
5049
PixelFormat format) const {
51-
auto surface = TestMetalSurface::Create(*metal_context_, SkISize::Make(width, height));
50+
auto surface = TestMetalSurface::Create(*metal_context_, DlISize(width, height));
5251
surface->GetSurface()->getCanvas()->clear(SK_ColorTRANSPARENT);
5352
return std::make_shared<DlMetalSurfaceInstance>(std::move(surface));
5453
}

engine/src/flutter/display_list/testing/dl_test_surface_provider.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44

55
#include "flutter/display_list/testing/dl_test_surface_provider.h"
66

7-
#include "third_party/skia/include/core/SkCanvas.h"
8-
#include "third_party/skia/include/core/SkData.h"
9-
#include "third_party/skia/include/core/SkImage.h"
10-
#include "third_party/skia/include/core/SkSurface.h"
117
#include "third_party/skia/include/encode/SkPngEncoder.h"
128
#include "third_party/skia/include/gpu/ganesh/GrDirectContext.h"
139

engine/src/flutter/display_list/testing/dl_test_surface_software.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#include "flutter/display_list/testing/dl_test_surface_software.h"
66

7-
#include "third_party/skia/include/core/SkCanvas.h"
87
#include "third_party/skia/include/core/SkSurface.h"
98

109
namespace flutter {

engine/src/flutter/flow/compositor_context.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include <optional>
88
#include <utility>
99
#include "flutter/flow/layers/layer_tree.h"
10-
#include "third_party/skia/include/core/SkCanvas.h"
1110

1211
namespace flutter {
1312

@@ -74,7 +73,7 @@ std::unique_ptr<CompositorContext::ScopedFrame> CompositorContext::AcquireFrame(
7473
GrDirectContext* gr_context,
7574
DlCanvas* canvas,
7675
ExternalViewEmbedder* view_embedder,
77-
const SkMatrix& root_surface_transformation,
76+
const DlMatrix& root_surface_transformation,
7877
bool instrumentation_enabled,
7978
bool surface_supports_readback,
8079
fml::RefPtr<fml::RasterThreadMerger>
@@ -91,7 +90,7 @@ CompositorContext::ScopedFrame::ScopedFrame(
9190
GrDirectContext* gr_context,
9291
DlCanvas* canvas,
9392
ExternalViewEmbedder* view_embedder,
94-
const SkMatrix& root_surface_transformation,
93+
const DlMatrix& root_surface_transformation,
9594
bool instrumentation_enabled,
9695
bool surface_supports_readback,
9796
fml::RefPtr<fml::RasterThreadMerger> raster_thread_merger,

engine/src/flutter/flow/compositor_context.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "flutter/flow/stopwatch.h"
1717
#include "flutter/fml/macros.h"
1818
#include "flutter/fml/raster_thread_merger.h"
19-
#include "third_party/skia/include/core/SkCanvas.h"
2019
#include "third_party/skia/include/gpu/ganesh/GrDirectContext.h"
2120

2221
namespace flutter {
@@ -111,7 +110,7 @@ class CompositorContext {
111110
GrDirectContext* gr_context,
112111
DlCanvas* canvas,
113112
ExternalViewEmbedder* view_embedder,
114-
const SkMatrix& root_surface_transformation,
113+
const DlMatrix& root_surface_transformation,
115114
bool instrumentation_enabled,
116115
bool surface_supports_readback,
117116
fml::RefPtr<fml::RasterThreadMerger> raster_thread_merger,
@@ -125,7 +124,7 @@ class CompositorContext {
125124

126125
CompositorContext& context() const { return context_; }
127126

128-
const SkMatrix& root_surface_transformation() const {
127+
const DlMatrix& root_surface_transformation() const {
129128
return root_surface_transformation_;
130129
}
131130

@@ -154,7 +153,7 @@ class CompositorContext {
154153
DlCanvas* canvas_;
155154
impeller::AiksContext* aiks_context_;
156155
ExternalViewEmbedder* view_embedder_;
157-
const SkMatrix root_surface_transformation_;
156+
const DlMatrix root_surface_transformation_;
158157
const bool instrumentation_enabled_;
159158
const bool surface_supports_readback_;
160159
fml::RefPtr<fml::RasterThreadMerger> raster_thread_merger_;
@@ -172,7 +171,7 @@ class CompositorContext {
172171
GrDirectContext* gr_context,
173172
DlCanvas* canvas,
174173
ExternalViewEmbedder* view_embedder,
175-
const SkMatrix& root_surface_transformation,
174+
const DlMatrix& root_surface_transformation,
176175
bool instrumentation_enabled,
177176
bool surface_supports_readback,
178177
fml::RefPtr<fml::RasterThreadMerger> raster_thread_merger,

engine/src/flutter/flow/layers/layer_tree.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ bool LayerTree::Preroll(CompositorContext::ScopedFrame& frame,
3737

3838
SkColorSpace* color_space = GetColorSpace(frame.canvas());
3939
LayerStateStack state_stack;
40-
state_stack.set_preroll_delegate(
41-
cull_rect, ToDlMatrix(frame.root_surface_transformation()));
40+
state_stack.set_preroll_delegate(cull_rect,
41+
frame.root_surface_transformation());
4242

4343
raster_cache_items_.clear();
4444

engine/src/flutter/flow/layers/layer_tree_unittests.cc

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,14 @@ class LayerTreeTest : public CanvasTest {
2222
LayerTreeTest()
2323
: root_transform_(DlMatrix::MakeTranslation({1.0f, 1.0f})),
2424
builder_(DisplayListBuilder::kMaxCullRect),
25-
scoped_frame_(
26-
compositor_context_.AcquireFrame(nullptr,
27-
&builder_,
28-
nullptr,
29-
ToSkMatrix(root_transform_),
30-
false,
31-
true,
32-
nullptr,
33-
nullptr)) {}
25+
scoped_frame_(compositor_context_.AcquireFrame(nullptr,
26+
&builder_,
27+
nullptr,
28+
root_transform_,
29+
false,
30+
true,
31+
nullptr,
32+
nullptr)) {}
3433

3534
CompositorContext::ScopedFrame& frame() { return *scoped_frame_.get(); }
3635
const DlMatrix& root_transform() { return root_transform_; }

0 commit comments

Comments
 (0)