Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit cb27fab

Browse files
committed
Merge remote-tracking branch 'upstream/main' into xilaizhang-android-2
2 parents 2c167f4 + 526fd0d commit cb27fab

25 files changed

+638
-136
lines changed

DEPS

Lines changed: 78 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ vars = {
1818
'llvm_git': 'https://llvm.googlesource.com',
1919
# OCMock is for testing only so there is no google clone
2020
'ocmock_git': 'https://github.com/erikdoe/ocmock.git',
21-
'skia_revision': '3fea88565a83a24bbcdc3513e143bac2634357b0',
21+
'skia_revision': '20a1c61c55977f0b6c291584d8b1108e180883bf',
2222

2323
# WARNING: DO NOT EDIT canvaskit_cipd_instance MANUALLY
2424
# See `lib/web_ui/README.md` for how to roll CanvasKit to a new version.
@@ -39,7 +39,13 @@ vars = {
3939
# The list of revisions for these tools comes from Fuchsia, here:
4040
# https://fuchsia.googlesource.com/integration/+/HEAD/toolchain
4141
# If there are problems with the toolchain, contact fuchsia-toolchain@.
42-
'clang_version': 'git_revision:20d06c833d833ef6b2d0f519cc4a7998d49a2803',
42+
'clang_version': 'git_revision:5344d8e10bb7d8672d4bfae8adb010465470d51b',
43+
44+
# The goma version and the clang version can be tightly coupled. If goma
45+
# stops working on a clang roll, this may need to be updated using the value
46+
# from the 'integration' tag of
47+
# https://chrome-infra-packages.appspot.com/p/fuchsia/third_party/goma/client
48+
'goma_version': ' git_revision:41b3bcb64014144a844153fd5588c36411fffb56',
4349

4450
# When updating the Dart revision, ensure that all entries that are
4551
# dependencies of Dart are also updated to match the entries in the
@@ -98,7 +104,12 @@ vars = {
98104
"checkout_llvm": False,
99105

100106
# Setup Git hooks by default.
101-
"setup_githooks": True,
107+
'setup_githooks': True,
108+
109+
# When this is true, the goma client will be downloaded from cipd, and
110+
# the engine build will prefer to use this client over a client that is
111+
# specified by GOMA_DIR, or installed in the default goma install location.
112+
'use_cipd_goma': False,
102113

103114
# This is not downloaded be default because it increases the
104115
# `gclient sync` time by between 1 and 3 minutes. This option is enabled
@@ -830,6 +841,40 @@ deps = {
830841
'dep_type': 'cipd',
831842
},
832843

844+
# GOMA
845+
'src/buildtools/mac-x64/goma': {
846+
'packages': [
847+
{
848+
'package': 'fuchsia/third_party/goma/client/mac-amd64',
849+
'version': Var('goma_version'),
850+
}
851+
],
852+
'condition': 'use_cipd_goma and host_os == "mac"',
853+
'dep_type': 'cipd',
854+
},
855+
856+
'src/buildtools/linux-x64/goma': {
857+
'packages': [
858+
{
859+
'package': 'fuchsia/third_party/goma/client/linux-amd64',
860+
'version': Var('goma_version'),
861+
}
862+
],
863+
'condition': 'use_cipd_goma and host_os == "linux"',
864+
'dep_type': 'cipd',
865+
},
866+
867+
'src/buildtools/windows-x64/goma': {
868+
'packages': [
869+
{
870+
'package': 'fuchsia/third_party/goma/client/windows-amd64',
871+
'version': Var('goma_version'),
872+
}
873+
],
874+
'condition': 'use_cipd_goma and download_windows_deps',
875+
'dep_type': 'cipd',
876+
},
877+
833878
# Get the SDK from https://chrome-infra-packages.appspot.com/p/fuchsia/sdk/core at the 'latest' tag
834879
# Get the toolchain from https://chrome-infra-packages.appspot.com/p/fuchsia/clang at the 'goma' tag
835880
'src/fuchsia/sdk/mac': {
@@ -965,6 +1010,36 @@ hooks = [
9651010
'src/flutter/tools/activate_emsdk.py',
9661011
]
9671012
},
1013+
{
1014+
'name': 'Start compiler proxy',
1015+
'pattern': '.',
1016+
'condition': 'use_cipd_goma and host_os == "mac"',
1017+
'action': [
1018+
'python3',
1019+
'src/buildtools/mac-x64/goma/goma_ctl.py',
1020+
'ensure_start'
1021+
]
1022+
},
1023+
{
1024+
'name': 'Start compiler proxy',
1025+
'pattern': '.',
1026+
'condition': 'use_cipd_goma and host_os == "linux"',
1027+
'action': [
1028+
'python3',
1029+
'src/buildtools/linux-x64/goma/goma_ctl.py',
1030+
'ensure_start'
1031+
]
1032+
},
1033+
{
1034+
'name': 'Start compiler proxy',
1035+
'pattern': '.',
1036+
'condition': 'use_cipd_goma and download_windows_deps',
1037+
'action': [
1038+
'python3',
1039+
'src/buildtools/windows-x64/goma/goma_ctl.py',
1040+
'ensure_start'
1041+
]
1042+
},
9681043
{
9691044
'name': 'Setup githooks',
9701045
'pattern': '.',

ci/licenses_golden/licenses_skia

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Signature: c33c3351133cb6b13039079b3c94f1e0
1+
Signature: e7f272d896f2837bf7a1825fa17efec1
22

33
====================================================================================================
44
LIBRARY: etc1
@@ -384,7 +384,6 @@ FILE: ../../../third_party/skia/modules/pathkit/perf/pathops.bench.js
384384
FILE: ../../../third_party/skia/modules/pathkit/perf/perfReporter.js
385385
FILE: ../../../third_party/skia/modules/skparagraph/test.html
386386
FILE: ../../../third_party/skia/package-lock.json
387-
FILE: ../../../third_party/skia/relnotes/skrp.md
388387
FILE: ../../../third_party/skia/src/core/SkOrderedReadBuffer.h
389388
FILE: ../../../third_party/skia/src/gpu/gpu_workaround_list.txt
390389
FILE: ../../../third_party/skia/src/sksl/generated/sksl_compute.minified.sksl

flow/compositor_context.cc

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ std::optional<SkRect> FrameDamage::ComputeClipRect(
4343
context.ComputeDamage(additional_damage_, horizontal_clip_alignment_,
4444
vertical_clip_alignment_);
4545
return SkRect::Make(damage_->buffer_damage);
46-
} else {
47-
return std::nullopt;
4846
}
47+
return std::nullopt;
4948
}
5049

5150
CompositorContext::CompositorContext()
@@ -125,10 +124,16 @@ RasterStatus CompositorContext::ScopedFrame::Raster(
125124
FrameDamage* frame_damage) {
126125
TRACE_EVENT0("flutter", "CompositorContext::ScopedFrame::Raster");
127126

128-
std::optional<SkRect> clip_rect =
129-
frame_damage
130-
? frame_damage->ComputeClipRect(layer_tree, !ignore_raster_cache)
131-
: std::nullopt;
127+
std::optional<SkRect> clip_rect;
128+
if (frame_damage) {
129+
clip_rect = frame_damage->ComputeClipRect(layer_tree, !ignore_raster_cache);
130+
131+
if (aiks_context_ &&
132+
!ShouldPerformPartialRepaint(clip_rect, layer_tree.frame_size())) {
133+
clip_rect = std::nullopt;
134+
frame_damage->Reset();
135+
}
136+
}
132137

133138
bool root_needs_readback = layer_tree.Preroll(
134139
*this, ignore_raster_cache, clip_rect ? *clip_rect : kGiantRect);
@@ -146,10 +151,22 @@ RasterStatus CompositorContext::ScopedFrame::Raster(
146151
return RasterStatus::kSkipAndRetry;
147152
}
148153

154+
if (aiks_context_) {
155+
PaintLayerTreeImpeller(layer_tree, clip_rect, ignore_raster_cache);
156+
} else {
157+
PaintLayerTreeSkia(layer_tree, clip_rect, needs_save_layer,
158+
ignore_raster_cache);
159+
}
160+
return RasterStatus::kSuccess;
161+
}
162+
163+
void CompositorContext::ScopedFrame::PaintLayerTreeSkia(
164+
flutter::LayerTree& layer_tree,
165+
std::optional<SkRect> clip_rect,
166+
bool needs_save_layer,
167+
bool ignore_raster_cache) {
149168
DlAutoCanvasRestore restore(canvas(), clip_rect.has_value());
150169

151-
// Clearing canvas after preroll reduces one render target switch when preroll
152-
// paints some raster cache.
153170
if (canvas()) {
154171
if (clip_rect) {
155172
canvas()->ClipRect(*clip_rect);
@@ -164,9 +181,48 @@ RasterStatus CompositorContext::ScopedFrame::Raster(
164181
}
165182
canvas()->Clear(DlColor::kTransparent());
166183
}
167-
layer_tree.Paint(*this, ignore_raster_cache);
184+
168185
// The canvas()->Restore() is taken care of by the DlAutoCanvasRestore
169-
return RasterStatus::kSuccess;
186+
layer_tree.Paint(*this, ignore_raster_cache);
187+
}
188+
189+
void CompositorContext::ScopedFrame::PaintLayerTreeImpeller(
190+
flutter::LayerTree& layer_tree,
191+
std::optional<SkRect> clip_rect,
192+
bool ignore_raster_cache) {
193+
if (canvas() && clip_rect) {
194+
canvas()->Translate(-clip_rect->x(), -clip_rect->y());
195+
}
196+
197+
layer_tree.Paint(*this, ignore_raster_cache);
198+
}
199+
200+
/// @brief The max ratio of pixel width or height to size that is dirty which
201+
/// results in a partial repaint.
202+
///
203+
/// Performing a partial repaint has a small overhead - Impeller needs to
204+
/// allocate a fairly large resolve texture for the root pass instead of
205+
/// using the drawable texture, and a final blit must be performed. At a
206+
/// minimum, if the damage rect is the entire buffer, we must not perform
207+
/// a partial repaint. Beyond that, we could only experimentally
208+
/// determine what this value should be. From looking at the Flutter
209+
/// Gallery, we noticed that there are occassionally small partial
210+
/// repaints which shave off trivial numbers of pixels.
211+
constexpr float kImpellerRepaintRatio = 0.7f;
212+
213+
bool CompositorContext::ShouldPerformPartialRepaint(
214+
std::optional<SkRect> damage_rect,
215+
SkISize layer_tree_size) {
216+
if (!damage_rect.has_value()) {
217+
return false;
218+
}
219+
if (damage_rect->width() >= layer_tree_size.width() &&
220+
damage_rect->height() >= layer_tree_size.height()) {
221+
return false;
222+
}
223+
auto rx = damage_rect->width() / layer_tree_size.width();
224+
auto ry = damage_rect->height() / layer_tree_size.height();
225+
return rx <= kImpellerRepaintRatio || ry <= kImpellerRepaintRatio;
170226
}
171227

172228
void CompositorContext::OnGrContextCreated() {

flow/compositor_context.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,24 @@ class FrameDamage {
9191

9292
// See Damage::buffer_damage.
9393
std::optional<SkIRect> GetBufferDamage() {
94-
return damage_ ? std::make_optional(damage_->buffer_damage) : std::nullopt;
94+
return (damage_ && !ignore_damage_)
95+
? std::make_optional(damage_->buffer_damage)
96+
: std::nullopt;
9597
}
9698

99+
// Remove reported buffer_damage to inform clients that a partial repaint
100+
// should not be performed on this frame.
101+
// frame_damage is required to correctly track accumulated damage for
102+
// subsequent frames.
103+
void Reset() { ignore_damage_ = true; }
104+
97105
private:
98106
SkIRect additional_damage_ = SkIRect::MakeEmpty();
99107
std::optional<Damage> damage_;
100108
const LayerTree* prev_layer_tree_ = nullptr;
101109
int vertical_clip_alignment_ = 1;
102110
int horizontal_clip_alignment_ = 1;
111+
bool ignore_damage_ = false;
103112
};
104113

105114
class CompositorContext {
@@ -144,6 +153,15 @@ class CompositorContext {
144153
FrameDamage* frame_damage);
145154

146155
private:
156+
void PaintLayerTreeSkia(flutter::LayerTree& layer_tree,
157+
std::optional<SkRect> clip_rect,
158+
bool needs_save_layer,
159+
bool ignore_raster_cache);
160+
161+
void PaintLayerTreeImpeller(flutter::LayerTree& layer_tree,
162+
std::optional<SkRect> clip_rect,
163+
bool ignore_raster_cache);
164+
147165
CompositorContext& context_;
148166
GrDirectContext* gr_context_;
149167
DlCanvas* canvas_;
@@ -205,6 +223,12 @@ class CompositorContext {
205223

206224
void EndFrame(ScopedFrame& frame, bool enable_instrumentation);
207225

226+
/// @brief Whether Impeller shouild attempt a partial repaint.
227+
/// The Impeller backend requires an additional blit pass, which may
228+
/// not be worthwhile if the damage region is large.
229+
static bool ShouldPerformPartialRepaint(std::optional<SkRect> damage_rect,
230+
SkISize layer_tree_size);
231+
208232
FML_DISALLOW_COPY_AND_ASSIGN(CompositorContext);
209233
};
210234

impeller/playground/backend/metal/playground_impl_mtl.mm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@
115115
data_->metal_layer.drawableSize =
116116
CGSizeMake(layer_size.width * scale.x, layer_size.height * scale.y);
117117

118-
return SurfaceMTL::WrapCurrentMetalLayerDrawable(context, data_->metal_layer);
118+
auto drawable =
119+
SurfaceMTL::GetMetalDrawableAndValidate(context, data_->metal_layer);
120+
return SurfaceMTL::WrapCurrentMetalLayerDrawable(context, drawable);
119121
}
120122

121123
} // namespace impeller

impeller/renderer/backend/metal/context_mtl.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ static bool DeviceSupportsComputeSubgroups(id<MTLDevice> device) {
5555
.SetSupportsBufferToTextureBlits(true)
5656
.SetSupportsTextureToTextureBlits(true)
5757
.SetSupportsDecalTileMode(true)
58+
.SetSupportsSharedDeviceBufferTextureMemory(true)
5859
.SetSupportsFramebufferFetch(DeviceSupportsFramebufferFetch(device))
5960
.SetDefaultColorFormat(color_format)
6061
.SetDefaultStencilFormat(PixelFormat::kS8UInt)

impeller/renderer/backend/metal/surface_mtl.h

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <QuartzCore/CAMetalLayer.h>
88

99
#include "flutter/fml/macros.h"
10+
#include "impeller/geometry/rect.h"
1011
#include "impeller/renderer/context.h"
1112
#include "impeller/renderer/surface.h"
1213

@@ -32,26 +33,39 @@ class SurfaceMTL final : public Surface {
3233
///
3334
/// @return A pointer to the wrapped surface or null.
3435
///
35-
static std::unique_ptr<SurfaceMTL> WrapCurrentMetalLayerDrawable(
36+
static id<CAMetalDrawable> GetMetalDrawableAndValidate(
3637
const std::shared_ptr<Context>& context,
3738
CAMetalLayer* layer);
39+
40+
static std::unique_ptr<SurfaceMTL> WrapCurrentMetalLayerDrawable(
41+
const std::shared_ptr<Context>& context,
42+
id<CAMetalDrawable> drawable,
43+
std::optional<IRect> clip_rect = std::nullopt);
3844
#pragma GCC diagnostic pop
3945

4046
// |Surface|
4147
~SurfaceMTL() override;
4248

4349
id<MTLDrawable> drawable() const { return drawable_; }
4450

51+
// |Surface|
52+
bool Present() const override;
53+
4554
private:
4655
std::weak_ptr<Context> context_;
47-
id<MTLDrawable> drawable_ = nil;
56+
std::shared_ptr<Texture> resolve_texture_;
57+
id<CAMetalDrawable> drawable_ = nil;
58+
bool requires_blit_ = false;
59+
std::optional<IRect> clip_rect_;
60+
61+
static bool ShouldPerformPartialRepaint(std::optional<IRect> damage_rect);
4862

4963
SurfaceMTL(const std::weak_ptr<Context>& context,
5064
const RenderTarget& target,
51-
id<MTLDrawable> drawable);
52-
53-
// |Surface|
54-
bool Present() const override;
65+
std::shared_ptr<Texture> resolve_texture,
66+
id<CAMetalDrawable> drawable,
67+
bool requires_blit,
68+
std::optional<IRect> clip_rect);
5569

5670
FML_DISALLOW_COPY_AND_ASSIGN(SurfaceMTL);
5771
};

0 commit comments

Comments
 (0)