1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef SURFACE_OHOS_VULKAN_H 17 #define SURFACE_OHOS_VULKAN_H 18 19 #include <vulkan_window.h> 20 #include "surface.h" 21 #include "window.h" 22 #include "surface_ohos.h" 23 #include "surface_frame_ohos_vulkan.h" 24 #include "rs_surface_ohos_vulkan.h" 25 #include "native_buffer_utils.h" 26 #include "platform/common/rs_system_properties.h" 27 28 namespace OHOS { 29 namespace Rosen { 30 class SurfaceOhosVulkan : public SurfaceOhos { 31 public: 32 explicit SurfaceOhosVulkan(const sptr<Surface>& producer); 33 ~SurfaceOhosVulkan() override; 34 IsValid()35 bool IsValid() const override 36 { 37 return producer_ != nullptr; 38 } 39 40 std::unique_ptr<SurfaceFrame> RequestFrame(int32_t width, int32_t height) override; 41 std::unique_ptr<SurfaceFrame> NativeRequestFrame(int32_t width, int32_t height) override; 42 bool FlushFrame(std::unique_ptr<SurfaceFrame>& frame) override; 43 bool NativeFlushFrame(std::unique_ptr<SurfaceFrame>& frame) override; 44 SkCanvas* GetSkCanvas(std::unique_ptr<SurfaceFrame>& frame) override; 45 int32_t RequestNativeWindowBuffer(NativeWindowBuffer** nativeWindowBuffer, 46 int32_t width, int32_t height, int& fenceFd); 47 48 void CreateVkSemaphore( 49 VkSemaphore* semaphore, RsVulkanContext& vkContext, NativeBufferUtils::NativeSurfaceInfo& nativeSurface); 50 Drawing::Canvas* GetCanvas(std::unique_ptr<SurfaceFrame>& frame) override; 51 private: 52 void SetNativeWindowInfo(int32_t width, int32_t height); 53 std::unique_ptr<SurfaceFrameOhosVulkan> frame_; 54 struct NativeWindow *mNativeWindow_ = nullptr; 55 vulkan::VulkanWindow *mVulkanWindow_ = nullptr; 56 std::list<NativeWindowBuffer*> surfaceList_; 57 std::unordered_map<NativeWindowBuffer*, NativeBufferUtils::NativeSurfaceInfo> surfaceMap_; 58 std::shared_ptr<Drawing::GPUContext> drContext_; 59 std::shared_ptr<Drawing::Surface> surface_ = nullptr; 60 }; 61 } // namespace Rosen 62 } // namespace OHOS 63 #endif 64