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/platform/android/android_surface_vulkan.h" 6 7 #include <utility> 8 9 #include "flutter/fml/logging.h" 10 #include "flutter/shell/gpu/gpu_surface_vulkan.h" 11 #include "flutter/vulkan/vulkan_native_surface_android.h" 12 13 namespace flutter { 14 AndroidSurfaceVulkan()15AndroidSurfaceVulkan::AndroidSurfaceVulkan() 16 : proc_table_(fml::MakeRefCounted<vulkan::VulkanProcTable>()) {} 17 18 AndroidSurfaceVulkan::~AndroidSurfaceVulkan() = default; 19 IsValid() const20bool AndroidSurfaceVulkan::IsValid() const { 21 return proc_table_->HasAcquiredMandatoryProcAddresses(); 22 } 23 24 // |AndroidSurface| TeardownOnScreenContext()25void AndroidSurfaceVulkan::TeardownOnScreenContext() { 26 // Nothing to do. 27 } 28 29 // |AndroidSurface| CreateGPUSurface()30std::unique_ptr<Surface> AndroidSurfaceVulkan::CreateGPUSurface() { 31 if (!IsValid()) { 32 return nullptr; 33 } 34 35 if (!native_window_ || !native_window_->IsValid()) { 36 return nullptr; 37 } 38 39 auto vulkan_surface_android = 40 std::make_unique<vulkan::VulkanNativeSurfaceAndroid>( 41 native_window_->handle()); 42 43 if (!vulkan_surface_android->IsValid()) { 44 return nullptr; 45 } 46 47 auto gpu_surface = std::make_unique<GPUSurfaceVulkan>( 48 proc_table_, std::move(vulkan_surface_android)); 49 50 if (!gpu_surface->IsValid()) { 51 return nullptr; 52 } 53 54 return gpu_surface; 55 } 56 57 // |AndroidSurface| OnScreenSurfaceResize(const SkISize & size) const58bool AndroidSurfaceVulkan::OnScreenSurfaceResize(const SkISize& size) const { 59 return true; 60 } 61 62 // |AndroidSurface| ResourceContextMakeCurrent()63bool AndroidSurfaceVulkan::ResourceContextMakeCurrent() { 64 FML_DLOG(ERROR) << "The vulkan backend does not support resource contexts."; 65 return false; 66 } 67 68 // |AndroidSurface| ResourceContextClearCurrent()69bool AndroidSurfaceVulkan::ResourceContextClearCurrent() { 70 FML_DLOG(ERROR) << "The vulkan backend does not support resource contexts."; 71 return false; 72 } 73 74 // |AndroidSurface| SetNativeWindow(fml::RefPtr<AndroidNativeWindow> window)75bool AndroidSurfaceVulkan::SetNativeWindow( 76 fml::RefPtr<AndroidNativeWindow> window) { 77 native_window_ = std::move(window); 78 return native_window_ && native_window_->IsValid(); 79 } 80 81 } // namespace flutter 82