Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 1 | /* |
| 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 McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 17 | #define LOG_TAG "GLConsumer" |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 18 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
Jamie Gennis | e70d8b4 | 2011-01-09 13:24:09 -0800 | [diff] [blame] | 19 | //#define LOG_NDEBUG 0 |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 20 | |
| 21 | #define GL_GLEXT_PROTOTYPES |
| 22 | #define EGL_EGLEXT_PROTOTYPES |
| 23 | |
| 24 | #include <EGL/egl.h> |
| 25 | #include <EGL/eglext.h> |
| 26 | #include <GLES2/gl2.h> |
| 27 | #include <GLES2/gl2ext.h> |
| 28 | |
Jamie Gennis | 9fea342 | 2012-08-07 18:03:04 -0700 | [diff] [blame] | 29 | #include <hardware/hardware.h> |
| 30 | |
Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 31 | #include <gui/IGraphicBufferAlloc.h> |
| 32 | #include <gui/ISurfaceComposer.h> |
| 33 | #include <gui/SurfaceComposerClient.h> |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 34 | #include <gui/GLConsumer.h> |
Mathias Agopian | 41f673c | 2011-11-17 17:48:35 -0800 | [diff] [blame] | 35 | |
Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 36 | #include <private/gui/ComposerService.h> |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 37 | |
| 38 | #include <utils/Log.h> |
Mathias Agopian | 68c7794 | 2011-05-09 19:08:33 -0700 | [diff] [blame] | 39 | #include <utils/String8.h> |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 40 | #include <utils/Trace.h> |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 41 | |
Andy McFadden | 97eba89 | 2012-12-11 15:21:45 -0800 | [diff] [blame] | 42 | namespace android { |
| 43 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 44 | // This compile option makes GLConsumer use the |
Jamie Gennis | 01dbf55 | 2012-09-06 14:54:19 -0700 | [diff] [blame] | 45 | // EGL_ANDROID_native_fence_sync extension to create Android native fences to |
| 46 | // signal when all GLES reads for a given buffer have completed. It is not |
| 47 | // compatible with using the EGL_KHR_fence_sync extension for the same |
| 48 | // purpose. |
| 49 | #ifdef USE_NATIVE_FENCE_SYNC |
| 50 | #ifdef USE_FENCE_SYNC |
| 51 | #error "USE_NATIVE_FENCE_SYNC and USE_FENCE_SYNC are incompatible" |
| 52 | #endif |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 53 | const bool GLConsumer::sUseNativeFenceSync = true; |
Jamie Gennis | 01dbf55 | 2012-09-06 14:54:19 -0700 | [diff] [blame] | 54 | #else |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 55 | const bool GLConsumer::sUseNativeFenceSync = false; |
Jamie Gennis | 61e04b9 | 2012-09-09 17:48:42 -0700 | [diff] [blame] | 56 | #endif |
| 57 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 58 | // This compile option makes GLConsumer use the EGL_ANDROID_sync_wait |
Jamie Gennis | 61e04b9 | 2012-09-09 17:48:42 -0700 | [diff] [blame] | 59 | // extension to insert server-side waits into the GLES command stream. This |
| 60 | // feature requires the EGL_ANDROID_native_fence_sync and |
| 61 | // EGL_ANDROID_wait_sync extensions. |
| 62 | #ifdef USE_WAIT_SYNC |
| 63 | static const bool useWaitSync = true; |
| 64 | #else |
| 65 | static const bool useWaitSync = false; |
Jamie Gennis | 01dbf55 | 2012-09-06 14:54:19 -0700 | [diff] [blame] | 66 | #endif |
| 67 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 68 | // Macros for including the GLConsumer name in log messages |
Steve Block | 6807e59 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 69 | #define ST_LOGV(x, ...) ALOGV("[%s] "x, mName.string(), ##__VA_ARGS__) |
Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 70 | #define ST_LOGD(x, ...) ALOGD("[%s] "x, mName.string(), ##__VA_ARGS__) |
Steve Block | a19954a | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 71 | #define ST_LOGI(x, ...) ALOGI("[%s] "x, mName.string(), ##__VA_ARGS__) |
Steve Block | 32397c1 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 72 | #define ST_LOGW(x, ...) ALOGW("[%s] "x, mName.string(), ##__VA_ARGS__) |
Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 73 | #define ST_LOGE(x, ...) ALOGE("[%s] "x, mName.string(), ##__VA_ARGS__) |
Mathias Agopian | 29b5762 | 2011-08-17 15:42:04 -0700 | [diff] [blame] | 74 | |
Jamie Gennis | f238e28 | 2011-01-09 16:33:17 -0800 | [diff] [blame] | 75 | // Transform matrices |
| 76 | static float mtxIdentity[16] = { |
| 77 | 1, 0, 0, 0, |
| 78 | 0, 1, 0, 0, |
| 79 | 0, 0, 1, 0, |
| 80 | 0, 0, 0, 1, |
| 81 | }; |
| 82 | static float mtxFlipH[16] = { |
| 83 | -1, 0, 0, 0, |
| 84 | 0, 1, 0, 0, |
| 85 | 0, 0, 1, 0, |
| 86 | 1, 0, 0, 1, |
| 87 | }; |
| 88 | static float mtxFlipV[16] = { |
| 89 | 1, 0, 0, 0, |
| 90 | 0, -1, 0, 0, |
| 91 | 0, 0, 1, 0, |
| 92 | 0, 1, 0, 1, |
| 93 | }; |
| 94 | static float mtxRot90[16] = { |
| 95 | 0, 1, 0, 0, |
| 96 | -1, 0, 0, 0, |
| 97 | 0, 0, 1, 0, |
| 98 | 1, 0, 0, 1, |
| 99 | }; |
| 100 | static float mtxRot180[16] = { |
| 101 | -1, 0, 0, 0, |
| 102 | 0, -1, 0, 0, |
| 103 | 0, 0, 1, 0, |
| 104 | 1, 1, 0, 1, |
| 105 | }; |
| 106 | static float mtxRot270[16] = { |
| 107 | 0, -1, 0, 0, |
| 108 | 1, 0, 0, 0, |
| 109 | 0, 0, 1, 0, |
| 110 | 0, 1, 0, 1, |
| 111 | }; |
| 112 | |
| 113 | static void mtxMul(float out[16], const float a[16], const float b[16]); |
| 114 | |
Jamie Gennis | fa28c35 | 2011-09-16 17:30:26 -0700 | [diff] [blame] | 115 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 116 | GLConsumer::GLConsumer(GLuint tex, bool allowSynchronousMode, |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame] | 117 | GLenum texTarget, bool useFenceSync, const sp<BufferQueue> &bufferQueue) : |
Jamie Gennis | 9fea342 | 2012-08-07 18:03:04 -0700 | [diff] [blame] | 118 | ConsumerBase(bufferQueue == 0 ? new BufferQueue(allowSynchronousMode) : bufferQueue), |
Eino-Ville Talvala | 1d01a12 | 2011-02-18 11:02:42 -0800 | [diff] [blame] | 119 | mCurrentTransform(0), |
Jamie Gennis | 1df8c34 | 2012-12-20 14:05:45 -0800 | [diff] [blame] | 120 | mCurrentFence(Fence::NO_FENCE), |
Eino-Ville Talvala | 1d01a12 | 2011-02-18 11:02:42 -0800 | [diff] [blame] | 121 | mCurrentTimestamp(0), |
Jamie Gennis | 5c1139f | 2012-05-08 16:56:34 -0700 | [diff] [blame] | 122 | mFilteringEnabled(true), |
Mathias Agopian | b3e518c | 2011-04-21 18:52:51 -0700 | [diff] [blame] | 123 | mTexName(tex), |
Jamie Gennis | 86edf4f | 2011-11-14 14:51:01 -0800 | [diff] [blame] | 124 | #ifdef USE_FENCE_SYNC |
| 125 | mUseFenceSync(useFenceSync), |
| 126 | #else |
| 127 | mUseFenceSync(false), |
| 128 | #endif |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 129 | mTexTarget(texTarget), |
Jamie Gennis | ce56137 | 2012-03-19 18:33:05 -0700 | [diff] [blame] | 130 | mEglDisplay(EGL_NO_DISPLAY), |
| 131 | mEglContext(EGL_NO_CONTEXT), |
Jamie Gennis | 74bed55 | 2012-03-28 19:05:54 -0700 | [diff] [blame] | 132 | mCurrentTexture(BufferQueue::INVALID_BUFFER_SLOT), |
| 133 | mAttached(true) |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 134 | { |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 135 | ST_LOGV("GLConsumer"); |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame] | 136 | |
Jamie Gennis | fa28c35 | 2011-09-16 17:30:26 -0700 | [diff] [blame] | 137 | memcpy(mCurrentTransformMatrix, mtxIdentity, |
| 138 | sizeof(mCurrentTransformMatrix)); |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 139 | |
Jamie Gennis | 9fea342 | 2012-08-07 18:03:04 -0700 | [diff] [blame] | 140 | mBufferQueue->setConsumerUsageBits(DEFAULT_USAGE_FLAGS); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 141 | } |
| 142 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 143 | status_t GLConsumer::setDefaultMaxBufferCount(int bufferCount) { |
Mathias Agopian | 8072711 | 2011-05-02 19:51:12 -0700 | [diff] [blame] | 144 | Mutex::Autolock lock(mMutex); |
Jamie Gennis | 31a353d | 2012-08-24 17:25:13 -0700 | [diff] [blame] | 145 | return mBufferQueue->setDefaultMaxBufferCount(bufferCount); |
Mathias Agopian | 8072711 | 2011-05-02 19:51:12 -0700 | [diff] [blame] | 146 | } |
| 147 | |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 148 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 149 | status_t GLConsumer::setDefaultBufferSize(uint32_t w, uint32_t h) |
Mathias Agopian | a5c75c0 | 2011-03-31 19:10:24 -0700 | [diff] [blame] | 150 | { |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame] | 151 | Mutex::Autolock lock(mMutex); |
Daniel Lam | 016c8cb | 2012-04-03 15:54:58 -0700 | [diff] [blame] | 152 | mDefaultWidth = w; |
| 153 | mDefaultHeight = h; |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame] | 154 | return mBufferQueue->setDefaultBufferSize(w, h); |
Mathias Agopian | a5c75c0 | 2011-03-31 19:10:24 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 157 | status_t GLConsumer::updateTexImage() { |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 158 | ATRACE_CALL(); |
| 159 | ST_LOGV("updateTexImage"); |
| 160 | Mutex::Autolock lock(mMutex); |
| 161 | |
| 162 | if (mAbandoned) { |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 163 | ST_LOGE("updateTexImage: GLConsumer is abandoned!"); |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 164 | return NO_INIT; |
| 165 | } |
| 166 | |
| 167 | // Make sure the EGL state is the same as in previous calls. |
| 168 | status_t err = checkAndUpdateEglStateLocked(); |
| 169 | if (err != NO_ERROR) { |
| 170 | return err; |
| 171 | } |
| 172 | |
| 173 | BufferQueue::BufferItem item; |
| 174 | |
| 175 | // Acquire the next buffer. |
| 176 | // In asynchronous mode the list is guaranteed to be one buffer |
| 177 | // deep, while in synchronous mode we use the oldest buffer. |
| 178 | err = acquireBufferLocked(&item); |
| 179 | if (err != NO_ERROR) { |
| 180 | if (err == BufferQueue::NO_BUFFER_AVAILABLE) { |
| 181 | // We always bind the texture even if we don't update its contents. |
| 182 | ST_LOGV("updateTexImage: no buffers were available"); |
| 183 | glBindTexture(mTexTarget, mTexName); |
| 184 | err = NO_ERROR; |
| 185 | } else { |
| 186 | ST_LOGE("updateTexImage: acquire failed: %s (%d)", |
| 187 | strerror(-err), err); |
| 188 | } |
| 189 | return err; |
| 190 | } |
| 191 | |
| 192 | // Release the previous buffer. |
| 193 | err = releaseAndUpdateLocked(item); |
| 194 | if (err != NO_ERROR) { |
| 195 | // We always bind the texture. |
| 196 | glBindTexture(mTexTarget, mTexName); |
| 197 | return err; |
| 198 | } |
| 199 | |
Andy McFadden | 97eba89 | 2012-12-11 15:21:45 -0800 | [diff] [blame] | 200 | // Bind the new buffer to the GL texture, and wait until it's ready. |
| 201 | return bindTextureImageLocked(); |
Mathias Agopian | 2c8207e | 2012-05-23 17:56:42 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 204 | status_t GLConsumer::acquireBufferLocked(BufferQueue::BufferItem *item) { |
Jamie Gennis | 9fea342 | 2012-08-07 18:03:04 -0700 | [diff] [blame] | 205 | status_t err = ConsumerBase::acquireBufferLocked(item); |
| 206 | if (err != NO_ERROR) { |
| 207 | return err; |
| 208 | } |
| 209 | |
| 210 | int slot = item->mBuf; |
| 211 | if (item->mGraphicBuffer != NULL) { |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 212 | // This buffer has not been acquired before, so we must assume |
| 213 | // that any EGLImage in mEglSlots is stale. |
Jamie Gennis | 9fea342 | 2012-08-07 18:03:04 -0700 | [diff] [blame] | 214 | if (mEglSlots[slot].mEglImage != EGL_NO_IMAGE_KHR) { |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 215 | if (!eglDestroyImageKHR(mEglDisplay, mEglSlots[slot].mEglImage)) { |
| 216 | ST_LOGW("acquireBufferLocked: eglDestroyImageKHR failed for slot=%d", |
| 217 | slot); |
| 218 | // keep going |
| 219 | } |
Jamie Gennis | 9fea342 | 2012-08-07 18:03:04 -0700 | [diff] [blame] | 220 | mEglSlots[slot].mEglImage = EGL_NO_IMAGE_KHR; |
| 221 | } |
| 222 | } |
| 223 | |
Jamie Gennis | 9fea342 | 2012-08-07 18:03:04 -0700 | [diff] [blame] | 224 | return NO_ERROR; |
| 225 | } |
| 226 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 227 | status_t GLConsumer::releaseBufferLocked(int buf, EGLDisplay display, |
Jamie Gennis | b272541 | 2012-09-05 20:09:05 -0700 | [diff] [blame] | 228 | EGLSyncKHR eglFence) { |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 229 | status_t err = ConsumerBase::releaseBufferLocked(buf, display, eglFence); |
Jamie Gennis | 9fea342 | 2012-08-07 18:03:04 -0700 | [diff] [blame] | 230 | |
Jamie Gennis | d1b330d | 2012-09-21 11:55:35 -0700 | [diff] [blame] | 231 | mEglSlots[buf].mEglFence = EGL_NO_SYNC_KHR; |
Jamie Gennis | 9fea342 | 2012-08-07 18:03:04 -0700 | [diff] [blame] | 232 | |
| 233 | return err; |
| 234 | } |
| 235 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 236 | status_t GLConsumer::releaseAndUpdateLocked(const BufferQueue::BufferItem& item) |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 237 | { |
Daniel Lam | 9abe1eb | 2012-03-26 20:37:15 -0700 | [diff] [blame] | 238 | status_t err = NO_ERROR; |
| 239 | |
Jamie Gennis | 74bed55 | 2012-03-28 19:05:54 -0700 | [diff] [blame] | 240 | if (!mAttached) { |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 241 | ST_LOGE("releaseAndUpdate: GLConsumer is not attached to an OpenGL " |
Jamie Gennis | 74bed55 | 2012-03-28 19:05:54 -0700 | [diff] [blame] | 242 | "ES context"); |
| 243 | return INVALID_OPERATION; |
| 244 | } |
| 245 | |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 246 | // Confirm state. |
| 247 | err = checkAndUpdateEglStateLocked(); |
| 248 | if (err != NO_ERROR) { |
| 249 | return err; |
| 250 | } |
| 251 | |
| 252 | int buf = item.mBuf; |
| 253 | |
| 254 | // If the mEglSlot entry is empty, create an EGLImage for the gralloc |
| 255 | // buffer currently in the slot in ConsumerBase. |
| 256 | // |
| 257 | // We may have to do this even when item.mGraphicBuffer == NULL (which |
| 258 | // means the buffer was previously acquired), if we destroyed the |
| 259 | // EGLImage when detaching from a context but the buffer has not been |
| 260 | // re-allocated. |
| 261 | if (mEglSlots[buf].mEglImage == EGL_NO_IMAGE_KHR) { |
| 262 | EGLImageKHR image = createImage(mEglDisplay, mSlots[buf].mGraphicBuffer); |
| 263 | if (image == EGL_NO_IMAGE_KHR) { |
| 264 | ST_LOGW("releaseAndUpdate: unable to createImage on display=%p slot=%d", |
| 265 | mEglDisplay, buf); |
| 266 | return UNKNOWN_ERROR; |
| 267 | } |
| 268 | mEglSlots[buf].mEglImage = image; |
| 269 | } |
| 270 | |
| 271 | // Do whatever sync ops we need to do before releasing the old slot. |
| 272 | err = syncForReleaseLocked(mEglDisplay); |
| 273 | if (err != NO_ERROR) { |
| 274 | // Release the buffer we just acquired. It's not safe to |
| 275 | // release the old buffer, so instead we just drop the new frame. |
| 276 | releaseBufferLocked(buf, mEglDisplay, EGL_NO_SYNC_KHR); |
| 277 | return err; |
| 278 | } |
| 279 | |
| 280 | ST_LOGV("releaseAndUpdate: (slot=%d buf=%p) -> (slot=%d buf=%p)", |
| 281 | mCurrentTexture, |
| 282 | mCurrentTextureBuf != NULL ? mCurrentTextureBuf->handle : 0, |
| 283 | buf, mSlots[buf].mGraphicBuffer->handle); |
| 284 | |
| 285 | // release old buffer |
| 286 | if (mCurrentTexture != BufferQueue::INVALID_BUFFER_SLOT) { |
| 287 | status_t status = releaseBufferLocked(mCurrentTexture, mEglDisplay, |
| 288 | mEglSlots[mCurrentTexture].mEglFence); |
| 289 | if (status != NO_ERROR && status != BufferQueue::STALE_BUFFER_SLOT) { |
| 290 | ST_LOGE("releaseAndUpdate: failed to release buffer: %s (%d)", |
| 291 | strerror(-status), status); |
| 292 | err = status; |
| 293 | // keep going, with error raised [?] |
| 294 | } |
| 295 | } |
| 296 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 297 | // Update the GLConsumer state. |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 298 | mCurrentTexture = buf; |
| 299 | mCurrentTextureBuf = mSlots[buf].mGraphicBuffer; |
| 300 | mCurrentCrop = item.mCrop; |
| 301 | mCurrentTransform = item.mTransform; |
| 302 | mCurrentScalingMode = item.mScalingMode; |
| 303 | mCurrentTimestamp = item.mTimestamp; |
| 304 | mCurrentFence = item.mFence; |
| 305 | |
| 306 | computeCurrentTransformMatrixLocked(); |
| 307 | |
| 308 | return err; |
| 309 | } |
| 310 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 311 | status_t GLConsumer::bindTextureImageLocked() { |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 312 | if (mEglDisplay == EGL_NO_DISPLAY) { |
| 313 | ALOGE("bindTextureImage: invalid display"); |
| 314 | return INVALID_OPERATION; |
| 315 | } |
| 316 | |
| 317 | GLint error; |
| 318 | while ((error = glGetError()) != GL_NO_ERROR) { |
| 319 | ST_LOGW("bindTextureImage: clearing GL error: %#04x", error); |
| 320 | } |
| 321 | |
| 322 | glBindTexture(mTexTarget, mTexName); |
| 323 | if (mCurrentTexture == BufferQueue::INVALID_BUFFER_SLOT) { |
| 324 | if (mCurrentTextureBuf == NULL) { |
| 325 | ST_LOGE("bindTextureImage: no currently-bound texture"); |
| 326 | return NO_INIT; |
| 327 | } |
Andy McFadden | 97eba89 | 2012-12-11 15:21:45 -0800 | [diff] [blame] | 328 | status_t err = bindUnslottedBufferLocked(mEglDisplay); |
| 329 | if (err != NO_ERROR) { |
| 330 | return err; |
| 331 | } |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 332 | } else { |
| 333 | EGLImageKHR image = mEglSlots[mCurrentTexture].mEglImage; |
| 334 | |
| 335 | glEGLImageTargetTexture2DOES(mTexTarget, (GLeglImageOES)image); |
| 336 | |
| 337 | while ((error = glGetError()) != GL_NO_ERROR) { |
| 338 | ST_LOGE("bindTextureImage: error binding external texture image %p" |
| 339 | ": %#04x", image, error); |
| 340 | return UNKNOWN_ERROR; |
| 341 | } |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 342 | } |
Andy McFadden | 97eba89 | 2012-12-11 15:21:45 -0800 | [diff] [blame] | 343 | |
| 344 | // Wait for the new buffer to be ready. |
| 345 | return doGLFenceWaitLocked(); |
| 346 | |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 347 | } |
| 348 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 349 | status_t GLConsumer::checkAndUpdateEglStateLocked() { |
Jamie Gennis | ce56137 | 2012-03-19 18:33:05 -0700 | [diff] [blame] | 350 | EGLDisplay dpy = eglGetCurrentDisplay(); |
| 351 | EGLContext ctx = eglGetCurrentContext(); |
| 352 | |
Jamie Gennis | 74bed55 | 2012-03-28 19:05:54 -0700 | [diff] [blame] | 353 | if ((mEglDisplay != dpy && mEglDisplay != EGL_NO_DISPLAY) || |
| 354 | dpy == EGL_NO_DISPLAY) { |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 355 | ST_LOGE("checkAndUpdateEglState: invalid current EGLDisplay"); |
Jamie Gennis | 74bed55 | 2012-03-28 19:05:54 -0700 | [diff] [blame] | 356 | return INVALID_OPERATION; |
Jamie Gennis | ce56137 | 2012-03-19 18:33:05 -0700 | [diff] [blame] | 357 | } |
| 358 | |
Jamie Gennis | 74bed55 | 2012-03-28 19:05:54 -0700 | [diff] [blame] | 359 | if ((mEglContext != ctx && mEglContext != EGL_NO_CONTEXT) || |
| 360 | ctx == EGL_NO_CONTEXT) { |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 361 | ST_LOGE("checkAndUpdateEglState: invalid current EGLContext"); |
Jamie Gennis | 74bed55 | 2012-03-28 19:05:54 -0700 | [diff] [blame] | 362 | return INVALID_OPERATION; |
Jamie Gennis | ce56137 | 2012-03-19 18:33:05 -0700 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | mEglDisplay = dpy; |
| 366 | mEglContext = ctx; |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 367 | return NO_ERROR; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 368 | } |
| 369 | |
Jesse Hall | 13f01cb | 2013-03-20 11:37:21 -0700 | [diff] [blame] | 370 | void GLConsumer::setReleaseFence(const sp<Fence>& fence) { |
| 371 | if (fence->isValid() && |
| 372 | mCurrentTexture != BufferQueue::INVALID_BUFFER_SLOT) { |
| 373 | status_t err = addReleaseFence(mCurrentTexture, fence); |
| 374 | if (err != OK) { |
| 375 | ST_LOGE("setReleaseFence: failed to add the fence: %s (%d)", |
| 376 | strerror(-err), err); |
| 377 | } |
Jesse Hall | ef19414 | 2012-06-14 14:45:17 -0700 | [diff] [blame] | 378 | } |
| 379 | } |
| 380 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 381 | status_t GLConsumer::detachFromContext() { |
Jamie Gennis | 74bed55 | 2012-03-28 19:05:54 -0700 | [diff] [blame] | 382 | ATRACE_CALL(); |
| 383 | ST_LOGV("detachFromContext"); |
| 384 | Mutex::Autolock lock(mMutex); |
| 385 | |
| 386 | if (mAbandoned) { |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 387 | ST_LOGE("detachFromContext: abandoned GLConsumer"); |
Jamie Gennis | 74bed55 | 2012-03-28 19:05:54 -0700 | [diff] [blame] | 388 | return NO_INIT; |
| 389 | } |
| 390 | |
| 391 | if (!mAttached) { |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 392 | ST_LOGE("detachFromContext: GLConsumer is not attached to a " |
Jamie Gennis | 74bed55 | 2012-03-28 19:05:54 -0700 | [diff] [blame] | 393 | "context"); |
| 394 | return INVALID_OPERATION; |
| 395 | } |
| 396 | |
| 397 | EGLDisplay dpy = eglGetCurrentDisplay(); |
| 398 | EGLContext ctx = eglGetCurrentContext(); |
| 399 | |
| 400 | if (mEglDisplay != dpy && mEglDisplay != EGL_NO_DISPLAY) { |
| 401 | ST_LOGE("detachFromContext: invalid current EGLDisplay"); |
| 402 | return INVALID_OPERATION; |
| 403 | } |
| 404 | |
| 405 | if (mEglContext != ctx && mEglContext != EGL_NO_CONTEXT) { |
| 406 | ST_LOGE("detachFromContext: invalid current EGLContext"); |
| 407 | return INVALID_OPERATION; |
| 408 | } |
| 409 | |
| 410 | if (dpy != EGL_NO_DISPLAY && ctx != EGL_NO_CONTEXT) { |
| 411 | status_t err = syncForReleaseLocked(dpy); |
| 412 | if (err != OK) { |
| 413 | return err; |
| 414 | } |
| 415 | |
| 416 | glDeleteTextures(1, &mTexName); |
| 417 | } |
| 418 | |
Jamie Gennis | 9aa74db | 2012-04-17 13:07:45 -0700 | [diff] [blame] | 419 | // Because we're giving up the EGLDisplay we need to free all the EGLImages |
| 420 | // that are associated with it. They'll be recreated when the |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 421 | // GLConsumer gets attached to a new OpenGL ES context (and thus gets a |
Jamie Gennis | 9aa74db | 2012-04-17 13:07:45 -0700 | [diff] [blame] | 422 | // new EGLDisplay). |
| 423 | for (int i =0; i < BufferQueue::NUM_BUFFER_SLOTS; i++) { |
Jamie Gennis | 9fea342 | 2012-08-07 18:03:04 -0700 | [diff] [blame] | 424 | EGLImageKHR img = mEglSlots[i].mEglImage; |
Jamie Gennis | 5c8a608 | 2012-05-02 13:10:56 -0700 | [diff] [blame] | 425 | if (img != EGL_NO_IMAGE_KHR) { |
Jamie Gennis | 9aa74db | 2012-04-17 13:07:45 -0700 | [diff] [blame] | 426 | eglDestroyImageKHR(mEglDisplay, img); |
Jamie Gennis | 9fea342 | 2012-08-07 18:03:04 -0700 | [diff] [blame] | 427 | mEglSlots[i].mEglImage = EGL_NO_IMAGE_KHR; |
Jamie Gennis | 9aa74db | 2012-04-17 13:07:45 -0700 | [diff] [blame] | 428 | } |
| 429 | } |
| 430 | |
Jamie Gennis | 74bed55 | 2012-03-28 19:05:54 -0700 | [diff] [blame] | 431 | mEglDisplay = EGL_NO_DISPLAY; |
| 432 | mEglContext = EGL_NO_CONTEXT; |
| 433 | mAttached = false; |
| 434 | |
| 435 | return OK; |
| 436 | } |
| 437 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 438 | status_t GLConsumer::attachToContext(GLuint tex) { |
Jamie Gennis | 74bed55 | 2012-03-28 19:05:54 -0700 | [diff] [blame] | 439 | ATRACE_CALL(); |
| 440 | ST_LOGV("attachToContext"); |
| 441 | Mutex::Autolock lock(mMutex); |
| 442 | |
| 443 | if (mAbandoned) { |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 444 | ST_LOGE("attachToContext: abandoned GLConsumer"); |
Jamie Gennis | 74bed55 | 2012-03-28 19:05:54 -0700 | [diff] [blame] | 445 | return NO_INIT; |
| 446 | } |
| 447 | |
| 448 | if (mAttached) { |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 449 | ST_LOGE("attachToContext: GLConsumer is already attached to a " |
Jamie Gennis | 74bed55 | 2012-03-28 19:05:54 -0700 | [diff] [blame] | 450 | "context"); |
| 451 | return INVALID_OPERATION; |
| 452 | } |
| 453 | |
| 454 | EGLDisplay dpy = eglGetCurrentDisplay(); |
| 455 | EGLContext ctx = eglGetCurrentContext(); |
| 456 | |
| 457 | if (dpy == EGL_NO_DISPLAY) { |
| 458 | ST_LOGE("attachToContext: invalid current EGLDisplay"); |
| 459 | return INVALID_OPERATION; |
| 460 | } |
| 461 | |
| 462 | if (ctx == EGL_NO_CONTEXT) { |
| 463 | ST_LOGE("attachToContext: invalid current EGLContext"); |
| 464 | return INVALID_OPERATION; |
| 465 | } |
| 466 | |
| 467 | // We need to bind the texture regardless of whether there's a current |
| 468 | // buffer. |
| 469 | glBindTexture(mTexTarget, tex); |
| 470 | |
| 471 | if (mCurrentTextureBuf != NULL) { |
Jamie Gennis | 5c8a608 | 2012-05-02 13:10:56 -0700 | [diff] [blame] | 472 | // The EGLImageKHR that was associated with the slot was destroyed when |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 473 | // the GLConsumer was detached from the old context, so we need to |
Jamie Gennis | 5c8a608 | 2012-05-02 13:10:56 -0700 | [diff] [blame] | 474 | // recreate it here. |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 475 | status_t err = bindUnslottedBufferLocked(dpy); |
| 476 | if (err != NO_ERROR) { |
Jamie Gennis | 74bed55 | 2012-03-28 19:05:54 -0700 | [diff] [blame] | 477 | return err; |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | mEglDisplay = dpy; |
| 482 | mEglContext = ctx; |
| 483 | mTexName = tex; |
| 484 | mAttached = true; |
| 485 | |
| 486 | return OK; |
| 487 | } |
| 488 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 489 | status_t GLConsumer::bindUnslottedBufferLocked(EGLDisplay dpy) { |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 490 | ST_LOGV("bindUnslottedBuffer ct=%d ctb=%p", |
| 491 | mCurrentTexture, mCurrentTextureBuf.get()); |
| 492 | |
| 493 | // Create a temporary EGLImageKHR. |
| 494 | EGLImageKHR image = createImage(dpy, mCurrentTextureBuf); |
| 495 | if (image == EGL_NO_IMAGE_KHR) { |
| 496 | return UNKNOWN_ERROR; |
| 497 | } |
| 498 | |
| 499 | // Attach the current buffer to the GL texture. |
| 500 | glEGLImageTargetTexture2DOES(mTexTarget, (GLeglImageOES)image); |
| 501 | |
| 502 | GLint error; |
| 503 | status_t err = OK; |
| 504 | while ((error = glGetError()) != GL_NO_ERROR) { |
| 505 | ST_LOGE("bindUnslottedBuffer: error binding external texture image %p " |
| 506 | "(slot %d): %#04x", image, mCurrentTexture, error); |
| 507 | err = UNKNOWN_ERROR; |
| 508 | } |
| 509 | |
| 510 | // We destroy the EGLImageKHR here because the current buffer may no |
| 511 | // longer be associated with one of the buffer slots, so we have |
| 512 | // nowhere to to store it. If the buffer is still associated with a |
| 513 | // slot then another EGLImageKHR will be created next time that buffer |
| 514 | // gets acquired in updateTexImage. |
| 515 | eglDestroyImageKHR(dpy, image); |
| 516 | |
| 517 | return err; |
| 518 | } |
| 519 | |
| 520 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 521 | status_t GLConsumer::syncForReleaseLocked(EGLDisplay dpy) { |
Jamie Gennis | 74bed55 | 2012-03-28 19:05:54 -0700 | [diff] [blame] | 522 | ST_LOGV("syncForReleaseLocked"); |
| 523 | |
Jamie Gennis | 01dbf55 | 2012-09-06 14:54:19 -0700 | [diff] [blame] | 524 | if (mCurrentTexture != BufferQueue::INVALID_BUFFER_SLOT) { |
Andy McFadden | 97eba89 | 2012-12-11 15:21:45 -0800 | [diff] [blame] | 525 | if (sUseNativeFenceSync) { |
Jamie Gennis | 01dbf55 | 2012-09-06 14:54:19 -0700 | [diff] [blame] | 526 | EGLSyncKHR sync = eglCreateSyncKHR(dpy, |
| 527 | EGL_SYNC_NATIVE_FENCE_ANDROID, NULL); |
| 528 | if (sync == EGL_NO_SYNC_KHR) { |
| 529 | ST_LOGE("syncForReleaseLocked: error creating EGL fence: %#x", |
| 530 | eglGetError()); |
Jamie Gennis | 74bed55 | 2012-03-28 19:05:54 -0700 | [diff] [blame] | 531 | return UNKNOWN_ERROR; |
Jamie Gennis | 74bed55 | 2012-03-28 19:05:54 -0700 | [diff] [blame] | 532 | } |
Jamie Gennis | 01dbf55 | 2012-09-06 14:54:19 -0700 | [diff] [blame] | 533 | glFlush(); |
| 534 | int fenceFd = eglDupNativeFenceFDANDROID(dpy, sync); |
Jamie Gennis | 98ff059 | 2012-09-10 14:49:42 -0700 | [diff] [blame] | 535 | eglDestroySyncKHR(dpy, sync); |
Jamie Gennis | 01dbf55 | 2012-09-06 14:54:19 -0700 | [diff] [blame] | 536 | if (fenceFd == EGL_NO_NATIVE_FENCE_FD_ANDROID) { |
| 537 | ST_LOGE("syncForReleaseLocked: error dup'ing native fence " |
| 538 | "fd: %#x", eglGetError()); |
| 539 | return UNKNOWN_ERROR; |
| 540 | } |
| 541 | sp<Fence> fence(new Fence(fenceFd)); |
Jesse Hall | 9504eb9 | 2012-10-05 14:34:21 -0700 | [diff] [blame] | 542 | status_t err = addReleaseFenceLocked(mCurrentTexture, fence); |
Jamie Gennis | 01dbf55 | 2012-09-06 14:54:19 -0700 | [diff] [blame] | 543 | if (err != OK) { |
| 544 | ST_LOGE("syncForReleaseLocked: error adding release fence: " |
| 545 | "%s (%d)", strerror(-err), err); |
| 546 | return err; |
| 547 | } |
| 548 | } else if (mUseFenceSync) { |
| 549 | EGLSyncKHR fence = mEglSlots[mCurrentTexture].mEglFence; |
| 550 | if (fence != EGL_NO_SYNC_KHR) { |
| 551 | // There is already a fence for the current slot. We need to |
| 552 | // wait on that before replacing it with another fence to |
| 553 | // ensure that all outstanding buffer accesses have completed |
| 554 | // before the producer accesses it. |
| 555 | EGLint result = eglClientWaitSyncKHR(dpy, fence, 0, 1000000000); |
| 556 | if (result == EGL_FALSE) { |
| 557 | ST_LOGE("syncForReleaseLocked: error waiting for previous " |
| 558 | "fence: %#x", eglGetError()); |
| 559 | return UNKNOWN_ERROR; |
| 560 | } else if (result == EGL_TIMEOUT_EXPIRED_KHR) { |
| 561 | ST_LOGE("syncForReleaseLocked: timeout waiting for previous " |
| 562 | "fence"); |
| 563 | return TIMED_OUT; |
| 564 | } |
| 565 | eglDestroySyncKHR(dpy, fence); |
| 566 | } |
Jamie Gennis | 74bed55 | 2012-03-28 19:05:54 -0700 | [diff] [blame] | 567 | |
Jamie Gennis | 01dbf55 | 2012-09-06 14:54:19 -0700 | [diff] [blame] | 568 | // Create a fence for the outstanding accesses in the current |
| 569 | // OpenGL ES context. |
| 570 | fence = eglCreateSyncKHR(dpy, EGL_SYNC_FENCE_KHR, NULL); |
| 571 | if (fence == EGL_NO_SYNC_KHR) { |
| 572 | ST_LOGE("syncForReleaseLocked: error creating fence: %#x", |
| 573 | eglGetError()); |
| 574 | return UNKNOWN_ERROR; |
| 575 | } |
| 576 | glFlush(); |
| 577 | mEglSlots[mCurrentTexture].mEglFence = fence; |
Jamie Gennis | 74bed55 | 2012-03-28 19:05:54 -0700 | [diff] [blame] | 578 | } |
Jamie Gennis | 74bed55 | 2012-03-28 19:05:54 -0700 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | return OK; |
| 582 | } |
| 583 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 584 | bool GLConsumer::isExternalFormat(uint32_t format) |
Mathias Agopian | 7a042bf | 2011-04-11 21:19:55 -0700 | [diff] [blame] | 585 | { |
| 586 | switch (format) { |
| 587 | // supported YUV formats |
| 588 | case HAL_PIXEL_FORMAT_YV12: |
| 589 | // Legacy/deprecated YUV formats |
| 590 | case HAL_PIXEL_FORMAT_YCbCr_422_SP: |
| 591 | case HAL_PIXEL_FORMAT_YCrCb_420_SP: |
| 592 | case HAL_PIXEL_FORMAT_YCbCr_422_I: |
| 593 | return true; |
| 594 | } |
| 595 | |
| 596 | // Any OEM format needs to be considered |
| 597 | if (format>=0x100 && format<=0x1FF) |
| 598 | return true; |
| 599 | |
| 600 | return false; |
| 601 | } |
| 602 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 603 | GLenum GLConsumer::getCurrentTextureTarget() const { |
Jamie Gennis | fb1b5a2 | 2011-09-28 12:13:31 -0700 | [diff] [blame] | 604 | return mTexTarget; |
Mathias Agopian | 7a042bf | 2011-04-11 21:19:55 -0700 | [diff] [blame] | 605 | } |
| 606 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 607 | void GLConsumer::getTransformMatrix(float mtx[16]) { |
Jamie Gennis | f238e28 | 2011-01-09 16:33:17 -0800 | [diff] [blame] | 608 | Mutex::Autolock lock(mMutex); |
Jamie Gennis | 736aa95 | 2011-06-12 17:03:06 -0700 | [diff] [blame] | 609 | memcpy(mtx, mCurrentTransformMatrix, sizeof(mCurrentTransformMatrix)); |
| 610 | } |
| 611 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 612 | void GLConsumer::setFilteringEnabled(bool enabled) { |
Jamie Gennis | 5c1139f | 2012-05-08 16:56:34 -0700 | [diff] [blame] | 613 | Mutex::Autolock lock(mMutex); |
Mathias Agopian | e96e9e1 | 2012-09-24 19:26:11 -0700 | [diff] [blame] | 614 | if (mAbandoned) { |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 615 | ST_LOGE("setFilteringEnabled: GLConsumer is abandoned!"); |
Mathias Agopian | e96e9e1 | 2012-09-24 19:26:11 -0700 | [diff] [blame] | 616 | return; |
| 617 | } |
Jamie Gennis | 5c1139f | 2012-05-08 16:56:34 -0700 | [diff] [blame] | 618 | bool needsRecompute = mFilteringEnabled != enabled; |
| 619 | mFilteringEnabled = enabled; |
Mathias Agopian | e96e9e1 | 2012-09-24 19:26:11 -0700 | [diff] [blame] | 620 | |
| 621 | if (needsRecompute && mCurrentTextureBuf==NULL) { |
| 622 | ST_LOGD("setFilteringEnabled called with mCurrentTextureBuf == NULL"); |
| 623 | } |
| 624 | |
| 625 | if (needsRecompute && mCurrentTextureBuf != NULL) { |
| 626 | computeCurrentTransformMatrixLocked(); |
Jamie Gennis | 5c1139f | 2012-05-08 16:56:34 -0700 | [diff] [blame] | 627 | } |
| 628 | } |
| 629 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 630 | void GLConsumer::computeCurrentTransformMatrixLocked() { |
Mathias Agopian | e96e9e1 | 2012-09-24 19:26:11 -0700 | [diff] [blame] | 631 | ST_LOGV("computeCurrentTransformMatrixLocked"); |
Jamie Gennis | f238e28 | 2011-01-09 16:33:17 -0800 | [diff] [blame] | 632 | |
Jamie Gennis | a214c64 | 2011-01-14 13:53:31 -0800 | [diff] [blame] | 633 | float xform[16]; |
| 634 | for (int i = 0; i < 16; i++) { |
| 635 | xform[i] = mtxIdentity[i]; |
| 636 | } |
| 637 | if (mCurrentTransform & NATIVE_WINDOW_TRANSFORM_FLIP_H) { |
| 638 | float result[16]; |
| 639 | mtxMul(result, xform, mtxFlipH); |
| 640 | for (int i = 0; i < 16; i++) { |
| 641 | xform[i] = result[i]; |
| 642 | } |
| 643 | } |
| 644 | if (mCurrentTransform & NATIVE_WINDOW_TRANSFORM_FLIP_V) { |
| 645 | float result[16]; |
| 646 | mtxMul(result, xform, mtxFlipV); |
| 647 | for (int i = 0; i < 16; i++) { |
| 648 | xform[i] = result[i]; |
| 649 | } |
| 650 | } |
| 651 | if (mCurrentTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) { |
| 652 | float result[16]; |
| 653 | mtxMul(result, xform, mtxRot90); |
| 654 | for (int i = 0; i < 16; i++) { |
| 655 | xform[i] = result[i]; |
| 656 | } |
Jamie Gennis | f238e28 | 2011-01-09 16:33:17 -0800 | [diff] [blame] | 657 | } |
| 658 | |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 659 | sp<GraphicBuffer>& buf(mCurrentTextureBuf); |
Mathias Agopian | e96e9e1 | 2012-09-24 19:26:11 -0700 | [diff] [blame] | 660 | |
| 661 | if (buf == NULL) { |
| 662 | ST_LOGD("computeCurrentTransformMatrixLocked: mCurrentTextureBuf is NULL"); |
| 663 | } |
| 664 | |
Jamie Gennis | d72f233 | 2012-05-07 13:50:11 -0700 | [diff] [blame] | 665 | Rect cropRect = mCurrentCrop; |
Jamie Gennis | 5c1139f | 2012-05-08 16:56:34 -0700 | [diff] [blame] | 666 | float tx = 0.0f, ty = 0.0f, sx = 1.0f, sy = 1.0f; |
| 667 | float bufferWidth = buf->getWidth(); |
| 668 | float bufferHeight = buf->getHeight(); |
Jamie Gennis | d72f233 | 2012-05-07 13:50:11 -0700 | [diff] [blame] | 669 | if (!cropRect.isEmpty()) { |
Jamie Gennis | 5c1139f | 2012-05-08 16:56:34 -0700 | [diff] [blame] | 670 | float shrinkAmount = 0.0f; |
| 671 | if (mFilteringEnabled) { |
| 672 | // In order to prevent bilinear sampling beyond the edge of the |
| 673 | // crop rectangle we may need to shrink it by 2 texels in each |
| 674 | // dimension. Normally this would just need to take 1/2 a texel |
| 675 | // off each end, but because the chroma channels of YUV420 images |
| 676 | // are subsampled we may need to shrink the crop region by a whole |
| 677 | // texel on each side. |
| 678 | switch (buf->getPixelFormat()) { |
| 679 | case PIXEL_FORMAT_RGBA_8888: |
| 680 | case PIXEL_FORMAT_RGBX_8888: |
| 681 | case PIXEL_FORMAT_RGB_888: |
| 682 | case PIXEL_FORMAT_RGB_565: |
| 683 | case PIXEL_FORMAT_BGRA_8888: |
| 684 | case PIXEL_FORMAT_RGBA_5551: |
| 685 | case PIXEL_FORMAT_RGBA_4444: |
| 686 | // We know there's no subsampling of any channels, so we |
| 687 | // only need to shrink by a half a pixel. |
| 688 | shrinkAmount = 0.5; |
Romain Guy | 4f9c284 | 2012-08-01 19:16:59 -0700 | [diff] [blame] | 689 | break; |
Jamie Gennis | 9fea342 | 2012-08-07 18:03:04 -0700 | [diff] [blame] | 690 | |
Jamie Gennis | 5c1139f | 2012-05-08 16:56:34 -0700 | [diff] [blame] | 691 | default: |
| 692 | // If we don't recognize the format, we must assume the |
| 693 | // worst case (that we care about), which is YUV420. |
| 694 | shrinkAmount = 1.0; |
Jamie Gennis | 9fea342 | 2012-08-07 18:03:04 -0700 | [diff] [blame] | 695 | break; |
Jamie Gennis | 5c1139f | 2012-05-08 16:56:34 -0700 | [diff] [blame] | 696 | } |
| 697 | } |
Jamie Gennis | d72f233 | 2012-05-07 13:50:11 -0700 | [diff] [blame] | 698 | |
Jamie Gennis | 5c1139f | 2012-05-08 16:56:34 -0700 | [diff] [blame] | 699 | // Only shrink the dimensions that are not the size of the buffer. |
| 700 | if (cropRect.width() < bufferWidth) { |
| 701 | tx = (float(cropRect.left) + shrinkAmount) / bufferWidth; |
| 702 | sx = (float(cropRect.width()) - (2.0f * shrinkAmount)) / |
| 703 | bufferWidth; |
| 704 | } |
| 705 | if (cropRect.height() < bufferHeight) { |
| 706 | ty = (float(bufferHeight - cropRect.bottom) + shrinkAmount) / |
| 707 | bufferHeight; |
| 708 | sy = (float(cropRect.height()) - (2.0f * shrinkAmount)) / |
| 709 | bufferHeight; |
| 710 | } |
Jamie Gennis | a214c64 | 2011-01-14 13:53:31 -0800 | [diff] [blame] | 711 | } |
Jamie Gennis | f238e28 | 2011-01-09 16:33:17 -0800 | [diff] [blame] | 712 | float crop[16] = { |
Jamie Gennis | a214c64 | 2011-01-14 13:53:31 -0800 | [diff] [blame] | 713 | sx, 0, 0, 0, |
| 714 | 0, sy, 0, 0, |
Jamie Gennis | f238e28 | 2011-01-09 16:33:17 -0800 | [diff] [blame] | 715 | 0, 0, 1, 0, |
Jamie Gennis | d99c088 | 2011-03-10 16:24:46 -0800 | [diff] [blame] | 716 | tx, ty, 0, 1, |
Jamie Gennis | f238e28 | 2011-01-09 16:33:17 -0800 | [diff] [blame] | 717 | }; |
| 718 | |
Jamie Gennis | a214c64 | 2011-01-14 13:53:31 -0800 | [diff] [blame] | 719 | float mtxBeforeFlipV[16]; |
| 720 | mtxMul(mtxBeforeFlipV, crop, xform); |
| 721 | |
| 722 | // SurfaceFlinger expects the top of its window textures to be at a Y |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 723 | // coordinate of 0, so GLConsumer must behave the same way. We don't |
Jamie Gennis | a214c64 | 2011-01-14 13:53:31 -0800 | [diff] [blame] | 724 | // want to expose this to applications, however, so we must add an |
| 725 | // additional vertical flip to the transform after all the other transforms. |
Jamie Gennis | 736aa95 | 2011-06-12 17:03:06 -0700 | [diff] [blame] | 726 | mtxMul(mCurrentTransformMatrix, mtxFlipV, mtxBeforeFlipV); |
Jamie Gennis | f238e28 | 2011-01-09 16:33:17 -0800 | [diff] [blame] | 727 | } |
| 728 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 729 | nsecs_t GLConsumer::getTimestamp() { |
Jamie Gennis | 6ee96ad | 2011-10-19 13:36:31 -0700 | [diff] [blame] | 730 | ST_LOGV("getTimestamp"); |
Eino-Ville Talvala | 1d01a12 | 2011-02-18 11:02:42 -0800 | [diff] [blame] | 731 | Mutex::Autolock lock(mMutex); |
| 732 | return mCurrentTimestamp; |
| 733 | } |
| 734 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 735 | EGLImageKHR GLConsumer::createImage(EGLDisplay dpy, |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 736 | const sp<GraphicBuffer>& graphicBuffer) { |
| 737 | EGLClientBuffer cbuf = (EGLClientBuffer)graphicBuffer->getNativeBuffer(); |
| 738 | EGLint attrs[] = { |
| 739 | EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, |
| 740 | EGL_NONE, |
| 741 | }; |
| 742 | EGLImageKHR image = eglCreateImageKHR(dpy, EGL_NO_CONTEXT, |
| 743 | EGL_NATIVE_BUFFER_ANDROID, cbuf, attrs); |
Mathias Agopian | 3cd5a11 | 2011-04-26 14:57:40 -0700 | [diff] [blame] | 744 | if (image == EGL_NO_IMAGE_KHR) { |
| 745 | EGLint error = eglGetError(); |
Jamie Gennis | fa28c35 | 2011-09-16 17:30:26 -0700 | [diff] [blame] | 746 | ST_LOGE("error creating EGLImage: %#x", error); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 747 | } |
| 748 | return image; |
| 749 | } |
| 750 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 751 | sp<GraphicBuffer> GLConsumer::getCurrentBuffer() const { |
Mathias Agopian | 7a042bf | 2011-04-11 21:19:55 -0700 | [diff] [blame] | 752 | Mutex::Autolock lock(mMutex); |
| 753 | return mCurrentTextureBuf; |
| 754 | } |
| 755 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 756 | Rect GLConsumer::getCurrentCrop() const { |
Mathias Agopian | 7a042bf | 2011-04-11 21:19:55 -0700 | [diff] [blame] | 757 | Mutex::Autolock lock(mMutex); |
Daniel Lam | 016c8cb | 2012-04-03 15:54:58 -0700 | [diff] [blame] | 758 | |
| 759 | Rect outCrop = mCurrentCrop; |
| 760 | if (mCurrentScalingMode == NATIVE_WINDOW_SCALING_MODE_SCALE_CROP) { |
| 761 | int32_t newWidth = mCurrentCrop.width(); |
| 762 | int32_t newHeight = mCurrentCrop.height(); |
| 763 | |
| 764 | if (newWidth * mDefaultHeight > newHeight * mDefaultWidth) { |
| 765 | newWidth = newHeight * mDefaultWidth / mDefaultHeight; |
| 766 | ST_LOGV("too wide: newWidth = %d", newWidth); |
| 767 | } else if (newWidth * mDefaultHeight < newHeight * mDefaultWidth) { |
| 768 | newHeight = newWidth * mDefaultHeight / mDefaultWidth; |
| 769 | ST_LOGV("too tall: newHeight = %d", newHeight); |
| 770 | } |
| 771 | |
| 772 | // The crop is too wide |
| 773 | if (newWidth < mCurrentCrop.width()) { |
| 774 | int32_t dw = (newWidth - mCurrentCrop.width())/2; |
| 775 | outCrop.left -=dw; |
| 776 | outCrop.right += dw; |
| 777 | // The crop is too tall |
| 778 | } else if (newHeight < mCurrentCrop.height()) { |
| 779 | int32_t dh = (newHeight - mCurrentCrop.height())/2; |
| 780 | outCrop.top -= dh; |
| 781 | outCrop.bottom += dh; |
| 782 | } |
| 783 | |
| 784 | ST_LOGV("getCurrentCrop final crop [%d,%d,%d,%d]", |
| 785 | outCrop.left, outCrop.top, |
| 786 | outCrop.right,outCrop.bottom); |
| 787 | } |
| 788 | |
Daniel Lam | 016c8cb | 2012-04-03 15:54:58 -0700 | [diff] [blame] | 789 | return outCrop; |
Mathias Agopian | 7a042bf | 2011-04-11 21:19:55 -0700 | [diff] [blame] | 790 | } |
| 791 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 792 | uint32_t GLConsumer::getCurrentTransform() const { |
Mathias Agopian | 7a042bf | 2011-04-11 21:19:55 -0700 | [diff] [blame] | 793 | Mutex::Autolock lock(mMutex); |
| 794 | return mCurrentTransform; |
| 795 | } |
| 796 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 797 | uint32_t GLConsumer::getCurrentScalingMode() const { |
Mathias Agopian | 7734ebf | 2011-07-13 15:24:42 -0700 | [diff] [blame] | 798 | Mutex::Autolock lock(mMutex); |
| 799 | return mCurrentScalingMode; |
| 800 | } |
| 801 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 802 | sp<Fence> GLConsumer::getCurrentFence() const { |
Jesse Hall | dc5b485 | 2012-06-29 15:21:18 -0700 | [diff] [blame] | 803 | Mutex::Autolock lock(mMutex); |
| 804 | return mCurrentFence; |
| 805 | } |
| 806 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 807 | status_t GLConsumer::doGLFenceWait() const { |
Jamie Gennis | 61e04b9 | 2012-09-09 17:48:42 -0700 | [diff] [blame] | 808 | Mutex::Autolock lock(mMutex); |
Jamie Gennis | 3941cb2 | 2012-09-17 16:58:17 -0700 | [diff] [blame] | 809 | return doGLFenceWaitLocked(); |
| 810 | } |
| 811 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 812 | status_t GLConsumer::doGLFenceWaitLocked() const { |
Jamie Gennis | 61e04b9 | 2012-09-09 17:48:42 -0700 | [diff] [blame] | 813 | |
| 814 | EGLDisplay dpy = eglGetCurrentDisplay(); |
| 815 | EGLContext ctx = eglGetCurrentContext(); |
| 816 | |
| 817 | if (mEglDisplay != dpy || mEglDisplay == EGL_NO_DISPLAY) { |
| 818 | ST_LOGE("doGLFenceWait: invalid current EGLDisplay"); |
| 819 | return INVALID_OPERATION; |
| 820 | } |
| 821 | |
| 822 | if (mEglContext != ctx || mEglContext == EGL_NO_CONTEXT) { |
| 823 | ST_LOGE("doGLFenceWait: invalid current EGLContext"); |
| 824 | return INVALID_OPERATION; |
| 825 | } |
| 826 | |
Jamie Gennis | 1df8c34 | 2012-12-20 14:05:45 -0800 | [diff] [blame] | 827 | if (mCurrentFence->isValid()) { |
Jamie Gennis | 61e04b9 | 2012-09-09 17:48:42 -0700 | [diff] [blame] | 828 | if (useWaitSync) { |
| 829 | // Create an EGLSyncKHR from the current fence. |
| 830 | int fenceFd = mCurrentFence->dup(); |
| 831 | if (fenceFd == -1) { |
| 832 | ST_LOGE("doGLFenceWait: error dup'ing fence fd: %d", errno); |
| 833 | return -errno; |
| 834 | } |
| 835 | EGLint attribs[] = { |
| 836 | EGL_SYNC_NATIVE_FENCE_FD_ANDROID, fenceFd, |
| 837 | EGL_NONE |
| 838 | }; |
| 839 | EGLSyncKHR sync = eglCreateSyncKHR(dpy, |
| 840 | EGL_SYNC_NATIVE_FENCE_ANDROID, attribs); |
| 841 | if (sync == EGL_NO_SYNC_KHR) { |
| 842 | close(fenceFd); |
| 843 | ST_LOGE("doGLFenceWait: error creating EGL fence: %#x", |
| 844 | eglGetError()); |
| 845 | return UNKNOWN_ERROR; |
| 846 | } |
| 847 | |
| 848 | // XXX: The spec draft is inconsistent as to whether this should |
| 849 | // return an EGLint or void. Ignore the return value for now, as |
| 850 | // it's not strictly needed. |
| 851 | eglWaitSyncANDROID(dpy, sync, 0); |
| 852 | EGLint eglErr = eglGetError(); |
| 853 | eglDestroySyncKHR(dpy, sync); |
| 854 | if (eglErr != EGL_SUCCESS) { |
| 855 | ST_LOGE("doGLFenceWait: error waiting for EGL fence: %#x", |
| 856 | eglErr); |
| 857 | return UNKNOWN_ERROR; |
| 858 | } |
| 859 | } else { |
Jesse Hall | ba607d5 | 2012-10-01 14:05:20 -0700 | [diff] [blame] | 860 | status_t err = mCurrentFence->waitForever(1000, |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 861 | "GLConsumer::doGLFenceWaitLocked"); |
Jamie Gennis | 61e04b9 | 2012-09-09 17:48:42 -0700 | [diff] [blame] | 862 | if (err != NO_ERROR) { |
| 863 | ST_LOGE("doGLFenceWait: error waiting for fence: %d", err); |
| 864 | return err; |
| 865 | } |
| 866 | } |
| 867 | } |
| 868 | |
| 869 | return NO_ERROR; |
| 870 | } |
| 871 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 872 | bool GLConsumer::isSynchronousMode() const { |
Jamie Gennis | 5976946 | 2011-11-19 18:04:43 -0800 | [diff] [blame] | 873 | Mutex::Autolock lock(mMutex); |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame] | 874 | return mBufferQueue->isSynchronousMode(); |
Jamie Gennis | 5976946 | 2011-11-19 18:04:43 -0800 | [diff] [blame] | 875 | } |
| 876 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 877 | void GLConsumer::freeBufferLocked(int slotIndex) { |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 878 | ST_LOGV("freeBufferLocked: slotIndex=%d", slotIndex); |
Daniel Lam | 9abe1eb | 2012-03-26 20:37:15 -0700 | [diff] [blame] | 879 | if (slotIndex == mCurrentTexture) { |
| 880 | mCurrentTexture = BufferQueue::INVALID_BUFFER_SLOT; |
| 881 | } |
Jamie Gennis | 9fea342 | 2012-08-07 18:03:04 -0700 | [diff] [blame] | 882 | EGLImageKHR img = mEglSlots[slotIndex].mEglImage; |
Jamie Gennis | 9aa74db | 2012-04-17 13:07:45 -0700 | [diff] [blame] | 883 | if (img != EGL_NO_IMAGE_KHR) { |
| 884 | ST_LOGV("destroying EGLImage dpy=%p img=%p", mEglDisplay, img); |
| 885 | eglDestroyImageKHR(mEglDisplay, img); |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 886 | } |
Jamie Gennis | 9fea342 | 2012-08-07 18:03:04 -0700 | [diff] [blame] | 887 | mEglSlots[slotIndex].mEglImage = EGL_NO_IMAGE_KHR; |
| 888 | ConsumerBase::freeBufferLocked(slotIndex); |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 889 | } |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 890 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 891 | void GLConsumer::abandonLocked() { |
Jamie Gennis | 9fea342 | 2012-08-07 18:03:04 -0700 | [diff] [blame] | 892 | ST_LOGV("abandonLocked"); |
| 893 | mCurrentTextureBuf.clear(); |
| 894 | ConsumerBase::abandonLocked(); |
Jamie Gennis | 7b305ff | 2011-07-19 12:08:33 -0700 | [diff] [blame] | 895 | } |
| 896 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 897 | void GLConsumer::setName(const String8& name) { |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 898 | Mutex::Autolock _l(mMutex); |
Jamie Gennis | fa28c35 | 2011-09-16 17:30:26 -0700 | [diff] [blame] | 899 | mName = name; |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame] | 900 | mBufferQueue->setConsumerName(name); |
| 901 | } |
| 902 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 903 | status_t GLConsumer::setDefaultBufferFormat(uint32_t defaultFormat) { |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame] | 904 | Mutex::Autolock lock(mMutex); |
| 905 | return mBufferQueue->setDefaultBufferFormat(defaultFormat); |
| 906 | } |
| 907 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 908 | status_t GLConsumer::setConsumerUsageBits(uint32_t usage) { |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame] | 909 | Mutex::Autolock lock(mMutex); |
Eino-Ville Talvala | 85b2176 | 2012-04-13 15:16:31 -0700 | [diff] [blame] | 910 | usage |= DEFAULT_USAGE_FLAGS; |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame] | 911 | return mBufferQueue->setConsumerUsageBits(usage); |
| 912 | } |
| 913 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 914 | status_t GLConsumer::setTransformHint(uint32_t hint) { |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame] | 915 | Mutex::Autolock lock(mMutex); |
| 916 | return mBufferQueue->setTransformHint(hint); |
| 917 | } |
| 918 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 919 | // Used for refactoring BufferQueue from GLConsumer |
| 920 | // Should not be in final interface once users of GLConsumer are clean up. |
| 921 | status_t GLConsumer::setSynchronousMode(bool enabled) { |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame] | 922 | Mutex::Autolock lock(mMutex); |
| 923 | return mBufferQueue->setSynchronousMode(enabled); |
| 924 | } |
| 925 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 926 | void GLConsumer::dumpLocked(String8& result, const char* prefix, |
Jamie Gennis | 9fea342 | 2012-08-07 18:03:04 -0700 | [diff] [blame] | 927 | char* buffer, size_t size) const |
Mathias Agopian | 68c7794 | 2011-05-09 19:08:33 -0700 | [diff] [blame] | 928 | { |
Jamie Gennis | 9fea342 | 2012-08-07 18:03:04 -0700 | [diff] [blame] | 929 | snprintf(buffer, size, |
| 930 | "%smTexName=%d mCurrentTexture=%d\n" |
| 931 | "%smCurrentCrop=[%d,%d,%d,%d] mCurrentTransform=%#x\n", |
| 932 | prefix, mTexName, mCurrentTexture, prefix, mCurrentCrop.left, |
| 933 | mCurrentCrop.top, mCurrentCrop.right, mCurrentCrop.bottom, |
| 934 | mCurrentTransform); |
Mathias Agopian | 68c7794 | 2011-05-09 19:08:33 -0700 | [diff] [blame] | 935 | result.append(buffer); |
| 936 | |
Jamie Gennis | 9fea342 | 2012-08-07 18:03:04 -0700 | [diff] [blame] | 937 | ConsumerBase::dumpLocked(result, prefix, buffer, size); |
Mathias Agopian | 68c7794 | 2011-05-09 19:08:33 -0700 | [diff] [blame] | 938 | } |
| 939 | |
Jamie Gennis | f238e28 | 2011-01-09 16:33:17 -0800 | [diff] [blame] | 940 | static void mtxMul(float out[16], const float a[16], const float b[16]) { |
| 941 | out[0] = a[0]*b[0] + a[4]*b[1] + a[8]*b[2] + a[12]*b[3]; |
| 942 | out[1] = a[1]*b[0] + a[5]*b[1] + a[9]*b[2] + a[13]*b[3]; |
| 943 | out[2] = a[2]*b[0] + a[6]*b[1] + a[10]*b[2] + a[14]*b[3]; |
| 944 | out[3] = a[3]*b[0] + a[7]*b[1] + a[11]*b[2] + a[15]*b[3]; |
| 945 | |
| 946 | out[4] = a[0]*b[4] + a[4]*b[5] + a[8]*b[6] + a[12]*b[7]; |
| 947 | out[5] = a[1]*b[4] + a[5]*b[5] + a[9]*b[6] + a[13]*b[7]; |
| 948 | out[6] = a[2]*b[4] + a[6]*b[5] + a[10]*b[6] + a[14]*b[7]; |
| 949 | out[7] = a[3]*b[4] + a[7]*b[5] + a[11]*b[6] + a[15]*b[7]; |
| 950 | |
| 951 | out[8] = a[0]*b[8] + a[4]*b[9] + a[8]*b[10] + a[12]*b[11]; |
| 952 | out[9] = a[1]*b[8] + a[5]*b[9] + a[9]*b[10] + a[13]*b[11]; |
| 953 | out[10] = a[2]*b[8] + a[6]*b[9] + a[10]*b[10] + a[14]*b[11]; |
| 954 | out[11] = a[3]*b[8] + a[7]*b[9] + a[11]*b[10] + a[15]*b[11]; |
| 955 | |
| 956 | out[12] = a[0]*b[12] + a[4]*b[13] + a[8]*b[14] + a[12]*b[15]; |
| 957 | out[13] = a[1]*b[12] + a[5]*b[13] + a[9]*b[14] + a[13]*b[15]; |
| 958 | out[14] = a[2]*b[12] + a[6]*b[13] + a[10]*b[14] + a[14]*b[15]; |
| 959 | out[15] = a[3]*b[12] + a[7]*b[13] + a[11]*b[14] + a[15]*b[15]; |
| 960 | } |
| 961 | |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 962 | }; // namespace android |