1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program Tester Core
3  * ----------------------------------------
4  *
5  * Copyright 2014 The Android Open Source Project
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief EGL unique resources
22  *//*--------------------------------------------------------------------*/
23 
24 #include "egluUnique.hpp"
25 #include "eglwLibrary.hpp"
26 #include "eglwEnums.hpp"
27 
28 namespace eglu
29 {
30 
31 using namespace eglw;
32 
UniqueDisplay(const Library & egl,EGLDisplay display)33 UniqueDisplay::UniqueDisplay (const Library& egl, EGLDisplay display)
34 	: m_egl		(egl)
35 	, m_display	(display)
36 {
37 }
38 
~UniqueDisplay(void)39 UniqueDisplay::~UniqueDisplay (void)
40 {
41 	if (m_display != EGL_NO_DISPLAY)
42 		m_egl.terminate(m_display);
43 }
44 
operator bool(void) const45 UniqueDisplay::operator bool (void) const
46 {
47 	return m_display != EGL_NO_DISPLAY;
48 }
49 
UniqueSurface(const Library & egl,EGLDisplay display,EGLSurface surface)50 UniqueSurface::UniqueSurface (const Library& egl, EGLDisplay display, EGLSurface surface)
51 	: m_egl		(egl)
52 	, m_display	(display)
53 	, m_surface	(surface)
54 {
55 }
56 
~UniqueSurface(void)57 UniqueSurface::~UniqueSurface (void)
58 {
59 	if (m_surface != EGL_NO_SURFACE)
60 		m_egl.destroySurface(m_display, m_surface);
61 }
62 
operator bool(void) const63 UniqueSurface::operator bool (void) const
64 {
65 	return m_surface != EGL_NO_SURFACE;
66 }
67 
UniqueContext(const Library & egl,EGLDisplay display,EGLContext context)68 UniqueContext::UniqueContext (const Library& egl, EGLDisplay display, EGLContext context)
69 	: m_egl		(egl)
70 	, m_display	(display)
71 	, m_context	(context)
72 {
73 }
74 
~UniqueContext(void)75 UniqueContext::~UniqueContext (void)
76 {
77 	if (m_context != EGL_NO_CONTEXT)
78 		m_egl.destroyContext(m_display, m_context);
79 }
80 
operator bool(void) const81 UniqueContext::operator bool (void) const
82 {
83 	return m_context != EGL_NO_CONTEXT;
84 }
85 
ScopedCurrentContext(const Library & egl,EGLDisplay display,EGLSurface draw,EGLSurface read,EGLContext context)86 ScopedCurrentContext::ScopedCurrentContext (const Library& egl, EGLDisplay display, EGLSurface draw, EGLSurface read, EGLContext context)
87 	: m_egl		(egl)
88 	, m_display (display)
89 {
90 	EGLU_CHECK_CALL(m_egl, makeCurrent(display, draw, read, context));
91 }
92 
~ScopedCurrentContext(void)93 ScopedCurrentContext::~ScopedCurrentContext (void)
94 {
95 	m_egl.makeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
96 }
97 
UniqueImage(const Library & egl,EGLDisplay display,EGLImage image)98 UniqueImage::UniqueImage (const Library& egl, EGLDisplay display, EGLImage image)
99 	: m_egl		(egl)
100 	, m_display	(display)
101 	, m_image	(image)
102 {
103 }
104 
~UniqueImage(void)105 UniqueImage::~UniqueImage (void)
106 {
107 	if (m_image != EGL_NO_IMAGE)
108 		m_egl.destroyImageKHR(m_display, m_image);
109 }
110 
operator bool(void) const111 UniqueImage::operator bool (void) const
112 {
113 	return m_image != EGL_NO_IMAGE;
114 }
115 
116 } // eglu
117