| Flutter Impeller |

experimental_canvas.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_AIKS_EXPERIMENTAL_CANVAS_H_
6 #define FLUTTER_IMPELLER_AIKS_EXPERIMENTAL_CANVAS_H_
7
8 #include <memory>
9 #include <optional>
10 #include <vector>
11
12 #include "impeller/aiks/canvas.h"
13 #include "impeller/aiks/image_filter.h"
14 #include "impeller/aiks/paint.h"
15 #include "impeller/entity/entity.h"
16 #include "impeller/entity/entity_pass.h"
17 #include "impeller/entity/entity_pass_clip_stack.h"
18
19 namespace impeller {
20
21 struct LazyRenderingConfig {
22 std::unique_ptr<EntityPassTarget> entity_pass_target;
23 std::unique_ptr<InlinePassContext> inline_pass_context;
24
25 LazyRenderingConfig(ContentContext& renderer,
26 std::unique_ptr<EntityPassTarget> p_entity_pass_target)
27 : entity_pass_target(std::move(p_entity_pass_target)) {
28 inline_pass_context =
29 std::make_unique<InlinePassContext>(renderer, *entity_pass_target, 0);
30 }
31 };
32
33 /// This Canvas attempts to translate from display lists to draw calls directly.
34 ///
35 /// It's not fully implemented yet but if successful it will be replacing the
36 /// aiks Canvas functionality.
37 ///
38 /// See also:
39 /// - go/impeller-canvas-efficiency
40 class ExperimentalCanvas : public Canvas {
41 public:
42 ExperimentalCanvas(ContentContext& renderer,
43 RenderTarget& render_target,
44 bool requires_readback);
45
46 ExperimentalCanvas(ContentContext& renderer,
47 RenderTarget& render_target,
48 bool requires_readback,
49 Rect cull_rect);
50
51 ExperimentalCanvas(ContentContext& renderer,
52 RenderTarget& render_target,
53 bool requires_readback,
54 IRect cull_rect);
55
56 ~ExperimentalCanvas() override = default;
57
58 void Save(uint32_t total_content_depth) override;
59
60 void SaveLayer(const Paint& paint,
61 std::optional<Rect> bounds,
62 const std::shared_ptr<ImageFilter>& backdrop_filter,
63 ContentBoundsPromise bounds_promise,
64 uint32_t total_content_depth,
65 bool can_distribute_opacity) override;
66
67 bool Restore() override;
68
69 void EndReplay();
70
71 void DrawTextFrame(const std::shared_ptr<TextFrame>& text_frame,
72 Point position,
73 const Paint& paint) override;
74
75 struct SaveLayerState {
76 Paint paint;
77 Rect coverage;
78 };
79
80 private:
81 // clip depth of the previous save or 0.
82 size_t GetClipHeightFloor() const {
83 if (transform_stack_.size() > 1) {
84 return transform_stack_[transform_stack_.size() - 2].clip_height;
85 }
86 return 0;
87 }
88
89 ContentContext& renderer_;
90 RenderTarget& render_target_;
91 const bool requires_readback_;
92 EntityPassClipStack clip_coverage_stack_;
93 std::vector<LazyRenderingConfig> render_passes_;
94 std::vector<SaveLayerState> save_layer_state_;
95
96 void SetupRenderPass();
97
98 void AddRenderEntityToCurrentPass(Entity entity, bool reuse_depth) override;
99 void AddClipEntityToCurrentPass(Entity entity) override;
100 bool BlitToOnscreen();
101
102 Point GetGlobalPassPosition() {
103 if (save_layer_state_.empty()) {
104 return Point(0, 0);
105 }
106 return save_layer_state_.back().coverage.GetOrigin();
107 }
108
109 ExperimentalCanvas(const ExperimentalCanvas&) = delete;
110
111 ExperimentalCanvas& operator=(const ExperimentalCanvas&) = delete;
112 };
113
114 } // namespace impeller
115
116 #endif // FLUTTER_IMPELLER_AIKS_EXPERIMENTAL_CANVAS_H_
image_filter.h
impeller::ExperimentalCanvas::SaveLayer
void SaveLayer(const Paint &paint, std::optional< Rect > bounds, const std::shared_ptr< ImageFilter > &backdrop_filter, ContentBoundsPromise bounds_promise, uint32_t total_content_depth, bool can_distribute_opacity) override
Definition: experimental_canvas.cc:207
entity.h
impeller::Paint
Definition: paint.h:23
impeller::ExperimentalCanvas::SaveLayerState::paint
Paint paint
Definition: experimental_canvas.h:76
impeller::LazyRenderingConfig
Definition: experimental_canvas.h:21
impeller::Canvas
Definition: canvas.h:60
impeller::ContentBoundsPromise
ContentBoundsPromise
Definition: entity_pass.h:28
impeller::LazyRenderingConfig::LazyRenderingConfig
LazyRenderingConfig(ContentContext &renderer, std::unique_ptr< EntityPassTarget > p_entity_pass_target)
Definition: experimental_canvas.h:25
impeller::ExperimentalCanvas::Save
void Save(uint32_t total_content_depth) override
Definition: experimental_canvas.cc:193
impeller::Point
TPoint< Scalar > Point
Definition: point.h:322
impeller::LazyRenderingConfig::inline_pass_context
std::unique_ptr< InlinePassContext > inline_pass_context
Definition: experimental_canvas.h:23
canvas.h
impeller::ExperimentalCanvas::Restore
bool Restore() override
Definition: experimental_canvas.cc:416
impeller::RenderTarget
Definition: render_target.h:38
entity_pass.h
impeller::ExperimentalCanvas::DrawTextFrame
void DrawTextFrame(const std::shared_ptr< TextFrame > &text_frame, Point position, const Paint &paint) override
Definition: experimental_canvas.cc:558
impeller::ExperimentalCanvas::ExperimentalCanvas
ExperimentalCanvas(ContentContext &renderer, RenderTarget &render_target, bool requires_readback)
Definition: experimental_canvas.cc:109
entity_pass_clip_stack.h
impeller::ExperimentalCanvas::EndReplay
void EndReplay()
Definition: experimental_canvas.cc:745
impeller::ExperimentalCanvas::~ExperimentalCanvas
~ExperimentalCanvas() override=default
impeller::ExperimentalCanvas
Definition: experimental_canvas.h:40
std
Definition: comparable.h:95
impeller::TPoint< Scalar >
impeller::ExperimentalCanvas::SaveLayerState::coverage
Rect coverage
Definition: experimental_canvas.h:77
paint
const Paint & paint
Definition: color_source.cc:38
paint.h
impeller::LazyRenderingConfig::entity_pass_target
std::unique_ptr< EntityPassTarget > entity_pass_target
Definition: experimental_canvas.h:22
impeller::ExperimentalCanvas::SaveLayerState
Definition: experimental_canvas.h:75
impeller
Definition: aiks_blend_unittests.cc:18
impeller::Canvas::transform_stack_
std::deque< CanvasStackEntry > transform_stack_
Definition: canvas.h:181
impeller::ContentContext
Definition: content_context.h:366
impeller::TRect< Scalar >