| Flutter Impeller |

scene_contents.cc
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 #include "impeller/entity/contents/scene_contents.h"
6
7 #include "impeller/core/formats.h"
8 #include "impeller/entity/contents/content_context.h"
9 #include "impeller/entity/contents/tiled_texture_contents.h"
10 #include "impeller/entity/entity.h"
11 #include "impeller/geometry/path_builder.h"
12 #include "impeller/scene/camera.h"
13 #include "impeller/scene/scene.h"
14
15 namespace impeller {
16
17 SceneContents::SceneContents() = default;
18
19 SceneContents::~SceneContents() = default;
20
21 void SceneContents::SetCameraTransform(Matrix matrix) {
22 camera_transform_ = matrix;
23 }
24
25 void SceneContents::SetNode(std::shared_ptr<scene::Node> node) {
26 node_ = std::move(node);
27 }
28
29 bool SceneContents::Render(const ContentContext& renderer,
30 const Entity& entity,
31 RenderPass& pass) const {
32 if (!node_) {
33 return true;
34 }
35
36 auto coverage = GetCoverage(entity);
37 if (!coverage.has_value()) {
38 return true;
39 }
40
41 // This happens for CoverGeometry (DrawPaint). In this situation,
42 // Draw the scene to the full layer.
43 if (coverage.value().IsMaximum()) {
44 coverage = Rect::MakeSize(pass.GetRenderTargetSize());
45 }
46
47 RenderTarget subpass_target = RenderTarget::CreateOffscreenMSAA(
48 *renderer.GetContext(), // context
49 *renderer.GetRenderTargetCache(), // allocator
50 ISize(coverage.value().size), // size
51 "SceneContents", // label
52 RenderTarget::AttachmentConfigMSAA{
53 .storage_mode = StorageMode::kDeviceTransient,
54 .resolve_storage_mode = StorageMode::kDevicePrivate,
55 .load_action = LoadAction::kClear,
56 .store_action = StoreAction::kMultisampleResolve,
57 }, // color_attachment_config
58 RenderTarget::AttachmentConfig{
59 .storage_mode = StorageMode::kDeviceTransient,
60 .load_action = LoadAction::kDontCare,
61 .store_action = StoreAction::kDontCare,
62 } // stencil_attachment_config
63 );
64 if (!subpass_target.IsValid()) {
65 return false;
66 }
67
68 scene::Scene scene(renderer.GetSceneContext());
69 scene.GetRoot().AddChild(node_);
70
71 if (!scene.Render(subpass_target, camera_transform_)) {
72 return false;
73 }
74
75 // Render the texture to the pass.
76 TiledTextureContents contents;
77 contents.SetGeometry(GetGeometry());
78 contents.SetTexture(subpass_target.GetRenderTargetTexture());
79 contents.SetEffectTransform(
80 Matrix::MakeScale(1 / entity.GetTransformation().GetScale()));
81 return contents.Render(renderer, entity, pass);
82 }
83
84 } // namespace impeller
impeller::SceneContents::SetCameraTransform
void SetCameraTransform(Matrix matrix)
Definition: scene_contents.cc:21
impeller::ColorSourceContents::SetGeometry
void SetGeometry(std::shared_ptr< Geometry > geometry)
Set the geometry that this contents will use to render.
Definition: color_source_contents.cc:17
impeller::ColorSourceContents::SetEffectTransform
void SetEffectTransform(Matrix matrix)
Set the effect transform for this color source.
Definition: color_source_contents.cc:33
entity.h
formats.h
tiled_texture_contents.h
impeller::ColorSourceContents::GetGeometry
const std::shared_ptr< Geometry > & GetGeometry() const
Get the geometry that this contents will use to render.
Definition: color_source_contents.cc:21
impeller::SceneContents::SetNode
void SetNode(std::shared_ptr< scene::Node > node)
Definition: scene_contents.cc:25
impeller::SceneContents::SceneContents
SceneContents()
impeller::scene::Scene::GetRoot
Node & GetRoot()
Definition: scene.cc:29
impeller::RenderTarget::AttachmentConfigMSAA
Definition: render_target.h:57
impeller::RenderTarget::AttachmentConfig
Definition: render_target.h:50
impeller::Entity::GetTransformation
const Matrix & GetTransformation() const
Definition: entity.cc:49
path_builder.h
impeller::Entity
Definition: entity.h:21
impeller::RenderPass::GetRenderTargetSize
ISize GetRenderTargetSize() const
Definition: render_pass.cc:30
impeller::TSize< int64_t >
scene.h
impeller::RenderTarget::GetRenderTargetTexture
std::shared_ptr< Texture > GetRenderTargetTexture() const
Definition: render_target.cc:155
scene_contents.h
impeller::SceneContents::~SceneContents
~SceneContents() override
impeller::Matrix::GetScale
constexpr Vector3 GetScale() const
Definition: matrix.h:301
impeller::ContentContext::GetContext
std::shared_ptr< Context > GetContext() const
Definition: content_context.cc:440
impeller::ContentContext::GetRenderTargetCache
std::shared_ptr< RenderTargetAllocator > GetRenderTargetCache() const
Definition: content_context.h:716
impeller::RenderTarget
Definition: render_target.h:48
impeller::SceneContents::Render
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Definition: scene_contents.cc:29
impeller::RenderTarget::IsValid
bool IsValid() const
Definition: render_target.cc:34
camera.h
impeller::scene::Node::AddChild
bool AddChild(std::shared_ptr< Node > child)
Definition: node.cc:309
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:27
content_context.h
impeller::ColorSourceContents::GetCoverage
std::optional< Rect > GetCoverage(const Entity &entity) const override
Get the screen space bounding rectangle that this contents affects.
Definition: color_source_contents.cc:45
impeller::TiledTextureContents
Definition: tiled_texture_contents.h:21
impeller::TRect< Scalar >::MakeSize
constexpr static TRect MakeSize(const TSize< U > &size)
Definition: rect.h:52
impeller::TiledTextureContents::Render
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Definition: tiled_texture_contents.cc:113
impeller::scene::Scene
Definition: scene.h:20
impeller::scene::Scene::Render
bool Render(const RenderTarget &render_target, const Matrix &camera_transform)
Definition: scene.cc:33
impeller
Definition: aiks_context.cc:10
impeller::Matrix::MakeScale
static constexpr Matrix MakeScale(const Vector3 &s)
Definition: matrix.h:103
impeller::ContentContext
Definition: content_context.h:344
impeller::RenderTarget::CreateOffscreenMSAA
static RenderTarget CreateOffscreenMSAA(const Context &context, RenderTargetAllocator &allocator, ISize size, const std::string &label="Offscreen MSAA", AttachmentConfigMSAA color_attachment_config=kDefaultColorAttachmentConfigMSAA, std::optional< AttachmentConfig > stencil_attachment_config=kDefaultStencilAttachmentConfig)
Definition: render_target.cc:270
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:36
impeller::TiledTextureContents::SetTexture
void SetTexture(std::shared_ptr< Texture > texture)
Definition: tiled_texture_contents.cc:44