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 | 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 | |
Mathias Agopian | 7a042bf | 2011-04-11 21:19:55 -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> |
| 34 | #include <gui/SurfaceTexture.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 | |
Jamie Gennis | 86edf4f | 2011-11-14 14:51:01 -0800 | [diff] [blame] | 42 | // This compile option makes SurfaceTexture use the EGL_KHR_fence_sync extension |
| 43 | // to synchronize access to the buffers. It will cause dequeueBuffer to stall, |
| 44 | // waiting for the GL reads for the buffer being dequeued to complete before |
| 45 | // allowing the buffer to be dequeued. |
| 46 | #ifdef USE_FENCE_SYNC |
| 47 | #ifdef ALLOW_DEQUEUE_CURRENT_BUFFER |
| 48 | #error "USE_FENCE_SYNC and ALLOW_DEQUEUE_CURRENT_BUFFER are incompatible" |
| 49 | #endif |
| 50 | #endif |
| 51 | |
Jamie Gennis | fa28c35 | 2011-09-16 17:30:26 -0700 | [diff] [blame] | 52 | // Macros for including the SurfaceTexture name in log messages |
Steve Block | 6807e59 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 53 | #define ST_LOGV(x, ...) ALOGV("[%s] "x, mName.string(), ##__VA_ARGS__) |
Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 54 | #define ST_LOGD(x, ...) ALOGD("[%s] "x, mName.string(), ##__VA_ARGS__) |
Steve Block | a19954a | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 55 | #define ST_LOGI(x, ...) ALOGI("[%s] "x, mName.string(), ##__VA_ARGS__) |
Steve Block | 32397c1 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 56 | #define ST_LOGW(x, ...) ALOGW("[%s] "x, mName.string(), ##__VA_ARGS__) |
Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 57 | #define ST_LOGE(x, ...) ALOGE("[%s] "x, mName.string(), ##__VA_ARGS__) |
Mathias Agopian | 29b5762 | 2011-08-17 15:42:04 -0700 | [diff] [blame] | 58 | |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 59 | namespace android { |
| 60 | |
Jamie Gennis | f238e28 | 2011-01-09 16:33:17 -0800 | [diff] [blame] | 61 | // Transform matrices |
| 62 | static float mtxIdentity[16] = { |
| 63 | 1, 0, 0, 0, |
| 64 | 0, 1, 0, 0, |
| 65 | 0, 0, 1, 0, |
| 66 | 0, 0, 0, 1, |
| 67 | }; |
| 68 | static float mtxFlipH[16] = { |
| 69 | -1, 0, 0, 0, |
| 70 | 0, 1, 0, 0, |
| 71 | 0, 0, 1, 0, |
| 72 | 1, 0, 0, 1, |
| 73 | }; |
| 74 | static float mtxFlipV[16] = { |
| 75 | 1, 0, 0, 0, |
| 76 | 0, -1, 0, 0, |
| 77 | 0, 0, 1, 0, |
| 78 | 0, 1, 0, 1, |
| 79 | }; |
| 80 | static float mtxRot90[16] = { |
| 81 | 0, 1, 0, 0, |
| 82 | -1, 0, 0, 0, |
| 83 | 0, 0, 1, 0, |
| 84 | 1, 0, 0, 1, |
| 85 | }; |
| 86 | static float mtxRot180[16] = { |
| 87 | -1, 0, 0, 0, |
| 88 | 0, -1, 0, 0, |
| 89 | 0, 0, 1, 0, |
| 90 | 1, 1, 0, 1, |
| 91 | }; |
| 92 | static float mtxRot270[16] = { |
| 93 | 0, -1, 0, 0, |
| 94 | 1, 0, 0, 0, |
| 95 | 0, 0, 1, 0, |
| 96 | 0, 1, 0, 1, |
| 97 | }; |
| 98 | |
| 99 | static void mtxMul(float out[16], const float a[16], const float b[16]); |
| 100 | |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 101 | // Get an ID that's unique within this process. |
| 102 | static int32_t createProcessUniqueId() { |
| 103 | static volatile int32_t globalCounter = 0; |
| 104 | return android_atomic_inc(&globalCounter); |
| 105 | } |
Jamie Gennis | fa28c35 | 2011-09-16 17:30:26 -0700 | [diff] [blame] | 106 | |
Jamie Gennis | fb1b5a2 | 2011-09-28 12:13:31 -0700 | [diff] [blame] | 107 | SurfaceTexture::SurfaceTexture(GLuint tex, bool allowSynchronousMode, |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame] | 108 | GLenum texTarget, bool useFenceSync, const sp<BufferQueue> &bufferQueue) : |
Eino-Ville Talvala | 1d01a12 | 2011-02-18 11:02:42 -0800 | [diff] [blame] | 109 | mCurrentTransform(0), |
| 110 | mCurrentTimestamp(0), |
Mathias Agopian | b3e518c | 2011-04-21 18:52:51 -0700 | [diff] [blame] | 111 | mTexName(tex), |
Jamie Gennis | 86edf4f | 2011-11-14 14:51:01 -0800 | [diff] [blame] | 112 | #ifdef USE_FENCE_SYNC |
| 113 | mUseFenceSync(useFenceSync), |
| 114 | #else |
| 115 | mUseFenceSync(false), |
| 116 | #endif |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 117 | mTexTarget(texTarget), |
| 118 | mAbandoned(false), |
| 119 | mCurrentTexture(BufferQueue::INVALID_BUFFER_SLOT) |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 120 | { |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 121 | // Choose a name using the PID and a process-unique ID. |
| 122 | mName = String8::format("unnamed-%d-%d", getpid(), createProcessUniqueId()); |
Jamie Gennis | 6ee96ad | 2011-10-19 13:36:31 -0700 | [diff] [blame] | 123 | ST_LOGV("SurfaceTexture"); |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame] | 124 | if (bufferQueue == 0) { |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame] | 125 | ST_LOGV("Creating a new BufferQueue"); |
| 126 | mBufferQueue = new BufferQueue(allowSynchronousMode); |
| 127 | } |
| 128 | else { |
| 129 | mBufferQueue = bufferQueue; |
| 130 | } |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame] | 131 | |
Jamie Gennis | fa28c35 | 2011-09-16 17:30:26 -0700 | [diff] [blame] | 132 | memcpy(mCurrentTransformMatrix, mtxIdentity, |
| 133 | sizeof(mCurrentTransformMatrix)); |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame^] | 134 | |
| 135 | // Note that we can't create an sp<...>(this) in a ctor that will not keep a |
| 136 | // reference once the ctor ends, as that would cause the refcount of 'this' |
| 137 | // dropping to 0 at the end of the ctor. Since all we need is a wp<...> |
| 138 | // that's what we create. |
| 139 | wp<BufferQueue::ConsumerListener> listener; |
| 140 | sp<BufferQueue::ConsumerListener> proxy; |
| 141 | listener = static_cast<BufferQueue::ConsumerListener*>(this); |
| 142 | proxy = new BufferQueue::ProxyConsumerListener(listener); |
| 143 | |
| 144 | status_t err = mBufferQueue->consumerConnect(proxy); |
| 145 | if (err != NO_ERROR) { |
| 146 | ST_LOGE("SurfaceTexture: error connecting to BufferQueue: %s (%d)", |
| 147 | strerror(-err), err); |
| 148 | } else { |
| 149 | mBufferQueue->setConsumerName(mName); |
| 150 | } |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | SurfaceTexture::~SurfaceTexture() { |
Jamie Gennis | 6ee96ad | 2011-10-19 13:36:31 -0700 | [diff] [blame] | 154 | ST_LOGV("~SurfaceTexture"); |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame] | 155 | |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 156 | abandon(); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 157 | } |
| 158 | |
Mathias Agopian | 8072711 | 2011-05-02 19:51:12 -0700 | [diff] [blame] | 159 | status_t SurfaceTexture::setBufferCountServer(int bufferCount) { |
| 160 | Mutex::Autolock lock(mMutex); |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame] | 161 | return mBufferQueue->setBufferCountServer(bufferCount); |
Mathias Agopian | 8072711 | 2011-05-02 19:51:12 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 164 | |
Mathias Agopian | a5c75c0 | 2011-03-31 19:10:24 -0700 | [diff] [blame] | 165 | status_t SurfaceTexture::setDefaultBufferSize(uint32_t w, uint32_t h) |
| 166 | { |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame] | 167 | Mutex::Autolock lock(mMutex); |
| 168 | return mBufferQueue->setDefaultBufferSize(w, h); |
Mathias Agopian | a5c75c0 | 2011-03-31 19:10:24 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 171 | status_t SurfaceTexture::updateTexImage() { |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 172 | ATRACE_CALL(); |
Jamie Gennis | 6ee96ad | 2011-10-19 13:36:31 -0700 | [diff] [blame] | 173 | ST_LOGV("updateTexImage"); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 174 | Mutex::Autolock lock(mMutex); |
| 175 | |
Mathias Agopian | e47498f | 2011-08-08 19:35:15 -0700 | [diff] [blame] | 176 | if (mAbandoned) { |
Jamie Gennis | fa28c35 | 2011-09-16 17:30:26 -0700 | [diff] [blame] | 177 | ST_LOGE("calling updateTexImage() on an abandoned SurfaceTexture"); |
Mathias Agopian | 8e19c2e | 2011-08-10 17:35:09 -0700 | [diff] [blame] | 178 | return NO_INIT; |
Mathias Agopian | e47498f | 2011-08-08 19:35:15 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame] | 181 | BufferQueue::BufferItem item; |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 182 | |
Jamie Gennis | 50c4efc | 2011-06-27 15:41:52 -0700 | [diff] [blame] | 183 | // In asynchronous mode the list is guaranteed to be one buffer |
| 184 | // deep, while in synchronous mode we use the oldest buffer. |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame^] | 185 | if (mBufferQueue->acquireBuffer(&item) == NO_ERROR) { |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 186 | int buf = item.mBuf; |
| 187 | // This buffer was newly allocated, so we need to clean up on our side |
| 188 | if (item.mGraphicBuffer != NULL) { |
| 189 | mEGLSlots[buf].mGraphicBuffer = 0; |
| 190 | if (mEGLSlots[buf].mEglImage != EGL_NO_IMAGE_KHR) { |
| 191 | eglDestroyImageKHR(mEGLSlots[buf].mEglDisplay, |
| 192 | mEGLSlots[buf].mEglImage); |
| 193 | mEGLSlots[buf].mEglImage = EGL_NO_IMAGE_KHR; |
| 194 | mEGLSlots[buf].mEglDisplay = EGL_NO_DISPLAY; |
| 195 | } |
| 196 | mEGLSlots[buf].mGraphicBuffer = item.mGraphicBuffer; |
| 197 | } |
Mathias Agopian | b3e518c | 2011-04-21 18:52:51 -0700 | [diff] [blame] | 198 | |
Jamie Gennis | f238e28 | 2011-01-09 16:33:17 -0800 | [diff] [blame] | 199 | // Update the GL texture object. |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 200 | EGLImageKHR image = mEGLSlots[buf].mEglImage; |
Jamie Gennis | 86edf4f | 2011-11-14 14:51:01 -0800 | [diff] [blame] | 201 | EGLDisplay dpy = eglGetCurrentDisplay(); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 202 | if (image == EGL_NO_IMAGE_KHR) { |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 203 | if (item.mGraphicBuffer == 0) { |
Jamie Gennis | fa28c35 | 2011-09-16 17:30:26 -0700 | [diff] [blame] | 204 | ST_LOGE("buffer at slot %d is null", buf); |
Mathias Agopian | 8e19c2e | 2011-08-10 17:35:09 -0700 | [diff] [blame] | 205 | return BAD_VALUE; |
Mathias Agopian | e47498f | 2011-08-08 19:35:15 -0700 | [diff] [blame] | 206 | } |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 207 | image = createImage(dpy, item.mGraphicBuffer); |
| 208 | mEGLSlots[buf].mEglImage = image; |
| 209 | mEGLSlots[buf].mEglDisplay = dpy; |
Mathias Agopian | 3cd5a11 | 2011-04-26 14:57:40 -0700 | [diff] [blame] | 210 | if (image == EGL_NO_IMAGE_KHR) { |
| 211 | // NOTE: if dpy was invalid, createImage() is guaranteed to |
| 212 | // fail. so we'd end up here. |
| 213 | return -EINVAL; |
| 214 | } |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 215 | } |
Jamie Gennis | 0eb8851 | 2011-01-26 11:52:02 -0800 | [diff] [blame] | 216 | |
| 217 | GLint error; |
| 218 | while ((error = glGetError()) != GL_NO_ERROR) { |
Jamie Gennis | fa28c35 | 2011-09-16 17:30:26 -0700 | [diff] [blame] | 219 | ST_LOGW("updateTexImage: clearing GL error: %#04x", error); |
Jamie Gennis | 0eb8851 | 2011-01-26 11:52:02 -0800 | [diff] [blame] | 220 | } |
Mathias Agopian | 7a042bf | 2011-04-11 21:19:55 -0700 | [diff] [blame] | 221 | |
Jamie Gennis | fb1b5a2 | 2011-09-28 12:13:31 -0700 | [diff] [blame] | 222 | glBindTexture(mTexTarget, mTexName); |
| 223 | glEGLImageTargetTexture2DOES(mTexTarget, (GLeglImageOES)image); |
Mathias Agopian | 7a042bf | 2011-04-11 21:19:55 -0700 | [diff] [blame] | 224 | |
Jamie Gennis | 0eb8851 | 2011-01-26 11:52:02 -0800 | [diff] [blame] | 225 | bool failed = false; |
| 226 | while ((error = glGetError()) != GL_NO_ERROR) { |
Jamie Gennis | fa28c35 | 2011-09-16 17:30:26 -0700 | [diff] [blame] | 227 | ST_LOGE("error binding external texture image %p (slot %d): %#04x", |
Mathias Agopian | b3e518c | 2011-04-21 18:52:51 -0700 | [diff] [blame] | 228 | image, buf, error); |
Jamie Gennis | 0eb8851 | 2011-01-26 11:52:02 -0800 | [diff] [blame] | 229 | failed = true; |
| 230 | } |
| 231 | if (failed) { |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame] | 232 | mBufferQueue->releaseBuffer(buf, mEGLSlots[buf].mEglDisplay, |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 233 | mEGLSlots[buf].mFence); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 234 | return -EINVAL; |
| 235 | } |
Jamie Gennis | 9a78c90 | 2011-01-12 18:30:40 -0800 | [diff] [blame] | 236 | |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame] | 237 | if (mCurrentTexture != BufferQueue::INVALID_BUFFER_SLOT) { |
Jamie Gennis | 86edf4f | 2011-11-14 14:51:01 -0800 | [diff] [blame] | 238 | if (mUseFenceSync) { |
| 239 | EGLSyncKHR fence = eglCreateSyncKHR(dpy, EGL_SYNC_FENCE_KHR, |
| 240 | NULL); |
| 241 | if (fence == EGL_NO_SYNC_KHR) { |
Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 242 | ALOGE("updateTexImage: error creating fence: %#x", |
Jamie Gennis | 86edf4f | 2011-11-14 14:51:01 -0800 | [diff] [blame] | 243 | eglGetError()); |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame] | 244 | mBufferQueue->releaseBuffer(buf, mEGLSlots[buf].mEglDisplay, |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 245 | mEGLSlots[buf].mFence); |
Jamie Gennis | 86edf4f | 2011-11-14 14:51:01 -0800 | [diff] [blame] | 246 | return -EINVAL; |
| 247 | } |
| 248 | glFlush(); |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 249 | mEGLSlots[mCurrentTexture].mFence = fence; |
Jamie Gennis | 86edf4f | 2011-11-14 14:51:01 -0800 | [diff] [blame] | 250 | } |
| 251 | } |
| 252 | |
| 253 | ST_LOGV("updateTexImage: (slot=%d buf=%p) -> (slot=%d buf=%p)", |
| 254 | mCurrentTexture, |
| 255 | mCurrentTextureBuf != NULL ? mCurrentTextureBuf->handle : 0, |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 256 | buf, item.mGraphicBuffer != NULL ? item.mGraphicBuffer->handle : 0); |
Jamie Gennis | 6ee96ad | 2011-10-19 13:36:31 -0700 | [diff] [blame] | 257 | |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 258 | // release old buffer |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame] | 259 | mBufferQueue->releaseBuffer(mCurrentTexture, |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 260 | mEGLSlots[mCurrentTexture].mEglDisplay, |
| 261 | mEGLSlots[mCurrentTexture].mFence); |
Mathias Agopian | b3e518c | 2011-04-21 18:52:51 -0700 | [diff] [blame] | 262 | |
Jamie Gennis | 9a78c90 | 2011-01-12 18:30:40 -0800 | [diff] [blame] | 263 | // Update the SurfaceTexture state. |
Mathias Agopian | b3e518c | 2011-04-21 18:52:51 -0700 | [diff] [blame] | 264 | mCurrentTexture = buf; |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 265 | mCurrentTextureBuf = mEGLSlots[buf].mGraphicBuffer; |
| 266 | mCurrentCrop = item.mCrop; |
| 267 | mCurrentTransform = item.mTransform; |
| 268 | mCurrentScalingMode = item.mScalingMode; |
| 269 | mCurrentTimestamp = item.mTimestamp; |
Jamie Gennis | 736aa95 | 2011-06-12 17:03:06 -0700 | [diff] [blame] | 270 | computeCurrentTransformMatrix(); |
Jamie Gennis | 50c4efc | 2011-06-27 15:41:52 -0700 | [diff] [blame] | 271 | |
| 272 | // Now that we've passed the point at which failures can happen, |
| 273 | // it's safe to remove the buffer from the front of the queue. |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 274 | |
Mathias Agopian | 7a042bf | 2011-04-11 21:19:55 -0700 | [diff] [blame] | 275 | } else { |
| 276 | // We always bind the texture even if we don't update its contents. |
Jamie Gennis | fb1b5a2 | 2011-09-28 12:13:31 -0700 | [diff] [blame] | 277 | glBindTexture(mTexTarget, mTexName); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 278 | } |
Jamie Gennis | 50c4efc | 2011-06-27 15:41:52 -0700 | [diff] [blame] | 279 | |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 280 | return OK; |
| 281 | } |
| 282 | |
Mathias Agopian | 7a042bf | 2011-04-11 21:19:55 -0700 | [diff] [blame] | 283 | bool SurfaceTexture::isExternalFormat(uint32_t format) |
| 284 | { |
| 285 | switch (format) { |
| 286 | // supported YUV formats |
| 287 | case HAL_PIXEL_FORMAT_YV12: |
| 288 | // Legacy/deprecated YUV formats |
| 289 | case HAL_PIXEL_FORMAT_YCbCr_422_SP: |
| 290 | case HAL_PIXEL_FORMAT_YCrCb_420_SP: |
| 291 | case HAL_PIXEL_FORMAT_YCbCr_422_I: |
| 292 | return true; |
| 293 | } |
| 294 | |
| 295 | // Any OEM format needs to be considered |
| 296 | if (format>=0x100 && format<=0x1FF) |
| 297 | return true; |
| 298 | |
| 299 | return false; |
| 300 | } |
| 301 | |
Mathias Agopian | 7a042bf | 2011-04-11 21:19:55 -0700 | [diff] [blame] | 302 | GLenum SurfaceTexture::getCurrentTextureTarget() const { |
Jamie Gennis | fb1b5a2 | 2011-09-28 12:13:31 -0700 | [diff] [blame] | 303 | return mTexTarget; |
Mathias Agopian | 7a042bf | 2011-04-11 21:19:55 -0700 | [diff] [blame] | 304 | } |
| 305 | |
Jamie Gennis | f238e28 | 2011-01-09 16:33:17 -0800 | [diff] [blame] | 306 | void SurfaceTexture::getTransformMatrix(float mtx[16]) { |
Jamie Gennis | f238e28 | 2011-01-09 16:33:17 -0800 | [diff] [blame] | 307 | Mutex::Autolock lock(mMutex); |
Jamie Gennis | 736aa95 | 2011-06-12 17:03:06 -0700 | [diff] [blame] | 308 | memcpy(mtx, mCurrentTransformMatrix, sizeof(mCurrentTransformMatrix)); |
| 309 | } |
| 310 | |
| 311 | void SurfaceTexture::computeCurrentTransformMatrix() { |
Jamie Gennis | 6ee96ad | 2011-10-19 13:36:31 -0700 | [diff] [blame] | 312 | ST_LOGV("computeCurrentTransformMatrix"); |
Jamie Gennis | f238e28 | 2011-01-09 16:33:17 -0800 | [diff] [blame] | 313 | |
Jamie Gennis | a214c64 | 2011-01-14 13:53:31 -0800 | [diff] [blame] | 314 | float xform[16]; |
| 315 | for (int i = 0; i < 16; i++) { |
| 316 | xform[i] = mtxIdentity[i]; |
| 317 | } |
| 318 | if (mCurrentTransform & NATIVE_WINDOW_TRANSFORM_FLIP_H) { |
| 319 | float result[16]; |
| 320 | mtxMul(result, xform, mtxFlipH); |
| 321 | for (int i = 0; i < 16; i++) { |
| 322 | xform[i] = result[i]; |
| 323 | } |
| 324 | } |
| 325 | if (mCurrentTransform & NATIVE_WINDOW_TRANSFORM_FLIP_V) { |
| 326 | float result[16]; |
| 327 | mtxMul(result, xform, mtxFlipV); |
| 328 | for (int i = 0; i < 16; i++) { |
| 329 | xform[i] = result[i]; |
| 330 | } |
| 331 | } |
| 332 | if (mCurrentTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) { |
| 333 | float result[16]; |
| 334 | mtxMul(result, xform, mtxRot90); |
| 335 | for (int i = 0; i < 16; i++) { |
| 336 | xform[i] = result[i]; |
| 337 | } |
Jamie Gennis | f238e28 | 2011-01-09 16:33:17 -0800 | [diff] [blame] | 338 | } |
| 339 | |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 340 | sp<GraphicBuffer>& buf(mCurrentTextureBuf); |
Jamie Gennis | a214c64 | 2011-01-14 13:53:31 -0800 | [diff] [blame] | 341 | float tx, ty, sx, sy; |
| 342 | if (!mCurrentCrop.isEmpty()) { |
Jamie Gennis | d99c088 | 2011-03-10 16:24:46 -0800 | [diff] [blame] | 343 | // In order to prevent bilinear sampling at the of the crop rectangle we |
| 344 | // may need to shrink it by 2 texels in each direction. Normally this |
| 345 | // would just need to take 1/2 a texel off each end, but because the |
| 346 | // chroma channels will likely be subsampled we need to chop off a whole |
| 347 | // texel. This will cause artifacts if someone does nearest sampling |
| 348 | // with 1:1 pixel:texel ratio, but it's impossible to simultaneously |
| 349 | // accomodate the bilinear and nearest sampling uses. |
| 350 | // |
| 351 | // If nearest sampling turns out to be a desirable usage of these |
| 352 | // textures then we could add the ability to switch a SurfaceTexture to |
| 353 | // nearest-mode. Preferably, however, the image producers (video |
| 354 | // decoder, camera, etc.) would simply not use a crop rectangle (or at |
| 355 | // least not tell the framework about it) so that the GPU can do the |
| 356 | // correct edge behavior. |
| 357 | int xshrink = 0, yshrink = 0; |
| 358 | if (mCurrentCrop.left > 0) { |
| 359 | tx = float(mCurrentCrop.left + 1) / float(buf->getWidth()); |
| 360 | xshrink++; |
| 361 | } else { |
| 362 | tx = 0.0f; |
| 363 | } |
Mathias Agopian | a5c75c0 | 2011-03-31 19:10:24 -0700 | [diff] [blame] | 364 | if (mCurrentCrop.right < int32_t(buf->getWidth())) { |
Jamie Gennis | d99c088 | 2011-03-10 16:24:46 -0800 | [diff] [blame] | 365 | xshrink++; |
| 366 | } |
Mathias Agopian | a5c75c0 | 2011-03-31 19:10:24 -0700 | [diff] [blame] | 367 | if (mCurrentCrop.bottom < int32_t(buf->getHeight())) { |
Jamie Gennis | d99c088 | 2011-03-10 16:24:46 -0800 | [diff] [blame] | 368 | ty = (float(buf->getHeight() - mCurrentCrop.bottom) + 1.0f) / |
| 369 | float(buf->getHeight()); |
| 370 | yshrink++; |
| 371 | } else { |
| 372 | ty = 0.0f; |
| 373 | } |
| 374 | if (mCurrentCrop.top > 0) { |
| 375 | yshrink++; |
| 376 | } |
| 377 | sx = float(mCurrentCrop.width() - xshrink) / float(buf->getWidth()); |
| 378 | sy = float(mCurrentCrop.height() - yshrink) / float(buf->getHeight()); |
Jamie Gennis | a214c64 | 2011-01-14 13:53:31 -0800 | [diff] [blame] | 379 | } else { |
| 380 | tx = 0.0f; |
| 381 | ty = 0.0f; |
| 382 | sx = 1.0f; |
| 383 | sy = 1.0f; |
| 384 | } |
Jamie Gennis | f238e28 | 2011-01-09 16:33:17 -0800 | [diff] [blame] | 385 | float crop[16] = { |
Jamie Gennis | a214c64 | 2011-01-14 13:53:31 -0800 | [diff] [blame] | 386 | sx, 0, 0, 0, |
| 387 | 0, sy, 0, 0, |
Jamie Gennis | f238e28 | 2011-01-09 16:33:17 -0800 | [diff] [blame] | 388 | 0, 0, 1, 0, |
Jamie Gennis | d99c088 | 2011-03-10 16:24:46 -0800 | [diff] [blame] | 389 | tx, ty, 0, 1, |
Jamie Gennis | f238e28 | 2011-01-09 16:33:17 -0800 | [diff] [blame] | 390 | }; |
| 391 | |
Jamie Gennis | a214c64 | 2011-01-14 13:53:31 -0800 | [diff] [blame] | 392 | float mtxBeforeFlipV[16]; |
| 393 | mtxMul(mtxBeforeFlipV, crop, xform); |
| 394 | |
| 395 | // SurfaceFlinger expects the top of its window textures to be at a Y |
| 396 | // coordinate of 0, so SurfaceTexture must behave the same way. We don't |
| 397 | // want to expose this to applications, however, so we must add an |
| 398 | // additional vertical flip to the transform after all the other transforms. |
Jamie Gennis | 736aa95 | 2011-06-12 17:03:06 -0700 | [diff] [blame] | 399 | mtxMul(mCurrentTransformMatrix, mtxFlipV, mtxBeforeFlipV); |
Jamie Gennis | f238e28 | 2011-01-09 16:33:17 -0800 | [diff] [blame] | 400 | } |
| 401 | |
Eino-Ville Talvala | 1d01a12 | 2011-02-18 11:02:42 -0800 | [diff] [blame] | 402 | nsecs_t SurfaceTexture::getTimestamp() { |
Jamie Gennis | 6ee96ad | 2011-10-19 13:36:31 -0700 | [diff] [blame] | 403 | ST_LOGV("getTimestamp"); |
Eino-Ville Talvala | 1d01a12 | 2011-02-18 11:02:42 -0800 | [diff] [blame] | 404 | Mutex::Autolock lock(mMutex); |
| 405 | return mCurrentTimestamp; |
| 406 | } |
| 407 | |
Jamie Gennis | c4d4aea | 2011-01-13 14:43:36 -0800 | [diff] [blame] | 408 | void SurfaceTexture::setFrameAvailableListener( |
Pannag Sanketi | 292a31a | 2011-06-24 09:56:27 -0700 | [diff] [blame] | 409 | const sp<FrameAvailableListener>& listener) { |
Jamie Gennis | 6ee96ad | 2011-10-19 13:36:31 -0700 | [diff] [blame] | 410 | ST_LOGV("setFrameAvailableListener"); |
Jamie Gennis | c4d4aea | 2011-01-13 14:43:36 -0800 | [diff] [blame] | 411 | Mutex::Autolock lock(mMutex); |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame^] | 412 | mFrameAvailableListener = listener; |
Jamie Gennis | c4d4aea | 2011-01-13 14:43:36 -0800 | [diff] [blame] | 413 | } |
| 414 | |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 415 | EGLImageKHR SurfaceTexture::createImage(EGLDisplay dpy, |
| 416 | const sp<GraphicBuffer>& graphicBuffer) { |
| 417 | EGLClientBuffer cbuf = (EGLClientBuffer)graphicBuffer->getNativeBuffer(); |
| 418 | EGLint attrs[] = { |
| 419 | EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, |
| 420 | EGL_NONE, |
| 421 | }; |
| 422 | EGLImageKHR image = eglCreateImageKHR(dpy, EGL_NO_CONTEXT, |
| 423 | EGL_NATIVE_BUFFER_ANDROID, cbuf, attrs); |
Mathias Agopian | 3cd5a11 | 2011-04-26 14:57:40 -0700 | [diff] [blame] | 424 | if (image == EGL_NO_IMAGE_KHR) { |
| 425 | EGLint error = eglGetError(); |
Jamie Gennis | fa28c35 | 2011-09-16 17:30:26 -0700 | [diff] [blame] | 426 | ST_LOGE("error creating EGLImage: %#x", error); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 427 | } |
| 428 | return image; |
| 429 | } |
| 430 | |
Mathias Agopian | 7a042bf | 2011-04-11 21:19:55 -0700 | [diff] [blame] | 431 | sp<GraphicBuffer> SurfaceTexture::getCurrentBuffer() const { |
| 432 | Mutex::Autolock lock(mMutex); |
| 433 | return mCurrentTextureBuf; |
| 434 | } |
| 435 | |
| 436 | Rect SurfaceTexture::getCurrentCrop() const { |
| 437 | Mutex::Autolock lock(mMutex); |
| 438 | return mCurrentCrop; |
| 439 | } |
| 440 | |
| 441 | uint32_t SurfaceTexture::getCurrentTransform() const { |
| 442 | Mutex::Autolock lock(mMutex); |
| 443 | return mCurrentTransform; |
| 444 | } |
| 445 | |
Mathias Agopian | 7734ebf | 2011-07-13 15:24:42 -0700 | [diff] [blame] | 446 | uint32_t SurfaceTexture::getCurrentScalingMode() const { |
| 447 | Mutex::Autolock lock(mMutex); |
| 448 | return mCurrentScalingMode; |
| 449 | } |
| 450 | |
Jamie Gennis | 5976946 | 2011-11-19 18:04:43 -0800 | [diff] [blame] | 451 | bool SurfaceTexture::isSynchronousMode() const { |
| 452 | Mutex::Autolock lock(mMutex); |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame] | 453 | return mBufferQueue->isSynchronousMode(); |
Jamie Gennis | 5976946 | 2011-11-19 18:04:43 -0800 | [diff] [blame] | 454 | } |
| 455 | |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame^] | 456 | void SurfaceTexture::freeBufferLocked(int slotIndex) { |
| 457 | ST_LOGV("freeBufferLocked: slotIndex=%d", slotIndex); |
| 458 | mEGLSlots[slotIndex].mGraphicBuffer = 0; |
| 459 | if (mEGLSlots[slotIndex].mEglImage != EGL_NO_IMAGE_KHR) { |
| 460 | EGLImageKHR img = mEGLSlots[slotIndex].mEglImage; |
| 461 | if (img != EGL_NO_IMAGE_KHR) { |
| 462 | eglDestroyImageKHR(mEGLSlots[slotIndex].mEglDisplay, img); |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 463 | } |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame^] | 464 | mEGLSlots[slotIndex].mEglImage = EGL_NO_IMAGE_KHR; |
| 465 | mEGLSlots[slotIndex].mEglDisplay = EGL_NO_DISPLAY; |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 466 | } |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame^] | 467 | } |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 468 | |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame^] | 469 | void SurfaceTexture::abandon() { |
| 470 | ST_LOGV("abandon"); |
| 471 | Mutex::Autolock lock(mMutex); |
| 472 | |
| 473 | if (!mAbandoned) { |
| 474 | mAbandoned = true; |
| 475 | mCurrentTextureBuf.clear(); |
| 476 | |
| 477 | // destroy all egl buffers |
| 478 | for (int i =0; i < BufferQueue::NUM_BUFFER_SLOTS; i++) { |
| 479 | freeBufferLocked(i); |
| 480 | } |
| 481 | |
| 482 | // disconnect from the BufferQueue |
| 483 | mBufferQueue->consumerDisconnect(); |
| 484 | mBufferQueue.clear(); |
| 485 | } |
Jamie Gennis | 7b305ff | 2011-07-19 12:08:33 -0700 | [diff] [blame] | 486 | } |
| 487 | |
Jamie Gennis | fa28c35 | 2011-09-16 17:30:26 -0700 | [diff] [blame] | 488 | void SurfaceTexture::setName(const String8& name) { |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 489 | Mutex::Autolock _l(mMutex); |
Jamie Gennis | fa28c35 | 2011-09-16 17:30:26 -0700 | [diff] [blame] | 490 | mName = name; |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame] | 491 | mBufferQueue->setConsumerName(name); |
| 492 | } |
| 493 | |
| 494 | status_t SurfaceTexture::setDefaultBufferFormat(uint32_t defaultFormat) { |
| 495 | Mutex::Autolock lock(mMutex); |
| 496 | return mBufferQueue->setDefaultBufferFormat(defaultFormat); |
| 497 | } |
| 498 | |
| 499 | status_t SurfaceTexture::setConsumerUsageBits(uint32_t usage) { |
| 500 | Mutex::Autolock lock(mMutex); |
| 501 | return mBufferQueue->setConsumerUsageBits(usage); |
| 502 | } |
| 503 | |
| 504 | status_t SurfaceTexture::setTransformHint(uint32_t hint) { |
| 505 | Mutex::Autolock lock(mMutex); |
| 506 | return mBufferQueue->setTransformHint(hint); |
| 507 | } |
| 508 | |
| 509 | // Used for refactoring BufferQueue from SurfaceTexture |
| 510 | // Should not be in final interface once users of SurfaceTexture are clean up. |
| 511 | status_t SurfaceTexture::setSynchronousMode(bool enabled) { |
| 512 | Mutex::Autolock lock(mMutex); |
| 513 | return mBufferQueue->setSynchronousMode(enabled); |
| 514 | } |
| 515 | |
| 516 | // Used for refactoring, should not be in final interface |
| 517 | sp<BufferQueue> SurfaceTexture::getBufferQueue() const { |
| 518 | Mutex::Autolock lock(mMutex); |
| 519 | return mBufferQueue; |
| 520 | } |
| 521 | |
| 522 | // Used for refactoring, should not be in final interface |
| 523 | status_t SurfaceTexture::setBufferCount(int bufferCount) { |
| 524 | Mutex::Autolock lock(mMutex); |
| 525 | return mBufferQueue->setBufferCount(bufferCount); |
| 526 | } |
| 527 | |
| 528 | // Used for refactoring, should not be in final interface |
| 529 | status_t SurfaceTexture::connect(int api, |
| 530 | uint32_t* outWidth, uint32_t* outHeight, uint32_t* outTransform) { |
| 531 | Mutex::Autolock lock(mMutex); |
| 532 | return mBufferQueue->connect(api, outWidth, outHeight, outTransform); |
Jamie Gennis | fa28c35 | 2011-09-16 17:30:26 -0700 | [diff] [blame] | 533 | } |
| 534 | |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame^] | 535 | void SurfaceTexture::onFrameAvailable() { |
| 536 | ST_LOGV("onFrameAvailable"); |
| 537 | |
| 538 | sp<FrameAvailableListener> listener; |
| 539 | { // scope for the lock |
| 540 | Mutex::Autolock lock(mMutex); |
| 541 | listener = mFrameAvailableListener; |
| 542 | } |
| 543 | |
| 544 | if (listener != NULL) { |
| 545 | ST_LOGV("actually calling onFrameAvailable"); |
| 546 | listener->onFrameAvailable(); |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | void SurfaceTexture::onBuffersReleased() { |
| 551 | ST_LOGV("onBuffersReleased"); |
| 552 | |
| 553 | Mutex::Autolock lock(mMutex); |
| 554 | |
| 555 | if (mAbandoned) { |
| 556 | // Nothing to do if we're already abandoned. |
| 557 | return; |
| 558 | } |
| 559 | |
| 560 | uint32_t mask = 0; |
| 561 | mBufferQueue->getReleasedBuffers(&mask); |
| 562 | for (int i = 0; i < BufferQueue::NUM_BUFFER_SLOTS; i++) { |
| 563 | if (mask & (1 << i)) { |
| 564 | freeBufferLocked(i); |
| 565 | } |
| 566 | } |
| 567 | } |
| 568 | |
Mathias Agopian | 68c7794 | 2011-05-09 19:08:33 -0700 | [diff] [blame] | 569 | void SurfaceTexture::dump(String8& result) const |
| 570 | { |
| 571 | char buffer[1024]; |
| 572 | dump(result, "", buffer, 1024); |
| 573 | } |
| 574 | |
| 575 | void SurfaceTexture::dump(String8& result, const char* prefix, |
| 576 | char* buffer, size_t SIZE) const |
| 577 | { |
| 578 | Mutex::Autolock _l(mMutex); |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame^] | 579 | snprintf(buffer, SIZE, "%smTexName=%d, mAbandoned=%d\n", prefix, mTexName, |
| 580 | int(mAbandoned)); |
Mathias Agopian | 68c7794 | 2011-05-09 19:08:33 -0700 | [diff] [blame] | 581 | result.append(buffer); |
| 582 | |
Mathias Agopian | 68c7794 | 2011-05-09 19:08:33 -0700 | [diff] [blame] | 583 | snprintf(buffer, SIZE, |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame^] | 584 | "%snext : {crop=[%d,%d,%d,%d], transform=0x%02x, current=%d}\n", |
| 585 | prefix, mCurrentCrop.left, |
Mathias Agopian | 68c7794 | 2011-05-09 19:08:33 -0700 | [diff] [blame] | 586 | mCurrentCrop.top, mCurrentCrop.right, mCurrentCrop.bottom, |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 587 | mCurrentTransform, mCurrentTexture |
Mathias Agopian | 68c7794 | 2011-05-09 19:08:33 -0700 | [diff] [blame] | 588 | ); |
| 589 | result.append(buffer); |
| 590 | |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame^] | 591 | if (!mAbandoned) { |
| 592 | mBufferQueue->dump(result, prefix, buffer, SIZE); |
| 593 | } |
Mathias Agopian | 68c7794 | 2011-05-09 19:08:33 -0700 | [diff] [blame] | 594 | } |
| 595 | |
Jamie Gennis | f238e28 | 2011-01-09 16:33:17 -0800 | [diff] [blame] | 596 | static void mtxMul(float out[16], const float a[16], const float b[16]) { |
| 597 | out[0] = a[0]*b[0] + a[4]*b[1] + a[8]*b[2] + a[12]*b[3]; |
| 598 | out[1] = a[1]*b[0] + a[5]*b[1] + a[9]*b[2] + a[13]*b[3]; |
| 599 | out[2] = a[2]*b[0] + a[6]*b[1] + a[10]*b[2] + a[14]*b[3]; |
| 600 | out[3] = a[3]*b[0] + a[7]*b[1] + a[11]*b[2] + a[15]*b[3]; |
| 601 | |
| 602 | out[4] = a[0]*b[4] + a[4]*b[5] + a[8]*b[6] + a[12]*b[7]; |
| 603 | out[5] = a[1]*b[4] + a[5]*b[5] + a[9]*b[6] + a[13]*b[7]; |
| 604 | out[6] = a[2]*b[4] + a[6]*b[5] + a[10]*b[6] + a[14]*b[7]; |
| 605 | out[7] = a[3]*b[4] + a[7]*b[5] + a[11]*b[6] + a[15]*b[7]; |
| 606 | |
| 607 | out[8] = a[0]*b[8] + a[4]*b[9] + a[8]*b[10] + a[12]*b[11]; |
| 608 | out[9] = a[1]*b[8] + a[5]*b[9] + a[9]*b[10] + a[13]*b[11]; |
| 609 | out[10] = a[2]*b[8] + a[6]*b[9] + a[10]*b[10] + a[14]*b[11]; |
| 610 | out[11] = a[3]*b[8] + a[7]*b[9] + a[11]*b[10] + a[15]*b[11]; |
| 611 | |
| 612 | out[12] = a[0]*b[12] + a[4]*b[13] + a[8]*b[14] + a[12]*b[15]; |
| 613 | out[13] = a[1]*b[12] + a[5]*b[13] + a[9]*b[14] + a[13]*b[15]; |
| 614 | out[14] = a[2]*b[12] + a[6]*b[13] + a[10]*b[14] + a[14]*b[15]; |
| 615 | out[15] = a[3]*b[12] + a[7]*b[13] + a[11]*b[14] + a[15]*b[15]; |
| 616 | } |
| 617 | |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 618 | }; // namespace android |