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) : m_egl(egl), m_display(display)
34 {
35 }
36
~UniqueDisplay(void)37 UniqueDisplay::~UniqueDisplay(void)
38 {
39 if (m_display != EGL_NO_DISPLAY)
40 m_egl.terminate(m_display);
41 }
42
operator bool(void) const43 UniqueDisplay::operator bool(void) const
44 {
45 return m_display != EGL_NO_DISPLAY;
46 }
47
UniqueSurface(const Library & egl,EGLDisplay display,EGLSurface surface)48 UniqueSurface::UniqueSurface(const Library &egl, EGLDisplay display, EGLSurface surface)
49 : m_egl(egl)
50 , m_display(display)
51 , m_surface(surface)
52 {
53 }
54
~UniqueSurface(void)55 UniqueSurface::~UniqueSurface(void)
56 {
57 if (m_surface != EGL_NO_SURFACE)
58 m_egl.destroySurface(m_display, m_surface);
59 }
60
operator bool(void) const61 UniqueSurface::operator bool(void) const
62 {
63 return m_surface != EGL_NO_SURFACE;
64 }
65
UniqueContext(const Library & egl,EGLDisplay display,EGLContext context)66 UniqueContext::UniqueContext(const Library &egl, EGLDisplay display, EGLContext context)
67 : m_egl(egl)
68 , m_display(display)
69 , m_context(context)
70 {
71 }
72
~UniqueContext(void)73 UniqueContext::~UniqueContext(void)
74 {
75 if (m_context != EGL_NO_CONTEXT)
76 m_egl.destroyContext(m_display, m_context);
77 }
78
operator bool(void) const79 UniqueContext::operator bool(void) const
80 {
81 return m_context != EGL_NO_CONTEXT;
82 }
83
ScopedCurrentContext(const Library & egl,EGLDisplay display,EGLSurface draw,EGLSurface read,EGLContext context)84 ScopedCurrentContext::ScopedCurrentContext(const Library &egl, EGLDisplay display, EGLSurface draw, EGLSurface read,
85 EGLContext context)
86 : m_egl(egl)
87 , m_display(display)
88 {
89 EGLU_CHECK_CALL(m_egl, makeCurrent(display, draw, read, context));
90 }
91
~ScopedCurrentContext(void)92 ScopedCurrentContext::~ScopedCurrentContext(void)
93 {
94 m_egl.makeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
95 }
96
UniqueImage(const Library & egl,EGLDisplay display,EGLImage image)97 UniqueImage::UniqueImage(const Library &egl, EGLDisplay display, EGLImage image)
98 : m_egl(egl)
99 , m_display(display)
100 , m_image(image)
101 {
102 }
103
~UniqueImage(void)104 UniqueImage::~UniqueImage(void)
105 {
106 if (m_image != EGL_NO_IMAGE)
107 m_egl.destroyImageKHR(m_display, m_image);
108 }
109
operator bool(void) const110 UniqueImage::operator bool(void) const
111 {
112 return m_image != EGL_NO_IMAGE;
113 }
114
115 } // namespace eglu
116