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 RENDER_CONTEXT_BASE_H 17 #define RENDER_CONTEXT_BASE_H 18 19 #include "rs_render_surface_frame.h" 20 21 namespace OHOS { 22 namespace Rosen { 23 class RenderContextBase { 24 public: RenderContextBase()25 explicit RenderContextBase() 26 { 27 frame_ = std::make_unique<RSRenderSurfaceFrame>(); 28 std::shared_ptr<EGLState> eglState = std::make_shared<EGLState>(); 29 frame_->eglState = eglState; 30 } 31 virtual ~RenderContextBase() = default; 32 virtual void Init() = 0; IsContextReady()33 virtual bool IsContextReady() { return false; } 34 virtual void MakeCurrent(void* curSurface = nullptr, void* curContext = nullptr) {} 35 virtual void* CreateContext(bool share = false) { return nullptr; }; CreateSurface(const std::shared_ptr<RSRenderSurfaceFrame> & frame)36 virtual bool CreateSurface(const std::shared_ptr<RSRenderSurfaceFrame>& frame) { return false; } DestroySurface(const std::shared_ptr<RSRenderSurfaceFrame> & frame)37 virtual void DestroySurface(const std::shared_ptr<RSRenderSurfaceFrame>& frame) {} DamageFrame(const std::shared_ptr<RSRenderSurfaceFrame> & frame)38 virtual void DamageFrame(const std::shared_ptr<RSRenderSurfaceFrame>& frame) {}; GetBufferAge()39 virtual int32_t GetBufferAge() { return 0; } SwapBuffers(const std::shared_ptr<RSRenderSurfaceFrame> & frame)40 virtual void SwapBuffers(const std::shared_ptr<RSRenderSurfaceFrame>& frame) {} Destroy()41 virtual void Destroy() {} GetRSRenderSurfaceFrame()42 std::shared_ptr<RSRenderSurfaceFrame> GetRSRenderSurfaceFrame() 43 { 44 return frame_; 45 } SetPlatformName(const PlatformName & platformName)46 void SetPlatformName(const PlatformName& platformName) 47 { 48 platformName_ = platformName; 49 } GetPlatformName()50 PlatformName GetPlatformName() const 51 { 52 return platformName_; 53 } SetRenderType(const RenderType & renderType)54 void SetRenderType(const RenderType& renderType) 55 { 56 renderType_ = renderType; 57 } GetRenderType()58 RenderType GetRenderType() const 59 { 60 return renderType_; 61 } 62 protected: 63 std::shared_ptr<RSRenderSurfaceFrame> frame_ = nullptr; 64 PlatformName platformName_ = PlatformName::OHOS; 65 RenderType renderType_ = RenderType::GLES; 66 }; 67 } 68 } 69 #endif