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 | |
| 17 | #define LOG_TAG "SurfaceTexture" |
Jamie Gennis | e70d8b4 | 2011-01-09 13:24:09 -0800 | [diff] [blame] | 18 | //#define LOG_NDEBUG 0 |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 19 | |
| 20 | #define GL_GLEXT_PROTOTYPES |
| 21 | #define EGL_EGLEXT_PROTOTYPES |
| 22 | |
| 23 | #include <EGL/egl.h> |
| 24 | #include <EGL/eglext.h> |
| 25 | #include <GLES2/gl2.h> |
| 26 | #include <GLES2/gl2ext.h> |
| 27 | |
| 28 | #include <gui/SurfaceTexture.h> |
| 29 | |
| 30 | #include <surfaceflinger/ISurfaceComposer.h> |
| 31 | #include <surfaceflinger/SurfaceComposerClient.h> |
Jamie Gennis | 9a78c90 | 2011-01-12 18:30:40 -0800 | [diff] [blame] | 32 | #include <surfaceflinger/IGraphicBufferAlloc.h> |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 33 | |
| 34 | #include <utils/Log.h> |
| 35 | |
| 36 | namespace android { |
| 37 | |
Jamie Gennis | f238e28 | 2011-01-09 16:33:17 -0800 | [diff] [blame] | 38 | // Transform matrices |
| 39 | static float mtxIdentity[16] = { |
| 40 | 1, 0, 0, 0, |
| 41 | 0, 1, 0, 0, |
| 42 | 0, 0, 1, 0, |
| 43 | 0, 0, 0, 1, |
| 44 | }; |
| 45 | static float mtxFlipH[16] = { |
| 46 | -1, 0, 0, 0, |
| 47 | 0, 1, 0, 0, |
| 48 | 0, 0, 1, 0, |
| 49 | 1, 0, 0, 1, |
| 50 | }; |
| 51 | static float mtxFlipV[16] = { |
| 52 | 1, 0, 0, 0, |
| 53 | 0, -1, 0, 0, |
| 54 | 0, 0, 1, 0, |
| 55 | 0, 1, 0, 1, |
| 56 | }; |
| 57 | static float mtxRot90[16] = { |
| 58 | 0, 1, 0, 0, |
| 59 | -1, 0, 0, 0, |
| 60 | 0, 0, 1, 0, |
| 61 | 1, 0, 0, 1, |
| 62 | }; |
| 63 | static float mtxRot180[16] = { |
| 64 | -1, 0, 0, 0, |
| 65 | 0, -1, 0, 0, |
| 66 | 0, 0, 1, 0, |
| 67 | 1, 1, 0, 1, |
| 68 | }; |
| 69 | static float mtxRot270[16] = { |
| 70 | 0, -1, 0, 0, |
| 71 | 1, 0, 0, 0, |
| 72 | 0, 0, 1, 0, |
| 73 | 0, 1, 0, 1, |
| 74 | }; |
| 75 | |
| 76 | static void mtxMul(float out[16], const float a[16], const float b[16]); |
| 77 | |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 78 | SurfaceTexture::SurfaceTexture(GLuint tex) : |
| 79 | mBufferCount(MIN_BUFFER_SLOTS), mCurrentTexture(INVALID_BUFFER_SLOT), |
Jamie Gennis | f73935b | 2011-02-04 13:46:38 -0800 | [diff] [blame^] | 80 | mCurrentTransform(0), mLastQueued(INVALID_BUFFER_SLOT), |
| 81 | mLastQueuedTransform(0), mNextTransform(0), mTexName(tex) { |
Jamie Gennis | e70d8b4 | 2011-01-09 13:24:09 -0800 | [diff] [blame] | 82 | LOGV("SurfaceTexture::SurfaceTexture"); |
Jamie Gennis | 3461e0f | 2011-01-07 16:05:47 -0800 | [diff] [blame] | 83 | for (int i = 0; i < NUM_BUFFER_SLOTS; i++) { |
| 84 | mSlots[i].mEglImage = EGL_NO_IMAGE_KHR; |
| 85 | mSlots[i].mEglDisplay = EGL_NO_DISPLAY; |
| 86 | mSlots[i].mOwnedByClient = false; |
| 87 | } |
Jamie Gennis | 9a78c90 | 2011-01-12 18:30:40 -0800 | [diff] [blame] | 88 | sp<ISurfaceComposer> composer(ComposerService::getComposerService()); |
| 89 | mGraphicBufferAlloc = composer->createGraphicBufferAlloc(); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | SurfaceTexture::~SurfaceTexture() { |
Jamie Gennis | e70d8b4 | 2011-01-09 13:24:09 -0800 | [diff] [blame] | 93 | LOGV("SurfaceTexture::~SurfaceTexture"); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 94 | freeAllBuffers(); |
| 95 | } |
| 96 | |
| 97 | status_t SurfaceTexture::setBufferCount(int bufferCount) { |
Jamie Gennis | e70d8b4 | 2011-01-09 13:24:09 -0800 | [diff] [blame] | 98 | LOGV("SurfaceTexture::setBufferCount"); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 99 | Mutex::Autolock lock(mMutex); |
| 100 | freeAllBuffers(); |
| 101 | mBufferCount = bufferCount; |
Jamie Gennis | 67eedd7 | 2011-01-09 13:25:39 -0800 | [diff] [blame] | 102 | mCurrentTexture = INVALID_BUFFER_SLOT; |
| 103 | mLastQueued = INVALID_BUFFER_SLOT; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 104 | return OK; |
| 105 | } |
| 106 | |
| 107 | sp<GraphicBuffer> SurfaceTexture::requestBuffer(int buf, |
| 108 | uint32_t w, uint32_t h, uint32_t format, uint32_t usage) { |
Jamie Gennis | e70d8b4 | 2011-01-09 13:24:09 -0800 | [diff] [blame] | 109 | LOGV("SurfaceTexture::requestBuffer"); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 110 | Mutex::Autolock lock(mMutex); |
| 111 | if (buf < 0 || mBufferCount <= buf) { |
| 112 | LOGE("requestBuffer: slot index out of range [0, %d]: %d", |
| 113 | mBufferCount, buf); |
| 114 | return 0; |
| 115 | } |
| 116 | usage |= GraphicBuffer::USAGE_HW_TEXTURE; |
Jamie Gennis | 9a78c90 | 2011-01-12 18:30:40 -0800 | [diff] [blame] | 117 | sp<GraphicBuffer> graphicBuffer( |
| 118 | mGraphicBufferAlloc->createGraphicBuffer(w, h, format, usage)); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 119 | if (graphicBuffer == 0) { |
| 120 | LOGE("requestBuffer: SurfaceComposer::createGraphicBuffer failed"); |
| 121 | } else { |
| 122 | mSlots[buf].mGraphicBuffer = graphicBuffer; |
| 123 | if (mSlots[buf].mEglImage != EGL_NO_IMAGE_KHR) { |
| 124 | eglDestroyImageKHR(mSlots[buf].mEglDisplay, mSlots[buf].mEglImage); |
| 125 | mSlots[buf].mEglImage = EGL_NO_IMAGE_KHR; |
| 126 | mSlots[buf].mEglDisplay = EGL_NO_DISPLAY; |
| 127 | } |
Jamie Gennis | 9a78c90 | 2011-01-12 18:30:40 -0800 | [diff] [blame] | 128 | mAllocdBuffers.add(graphicBuffer); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 129 | } |
| 130 | return graphicBuffer; |
| 131 | } |
| 132 | |
| 133 | status_t SurfaceTexture::dequeueBuffer(int *buf) { |
Jamie Gennis | e70d8b4 | 2011-01-09 13:24:09 -0800 | [diff] [blame] | 134 | LOGV("SurfaceTexture::dequeueBuffer"); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 135 | Mutex::Autolock lock(mMutex); |
| 136 | int found = INVALID_BUFFER_SLOT; |
| 137 | for (int i = 0; i < mBufferCount; i++) { |
Jamie Gennis | 235c424 | 2011-01-11 15:00:09 -0800 | [diff] [blame] | 138 | if (!mSlots[i].mOwnedByClient && i != mCurrentTexture && i != mLastQueued) { |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 139 | mSlots[i].mOwnedByClient = true; |
| 140 | found = i; |
| 141 | break; |
| 142 | } |
| 143 | } |
| 144 | if (found == INVALID_BUFFER_SLOT) { |
| 145 | return -EBUSY; |
| 146 | } |
| 147 | *buf = found; |
| 148 | return OK; |
| 149 | } |
| 150 | |
| 151 | status_t SurfaceTexture::queueBuffer(int buf) { |
Jamie Gennis | e70d8b4 | 2011-01-09 13:24:09 -0800 | [diff] [blame] | 152 | LOGV("SurfaceTexture::queueBuffer"); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 153 | Mutex::Autolock lock(mMutex); |
| 154 | if (buf < 0 || mBufferCount <= buf) { |
| 155 | LOGE("queueBuffer: slot index out of range [0, %d]: %d", |
| 156 | mBufferCount, buf); |
| 157 | return -EINVAL; |
| 158 | } else if (!mSlots[buf].mOwnedByClient) { |
| 159 | LOGE("queueBuffer: slot %d is not owned by the client", buf); |
| 160 | return -EINVAL; |
| 161 | } else if (mSlots[buf].mGraphicBuffer == 0) { |
| 162 | LOGE("queueBuffer: slot %d was enqueued without requesting a buffer", |
| 163 | buf); |
| 164 | return -EINVAL; |
| 165 | } |
| 166 | mSlots[buf].mOwnedByClient = false; |
| 167 | mLastQueued = buf; |
Jamie Gennis | f238e28 | 2011-01-09 16:33:17 -0800 | [diff] [blame] | 168 | mLastQueuedCrop = mNextCrop; |
| 169 | mLastQueuedTransform = mNextTransform; |
Jamie Gennis | c4d4aea | 2011-01-13 14:43:36 -0800 | [diff] [blame] | 170 | if (mFrameAvailableListener != 0) { |
| 171 | mFrameAvailableListener->onFrameAvailable(); |
| 172 | } |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 173 | return OK; |
| 174 | } |
| 175 | |
| 176 | void SurfaceTexture::cancelBuffer(int buf) { |
Jamie Gennis | e70d8b4 | 2011-01-09 13:24:09 -0800 | [diff] [blame] | 177 | LOGV("SurfaceTexture::cancelBuffer"); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 178 | Mutex::Autolock lock(mMutex); |
| 179 | if (buf < 0 || mBufferCount <= buf) { |
| 180 | LOGE("cancelBuffer: slot index out of range [0, %d]: %d", mBufferCount, |
| 181 | buf); |
| 182 | return; |
| 183 | } else if (!mSlots[buf].mOwnedByClient) { |
| 184 | LOGE("cancelBuffer: slot %d is not owned by the client", buf); |
| 185 | return; |
| 186 | } |
| 187 | mSlots[buf].mOwnedByClient = false; |
| 188 | } |
| 189 | |
Jamie Gennis | f238e28 | 2011-01-09 16:33:17 -0800 | [diff] [blame] | 190 | status_t SurfaceTexture::setCrop(const Rect& crop) { |
Jamie Gennis | e70d8b4 | 2011-01-09 13:24:09 -0800 | [diff] [blame] | 191 | LOGV("SurfaceTexture::setCrop"); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 192 | Mutex::Autolock lock(mMutex); |
Jamie Gennis | f238e28 | 2011-01-09 16:33:17 -0800 | [diff] [blame] | 193 | mNextCrop = crop; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 194 | return OK; |
| 195 | } |
| 196 | |
| 197 | status_t SurfaceTexture::setTransform(uint32_t transform) { |
Jamie Gennis | e70d8b4 | 2011-01-09 13:24:09 -0800 | [diff] [blame] | 198 | LOGV("SurfaceTexture::setTransform"); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 199 | Mutex::Autolock lock(mMutex); |
Jamie Gennis | f238e28 | 2011-01-09 16:33:17 -0800 | [diff] [blame] | 200 | mNextTransform = transform; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 201 | return OK; |
| 202 | } |
| 203 | |
| 204 | status_t SurfaceTexture::updateTexImage() { |
Jamie Gennis | e70d8b4 | 2011-01-09 13:24:09 -0800 | [diff] [blame] | 205 | LOGV("SurfaceTexture::updateTexImage"); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 206 | Mutex::Autolock lock(mMutex); |
| 207 | |
| 208 | // We always bind the texture even if we don't update its contents. |
| 209 | glBindTexture(GL_TEXTURE_EXTERNAL_OES, mTexName); |
| 210 | |
| 211 | // Initially both mCurrentTexture and mLastQueued are INVALID_BUFFER_SLOT, |
| 212 | // so this check will fail until a buffer gets queued. |
| 213 | if (mCurrentTexture != mLastQueued) { |
Jamie Gennis | f238e28 | 2011-01-09 16:33:17 -0800 | [diff] [blame] | 214 | // Update the GL texture object. |
Jamie Gennis | 9a78c90 | 2011-01-12 18:30:40 -0800 | [diff] [blame] | 215 | EGLImageKHR image = mSlots[mLastQueued].mEglImage; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 216 | if (image == EGL_NO_IMAGE_KHR) { |
| 217 | EGLDisplay dpy = eglGetCurrentDisplay(); |
Jamie Gennis | 9a78c90 | 2011-01-12 18:30:40 -0800 | [diff] [blame] | 218 | sp<GraphicBuffer> graphicBuffer = mSlots[mLastQueued].mGraphicBuffer; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 219 | image = createImage(dpy, graphicBuffer); |
Jamie Gennis | 9a78c90 | 2011-01-12 18:30:40 -0800 | [diff] [blame] | 220 | mSlots[mLastQueued].mEglImage = image; |
| 221 | mSlots[mLastQueued].mEglDisplay = dpy; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 222 | } |
| 223 | glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, (GLeglImageOES)image); |
| 224 | GLint error = glGetError(); |
| 225 | if (error != GL_NO_ERROR) { |
| 226 | LOGE("error binding external texture image %p (slot %d): %#04x", |
Jamie Gennis | 9a78c90 | 2011-01-12 18:30:40 -0800 | [diff] [blame] | 227 | image, mLastQueued, error); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 228 | return -EINVAL; |
| 229 | } |
Jamie Gennis | 9a78c90 | 2011-01-12 18:30:40 -0800 | [diff] [blame] | 230 | |
| 231 | // Update the SurfaceTexture state. |
| 232 | mCurrentTexture = mLastQueued; |
| 233 | mCurrentTextureBuf = mSlots[mCurrentTexture].mGraphicBuffer; |
| 234 | mCurrentCrop = mLastQueuedCrop; |
| 235 | mCurrentTransform = mLastQueuedTransform; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 236 | } |
| 237 | return OK; |
| 238 | } |
| 239 | |
Jamie Gennis | f238e28 | 2011-01-09 16:33:17 -0800 | [diff] [blame] | 240 | void SurfaceTexture::getTransformMatrix(float mtx[16]) { |
| 241 | LOGV("SurfaceTexture::updateTexImage"); |
| 242 | Mutex::Autolock lock(mMutex); |
| 243 | |
Jamie Gennis | a214c64 | 2011-01-14 13:53:31 -0800 | [diff] [blame] | 244 | float xform[16]; |
| 245 | for (int i = 0; i < 16; i++) { |
| 246 | xform[i] = mtxIdentity[i]; |
| 247 | } |
| 248 | if (mCurrentTransform & NATIVE_WINDOW_TRANSFORM_FLIP_H) { |
| 249 | float result[16]; |
| 250 | mtxMul(result, xform, mtxFlipH); |
| 251 | for (int i = 0; i < 16; i++) { |
| 252 | xform[i] = result[i]; |
| 253 | } |
| 254 | } |
| 255 | if (mCurrentTransform & NATIVE_WINDOW_TRANSFORM_FLIP_V) { |
| 256 | float result[16]; |
| 257 | mtxMul(result, xform, mtxFlipV); |
| 258 | for (int i = 0; i < 16; i++) { |
| 259 | xform[i] = result[i]; |
| 260 | } |
| 261 | } |
| 262 | if (mCurrentTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) { |
| 263 | float result[16]; |
| 264 | mtxMul(result, xform, mtxRot90); |
| 265 | for (int i = 0; i < 16; i++) { |
| 266 | xform[i] = result[i]; |
| 267 | } |
Jamie Gennis | f238e28 | 2011-01-09 16:33:17 -0800 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | sp<GraphicBuffer>& buf(mSlots[mCurrentTexture].mGraphicBuffer); |
Jamie Gennis | a214c64 | 2011-01-14 13:53:31 -0800 | [diff] [blame] | 271 | float tx, ty, sx, sy; |
| 272 | if (!mCurrentCrop.isEmpty()) { |
| 273 | tx = float(mCurrentCrop.left) / float(buf->getWidth()); |
| 274 | ty = float(buf->getHeight() - mCurrentCrop.bottom) / |
| 275 | float(buf->getHeight()); |
| 276 | sx = float(mCurrentCrop.width()) / float(buf->getWidth()); |
| 277 | sy = float(mCurrentCrop.height()) / float(buf->getHeight()); |
| 278 | } else { |
| 279 | tx = 0.0f; |
| 280 | ty = 0.0f; |
| 281 | sx = 1.0f; |
| 282 | sy = 1.0f; |
| 283 | } |
Jamie Gennis | f238e28 | 2011-01-09 16:33:17 -0800 | [diff] [blame] | 284 | float crop[16] = { |
Jamie Gennis | a214c64 | 2011-01-14 13:53:31 -0800 | [diff] [blame] | 285 | sx, 0, 0, 0, |
| 286 | 0, sy, 0, 0, |
Jamie Gennis | f238e28 | 2011-01-09 16:33:17 -0800 | [diff] [blame] | 287 | 0, 0, 1, 0, |
Jamie Gennis | a214c64 | 2011-01-14 13:53:31 -0800 | [diff] [blame] | 288 | sx*tx, sy*ty, 0, 1, |
Jamie Gennis | f238e28 | 2011-01-09 16:33:17 -0800 | [diff] [blame] | 289 | }; |
| 290 | |
Jamie Gennis | a214c64 | 2011-01-14 13:53:31 -0800 | [diff] [blame] | 291 | float mtxBeforeFlipV[16]; |
| 292 | mtxMul(mtxBeforeFlipV, crop, xform); |
| 293 | |
| 294 | // SurfaceFlinger expects the top of its window textures to be at a Y |
| 295 | // coordinate of 0, so SurfaceTexture must behave the same way. We don't |
| 296 | // want to expose this to applications, however, so we must add an |
| 297 | // additional vertical flip to the transform after all the other transforms. |
| 298 | mtxMul(mtx, mtxFlipV, mtxBeforeFlipV); |
Jamie Gennis | f238e28 | 2011-01-09 16:33:17 -0800 | [diff] [blame] | 299 | } |
| 300 | |
Jamie Gennis | c4d4aea | 2011-01-13 14:43:36 -0800 | [diff] [blame] | 301 | void SurfaceTexture::setFrameAvailableListener( |
| 302 | const sp<FrameAvailableListener>& l) { |
| 303 | LOGV("SurfaceTexture::setFrameAvailableListener"); |
| 304 | Mutex::Autolock lock(mMutex); |
| 305 | mFrameAvailableListener = l; |
| 306 | } |
| 307 | |
Jamie Gennis | 1b20cde | 2011-02-02 15:31:47 -0800 | [diff] [blame] | 308 | sp<IBinder> SurfaceTexture::getAllocator() { |
| 309 | LOGV("SurfaceTexture::getAllocator"); |
| 310 | return mGraphicBufferAlloc->asBinder(); |
| 311 | } |
| 312 | |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 313 | void SurfaceTexture::freeAllBuffers() { |
| 314 | for (int i = 0; i < NUM_BUFFER_SLOTS; i++) { |
| 315 | mSlots[i].mGraphicBuffer = 0; |
| 316 | mSlots[i].mOwnedByClient = false; |
| 317 | if (mSlots[i].mEglImage != EGL_NO_IMAGE_KHR) { |
| 318 | eglDestroyImageKHR(mSlots[i].mEglDisplay, mSlots[i].mEglImage); |
| 319 | mSlots[i].mEglImage = EGL_NO_IMAGE_KHR; |
| 320 | mSlots[i].mEglDisplay = EGL_NO_DISPLAY; |
| 321 | } |
| 322 | } |
Jamie Gennis | 9a78c90 | 2011-01-12 18:30:40 -0800 | [diff] [blame] | 323 | |
| 324 | int exceptBuf = -1; |
| 325 | for (size_t i = 0; i < mAllocdBuffers.size(); i++) { |
| 326 | if (mAllocdBuffers[i] == mCurrentTextureBuf) { |
| 327 | exceptBuf = i; |
| 328 | break; |
| 329 | } |
| 330 | } |
| 331 | mAllocdBuffers.clear(); |
| 332 | if (exceptBuf >= 0) { |
| 333 | mAllocdBuffers.add(mCurrentTextureBuf); |
| 334 | } |
| 335 | mGraphicBufferAlloc->freeAllGraphicBuffersExcept(exceptBuf); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | EGLImageKHR SurfaceTexture::createImage(EGLDisplay dpy, |
| 339 | const sp<GraphicBuffer>& graphicBuffer) { |
| 340 | EGLClientBuffer cbuf = (EGLClientBuffer)graphicBuffer->getNativeBuffer(); |
| 341 | EGLint attrs[] = { |
| 342 | EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, |
| 343 | EGL_NONE, |
| 344 | }; |
| 345 | EGLImageKHR image = eglCreateImageKHR(dpy, EGL_NO_CONTEXT, |
| 346 | EGL_NATIVE_BUFFER_ANDROID, cbuf, attrs); |
| 347 | EGLint error = eglGetError(); |
| 348 | if (error != EGL_SUCCESS) { |
| 349 | LOGE("error creating EGLImage: %#x", error); |
| 350 | } else if (image == EGL_NO_IMAGE_KHR) { |
| 351 | LOGE("no error reported, but no image was returned by " |
| 352 | "eglCreateImageKHR"); |
| 353 | } |
| 354 | return image; |
| 355 | } |
| 356 | |
Jamie Gennis | f238e28 | 2011-01-09 16:33:17 -0800 | [diff] [blame] | 357 | static void mtxMul(float out[16], const float a[16], const float b[16]) { |
| 358 | out[0] = a[0]*b[0] + a[4]*b[1] + a[8]*b[2] + a[12]*b[3]; |
| 359 | out[1] = a[1]*b[0] + a[5]*b[1] + a[9]*b[2] + a[13]*b[3]; |
| 360 | out[2] = a[2]*b[0] + a[6]*b[1] + a[10]*b[2] + a[14]*b[3]; |
| 361 | out[3] = a[3]*b[0] + a[7]*b[1] + a[11]*b[2] + a[15]*b[3]; |
| 362 | |
| 363 | out[4] = a[0]*b[4] + a[4]*b[5] + a[8]*b[6] + a[12]*b[7]; |
| 364 | out[5] = a[1]*b[4] + a[5]*b[5] + a[9]*b[6] + a[13]*b[7]; |
| 365 | out[6] = a[2]*b[4] + a[6]*b[5] + a[10]*b[6] + a[14]*b[7]; |
| 366 | out[7] = a[3]*b[4] + a[7]*b[5] + a[11]*b[6] + a[15]*b[7]; |
| 367 | |
| 368 | out[8] = a[0]*b[8] + a[4]*b[9] + a[8]*b[10] + a[12]*b[11]; |
| 369 | out[9] = a[1]*b[8] + a[5]*b[9] + a[9]*b[10] + a[13]*b[11]; |
| 370 | out[10] = a[2]*b[8] + a[6]*b[9] + a[10]*b[10] + a[14]*b[11]; |
| 371 | out[11] = a[3]*b[8] + a[7]*b[9] + a[11]*b[10] + a[15]*b[11]; |
| 372 | |
| 373 | out[12] = a[0]*b[12] + a[4]*b[13] + a[8]*b[14] + a[12]*b[15]; |
| 374 | out[13] = a[1]*b[12] + a[5]*b[13] + a[9]*b[14] + a[13]*b[15]; |
| 375 | out[14] = a[2]*b[12] + a[6]*b[13] + a[10]*b[14] + a[14]*b[15]; |
| 376 | out[15] = a[3]*b[12] + a[7]*b[13] + a[11]*b[14] + a[15]*b[15]; |
| 377 | } |
| 378 | |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 379 | }; // namespace android |