egl_object.cpp revision ada798b7ca7cabc255aa159964b64975e7fdb2df
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#include <GLES/gl.h>
24#include <GLES/glext.h>
25
26#include <utils/threads.h>
27
28#include "egl_object.h"
29
30// ----------------------------------------------------------------------------
31namespace android {
32// ----------------------------------------------------------------------------
33
34egl_object_t::egl_object_t(egl_display_t* disp) :
35    display(disp), count(1) {
36    // NOTE: this does an implicit incRef
37    display->addObject(this);
38}
39
40egl_object_t::~egl_object_t() {
41}
42
43void egl_object_t::terminate() {
44    // this marks the object as "terminated"
45    display->removeObject(this);
46    if (decRef() == 1) {
47        // shouldn't happen because this is called from LocalRef
48        ALOGE("egl_object_t::terminate() removed the last reference!");
49    }
50}
51
52void egl_object_t::destroy() {
53    if (decRef() == 1) {
54        delete this;
55    }
56}
57
58bool egl_object_t::get(egl_display_t const* display, egl_object_t* object) {
59    // used by LocalRef, this does an incRef() atomically with
60    // checking that the object is valid.
61    return display->getObject(object);
62}
63
64// ----------------------------------------------------------------------------
65
66egl_context_t::egl_context_t(EGLDisplay dpy, EGLContext context, EGLConfig config,
67        egl_connection_t const* cnx, int version) :
68    egl_object_t(get_display(dpy)), dpy(dpy), context(context),
69            config(config), read(0), draw(0), cnx(cnx),
70            version(version)
71{
72}
73
74void egl_context_t::onLooseCurrent() {
75    read = NULL;
76    draw = NULL;
77}
78
79void egl_context_t::onMakeCurrent(EGLSurface draw, EGLSurface read) {
80    this->read = read;
81    this->draw = draw;
82
83    /*
84     * Here we cache the GL_EXTENSIONS string for this context and we
85     * add the extensions always handled by the wrapper
86     */
87
88    if (gl_extensions.isEmpty()) {
89        // call the implementation's glGetString(GL_EXTENSIONS)
90        const char* exts = (const char *)gEGLImpl.hooks[version]->gl.glGetString(GL_EXTENSIONS);
91        gl_extensions.setTo(exts);
92        if (gl_extensions.find("GL_EXT_debug_marker") < 0) {
93            String8 temp("GL_EXT_debug_marker ");
94            temp.append(gl_extensions);
95            gl_extensions.setTo(temp);
96        }
97    }
98}
99
100// ----------------------------------------------------------------------------
101}; // namespace android
102// ----------------------------------------------------------------------------
103