Flutter Engine
flutter::PhysicalShapeLayer Class Reference

#include <physical_shape_layer.h>

Inheritance diagram for flutter::PhysicalShapeLayer:
flutter::ContainerLayer flutter::Layer

Public Member Functions

 PhysicalShapeLayer (SkColor color, SkColor shadow_color, float elevation, const SkPath &path, Clip clip_behavior)
 
void Diff (DiffContext *context, const Layer *old_layer) override
 
void Preroll (PrerollContext *context, const SkMatrix &matrix) override
 
void Paint (PaintContext &context) const override
 
bool UsesSaveLayer () const
 
float elevation () const
 
- Public Member Functions inherited from flutter::ContainerLayer
 ContainerLayer ()
 
void PreservePaintRegion (DiffContext *context) override
 
virtual void Add (std::shared_ptr< Layer > layer)
 
const std::vector< std::shared_ptr< Layer > > & layers () const
 
virtual void DiffChildren (DiffContext *context, const ContainerLayer *old_layer)
 
- Public Member Functions inherited from flutter::Layer
 Layer ()
 
virtual ~Layer ()
 
void AssignOldLayer (Layer *old_layer)
 
virtual bool IsReplacing (DiffContext *context, const Layer *old_layer) const
 
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
 
virtual const PictureLayeras_picture_layer () const
 
virtual const DisplayListLayeras_display_list_layer () const
 
virtual const TextureLayeras_texture_layer () const
 
virtual const PerformanceOverlayLayeras_performance_overlay_layer () const
 
virtual const testing::MockLayeras_mock_layer () const
 

Static Public Member Functions

static SkRect ComputeShadowBounds (const SkPath &path, float elevation, SkScalar dpr, const SkMatrix &ctm)
 
static void DrawShadow (SkCanvas *canvas, const SkPath &path, SkColor color, float elevation, bool transparentOccluder, SkScalar dpr)
 

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 12 of file physical_shape_layer.h.

Constructor & Destructor Documentation

◆ PhysicalShapeLayer()

flutter::PhysicalShapeLayer::PhysicalShapeLayer ( SkColor  color,
SkColor  shadow_color,
float  elevation,
const SkPath &  path,
Clip  clip_behavior 
)

Definition at line 15 of file physical_shape_layer.cc.

20  : color_(color),
21  shadow_color_(shadow_color),
22  elevation_(elevation),
23  path_(path),
24  clip_behavior_(clip_behavior) {}
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57

Member Function Documentation

◆ ComputeShadowBounds()

SkRect flutter::PhysicalShapeLayer::ComputeShadowBounds ( const SkPath &  path,
float  elevation,
SkScalar  dpr,
const SkMatrix &  ctm 
)
static

Definition at line 129 of file physical_shape_layer.cc.

Referenced by Diff(), flutter::DisplayListBoundsCalculator::drawShadow(), Preroll(), and flutter::testing::TEST_F().

132  {
133  SkRect shadow_bounds(path.getBounds());
134  SkShadowUtils::GetLocalBounds(
135  ctm, path, SkPoint3::Make(0, 0, dpr * elevation),
136  SkPoint3::Make(0, -1, 1), kLightRadius / kLightHeight,
137  SkShadowFlags::kDirectionalLight_ShadowFlag, &shadow_bounds);
138  return shadow_bounds;
139 }
const SkScalar kLightHeight
const SkScalar kLightRadius
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57

◆ Diff()

void flutter::PhysicalShapeLayer::Diff ( DiffContext context,
const Layer old_layer 
)
overridevirtual

Reimplemented from flutter::ContainerLayer.

Definition at line 26 of file physical_shape_layer.cc.

References flutter::DiffContext::AddLayerBounds(), ComputeShadowBounds(), flutter::DiffContext::CurrentSubtreeRegion(), flutter::ContainerLayer::DiffChildren(), FML_DCHECK, flutter::DiffContext::frame_device_pixel_ratio(), flutter::DiffContext::GetOldLayerPaintRegion(), flutter::DiffContext::GetTransform(), flutter::DiffContext::IsSubtreeDirty(), flutter::DiffContext::MarkSubtreeDirty(), flutter::none, flutter::DiffContext::PushCullRect(), and flutter::DiffContext::SetLayerPaintRegion().

26  {
27  DiffContext::AutoSubtreeRestore subtree(context);
28  auto* prev = static_cast<const PhysicalShapeLayer*>(old_layer);
29  if (!context->IsSubtreeDirty()) {
30  FML_DCHECK(prev);
31  if (color_ != prev->color_ || shadow_color_ != prev->shadow_color_ ||
32  elevation_ != prev->elevation() || path_ != prev->path_ ||
33  clip_behavior_ != prev->clip_behavior_) {
34  context->MarkSubtreeDirty(context->GetOldLayerPaintRegion(old_layer));
35  }
36  }
37 
38  SkRect bounds;
39  if (elevation_ == 0) {
40  bounds = path_.getBounds();
41  } else {
42  bounds = ComputeShadowBounds(path_, elevation_,
43  context->frame_device_pixel_ratio(),
44  context->GetTransform());
45  }
46 
47  context->AddLayerBounds(bounds);
48 
49  // Only push cull rect if there is clip.
50  if (clip_behavior_ == Clip::none || context->PushCullRect(bounds)) {
51  DiffChildren(context, prev);
52  }
53  context->SetLayerPaintRegion(this, context->CurrentSubtreeRegion());
54 }
#define FML_DCHECK(condition)
Definition: logging.h:86
static SkRect ComputeShadowBounds(const SkPath &path, float elevation, SkScalar dpr, const SkMatrix &ctm)
virtual void DiffChildren(DiffContext *context, const ContainerLayer *old_layer)
PhysicalShapeLayer(SkColor color, SkColor shadow_color, float elevation, const SkPath &path, Clip clip_behavior)

◆ DrawShadow()

void flutter::PhysicalShapeLayer::DrawShadow ( SkCanvas *  canvas,
const SkPath &  path,
SkColor  color,
float  elevation,
bool  transparentOccluder,
SkScalar  dpr 
)
static

Definition at line 141 of file physical_shape_layer.cc.

References flags.

Referenced by flutter::DisplayListCanvasDispatcher::drawShadow(), flutter::Canvas::drawShadow(), Paint(), and flutter::testing::TEST_F().

146  {
147  const SkScalar kAmbientAlpha = 0.039f;
148  const SkScalar kSpotAlpha = 0.25f;
149 
150  uint32_t flags = transparentOccluder
151  ? SkShadowFlags::kTransparentOccluder_ShadowFlag
152  : SkShadowFlags::kNone_ShadowFlag;
153  flags |= SkShadowFlags::kDirectionalLight_ShadowFlag;
154  SkColor inAmbient = SkColorSetA(color, kAmbientAlpha * SkColorGetA(color));
155  SkColor inSpot = SkColorSetA(color, kSpotAlpha * SkColorGetA(color));
156  SkColor ambientColor, spotColor;
157  SkShadowUtils::ComputeTonalColors(inAmbient, inSpot, &ambientColor,
158  &spotColor);
159  SkShadowUtils::DrawShadow(canvas, path, SkPoint3::Make(0, 0, dpr * elevation),
160  SkPoint3::Make(0, -1, 1),
161  kLightRadius / kLightHeight, ambientColor,
162  spotColor, flags);
163 }
const SkScalar kLightHeight
FlutterSemanticsFlag flags
const SkScalar kLightRadius
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57

◆ elevation()

float flutter::PhysicalShapeLayer::elevation ( ) const
inline

Definition at line 41 of file physical_shape_layer.h.

41 { return elevation_; }

◆ Paint()

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

Reimplemented from flutter::ContainerLayer.

Definition at line 76 of file physical_shape_layer.cc.

References flutter::antiAlias, flutter::antiAliasWithSaveLayer, flutter::Layer::PaintContext::checkerboard_offscreen_layers, flutter::DrawCheckerboard(), DrawShadow(), FML_DCHECK, flutter::Layer::PaintContext::frame_device_pixel_ratio, flutter::hardEdge, flutter::Layer::PaintContext::internal_nodes_canvas, flutter::Layer::PaintContext::leaf_nodes_canvas, flutter::Layer::needs_painting(), flutter::none, flutter::Layer::paint_bounds(), flutter::ContainerLayer::PaintChildren(), TRACE_EVENT0, and UsesSaveLayer().

76  {
77  TRACE_EVENT0("flutter", "PhysicalShapeLayer::Paint");
78  FML_DCHECK(needs_painting(context));
79 
80  if (elevation_ != 0) {
81  DrawShadow(context.leaf_nodes_canvas, path_, shadow_color_, elevation_,
82  SkColorGetA(color_) != 0xff, context.frame_device_pixel_ratio);
83  }
84 
85  // Call drawPath without clip if possible for better performance.
86  SkPaint paint;
87  paint.setColor(color_);
88  paint.setAntiAlias(true);
89  if (clip_behavior_ != Clip::antiAliasWithSaveLayer) {
90  context.leaf_nodes_canvas->drawPath(path_, paint);
91  }
92 
93  int saveCount = context.internal_nodes_canvas->save();
94  switch (clip_behavior_) {
95  case Clip::hardEdge:
96  context.internal_nodes_canvas->clipPath(path_, false);
97  break;
98  case Clip::antiAlias:
99  context.internal_nodes_canvas->clipPath(path_, true);
100  break;
102  TRACE_EVENT0("flutter", "Canvas::saveLayer");
103  context.internal_nodes_canvas->clipPath(path_, true);
104  context.internal_nodes_canvas->saveLayer(paint_bounds(), nullptr);
105  } break;
106  case Clip::none:
107  break;
108  }
109 
110  if (UsesSaveLayer()) {
111  // If we want to avoid the bleeding edge artifact
112  // (https://github.com/flutter/flutter/issues/18057#issue-328003931)
113  // using saveLayer, we have to call drawPaint instead of drawPath as
114  // anti-aliased drawPath will always have such artifacts.
115  context.leaf_nodes_canvas->drawPaint(paint);
116  }
117 
118  PaintChildren(context);
119 
120  context.internal_nodes_canvas->restoreToCount(saveCount);
121 
122  if (UsesSaveLayer()) {
123  if (context.checkerboard_offscreen_layers) {
124  DrawCheckerboard(context.internal_nodes_canvas, paint_bounds());
125  }
126  }
127 }
#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:245
const SkRect & paint_bounds() const
Definition: layer.h:223
static void DrawShadow(SkCanvas *canvas, const SkPath &path, SkColor color, float elevation, bool transparentOccluder, SkScalar dpr)
void DrawCheckerboard(SkCanvas *canvas, SkColor c1, SkColor c2, int size)
Definition: paint_utils.cc:29
void PaintChildren(PaintContext &context) const

◆ Preroll()

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

Reimplemented from flutter::ContainerLayer.

Definition at line 56 of file physical_shape_layer.cc.

References ComputeShadowBounds(), flutter::Layer::AutoPrerollSaveLayerState::Create(), flutter::PrerollContext::frame_device_pixel_ratio, flutter::ContainerLayer::PrerollChildren(), flutter::Layer::set_paint_bounds(), TRACE_EVENT0, and UsesSaveLayer().

57  {
58  TRACE_EVENT0("flutter", "PhysicalShapeLayer::Preroll");
59  Layer::AutoPrerollSaveLayerState save =
61 
62  SkRect child_paint_bounds;
63  PrerollChildren(context, matrix, &child_paint_bounds);
64 
65  if (elevation_ == 0) {
66  set_paint_bounds(path_.getBounds());
67  } else {
68  // We will draw the shadow in Paint(), so add some margin to the paint
69  // bounds to leave space for the shadow. We fill this whole region and clip
70  // children to it so we don't need to join the child paint bounds.
72  path_, elevation_, context->frame_device_pixel_ratio, matrix));
73  }
74 }
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:90
void PrerollChildren(PrerollContext *context, const SkMatrix &child_matrix, SkRect *child_paint_bounds)
static SkRect ComputeShadowBounds(const SkPath &path, float elevation, SkScalar dpr, const SkMatrix &ctm)
static AutoPrerollSaveLayerState Create(PrerollContext *preroll_context, bool save_layer_is_active=true, bool layer_itself_performs_readback=false)
Definition: layer.cc:44
void set_paint_bounds(const SkRect &paint_bounds)
Definition: layer.h:236

◆ UsesSaveLayer()

bool flutter::PhysicalShapeLayer::UsesSaveLayer ( ) const
inline

Definition at line 37 of file physical_shape_layer.h.

References flutter::antiAliasWithSaveLayer.

Referenced by Paint(), and Preroll().

37  {
38  return clip_behavior_ == Clip::antiAliasWithSaveLayer;
39  }

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