Flutter Engine
flutter::OpacityLayer Class Reference

#include <opacity_layer.h>

Inheritance diagram for flutter::OpacityLayer:
flutter::MergedContainerLayer flutter::ContainerLayer flutter::Layer

Public Member Functions

 OpacityLayer (SkAlpha alpha, const SkPoint &offset)
 
void Preroll (PrerollContext *context, const SkMatrix &matrix) override
 
void Paint (PaintContext &context) const override
 
- Public Member Functions inherited from flutter::MergedContainerLayer
 MergedContainerLayer ()
 
void Add (std::shared_ptr< Layer > layer) override
 
- Public Member Functions inherited from flutter::ContainerLayer
 ContainerLayer ()
 
const std::vector< std::shared_ptr< Layer > > & layers () const
 
- Public Member Functions inherited from flutter::Layer
 Layer ()
 
virtual ~Layer ()
 
void AssignOldLayer (Layer *old_layer)
 
bool subtree_has_platform_view () const
 
void set_subtree_has_platform_view (bool value)
 
const SkRect & paint_bounds () const
 
void set_paint_bounds (const SkRect &paint_bounds)
 
bool is_empty () const
 
bool needs_painting (PaintContext &context) const
 
uint64_t original_layer_id () const
 
uint64_t unique_id () const
 

Additional Inherited Members

- Protected Member Functions inherited from flutter::MergedContainerLayer
ContainerLayerGetChildContainer () const
 Returns the ContainerLayer used to hold all of the children of the MergedContainerLayer. Note that this may not be the best layer to use for caching the children. More...
 
LayerGetCacheableChild () const
 Returns the best choice for a Layer object that can be used in RasterCache operations to cache the children. More...
 
- Protected Member Functions inherited from flutter::ContainerLayer
void PrerollChildren (PrerollContext *context, const SkMatrix &child_matrix, SkRect *child_paint_bounds)
 
void PaintChildren (PaintContext &context) const
 
- Static Protected Member Functions inherited from flutter::ContainerLayer
static void TryToPrepareRasterCache (PrerollContext *context, Layer *layer, const SkMatrix &matrix)
 

Detailed Description

Definition at line 16 of file opacity_layer.h.

Constructor & Destructor Documentation

◆ OpacityLayer()

flutter::OpacityLayer::OpacityLayer ( SkAlpha  alpha,
const SkPoint &  offset 
)

Definition at line 12 of file opacity_layer.cc.

References FML_DCHECK, and flutter::RasterCache::GetIntegralTransCTM().

13  : alpha_(alpha), offset_(offset) {}

Member Function Documentation

◆ Paint()

void flutter::OpacityLayer::Paint ( PaintContext context) const
overridevirtual

Reimplemented from flutter::ContainerLayer.

Definition at line 69 of file opacity_layer.cc.

References flutter::Layer::AutoSaveLayer::Create(), flutter::RasterCache::Draw(), FML_DCHECK, flutter::MergedContainerLayer::GetCacheableChild(), flutter::RasterCache::GetIntegralTransCTM(), flutter::Layer::PaintContext::internal_nodes_canvas, flutter::Layer::PaintContext::leaf_nodes_canvas, flutter::Layer::needs_painting(), flutter::Layer::paint_bounds(), flutter::ContainerLayer::PaintChildren(), flutter::Layer::PaintContext::raster_cache, and TRACE_EVENT0.

69  {
70  TRACE_EVENT0("flutter", "OpacityLayer::Paint");
71  FML_DCHECK(needs_painting(context));
72 
73  SkPaint paint;
74  paint.setAlpha(alpha_);
75 
76  SkAutoCanvasRestore save(context.internal_nodes_canvas, true);
77  context.internal_nodes_canvas->translate(offset_.fX, offset_.fY);
78 
79 #ifndef SUPPORT_FRACTIONAL_TRANSLATION
80  context.internal_nodes_canvas->setMatrix(RasterCache::GetIntegralTransCTM(
81  context.leaf_nodes_canvas->getTotalMatrix()));
82 #endif
83 
84  if (context.raster_cache &&
85  context.raster_cache->Draw(GetCacheableChild(),
86  *context.leaf_nodes_canvas, &paint)) {
87  return;
88  }
89 
90  // Skia may clip the content with saveLayerBounds (although it's not a
91  // guaranteed clip). So we have to provide a big enough saveLayerBounds. To do
92  // so, we first remove the offset from paint bounds since it's already in the
93  // matrix. Then we round out the bounds.
94  //
95  // Note that the following lines are only accessible when the raster cache is
96  // not available (e.g., when we're using the software backend in golden
97  // tests).
98  SkRect saveLayerBounds;
99  paint_bounds()
100  .makeOffset(-offset_.fX, -offset_.fY)
101  .roundOut(&saveLayerBounds);
102 
103  Layer::AutoSaveLayer save_layer =
104  Layer::AutoSaveLayer::Create(context, saveLayerBounds, &paint);
105  PaintChildren(context);
106 }
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:90
#define FML_DCHECK(condition)
Definition: logging.h:86
bool needs_painting(PaintContext &context) const
Definition: layer.h:249
Layer * GetCacheableChild() const
Returns the best choice for a Layer object that can be used in RasterCache operations to cache the ch...
const SkRect & paint_bounds() const
Definition: layer.h:227
static SkMatrix GetIntegralTransCTM(const SkMatrix &ctm)
Snap the translation components of the matrix to integers.
Definition: raster_cache.h:126
void PaintChildren(PaintContext &context) const
static AutoSaveLayer Create(const PaintContext &paint_context, const SkRect &bounds, const SkPaint *paint, SaveMode save_mode=SaveMode::kInternalNodesCanvas)
Definition: layer.cc:82

◆ Preroll()

void flutter::OpacityLayer::Preroll ( PrerollContext context,
const SkMatrix &  matrix 
)
overridevirtual

Reimplemented from flutter::ContainerLayer.

Definition at line 37 of file opacity_layer.cc.

References flutter::Layer::AutoPrerollSaveLayerState::Create(), flutter::PrerollContext::cull_rect, FML_DCHECK, flutter::MergedContainerLayer::GetCacheableChild(), flutter::MergedContainerLayer::GetChildContainer(), flutter::RasterCache::GetIntegralTransCTM(), flutter::ContainerLayer::layers(), flutter::PrerollContext::mutators_stack, flutter::Layer::paint_bounds(), flutter::MutatorsStack::Pop(), flutter::ContainerLayer::Preroll(), flutter::MutatorsStack::PushOpacity(), flutter::MutatorsStack::PushTransform(), flutter::Layer::set_paint_bounds(), TRACE_EVENT0, and flutter::ContainerLayer::TryToPrepareRasterCache().

37  {
38  TRACE_EVENT0("flutter", "OpacityLayer::Preroll");
39  FML_DCHECK(!GetChildContainer()->layers().empty()); // We can't be a leaf.
40 
41  SkMatrix child_matrix = matrix;
42  child_matrix.preTranslate(offset_.fX, offset_.fY);
43 
44  // Similar to what's done in TransformLayer::Preroll, we have to apply the
45  // reverse transformation to the cull rect to properly cull child layers.
46  context->cull_rect = context->cull_rect.makeOffset(-offset_.fX, -offset_.fY);
47 
48  context->mutators_stack.PushTransform(
49  SkMatrix::Translate(offset_.fX, offset_.fY));
50  context->mutators_stack.PushOpacity(alpha_);
51  Layer::AutoPrerollSaveLayerState save =
53  ContainerLayer::Preroll(context, child_matrix);
54  context->mutators_stack.Pop();
55  context->mutators_stack.Pop();
56 
57  {
58  set_paint_bounds(paint_bounds().makeOffset(offset_.fX, offset_.fY));
59 #ifndef SUPPORT_FRACTIONAL_TRANSLATION
60  child_matrix = RasterCache::GetIntegralTransCTM(child_matrix);
61 #endif
62  TryToPrepareRasterCache(context, GetCacheableChild(), child_matrix);
63  }
64 
65  // Restore cull_rect
66  context->cull_rect = context->cull_rect.makeOffset(offset_.fX, offset_.fY);
67 }
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:90
#define FML_DCHECK(condition)
Definition: logging.h:86
const std::vector< std::shared_ptr< Layer > > & layers() const
Layer * GetCacheableChild() const
Returns the best choice for a Layer object that can be used in RasterCache operations to cache the ch...
ContainerLayer * GetChildContainer() const
Returns the ContainerLayer used to hold all of the children of the MergedContainerLayer. Note that this may not be the best layer to use for caching the children.
static AutoPrerollSaveLayerState Create(PrerollContext *preroll_context, bool save_layer_is_active=true, bool layer_itself_performs_readback=false)
Definition: layer.cc:44
const SkRect & paint_bounds() const
Definition: layer.h:227
void Preroll(PrerollContext *context, const SkMatrix &matrix) override
void set_paint_bounds(const SkRect &paint_bounds)
Definition: layer.h:240
static SkMatrix GetIntegralTransCTM(const SkMatrix &ctm)
Snap the translation components of the matrix to integers.
Definition: raster_cache.h:126
static void TryToPrepareRasterCache(PrerollContext *context, Layer *layer, const SkMatrix &matrix)

The documentation for this class was generated from the following files: