Add offset to engine OpacityLayer (#6594)

See https://github.com/flutter/flutter/pull/22566#discussion_r226082171
for why we add this.
This commit is contained in:
liyuqian 2018-10-19 11:46:12 -07:00 committed by GitHub
parent a9974a3f4a
commit e79d77f6e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 5 deletions

View File

@ -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(

View File

@ -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);
};

View File

@ -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.
///

View File

@ -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));
}

View File

@ -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,