1 /* 2 * Copyright (c) 2022 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 "canvas_context.h" 17 18 #include <iostream> 19 20 #include "drawing_utils.h" 21 #include "software_render_backend.h" 22 #include "gles_render_backend.h" 23 #include "vulkan_render_backend.h" 24 25 namespace OHOS { 26 namespace Rosen { Create()27CanvasContext* CanvasContext::Create() 28 { 29 auto type = Setting::GetRenderBackendType(); 30 switch (type) { 31 case RenderBackendType::VULKAN: 32 #ifdef ACE_ENABLE_VK 33 std::cout << "CanvasContext::Create with vulkan backend" << std::endl; 34 return new CanvasContext(std::make_unique<VulkanRenderBackend>()); 35 #endif 36 case RenderBackendType::GLES: 37 #ifdef ACE_ENABLE_GL 38 std::cout << "CanvasContext::Create with gles backend" << std::endl; 39 return new CanvasContext(std::make_unique<GLESRenderBackend>()); 40 #endif 41 case RenderBackendType::SOFTWARE: 42 std::cout << "CanvasContext::Create with software backend" << std::endl; 43 return new CanvasContext(std::make_unique<SoftwareRenderBackend>()); 44 default: 45 return nullptr; 46 } 47 } 48 CanvasContext(std::unique_ptr<IRenderBackend> renderBackend)49CanvasContext::CanvasContext(std::unique_ptr<IRenderBackend> renderBackend) 50 : renderBackend_(std::move(renderBackend)) 51 { 52 } 53 ~CanvasContext()54CanvasContext::~CanvasContext() 55 { 56 renderBackend_->Destroy(); 57 } 58 CreateSurface(void * window)59void* CanvasContext::CreateSurface(void* window) 60 { 61 return renderBackend_->CreateSurface(window); 62 } 63 RenderFrame()64void CanvasContext::RenderFrame() 65 { 66 renderBackend_->RenderFrame(); 67 } 68 AcquireCanvas(std::unique_ptr<SurfaceFrame> & frame)69SkCanvas* CanvasContext::AcquireCanvas(std::unique_ptr<SurfaceFrame>& frame) 70 { 71 return renderBackend_->AcquireCanvas(frame); 72 } 73 InitDrawContext()74void CanvasContext::InitDrawContext() 75 { 76 renderBackend_->InitDrawContext(); 77 } 78 MakeCurrent()79void CanvasContext::MakeCurrent() 80 { 81 renderBackend_->MakeCurrent(); 82 } 83 SwapBuffers()84void CanvasContext::SwapBuffers() 85 { 86 renderBackend_->SwapBuffers(); 87 } 88 } 89 }