Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
6
7#include <memory>
8#include <utility>
9
10#include "flutter/fml/logging.h"
11#include "fml/closure.h"
15
16namespace impeller {
17namespace scene {
18
19Scene::Scene(std::shared_ptr<SceneContext> scene_context)
20 : scene_context_(std::move(scene_context)) {
21 root_.is_root_ = true;
22};
23
25 for (auto& child : GetRoot().GetChildren()) {
26 child->parent_ = nullptr;
27 }
28}
29
31 return root_;
32}
33
34bool 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.
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
67bool 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
Wraps a closure that is invoked in the destructor unless released by the caller.
Definition closure.h:32
ISize GetRenderTargetSize() const
Matrix GetTransform(ISize target_size) const
Definition camera.cc:24
bool Render(SceneEncoder &encoder, Allocator &allocator, const Matrix &parent_transform)
Definition node.cc:345
std::vector< std::shared_ptr< Node > > & GetChildren()
Definition node.cc:325
bool Render(const RenderTarget &render_target, const Matrix &camera_transform)
Definition scene.cc:34
#define FML_LOG(severity)
Definition logging.h:82
Definition ref_ptr.h:256
A 4x4 matrix using column-major storage.
Definition matrix.h:37
#define ERROR(message)