2 ** Copyright 2007, The Android Open Source Project
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
8 ** http://www.apache.org/licenses/LICENSE-2.0
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.
25 #include <EGL/eglext.h>
27 #include <utils/threads.h>
29 #include "egl_object.h"
31 // ----------------------------------------------------------------------------
33 // ----------------------------------------------------------------------------
35 egl_object_t::egl_object_t(egl_display_t* disp) :
36 display(disp), count(1) {
37 // NOTE: this does an implicit incRef
38 display->addObject(this);
41 egl_object_t::~egl_object_t() {
44 void egl_object_t::terminate() {
45 // this marks the object as "terminated"
46 display->removeObject(this);
48 // shouldn't happen because this is called from LocalRef
49 ALOGE("egl_object_t::terminate() removed the last reference!");
53 void egl_object_t::destroy() {
59 bool egl_object_t::get(egl_display_t const* display, egl_object_t* object) {
60 // used by LocalRef, this does an incRef() atomically with
61 // checking that the object is valid.
62 return display->getObject(object);
65 // ----------------------------------------------------------------------------
67 egl_surface_t::egl_surface_t(egl_display_t* dpy, EGLConfig config,
68 EGLNativeWindowType win, EGLSurface surface,
69 egl_connection_t const* cnx) :
70 egl_object_t(dpy), surface(surface), config(config), win(win), cnx(cnx)
73 getDisplay()->onWindowSurfaceCreated();
77 egl_surface_t::~egl_surface_t() {
78 ANativeWindow* const window = win.get();
80 native_window_set_buffers_format(window, 0);
81 if (native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL)) {
82 ALOGW("EGLNativeWindowType %p disconnect failed", window);
84 getDisplay()->onWindowSurfaceDestroyed();
88 // ----------------------------------------------------------------------------
90 egl_context_t::egl_context_t(EGLDisplay dpy, EGLContext context, EGLConfig config,
91 egl_connection_t const* cnx, int version) :
92 egl_object_t(get_display_nowake(dpy)), dpy(dpy), context(context),
93 config(config), read(0), draw(0), cnx(cnx), version(version) {
96 void egl_context_t::onLooseCurrent() {
101 void egl_context_t::onMakeCurrent(EGLSurface draw, EGLSurface read) {
106 * Here we cache the GL_EXTENSIONS string for this context and we
107 * add the extensions always handled by the wrapper
110 if (gl_extensions.isEmpty()) {
111 // call the implementation's glGetString(GL_EXTENSIONS)
112 const char* exts = (const char *)gEGLImpl.hooks[version]->gl.glGetString(GL_EXTENSIONS);
113 gl_extensions.setTo(exts);
114 if (gl_extensions.find("GL_EXT_debug_marker") < 0) {
115 String8 temp("GL_EXT_debug_marker ");
116 temp.append(gl_extensions);
117 gl_extensions.setTo(temp);
120 // tokenize the supported extensions for the glGetStringi() wrapper
121 std::stringstream ss;
123 ss << gl_extensions.string();
125 tokenized_gl_extensions.push(String8(str.c_str()));
130 // ----------------------------------------------------------------------------
131 }; // namespace android
132 // ----------------------------------------------------------------------------