• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #if RENDER_HAS_GLES_BACKEND
19 #define EGL_EGLEXT_PROTOTYPES
20 #include <EGL/egl.h>
21 #include <EGL/eglext.h>
22 #undef EGL_EGLEXT_PROTOTYPES
23 #endif
24 
25 #include <render/namespace.h>
26 
27 #include "gles/device_gles.h"
28 #include "gles/gl_functions.h"
29 #include "util/log.h"
30 
RENDER_BEGIN_NAMESPACE()31 RENDER_BEGIN_NAMESPACE()
32 GpuSemaphoreGles::GpuSemaphoreGles(Device& device) : device_((DeviceGLES&)device)
33 {
34     PLUGIN_UNUSED(device_);
35     PLUGIN_ASSERT(device_.IsActive());
36 }
37 
GpuSemaphoreGles(Device & device,const uint64_t handle)38 GpuSemaphoreGles::GpuSemaphoreGles(Device& device, const uint64_t handle)
39     : device_((DeviceGLES&)device), ownsResources_(false)
40 {
41     PLUGIN_ASSERT(device_.IsActive());
42     // do not let invalid inputs in
43     PLUGIN_ASSERT(handle != 0);
44     if (handle) {
45         plat_.sync = handle;
46     }
47 }
48 
~GpuSemaphoreGles()49 GpuSemaphoreGles::~GpuSemaphoreGles()
50 {
51     if (ownsResources_ && plat_.sync) {
52         PLUGIN_ASSERT(device_.IsActive());
53 #if RENDER_HAS_GLES_BACKEND
54         const auto disp = static_cast<const DevicePlatformDataGLES &>(device_.GetEglState().GetPlatformData()).display;
55         EGLSyncKHR sync = reinterpret_cast<EGLSyncKHR>(plat_.sync);
56         eglDestroySyncKHR(disp, sync);
57 #elif RENDER_HAS_GL_BACKEND
58         GLsync sync = reinterpret_cast<GLsync>(plat_.sync);
59         glDeleteSync(sync);
60 #else
61         BASE_LOG_E("no available backend type");
62 #endif
63     }
64     plat_.sync = 0;
65 }
66 
GetHandle() const67 uint64_t GpuSemaphoreGles::GetHandle() const
68 {
69     return plat_.sync;
70 }
71 
GetPlatformData() const72 const GpuSemaphorePlatformDataGles& GpuSemaphoreGles::GetPlatformData() const
73 {
74     return plat_;
75 }
76 RENDER_END_NAMESPACE()
77