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 "gpu_semaphore_gles.h"
17 
18 #include <render/namespace.h>
19 
20 #include "gles/device_gles.h"
21 #include "gles/gl_functions.h"
22 #include "util/log.h"
23 
RENDER_BEGIN_NAMESPACE()24 RENDER_BEGIN_NAMESPACE()
25 GpuSemaphoreGles::GpuSemaphoreGles(Device& device) : device_((DeviceGLES&)device)
26 {
27     PLUGIN_ASSERT(device_.IsActive());
28 }
29 
GpuSemaphoreGles(Device & device,const uint64_t handle)30 GpuSemaphoreGles::GpuSemaphoreGles(Device& device, const uint64_t handle)
31     : device_((DeviceGLES&)device), ownsResources_(false)
32 {
33     PLUGIN_ASSERT(device_.IsActive());
34     // do not let invalid inputs in
35     PLUGIN_ASSERT(handle != 0);
36     if (handle) {
37         plat_.sync = handle;
38     }
39 }
40 
~GpuSemaphoreGles()41 GpuSemaphoreGles::~GpuSemaphoreGles()
42 {
43     if (ownsResources_ && plat_.sync) {
44         PLUGIN_ASSERT(device_.IsActive());
45         GLsync sync = reinterpret_cast<GLsync>(plat_.sync);
46         glDeleteSync(sync);
47     }
48     plat_.sync = 0;
49 }
50 
GetHandle() const51 uint64_t GpuSemaphoreGles::GetHandle() const
52 {
53     return plat_.sync;
54 }
55 
GetPlatformData() const56 const GpuSemaphorePlatformDataGles& GpuSemaphoreGles::GetPlatformData() const
57 {
58     return plat_;
59 }
60 RENDER_END_NAMESPACE()
61