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..75e939e03e97e 100644 --- a/flow/layers/opacity_layer.h +++ b/flow/layers/opacity_layer.h @@ -15,6 +15,7 @@ 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 +26,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,