Files
compute-runtime/runtime/sharings/gl/gl_context_guard.cpp
Maciej Plewka 9e52684f5b Change namespace from OCLRT to NEO
Change-Id: If965c79d70392db26597aea4c2f3b7ae2820fe96
Signed-off-by: Maciej Plewka <maciej.plewka@intel.com>
2019-03-26 15:48:19 +01:00

35 lines
1.1 KiB
C++

/*
* Copyright (C) 2018-2019 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "runtime/sharings/gl/gl_sharing.h"
namespace NEO {
GLContextGuard::GLContextGuard(GLSharingFunctions &sharingFcns) : sharingFunctions(&sharingFcns) {
currentContextHandle = sharingFcns.getCurrentContext();
currentDisplayHandle = sharingFcns.getCurrentDisplay();
auto ctxToMakeCurrent = sharingFcns.getContextHandle();
if (currentContextHandle == 0) {
ctxToMakeCurrent = sharingFcns.getBackupContextHandle();
}
if (currentContextHandle != sharingFcns.getContextHandle() && currentContextHandle != sharingFcns.getBackupContextHandle()) {
if (sharingFcns.makeCurrent(ctxToMakeCurrent) == GL_FALSE) {
while (sharingFcns.makeCurrent(sharingFcns.getBackupContextHandle()) == GL_FALSE) {
;
}
}
}
}
GLContextGuard::~GLContextGuard() {
if (currentContextHandle != sharingFunctions->getContextHandle()) {
sharingFunctions->makeCurrent(currentContextHandle, currentDisplayHandle);
}
}
} // namespace NEO