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 ()
 
bool needs_system_composite () const
 
void set_needs_system_composite (bool value)
 
const SkRect & paint_bounds () const
 
void set_paint_bounds (const SkRect &paint_bounds)
 
bool needs_painting () 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.

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

Member Function Documentation

◆ Paint()

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

Reimplemented from flutter::ContainerLayer.

Definition at line 47 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.

47  {
48  TRACE_EVENT0("flutter", "OpacityLayer::Paint");
50 
51  SkPaint paint;
52  paint.setAlpha(alpha_);
53 
54  SkAutoCanvasRestore save(context.internal_nodes_canvas, true);
55  context.internal_nodes_canvas->translate(offset_.fX, offset_.fY);
56 
57 #ifndef SUPPORT_FRACTIONAL_TRANSLATION
58  context.internal_nodes_canvas->setMatrix(RasterCache::GetIntegralTransCTM(
59  context.leaf_nodes_canvas->getTotalMatrix()));
60 #endif
61 
62  if (context.raster_cache &&
63  context.raster_cache->Draw(GetCacheableChild(),
64  *context.leaf_nodes_canvas, &paint)) {
65  return;
66  }
67 
68  // Skia may clip the content with saveLayerBounds (although it's not a
69  // guaranteed clip). So we have to provide a big enough saveLayerBounds. To do
70  // so, we first remove the offset from paint bounds since it's already in the
71  // matrix. Then we round out the bounds.
72  //
73  // Note that the following lines are only accessible when the raster cache is
74  // not available (e.g., when we're using the software backend in golden
75  // tests).
76  SkRect saveLayerBounds;
77  paint_bounds()
78  .makeOffset(-offset_.fX, -offset_.fY)
79  .roundOut(&saveLayerBounds);
80 
81  Layer::AutoSaveLayer save_layer =
82  Layer::AutoSaveLayer::Create(context, saveLayerBounds, &paint);
83  PaintChildren(context);
84 }
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:75
#define FML_DCHECK(condition)
Definition: logging.h:86
static AutoSaveLayer Create(const PaintContext &paint_context, const SkRect &bounds, const SkPaint *paint)
Definition: layer.cc:96
Layer * GetCacheableChild() const
Returns the best choice for a Layer object that can be used in RasterCache operations to cache the ch...
bool needs_painting() const
Definition: layer.h:174
const SkRect & paint_bounds() const
Definition: layer.h:166
static SkMatrix GetIntegralTransCTM(const SkMatrix &ctm)
Snap the translation components of the matrix to integers.
Definition: raster_cache.h:115
void PaintChildren(PaintContext &context) const

◆ Preroll()

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

Reimplemented from flutter::ContainerLayer.

Definition at line 15 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().

15  {
16  TRACE_EVENT0("flutter", "OpacityLayer::Preroll");
17  FML_DCHECK(!GetChildContainer()->layers().empty()); // We can't be a leaf.
18 
19  SkMatrix child_matrix = matrix;
20  child_matrix.postTranslate(offset_.fX, offset_.fY);
21 
22  // Similar to what's done in TransformLayer::Preroll, we have to apply the
23  // reverse transformation to the cull rect to properly cull child layers.
24  context->cull_rect = context->cull_rect.makeOffset(-offset_.fX, -offset_.fY);
25 
26  context->mutators_stack.PushTransform(
27  SkMatrix::Translate(offset_.fX, offset_.fY));
28  context->mutators_stack.PushOpacity(alpha_);
29  Layer::AutoPrerollSaveLayerState save =
31  ContainerLayer::Preroll(context, child_matrix);
32  context->mutators_stack.Pop();
33  context->mutators_stack.Pop();
34 
35  {
36  set_paint_bounds(paint_bounds().makeOffset(offset_.fX, offset_.fY));
37 #ifndef SUPPORT_FRACTIONAL_TRANSLATION
38  child_matrix = RasterCache::GetIntegralTransCTM(child_matrix);
39 #endif
40  TryToPrepareRasterCache(context, GetCacheableChild(), child_matrix);
41  }
42 
43  // Restore cull_rect
44  context->cull_rect = context->cull_rect.makeOffset(offset_.fX, offset_.fY);
45 }
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:75
#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:43
const SkRect & paint_bounds() const
Definition: layer.h:166
void Preroll(PrerollContext *context, const SkMatrix &matrix) override
void set_paint_bounds(const SkRect &paint_bounds)
Definition: layer.h:170
static SkMatrix GetIntegralTransCTM(const SkMatrix &ctm)
Snap the translation components of the matrix to integers.
Definition: raster_cache.h:115
static void TryToPrepareRasterCache(PrerollContext *context, Layer *layer, const SkMatrix &matrix)

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