blob: 72b4823ea0ae4e9b337e9c22b401887d31fcb267 [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
Mathias Agopian311b4792017-02-28 15:00:49 -080017#include "egl_object.h"
18
Michael Lentinee2fc6f82015-07-28 16:30:10 -070019#include <sstream>
20
Mathias Agopian518ec112011-05-13 16:21:08 -070021
22// ----------------------------------------------------------------------------
23namespace android {
24// ----------------------------------------------------------------------------
25
26egl_object_t::egl_object_t(egl_display_t* disp) :
Mathias Agopian5b287a62011-05-16 18:58:55 -070027 display(disp), count(1) {
28 // NOTE: this does an implicit incRef
Mathias Agopian518ec112011-05-13 16:21:08 -070029 display->addObject(this);
30}
31
Mathias Agopian5b287a62011-05-16 18:58:55 -070032egl_object_t::~egl_object_t() {
Mathias Agopian518ec112011-05-13 16:21:08 -070033}
34
Mathias Agopian5b287a62011-05-16 18:58:55 -070035void egl_object_t::terminate() {
36 // this marks the object as "terminated"
37 display->removeObject(this);
38 if (decRef() == 1) {
39 // shouldn't happen because this is called from LocalRef
Steve Blocke6f43dd2012-01-06 19:20:56 +000040 ALOGE("egl_object_t::terminate() removed the last reference!");
Mathias Agopian5b287a62011-05-16 18:58:55 -070041 }
42}
43
44void egl_object_t::destroy() {
45 if (decRef() == 1) {
46 delete this;
47 }
48}
49
Mathias Agopianf0480de2011-11-13 20:50:07 -080050bool egl_object_t::get(egl_display_t const* display, egl_object_t* object) {
Mathias Agopian5b287a62011-05-16 18:58:55 -070051 // used by LocalRef, this does an incRef() atomically with
52 // checking that the object is valid.
Mathias Agopianf0480de2011-11-13 20:50:07 -080053 return display->getObject(object);
Mathias Agopian518ec112011-05-13 16:21:08 -070054}
55
56// ----------------------------------------------------------------------------
Mathias Agopian48d438d2012-01-28 21:44:00 -080057
Courtney Goeltzenleuchter37836572017-04-26 15:07:51 -060058egl_surface_t::egl_surface_t(egl_display_t* dpy, EGLConfig config, EGLNativeWindowType win,
59 EGLSurface surface, EGLint colorSpace, egl_connection_t const* cnx)
60 : egl_object_t(dpy),
61 surface(surface),
62 config(config),
63 win(win),
64 cnx(cnx),
65 connected(true),
66 colorSpace(colorSpace) {
Mathias Agopian65421432017-03-08 11:49:05 -080067 if (win) {
68 win->incStrong(this);
69 }
70}
Jesse Hall25838592012-04-05 15:53:28 -070071
72egl_surface_t::~egl_surface_t() {
Mathias Agopian65421432017-03-08 11:49:05 -080073 if (win != NULL) {
Pablo Ceballosae8cf0b2016-05-02 11:24:13 -070074 disconnect();
Mathias Agopian65421432017-03-08 11:49:05 -080075 win->decStrong(this);
Pablo Ceballosae8cf0b2016-05-02 11:24:13 -070076 }
77}
78
79void egl_surface_t::disconnect() {
Mathias Agopian65421432017-03-08 11:49:05 -080080 if (win != NULL && connected) {
81 native_window_set_buffers_format(win, 0);
82 if (native_window_api_disconnect(win, NATIVE_WINDOW_API_EGL)) {
83 ALOGW("EGLNativeWindowType %p disconnect failed", win);
Jesse Hall25838592012-04-05 15:53:28 -070084 }
Pablo Ceballosae8cf0b2016-05-02 11:24:13 -070085 connected = false;
Jesse Hall25838592012-04-05 15:53:28 -070086 }
87}
88
Pablo Ceballosae8cf0b2016-05-02 11:24:13 -070089void egl_surface_t::terminate() {
90 disconnect();
91 egl_object_t::terminate();
92}
93
Jesse Hall25838592012-04-05 15:53:28 -070094// ----------------------------------------------------------------------------
95
Mathias Agopian48d438d2012-01-28 21:44:00 -080096egl_context_t::egl_context_t(EGLDisplay dpy, EGLContext context, EGLConfig config,
Mathias Agopianada798b2012-02-13 17:09:30 -080097 egl_connection_t const* cnx, int version) :
Jesse Hallb29e5e82012-04-04 16:53:42 -070098 egl_object_t(get_display_nowake(dpy)), dpy(dpy), context(context),
99 config(config), read(0), draw(0), cnx(cnx), version(version) {
Mathias Agopian48d438d2012-01-28 21:44:00 -0800100}
101
102void egl_context_t::onLooseCurrent() {
103 read = NULL;
104 draw = NULL;
105}
106
107void egl_context_t::onMakeCurrent(EGLSurface draw, EGLSurface read) {
108 this->read = read;
109 this->draw = draw;
110
111 /*
112 * Here we cache the GL_EXTENSIONS string for this context and we
113 * add the extensions always handled by the wrapper
114 */
115
Mathias Agopian65421432017-03-08 11:49:05 -0800116 if (gl_extensions.empty()) {
Mathias Agopian48d438d2012-01-28 21:44:00 -0800117 // call the implementation's glGetString(GL_EXTENSIONS)
Mathias Agopianada798b2012-02-13 17:09:30 -0800118 const char* exts = (const char *)gEGLImpl.hooks[version]->gl.glGetString(GL_EXTENSIONS);
Alistair Strachan89301ea2015-05-22 14:10:09 -0700119
Jesse Hall09fc8f92017-09-29 15:57:42 -0700120 // If this context is sharing with another context, and the other context was reset
121 // e.g. due to robustness failure, this context might also be reset and glGetString can
122 // return NULL.
123 if (exts) {
124 gl_extensions = exts;
125 if (gl_extensions.find("GL_EXT_debug_marker") == std::string::npos) {
126 gl_extensions.insert(0, "GL_EXT_debug_marker ");
127 }
128
129 // tokenize the supported extensions for the glGetStringi() wrapper
130 std::stringstream ss;
131 std::string str;
132 ss << gl_extensions;
133 while (ss >> str) {
134 tokenized_gl_extensions.push_back(str);
135 }
Alistair Strachan89301ea2015-05-22 14:10:09 -0700136 }
Mathias Agopian48d438d2012-01-28 21:44:00 -0800137 }
138}
139
140// ----------------------------------------------------------------------------
Mathias Agopian518ec112011-05-13 16:21:08 -0700141}; // namespace android
142// ----------------------------------------------------------------------------