1 /*
2  * Copyright (c) 2024 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 "drawing_gpu_context.h"
17 
18 #include "image/gpu_context.h"
19 
20 using namespace OHOS;
21 using namespace Rosen;
22 using namespace Drawing;
23 
CastToGPUContext(OH_Drawing_GpuContext * cGpuContext)24 static GPUContext* CastToGPUContext(OH_Drawing_GpuContext* cGpuContext)
25 {
26     return reinterpret_cast<GPUContext*>(cGpuContext);
27 }
28 
OH_Drawing_GpuContextCreateFromGL(OH_Drawing_GpuContextOptions ops)29 OH_Drawing_GpuContext* OH_Drawing_GpuContextCreateFromGL(OH_Drawing_GpuContextOptions ops)
30 {
31     GPUContextOptions contextOps;
32     contextOps.SetAllowPathMaskCaching(ops.allowPathMaskCaching);
33     GPUContext* context = new GPUContext();
34     bool isSuccess = context->BuildFromGL(contextOps);
35     if (isSuccess) {
36         return (OH_Drawing_GpuContext*)context;
37     }
38     delete context;
39     context = nullptr;
40     return nullptr;
41 }
42 
OH_Drawing_GpuContextDestroy(OH_Drawing_GpuContext * cGpuContext)43 void OH_Drawing_GpuContextDestroy(OH_Drawing_GpuContext* cGpuContext)
44 {
45     if (cGpuContext == nullptr) {
46         return;
47     }
48     delete CastToGPUContext(cGpuContext);
49     cGpuContext = nullptr;
50 }
51