Skip to content

Commit

Permalink
fuchsia: Remove Opacity hole-punch (flutter#21527)
Browse files Browse the repository at this point in the history
  • Loading branch information
arbreng authored Oct 1, 2020
1 parent af5717e commit 1f183ba
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 26 deletions.
18 changes: 1 addition & 17 deletions flow/layers/child_scene_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,10 @@ void ChildSceneLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {

context->child_scene_layer_exists_below = true;
CheckForChildLayerBelow(context);

// An alpha "hole punch" is required if the frame behind us is not opaque.
if (!context->is_opaque) {
set_paint_bounds(
SkRect::MakeXYWH(offset_.fX, offset_.fY, size_.fWidth, size_.fHeight));
}
}

void ChildSceneLayer::Paint(PaintContext& context) const {
TRACE_EVENT0("flutter", "ChildSceneLayer::Paint");
FML_DCHECK(needs_painting());
FML_DCHECK(needs_system_composite());

// If we are being rendered into our own frame using the system compositor,
// then it is neccesary to "punch a hole" in the canvas/frame behind us so
// that group opacity looks correct.
SkPaint paint;
paint.setColor(SK_ColorTRANSPARENT);
paint.setBlendMode(SkBlendMode::kSrc);
context.leaf_nodes_canvas->drawRect(paint_bounds(), paint);
FML_NOTREACHED();
}

void ChildSceneLayer::UpdateScene(SceneUpdateContext& context) {
Expand Down
1 change: 0 additions & 1 deletion flow/layers/layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ struct PrerollContext {
// These allow us to track properties like elevation, opacity, and the
// prescence of a platform view during Preroll.
bool has_platform_view = false;
bool is_opaque = true;
#if defined(LEGACY_FUCHSIA_EMBEDDER)
// True if, during the traversal so far, we have seen a child_scene_layer.
// Informs whether a layer needs to be system composited.
Expand Down
7 changes: 1 addition & 6 deletions flow/layers/opacity_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,15 @@ OpacityLayer::OpacityLayer(SkAlpha alpha, const SkPoint& offset)

void OpacityLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
TRACE_EVENT0("flutter", "OpacityLayer::Preroll");
FML_DCHECK(!GetChildContainer()->layers().empty()); // We can't be a leaf.

ContainerLayer* container = GetChildContainer();
FML_DCHECK(!container->layers().empty()); // OpacityLayer can't be a leaf.

const bool parent_is_opaque = context->is_opaque;
SkMatrix child_matrix = matrix;
child_matrix.postTranslate(offset_.fX, offset_.fY);

// Similar to what's done in TransformLayer::Preroll, we have to apply the
// reverse transformation to the cull rect to properly cull child layers.
context->cull_rect = context->cull_rect.makeOffset(-offset_.fX, -offset_.fY);

context->is_opaque = parent_is_opaque && (alpha_ == SK_AlphaOPAQUE);
context->mutators_stack.PushTransform(
SkMatrix::Translate(offset_.fX, offset_.fY));
context->mutators_stack.PushOpacity(alpha_);
Expand All @@ -35,7 +31,6 @@ void OpacityLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
ContainerLayer::Preroll(context, child_matrix);
context->mutators_stack.Pop();
context->mutators_stack.Pop();
context->is_opaque = parent_is_opaque;

{
set_paint_bounds(paint_bounds().makeOffset(offset_.fX, offset_.fY));
Expand Down
5 changes: 3 additions & 2 deletions flow/layers/opacity_layer_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ TEST_F(OpacityLayerTest, LeafLayer) {
auto layer =
std::make_shared<OpacityLayer>(SK_AlphaOPAQUE, SkPoint::Make(0.0f, 0.0f));

EXPECT_DEATH_IF_SUPPORTED(layer->Preroll(preroll_context(), SkMatrix()),
"\\!container->layers\\(\\)\\.empty\\(\\)");
EXPECT_DEATH_IF_SUPPORTED(
layer->Preroll(preroll_context(), SkMatrix()),
"\\!GetChildContainer\\(\\)->layers\\(\\)\\.empty\\(\\)");
}

TEST_F(OpacityLayerTest, PaintingEmptyLayerDies) {
Expand Down

0 comments on commit 1f183ba

Please sign in to comment.