Flutter Impeller
clip_contents.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef FLUTTER_IMPELLER_ENTITY_CONTENTS_CLIP_CONTENTS_H_
6 #define FLUTTER_IMPELLER_ENTITY_CONTENTS_CLIP_CONTENTS_H_
7 
8 #include <functional>
9 #include <memory>
10 #include <vector>
11 
12 #include "flutter/fml/macros.h"
14 #include "impeller/entity/entity.h"
16 
17 namespace impeller {
18 
19 class ClipContents final : public Contents {
20  public:
21  ClipContents();
22 
23  ~ClipContents();
24 
25  void SetGeometry(const std::shared_ptr<Geometry>& geometry);
26 
28 
29  // |Contents|
30  std::optional<Rect> GetCoverage(const Entity& entity) const override;
31 
32  // |Contents|
34  const Entity& entity,
35  const std::optional<Rect>& current_clip_coverage) const override;
36 
37  // |Contents|
38  bool ShouldRender(const Entity& entity,
39  const std::optional<Rect> clip_coverage) const override;
40 
41  // |Contents|
42  bool Render(const ContentContext& renderer,
43  const Entity& entity,
44  RenderPass& pass) const override;
45  // |Contents|
46  bool CanInheritOpacity(const Entity& entity) const override;
47 
48  // |Contents|
49  void SetInheritedOpacity(Scalar opacity) override;
50 
51  private:
52  std::shared_ptr<Geometry> geometry_;
54 
55  ClipContents(const ClipContents&) = delete;
56 
57  ClipContents& operator=(const ClipContents&) = delete;
58 };
59 
60 class ClipRestoreContents final : public Contents {
61  public:
63 
65 
66  /// @brief The area on the pass texture where this clip restore will be
67  /// applied. If unset, the entire pass texture will be restored.
68  ///
69  /// @note This rectangle is not transformed by the entity's transform.
70  void SetRestoreCoverage(std::optional<Rect> coverage);
71 
72  // |Contents|
73  std::optional<Rect> GetCoverage(const Entity& entity) const override;
74 
75  // |Contents|
77  const Entity& entity,
78  const std::optional<Rect>& current_clip_coverage) const override;
79 
80  // |Contents|
81  bool ShouldRender(const Entity& entity,
82  const std::optional<Rect> clip_coverage) const override;
83 
84  // |Contents|
85  bool Render(const ContentContext& renderer,
86  const Entity& entity,
87  RenderPass& pass) const override;
88 
89  // |Contents|
90  bool CanInheritOpacity(const Entity& entity) const override;
91 
92  // |Contents|
93  void SetInheritedOpacity(Scalar opacity) override;
94 
95  private:
96  std::optional<Rect> restore_coverage_;
97 
99 
100  ClipRestoreContents& operator=(const ClipRestoreContents&) = delete;
101 };
102 
103 } // namespace impeller
104 
105 #endif // FLUTTER_IMPELLER_ENTITY_CONTENTS_CLIP_CONTENTS_H_
impeller::Entity::ClipOperation::kIntersect
@ kIntersect
contents.h
impeller::ClipRestoreContents::ClipRestoreContents
ClipRestoreContents()
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::ClipRestoreContents::GetCoverage
std::optional< Rect > GetCoverage(const Entity &entity) const override
Get the area of the render pass that will be affected when this contents is rendered.
Definition: clip_contents.cc:150
entity.h
impeller::ClipRestoreContents::CanInheritOpacity
bool CanInheritOpacity(const Entity &entity) const override
Whether or not this contents can accept the opacity peephole optimization.
Definition: clip_contents.cc:167
impeller::ClipContents::SetClipOperation
void SetClipOperation(Entity::ClipOperation clip_op)
Definition: clip_contents.cc:29
impeller::ClipRestoreContents::SetRestoreCoverage
void SetRestoreCoverage(std::optional< Rect > coverage)
The area on the pass texture where this clip restore will be applied. If unset, the entire pass textu...
Definition: clip_contents.cc:145
impeller::ClipRestoreContents::~ClipRestoreContents
~ClipRestoreContents()
impeller::ClipContents::ShouldRender
bool ShouldRender(const Entity &entity, const std::optional< Rect > clip_coverage) const override
Definition: clip_contents.cc:65
impeller::ClipContents::GetClipCoverage
ClipCoverage GetClipCoverage(const Entity &entity, const std::optional< Rect > &current_clip_coverage) const override
Given the current pass space bounding rectangle of the clip buffer, return the expected clip coverage...
Definition: clip_contents.cc:37
impeller::Entity
Definition: entity.h:21
impeller::ClipContents::SetGeometry
void SetGeometry(const std::shared_ptr< Geometry > &geometry)
Definition: clip_contents.cc:25
impeller::ClipContents::ClipContents
ClipContents()
impeller::ClipRestoreContents::Render
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Definition: clip_contents.cc:173
impeller::ClipContents::~ClipContents
~ClipContents()
impeller::ClipContents::GetCoverage
std::optional< Rect > GetCoverage(const Entity &entity) const override
Get the area of the render pass that will be affected when this contents is rendered.
Definition: clip_contents.cc:33
geometry.h
impeller::ClipRestoreContents::SetInheritedOpacity
void SetInheritedOpacity(Scalar opacity) override
Inherit the provided opacity.
Definition: clip_contents.cc:171
impeller::ClipRestoreContents
Definition: clip_contents.h:60
impeller::ClipContents::Render
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Definition: clip_contents.cc:76
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:29
impeller::ClipRestoreContents::ShouldRender
bool ShouldRender(const Entity &entity, const std::optional< Rect > clip_coverage) const override
Definition: clip_contents.cc:161
impeller::ClipRestoreContents::GetClipCoverage
ClipCoverage GetClipCoverage(const Entity &entity, const std::optional< Rect > &current_clip_coverage) const override
Given the current pass space bounding rectangle of the clip buffer, return the expected clip coverage...
Definition: clip_contents.cc:155
impeller::Contents::ClipCoverage
Definition: contents.h:40
impeller::ClipContents::CanInheritOpacity
bool CanInheritOpacity(const Entity &entity) const override
Whether or not this contents can accept the opacity peephole optimization.
Definition: clip_contents.cc:70
impeller::ClipContents
Definition: clip_contents.h:19
impeller::Entity::ClipOperation
ClipOperation
Definition: entity.h:59
impeller::ClipContents::SetInheritedOpacity
void SetInheritedOpacity(Scalar opacity) override
Inherit the provided opacity.
Definition: clip_contents.cc:74
impeller::Contents
Definition: contents.h:34
impeller
Definition: aiks_context.cc:10
impeller::ContentContext
Definition: content_context.h:332