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