| Flutter Impeller |

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