Flutter Engine
The Flutter Engine
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
6
14
15namespace impeller {
16
18
20
22 camera_transform_ = matrix;
23}
24
25void SceneContents::SetNode(std::shared_ptr<scene::Node> node) {
26 node_ = std::move(node);
27}
28
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()) {
45 }
46
47 RenderTarget subpass_target;
48 if (renderer.GetContext()->GetCapabilities()->SupportsOffscreenMSAA()) {
49 subpass_target = renderer.GetRenderTargetCache()->CreateOffscreenMSAA(
50 *renderer.GetContext(), // context
51 ISize(coverage.value().GetSize()), // size
52 /*mip_count=*/1,
53 "SceneContents", // label
55 .storage_mode = StorageMode::kDeviceTransient,
56 .resolve_storage_mode = StorageMode::kDevicePrivate,
57 .load_action = LoadAction::kClear,
58 .store_action = StoreAction::kMultisampleResolve,
59 }, // color_attachment_config
61 .storage_mode = StorageMode::kDeviceTransient,
62 .load_action = LoadAction::kDontCare,
63 .store_action = StoreAction::kDontCare,
64 } // stencil_attachment_config
65 );
66 } else {
67 subpass_target = renderer.GetRenderTargetCache()->CreateOffscreen(
68 *renderer.GetContext(), // context
69 ISize(coverage.value().GetSize()), // size
70 /*mip_count=*/1,
71 "SceneContents", // label
73 .storage_mode = StorageMode::kDevicePrivate,
74 .load_action = LoadAction::kClear,
75 .store_action = StoreAction::kStore,
76 }, // color_attachment_config
78 .storage_mode = StorageMode::kDeviceTransient,
79 .load_action = LoadAction::kClear,
80 .store_action = StoreAction::kDontCare,
81 } // stencil_attachment_config
82 );
83 }
84
85 if (!subpass_target.IsValid()) {
86 return false;
87 }
88
89 scene::Scene scene(renderer.GetSceneContext());
90 scene.GetRoot().AddChild(node_);
91
92 if (!scene.Render(subpass_target, camera_transform_)) {
93 return false;
94 }
95
96 // Render the texture to the pass.
97 TiledTextureContents contents;
98 contents.SetGeometry(GetGeometry());
99 contents.SetTexture(subpass_target.GetRenderTargetTexture());
100 contents.SetEffectTransform(
101 Matrix::MakeScale(1 / entity.GetTransform().GetScale()));
102 return contents.Render(renderer, entity, pass);
103}
104
105} // namespace impeller
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 SetEffectTransform(Matrix matrix)
Set the effect transform for this color source.
void SetGeometry(std::shared_ptr< Geometry > geometry)
Set the geometry that this contents will use to render.
const std::shared_ptr< Geometry > & GetGeometry() const
Get the geometry that this contents will use to render.
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
Definition: entity.cc:46
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:33
ISize GetRenderTargetSize() const
Definition: render_pass.cc:43
std::shared_ptr< Texture > GetRenderTargetTexture() const
void SetCameraTransform(Matrix matrix)
void SetNode(std::shared_ptr< scene::Node > node)
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
void SetTexture(std::shared_ptr< Texture > texture)
bool AddChild(std::shared_ptr< Node > child)
Definition: node.cc:300
bool Render(const RenderTarget &render_target, const Matrix &camera_transform)
Definition: scene.cc:34
Node & GetRoot()
Definition: scene.cc:30
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
constexpr Vector3 GetScale() const
Definition: matrix.h:311
static constexpr Matrix MakeScale(const Vector3 &s)
Definition: matrix.h:104
static constexpr TRect MakeSize(const TSize< U > &size)
Definition: rect.h:146