• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  ** Copyright 2007, The Android Open Source Project
3  **
4  ** Licensed under the Apache License, Version 2.0 (the "License");
5  ** you may not use this file except in compliance with the License.
6  ** You may obtain a copy of the License at
7  **
8  **     http://www.apache.org/licenses/LICENSE-2.0
9  **
10  ** Unless required by applicable law or agreed to in writing, software
11  ** distributed under the License is distributed on an "AS IS" BASIS,
12  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  ** See the License for the specific language governing permissions and
14  ** limitations under the License.
15  */
16 
17 #include <ctype.h>
18 #include <stdint.h>
19 #include <stdlib.h>
20 
21 #include <EGL/egl.h>
22 #include <EGL/eglext.h>
23 
24 #include <utils/threads.h>
25 
26 #include "egl_object.h"
27 
28 // ----------------------------------------------------------------------------
29 namespace android {
30 // ----------------------------------------------------------------------------
31 
egl_object_t(egl_display_t * disp)32 egl_object_t::egl_object_t(egl_display_t* disp) :
33     display(disp), count(1) {
34     // NOTE: this does an implicit incRef
35     display->addObject(this);
36 }
37 
~egl_object_t()38 egl_object_t::~egl_object_t() {
39 }
40 
terminate()41 void egl_object_t::terminate() {
42     // this marks the object as "terminated"
43     display->removeObject(this);
44     if (decRef() == 1) {
45         // shouldn't happen because this is called from LocalRef
46         ALOGE("egl_object_t::terminate() removed the last reference!");
47     }
48 }
49 
destroy()50 void egl_object_t::destroy() {
51     if (decRef() == 1) {
52         delete this;
53     }
54 }
55 
get(egl_display_t const * display,egl_object_t * object)56 bool egl_object_t::get(egl_display_t const* display, egl_object_t* object) {
57     // used by LocalRef, this does an incRef() atomically with
58     // checking that the object is valid.
59     return display->getObject(object);
60 }
61 
62 // ----------------------------------------------------------------------------
63 
egl_surface_t(egl_display_t * dpy,EGLConfig config,EGLNativeWindowType win,EGLSurface surface,egl_connection_t const * cnx)64 egl_surface_t::egl_surface_t(egl_display_t* dpy, EGLConfig config,
65         EGLNativeWindowType win, EGLSurface surface,
66         egl_connection_t const* cnx) :
67     egl_object_t(dpy), surface(surface), config(config), win(win), cnx(cnx)
68 {
69     if (win) {
70         getDisplay()->onWindowSurfaceCreated();
71     }
72 }
73 
~egl_surface_t()74 egl_surface_t::~egl_surface_t() {
75     ANativeWindow* const window = win.get();
76     if (window != NULL) {
77         native_window_set_buffers_format(window, 0);
78         if (native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL)) {
79             ALOGW("EGLNativeWindowType %p disconnect failed", window);
80         }
81         getDisplay()->onWindowSurfaceDestroyed();
82     }
83 }
84 
85 // ----------------------------------------------------------------------------
86 
egl_context_t(EGLDisplay dpy,EGLContext context,EGLConfig config,egl_connection_t const * cnx,int version)87 egl_context_t::egl_context_t(EGLDisplay dpy, EGLContext context, EGLConfig config,
88         egl_connection_t const* cnx, int version) :
89     egl_object_t(get_display_nowake(dpy)), dpy(dpy), context(context),
90             config(config), read(0), draw(0), cnx(cnx), version(version) {
91 }
92 
onLooseCurrent()93 void egl_context_t::onLooseCurrent() {
94     read = NULL;
95     draw = NULL;
96 }
97 
onMakeCurrent(EGLSurface draw,EGLSurface read)98 void egl_context_t::onMakeCurrent(EGLSurface draw, EGLSurface read) {
99     this->read = read;
100     this->draw = draw;
101 
102     /*
103      * Here we cache the GL_EXTENSIONS string for this context and we
104      * add the extensions always handled by the wrapper
105      */
106 
107     if (gl_extensions.isEmpty()) {
108         // call the implementation's glGetString(GL_EXTENSIONS)
109         const char* exts = (const char *)gEGLImpl.hooks[version]->gl.glGetString(GL_EXTENSIONS);
110         gl_extensions.setTo(exts);
111         if (gl_extensions.find("GL_EXT_debug_marker") < 0) {
112             String8 temp("GL_EXT_debug_marker ");
113             temp.append(gl_extensions);
114             gl_extensions.setTo(temp);
115         }
116     }
117 }
118 
119 // ----------------------------------------------------------------------------
120 }; // namespace android
121 // ----------------------------------------------------------------------------
122