Skip to content

Commit 7e34f1f

Browse files
authored
Revert "SceneBuilder.addPicture returns the layer (#26074)" (#26133)
1 parent 247d1d9 commit 7e34f1f

File tree

11 files changed

+30
-96
lines changed

11 files changed

+30
-96
lines changed

lib/ui/compositing.dart

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,6 @@ class PhysicalShapeEngineLayer extends _EngineLayerWrapper {
188188
PhysicalShapeEngineLayer._(EngineLayer nativeLayer) : super._(nativeLayer);
189189
}
190190

191-
/// An opaque handle to a picture engine layer.
192-
///
193-
/// Instances of this class are created by [SceneBuilder.addPicture].
194-
///
195-
/// {@macro dart.ui.sceneBuilder.oldLayerCompatibility}
196-
class PictureEngineLayer extends _EngineLayerWrapper {
197-
PictureEngineLayer._(EngineLayer nativeLayer) : super._(nativeLayer);
198-
}
199-
200191
/// Builds a [Scene] containing the given visuals.
201192
///
202193
/// A [Scene] can then be rendered using [FlutterView.render].
@@ -708,29 +699,18 @@ class SceneBuilder extends NativeFieldWrapperClass2 {
708699
/// Adds a [Picture] to the scene.
709700
///
710701
/// The picture is rasterized at the given offset.
711-
///
712-
/// {@macro dart.ui.sceneBuilder.oldLayer}
713-
PictureEngineLayer addPicture(
702+
void addPicture(
714703
Offset offset,
715704
Picture picture, {
716705
bool isComplexHint = false,
717706
bool willChangeHint = false,
718-
PictureEngineLayer? oldLayer,
719707
}) {
720-
assert(_debugCheckCanBeUsedAsOldLayer(oldLayer, 'addPicture'));
721-
final EngineLayer engineLayer = EngineLayer._();
722708
final int hints = (isComplexHint ? 1 : 0) | (willChangeHint ? 2 : 0);
723-
_addPicture(engineLayer, offset.dx, offset.dy, picture, hints, oldLayer?._nativeLayer);
724-
return PictureEngineLayer._(engineLayer);
709+
_addPicture(offset.dx, offset.dy, picture, hints);
725710
}
726711

727-
void _addPicture(
728-
EngineLayer outEngineLayer,
729-
double dx,
730-
double dy,
731-
Picture picture,
732-
int hints,
733-
EngineLayer? oldLayer) native 'SceneBuilder_addPicture';
712+
void _addPicture(double dx, double dy, Picture picture, int hints)
713+
native 'SceneBuilder_addPicture';
734714

735715
/// Adds a backend texture to the scene.
736716
///

lib/ui/compositing/scene_builder.cc

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -272,20 +272,14 @@ void SceneBuilder::pop() {
272272
PopLayer();
273273
}
274274

275-
void SceneBuilder::addPicture(Dart_Handle layer_handle,
276-
double dx,
275+
void SceneBuilder::addPicture(double dx,
277276
double dy,
278277
Picture* picture,
279-
int hints,
280-
fml::RefPtr<EngineLayer> oldLayer) {
281-
auto layer = std::make_shared<flutter::PictureLayer>(
278+
int hints) {
279+
auto layer = std::make_unique<flutter::PictureLayer>(
282280
SkPoint::Make(dx, dy), UIDartState::CreateGPUObject(picture->picture()),
283281
!!(hints & 1), !!(hints & 2));
284-
AddLayer(layer);
285-
EngineLayer::MakeRetained(layer_handle, layer);
286-
if (oldLayer && oldLayer->Layer()) {
287-
layer->AssignOldLayer(oldLayer->Layer().get());
288-
}
282+
AddLayer(std::move(layer));
289283
}
290284

291285
void SceneBuilder::addTexture(double dx,

lib/ui/compositing/scene_builder.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,7 @@ class SceneBuilder : public RefCountedDartWrappable<SceneBuilder> {
101101
double top,
102102
double bottom);
103103

104-
void addPicture(Dart_Handle layer_handle,
105-
double dx,
106-
double dy,
107-
Picture* picture,
108-
int hints,
109-
fml::RefPtr<EngineLayer> oldLayer);
104+
void addPicture(double dx, double dy, Picture* picture, int hints);
110105

111106
void addTexture(double dx,
112107
double dy,

lib/ui/painting/engine_layer.cc

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

55
#include "flutter/lib/ui/painting/engine_layer.h"
66

7-
#include "flutter/lib/ui/ui_dart_state.h"
87
#include "third_party/tonic/converter/dart_converter.h"
98
#include "third_party/tonic/dart_args.h"
109
#include "third_party/tonic/dart_binding_macros.h"
@@ -14,14 +13,14 @@ using tonic::ToDart;
1413

1514
namespace flutter {
1615

17-
EngineLayer::EngineLayer(std::shared_ptr<flutter::Layer> layer)
16+
EngineLayer::EngineLayer(std::shared_ptr<flutter::ContainerLayer> layer)
1817
: layer_(layer) {}
1918

2019
EngineLayer::~EngineLayer() = default;
2120

2221
size_t EngineLayer::GetAllocationSize() const {
2322
// Provide an approximation of the total memory impact of this object to the
24-
// Dart GC. The Layer may hold references to a tree of other layers,
23+
// Dart GC. The ContainerLayer may hold references to a tree of other layers,
2524
// which in turn may contain Skia objects.
2625
return 3000;
2726
};

lib/ui/painting/engine_layer.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,19 @@ class EngineLayer : public RefCountedDartWrappable<EngineLayer> {
2424

2525
size_t GetAllocationSize() const override;
2626

27-
static fml::RefPtr<EngineLayer> MakeRetained(
28-
Dart_Handle dart_handle,
29-
std::shared_ptr<flutter::Layer> layer) {
30-
auto engine_layer = fml::MakeRefCounted<EngineLayer>(std::move(layer));
27+
static void MakeRetained(Dart_Handle dart_handle,
28+
std::shared_ptr<flutter::ContainerLayer> layer) {
29+
auto engine_layer = fml::MakeRefCounted<EngineLayer>(layer);
3130
engine_layer->AssociateWithDartWrapper(dart_handle);
32-
return engine_layer;
3331
}
3432

3533
static void RegisterNatives(tonic::DartLibraryNatives* natives);
3634

37-
std::shared_ptr<flutter::Layer> Layer() const { return layer_; }
35+
std::shared_ptr<flutter::ContainerLayer> Layer() const { return layer_; }
3836

3937
private:
40-
explicit EngineLayer(std::shared_ptr<flutter::Layer> layer);
41-
std::shared_ptr<flutter::Layer> layer_;
38+
explicit EngineLayer(std::shared_ptr<flutter::ContainerLayer> layer);
39+
std::shared_ptr<flutter::ContainerLayer> layer_;
4240

4341
FML_FRIEND_MAKE_REF_COUNTED(EngineLayer);
4442
};

lib/web_ui/lib/src/engine/canvaskit/layer.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ class ShaderMaskEngineLayer extends ContainerLayer implements ui.ShaderMaskEngin
411411
}
412412

413413
/// A layer containing a [Picture].
414-
class PictureLayer extends Layer implements ui.PictureEngineLayer {
414+
class PictureLayer extends Layer {
415415
/// The picture to paint into the canvas.
416416
final CkPicture picture;
417417

lib/web_ui/lib/src/engine/canvaskit/layer_scene_builder.dart

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,14 @@ class LayerSceneBuilder implements ui.SceneBuilder {
4545
}
4646

4747
@override
48-
ui.PictureEngineLayer addPicture(
48+
void addPicture(
4949
ui.Offset offset,
5050
ui.Picture picture, {
5151
bool isComplexHint = false,
5252
bool willChangeHint = false,
53-
ui.PictureEngineLayer? oldLayer,
5453
}) {
55-
final PictureLayer layer = PictureLayer(
56-
picture as CkPicture,
57-
offset,
58-
isComplexHint,
59-
willChangeHint,
60-
);
61-
currentLayer.add(layer);
62-
return layer;
54+
currentLayer.add(PictureLayer(
55+
picture as CkPicture, offset, isComplexHint, willChangeHint));
6356
}
6457

6558
@override

lib/web_ui/lib/src/engine/html/picture.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void _recycleCanvas(EngineCanvas? canvas) {
7878

7979
/// A surface that uses a combination of `<canvas>`, `<div>` and `<p>` elements
8080
/// to draw shapes and text.
81-
class PersistedPicture extends PersistedLeafSurface implements ui.PictureEngineLayer {
81+
class PersistedPicture extends PersistedLeafSurface {
8282
PersistedPicture(this.dx, this.dy, this.picture, this.hints)
8383
: localPaintBounds = picture.recordingCanvas!.pictureBounds;
8484

lib/web_ui/lib/src/engine/html/scene_builder.dart

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -359,12 +359,11 @@ class SurfaceSceneBuilder implements ui.SceneBuilder {
359359
///
360360
/// The picture is rasterized at the given offset.
361361
@override
362-
ui.PictureEngineLayer addPicture(
362+
void addPicture(
363363
ui.Offset offset,
364364
ui.Picture picture, {
365365
bool isComplexHint = false,
366366
bool willChangeHint = false,
367-
ui.PictureEngineLayer? oldLayer,
368367
}) {
369368
int hints = 0;
370369
if (isComplexHint) {
@@ -373,14 +372,8 @@ class SurfaceSceneBuilder implements ui.SceneBuilder {
373372
if (willChangeHint) {
374373
hints |= 2;
375374
}
376-
final PersistedPicture layer = PersistedPicture(
377-
offset.dx,
378-
offset.dy,
379-
picture as EnginePicture,
380-
hints,
381-
);
382-
_addSurface(layer);
383-
return layer;
375+
_addSurface(PersistedPicture(
376+
offset.dx, offset.dy, picture as EnginePicture, hints));
384377
}
385378

386379
/// Adds a backend texture to the scene.

lib/web_ui/lib/src/ui/compositing.dart

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ abstract class ShaderMaskEngineLayer implements EngineLayer {}
3131

3232
abstract class PhysicalShapeEngineLayer implements EngineLayer {}
3333

34-
// TODO(yjbanov): Incorporate into DOM diffing algorithm.
35-
// https://github.com/flutter/flutter/issues/82287
36-
abstract class PictureEngineLayer implements EngineLayer {}
37-
3834
abstract class SceneBuilder {
3935
factory SceneBuilder() {
4036
if (engine.useCanvasKit) {
@@ -103,12 +99,11 @@ abstract class SceneBuilder {
10399
void addRetained(EngineLayer retainedLayer);
104100
void pop();
105101
void addPerformanceOverlay(int enabledOptions, Rect bounds);
106-
PictureEngineLayer addPicture(
102+
void addPicture(
107103
Offset offset,
108104
Picture picture, {
109105
bool isComplexHint = false,
110106
bool willChangeHint = false,
111-
PictureEngineLayer? oldLayer,
112107
});
113108
void addTexture(
114109
int textureId, {

0 commit comments

Comments
 (0)