| Flutter Impeller |

scene.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/scene/scene.h"
6
7 #include <memory>
8 #include <utility>
9
10 #include "flutter/fml/logging.h"
11 #include "fml/closure.h"
12 #include "impeller/renderer/render_target.h"
13 #include "impeller/scene/scene_context.h"
14 #include "impeller/scene/scene_encoder.h"
15
16 namespace impeller {
17 namespace scene {
18
19 Scene::Scene(std::shared_ptr<SceneContext> scene_context)
20 : scene_context_(std::move(scene_context)) {
21 root_.is_root_ = true;
22 };
23
24 Scene::~Scene() {
25 for (auto& child : GetRoot().GetChildren()) {
26 child->parent_ = nullptr;
27 }
28 }
29
30 Node& Scene::GetRoot() {
31 return root_;
32 }
33
34 bool Scene::Render(const RenderTarget& render_target,
35 const Matrix& camera_transform) {
36 fml::ScopedCleanupClosure reset_state(
37 [context = scene_context_]() { context->GetTransientsBuffer().Reset(); });
38
39 // Collect the render commands from the scene.
40 SceneEncoder encoder;
41 if (!root_.Render(encoder,
42 *scene_context_->GetContext()->GetResourceAllocator(),
43 Matrix())) {
44 FML_LOG(ERROR) << "Failed to render frame.";
45 return false;
46 }
47
48 // Encode the commands.
49
50 std::shared_ptr<CommandBuffer> command_buffer =
51 encoder.BuildSceneCommandBuffer(*scene_context_, camera_transform,
52 render_target);
53
54 // TODO(bdero): Do post processing.
55
56 if (!scene_context_->GetContext()
57 ->GetCommandQueue()
58 ->Submit({command_buffer})
59 .ok()) {
60 FML_LOG(ERROR) << "Failed to submit command buffer.";
61 return false;
62 }
63
64 return true;
65 }
66
67 bool Scene::Render(const RenderTarget& render_target, const Camera& camera) {
68 return Render(render_target,
69 camera.GetTransform(render_target.GetRenderTargetSize()));
70 }
71
72 } // namespace scene
73 } // namespace impeller
scene_context.h
impeller::scene::Camera::GetTransform
Matrix GetTransform(ISize target_size) const
Definition: camera.cc:24
impeller::scene::Scene::Scene
Scene()=delete
impeller::scene::Scene::GetRoot
Node & GetRoot()
Definition: scene.cc:30
scene_encoder.h
scene.h
impeller::RenderTarget
Definition: render_target.h:38
impeller::scene::Scene::~Scene
~Scene()
Definition: scene.cc:24
impeller::RenderTarget::GetRenderTargetSize
ISize GetRenderTargetSize() const
Definition: render_target.cc:139
impeller::scene::Node::Render
bool Render(SceneEncoder &encoder, Allocator &allocator, const Matrix &parent_transform)
Definition: node.cc:345
std
Definition: comparable.h:95
impeller::scene::Node
Definition: node.h:30
impeller::scene::SceneEncoder
Definition: scene_encoder.h:30
render_target.h
impeller::scene::Scene::Render
bool Render(const RenderTarget &render_target, const Matrix &camera_transform)
Definition: scene.cc:34
impeller
Definition: aiks_blur_unittests.cc:20
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::scene::Camera
Definition: camera.h:15