Flutter Engine
The Flutter Engine
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
6
7#include <algorithm>
8
9#include "flutter/fml/trace_event.h"
12
13namespace impeller {
14
15Renderer::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
27Renderer::~Renderer() = default;
28
29bool Renderer::IsValid() const {
30 return is_valid_;
31}
32
33bool 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
61std::shared_ptr<Context> Renderer::GetContext() const {
62 return context_;
63}
64
65} // namespace impeller
Renderer(std::shared_ptr< Context > context, size_t max_frames_in_flight=kDefaultMaxFramesInFlight)
Definition: renderer.cc:15
bool Render(std::unique_ptr< Surface > surface, const RenderCallback &callback) const
Definition: renderer.cc:33
bool IsValid() const
Definition: renderer.cc:29
std::shared_ptr< Context > GetContext() const
Definition: renderer.cc:61
std::function< bool(RenderTarget &render_target)> RenderCallback
Definition: renderer.h:23
VkSurfaceKHR surface
Definition: main.cc:49
static float max(float r, float g, float b)
Definition: hsl.cpp:49
Definition: ascii_trie.cc:9
Definition: ref_ptr.h:256
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:131