Flutter Engine
The Flutter Engine
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
14#include "impeller/aiks/paint.h"
18
19namespace impeller {
20
21/// This Canvas attempts to translate from display lists to draw calls directly.
22///
23/// It's not fully implemented yet but if successful it will be replacing the
24/// aiks Canvas functionality.
25///
26/// See also:
27/// - go/impeller-canvas-efficiency
28class ExperimentalCanvas : public Canvas {
29 public:
31 RenderTarget& render_target,
32 bool requires_readback);
33
35 RenderTarget& render_target,
36 bool requires_readback,
37 Rect cull_rect);
38
40 RenderTarget& render_target,
41 bool requires_readback,
42 IRect cull_rect);
43
44 ~ExperimentalCanvas() override = default;
45
46 void Save(uint32_t total_content_depth) override;
47
48 void SaveLayer(const Paint& paint,
49 std::optional<Rect> bounds,
50 const std::shared_ptr<ImageFilter>& backdrop_filter,
51 ContentBoundsPromise bounds_promise,
52 uint32_t total_content_depth,
53 bool can_distribute_opacity) override;
54
55 bool Restore() override;
56
57 void EndReplay();
58
59 void DrawTextFrame(const std::shared_ptr<TextFrame>& text_frame,
60 Point position,
61 const Paint& paint) override;
62
66 };
67
68 private:
69 // clip depth of the previous save or 0.
70 size_t GetClipHeightFloor() const {
71 if (transform_stack_.size() > 1) {
72 return transform_stack_[transform_stack_.size() - 2].clip_height;
73 }
74 return 0;
75 }
76
77 ContentContext& renderer_;
78 RenderTarget& render_target_;
79 const bool requires_readback_;
80 EntityPassClipStack clip_coverage_stack_;
81 std::vector<std::unique_ptr<InlinePassContext>> inline_pass_contexts_;
82 std::vector<std::unique_ptr<EntityPassTarget>> entity_pass_targets_;
83 std::vector<SaveLayerState> save_layer_state_;
84 std::vector<std::shared_ptr<RenderPass>> render_passes_;
85
86 void SetupRenderPass();
87
88 void AddRenderEntityToCurrentPass(Entity entity, bool reuse_depth) override;
89 void AddClipEntityToCurrentPass(Entity entity) override;
90 bool BlitToOnscreen();
91
92 Point GetGlobalPassPosition() {
93 if (save_layer_state_.empty()) {
94 return Point(0, 0);
95 }
96 return save_layer_state_.back().coverage.GetOrigin();
97 }
98
100
101 ExperimentalCanvas& operator=(const ExperimentalCanvas&) = delete;
102};
103
104} // namespace impeller
105
106#endif // FLUTTER_IMPELLER_AIKS_EXPERIMENTAL_CANVAS_H_
std::deque< CanvasStackEntry > transform_stack_
Definition: canvas.h:181
void DrawTextFrame(const std::shared_ptr< TextFrame > &text_frame, Point position, const Paint &paint) override
ExperimentalCanvas(ContentContext &renderer, RenderTarget &render_target, bool requires_readback)
~ExperimentalCanvas() override=default
void Save(uint32_t total_content_depth) override
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
const Paint & paint
Definition: color_source.cc:38
Optional< SkRect > bounds
Definition: SkRecords.h:189
SK_API sk_sp< SkSurface > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)
TPoint< Scalar > Point
Definition: point.h:322
ContentBoundsPromise
Definition: entity_pass.h:28