| 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 "impeller/entity/contents/contents.h"
9 #include "impeller/entity/entity.h"
10 #include "impeller/entity/geometry/geometry.h"
11
12 namespace impeller {
13
14 struct ClipCoverage {
15 // TODO(jonahwilliams): this should probably use the Entity::ClipOperation
16 // enum, but that has transitive import errors.
17 bool is_difference_or_non_square = false;
18
19 /// @brief This coverage is the outer coverage of the clip.
20 ///
21 /// For example, if the clip is a circular clip, this is the rectangle that
22 /// contains the circle and not the rectangle that is contained within the
23 /// circle. This means that we cannot use the coverage alone to determine if
24 /// a clip can be culled, and instead also use the somewhat hacky
25 /// "is_difference_or_non_square" field.
26 std::optional<Rect> coverage = std::nullopt;
27 };
28
29 class ClipContents {
30 public:
31 ClipContents(Rect coverage_rect, bool is_axis_aligned_rect);
32
33 ~ClipContents();
34
35 /// @brief Set the pre-tessellated clip geometry.
36 void SetGeometry(GeometryResult geometry);
37
38 void SetClipOperation(Entity::ClipOperation clip_op);
39
40 //----------------------------------------------------------------------------
41 /// @brief Given the current pass space bounding rectangle of the clip
42 /// buffer, return the expected clip coverage after this draw call.
43 /// This should only be implemented for contents that may write to the
44 /// clip buffer.
45 ///
46 /// During rendering, coverage coordinates count pixels from the top
47 /// left corner of the framebuffer.
48 ///
49 ClipCoverage GetClipCoverage(
50 const std::optional<Rect>& current_clip_coverage) const;
51
52 bool Render(const ContentContext& renderer,
53 RenderPass& pass,
54 uint32_t clip_depth) const;
55
56 private:
57 // Pre-tessellated clip geometry.
58 GeometryResult clip_geometry_;
59 // Coverage rect of the tessellated geometry.
60 Rect coverage_rect_;
61 bool is_axis_aligned_rect_ = false;
62 Entity::ClipOperation clip_op_ = Entity::ClipOperation::kIntersect;
63 };
64
65 /// @brief Render a restore clip.
66 ///
67 /// This is is intended to be used for prevent overdraw mechanism. The clip
68 /// depth should be the depth of the entity that is currently being drawn, and
69 /// restore_coverage should be its coverage. If restore_coverage is
70 /// std::nullopt, the render pass coverage is used instead.
71 bool RenderClipRestore(const ContentContext& renderer,
72 RenderPass& pass,
73 uint32_t clip_depth,
74 std::optional<Rect> restore_coverage);
75
76 } // namespace impeller
77
78 #endif // FLUTTER_IMPELLER_ENTITY_CONTENTS_CLIP_CONTENTS_H_
impeller::ClipContents
Definition: clip_contents.h:29
impeller::ClipContents::ClipContents
ClipContents(Rect coverage_rect, bool is_axis_aligned_rect)
Definition: clip_contents.cc:30
impeller::ClipContents::SetGeometry
void SetGeometry(GeometryResult geometry)
Set the pre-tessellated clip geometry.
Definition: clip_contents.cc:36
impeller::ClipContents::~ClipContents
~ClipContents()
impeller::ClipContents::GetClipCoverage
ClipCoverage GetClipCoverage(const std::optional< Rect > &current_clip_coverage) const
Given the current pass space bounding rectangle of the clip buffer, return the expected clip coverage...
Definition: clip_contents.cc:44
impeller::ClipContents::SetClipOperation
void SetClipOperation(Entity::ClipOperation clip_op)
Definition: clip_contents.cc:40
impeller::ClipContents::Render
bool Render(const ContentContext &renderer, RenderPass &pass, uint32_t clip_depth) const
Definition: clip_contents.cc:69
impeller::ContentContext
Definition: content_context.h:371
impeller::Entity::ClipOperation
ClipOperation
Definition: entity.h:61
impeller::Entity::ClipOperation::kIntersect
@ kIntersect
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:30
contents.h
entity.h
geometry.h
impeller
Definition: allocation.cc:12
impeller::RenderClipRestore
bool RenderClipRestore(const ContentContext &renderer, RenderPass &pass, uint32_t clip_depth, std::optional< Rect > restore_coverage)
Render a restore clip.
Definition: clip_contents.cc:152
impeller::ClipCoverage
Definition: clip_contents.h:14
impeller::ClipCoverage::is_difference_or_non_square
bool is_difference_or_non_square
Definition: clip_contents.h:17
impeller::ClipCoverage::coverage
std::optional< Rect > coverage
This coverage is the outer coverage of the clip.
Definition: clip_contents.h:26
impeller::GeometryResult
Definition: geometry.h:21
impeller::TRect< Scalar >