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