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 #ifdef RS_ENABLE_OLD_VK 20 #include <vulkan_window.h> 21 #endif 22 #include "surface.h" 23 #include "window.h" 24 #include "surface_ohos.h" 25 #include "surface_frame_ohos_vulkan.h" 26 #include "rs_surface_ohos_vulkan.h" 27 #include "native_buffer_utils.h" 28 #include "platform/common/rs_system_properties.h" 29 30 namespace OHOS { 31 namespace Rosen { 32 class SurfaceOhosVulkan : public SurfaceOhos { 33 public: 34 explicit SurfaceOhosVulkan(const sptr<Surface>& producer); 35 ~SurfaceOhosVulkan() override; 36 IsValid()37 bool IsValid() const override 38 { 39 return producer_ != nullptr; 40 } 41 42 std::unique_ptr<SurfaceFrame> RequestFrame(int32_t width, int32_t height) override; 43 std::unique_ptr<SurfaceFrame> NativeRequestFrame(int32_t width, int32_t height) override; 44 bool FlushFrame(std::unique_ptr<SurfaceFrame>& frame) override; 45 bool NativeFlushFrame(std::unique_ptr<SurfaceFrame>& frame) override; 46 SkCanvas* GetSkCanvas(std::unique_ptr<SurfaceFrame>& frame) override; 47 int32_t RequestNativeWindowBuffer(NativeWindowBuffer** nativeWindowBuffer, 48 int32_t width, int32_t height, int& fenceFd); 49 50 void CreateVkSemaphore( 51 VkSemaphore* semaphore, RsVulkanContext& vkContext, NativeBufferUtils::NativeSurfaceInfo& nativeSurface); 52 Drawing::Canvas* GetCanvas(std::unique_ptr<SurfaceFrame>& frame) override; 53 private: 54 void SetNativeWindowInfo(int32_t width, int32_t height); 55 std::unique_ptr<SurfaceFrameOhosVulkan> frame_; 56 struct NativeWindow *mNativeWindow_ = nullptr; 57 #ifdef RS_ENABLE_OLD_VK 58 vulkan::RSVulkanWindow *mVulkanWindow_ = nullptr; 59 #endif 60 std::list<NativeWindowBuffer*> surfaceList_; 61 std::unordered_map<NativeWindowBuffer*, NativeBufferUtils::NativeSurfaceInfo> surfaceMap_; 62 std::shared_ptr<Drawing::GPUContext> drContext_; 63 std::shared_ptr<Drawing::Surface> surface_ = nullptr; 64 }; 65 } // namespace Rosen 66 } // namespace OHOS 67 #endif 68