| Flutter Impeller |

renderer.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/renderer/renderer.h"
6
7 #include <algorithm>
8
9 #include "flutter/fml/logging.h"
10 #include "flutter/fml/trace_event.h"
11 #include "impeller/base/validation.h"
12 #include "impeller/renderer/command_buffer.h"
13 #include "impeller/renderer/surface.h"
14
15 namespace impeller {
16
17 Renderer::Renderer(std::shared_ptr<Context> context,
18 size_t max_frames_in_flight)
19 : frames_in_flight_sema_(std::make_shared<fml::Semaphore>(
20 std::max<std::size_t>(1u, max_frames_in_flight))),
21 context_(std::move(context)) {
22 if (!context_ || !context_->IsValid()) {
23 return;
24 }
25
26 is_valid_ = true;
27 }
28
29 Renderer::~Renderer() = default;
30
31 bool Renderer::IsValid() const {
32 return is_valid_;
33 }
34
35 bool Renderer::Render(std::unique_ptr<Surface> surface,
36 const RenderCallback& render_callback) const {
37 TRACE_EVENT0("impeller", "Renderer::Render");
38 if (!IsValid()) {
39 return false;
40 }
41
42 if (!surface || !surface->IsValid()) {
43 return false;
44 }
45
46 RenderTarget render_target = surface->GetTargetRenderPassDescriptor();
47
48 if (render_callback && !render_callback(render_target)) {
49 return false;
50 }
51
52 if (!frames_in_flight_sema_->Wait()) {
53 return false;
54 }
55
56 const auto present_result = surface->Present();
57
58 frames_in_flight_sema_->Signal();
59
60 return present_result;
61 }
62
63 std::shared_ptr<Context> Renderer::GetContext() const {
64 return context_;
65 }
66
67 } // namespace impeller
impeller::Renderer::~Renderer
~Renderer()
impeller::Renderer::RenderCallback
std::function< bool(RenderTarget &render_target)> RenderCallback
Definition: renderer.h:25
impeller::Renderer::GetContext
std::shared_ptr< Context > GetContext() const
Definition: renderer.cc:63
validation.h
surface.h
impeller::RenderTarget
Definition: render_target.h:48
command_buffer.h
impeller::Renderer::IsValid
bool IsValid() const
Definition: renderer.cc:31
impeller::Renderer::Renderer
Renderer(std::shared_ptr< Context > context, size_t max_frames_in_flight=kDefaultMaxFramesInFlight)
Definition: renderer.cc:17
std
Definition: comparable.h:98
impeller::Renderer::Render
bool Render(std::unique_ptr< Surface > surface, const RenderCallback &callback) const
Definition: renderer.cc:35
renderer.h
impeller
Definition: aiks_context.cc:10