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