Skip to content

Commit

Permalink
Add offset to engine OpacityLayer (flutter#6594)
Browse files Browse the repository at this point in the history
See flutter/flutter#22566 (comment)
for why we add this.
  • Loading branch information
liyuqian authored Oct 19, 2018
1 parent a9974a3 commit e79d77f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
7 changes: 5 additions & 2 deletions flow/layers/opacity_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions flow/layers/opacity_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -25,6 +26,7 @@ class OpacityLayer : public ContainerLayer {

private:
int alpha_;
SkPoint offset_;

FML_DISALLOW_COPY_AND_ASSIGN(OpacityLayer);
};
Expand Down
5 changes: 4 additions & 1 deletion lib/ui/compositing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
3 changes: 2 additions & 1 deletion lib/ui/compositing/scene_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<flow::OpacityLayer>();
layer->set_alpha(alpha);
layer->set_offset(SkPoint::Make(dx, dy));
PushLayer(std::move(layer));
}

Expand Down
2 changes: 1 addition & 1 deletion lib/ui/compositing/scene_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SceneBuilder : public RefCountedDartWrappable<SceneBuilder> {
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,
Expand Down

0 comments on commit e79d77f

Please sign in to comment.