Flutter Engine
 
Loading...
Searching...
No Matches
atlas_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_ATLAS_CONTENTS_H_
6#define FLUTTER_IMPELLER_ENTITY_CONTENTS_ATLAS_CONTENTS_H_
7
8#include <memory>
9
14
15namespace impeller {
16
17struct VertexBuffer;
18
19// Interface wrapper to allow usage of DL pointer data without copying (or
20// circular imports).
22 public:
23 virtual bool ShouldUseBlend() const = 0;
24
25 virtual bool ShouldSkip() const = 0;
26
28 HostBuffer& host_buffer) const = 0;
29
31 HostBuffer& host_buffer) const = 0;
32
33 virtual Rect ComputeBoundingBox() const = 0;
34
35 virtual const std::shared_ptr<Texture>& GetAtlas() const = 0;
36
37 virtual const SamplerDescriptor& GetSamplerDescriptor() const = 0;
38
39 virtual BlendMode GetBlendMode() const = 0;
40
41 virtual bool ShouldInvertBlendMode() const { return true; }
42
43 /// @brief The source rect of the draw in texture coordinates if a strict
44 /// source rect should be applied, or nullopt.
45 ///
46 /// See also `Canvas::AttemptColorFilterOptimization`
47 virtual std::optional<Rect> GetStrictSrcRect() const { return std::nullopt; }
48};
49
50/// @brief An atlas geometry that adapts for drawImageRect.
52 public:
53 DrawImageRectAtlasGeometry(std::shared_ptr<Texture> texture,
54 const Rect& source,
55 const Rect& destination,
56 const Color& color,
57 BlendMode blend_mode,
58 const SamplerDescriptor& desc,
59 bool use_strict_src_rect = false);
60
62
63 bool ShouldUseBlend() const override;
64
65 bool ShouldSkip() const override;
66
67 VertexBuffer CreateSimpleVertexBuffer(HostBuffer& host_buffer) const override;
68
69 VertexBuffer CreateBlendVertexBuffer(HostBuffer& host_buffer) const override;
70
71 Rect ComputeBoundingBox() const override;
72
73 const std::shared_ptr<Texture>& GetAtlas() const override;
74
75 const SamplerDescriptor& GetSamplerDescriptor() const override;
76
77 BlendMode GetBlendMode() const override;
78
79 bool ShouldInvertBlendMode() const override;
80
81 std::optional<Rect> GetStrictSrcRect() const override;
82
83 private:
84 const std::shared_ptr<Texture> texture_;
85 const Rect source_;
86 const Rect destination_;
87 const Color color_;
88 const BlendMode blend_mode_;
89 const SamplerDescriptor desc_;
90 const bool use_strict_src_rect_;
91};
92
93class AtlasContents final : public Contents {
94 public:
95 explicit AtlasContents();
96
97 ~AtlasContents() override;
98
99 void SetGeometry(AtlasGeometry* geometry);
100
101 void SetAlpha(Scalar alpha);
102
103 // |Contents|
104 std::optional<Rect> GetCoverage(const Entity& entity) const override;
105
106 // |Contents|
107 bool Render(const ContentContext& renderer,
108 const Entity& entity,
109 RenderPass& pass) const override;
110
111 private:
112 AtlasGeometry* geometry_ = nullptr;
113 Scalar alpha_ = 1.0;
114
115 AtlasContents(const AtlasContents&) = delete;
116
117 AtlasContents& operator=(const AtlasContents&) = delete;
118};
119
120/// A specialized atlas class for applying a color matrix filter to a
121/// drawImageRect call.
122class ColorFilterAtlasContents final : public Contents {
123 public:
125
127
128 void SetGeometry(AtlasGeometry* geometry);
129
130 void SetAlpha(Scalar alpha);
131
132 void SetMatrix(ColorMatrix matrix);
133
134 // |Contents|
135 std::optional<Rect> GetCoverage(const Entity& entity) const override;
136
137 // |Contents|
138 bool Render(const ContentContext& renderer,
139 const Entity& entity,
140 RenderPass& pass) const override;
141
142 private:
143 // These contents are created temporarily on the stack and never stored.
144 // The referenced geometry is also stack allocated and will be de-allocated
145 // after the contents are.
146 AtlasGeometry* geometry_ = nullptr;
147 ColorMatrix matrix_;
148 Scalar alpha_ = 1.0;
149
151
152 ColorFilterAtlasContents& operator=(const ColorFilterAtlasContents&) = delete;
153};
154
155} // namespace impeller
156
157#endif // FLUTTER_IMPELLER_ENTITY_CONTENTS_ATLAS_CONTENTS_H_
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
void SetGeometry(AtlasGeometry *geometry)
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.
void SetAlpha(Scalar alpha)
virtual const SamplerDescriptor & GetSamplerDescriptor() const =0
virtual VertexBuffer CreateSimpleVertexBuffer(HostBuffer &host_buffer) const =0
virtual Rect ComputeBoundingBox() const =0
virtual const std::shared_ptr< Texture > & GetAtlas() const =0
virtual bool ShouldInvertBlendMode() const
virtual bool ShouldUseBlend() const =0
virtual bool ShouldSkip() const =0
virtual VertexBuffer CreateBlendVertexBuffer(HostBuffer &host_buffer) const =0
virtual BlendMode GetBlendMode() const =0
virtual std::optional< Rect > GetStrictSrcRect() const
The source rect of the draw in texture coordinates if a strict source rect should be applied,...
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.
void SetGeometry(AtlasGeometry *geometry)
void SetMatrix(ColorMatrix matrix)
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
An atlas geometry that adapts for drawImageRect.
const SamplerDescriptor & GetSamplerDescriptor() const override
std::optional< Rect > GetStrictSrcRect() const override
The source rect of the draw in texture coordinates if a strict source rect should be applied,...
BlendMode GetBlendMode() const override
bool ShouldInvertBlendMode() const override
VertexBuffer CreateBlendVertexBuffer(HostBuffer &host_buffer) const override
VertexBuffer CreateSimpleVertexBuffer(HostBuffer &host_buffer) const override
const std::shared_ptr< Texture > & GetAtlas() const override
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition render_pass.h:30
FlTexture * texture
float Scalar
Definition scalar.h:19
BlendMode
Definition color.h:58