Flutter Engine
gpu_surface_vulkan.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.h"
6 
7 #include "flutter/fml/logging.h"
8 
9 namespace flutter {
10 
12  GPUSurfaceVulkanDelegate* delegate,
13  std::unique_ptr<vulkan::VulkanNativeSurface> native_surface,
14  bool render_to_surface)
15  : window_(delegate->vk(), std::move(native_surface), render_to_surface),
16  delegate_(delegate),
17  render_to_surface_(render_to_surface),
18  weak_factory_(this) {}
19 
21 
23  return window_.IsValid();
24 }
25 
26 std::unique_ptr<SurfaceFrame> GPUSurfaceVulkan::AcquireFrame(
27  const SkISize& size) {
28  // TODO(38466): Refactor GPU surface APIs take into account the fact that an
29  // external view embedder may want to render to the root surface.
30  if (!render_to_surface_) {
31  return std::make_unique<SurfaceFrame>(
32  nullptr, true, [](const SurfaceFrame& surface_frame, SkCanvas* canvas) {
33  return true;
34  });
35  }
36 
37  auto surface = window_.AcquireSurface();
38 
39  if (surface == nullptr) {
40  return nullptr;
41  }
42 
44  [weak_this = weak_factory_.GetWeakPtr()](const SurfaceFrame&,
45  SkCanvas* canvas) -> bool {
46  // Frames are only ever acquired on the raster thread. This is also the
47  // thread on which the weak pointer factory is collected (as this instance
48  // is owned by the rasterizer). So this use of weak pointers is safe.
49  if (canvas == nullptr || !weak_this) {
50  return false;
51  }
52  return weak_this->window_.SwapBuffers();
53  };
54  return std::make_unique<SurfaceFrame>(std::move(surface), true,
55  std::move(callback));
56 }
57 
59  // This backend does not support delegating to the underlying platform to
60  // query for root surface transformations. Just return identity.
61  SkMatrix matrix;
62  matrix.reset();
63  return matrix;
64 }
65 
66 GrDirectContext* GPUSurfaceVulkan::GetContext() {
67  return window_.GetSkiaGrContext();
68 }
69 
71  return delegate_->GetExternalViewEmbedder();
72 }
73 
74 } // namespace flutter
std::function< bool(const SurfaceFrame &surface_frame, SkCanvas *canvas)> SubmitCallback
Definition: surface_frame.h:22
std::unique_ptr< SurfaceFrame > AcquireFrame(const SkISize &size) override
ExternalViewEmbedder * GetExternalViewEmbedder() override
Gets the view embedder that controls how the Flutter layer hierarchy split into multiple chunks shoul...
GPUSurfaceVulkan(GPUSurfaceVulkanDelegate *delegate, std::unique_ptr< vulkan::VulkanNativeSurface > native_surface, bool render_to_surface)
Definition: ref_ptr.h:252
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13
MockDelegate delegate_
GrDirectContext * GetSkiaGrContext()
flutter::ExternalViewEmbedder * GetExternalViewEmbedder() override
sk_sp< SkSurface > AcquireSurface()
GrDirectContext * GetContext() override
bool IsValid() const
SkMatrix GetRootTransformation() const override