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