Flutter Engine
flutter::TransformLayer Class Reference

#include <transform_layer.h>

Inheritance diagram for flutter::TransformLayer:
flutter::ContainerLayer flutter::Layer

Public Member Functions

 TransformLayer (const SkMatrix &transform)
 
void Preroll (PrerollContext *context, const SkMatrix &matrix) override
 
void Paint (PaintContext &context) const override
 
- Public Member Functions inherited from flutter::ContainerLayer
 ContainerLayer ()
 
virtual void Add (std::shared_ptr< Layer > layer)
 
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::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 14 of file transform_layer.h.

Constructor & Destructor Documentation

◆ TransformLayer()

flutter::TransformLayer::TransformLayer ( const SkMatrix &  transform)

Definition at line 11 of file transform_layer.cc.

References FML_DCHECK, and FML_LOG.

12  : transform_(transform) {
13  // Checks (in some degree) that SkMatrix transform_ is valid and initialized.
14  //
15  // If transform_ is uninitialized, this assert may look flaky as it doesn't
16  // fail all the time, and some rerun may make it pass. But don't ignore it and
17  // just rerun the test if this is triggered, since even a flaky failure here
18  // may signify a potentially big problem in the code.
19  //
20  // We have to write this flaky test because there is no reliable way to test
21  // whether a variable is initialized or not in C++.
22  FML_DCHECK(transform_.isFinite());
23  if (!transform_.isFinite()) {
24  FML_LOG(ERROR) << "TransformLayer is constructed with an invalid matrix.";
25  transform_.setIdentity();
26  }
27 }
#define FML_DCHECK(condition)
Definition: logging.h:86
#define FML_LOG(severity)
Definition: logging.h:65

Member Function Documentation

◆ Paint()

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

Reimplemented from flutter::ContainerLayer.

Definition at line 71 of file transform_layer.cc.

References FML_DCHECK, flutter::Layer::PaintContext::internal_nodes_canvas, flutter::Layer::needs_painting(), flutter::ContainerLayer::PaintChildren(), and TRACE_EVENT0.

71  {
72  TRACE_EVENT0("flutter", "TransformLayer::Paint");
74 
75  SkAutoCanvasRestore save(context.internal_nodes_canvas, true);
76  context.internal_nodes_canvas->concat(transform_);
77 
78  PaintChildren(context);
79 }
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:75
#define FML_DCHECK(condition)
Definition: logging.h:86
bool needs_painting() const
Definition: layer.h:174
void PaintChildren(PaintContext &context) const

◆ Preroll()

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

Reimplemented from flutter::ContainerLayer.

Definition at line 29 of file transform_layer.cc.

References flutter::PrerollContext::cull_rect, FML_DCHECK, flutter::kGiantRect, flutter::PrerollContext::mutators_stack, flutter::Layer::needs_system_composite(), flutter::MutatorsStack::Pop(), flutter::ContainerLayer::PrerollChildren(), flutter::MutatorsStack::PushTransform(), flutter::Layer::set_paint_bounds(), TRACE_EVENT0, and flutter::transform.

29  {
30  TRACE_EVENT0("flutter", "TransformLayer::Preroll");
31 
32  SkMatrix child_matrix;
33  child_matrix.setConcat(matrix, transform_);
34  context->mutators_stack.PushTransform(transform_);
35  SkRect previous_cull_rect = context->cull_rect;
36  SkMatrix inverse_transform_;
37  // Perspective projections don't produce rectangles that are useful for
38  // culling for some reason.
39  if (!transform_.hasPerspective() && transform_.invert(&inverse_transform_)) {
40  inverse_transform_.mapRect(&context->cull_rect);
41  } else {
42  context->cull_rect = kGiantRect;
43  }
44 
45  SkRect child_paint_bounds = SkRect::MakeEmpty();
46  PrerollChildren(context, child_matrix, &child_paint_bounds);
47 
48  transform_.mapRect(&child_paint_bounds);
49  set_paint_bounds(child_paint_bounds);
50 
51  context->cull_rect = previous_cull_rect;
52  context->mutators_stack.Pop();
53 }
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:75
void PrerollChildren(PrerollContext *context, const SkMatrix &child_matrix, SkRect *child_paint_bounds)
static constexpr SkRect kGiantRect
Definition: layer.h:38
void set_paint_bounds(const SkRect &paint_bounds)
Definition: layer.h:170

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