• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "flutter/fml/logging.h"
7 
8 namespace flutter {
9 
GPUSurfaceVulkan(fml::RefPtr<vulkan::VulkanProcTable> proc_table,std::unique_ptr<vulkan::VulkanNativeSurface> native_surface)10 GPUSurfaceVulkan::GPUSurfaceVulkan(
11     fml::RefPtr<vulkan::VulkanProcTable> proc_table,
12     std::unique_ptr<vulkan::VulkanNativeSurface> native_surface)
13     : window_(std::move(proc_table), std::move(native_surface)),
14       weak_factory_(this) {}
15 
16 GPUSurfaceVulkan::~GPUSurfaceVulkan() = default;
17 
18 // |Surface|
IsValid()19 bool GPUSurfaceVulkan::IsValid() {
20   return window_.IsValid();
21 }
22 
23 // |Surface|
AcquireFrame(const SkISize & size)24 std::unique_ptr<SurfaceFrame> GPUSurfaceVulkan::AcquireFrame(
25     const SkISize& size) {
26   auto surface = window_.AcquireSurface();
27 
28   if (surface == nullptr) {
29     return nullptr;
30   }
31 
32   SurfaceFrame::SubmitCallback callback =
33       [weak_this = weak_factory_.GetWeakPtr()](const SurfaceFrame&,
34                                                SkCanvas* canvas) -> bool {
35     // Frames are only ever acquired on the GPU thread. This is also the thread
36     // on which the weak pointer factory is collected (as this instance is owned
37     // by the rasterizer). So this use of weak pointers is safe.
38     if (canvas == nullptr || !weak_this) {
39       return false;
40     }
41     return weak_this->window_.SwapBuffers();
42   };
43   return std::make_unique<SurfaceFrame>(std::move(surface),
44                                         std::move(callback));
45 }
46 
47 // |Surface|
GetRootTransformation() const48 SkMatrix GPUSurfaceVulkan::GetRootTransformation() const {
49   // This backend does not support delegating to the underlying platform to
50   // query for root surface transformations. Just return identity.
51   SkMatrix matrix;
52   matrix.reset();
53   return matrix;
54 }
55 
56 // |Surface|
GetContext()57 GrContext* GPUSurfaceVulkan::GetContext() {
58   return window_.GetSkiaGrContext();
59 }
60 
61 }  // namespace flutter
62