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 #include "vulkan_render_backend.h" 17 #include <iostream> 18 #include "drawing_utils.h" 19 #include "skia_adapter/skia_surface.h" 20 #include "surface_ohos_vulkan.h" 21 22 namespace OHOS { 23 namespace Rosen { 24 Destroy()25void VulkanRenderBackend::Destroy() 26 { 27 grContext_ = nullptr; 28 skSurface_ = nullptr; 29 } 30 RenderFrame()31void VulkanRenderBackend::RenderFrame() 32 { 33 if (drSurface_ == nullptr) { 34 LOGE("drSurface is nullptr, can not RenderFrame"); 35 return; 36 } 37 skSurface_ = drSurface_->GetImpl<Drawing::SkiaSurface>()->GetSkSurface().get(); 38 if (skSurface_ == nullptr) { 39 std::cout << "skSurface is nullptr, can not RenderFrame" << std::endl; 40 return; 41 } 42 // flush commands 43 if (skSurface_->getCanvas() != nullptr) { 44 skSurface_->getCanvas()->flush(); 45 std::cout << "VulkanRenderBackend skia RenderFrame flushing end" << std::endl; 46 } else { 47 std::cout << "skia canvas is nullptr!!!" << std::endl; 48 } 49 } 50 AcquireSkCanvas(std::unique_ptr<SurfaceFrame> & frame)51SkCanvas* VulkanRenderBackend::AcquireSkCanvas(std::unique_ptr<SurfaceFrame>& frame) 52 { 53 auto vulkan_frame = reinterpret_cast<SurfaceFrameOhosVulkan*>(frame.get()); 54 drSurface_ = vulkan_frame->GetSurface(); 55 skSurface_ = drSurface_->GetImpl<Drawing::SkiaSurface>()->GetSkSurface().get(); 56 return skSurface_->getCanvas(); 57 } 58 AcquireDrCanvas(std::unique_ptr<SurfaceFrame> & frame)59Drawing::Canvas* VulkanRenderBackend::AcquireDrCanvas(std::unique_ptr<SurfaceFrame>& frame) 60 { 61 auto vulkan_frame = reinterpret_cast<SurfaceFrameOhosVulkan*>(frame.get()); 62 drSurface_ = vulkan_frame->GetSurface(); 63 return vulkan_frame->GetCanvas(); 64 } 65 } 66 }