Skip to content

Commit

Permalink
Fix according to Jim's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
liyuqian committed Apr 24, 2020
1 parent 54a623b commit 03ccad2
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
9 changes: 9 additions & 0 deletions flow/layers/container_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ void ContainerLayer::PaintChildren(PaintContext& context) const {
}
}

void ContainerLayer::TryToPrepareRasterCache(PrerollContext* context,
Layer* layer,
const SkMatrix& matrix) {
if (!context->has_platform_view && context->raster_cache &&
SkRect::Intersects(context->cull_rect, layer->paint_bounds())) {
context->raster_cache->Prepare(context, layer, matrix);
}
}

#if defined(OS_FUCHSIA)

void ContainerLayer::UpdateScene(SceneUpdateContext& context) {
Expand Down
14 changes: 14 additions & 0 deletions flow/layers/container_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ class ContainerLayer : public Layer {
// For OpacityLayer to restructure to have a single child.
void ClearChildren() { layers_.clear(); }

// Try to prepare the raster cache for a given layer.
//
// The raster cache would fail if either of the followings is true:
// 1. The context has a platform view.
// 2. The context does not have a valid raster cache.
// 3. The layer's paint bounds does not intersect with the cull rect.
//
// We make this a static function instead of a member function that directy
// uses the "this" pointer as the layer because we sometimes need to raster
// cache a child layer and one can't access its child's protected method.
static void TryToPrepareRasterCache(PrerollContext* context,
Layer* layer,
const SkMatrix& matrix);

private:
std::vector<std::shared_ptr<Layer>> layers_;

Expand Down
6 changes: 1 addition & 5 deletions flow/layers/image_filter_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ void ImageFilterLayer::Preroll(PrerollContext* context,
set_paint_bounds(child_paint_bounds_);
}

if (!context->has_platform_view && context->raster_cache &&
SkRect::Intersects(context->cull_rect, paint_bounds())) {
SkMatrix ctm = matrix;
context->raster_cache->Prepare(context, this, ctm);
}
TryToPrepareRasterCache(context, this, matrix);
}

void ImageFilterLayer::Paint(PaintContext& context) const {
Expand Down
6 changes: 1 addition & 5 deletions flow/layers/opacity_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ void OpacityLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {

{
set_paint_bounds(paint_bounds().makeOffset(offset_.fX, offset_.fY));
if (!context->has_platform_view && context->raster_cache &&
SkRect::Intersects(context->cull_rect, paint_bounds())) {
SkMatrix ctm = child_matrix;
context->raster_cache->Prepare(context, container, ctm);
}
TryToPrepareRasterCache(context, container, child_matrix);
}
}

Expand Down
3 changes: 0 additions & 3 deletions flow/raster_cache_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,6 @@ TEST(RasterCache, DeviceRectRoundOut) {
ASSERT_TRUE(cache.Draw(*picture, canvas));

canvas.translate(248, 0);
#ifndef SUPPORT_FRACTIONAL_TRANSLATION
canvas.setMatrix(RasterCache::GetIntegralTransCTM(canvas.getTotalMatrix()));
#endif
ASSERT_TRUE(cache.Draw(*picture, canvas));
}

Expand Down

0 comments on commit 03ccad2

Please sign in to comment.