• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 DRAWING_CONTEXT_H
17 #define DRAWING_CONTEXT_H
18 
19 #if defined(NEW_SKIA)
20 #include <include/gpu/GrDirectContext.h>
21 #else
22 #include <include/gpu/GrContext.h>
23 #endif
24 
25 #include "rs_render_surface_frame.h"
26 
27 namespace OHOS {
28 namespace Rosen {
29 class DrawingContext {
30 public:
DrawingContext(RenderType renderType)31     explicit DrawingContext(RenderType renderType) : renderType_(renderType) {}
32     ~DrawingContext() = default;
33     sk_sp<SkSurface> AcquireSurface(const std::shared_ptr<RSRenderSurfaceFrame>& frame);
34     bool SetUpDrawingContext();
35 #if defined(NEW_SKIA)
36     GrDirectContext* GetDrawingContext() const;
37 #else
38     GrContext* GetDrawingContext() const;
39 #endif
40 private:
41     sk_sp<SkSurface> AcquireSurfaceInGLES(const std::shared_ptr<RSRenderSurfaceFrame>& frame);
42     sk_sp<SkSurface> AcquireSurfaceInRaster(const std::shared_ptr<RSRenderSurfaceFrame>& frame);
43     sk_sp<SkSurface> AcquireSurfaceInVulkan(const std::shared_ptr<RSRenderSurfaceFrame>& frame);
44     sk_sp<SkColorSpace> GetSkColorSpace(const std::shared_ptr<RSRenderSurfaceFrame>& frame);
45 #if defined(NEW_SKIA)
46     sk_sp<GrDirectContext> grContext_ = nullptr;
47 #else
48     sk_sp<GrContext> grContext_ = nullptr;
49 #endif
50     RenderType renderType_;
51 };
52 }
53 }
54 #endif