blob: 90f27d1c7d966b202d0ed67e50cf5d9cf3d946e6 [file] [log] [blame]
Jesse Hall47743382013-02-08 11:13:46 -08001/*
Mathias Agopian518ec112011-05-13 16:21:08 -07002 ** Copyright 2007, The Android Open Source Project
3 **
Jesse Hall47743382013-02-08 11:13:46 -08004 ** 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
Mathias Agopian518ec112011-05-13 16:21:08 -07007 **
Jesse Hall47743382013-02-08 11:13:46 -08008 ** http://www.apache.org/licenses/LICENSE-2.0
Mathias Agopian518ec112011-05-13 16:21:08 -07009 **
Jesse Hall47743382013-02-08 11:13:46 -080010 ** 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
Mathias Agopian518ec112011-05-13 16:21:08 -070014 ** limitations under the License.
15 */
16
Michael Lentinee2fc6f82015-07-28 16:30:10 -070017#include <string>
18#include <sstream>
19
Mathias Agopian518ec112011-05-13 16:21:08 -070020#include <ctype.h>
21#include <stdint.h>
22#include <stdlib.h>
23
24#include <EGL/egl.h>
25#include <EGL/eglext.h>
Mathias Agopian518ec112011-05-13 16:21:08 -070026
27#include <utils/threads.h>
28
29#include "egl_object.h"
30
31// ----------------------------------------------------------------------------
32namespace android {
33// ----------------------------------------------------------------------------
34
35egl_object_t::egl_object_t(egl_display_t* disp) :
Mathias Agopian5b287a62011-05-16 18:58:55 -070036 display(disp), count(1) {
37 // NOTE: this does an implicit incRef
Mathias Agopian518ec112011-05-13 16:21:08 -070038 display->addObject(this);
39}
40
Mathias Agopian5b287a62011-05-16 18:58:55 -070041egl_object_t::~egl_object_t() {
Mathias Agopian518ec112011-05-13 16:21:08 -070042}
43
Mathias Agopian5b287a62011-05-16 18:58:55 -070044void egl_object_t::terminate() {
45 // this marks the object as "terminated"
46 display->removeObject(this);
47 if (decRef() == 1) {
48 // shouldn't happen because this is called from LocalRef
Steve Blocke6f43dd2012-01-06 19:20:56 +000049 ALOGE("egl_object_t::terminate() removed the last reference!");
Mathias Agopian5b287a62011-05-16 18:58:55 -070050 }
51}
52
53void egl_object_t::destroy() {
54 if (decRef() == 1) {
55 delete this;
56 }
57}
58
Mathias Agopianf0480de2011-11-13 20:50:07 -080059bool egl_object_t::get(egl_display_t const* display, egl_object_t* object) {
Mathias Agopian5b287a62011-05-16 18:58:55 -070060 // used by LocalRef, this does an incRef() atomically with
61 // checking that the object is valid.
Mathias Agopianf0480de2011-11-13 20:50:07 -080062 return display->getObject(object);
Mathias Agopian518ec112011-05-13 16:21:08 -070063}
64
65// ----------------------------------------------------------------------------
Mathias Agopian48d438d2012-01-28 21:44:00 -080066
Jesse Hall25838592012-04-05 15:53:28 -070067egl_surface_t::egl_surface_t(egl_display_t* dpy, EGLConfig config,
68 EGLNativeWindowType win, EGLSurface surface,
69 egl_connection_t const* cnx) :
Pablo Ceballosae8cf0b2016-05-02 11:24:13 -070070 egl_object_t(dpy), surface(surface), config(config), win(win), cnx(cnx),
71 connected(true)
Jesse Hall25838592012-04-05 15:53:28 -070072{
73 if (win) {
74 getDisplay()->onWindowSurfaceCreated();
75 }
76}
77
78egl_surface_t::~egl_surface_t() {
79 ANativeWindow* const window = win.get();
80 if (window != NULL) {
Pablo Ceballosae8cf0b2016-05-02 11:24:13 -070081 disconnect();
82 getDisplay()->onWindowSurfaceDestroyed();
83 }
84}
85
86void egl_surface_t::disconnect() {
87 ANativeWindow* const window = win.get();
88 if (window != NULL && connected) {
Jesse Hall25838592012-04-05 15:53:28 -070089 native_window_set_buffers_format(window, 0);
90 if (native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL)) {
91 ALOGW("EGLNativeWindowType %p disconnect failed", window);
92 }
Pablo Ceballosae8cf0b2016-05-02 11:24:13 -070093 connected = false;
Jesse Hall25838592012-04-05 15:53:28 -070094 }
95}
96
Pablo Ceballosae8cf0b2016-05-02 11:24:13 -070097void egl_surface_t::terminate() {
98 disconnect();
99 egl_object_t::terminate();
100}
101
Jesse Hall25838592012-04-05 15:53:28 -0700102// ----------------------------------------------------------------------------
103
Mathias Agopian48d438d2012-01-28 21:44:00 -0800104egl_context_t::egl_context_t(EGLDisplay dpy, EGLContext context, EGLConfig config,
Mathias Agopianada798b2012-02-13 17:09:30 -0800105 egl_connection_t const* cnx, int version) :
Jesse Hallb29e5e82012-04-04 16:53:42 -0700106 egl_object_t(get_display_nowake(dpy)), dpy(dpy), context(context),
107 config(config), read(0), draw(0), cnx(cnx), version(version) {
Mathias Agopian48d438d2012-01-28 21:44:00 -0800108}
109
110void egl_context_t::onLooseCurrent() {
111 read = NULL;
112 draw = NULL;
113}
114
115void egl_context_t::onMakeCurrent(EGLSurface draw, EGLSurface read) {
116 this->read = read;
117 this->draw = draw;
118
119 /*
120 * Here we cache the GL_EXTENSIONS string for this context and we
121 * add the extensions always handled by the wrapper
122 */
123
124 if (gl_extensions.isEmpty()) {
125 // call the implementation's glGetString(GL_EXTENSIONS)
Mathias Agopianada798b2012-02-13 17:09:30 -0800126 const char* exts = (const char *)gEGLImpl.hooks[version]->gl.glGetString(GL_EXTENSIONS);
Mathias Agopian48d438d2012-01-28 21:44:00 -0800127 gl_extensions.setTo(exts);
128 if (gl_extensions.find("GL_EXT_debug_marker") < 0) {
129 String8 temp("GL_EXT_debug_marker ");
130 temp.append(gl_extensions);
131 gl_extensions.setTo(temp);
132 }
Alistair Strachan89301ea2015-05-22 14:10:09 -0700133
134 // tokenize the supported extensions for the glGetStringi() wrapper
Michael Lentinee2fc6f82015-07-28 16:30:10 -0700135 std::stringstream ss;
136 std::string str;
137 ss << gl_extensions.string();
138 while (ss >> str) {
139 tokenized_gl_extensions.push(String8(str.c_str()));
Alistair Strachan89301ea2015-05-22 14:10:09 -0700140 }
Mathias Agopian48d438d2012-01-28 21:44:00 -0800141 }
142}
143
144// ----------------------------------------------------------------------------
Mathias Agopian518ec112011-05-13 16:21:08 -0700145}; // namespace android
146// ----------------------------------------------------------------------------