Flutter Engine
The Flutter Engine
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),
91 -> bool {
92#if ENABLE_EXPERIMENTAL_CANVAS
94 aiks_context->GetContentContext(), impeller::Matrix());
95 display_list->Dispatch(
96 collector,
97 SkIRect::MakeWH(cull_rect.width, cull_rect.height));
98 impeller::ExperimentalDlDispatcher impeller_dispatcher(
99 aiks_context->GetContentContext(), render_target,
100 display_list->root_has_backdrop_filter(),
101 display_list->max_root_blend_mode(),
103 impeller::Rect::MakeSize(cull_rect)));
104 display_list->Dispatch(
105 impeller_dispatcher,
106 SkIRect::MakeWH(cull_rect.width, cull_rect.height));
107 impeller_dispatcher.FinishRecording();
108 aiks_context->GetContentContext().GetTransientsBuffer().Reset();
109 aiks_context->GetContentContext()
110 .GetLazyGlyphAtlas()
111 ->ResetTextFrames();
112 return true;
113#else
114 impeller::Rect dl_cull_rect = impeller::Rect::MakeSize(cull_rect);
115 impeller::DlDispatcher impeller_dispatcher(dl_cull_rect);
116 display_list->Dispatch(
117 impeller_dispatcher,
118 SkIRect::MakeWH(cull_rect.width, cull_rect.height));
119 auto picture = impeller_dispatcher.EndRecordingAsPicture();
120
121 return aiks_context->Render(picture, render_target,
122 /*reset_host_buffer=*/true);
123#endif
124 }));
125 });
126
127 return std::make_unique<SurfaceFrame>(
128 nullptr, // surface
129 SurfaceFrame::FramebufferInfo{}, // framebuffer info
130 submit_callback, // submit callback
131 size, // frame size
132 nullptr, // context result
133 true // display list fallback
134 );
135}
136
137// |Surface|
138SkMatrix GPUSurfaceVulkanImpeller::GetRootTransformation() const {
139 // This backend does not currently support root surface transformations. Just
140 // return identity.
141 return {};
142}
143
144// |Surface|
145GrDirectContext* GPUSurfaceVulkanImpeller::GetContext() {
146 // Impeller != Skia.
147 return nullptr;
148}
149
150// |Surface|
151std::unique_ptr<GLContextResult>
152GPUSurfaceVulkanImpeller::MakeRenderContextCurrent() {
153 // This backend has no such concept.
154 return std::make_unique<GLContextDefaultResult>(true);
155}
156
157// |Surface|
158bool GPUSurfaceVulkanImpeller::EnableRasterCache() const {
159 return false;
160}
161
162// |Surface|
163std::shared_ptr<impeller::AiksContext>
164GPUSurfaceVulkanImpeller::GetAiksContext() const {
165 return aiks_context_;
166}
167
168} // namespace flutter
GPUSurfaceVulkanImpeller(std::shared_ptr< impeller::Context > context)
std::function< bool(SurfaceFrame &surface_frame, DlCanvas *canvas)> SubmitCallback
Definition: surface_frame.h:27
static SurfaceContextVK & Cast(Context &base)
Definition: backend_cast.h:13
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
sk_sp< const SkPicture > picture
Definition: SkRecords.h:299
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)
Definition: make_copyable.h:57
flutter::DlCanvas DlCanvas
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition: SkRect.h:56
Definition: SkSize.h:16
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
RoundOut(const TRect< U > &r)
Definition: rect.h:666
static constexpr TRect MakeSize(const TSize< U > &size)
Definition: rect.h:146
#define ERROR(message)
Definition: elf_loader.cc:260