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 
12 #include "impeller/entity/entity.h"
14 
15 namespace impeller {
16 
17 // Interface wrapper to allow usage of DL pointer data without copying (or
18 // circular imports).
20  public:
21  virtual bool ShouldUseBlend() const = 0;
22 
23  virtual bool ShouldSkip() const = 0;
24 
26  HostBuffer& host_buffer) const = 0;
27 
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.
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 
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:
113 
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 
139 
140  ColorFilterAtlasContents& operator=(const ColorFilterAtlasContents&) = delete;
141 };
142 
143 } // namespace impeller
144 
145 #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 VertexBuffer CreateSimpleVertexBuffer(HostBuffer &host_buffer) const =0
virtual Rect ComputeBoundingBox() const =0
virtual bool ShouldInvertBlendMode() const
virtual bool ShouldUseBlend() const =0
virtual const SamplerDescriptor & GetSamplerDescriptor() const =0
virtual bool ShouldSkip() const =0
virtual VertexBuffer CreateBlendVertexBuffer(HostBuffer &host_buffer) const =0
virtual BlendMode GetBlendMode() const =0
virtual const std::shared_ptr< Texture > & GetAtlas() const =0
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.
Rect ComputeBoundingBox() const override
const SamplerDescriptor & GetSamplerDescriptor() const override
bool ShouldUseBlend() const override
BlendMode GetBlendMode() const override
bool ShouldInvertBlendMode() const override
VertexBuffer CreateBlendVertexBuffer(HostBuffer &host_buffer) const override
VertexBuffer CreateSimpleVertexBuffer(HostBuffer &host_buffer) const override
DrawImageRectAtlasGeometry(std::shared_ptr< Texture > texture, const Rect &source, const Rect &destination, const Color &color, BlendMode blend_mode, const SamplerDescriptor &desc)
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
float Scalar
Definition: scalar.h:18
BlendMode
Definition: color.h:58