blob: 168129b1f761760d32b59e232c685cdd61443068 [file] [log] [blame]
Jamie Gennis8ba32fa2010-12-20 11:27:26 -08001/*
2 * Copyright (C) 2010 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
Andy McFadden2adaf042012-12-18 09:49:45 -080017#define LOG_TAG "GLConsumer"
Jamie Gennis1c8e95c2012-02-23 19:27:23 -080018#define ATRACE_TAG ATRACE_TAG_GRAPHICS
Jamie Gennise70d8b42011-01-09 13:24:09 -080019//#define LOG_NDEBUG 0
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080020
21#define GL_GLEXT_PROTOTYPES
22#define EGL_EGLEXT_PROTOTYPES
23
Mathias Agopiancb496ac2017-05-22 14:21:00 -070024#include <inttypes.h>
25
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080026#include <EGL/egl.h>
27#include <EGL/eglext.h>
28#include <GLES2/gl2.h>
29#include <GLES2/gl2ext.h>
Mathias Agopianad678e12013-07-23 17:28:53 -070030#include <cutils/compiler.h>
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080031
Jamie Gennis9fea3422012-08-07 18:03:04 -070032#include <hardware/hardware.h>
33
Chia-I Wu3bd03ff2017-11-17 12:04:57 -080034#include <math/mat4.h>
35
Dan Stozadd264162015-03-12 13:58:47 -070036#include <gui/BufferItem.h>
Ady Abrahama3b08ef2019-07-15 18:43:10 -070037#include <gui/DebugEGLImageTracker.h>
Mathias Agopianca088332013-03-28 17:44:13 -070038#include <gui/GLConsumer.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080039#include <gui/ISurfaceComposer.h>
40#include <gui/SurfaceComposerClient.h>
Mathias Agopian41f673c2011-11-17 17:48:35 -080041
Mathias Agopian90ac7992012-02-25 18:48:35 -080042#include <private/gui/ComposerService.h>
Mathias Agopianca088332013-03-28 17:44:13 -070043#include <private/gui/SyncFeatures.h>
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080044
45#include <utils/Log.h>
Mathias Agopian68c77942011-05-09 19:08:33 -070046#include <utils/String8.h>
Jamie Gennis1c8e95c2012-02-23 19:27:23 -080047#include <utils/Trace.h>
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080048
Craig Donneraec86972016-04-28 18:09:40 -070049#define PROT_CONTENT_EXT_STR "EGL_EXT_protected_content"
50#define EGL_PROTECTED_CONTENT_EXT 0x32C0
Jamie Gennisdbe92452013-09-23 17:22:10 -070051
Andy McFadden97eba892012-12-11 15:21:45 -080052namespace android {
53
Andy McFadden2adaf042012-12-18 09:49:45 -080054// Macros for including the GLConsumer name in log messages
Tomasz Wasilczykb19fe0c2023-08-11 00:06:51 +000055#define GLC_LOGV(x, ...) ALOGV("[%s] " x, mName.c_str(), ##__VA_ARGS__)
56#define GLC_LOGD(x, ...) ALOGD("[%s] " x, mName.c_str(), ##__VA_ARGS__)
57// #define GLC_LOGI(x, ...) ALOGI("[%s] " x, mName.c_str(), ##__VA_ARGS__)
58#define GLC_LOGW(x, ...) ALOGW("[%s] " x, mName.c_str(), ##__VA_ARGS__)
59#define GLC_LOGE(x, ...) ALOGE("[%s] " x, mName.c_str(), ##__VA_ARGS__)
Mathias Agopian29b57622011-08-17 15:42:04 -070060
Mathias Agopianad678e12013-07-23 17:28:53 -070061static const struct {
Dan Stozad723bd72014-11-18 10:24:03 -080062 uint32_t width, height;
Mathias Agopianad678e12013-07-23 17:28:53 -070063 char const* bits;
Mathias Agopian45263e22013-08-07 13:35:20 -070064} kDebugData = { 15, 12,
Dan Stozad723bd72014-11-18 10:24:03 -080065 "_______________"
66 "_______________"
67 "_____XX_XX_____"
68 "__X_X_____X_X__"
69 "__X_XXXXXXX_X__"
70 "__XXXXXXXXXXX__"
71 "___XX_XXX_XX___"
72 "____XXXXXXX____"
73 "_____X___X_____"
74 "____X_____X____"
75 "_______________"
76 "_______________"
Mathias Agopian45263e22013-08-07 13:35:20 -070077};
Mathias Agopianad678e12013-07-23 17:28:53 -070078
Chia-I Wu3bd03ff2017-11-17 12:04:57 -080079static const mat4 mtxIdentity;
Jamie Gennisf238e282011-01-09 16:33:17 -080080
Mathias Agopian9870c9b2013-08-08 17:46:48 -070081Mutex GLConsumer::sStaticInitLock;
82sp<GraphicBuffer> GLConsumer::sReleasedTexImageBuffer;
Jamie Gennisfa28c352011-09-16 17:30:26 -070083
Craig Donneraec86972016-04-28 18:09:40 -070084static bool hasEglProtectedContentImpl() {
85 EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
86 const char* exts = eglQueryString(dpy, EGL_EXTENSIONS);
87 size_t cropExtLen = strlen(PROT_CONTENT_EXT_STR);
88 size_t extsLen = strlen(exts);
89 bool equal = !strcmp(PROT_CONTENT_EXT_STR, exts);
90 bool atStart = !strncmp(PROT_CONTENT_EXT_STR " ", exts, cropExtLen+1);
91 bool atEnd = (cropExtLen+1) < extsLen &&
92 !strcmp(" " PROT_CONTENT_EXT_STR, exts + extsLen - (cropExtLen+1));
93 bool inMiddle = strstr(exts, " " PROT_CONTENT_EXT_STR " ");
Craig Donner4df76b22016-06-13 22:14:15 +000094 return equal || atStart || atEnd || inMiddle;
Craig Donneraec86972016-04-28 18:09:40 -070095}
96
97static bool hasEglProtectedContent() {
98 // Only compute whether the extension is present once the first time this
99 // function is called.
100 static bool hasIt = hasEglProtectedContentImpl();
101 return hasIt;
102}
103
Jim Shargod30823a2024-07-27 02:49:39 +0000104#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ)
105GLConsumer::GLConsumer(uint32_t tex, uint32_t texTarget, bool useFenceSync, bool isControlledByApp)
106 : ConsumerBase(isControlledByApp, /* isConsumerSurfaceFlinger */ false),
107 mCurrentCrop(Rect::EMPTY_RECT),
108 mCurrentTransform(0),
109 mCurrentScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE),
110 mCurrentFence(Fence::NO_FENCE),
111 mCurrentTimestamp(0),
112 mCurrentDataSpace(HAL_DATASPACE_UNKNOWN),
113 mCurrentFrameNumber(0),
114 mDefaultWidth(1),
115 mDefaultHeight(1),
116 mFilteringEnabled(true),
117 mTexName(tex),
118 mUseFenceSync(useFenceSync),
119 mTexTarget(texTarget),
120 mEglDisplay(EGL_NO_DISPLAY),
121 mEglContext(EGL_NO_CONTEXT),
Jim Shargo4f9c2752024-10-22 20:29:12 +0000122#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_UNLIMITED_SLOTS)
123 mEglSlots(BufferQueueDefs::NUM_BUFFER_SLOTS),
124#endif
Jim Shargod30823a2024-07-27 02:49:39 +0000125 mCurrentTexture(BufferQueue::INVALID_BUFFER_SLOT),
126 mAttached(true) {
127 GLC_LOGV("GLConsumer");
128
129 memcpy(mCurrentTransformMatrix, mtxIdentity.asArray(), sizeof(mCurrentTransformMatrix));
130
131 mConsumer->setConsumerUsageBits(DEFAULT_USAGE_FLAGS);
132}
133#endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ)
134
Jim Shargo4f9c2752024-10-22 20:29:12 +0000135GLConsumer::GLConsumer(const sp<IGraphicBufferConsumer>& bq, uint32_t tex, uint32_t texTarget,
136 bool useFenceSync, bool isControlledByApp)
137 : ConsumerBase(bq, isControlledByApp),
138 mCurrentCrop(Rect::EMPTY_RECT),
139 mCurrentTransform(0),
140 mCurrentScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE),
141 mCurrentFence(Fence::NO_FENCE),
142 mCurrentTimestamp(0),
143 mCurrentDataSpace(HAL_DATASPACE_UNKNOWN),
144 mCurrentFrameNumber(0),
145 mDefaultWidth(1),
146 mDefaultHeight(1),
147 mFilteringEnabled(true),
148 mTexName(tex),
149 mUseFenceSync(useFenceSync),
150 mTexTarget(texTarget),
151 mEglDisplay(EGL_NO_DISPLAY),
152 mEglContext(EGL_NO_CONTEXT),
153#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_UNLIMITED_SLOTS)
154 mEglSlots(BufferQueueDefs::NUM_BUFFER_SLOTS),
155#endif
156 mCurrentTexture(BufferQueue::INVALID_BUFFER_SLOT),
157 mAttached(true) {
Dan Stozad723bd72014-11-18 10:24:03 -0800158 GLC_LOGV("GLConsumer");
Daniel Lamb2675792012-02-23 14:35:13 -0800159
Chia-I Wu3bd03ff2017-11-17 12:04:57 -0800160 memcpy(mCurrentTransformMatrix, mtxIdentity.asArray(),
Jamie Gennisfa28c352011-09-16 17:30:26 -0700161 sizeof(mCurrentTransformMatrix));
Jamie Gennisfa5b40e2012-03-15 14:01:24 -0700162
Mathias Agopiandb89edc2013-08-02 01:40:18 -0700163 mConsumer->setConsumerUsageBits(DEFAULT_USAGE_FLAGS);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800164}
165
Jim Shargod30823a2024-07-27 02:49:39 +0000166#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ)
167GLConsumer::GLConsumer(uint32_t texTarget, bool useFenceSync, bool isControlledByApp)
168 : ConsumerBase(isControlledByApp, /* isConsumerSurfaceFlinger */ false),
169 mCurrentCrop(Rect::EMPTY_RECT),
170 mCurrentTransform(0),
171 mCurrentScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE),
172 mCurrentFence(Fence::NO_FENCE),
173 mCurrentTimestamp(0),
174 mCurrentDataSpace(HAL_DATASPACE_UNKNOWN),
175 mCurrentFrameNumber(0),
176 mDefaultWidth(1),
177 mDefaultHeight(1),
178 mFilteringEnabled(true),
179 mTexName(0),
180 mUseFenceSync(useFenceSync),
181 mTexTarget(texTarget),
182 mEglDisplay(EGL_NO_DISPLAY),
183 mEglContext(EGL_NO_CONTEXT),
Jim Shargo4f9c2752024-10-22 20:29:12 +0000184#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_UNLIMITED_SLOTS)
185 mEglSlots(BufferQueueDefs::NUM_BUFFER_SLOTS),
186#endif
Jim Shargod30823a2024-07-27 02:49:39 +0000187 mCurrentTexture(BufferQueue::INVALID_BUFFER_SLOT),
188 mAttached(false) {
189 GLC_LOGV("GLConsumer");
190
191 memcpy(mCurrentTransformMatrix, mtxIdentity.asArray(), sizeof(mCurrentTransformMatrix));
192
193 mConsumer->setConsumerUsageBits(DEFAULT_USAGE_FLAGS);
194}
195#endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ)
196
197GLConsumer::GLConsumer(const sp<IGraphicBufferConsumer>& bq, uint32_t texTarget, bool useFenceSync,
198 bool isControlledByApp)
199 : ConsumerBase(bq, isControlledByApp),
200 mCurrentCrop(Rect::EMPTY_RECT),
201 mCurrentTransform(0),
202 mCurrentScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE),
203 mCurrentFence(Fence::NO_FENCE),
204 mCurrentTimestamp(0),
205 mCurrentDataSpace(HAL_DATASPACE_UNKNOWN),
206 mCurrentFrameNumber(0),
207 mDefaultWidth(1),
208 mDefaultHeight(1),
209 mFilteringEnabled(true),
210 mTexName(0),
211 mUseFenceSync(useFenceSync),
212 mTexTarget(texTarget),
213 mEglDisplay(EGL_NO_DISPLAY),
214 mEglContext(EGL_NO_CONTEXT),
Jim Shargo4f9c2752024-10-22 20:29:12 +0000215#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_UNLIMITED_SLOTS)
216 mEglSlots(BufferQueueDefs::NUM_BUFFER_SLOTS),
217#endif
Jim Shargod30823a2024-07-27 02:49:39 +0000218 mCurrentTexture(BufferQueue::INVALID_BUFFER_SLOT),
219 mAttached(false) {
Dan Stozad723bd72014-11-18 10:24:03 -0800220 GLC_LOGV("GLConsumer");
Dan Stozaab574912014-06-25 14:21:45 -0700221
Chia-I Wu3bd03ff2017-11-17 12:04:57 -0800222 memcpy(mCurrentTransformMatrix, mtxIdentity.asArray(),
Dan Stozaab574912014-06-25 14:21:45 -0700223 sizeof(mCurrentTransformMatrix));
224
225 mConsumer->setConsumerUsageBits(DEFAULT_USAGE_FLAGS);
226}
227
Andy McFadden2adaf042012-12-18 09:49:45 -0800228status_t GLConsumer::setDefaultBufferSize(uint32_t w, uint32_t h)
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700229{
Daniel Lamb2675792012-02-23 14:35:13 -0800230 Mutex::Autolock lock(mMutex);
Pablo Ceballos65d9f6d2016-05-04 13:59:35 -0700231 if (mAbandoned) {
232 GLC_LOGE("setDefaultBufferSize: GLConsumer is abandoned!");
233 return NO_INIT;
234 }
Daniel Lam016c8cb2012-04-03 15:54:58 -0700235 mDefaultWidth = w;
236 mDefaultHeight = h;
Mathias Agopiandb89edc2013-08-02 01:40:18 -0700237 return mConsumer->setDefaultBufferSize(w, h);
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700238}
239
Andy McFadden2adaf042012-12-18 09:49:45 -0800240status_t GLConsumer::updateTexImage() {
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800241 ATRACE_CALL();
Dan Stozad723bd72014-11-18 10:24:03 -0800242 GLC_LOGV("updateTexImage");
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800243 Mutex::Autolock lock(mMutex);
244
245 if (mAbandoned) {
Dan Stozad723bd72014-11-18 10:24:03 -0800246 GLC_LOGE("updateTexImage: GLConsumer is abandoned!");
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800247 return NO_INIT;
248 }
249
250 // Make sure the EGL state is the same as in previous calls.
251 status_t err = checkAndUpdateEglStateLocked();
252 if (err != NO_ERROR) {
253 return err;
254 }
255
Dan Stozadd264162015-03-12 13:58:47 -0700256 BufferItem item;
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800257
258 // Acquire the next buffer.
259 // In asynchronous mode the list is guaranteed to be one buffer
260 // deep, while in synchronous mode we use the oldest buffer.
Andy McFadden1585c4d2013-06-28 13:52:40 -0700261 err = acquireBufferLocked(&item, 0);
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800262 if (err != NO_ERROR) {
263 if (err == BufferQueue::NO_BUFFER_AVAILABLE) {
264 // We always bind the texture even if we don't update its contents.
Dan Stozad723bd72014-11-18 10:24:03 -0800265 GLC_LOGV("updateTexImage: no buffers were available");
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800266 glBindTexture(mTexTarget, mTexName);
267 err = NO_ERROR;
268 } else {
Dan Stozad723bd72014-11-18 10:24:03 -0800269 GLC_LOGE("updateTexImage: acquire failed: %s (%d)",
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800270 strerror(-err), err);
271 }
272 return err;
273 }
274
275 // Release the previous buffer.
Mathias Agopianad678e12013-07-23 17:28:53 -0700276 err = updateAndReleaseLocked(item);
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800277 if (err != NO_ERROR) {
278 // We always bind the texture.
279 glBindTexture(mTexTarget, mTexName);
280 return err;
281 }
282
Andy McFadden97eba892012-12-11 15:21:45 -0800283 // Bind the new buffer to the GL texture, and wait until it's ready.
284 return bindTextureImageLocked();
Mathias Agopian2c8207e2012-05-23 17:56:42 -0700285}
286
Mathias Agopianad678e12013-07-23 17:28:53 -0700287
288status_t GLConsumer::releaseTexImage() {
289 ATRACE_CALL();
Dan Stozad723bd72014-11-18 10:24:03 -0800290 GLC_LOGV("releaseTexImage");
Mathias Agopianad678e12013-07-23 17:28:53 -0700291 Mutex::Autolock lock(mMutex);
292
293 if (mAbandoned) {
Dan Stozad723bd72014-11-18 10:24:03 -0800294 GLC_LOGE("releaseTexImage: GLConsumer is abandoned!");
Mathias Agopianad678e12013-07-23 17:28:53 -0700295 return NO_INIT;
296 }
297
298 // Make sure the EGL state is the same as in previous calls.
Mathias Agopian45155962013-08-08 18:16:21 -0700299 status_t err = NO_ERROR;
300
301 if (mAttached) {
302 err = checkAndUpdateEglStateLocked(true);
303 if (err != NO_ERROR) {
304 return err;
305 }
306 } else {
307 // if we're detached, no need to validate EGL's state -- we won't use it.
Mathias Agopianad678e12013-07-23 17:28:53 -0700308 }
309
310 // Update the GLConsumer state.
311 int buf = mCurrentTexture;
312 if (buf != BufferQueue::INVALID_BUFFER_SLOT) {
313
Dan Stozad723bd72014-11-18 10:24:03 -0800314 GLC_LOGV("releaseTexImage: (slot=%d, mAttached=%d)", buf, mAttached);
Mathias Agopianad678e12013-07-23 17:28:53 -0700315
Mathias Agopian45155962013-08-08 18:16:21 -0700316 if (mAttached) {
317 // Do whatever sync ops we need to do before releasing the slot.
318 err = syncForReleaseLocked(mEglDisplay);
319 if (err != NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800320 GLC_LOGE("syncForReleaseLocked failed (slot=%d), err=%d", buf, err);
Mathias Agopian45155962013-08-08 18:16:21 -0700321 return err;
322 }
323 } else {
324 // if we're detached, we just use the fence that was created in detachFromContext()
325 // so... basically, nothing more to do here.
Mathias Agopianad678e12013-07-23 17:28:53 -0700326 }
327
Jim Shargo52108082024-11-15 16:53:57 +0000328 err = releaseBufferLocked(buf, mSlots[buf].mGraphicBuffer);
Mathias Agopianad678e12013-07-23 17:28:53 -0700329 if (err < NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800330 GLC_LOGE("releaseTexImage: failed to release buffer: %s (%d)",
Mathias Agopianad678e12013-07-23 17:28:53 -0700331 strerror(-err), err);
332 return err;
333 }
334
Yi Kong48a619f2018-06-05 16:34:59 -0700335 if (mReleasedTexImage == nullptr) {
Eric Penner5c3d2432014-07-11 19:08:04 -0700336 mReleasedTexImage = new EglImage(getDebugTexImageBuffer());
337 }
338
Mathias Agopianad678e12013-07-23 17:28:53 -0700339 mCurrentTexture = BufferQueue::INVALID_BUFFER_SLOT;
Eric Penner5c3d2432014-07-11 19:08:04 -0700340 mCurrentTextureImage = mReleasedTexImage;
Mathias Agopianad678e12013-07-23 17:28:53 -0700341 mCurrentCrop.makeInvalid();
342 mCurrentTransform = 0;
Mathias Agopianad678e12013-07-23 17:28:53 -0700343 mCurrentTimestamp = 0;
Courtney Goeltzenleuchterbb09b432016-11-30 13:51:28 -0700344 mCurrentDataSpace = HAL_DATASPACE_UNKNOWN;
Mathias Agopianad678e12013-07-23 17:28:53 -0700345 mCurrentFence = Fence::NO_FENCE;
Brian Anderson3d4039d2016-09-23 16:31:30 -0700346 mCurrentFenceTime = FenceTime::NO_FENCE;
Mathias Agopianad678e12013-07-23 17:28:53 -0700347
Mathias Agopian45155962013-08-08 18:16:21 -0700348 if (mAttached) {
Xin Lie8b4e702020-08-29 01:34:09 -0700349 // This binds a buffer placeholder (mReleasedTexImage).
Dan Stozad723bd72014-11-18 10:24:03 -0800350 status_t result = bindTextureImageLocked();
351 if (result != NO_ERROR) {
352 return result;
Eric Penner5c3d2432014-07-11 19:08:04 -0700353 }
Mathias Agopian45155962013-08-08 18:16:21 -0700354 } else {
355 // detached, don't touch the texture (and we may not even have an
356 // EGLDisplay here.
357 }
Mathias Agopianad678e12013-07-23 17:28:53 -0700358 }
359
360 return NO_ERROR;
361}
362
Mathias Agopian9870c9b2013-08-08 17:46:48 -0700363sp<GraphicBuffer> GLConsumer::getDebugTexImageBuffer() {
364 Mutex::Autolock _l(sStaticInitLock);
Yi Kong48a619f2018-06-05 16:34:59 -0700365 if (CC_UNLIKELY(sReleasedTexImageBuffer == nullptr)) {
Mathias Agopian9870c9b2013-08-08 17:46:48 -0700366 // The first time, create the debug texture in case the application
367 // continues to use it.
368 sp<GraphicBuffer> buffer = new GraphicBuffer(
369 kDebugData.width, kDebugData.height, PIXEL_FORMAT_RGBA_8888,
SOOJONG HWANG0babcd32021-10-01 00:36:06 +0900370 DEFAULT_USAGE_FLAGS | GraphicBuffer::USAGE_SW_WRITE_RARELY,
Dan Stozad4079af2016-08-22 17:26:41 -0700371 "[GLConsumer debug texture]");
Mathias Agopian9870c9b2013-08-08 17:46:48 -0700372 uint32_t* bits;
373 buffer->lock(GraphicBuffer::USAGE_SW_WRITE_RARELY, reinterpret_cast<void**>(&bits));
Dan Stozad723bd72014-11-18 10:24:03 -0800374 uint32_t stride = buffer->getStride();
375 uint32_t height = buffer->getHeight();
376 memset(bits, 0, stride * height * 4);
377 for (uint32_t y = 0; y < kDebugData.height; y++) {
378 for (uint32_t x = 0; x < kDebugData.width; x++) {
379 bits[x] = (kDebugData.bits[y + kDebugData.width + x] == 'X') ?
380 0xFF000000 : 0xFFFFFFFF;
Mathias Agopian9870c9b2013-08-08 17:46:48 -0700381 }
Dan Stozad723bd72014-11-18 10:24:03 -0800382 bits += stride;
Mathias Agopian9870c9b2013-08-08 17:46:48 -0700383 }
384 buffer->unlock();
385 sReleasedTexImageBuffer = buffer;
386 }
387 return sReleasedTexImageBuffer;
388}
389
Dan Stozadd264162015-03-12 13:58:47 -0700390status_t GLConsumer::acquireBufferLocked(BufferItem *item,
Dan Stozaa4650a52015-05-12 12:56:16 -0700391 nsecs_t presentWhen, uint64_t maxFrameNumber) {
392 status_t err = ConsumerBase::acquireBufferLocked(item, presentWhen,
393 maxFrameNumber);
Jamie Gennis9fea3422012-08-07 18:03:04 -0700394 if (err != NO_ERROR) {
395 return err;
396 }
397
Eric Penner5c3d2432014-07-11 19:08:04 -0700398 // If item->mGraphicBuffer is not null, this buffer has not been acquired
399 // before, so any prior EglImage created is using a stale buffer. This
400 // replaces any old EglImage with a new one (using the new buffer).
Yi Kong48a619f2018-06-05 16:34:59 -0700401 if (item->mGraphicBuffer != nullptr) {
Pablo Ceballos47650f42015-08-04 16:38:17 -0700402 int slot = item->mSlot;
Eric Penner5c3d2432014-07-11 19:08:04 -0700403 mEglSlots[slot].mEglImage = new EglImage(item->mGraphicBuffer);
Jamie Gennisdbe92452013-09-23 17:22:10 -0700404 }
405
Jamie Gennis9fea3422012-08-07 18:03:04 -0700406 return NO_ERROR;
407}
408
Jim Shargo4f9c2752024-10-22 20:29:12 +0000409#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_UNLIMITED_SLOTS)
410void GLConsumer::onSlotCountChanged(int slotCount) {
411 ConsumerBase::onSlotCountChanged(slotCount);
412
413 Mutex::Autolock lock(mMutex);
414 if (slotCount > (int)mEglSlots.size()) {
415 mEglSlots.resize(slotCount);
416 }
417}
418#endif
419
Lajos Molnarc5d7b7d2013-05-03 14:50:50 -0700420status_t GLConsumer::releaseBufferLocked(int buf,
421 sp<GraphicBuffer> graphicBuffer,
422 EGLDisplay display, EGLSyncKHR eglFence) {
423 // release the buffer if it hasn't already been discarded by the
424 // BufferQueue. This can happen, for example, when the producer of this
425 // buffer has reallocated the original buffer slot after this buffer
426 // was acquired.
427 status_t err = ConsumerBase::releaseBufferLocked(
428 buf, graphicBuffer, display, eglFence);
Jamie Gennisd1b330d2012-09-21 11:55:35 -0700429 mEglSlots[buf].mEglFence = EGL_NO_SYNC_KHR;
Jamie Gennis9fea3422012-08-07 18:03:04 -0700430 return err;
431}
432
Dan Stoza3ce46042015-11-17 17:00:45 -0800433status_t GLConsumer::updateAndReleaseLocked(const BufferItem& item,
434 PendingRelease* pendingRelease)
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800435{
Daniel Lam9abe1eb2012-03-26 20:37:15 -0700436 status_t err = NO_ERROR;
437
Pablo Ceballos47650f42015-08-04 16:38:17 -0700438 int slot = item.mSlot;
Andy McFadden87a67842014-04-04 15:37:08 -0700439
Jamie Gennis74bed552012-03-28 19:05:54 -0700440 if (!mAttached) {
Dan Stozad723bd72014-11-18 10:24:03 -0800441 GLC_LOGE("updateAndRelease: GLConsumer is not attached to an OpenGL "
Jamie Gennis74bed552012-03-28 19:05:54 -0700442 "ES context");
Jim Shargo52108082024-11-15 16:53:57 +0000443 releaseBufferLocked(slot, mSlots[slot].mGraphicBuffer);
Jamie Gennis74bed552012-03-28 19:05:54 -0700444 return INVALID_OPERATION;
445 }
446
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800447 // Confirm state.
448 err = checkAndUpdateEglStateLocked();
449 if (err != NO_ERROR) {
Jim Shargo52108082024-11-15 16:53:57 +0000450 releaseBufferLocked(slot, mSlots[slot].mGraphicBuffer);
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800451 return err;
452 }
453
Eric Penner5c3d2432014-07-11 19:08:04 -0700454 // Ensure we have a valid EglImageKHR for the slot, creating an EglImage
455 // if nessessary, for the gralloc buffer currently in the slot in
456 // ConsumerBase.
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800457 // We may have to do this even when item.mGraphicBuffer == NULL (which
Eric Penner5c3d2432014-07-11 19:08:04 -0700458 // means the buffer was previously acquired).
Krzysztof Kosiński7108c312018-06-27 19:12:54 -0700459 err = mEglSlots[slot].mEglImage->createIfNeeded(mEglDisplay);
Eric Penner5c3d2432014-07-11 19:08:04 -0700460 if (err != NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800461 GLC_LOGW("updateAndRelease: unable to createImage on display=%p slot=%d",
Pablo Ceballos47650f42015-08-04 16:38:17 -0700462 mEglDisplay, slot);
Jim Shargo52108082024-11-15 16:53:57 +0000463 releaseBufferLocked(slot, mSlots[slot].mGraphicBuffer);
Eric Penner5c3d2432014-07-11 19:08:04 -0700464 return UNKNOWN_ERROR;
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800465 }
466
467 // Do whatever sync ops we need to do before releasing the old slot.
Pablo Ceballosff95aab2016-01-13 17:09:58 -0800468 if (slot != mCurrentTexture) {
Pablo Ceballos33fcc2e2015-11-20 15:44:51 -0800469 err = syncForReleaseLocked(mEglDisplay);
470 if (err != NO_ERROR) {
471 // Release the buffer we just acquired. It's not safe to
472 // release the old buffer, so instead we just drop the new frame.
473 // As we are still under lock since acquireBuffer, it is safe to
474 // release by slot.
Jim Shargo52108082024-11-15 16:53:57 +0000475 releaseBufferLocked(slot, mSlots[slot].mGraphicBuffer);
Pablo Ceballos33fcc2e2015-11-20 15:44:51 -0800476 return err;
477 }
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800478 }
479
Dan Stozad723bd72014-11-18 10:24:03 -0800480 GLC_LOGV("updateAndRelease: (slot=%d buf=%p) -> (slot=%d buf=%p)",
Yi Konga03e0442018-07-17 11:16:57 -0700481 mCurrentTexture, mCurrentTextureImage != nullptr ?
Yi Kong48a619f2018-06-05 16:34:59 -0700482 mCurrentTextureImage->graphicBufferHandle() : nullptr,
Pablo Ceballos47650f42015-08-04 16:38:17 -0700483 slot, mSlots[slot].mGraphicBuffer->handle);
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800484
Pablo Ceballosccdfd602015-10-07 15:05:45 -0700485 // Hang onto the pointer so that it isn't freed in the call to
Pablo Ceballos3559fbf2016-03-17 15:50:23 -0700486 // releaseBufferLocked() if we're in shared buffer mode and both buffers are
Pablo Ceballosccdfd602015-10-07 15:05:45 -0700487 // the same.
488 sp<EglImage> nextTextureImage = mEglSlots[slot].mEglImage;
489
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800490 // release old buffer
491 if (mCurrentTexture != BufferQueue::INVALID_BUFFER_SLOT) {
Dan Stoza3ce46042015-11-17 17:00:45 -0800492 if (pendingRelease == nullptr) {
493 status_t status = releaseBufferLocked(
494 mCurrentTexture, mCurrentTextureImage->graphicBuffer(),
495 mEglDisplay, mEglSlots[mCurrentTexture].mEglFence);
496 if (status < NO_ERROR) {
497 GLC_LOGE("updateAndRelease: failed to release buffer: %s (%d)",
498 strerror(-status), status);
499 err = status;
500 // keep going, with error raised [?]
501 }
502 } else {
503 pendingRelease->currentTexture = mCurrentTexture;
504 pendingRelease->graphicBuffer =
505 mCurrentTextureImage->graphicBuffer();
506 pendingRelease->display = mEglDisplay;
507 pendingRelease->fence = mEglSlots[mCurrentTexture].mEglFence;
508 pendingRelease->isPending = true;
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800509 }
510 }
511
Andy McFadden2adaf042012-12-18 09:49:45 -0800512 // Update the GLConsumer state.
Pablo Ceballos47650f42015-08-04 16:38:17 -0700513 mCurrentTexture = slot;
Pablo Ceballosccdfd602015-10-07 15:05:45 -0700514 mCurrentTextureImage = nextTextureImage;
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800515 mCurrentCrop = item.mCrop;
516 mCurrentTransform = item.mTransform;
517 mCurrentScalingMode = item.mScalingMode;
518 mCurrentTimestamp = item.mTimestamp;
Courtney Goeltzenleuchterbb09b432016-11-30 13:51:28 -0700519 mCurrentDataSpace = item.mDataSpace;
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800520 mCurrentFence = item.mFence;
Brian Anderson3d4039d2016-09-23 16:31:30 -0700521 mCurrentFenceTime = item.mFenceTime;
Eino-Ville Talvalad171da92013-09-19 13:36:07 -0700522 mCurrentFrameNumber = item.mFrameNumber;
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800523
524 computeCurrentTransformMatrixLocked();
525
526 return err;
527}
528
Andy McFadden2adaf042012-12-18 09:49:45 -0800529status_t GLConsumer::bindTextureImageLocked() {
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800530 if (mEglDisplay == EGL_NO_DISPLAY) {
531 ALOGE("bindTextureImage: invalid display");
532 return INVALID_OPERATION;
533 }
534
Dan Stozad723bd72014-11-18 10:24:03 -0800535 GLenum error;
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800536 while ((error = glGetError()) != GL_NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800537 GLC_LOGW("bindTextureImage: clearing GL error: %#04x", error);
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800538 }
539
540 glBindTexture(mTexTarget, mTexName);
Eric Penner5c3d2432014-07-11 19:08:04 -0700541 if (mCurrentTexture == BufferQueue::INVALID_BUFFER_SLOT &&
Yi Kong48a619f2018-06-05 16:34:59 -0700542 mCurrentTextureImage == nullptr) {
Dan Stozad723bd72014-11-18 10:24:03 -0800543 GLC_LOGE("bindTextureImage: no currently-bound texture");
Eric Penner5c3d2432014-07-11 19:08:04 -0700544 return NO_INIT;
545 }
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800546
Krzysztof Kosiński7108c312018-06-27 19:12:54 -0700547 status_t err = mCurrentTextureImage->createIfNeeded(mEglDisplay);
Eric Penner5c3d2432014-07-11 19:08:04 -0700548 if (err != NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800549 GLC_LOGW("bindTextureImage: can't create image on display=%p slot=%d",
Eric Penner5c3d2432014-07-11 19:08:04 -0700550 mEglDisplay, mCurrentTexture);
551 return UNKNOWN_ERROR;
552 }
Eric Penner5c3d2432014-07-11 19:08:04 -0700553 mCurrentTextureImage->bindToTextureTarget(mTexTarget);
554
Eric Penner2d14a0e2014-08-25 20:16:37 -0700555 // In the rare case that the display is terminated and then initialized
556 // again, we can't detect that the display changed (it didn't), but the
557 // image is invalid. In this case, repeat the exact same steps while
558 // forcing the creation of a new image.
559 if ((error = glGetError()) != GL_NO_ERROR) {
560 glBindTexture(mTexTarget, mTexName);
Krzysztof Kosiński7108c312018-06-27 19:12:54 -0700561 status_t result = mCurrentTextureImage->createIfNeeded(mEglDisplay, true);
Dan Stozad723bd72014-11-18 10:24:03 -0800562 if (result != NO_ERROR) {
563 GLC_LOGW("bindTextureImage: can't create image on display=%p slot=%d",
Eric Penner2d14a0e2014-08-25 20:16:37 -0700564 mEglDisplay, mCurrentTexture);
565 return UNKNOWN_ERROR;
566 }
567 mCurrentTextureImage->bindToTextureTarget(mTexTarget);
568 if ((error = glGetError()) != GL_NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800569 GLC_LOGE("bindTextureImage: error binding external image: %#04x", error);
Eric Penner2d14a0e2014-08-25 20:16:37 -0700570 return UNKNOWN_ERROR;
571 }
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800572 }
Andy McFadden97eba892012-12-11 15:21:45 -0800573
574 // Wait for the new buffer to be ready.
575 return doGLFenceWaitLocked();
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800576}
577
Mathias Agopian45155962013-08-08 18:16:21 -0700578status_t GLConsumer::checkAndUpdateEglStateLocked(bool contextCheck) {
Jamie Gennisce561372012-03-19 18:33:05 -0700579 EGLDisplay dpy = eglGetCurrentDisplay();
580 EGLContext ctx = eglGetCurrentContext();
581
Mathias Agopian45155962013-08-08 18:16:21 -0700582 if (!contextCheck) {
583 // if this is the first time we're called, mEglDisplay/mEglContext have
584 // never been set, so don't error out (below).
585 if (mEglDisplay == EGL_NO_DISPLAY) {
586 mEglDisplay = dpy;
587 }
Jesse Hall46a1f6b2014-08-06 12:15:15 -0700588 if (mEglContext == EGL_NO_CONTEXT) {
Mathias Agopian45155962013-08-08 18:16:21 -0700589 mEglContext = ctx;
590 }
591 }
592
593 if (mEglDisplay != dpy || dpy == EGL_NO_DISPLAY) {
Dan Stozad723bd72014-11-18 10:24:03 -0800594 GLC_LOGE("checkAndUpdateEglState: invalid current EGLDisplay");
Jamie Gennis74bed552012-03-28 19:05:54 -0700595 return INVALID_OPERATION;
Jamie Gennisce561372012-03-19 18:33:05 -0700596 }
597
Mathias Agopian45155962013-08-08 18:16:21 -0700598 if (mEglContext != ctx || ctx == EGL_NO_CONTEXT) {
Dan Stozad723bd72014-11-18 10:24:03 -0800599 GLC_LOGE("checkAndUpdateEglState: invalid current EGLContext");
Jamie Gennis74bed552012-03-28 19:05:54 -0700600 return INVALID_OPERATION;
Jamie Gennisce561372012-03-19 18:33:05 -0700601 }
602
603 mEglDisplay = dpy;
604 mEglContext = ctx;
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800605 return NO_ERROR;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800606}
607
Jesse Hall13f01cb2013-03-20 11:37:21 -0700608void GLConsumer::setReleaseFence(const sp<Fence>& fence) {
609 if (fence->isValid() &&
610 mCurrentTexture != BufferQueue::INVALID_BUFFER_SLOT) {
Lajos Molnarc5d7b7d2013-05-03 14:50:50 -0700611 status_t err = addReleaseFence(mCurrentTexture,
Eric Penner5c3d2432014-07-11 19:08:04 -0700612 mCurrentTextureImage->graphicBuffer(), fence);
Jesse Hall13f01cb2013-03-20 11:37:21 -0700613 if (err != OK) {
Dan Stozad723bd72014-11-18 10:24:03 -0800614 GLC_LOGE("setReleaseFence: failed to add the fence: %s (%d)",
Jesse Hall13f01cb2013-03-20 11:37:21 -0700615 strerror(-err), err);
616 }
Jesse Hallef194142012-06-14 14:45:17 -0700617 }
618}
619
Andy McFadden2adaf042012-12-18 09:49:45 -0800620status_t GLConsumer::detachFromContext() {
Jamie Gennis74bed552012-03-28 19:05:54 -0700621 ATRACE_CALL();
Dan Stozad723bd72014-11-18 10:24:03 -0800622 GLC_LOGV("detachFromContext");
Jamie Gennis74bed552012-03-28 19:05:54 -0700623 Mutex::Autolock lock(mMutex);
624
625 if (mAbandoned) {
Dan Stozad723bd72014-11-18 10:24:03 -0800626 GLC_LOGE("detachFromContext: abandoned GLConsumer");
Jamie Gennis74bed552012-03-28 19:05:54 -0700627 return NO_INIT;
628 }
629
630 if (!mAttached) {
Dan Stozad723bd72014-11-18 10:24:03 -0800631 GLC_LOGE("detachFromContext: GLConsumer is not attached to a "
Jamie Gennis74bed552012-03-28 19:05:54 -0700632 "context");
633 return INVALID_OPERATION;
634 }
635
636 EGLDisplay dpy = eglGetCurrentDisplay();
637 EGLContext ctx = eglGetCurrentContext();
638
639 if (mEglDisplay != dpy && mEglDisplay != EGL_NO_DISPLAY) {
Dan Stozad723bd72014-11-18 10:24:03 -0800640 GLC_LOGE("detachFromContext: invalid current EGLDisplay");
Jamie Gennis74bed552012-03-28 19:05:54 -0700641 return INVALID_OPERATION;
642 }
643
644 if (mEglContext != ctx && mEglContext != EGL_NO_CONTEXT) {
Dan Stozad723bd72014-11-18 10:24:03 -0800645 GLC_LOGE("detachFromContext: invalid current EGLContext");
Jamie Gennis74bed552012-03-28 19:05:54 -0700646 return INVALID_OPERATION;
647 }
648
649 if (dpy != EGL_NO_DISPLAY && ctx != EGL_NO_CONTEXT) {
650 status_t err = syncForReleaseLocked(dpy);
651 if (err != OK) {
652 return err;
653 }
654
655 glDeleteTextures(1, &mTexName);
656 }
657
658 mEglDisplay = EGL_NO_DISPLAY;
659 mEglContext = EGL_NO_CONTEXT;
660 mAttached = false;
661
662 return OK;
663}
664
Mathias Agopian3f844832013-08-07 21:24:32 -0700665status_t GLConsumer::attachToContext(uint32_t tex) {
Jamie Gennis74bed552012-03-28 19:05:54 -0700666 ATRACE_CALL();
Dan Stozad723bd72014-11-18 10:24:03 -0800667 GLC_LOGV("attachToContext");
Jamie Gennis74bed552012-03-28 19:05:54 -0700668 Mutex::Autolock lock(mMutex);
669
670 if (mAbandoned) {
Dan Stozad723bd72014-11-18 10:24:03 -0800671 GLC_LOGE("attachToContext: abandoned GLConsumer");
Jamie Gennis74bed552012-03-28 19:05:54 -0700672 return NO_INIT;
673 }
674
675 if (mAttached) {
Dan Stozad723bd72014-11-18 10:24:03 -0800676 GLC_LOGE("attachToContext: GLConsumer is already attached to a "
Jamie Gennis74bed552012-03-28 19:05:54 -0700677 "context");
678 return INVALID_OPERATION;
679 }
680
681 EGLDisplay dpy = eglGetCurrentDisplay();
682 EGLContext ctx = eglGetCurrentContext();
683
684 if (dpy == EGL_NO_DISPLAY) {
Dan Stozad723bd72014-11-18 10:24:03 -0800685 GLC_LOGE("attachToContext: invalid current EGLDisplay");
Jamie Gennis74bed552012-03-28 19:05:54 -0700686 return INVALID_OPERATION;
687 }
688
689 if (ctx == EGL_NO_CONTEXT) {
Dan Stozad723bd72014-11-18 10:24:03 -0800690 GLC_LOGE("attachToContext: invalid current EGLContext");
Jamie Gennis74bed552012-03-28 19:05:54 -0700691 return INVALID_OPERATION;
692 }
693
694 // We need to bind the texture regardless of whether there's a current
695 // buffer.
Mathias Agopian3f844832013-08-07 21:24:32 -0700696 glBindTexture(mTexTarget, GLuint(tex));
Jamie Gennis74bed552012-03-28 19:05:54 -0700697
Jamie Gennis74bed552012-03-28 19:05:54 -0700698 mEglDisplay = dpy;
699 mEglContext = ctx;
700 mTexName = tex;
701 mAttached = true;
702
Yi Kong48a619f2018-06-05 16:34:59 -0700703 if (mCurrentTextureImage != nullptr) {
Eric Penner5c3d2432014-07-11 19:08:04 -0700704 // This may wait for a buffer a second time. This is likely required if
705 // this is a different context, since otherwise the wait could be skipped
706 // by bouncing through another context. For the same context the extra
707 // wait is redundant.
708 status_t err = bindTextureImageLocked();
709 if (err != NO_ERROR) {
710 return err;
711 }
712 }
713
Jamie Gennis74bed552012-03-28 19:05:54 -0700714 return OK;
715}
716
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800717
Andy McFadden2adaf042012-12-18 09:49:45 -0800718status_t GLConsumer::syncForReleaseLocked(EGLDisplay dpy) {
Dan Stozad723bd72014-11-18 10:24:03 -0800719 GLC_LOGV("syncForReleaseLocked");
Jamie Gennis74bed552012-03-28 19:05:54 -0700720
Jamie Gennis01dbf552012-09-06 14:54:19 -0700721 if (mCurrentTexture != BufferQueue::INVALID_BUFFER_SLOT) {
Mathias Agopianca088332013-03-28 17:44:13 -0700722 if (SyncFeatures::getInstance().useNativeFenceSync()) {
Jamie Gennis01dbf552012-09-06 14:54:19 -0700723 EGLSyncKHR sync = eglCreateSyncKHR(dpy,
Yi Kong48a619f2018-06-05 16:34:59 -0700724 EGL_SYNC_NATIVE_FENCE_ANDROID, nullptr);
Jamie Gennis01dbf552012-09-06 14:54:19 -0700725 if (sync == EGL_NO_SYNC_KHR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800726 GLC_LOGE("syncForReleaseLocked: error creating EGL fence: %#x",
Jamie Gennis01dbf552012-09-06 14:54:19 -0700727 eglGetError());
Jamie Gennis74bed552012-03-28 19:05:54 -0700728 return UNKNOWN_ERROR;
Jamie Gennis74bed552012-03-28 19:05:54 -0700729 }
Jamie Gennis01dbf552012-09-06 14:54:19 -0700730 glFlush();
731 int fenceFd = eglDupNativeFenceFDANDROID(dpy, sync);
Jamie Gennis98ff0592012-09-10 14:49:42 -0700732 eglDestroySyncKHR(dpy, sync);
Jamie Gennis01dbf552012-09-06 14:54:19 -0700733 if (fenceFd == EGL_NO_NATIVE_FENCE_FD_ANDROID) {
Dan Stozad723bd72014-11-18 10:24:03 -0800734 GLC_LOGE("syncForReleaseLocked: error dup'ing native fence "
Jamie Gennis01dbf552012-09-06 14:54:19 -0700735 "fd: %#x", eglGetError());
736 return UNKNOWN_ERROR;
737 }
738 sp<Fence> fence(new Fence(fenceFd));
Lajos Molnarc5d7b7d2013-05-03 14:50:50 -0700739 status_t err = addReleaseFenceLocked(mCurrentTexture,
Eric Penner5c3d2432014-07-11 19:08:04 -0700740 mCurrentTextureImage->graphicBuffer(), fence);
Jamie Gennis01dbf552012-09-06 14:54:19 -0700741 if (err != OK) {
Dan Stozad723bd72014-11-18 10:24:03 -0800742 GLC_LOGE("syncForReleaseLocked: error adding release fence: "
Jamie Gennis01dbf552012-09-06 14:54:19 -0700743 "%s (%d)", strerror(-err), err);
744 return err;
745 }
Mathias Agopianca088332013-03-28 17:44:13 -0700746 } else if (mUseFenceSync && SyncFeatures::getInstance().useFenceSync()) {
Jamie Gennis01dbf552012-09-06 14:54:19 -0700747 EGLSyncKHR fence = mEglSlots[mCurrentTexture].mEglFence;
748 if (fence != EGL_NO_SYNC_KHR) {
749 // There is already a fence for the current slot. We need to
750 // wait on that before replacing it with another fence to
751 // ensure that all outstanding buffer accesses have completed
752 // before the producer accesses it.
753 EGLint result = eglClientWaitSyncKHR(dpy, fence, 0, 1000000000);
754 if (result == EGL_FALSE) {
Dan Stozad723bd72014-11-18 10:24:03 -0800755 GLC_LOGE("syncForReleaseLocked: error waiting for previous "
Jamie Gennis01dbf552012-09-06 14:54:19 -0700756 "fence: %#x", eglGetError());
757 return UNKNOWN_ERROR;
758 } else if (result == EGL_TIMEOUT_EXPIRED_KHR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800759 GLC_LOGE("syncForReleaseLocked: timeout waiting for previous "
Jamie Gennis01dbf552012-09-06 14:54:19 -0700760 "fence");
761 return TIMED_OUT;
762 }
763 eglDestroySyncKHR(dpy, fence);
764 }
Jamie Gennis74bed552012-03-28 19:05:54 -0700765
Jamie Gennis01dbf552012-09-06 14:54:19 -0700766 // Create a fence for the outstanding accesses in the current
767 // OpenGL ES context.
Yi Kong48a619f2018-06-05 16:34:59 -0700768 fence = eglCreateSyncKHR(dpy, EGL_SYNC_FENCE_KHR, nullptr);
Jamie Gennis01dbf552012-09-06 14:54:19 -0700769 if (fence == EGL_NO_SYNC_KHR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800770 GLC_LOGE("syncForReleaseLocked: error creating fence: %#x",
Jamie Gennis01dbf552012-09-06 14:54:19 -0700771 eglGetError());
772 return UNKNOWN_ERROR;
773 }
774 glFlush();
775 mEglSlots[mCurrentTexture].mEglFence = fence;
Jamie Gennis74bed552012-03-28 19:05:54 -0700776 }
Jamie Gennis74bed552012-03-28 19:05:54 -0700777 }
778
779 return OK;
780}
781
Mathias Agopian3f844832013-08-07 21:24:32 -0700782uint32_t GLConsumer::getCurrentTextureTarget() const {
Jamie Gennisfb1b5a22011-09-28 12:13:31 -0700783 return mTexTarget;
Mathias Agopian7a042bf2011-04-11 21:19:55 -0700784}
785
Andy McFadden2adaf042012-12-18 09:49:45 -0800786void GLConsumer::getTransformMatrix(float mtx[16]) {
Jamie Gennisf238e282011-01-09 16:33:17 -0800787 Mutex::Autolock lock(mMutex);
Jamie Gennis736aa952011-06-12 17:03:06 -0700788 memcpy(mtx, mCurrentTransformMatrix, sizeof(mCurrentTransformMatrix));
789}
790
Andy McFadden2adaf042012-12-18 09:49:45 -0800791void GLConsumer::setFilteringEnabled(bool enabled) {
Jamie Gennis5c1139f2012-05-08 16:56:34 -0700792 Mutex::Autolock lock(mMutex);
Mathias Agopiane96e9e12012-09-24 19:26:11 -0700793 if (mAbandoned) {
Dan Stozad723bd72014-11-18 10:24:03 -0800794 GLC_LOGE("setFilteringEnabled: GLConsumer is abandoned!");
Mathias Agopiane96e9e12012-09-24 19:26:11 -0700795 return;
796 }
Jamie Gennis5c1139f2012-05-08 16:56:34 -0700797 bool needsRecompute = mFilteringEnabled != enabled;
798 mFilteringEnabled = enabled;
Mathias Agopiane96e9e12012-09-24 19:26:11 -0700799
Yi Kong48a619f2018-06-05 16:34:59 -0700800 if (needsRecompute && mCurrentTextureImage==nullptr) {
Dan Stozad723bd72014-11-18 10:24:03 -0800801 GLC_LOGD("setFilteringEnabled called with mCurrentTextureImage == NULL");
Mathias Agopiane96e9e12012-09-24 19:26:11 -0700802 }
803
Yi Kong48a619f2018-06-05 16:34:59 -0700804 if (needsRecompute && mCurrentTextureImage != nullptr) {
Mathias Agopiane96e9e12012-09-24 19:26:11 -0700805 computeCurrentTransformMatrixLocked();
Jamie Gennis5c1139f2012-05-08 16:56:34 -0700806 }
807}
808
Andy McFadden2adaf042012-12-18 09:49:45 -0800809void GLConsumer::computeCurrentTransformMatrixLocked() {
Dan Stozad723bd72014-11-18 10:24:03 -0800810 GLC_LOGV("computeCurrentTransformMatrixLocked");
John Reck1a61da52016-04-28 13:18:15 -0700811 sp<GraphicBuffer> buf = (mCurrentTextureImage == nullptr) ?
812 nullptr : mCurrentTextureImage->graphicBuffer();
813 if (buf == nullptr) {
814 GLC_LOGD("computeCurrentTransformMatrixLocked: "
815 "mCurrentTextureImage is NULL");
816 }
Krzysztof Kosiński7108c312018-06-27 19:12:54 -0700817 computeTransformMatrix(mCurrentTransformMatrix, buf, mCurrentCrop,
John Reck1a61da52016-04-28 13:18:15 -0700818 mCurrentTransform, mFilteringEnabled);
819}
820
Chia-I Wu93b122f2017-12-01 08:51:39 -0800821Rect GLConsumer::scaleDownCrop(const Rect& crop, uint32_t bufferWidth, uint32_t bufferHeight) {
822 Rect outCrop = crop;
823
824 uint32_t newWidth = static_cast<uint32_t>(crop.width());
825 uint32_t newHeight = static_cast<uint32_t>(crop.height());
826
827 if (newWidth * bufferHeight > newHeight * bufferWidth) {
828 newWidth = newHeight * bufferWidth / bufferHeight;
829 ALOGV("too wide: newWidth = %d", newWidth);
830 } else if (newWidth * bufferHeight < newHeight * bufferWidth) {
831 newHeight = newWidth * bufferHeight / bufferWidth;
832 ALOGV("too tall: newHeight = %d", newHeight);
833 }
834
835 uint32_t currentWidth = static_cast<uint32_t>(crop.width());
836 uint32_t currentHeight = static_cast<uint32_t>(crop.height());
837
838 // The crop is too wide
839 if (newWidth < currentWidth) {
840 uint32_t dw = currentWidth - newWidth;
841 auto halfdw = dw / 2;
842 outCrop.left += halfdw;
843 // Not halfdw because it would subtract 1 too few when dw is odd
844 outCrop.right -= (dw - halfdw);
845 // The crop is too tall
846 } else if (newHeight < currentHeight) {
847 uint32_t dh = currentHeight - newHeight;
848 auto halfdh = dh / 2;
849 outCrop.top += halfdh;
850 // Not halfdh because it would subtract 1 too few when dh is odd
851 outCrop.bottom -= (dh - halfdh);
852 }
853
854 ALOGV("getCurrentCrop final crop [%d,%d,%d,%d]",
855 outCrop.left, outCrop.top,
856 outCrop.right,outCrop.bottom);
857
858 return outCrop;
859}
860
Andy McFadden2adaf042012-12-18 09:49:45 -0800861nsecs_t GLConsumer::getTimestamp() {
Dan Stozad723bd72014-11-18 10:24:03 -0800862 GLC_LOGV("getTimestamp");
Eino-Ville Talvala1d01a122011-02-18 11:02:42 -0800863 Mutex::Autolock lock(mMutex);
864 return mCurrentTimestamp;
865}
866
Courtney Goeltzenleuchterbb09b432016-11-30 13:51:28 -0700867android_dataspace GLConsumer::getCurrentDataSpace() {
868 GLC_LOGV("getCurrentDataSpace");
869 Mutex::Autolock lock(mMutex);
870 return mCurrentDataSpace;
871}
872
Dan Stozad723bd72014-11-18 10:24:03 -0800873uint64_t GLConsumer::getFrameNumber() {
874 GLC_LOGV("getFrameNumber");
Eino-Ville Talvalad171da92013-09-19 13:36:07 -0700875 Mutex::Autolock lock(mMutex);
876 return mCurrentFrameNumber;
877}
878
Chia-I Wu06d63de2017-01-04 14:58:51 +0800879sp<GraphicBuffer> GLConsumer::getCurrentBuffer(int* outSlot) const {
Mathias Agopian7a042bf2011-04-11 21:19:55 -0700880 Mutex::Autolock lock(mMutex);
Chia-I Wu06d63de2017-01-04 14:58:51 +0800881
882 if (outSlot != nullptr) {
883 *outSlot = mCurrentTexture;
884 }
885
886 return (mCurrentTextureImage == nullptr) ?
Yi Kong48a619f2018-06-05 16:34:59 -0700887 nullptr : mCurrentTextureImage->graphicBuffer();
Mathias Agopian7a042bf2011-04-11 21:19:55 -0700888}
889
Andy McFadden2adaf042012-12-18 09:49:45 -0800890Rect GLConsumer::getCurrentCrop() const {
Mathias Agopian7a042bf2011-04-11 21:19:55 -0700891 Mutex::Autolock lock(mMutex);
Chia-I Wu93b122f2017-12-01 08:51:39 -0800892 return (mCurrentScalingMode == NATIVE_WINDOW_SCALING_MODE_SCALE_CROP)
893 ? scaleDownCrop(mCurrentCrop, mDefaultWidth, mDefaultHeight)
894 : mCurrentCrop;
Mathias Agopian7a042bf2011-04-11 21:19:55 -0700895}
896
Andy McFadden2adaf042012-12-18 09:49:45 -0800897uint32_t GLConsumer::getCurrentTransform() const {
Mathias Agopian7a042bf2011-04-11 21:19:55 -0700898 Mutex::Autolock lock(mMutex);
899 return mCurrentTransform;
900}
901
Andy McFadden2adaf042012-12-18 09:49:45 -0800902uint32_t GLConsumer::getCurrentScalingMode() const {
Mathias Agopian7734ebf2011-07-13 15:24:42 -0700903 Mutex::Autolock lock(mMutex);
904 return mCurrentScalingMode;
905}
906
Andy McFadden2adaf042012-12-18 09:49:45 -0800907sp<Fence> GLConsumer::getCurrentFence() const {
Jesse Halldc5b4852012-06-29 15:21:18 -0700908 Mutex::Autolock lock(mMutex);
909 return mCurrentFence;
910}
911
Brian Anderson3d4039d2016-09-23 16:31:30 -0700912std::shared_ptr<FenceTime> GLConsumer::getCurrentFenceTime() const {
913 Mutex::Autolock lock(mMutex);
914 return mCurrentFenceTime;
915}
916
Andy McFadden2adaf042012-12-18 09:49:45 -0800917status_t GLConsumer::doGLFenceWaitLocked() const {
Jamie Gennis61e04b92012-09-09 17:48:42 -0700918
919 EGLDisplay dpy = eglGetCurrentDisplay();
920 EGLContext ctx = eglGetCurrentContext();
921
922 if (mEglDisplay != dpy || mEglDisplay == EGL_NO_DISPLAY) {
Dan Stozad723bd72014-11-18 10:24:03 -0800923 GLC_LOGE("doGLFenceWait: invalid current EGLDisplay");
Jamie Gennis61e04b92012-09-09 17:48:42 -0700924 return INVALID_OPERATION;
925 }
926
927 if (mEglContext != ctx || mEglContext == EGL_NO_CONTEXT) {
Dan Stozad723bd72014-11-18 10:24:03 -0800928 GLC_LOGE("doGLFenceWait: invalid current EGLContext");
Jamie Gennis61e04b92012-09-09 17:48:42 -0700929 return INVALID_OPERATION;
930 }
931
Jamie Gennis1df8c342012-12-20 14:05:45 -0800932 if (mCurrentFence->isValid()) {
Jeffrey Kardatzkea45e1c82018-03-13 12:07:28 -0700933 if (SyncFeatures::getInstance().useWaitSync() &&
934 SyncFeatures::getInstance().useNativeFenceSync()) {
Jamie Gennis61e04b92012-09-09 17:48:42 -0700935 // Create an EGLSyncKHR from the current fence.
936 int fenceFd = mCurrentFence->dup();
937 if (fenceFd == -1) {
Dan Stozad723bd72014-11-18 10:24:03 -0800938 GLC_LOGE("doGLFenceWait: error dup'ing fence fd: %d", errno);
Jamie Gennis61e04b92012-09-09 17:48:42 -0700939 return -errno;
940 }
941 EGLint attribs[] = {
942 EGL_SYNC_NATIVE_FENCE_FD_ANDROID, fenceFd,
943 EGL_NONE
944 };
945 EGLSyncKHR sync = eglCreateSyncKHR(dpy,
946 EGL_SYNC_NATIVE_FENCE_ANDROID, attribs);
947 if (sync == EGL_NO_SYNC_KHR) {
948 close(fenceFd);
Dan Stozad723bd72014-11-18 10:24:03 -0800949 GLC_LOGE("doGLFenceWait: error creating EGL fence: %#x",
Jamie Gennis61e04b92012-09-09 17:48:42 -0700950 eglGetError());
951 return UNKNOWN_ERROR;
952 }
953
954 // XXX: The spec draft is inconsistent as to whether this should
955 // return an EGLint or void. Ignore the return value for now, as
956 // it's not strictly needed.
Mathias Agopian2bb71682013-03-27 17:32:41 -0700957 eglWaitSyncKHR(dpy, sync, 0);
Jamie Gennis61e04b92012-09-09 17:48:42 -0700958 EGLint eglErr = eglGetError();
959 eglDestroySyncKHR(dpy, sync);
960 if (eglErr != EGL_SUCCESS) {
Dan Stozad723bd72014-11-18 10:24:03 -0800961 GLC_LOGE("doGLFenceWait: error waiting for EGL fence: %#x",
Jamie Gennis61e04b92012-09-09 17:48:42 -0700962 eglErr);
963 return UNKNOWN_ERROR;
964 }
965 } else {
Mathias Agopianea74d3b2013-05-16 18:03:22 -0700966 status_t err = mCurrentFence->waitForever(
Andy McFadden2adaf042012-12-18 09:49:45 -0800967 "GLConsumer::doGLFenceWaitLocked");
Jamie Gennis61e04b92012-09-09 17:48:42 -0700968 if (err != NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800969 GLC_LOGE("doGLFenceWait: error waiting for fence: %d", err);
Jamie Gennis61e04b92012-09-09 17:48:42 -0700970 return err;
971 }
972 }
973 }
974
975 return NO_ERROR;
976}
977
Andy McFadden2adaf042012-12-18 09:49:45 -0800978void GLConsumer::freeBufferLocked(int slotIndex) {
Dan Stozad723bd72014-11-18 10:24:03 -0800979 GLC_LOGV("freeBufferLocked: slotIndex=%d", slotIndex);
Daniel Lam9abe1eb2012-03-26 20:37:15 -0700980 if (slotIndex == mCurrentTexture) {
981 mCurrentTexture = BufferQueue::INVALID_BUFFER_SLOT;
982 }
Eric Penner5c3d2432014-07-11 19:08:04 -0700983 mEglSlots[slotIndex].mEglImage.clear();
Jamie Gennis9fea3422012-08-07 18:03:04 -0700984 ConsumerBase::freeBufferLocked(slotIndex);
Jamie Gennisfa5b40e2012-03-15 14:01:24 -0700985}
Daniel Lameae59d22012-01-22 15:26:27 -0800986
Andy McFadden2adaf042012-12-18 09:49:45 -0800987void GLConsumer::abandonLocked() {
Dan Stozad723bd72014-11-18 10:24:03 -0800988 GLC_LOGV("abandonLocked");
Eric Penner5c3d2432014-07-11 19:08:04 -0700989 mCurrentTextureImage.clear();
Jamie Gennis9fea3422012-08-07 18:03:04 -0700990 ConsumerBase::abandonLocked();
Jamie Gennis7b305ff2011-07-19 12:08:33 -0700991}
992
Chia-I Wue2786ea2017-08-07 10:36:08 -0700993status_t GLConsumer::setConsumerUsageBits(uint64_t usage) {
Chia-I Wua81bc492017-11-27 10:16:00 -0800994 return ConsumerBase::setConsumerUsageBits(usage | DEFAULT_USAGE_FLAGS);
Pablo Ceballos19e3e062015-08-19 16:16:06 -0700995}
996
Mathias Agopian74d211a2013-04-22 16:55:35 +0200997void GLConsumer::dumpLocked(String8& result, const char* prefix) const
Mathias Agopian68c77942011-05-09 19:08:33 -0700998{
Mathias Agopian74d211a2013-04-22 16:55:35 +0200999 result.appendFormat(
Jamie Gennis9fea3422012-08-07 18:03:04 -07001000 "%smTexName=%d mCurrentTexture=%d\n"
1001 "%smCurrentCrop=[%d,%d,%d,%d] mCurrentTransform=%#x\n",
1002 prefix, mTexName, mCurrentTexture, prefix, mCurrentCrop.left,
1003 mCurrentCrop.top, mCurrentCrop.right, mCurrentCrop.bottom,
1004 mCurrentTransform);
Mathias Agopian68c77942011-05-09 19:08:33 -07001005
Mathias Agopian74d211a2013-04-22 16:55:35 +02001006 ConsumerBase::dumpLocked(result, prefix);
Mathias Agopian68c77942011-05-09 19:08:33 -07001007}
1008
Eric Penner5c3d2432014-07-11 19:08:04 -07001009GLConsumer::EglImage::EglImage(sp<GraphicBuffer> graphicBuffer) :
1010 mGraphicBuffer(graphicBuffer),
1011 mEglImage(EGL_NO_IMAGE_KHR),
Krzysztof Kosiński7108c312018-06-27 19:12:54 -07001012 mEglDisplay(EGL_NO_DISPLAY) {
Eric Penner5c3d2432014-07-11 19:08:04 -07001013}
1014
1015GLConsumer::EglImage::~EglImage() {
1016 if (mEglImage != EGL_NO_IMAGE_KHR) {
1017 if (!eglDestroyImageKHR(mEglDisplay, mEglImage)) {
1018 ALOGE("~EglImage: eglDestroyImageKHR failed");
1019 }
Ady Abrahama3b08ef2019-07-15 18:43:10 -07001020 DEBUG_EGL_IMAGE_TRACKER_DESTROY();
Michael Lentine78be65e2014-10-02 12:10:07 -07001021 eglTerminate(mEglDisplay);
Eric Penner5c3d2432014-07-11 19:08:04 -07001022 }
1023}
1024
1025status_t GLConsumer::EglImage::createIfNeeded(EGLDisplay eglDisplay,
Eric Penner2d14a0e2014-08-25 20:16:37 -07001026 bool forceCreation) {
Eric Penner5c3d2432014-07-11 19:08:04 -07001027 // If there's an image and it's no longer valid, destroy it.
1028 bool haveImage = mEglImage != EGL_NO_IMAGE_KHR;
1029 bool displayInvalid = mEglDisplay != eglDisplay;
Krzysztof Kosiński7108c312018-06-27 19:12:54 -07001030 if (haveImage && (displayInvalid || forceCreation)) {
Eric Penner5c3d2432014-07-11 19:08:04 -07001031 if (!eglDestroyImageKHR(mEglDisplay, mEglImage)) {
1032 ALOGE("createIfNeeded: eglDestroyImageKHR failed");
1033 }
Ady Abrahama3b08ef2019-07-15 18:43:10 -07001034 DEBUG_EGL_IMAGE_TRACKER_DESTROY();
Michael Lentine78be65e2014-10-02 12:10:07 -07001035 eglTerminate(mEglDisplay);
Eric Penner5c3d2432014-07-11 19:08:04 -07001036 mEglImage = EGL_NO_IMAGE_KHR;
1037 mEglDisplay = EGL_NO_DISPLAY;
1038 }
1039
1040 // If there's no image, create one.
1041 if (mEglImage == EGL_NO_IMAGE_KHR) {
1042 mEglDisplay = eglDisplay;
Krzysztof Kosiński7108c312018-06-27 19:12:54 -07001043 mEglImage = createImage(mEglDisplay, mGraphicBuffer);
Eric Penner5c3d2432014-07-11 19:08:04 -07001044 }
1045
1046 // Fail if we can't create a valid image.
1047 if (mEglImage == EGL_NO_IMAGE_KHR) {
1048 mEglDisplay = EGL_NO_DISPLAY;
Eric Penner5c3d2432014-07-11 19:08:04 -07001049 const sp<GraphicBuffer>& buffer = mGraphicBuffer;
Mathias Agopiancb496ac2017-05-22 14:21:00 -07001050 ALOGE("Failed to create image. size=%ux%u st=%u usage=%#" PRIx64 " fmt=%d",
Eric Penner5c3d2432014-07-11 19:08:04 -07001051 buffer->getWidth(), buffer->getHeight(), buffer->getStride(),
1052 buffer->getUsage(), buffer->getPixelFormat());
1053 return UNKNOWN_ERROR;
1054 }
1055
1056 return OK;
1057}
1058
1059void GLConsumer::EglImage::bindToTextureTarget(uint32_t texTarget) {
Dan Stozad723bd72014-11-18 10:24:03 -08001060 glEGLImageTargetTexture2DOES(texTarget,
1061 static_cast<GLeglImageOES>(mEglImage));
Eric Penner5c3d2432014-07-11 19:08:04 -07001062}
1063
1064EGLImageKHR GLConsumer::EglImage::createImage(EGLDisplay dpy,
Krzysztof Kosiński7108c312018-06-27 19:12:54 -07001065 const sp<GraphicBuffer>& graphicBuffer) {
Dan Stozad723bd72014-11-18 10:24:03 -08001066 EGLClientBuffer cbuf =
1067 static_cast<EGLClientBuffer>(graphicBuffer->getNativeBuffer());
Craig Donneraec86972016-04-28 18:09:40 -07001068 const bool createProtectedImage =
1069 (graphicBuffer->getUsage() & GRALLOC_USAGE_PROTECTED) &&
1070 hasEglProtectedContent();
Eric Penner5c3d2432014-07-11 19:08:04 -07001071 EGLint attrs[] = {
Krzysztof Kosiński7108c312018-06-27 19:12:54 -07001072 EGL_IMAGE_PRESERVED_KHR, EGL_TRUE,
Craig Donneraec86972016-04-28 18:09:40 -07001073 createProtectedImage ? EGL_PROTECTED_CONTENT_EXT : EGL_NONE,
1074 createProtectedImage ? EGL_TRUE : EGL_NONE,
Eric Penner5c3d2432014-07-11 19:08:04 -07001075 EGL_NONE,
1076 };
Yi Kong48a619f2018-06-05 16:34:59 -07001077 eglInitialize(dpy, nullptr, nullptr);
Eric Penner5c3d2432014-07-11 19:08:04 -07001078 EGLImageKHR image = eglCreateImageKHR(dpy, EGL_NO_CONTEXT,
1079 EGL_NATIVE_BUFFER_ANDROID, cbuf, attrs);
1080 if (image == EGL_NO_IMAGE_KHR) {
1081 EGLint error = eglGetError();
1082 ALOGE("error creating EGLImage: %#x", error);
Michael Lentine78be65e2014-10-02 12:10:07 -07001083 eglTerminate(dpy);
Ady Abrahama3b08ef2019-07-15 18:43:10 -07001084 } else {
1085 DEBUG_EGL_IMAGE_TRACKER_CREATE();
Eric Penner5c3d2432014-07-11 19:08:04 -07001086 }
Ady Abrahama3b08ef2019-07-15 18:43:10 -07001087
Eric Penner5c3d2432014-07-11 19:08:04 -07001088 return image;
1089}
1090
Jamie Gennis8ba32fa2010-12-20 11:27:26 -08001091}; // namespace android