Flutter Impeller
runtime_effect_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_RUNTIME_EFFECT_CONTENTS_H_
6 #define FLUTTER_IMPELLER_ENTITY_CONTENTS_RUNTIME_EFFECT_CONTENTS_H_
7 
8 #include <memory>
9 #include <vector>
10 
15 
16 namespace impeller {
17 
19  public:
20  explicit RuntimeEffectContents(const Geometry* geometry);
21 
23  struct TextureInput {
25  std::shared_ptr<Texture> texture;
26  };
27 
28  void SetRuntimeStage(std::shared_ptr<RuntimeStage> runtime_stage);
29 
30  void SetUniformData(std::shared_ptr<std::vector<uint8_t>> uniform_data);
31 
32  void SetTextureInputs(std::vector<TextureInput> texture_inputs);
33 
34  const Geometry* GetGeometry() const override;
35 
36  // |Contents|
37  bool Render(const ContentContext& renderer,
38  const Entity& entity,
39  RenderPass& pass) const override;
40 
41  /// Load the runtime effect and ensure a default PSO is initialized.
42  bool BootstrapShader(const ContentContext& renderer) const;
43 
44  // Visible for testing
45  /// Copies the uniform data into the host buffer.
46  ///
47  /// If the `uniform` has a `padding_layout`, it is used to repack the data.
48  ///
49  /// @param source_data The pointer to the start of the uniform data in the
50  /// source.
51  /// @param host_buffer The host buffer to emplace the uniform data into.
52  /// @param uniform The description of the uniform being emplaced.
53  static BufferView EmplaceUniform(const uint8_t* source_data,
54  HostBuffer& host_buffer,
55  const RuntimeUniformDescription& uniform);
56 
57  private:
58  bool RegisterShader(const ContentContext& renderer) const;
59 
60  // If async is true, this will always return nullptr as pipeline creation
61  // is not blocked on.
62  std::shared_ptr<Pipeline<PipelineDescriptor>> CreatePipeline(
63  const ContentContext& renderer,
64  ContentContextOptions options,
65  bool async) const;
66 
67  const Geometry* geometry_ = nullptr;
68  std::shared_ptr<RuntimeStage> runtime_stage_;
69  std::shared_ptr<std::vector<uint8_t>> uniform_data_;
70  std::vector<TextureInput> texture_inputs_;
71 };
72 
73 } // namespace impeller
74 
75 #endif // FLUTTER_IMPELLER_ENTITY_CONTENTS_RUNTIME_EFFECT_CONTENTS_H_
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:30
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
bool BootstrapShader(const ContentContext &renderer) const
Load the runtime effect and ensure a default PSO is initialized.
void SetRuntimeStage(std::shared_ptr< RuntimeStage > runtime_stage)
void SetTextureInputs(std::vector< TextureInput > texture_inputs)
static BufferView EmplaceUniform(const uint8_t *source_data, HostBuffer &host_buffer, const RuntimeUniformDescription &uniform)
const Geometry * GetGeometry() const override
Get the geometry that this contents will use to render.
RuntimeEffectContents(const Geometry *geometry)
void SetUniformData(std::shared_ptr< std::vector< uint8_t >> uniform_data)