Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
gpu_surface_vulkan_impeller.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 "flutter/shell/gpu/gpu_surface_vulkan_impeller.h"
6
7#include "flutter/fml/make_copyable.h"
13
14namespace flutter {
15
16#define ENABLE_EXPERIMENTAL_CANVAS false
17
19 std::shared_ptr<impeller::Context> context) {
20 if (!context || !context->IsValid()) {
21 return;
22 }
23
24 auto renderer = std::make_shared<impeller::Renderer>(context);
25 if (!renderer->IsValid()) {
26 return;
27 }
28
29 auto aiks_context = std::make_shared<impeller::AiksContext>(
31 if (!aiks_context->IsValid()) {
32 return;
33 }
34
35 impeller_context_ = std::move(context);
36 impeller_renderer_ = std::move(renderer);
37 aiks_context_ = std::move(aiks_context);
38 is_valid_ = true;
39}
40
41// |Surface|
43
44// |Surface|
46 return is_valid_;
47}
48
49// |Surface|
50std::unique_ptr<SurfaceFrame> GPUSurfaceVulkanImpeller::AcquireFrame(
51 const SkISize& size) {
52 if (!IsValid()) {
53 FML_LOG(ERROR) << "Vulkan surface was invalid.";
54 return nullptr;
55 }
56
57 if (size.isEmpty()) {
58 FML_LOG(ERROR) << "Vulkan surface was asked for an empty frame.";
59 return nullptr;
60 }
61
62 auto& context_vk = impeller::SurfaceContextVK::Cast(*impeller_context_);
63 std::unique_ptr<impeller::Surface> surface = context_vk.AcquireNextSurface();
64
65 if (!surface) {
66 FML_LOG(ERROR) << "No surface available.";
67 return nullptr;
68 }
69
70 SurfaceFrame::SubmitCallback submit_callback =
71 fml::MakeCopyable([renderer = impeller_renderer_, //
72 aiks_context = aiks_context_, //
73 surface = std::move(surface) //
74 ](SurfaceFrame& surface_frame, DlCanvas* canvas) mutable -> bool {
75 if (!aiks_context) {
76 return false;
77 }
78
79 auto display_list = surface_frame.BuildDisplayList();
80 if (!display_list) {
81 FML_LOG(ERROR) << "Could not build display list for surface frame.";
82 return false;
83 }
84
85 auto cull_rect =
86 surface->GetTargetRenderPassDescriptor().GetRenderTargetSize();
87
88 return renderer->Render(
89 std::move(surface),
90 fml::MakeCopyable([aiks_context, cull_rect, display_list](
91 impeller::RenderTarget& render_target)
92 -> bool {
93#if ENABLE_EXPERIMENTAL_CANVAS
95 aiks_context->GetContentContext(), impeller::Matrix());
96 display_list->Dispatch(
97 collector,
98 SkIRect::MakeWH(cull_rect.width, cull_rect.height));
99 impeller::ExperimentalDlDispatcher impeller_dispatcher(
100 aiks_context->GetContentContext(), render_target,
102 impeller::Rect::MakeSize(cull_rect)));
103 display_list->Dispatch(
104 impeller_dispatcher,
105 SkIRect::MakeWH(cull_rect.width, cull_rect.height));
106 impeller_dispatcher.FinishRecording();
107 aiks_context->GetContentContext().GetTransientsBuffer().Reset();
108 aiks_context->GetContentContext()
109 .GetLazyGlyphAtlas()
110 ->ResetTextFrames();
111 return true;
112#else
113 impeller::Rect dl_cull_rect = impeller::Rect::MakeSize(cull_rect);
114 impeller::DlDispatcher impeller_dispatcher(dl_cull_rect);
115 display_list->Dispatch(
116 impeller_dispatcher,
117 SkIRect::MakeWH(cull_rect.width, cull_rect.height));
118 auto picture = impeller_dispatcher.EndRecordingAsPicture();
119
120 return aiks_context->Render(picture, render_target,
121 /*reset_host_buffer=*/true);
122#endif
123 }));
124 });
125
126 return std::make_unique<SurfaceFrame>(
127 nullptr, // surface
128 SurfaceFrame::FramebufferInfo{}, // framebuffer info
129 submit_callback, // submit callback
130 size, // frame size
131 nullptr, // context result
132 true // display list fallback
133 );
134}
135
136// |Surface|
138 // This backend does not currently support root surface transformations. Just
139 // return identity.
140 return {};
141}
142
143// |Surface|
145 // Impeller != Skia.
146 return nullptr;
147}
148
149// |Surface|
150std::unique_ptr<GLContextResult>
152 // This backend has no such concept.
153 return std::make_unique<GLContextDefaultResult>(true);
154}
155
156// |Surface|
158 return false;
159}
160
161// |Surface|
162std::shared_ptr<impeller::AiksContext>
164 return aiks_context_;
165}
166
167} // namespace flutter
Developer-facing API for rendering anything within the engine.
Definition dl_canvas.h:37
std::unique_ptr< GLContextResult > MakeRenderContextCurrent() override
GPUSurfaceVulkanImpeller(std::shared_ptr< impeller::Context > context)
std::shared_ptr< impeller::AiksContext > GetAiksContext() const override
std::unique_ptr< SurfaceFrame > AcquireFrame(const SkISize &size) override
std::function< bool(SurfaceFrame &surface_frame, DlCanvas *canvas)> SubmitCallback
sk_sp< DisplayList > BuildDisplayList()
static SurfaceContextVK & Cast(Context &base)
Performs a first pass over the display list to collect all text frames.
static std::shared_ptr< TypographerContext > Make()
VkSurfaceKHR surface
Definition main.cc:49
#define FML_LOG(severity)
Definition logging.h:82
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition switches.h:259
internal::CopyableLambda< T > MakeCopyable(T lambda)
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition SkRect.h:56
A 4x4 matrix using column-major storage.
Definition matrix.h:37
RoundOut(const TRect< U > &r)
Definition rect.h:643
static constexpr TRect MakeSize(const TSize< U > &size)
Definition rect.h:146
#define ERROR(message)