Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the internal_nodes_canvas for all leaf node operations. #6804

Merged
merged 2 commits into from
Nov 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions flow/layers/clip_path_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,15 @@ void ClipPathLayer::Paint(PaintContext& context) const {
TRACE_EVENT0("flutter", "ClipPathLayer::Paint");
FML_DCHECK(needs_painting());

SkAutoCanvasRestore save(context.canvas, true);
context.canvas->clipPath(clip_path_, clip_behavior_ != Clip::hardEdge);
SkAutoCanvasRestore save(context.internal_nodes_canvas, true);
context.internal_nodes_canvas->clipPath(clip_path_,
clip_behavior_ != Clip::hardEdge);
if (clip_behavior_ == Clip::antiAliasWithSaveLayer) {
context.canvas->saveLayer(paint_bounds(), nullptr);
context.internal_nodes_canvas->saveLayer(paint_bounds(), nullptr);
}
PaintChildren(context);
if (clip_behavior_ == Clip::antiAliasWithSaveLayer) {
context.canvas->restore();
context.internal_nodes_canvas->restore();
}
}

Expand Down
9 changes: 5 additions & 4 deletions flow/layers/clip_rect_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ void ClipRectLayer::Paint(PaintContext& context) const {
TRACE_EVENT0("flutter", "ClipRectLayer::Paint");
FML_DCHECK(needs_painting());

SkAutoCanvasRestore save(context.canvas, true);
context.canvas->clipRect(paint_bounds(), clip_behavior_ != Clip::hardEdge);
SkAutoCanvasRestore save(context.internal_nodes_canvas, true);
context.internal_nodes_canvas->clipRect(paint_bounds(),
clip_behavior_ != Clip::hardEdge);
if (clip_behavior_ == Clip::antiAliasWithSaveLayer) {
context.canvas->saveLayer(paint_bounds(), nullptr);
context.internal_nodes_canvas->saveLayer(paint_bounds(), nullptr);
}
PaintChildren(context);
if (clip_behavior_ == Clip::antiAliasWithSaveLayer) {
context.canvas->restore();
context.internal_nodes_canvas->restore();
}
}

Expand Down
9 changes: 5 additions & 4 deletions flow/layers/clip_rrect_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@ void ClipRRectLayer::Paint(PaintContext& context) const {
TRACE_EVENT0("flutter", "ClipRRectLayer::Paint");
FML_DCHECK(needs_painting());

SkAutoCanvasRestore save(context.canvas, true);
context.canvas->clipRRect(clip_rrect_, clip_behavior_ != Clip::hardEdge);
SkAutoCanvasRestore save(context.internal_nodes_canvas, true);
context.internal_nodes_canvas->clipRRect(clip_rrect_,
clip_behavior_ != Clip::hardEdge);
if (clip_behavior_ == Clip::antiAliasWithSaveLayer) {
context.canvas->saveLayer(paint_bounds(), nullptr);
context.internal_nodes_canvas->saveLayer(paint_bounds(), nullptr);
}
PaintChildren(context);
if (clip_behavior_ == Clip::antiAliasWithSaveLayer) {
context.canvas->restore();
context.internal_nodes_canvas->restore();
}
}

Expand Down
8 changes: 4 additions & 4 deletions flow/layers/layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ Layer::AutoSaveLayer::AutoSaveLayer(const PaintContext& paint_context,
const SkRect& bounds,
const SkPaint* paint)
: paint_context_(paint_context), bounds_(bounds) {
paint_context_.canvas->saveLayer(bounds_, paint);
paint_context_.internal_nodes_canvas->saveLayer(bounds_, paint);
}

Layer::AutoSaveLayer::AutoSaveLayer(const PaintContext& paint_context,
const SkCanvas::SaveLayerRec& layer_rec)
: paint_context_(paint_context), bounds_(*layer_rec.fBounds) {
paint_context_.canvas->saveLayer(layer_rec);
paint_context_.internal_nodes_canvas->saveLayer(layer_rec);
}

Layer::AutoSaveLayer Layer::AutoSaveLayer::Create(
Expand All @@ -50,9 +50,9 @@ Layer::AutoSaveLayer Layer::AutoSaveLayer::Create(

Layer::AutoSaveLayer::~AutoSaveLayer() {
if (paint_context_.checkerboard_offscreen_layers) {
DrawCheckerboard(paint_context_.canvas, bounds_);
DrawCheckerboard(paint_context_.internal_nodes_canvas, bounds_);
}
paint_context_.canvas->restore();
paint_context_.internal_nodes_canvas->restore();
}

} // namespace flow
6 changes: 1 addition & 5 deletions flow/layers/layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,7 @@ class Layer {
// The leaf_nodes_canvas is the "current" canvas and is used by leaf
// layers.
SkCanvas* internal_nodes_canvas;
// I'm temporarily leaving the name of this field to be canvas to reduce
// noise in the incremental change. A followup change will rename this
// and use the corrrect canvas in each callsite.
// TODO(amirh) rename canvas to leaf_nodes_canvas.
SkCanvas* canvas;
SkCanvas* leaf_nodes_canvas;
ExternalViewEmbedder* view_embedder;
const Stopwatch& frame_time;
const Stopwatch& engine_time;
Expand Down
12 changes: 6 additions & 6 deletions flow/layers/opacity_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ void OpacityLayer::Paint(PaintContext& context) const {
SkPaint paint;
paint.setAlpha(alpha_);

SkAutoCanvasRestore save(context.canvas, true);
context.canvas->translate(offset_.fX, offset_.fY);
SkAutoCanvasRestore save(context.internal_nodes_canvas, true);
context.internal_nodes_canvas->translate(offset_.fX, offset_.fY);

#ifndef SUPPORT_FRACTIONAL_TRANSLATION
context.canvas->setMatrix(
RasterCache::GetIntegralTransCTM(context.canvas->getTotalMatrix()));
context.internal_nodes_canvas->setMatrix(RasterCache::GetIntegralTransCTM(
context.leaf_nodes_canvas->getTotalMatrix()));
#endif

// Embedded platform views are changing the canvas in the middle of the paint
Expand All @@ -45,11 +45,11 @@ void OpacityLayer::Paint(PaintContext& context) const {
// don't use the cache.
if (context.view_embedder == nullptr && layers().size() == 1 &&
context.raster_cache) {
const SkMatrix& ctm = context.canvas->getTotalMatrix();
const SkMatrix& ctm = context.leaf_nodes_canvas->getTotalMatrix();
RasterCacheResult child_cache =
context.raster_cache->Get(layers()[0].get(), ctm);
if (child_cache.is_valid()) {
child_cache.draw(*context.canvas, &paint);
child_cache.draw(*context.leaf_nodes_canvas, &paint);
return;
}
}
Expand Down
11 changes: 6 additions & 5 deletions flow/layers/performance_overlay_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,16 @@ void PerformanceOverlayLayer::Paint(PaintContext& context) const {
SkScalar y = paint_bounds().y() + padding;
SkScalar width = paint_bounds().width() - (padding * 2);
SkScalar height = paint_bounds().height() / 2;
SkAutoCanvasRestore save(context.canvas, true);
SkAutoCanvasRestore save(context.leaf_nodes_canvas, true);

VisualizeStopWatch(*context.canvas, context.frame_time, x, y, width,
height - padding,
VisualizeStopWatch(*context.leaf_nodes_canvas, context.frame_time, x, y,
width, height - padding,
options_ & kVisualizeRasterizerStatistics,
options_ & kDisplayRasterizerStatistics, "GPU");

VisualizeStopWatch(*context.canvas, context.engine_time, x, y + height, width,
height - padding, options_ & kVisualizeEngineStatistics,
VisualizeStopWatch(*context.leaf_nodes_canvas, context.engine_time, x,
y + height, width, height - padding,
options_ & kVisualizeEngineStatistics,
options_ & kDisplayEngineStatistics, "UI");
}

Expand Down
18 changes: 9 additions & 9 deletions flow/layers/physical_shape_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,28 +83,28 @@ void PhysicalShapeLayer::Paint(PaintContext& context) const {
FML_DCHECK(needs_painting());

if (elevation_ != 0) {
DrawShadow(context.canvas, path_, shadow_color_, elevation_,
DrawShadow(context.leaf_nodes_canvas, path_, shadow_color_, elevation_,
SkColorGetA(color_) != 0xff, device_pixel_ratio_);
}

// Call drawPath without clip if possible for better performance.
SkPaint paint;
paint.setColor(color_);
if (clip_behavior_ != Clip::antiAliasWithSaveLayer) {
context.canvas->drawPath(path_, paint);
context.leaf_nodes_canvas->drawPath(path_, paint);
}

int saveCount = context.canvas->save();
int saveCount = context.internal_nodes_canvas->save();
switch (clip_behavior_) {
case Clip::hardEdge:
context.canvas->clipPath(path_, false);
context.internal_nodes_canvas->clipPath(path_, false);
break;
case Clip::antiAlias:
context.canvas->clipPath(path_, true);
context.internal_nodes_canvas->clipPath(path_, true);
break;
case Clip::antiAliasWithSaveLayer:
context.canvas->clipPath(path_, true);
context.canvas->saveLayer(paint_bounds(), nullptr);
context.internal_nodes_canvas->clipPath(path_, true);
context.internal_nodes_canvas->saveLayer(paint_bounds(), nullptr);
break;
case Clip::none:
break;
Expand All @@ -115,12 +115,12 @@ void PhysicalShapeLayer::Paint(PaintContext& context) const {
// (https://github.com/flutter/flutter/issues/18057#issue-328003931)
// using saveLayer, we have to call drawPaint instead of drawPath as
// anti-aliased drawPath will always have such artifacts.
context.canvas->drawPaint(paint);
context.leaf_nodes_canvas->drawPaint(paint);
}

PaintChildren(context);

context.canvas->restoreToCount(saveCount);
context.internal_nodes_canvas->restoreToCount(saveCount);
}

void PhysicalShapeLayer::DrawShadow(SkCanvas* canvas,
Expand Down
14 changes: 7 additions & 7 deletions flow/layers/picture_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,22 @@ void PictureLayer::Paint(PaintContext& context) const {
FML_DCHECK(picture_.get());
FML_DCHECK(needs_painting());

SkAutoCanvasRestore save(context.canvas, true);
context.canvas->translate(offset_.x(), offset_.y());
SkAutoCanvasRestore save(context.leaf_nodes_canvas, true);
context.leaf_nodes_canvas->translate(offset_.x(), offset_.y());
#ifndef SUPPORT_FRACTIONAL_TRANSLATION
context.canvas->setMatrix(
RasterCache::GetIntegralTransCTM(context.canvas->getTotalMatrix()));
context.leaf_nodes_canvas->setMatrix(RasterCache::GetIntegralTransCTM(
context.leaf_nodes_canvas->getTotalMatrix()));
#endif

if (context.raster_cache) {
const SkMatrix& ctm = context.canvas->getTotalMatrix();
const SkMatrix& ctm = context.leaf_nodes_canvas->getTotalMatrix();
RasterCacheResult result = context.raster_cache->Get(*picture(), ctm);
if (result.is_valid()) {
result.draw(*context.canvas);
result.draw(*context.leaf_nodes_canvas);
return;
}
}
context.canvas->drawPicture(picture());
context.leaf_nodes_canvas->drawPicture(picture());
}

} // namespace flow
4 changes: 2 additions & 2 deletions flow/layers/platform_view_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ void PlatformViewLayer::Paint(PaintContext& context) const {
return;
}
EmbeddedViewParams params;
SkMatrix transform = context.canvas->getTotalMatrix();
SkMatrix transform = context.leaf_nodes_canvas->getTotalMatrix();
params.offsetPixels =
SkPoint::Make(transform.getTranslateX(), transform.getTranslateY());
params.sizePoints = size_;

SkCanvas* canvas =
context.view_embedder->CompositeEmbeddedView(view_id_, params);
context.canvas = canvas;
context.leaf_nodes_canvas = canvas;
}
} // namespace flow
4 changes: 2 additions & 2 deletions flow/layers/shader_mask_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ void ShaderMaskLayer::Paint(PaintContext& context) const {
SkPaint paint;
paint.setBlendMode(blend_mode_);
paint.setShader(shader_);
context.canvas->translate(mask_rect_.left(), mask_rect_.top());
context.canvas->drawRect(
context.leaf_nodes_canvas->translate(mask_rect_.left(), mask_rect_.top());
context.leaf_nodes_canvas->drawRect(
SkRect::MakeWH(mask_rect_.width(), mask_rect_.height()), paint);
}

Expand Down
2 changes: 1 addition & 1 deletion flow/layers/texture_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void TextureLayer::Paint(PaintContext& context) const {
if (!texture) {
return;
}
texture->Paint(*context.canvas, paint_bounds(), freeze_);
texture->Paint(*context.leaf_nodes_canvas, paint_bounds(), freeze_);
}

} // namespace flow