Debian Codegraph @

opencl/source/sharings/gl/windows/gl_context_guard_windows.cpp

raw
1 /*
2 * Copyright (C) 2020-2021 Intel Corporation
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 */
7
8 #include "opencl/source/sharings/gl/gl_context_guard.h"
9 #include "opencl/source/sharings/gl/windows/gl_sharing_windows.h"
10
11 namespace NEO {
12 GLContextGuard::GLContextGuard(GLSharingFunctions &sharingFcns) : sharingFunctions(&sharingFcns) {
13 auto &sharing = *static_cast<GLSharingFunctionsWindows *>(sharingFunctions);
14
15 currentContextHandle = sharing.getCurrentContext();
16 currentDisplayHandle = sharing.getCurrentDisplay();
17 auto ctxToMakeCurrent = sharing.getContextHandle();
18
19 if (currentContextHandle == 0) {
20 ctxToMakeCurrent = sharing.getBackupContextHandle();
21 }
22
23 if (currentContextHandle != sharing.getContextHandle() && currentContextHandle != sharing.getBackupContextHandle()) {
24 if (sharing.makeCurrent(ctxToMakeCurrent) == GL_FALSE) {
25 while (sharing.makeCurrent(sharing.getBackupContextHandle()) == GL_FALSE) {
26 ;
27 }
28 }
29 }
30 }
31
32 GLContextGuard::~GLContextGuard() {
33 auto &sharing = *static_cast<GLSharingFunctionsWindows *>(sharingFunctions);
34 if (currentContextHandle != sharing.getContextHandle()) {
35 sharing.makeCurrent(currentContextHandle, currentDisplayHandle);
36 }
37 }
38 } // namespace NEO