From 8197056444df125dfefe9de37173c2a4675402df Mon Sep 17 00:00:00 2001 From: Yuqian Li Date: Thu, 18 Oct 2018 13:34:25 -0700 Subject: [PATCH 1/2] Add offset to engine OpacityLayer See https://github.com/flutter/flutter/pull/22566#discussion_r226082171 for why we add this. --- flow/layers/opacity_layer.cc | 7 +++++-- flow/layers/opacity_layer.h | 3 +++ lib/ui/compositing.dart | 5 ++++- lib/ui/compositing/scene_builder.cc | 3 ++- lib/ui/compositing/scene_builder.h | 2 +- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/flow/layers/opacity_layer.cc b/flow/layers/opacity_layer.cc index 202b53bdb9983..ebbced6f605a1 100644 --- a/flow/layers/opacity_layer.cc +++ b/flow/layers/opacity_layer.cc @@ -11,10 +11,12 @@ OpacityLayer::OpacityLayer() = default; OpacityLayer::~OpacityLayer() = default; void OpacityLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) { - ContainerLayer::Preroll(context, matrix); + SkMatrix child_matrix = matrix; + child_matrix.postTranslate(offset_.fX, offset_.fY); + ContainerLayer::Preroll(context, child_matrix); if (context->raster_cache && layers().size() == 1) { Layer* child = layers()[0].get(); - SkMatrix ctm = matrix; + SkMatrix ctm = child_matrix; #ifndef SUPPORT_FRACTIONAL_TRANSLATION ctm = RasterCache::GetIntegralTransCTM(ctm); #endif @@ -30,6 +32,7 @@ void OpacityLayer::Paint(PaintContext& context) const { paint.setAlpha(alpha_); SkAutoCanvasRestore save(&context.canvas, true); + context.canvas.translate(offset_.fX, offset_.fY); #ifndef SUPPORT_FRACTIONAL_TRANSLATION context.canvas.setMatrix( diff --git a/flow/layers/opacity_layer.h b/flow/layers/opacity_layer.h index 4733d13645233..6684ff7ea2bdd 100644 --- a/flow/layers/opacity_layer.h +++ b/flow/layers/opacity_layer.h @@ -15,6 +15,8 @@ class OpacityLayer : public ContainerLayer { ~OpacityLayer() override; void set_alpha(int alpha) { alpha_ = alpha; } + void set_offset(const SkPoint& offset) { offset_ = offset; } + void Preroll(PrerollContext* context, const SkMatrix& matrix) override; @@ -25,6 +27,7 @@ class OpacityLayer : public ContainerLayer { private: int alpha_; + SkPoint offset_; FML_DISALLOW_COPY_AND_ASSIGN(OpacityLayer); }; diff --git a/lib/ui/compositing.dart b/lib/ui/compositing.dart index 8c3d9261d69e5..935a1665248da 100644 --- a/lib/ui/compositing.dart +++ b/lib/ui/compositing.dart @@ -122,7 +122,10 @@ class SceneBuilder extends NativeFieldWrapperClass2 { /// opacity). /// /// See [pop] for details about the operation stack. - void pushOpacity(int alpha) native 'SceneBuilder_pushOpacity'; + void pushOpacity(int alpha, {Offset offset = Offset.zero}) { + _pushOpacity(alpha, offset.dx, offset.dy); + } + void _pushOpacity(int alpha, double dx, double dy) native 'SceneBuilder_pushOpacity'; /// Pushes a color filter operation onto the operation stack. /// diff --git a/lib/ui/compositing/scene_builder.cc b/lib/ui/compositing/scene_builder.cc index 76137c464969d..18810d4aa02fd 100644 --- a/lib/ui/compositing/scene_builder.cc +++ b/lib/ui/compositing/scene_builder.cc @@ -118,9 +118,10 @@ void SceneBuilder::pushClipPath(const CanvasPath* path, int clipBehavior) { PushLayer(std::move(layer)); } -void SceneBuilder::pushOpacity(int alpha) { +void SceneBuilder::pushOpacity(int alpha, double dx, double dy) { auto layer = std::make_unique(); layer->set_alpha(alpha); + layer->set_offset(SkPoint::Make(dx, dy)); PushLayer(std::move(layer)); } diff --git a/lib/ui/compositing/scene_builder.h b/lib/ui/compositing/scene_builder.h index 8674d004ab5d8..7fd1a0d17f4af 100644 --- a/lib/ui/compositing/scene_builder.h +++ b/lib/ui/compositing/scene_builder.h @@ -42,7 +42,7 @@ class SceneBuilder : public RefCountedDartWrappable { int clipBehavior); void pushClipRRect(const RRect& rrect, int clipBehavior); void pushClipPath(const CanvasPath* path, int clipBehavior); - void pushOpacity(int alpha); + void pushOpacity(int alpha, double dx = 0, double dy = 0); void pushColorFilter(int color, int blendMode); void pushBackdropFilter(ImageFilter* filter); void pushShaderMask(Shader* shader, From f664a6f49dba4c5b5a65359c4749264483356fe7 Mon Sep 17 00:00:00 2001 From: Yuqian Li Date: Fri, 19 Oct 2018 09:57:02 -0700 Subject: [PATCH 2/2] Clang-format --- flow/layers/opacity_layer.h | 1 - 1 file changed, 1 deletion(-) diff --git a/flow/layers/opacity_layer.h b/flow/layers/opacity_layer.h index 6684ff7ea2bdd..75e939e03e97e 100644 --- a/flow/layers/opacity_layer.h +++ b/flow/layers/opacity_layer.h @@ -17,7 +17,6 @@ class OpacityLayer : public ContainerLayer { void set_alpha(int alpha) { alpha_ = alpha; } void set_offset(const SkPoint& offset) { offset_ = offset; } - void Preroll(PrerollContext* context, const SkMatrix& matrix) override; void Paint(PaintContext& context) const override;