blob: 886a3fb22263a986f73aa325e3bc1cfeb7aff286 [file] [log] [blame]
Jamie Gennis8ba32fa2010-12-20 11:27:26 -08001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "SurfaceTexture"
Jamie Gennise70d8b42011-01-09 13:24:09 -080018//#define LOG_NDEBUG 0
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080019
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
Mathias Agopian7a042bf2011-04-11 21:19:55 -070030#include <hardware/hardware.h>
31
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080032#include <surfaceflinger/ISurfaceComposer.h>
33#include <surfaceflinger/SurfaceComposerClient.h>
Jamie Gennis9a78c902011-01-12 18:30:40 -080034#include <surfaceflinger/IGraphicBufferAlloc.h>
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080035
36#include <utils/Log.h>
Mathias Agopian68c77942011-05-09 19:08:33 -070037#include <utils/String8.h>
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080038
39namespace android {
40
Jamie Gennisf238e282011-01-09 16:33:17 -080041// Transform matrices
42static float mtxIdentity[16] = {
43 1, 0, 0, 0,
44 0, 1, 0, 0,
45 0, 0, 1, 0,
46 0, 0, 0, 1,
47};
48static float mtxFlipH[16] = {
49 -1, 0, 0, 0,
50 0, 1, 0, 0,
51 0, 0, 1, 0,
52 1, 0, 0, 1,
53};
54static float mtxFlipV[16] = {
55 1, 0, 0, 0,
56 0, -1, 0, 0,
57 0, 0, 1, 0,
58 0, 1, 0, 1,
59};
60static float mtxRot90[16] = {
61 0, 1, 0, 0,
62 -1, 0, 0, 0,
63 0, 0, 1, 0,
64 1, 0, 0, 1,
65};
66static float mtxRot180[16] = {
67 -1, 0, 0, 0,
68 0, -1, 0, 0,
69 0, 0, 1, 0,
70 1, 1, 0, 1,
71};
72static float mtxRot270[16] = {
73 0, -1, 0, 0,
74 1, 0, 0, 0,
75 0, 0, 1, 0,
76 0, 1, 0, 1,
77};
78
79static void mtxMul(float out[16], const float a[16], const float b[16]);
80
Grace Kloba14a0e582011-06-23 21:21:47 -070081SurfaceTexture::SurfaceTexture(GLuint tex, bool allowSynchronousMode) :
Mathias Agopiana5c75c02011-03-31 19:10:24 -070082 mDefaultWidth(1),
83 mDefaultHeight(1),
84 mPixelFormat(PIXEL_FORMAT_RGBA_8888),
Mathias Agopian80727112011-05-02 19:51:12 -070085 mBufferCount(MIN_ASYNC_BUFFER_SLOTS),
86 mClientBufferCount(0),
87 mServerBufferCount(MIN_ASYNC_BUFFER_SLOTS),
Eino-Ville Talvala1d01a122011-02-18 11:02:42 -080088 mCurrentTexture(INVALID_BUFFER_SLOT),
Mathias Agopian7a042bf2011-04-11 21:19:55 -070089 mCurrentTextureTarget(GL_TEXTURE_EXTERNAL_OES),
Eino-Ville Talvala1d01a122011-02-18 11:02:42 -080090 mCurrentTransform(0),
91 mCurrentTimestamp(0),
Eino-Ville Talvala1d01a122011-02-18 11:02:42 -080092 mNextTransform(0),
Mathias Agopianb3e518c2011-04-21 18:52:51 -070093 mTexName(tex),
Grace Kloba14a0e582011-06-23 21:21:47 -070094 mSynchronousMode(false),
95 mAllowSynchronousMode(allowSynchronousMode) {
Jamie Gennise70d8b42011-01-09 13:24:09 -080096 LOGV("SurfaceTexture::SurfaceTexture");
Jamie Gennis9a78c902011-01-12 18:30:40 -080097 sp<ISurfaceComposer> composer(ComposerService::getComposerService());
98 mGraphicBufferAlloc = composer->createGraphicBufferAlloc();
Mathias Agopiancc57d6f2011-04-27 18:57:33 -070099 mNextCrop.makeInvalid();
Jamie Gennis736aa952011-06-12 17:03:06 -0700100 memcpy(mCurrentTransformMatrix, mtxIdentity, sizeof(mCurrentTransformMatrix));
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800101}
102
103SurfaceTexture::~SurfaceTexture() {
Jamie Gennise70d8b42011-01-09 13:24:09 -0800104 LOGV("SurfaceTexture::~SurfaceTexture");
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800105 freeAllBuffers();
106}
107
Mathias Agopian80727112011-05-02 19:51:12 -0700108status_t SurfaceTexture::setBufferCountServerLocked(int bufferCount) {
109 if (bufferCount > NUM_BUFFER_SLOTS)
110 return BAD_VALUE;
111
112 // special-case, nothing to do
113 if (bufferCount == mBufferCount)
114 return OK;
115
116 if (!mClientBufferCount &&
117 bufferCount >= mBufferCount) {
118 // easy, we just have more buffers
119 mBufferCount = bufferCount;
120 mServerBufferCount = bufferCount;
121 mDequeueCondition.signal();
122 } else {
123 // we're here because we're either
124 // - reducing the number of available buffers
125 // - or there is a client-buffer-count in effect
126
127 // less than 2 buffers is never allowed
128 if (bufferCount < 2)
129 return BAD_VALUE;
130
131 // when there is non client-buffer-count in effect, the client is not
132 // allowed to dequeue more than one buffer at a time,
133 // so the next time they dequeue a buffer, we know that they don't
134 // own one. the actual resizing will happen during the next
135 // dequeueBuffer.
136
137 mServerBufferCount = bufferCount;
138 }
139 return OK;
140}
141
142status_t SurfaceTexture::setBufferCountServer(int bufferCount) {
143 Mutex::Autolock lock(mMutex);
144 return setBufferCountServerLocked(bufferCount);
145}
146
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800147status_t SurfaceTexture::setBufferCount(int bufferCount) {
Jamie Gennise70d8b42011-01-09 13:24:09 -0800148 LOGV("SurfaceTexture::setBufferCount");
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700149 Mutex::Autolock lock(mMutex);
Jamie Gennis9d4d6c12011-02-27 14:10:20 -0800150
Pannag Sanketi292a31a2011-06-24 09:56:27 -0700151 if (bufferCount > NUM_BUFFER_SLOTS) {
152 LOGE("setBufferCount: bufferCount larger than slots available");
153 return BAD_VALUE;
154 }
155
Mathias Agopian80727112011-05-02 19:51:12 -0700156 // Error out if the user has dequeued buffers
157 for (int i=0 ; i<mBufferCount ; i++) {
158 if (mSlots[i].mBufferState == BufferSlot::DEQUEUED) {
159 LOGE("setBufferCount: client owns some buffers");
160 return -EINVAL;
161 }
162 }
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700163
Mathias Agopian80727112011-05-02 19:51:12 -0700164 if (bufferCount == 0) {
165 const int minBufferSlots = mSynchronousMode ?
166 MIN_SYNC_BUFFER_SLOTS : MIN_ASYNC_BUFFER_SLOTS;
167 mClientBufferCount = 0;
168 bufferCount = (mServerBufferCount >= minBufferSlots) ?
169 mServerBufferCount : minBufferSlots;
170 return setBufferCountServerLocked(bufferCount);
171 }
172
173 // We don't allow the client to set a buffer-count less than
174 // MIN_ASYNC_BUFFER_SLOTS (3), there is no reason for it.
175 if (bufferCount < MIN_ASYNC_BUFFER_SLOTS) {
Jamie Gennis9d4d6c12011-02-27 14:10:20 -0800176 return BAD_VALUE;
177 }
178
Mathias Agopian80727112011-05-02 19:51:12 -0700179 // here we're guaranteed that the client doesn't have dequeued buffers
180 // and will release all of its buffer references.
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800181 freeAllBuffers();
182 mBufferCount = bufferCount;
Mathias Agopian80727112011-05-02 19:51:12 -0700183 mClientBufferCount = bufferCount;
Jamie Gennis67eedd72011-01-09 13:25:39 -0800184 mCurrentTexture = INVALID_BUFFER_SLOT;
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700185 mQueue.clear();
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700186 mDequeueCondition.signal();
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800187 return OK;
188}
189
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700190status_t SurfaceTexture::setDefaultBufferSize(uint32_t w, uint32_t h)
191{
192 Mutex::Autolock lock(mMutex);
193 if ((w != mDefaultWidth) || (h != mDefaultHeight)) {
194 mDefaultWidth = w;
195 mDefaultHeight = h;
196 }
197 return OK;
198}
199
Mathias Agopianc04f1532011-04-25 20:22:14 -0700200sp<GraphicBuffer> SurfaceTexture::requestBuffer(int buf) {
Jamie Gennise70d8b42011-01-09 13:24:09 -0800201 LOGV("SurfaceTexture::requestBuffer");
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800202 Mutex::Autolock lock(mMutex);
203 if (buf < 0 || mBufferCount <= buf) {
204 LOGE("requestBuffer: slot index out of range [0, %d]: %d",
205 mBufferCount, buf);
206 return 0;
207 }
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700208 mSlots[buf].mRequestBufferCalled = true;
Mathias Agopianc04f1532011-04-25 20:22:14 -0700209 return mSlots[buf].mGraphicBuffer;
210}
211
212status_t SurfaceTexture::dequeueBuffer(int *outBuf, uint32_t w, uint32_t h,
213 uint32_t format, uint32_t usage) {
214 LOGV("SurfaceTexture::dequeueBuffer");
215
Pannag Sanketi292a31a2011-06-24 09:56:27 -0700216 if ((w && !h) || (!w && h)) {
Mathias Agopianc04f1532011-04-25 20:22:14 -0700217 LOGE("dequeueBuffer: invalid size: w=%u, h=%u", w, h);
218 return BAD_VALUE;
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700219 }
220
Mathias Agopianc04f1532011-04-25 20:22:14 -0700221 Mutex::Autolock lock(mMutex);
Mathias Agopian80727112011-05-02 19:51:12 -0700222
223 status_t returnFlags(OK);
224
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700225 int found, foundSync;
226 int dequeuedCount = 0;
227 bool tryAgain = true;
228 while (tryAgain) {
Mathias Agopian80727112011-05-02 19:51:12 -0700229 // We need to wait for the FIFO to drain if the number of buffer
230 // needs to change.
231 //
232 // The condition "number of buffer needs to change" is true if
233 // - the client doesn't care about how many buffers there are
234 // - AND the actual number of buffer is different from what was
235 // set in the last setBufferCountServer()
236 // - OR -
237 // setBufferCountServer() was set to a value incompatible with
238 // the synchronization mode (for instance because the sync mode
239 // changed since)
240 //
241 // As long as this condition is true AND the FIFO is not empty, we
242 // wait on mDequeueCondition.
243
244 int minBufferCountNeeded = mSynchronousMode ?
245 MIN_SYNC_BUFFER_SLOTS : MIN_ASYNC_BUFFER_SLOTS;
246
247 if (!mClientBufferCount &&
248 ((mServerBufferCount != mBufferCount) ||
249 (mServerBufferCount < minBufferCountNeeded))) {
250 // wait for the FIFO to drain
251 while (!mQueue.isEmpty()) {
252 mDequeueCondition.wait(mMutex);
253 }
254 minBufferCountNeeded = mSynchronousMode ?
255 MIN_SYNC_BUFFER_SLOTS : MIN_ASYNC_BUFFER_SLOTS;
256 }
257
258
259 if (!mClientBufferCount &&
260 ((mServerBufferCount != mBufferCount) ||
261 (mServerBufferCount < minBufferCountNeeded))) {
262 // here we're guaranteed that mQueue is empty
263 freeAllBuffers();
264 mBufferCount = mServerBufferCount;
265 if (mBufferCount < minBufferCountNeeded)
266 mBufferCount = minBufferCountNeeded;
267 mCurrentTexture = INVALID_BUFFER_SLOT;
268 returnFlags |= ISurfaceTexture::RELEASE_ALL_BUFFERS;
269 }
270
271 // look for a free buffer to give to the client
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700272 found = INVALID_BUFFER_SLOT;
273 foundSync = INVALID_BUFFER_SLOT;
274 dequeuedCount = 0;
275 for (int i = 0; i < mBufferCount; i++) {
276 const int state = mSlots[i].mBufferState;
277 if (state == BufferSlot::DEQUEUED) {
278 dequeuedCount++;
279 }
Mathias Agopiane1220792011-05-04 18:28:07 -0700280 if (state == BufferSlot::FREE /*|| i == mCurrentTexture*/) {
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700281 foundSync = i;
282 if (i != mCurrentTexture) {
283 found = i;
284 break;
285 }
286 }
287 }
Mathias Agopian80727112011-05-02 19:51:12 -0700288
289 // clients are not allowed to dequeue more than one buffer
290 // if they didn't set a buffer count.
291 if (!mClientBufferCount && dequeuedCount) {
292 return -EINVAL;
293 }
294
Jamie Gennisc2c8dfd2011-05-23 18:44:04 -0700295 // See whether a buffer has been queued since the last setBufferCount so
296 // we know whether to perform the MIN_UNDEQUEUED_BUFFERS check below.
297 bool bufferHasBeenQueued = mCurrentTexture != INVALID_BUFFER_SLOT;
298 if (bufferHasBeenQueued) {
299 // make sure the client is not trying to dequeue more buffers
300 // than allowed.
301 const int avail = mBufferCount - (dequeuedCount+1);
302 if (avail < (MIN_UNDEQUEUED_BUFFERS-int(mSynchronousMode))) {
303 LOGE("dequeueBuffer: MIN_UNDEQUEUED_BUFFERS=%d exceeded (dequeued=%d)",
304 MIN_UNDEQUEUED_BUFFERS-int(mSynchronousMode),
305 dequeuedCount);
306 return -EBUSY;
307 }
Mathias Agopian80727112011-05-02 19:51:12 -0700308 }
309
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700310 // we're in synchronous mode and didn't find a buffer, we need to wait
Mathias Agopian80727112011-05-02 19:51:12 -0700311 // for for some buffers to be consumed
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700312 tryAgain = mSynchronousMode && (foundSync == INVALID_BUFFER_SLOT);
313 if (tryAgain) {
314 mDequeueCondition.wait(mMutex);
Mathias Agopianc04f1532011-04-25 20:22:14 -0700315 }
316 }
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700317
Mathias Agopian80727112011-05-02 19:51:12 -0700318 if (mSynchronousMode && found == INVALID_BUFFER_SLOT) {
319 // foundSync guaranteed to be != INVALID_BUFFER_SLOT
320 found = foundSync;
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700321 }
322
Mathias Agopianc04f1532011-04-25 20:22:14 -0700323 if (found == INVALID_BUFFER_SLOT) {
324 return -EBUSY;
325 }
326
327 const int buf = found;
328 *outBuf = found;
329
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700330 const bool useDefaultSize = !w && !h;
331 if (useDefaultSize) {
332 // use the default size
333 w = mDefaultWidth;
334 h = mDefaultHeight;
335 }
336
337 const bool updateFormat = (format != 0);
338 if (!updateFormat) {
339 // keep the current (or default) format
340 format = mPixelFormat;
341 }
342
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700343 // buffer is now in DEQUEUED (but can also be current at the same time,
344 // if we're in synchronous mode)
345 mSlots[buf].mBufferState = BufferSlot::DEQUEUED;
346
347 const sp<GraphicBuffer>& buffer(mSlots[buf].mGraphicBuffer);
Mathias Agopianc04f1532011-04-25 20:22:14 -0700348 if ((buffer == NULL) ||
349 (uint32_t(buffer->width) != w) ||
350 (uint32_t(buffer->height) != h) ||
351 (uint32_t(buffer->format) != format) ||
352 ((uint32_t(buffer->usage) & usage) != usage))
353 {
354 usage |= GraphicBuffer::USAGE_HW_TEXTURE;
Mathias Agopiand9e8c642011-07-01 14:53:49 -0700355 status_t error;
Mathias Agopianc04f1532011-04-25 20:22:14 -0700356 sp<GraphicBuffer> graphicBuffer(
Mathias Agopiand9e8c642011-07-01 14:53:49 -0700357 mGraphicBufferAlloc->createGraphicBuffer(
358 w, h, format, usage, &error));
Mathias Agopianc04f1532011-04-25 20:22:14 -0700359 if (graphicBuffer == 0) {
360 LOGE("dequeueBuffer: SurfaceComposer::createGraphicBuffer failed");
Mathias Agopiand9e8c642011-07-01 14:53:49 -0700361 return error;
Mathias Agopianc04f1532011-04-25 20:22:14 -0700362 }
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700363 if (updateFormat) {
364 mPixelFormat = format;
365 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800366 mSlots[buf].mGraphicBuffer = graphicBuffer;
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700367 mSlots[buf].mRequestBufferCalled = false;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800368 if (mSlots[buf].mEglImage != EGL_NO_IMAGE_KHR) {
369 eglDestroyImageKHR(mSlots[buf].mEglDisplay, mSlots[buf].mEglImage);
370 mSlots[buf].mEglImage = EGL_NO_IMAGE_KHR;
371 mSlots[buf].mEglDisplay = EGL_NO_DISPLAY;
372 }
Mathias Agopian80727112011-05-02 19:51:12 -0700373 returnFlags |= ISurfaceTexture::BUFFER_NEEDS_REALLOCATION;
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700374 }
Mathias Agopian80727112011-05-02 19:51:12 -0700375 return returnFlags;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800376}
377
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700378status_t SurfaceTexture::setSynchronousMode(bool enabled) {
379 Mutex::Autolock lock(mMutex);
Mathias Agopian80727112011-05-02 19:51:12 -0700380
381 status_t err = OK;
Grace Kloba14a0e582011-06-23 21:21:47 -0700382 if (!mAllowSynchronousMode && enabled)
383 return err;
384
Mathias Agopian80727112011-05-02 19:51:12 -0700385 if (!enabled) {
386 // going to asynchronous mode, drain the queue
387 while (mSynchronousMode != enabled && !mQueue.isEmpty()) {
388 mDequeueCondition.wait(mMutex);
389 }
390 }
391
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700392 if (mSynchronousMode != enabled) {
Mathias Agopian80727112011-05-02 19:51:12 -0700393 // - if we're going to asynchronous mode, the queue is guaranteed to be
394 // empty here
395 // - if the client set the number of buffers, we're guaranteed that
396 // we have at least 3 (because we don't allow less)
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700397 mSynchronousMode = enabled;
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700398 mDequeueCondition.signal();
399 }
Mathias Agopian80727112011-05-02 19:51:12 -0700400 return err;
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700401}
402
Eino-Ville Talvala1d01a122011-02-18 11:02:42 -0800403status_t SurfaceTexture::queueBuffer(int buf, int64_t timestamp) {
Jamie Gennise70d8b42011-01-09 13:24:09 -0800404 LOGV("SurfaceTexture::queueBuffer");
Mathias Agopiancf46eb92011-05-11 15:05:29 -0700405
406 sp<FrameAvailableListener> listener;
407
408 { // scope for the lock
Jamie Gennis8cd5ba42011-05-19 13:33:00 -0700409 Mutex::Autolock lock(mMutex);
410 if (buf < 0 || buf >= mBufferCount) {
411 LOGE("queueBuffer: slot index out of range [0, %d]: %d",
412 mBufferCount, buf);
413 return -EINVAL;
414 } else if (mSlots[buf].mBufferState != BufferSlot::DEQUEUED) {
415 LOGE("queueBuffer: slot %d is not owned by the client (state=%d)",
416 buf, mSlots[buf].mBufferState);
417 return -EINVAL;
418 } else if (buf == mCurrentTexture) {
419 LOGE("queueBuffer: slot %d is current!", buf);
420 return -EINVAL;
421 } else if (!mSlots[buf].mRequestBufferCalled) {
422 LOGE("queueBuffer: slot %d was enqueued without requesting a "
423 "buffer", buf);
424 return -EINVAL;
425 }
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700426
Jamie Gennis8cd5ba42011-05-19 13:33:00 -0700427 if (mSynchronousMode) {
Jamie Gennis3d8063b2011-06-26 18:27:47 -0700428 // In synchronous mode we queue all buffers in a FIFO.
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700429 mQueue.push_back(buf);
Jamie Gennis3d8063b2011-06-26 18:27:47 -0700430
431 // Synchronous mode always signals that an additional frame should
432 // be consumed.
433 listener = mFrameAvailableListener;
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700434 } else {
Jamie Gennis3d8063b2011-06-26 18:27:47 -0700435 // In asynchronous mode we only keep the most recent buffer.
Jamie Gennis8cd5ba42011-05-19 13:33:00 -0700436 if (mQueue.empty()) {
437 mQueue.push_back(buf);
Jamie Gennis3d8063b2011-06-26 18:27:47 -0700438
439 // Asynchronous mode only signals that a frame should be
440 // consumed if no previous frame was pending. If a frame were
441 // pending then the consumer would have already been notified.
442 listener = mFrameAvailableListener;
Jamie Gennis8cd5ba42011-05-19 13:33:00 -0700443 } else {
444 Fifo::iterator front(mQueue.begin());
445 // buffer currently queued is freed
446 mSlots[*front].mBufferState = BufferSlot::FREE;
447 // and we record the new buffer index in the queued list
448 *front = buf;
449 }
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700450 }
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700451
Jamie Gennis8cd5ba42011-05-19 13:33:00 -0700452 mSlots[buf].mBufferState = BufferSlot::QUEUED;
453 mSlots[buf].mCrop = mNextCrop;
454 mSlots[buf].mTransform = mNextTransform;
455 mSlots[buf].mTimestamp = timestamp;
456 mDequeueCondition.signal();
Mathias Agopiancf46eb92011-05-11 15:05:29 -0700457 } // scope for the lock
458
459 // call back without lock held
460 if (listener != 0) {
461 listener->onFrameAvailable();
462 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800463 return OK;
464}
465
466void SurfaceTexture::cancelBuffer(int buf) {
Jamie Gennise70d8b42011-01-09 13:24:09 -0800467 LOGV("SurfaceTexture::cancelBuffer");
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800468 Mutex::Autolock lock(mMutex);
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700469 if (buf < 0 || buf >= mBufferCount) {
470 LOGE("cancelBuffer: slot index out of range [0, %d]: %d",
471 mBufferCount, buf);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800472 return;
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700473 } else if (mSlots[buf].mBufferState != BufferSlot::DEQUEUED) {
474 LOGE("cancelBuffer: slot %d is not owned by the client (state=%d)",
475 buf, mSlots[buf].mBufferState);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800476 return;
477 }
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700478 mSlots[buf].mBufferState = BufferSlot::FREE;
479 mDequeueCondition.signal();
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800480}
481
Jamie Gennisf238e282011-01-09 16:33:17 -0800482status_t SurfaceTexture::setCrop(const Rect& crop) {
Jamie Gennise70d8b42011-01-09 13:24:09 -0800483 LOGV("SurfaceTexture::setCrop");
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800484 Mutex::Autolock lock(mMutex);
Jamie Gennisf238e282011-01-09 16:33:17 -0800485 mNextCrop = crop;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800486 return OK;
487}
488
489status_t SurfaceTexture::setTransform(uint32_t transform) {
Jamie Gennise70d8b42011-01-09 13:24:09 -0800490 LOGV("SurfaceTexture::setTransform");
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800491 Mutex::Autolock lock(mMutex);
Jamie Gennisf238e282011-01-09 16:33:17 -0800492 mNextTransform = transform;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800493 return OK;
494}
495
496status_t SurfaceTexture::updateTexImage() {
Jamie Gennise70d8b42011-01-09 13:24:09 -0800497 LOGV("SurfaceTexture::updateTexImage");
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800498 Mutex::Autolock lock(mMutex);
499
Jamie Gennis50c4efc2011-06-27 15:41:52 -0700500 // In asynchronous mode the list is guaranteed to be one buffer
501 // deep, while in synchronous mode we use the oldest buffer.
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700502 if (!mQueue.empty()) {
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700503 Fifo::iterator front(mQueue.begin());
Jamie Gennis50c4efc2011-06-27 15:41:52 -0700504 int buf = *front;
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700505
Jamie Gennisf238e282011-01-09 16:33:17 -0800506 // Update the GL texture object.
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700507 EGLImageKHR image = mSlots[buf].mEglImage;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800508 if (image == EGL_NO_IMAGE_KHR) {
509 EGLDisplay dpy = eglGetCurrentDisplay();
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700510 image = createImage(dpy, mSlots[buf].mGraphicBuffer);
511 mSlots[buf].mEglImage = image;
512 mSlots[buf].mEglDisplay = dpy;
Mathias Agopian3cd5a112011-04-26 14:57:40 -0700513 if (image == EGL_NO_IMAGE_KHR) {
514 // NOTE: if dpy was invalid, createImage() is guaranteed to
515 // fail. so we'd end up here.
516 return -EINVAL;
517 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800518 }
Jamie Gennis0eb88512011-01-26 11:52:02 -0800519
520 GLint error;
521 while ((error = glGetError()) != GL_NO_ERROR) {
Mathias Agopiancf46eb92011-05-11 15:05:29 -0700522 LOGW("updateTexImage: clearing GL error: %#04x", error);
Jamie Gennis0eb88512011-01-26 11:52:02 -0800523 }
Mathias Agopian7a042bf2011-04-11 21:19:55 -0700524
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700525 GLenum target = getTextureTarget(mSlots[buf].mGraphicBuffer->format);
Mathias Agopian7a042bf2011-04-11 21:19:55 -0700526 if (target != mCurrentTextureTarget) {
527 glDeleteTextures(1, &mTexName);
528 }
529 glBindTexture(target, mTexName);
530 glEGLImageTargetTexture2DOES(target, (GLeglImageOES)image);
531
Jamie Gennis0eb88512011-01-26 11:52:02 -0800532 bool failed = false;
533 while ((error = glGetError()) != GL_NO_ERROR) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800534 LOGE("error binding external texture image %p (slot %d): %#04x",
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700535 image, buf, error);
Jamie Gennis0eb88512011-01-26 11:52:02 -0800536 failed = true;
537 }
538 if (failed) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800539 return -EINVAL;
540 }
Jamie Gennis9a78c902011-01-12 18:30:40 -0800541
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700542 if (mCurrentTexture != INVALID_BUFFER_SLOT) {
Jamie Gennis50c4efc2011-06-27 15:41:52 -0700543 // The current buffer becomes FREE if it was still in the queued
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700544 // state. If it has already been given to the client
545 // (synchronous mode), then it stays in DEQUEUED state.
546 if (mSlots[mCurrentTexture].mBufferState == BufferSlot::QUEUED)
547 mSlots[mCurrentTexture].mBufferState = BufferSlot::FREE;
548 }
549
Jamie Gennis9a78c902011-01-12 18:30:40 -0800550 // Update the SurfaceTexture state.
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700551 mCurrentTexture = buf;
Mathias Agopian7a042bf2011-04-11 21:19:55 -0700552 mCurrentTextureTarget = target;
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700553 mCurrentTextureBuf = mSlots[buf].mGraphicBuffer;
Jamie Gennis8cd5ba42011-05-19 13:33:00 -0700554 mCurrentCrop = mSlots[buf].mCrop;
555 mCurrentTransform = mSlots[buf].mTransform;
556 mCurrentTimestamp = mSlots[buf].mTimestamp;
Jamie Gennis736aa952011-06-12 17:03:06 -0700557 computeCurrentTransformMatrix();
Jamie Gennis50c4efc2011-06-27 15:41:52 -0700558
559 // Now that we've passed the point at which failures can happen,
560 // it's safe to remove the buffer from the front of the queue.
561 mQueue.erase(front);
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700562 mDequeueCondition.signal();
Mathias Agopian7a042bf2011-04-11 21:19:55 -0700563 } else {
564 // We always bind the texture even if we don't update its contents.
565 glBindTexture(mCurrentTextureTarget, mTexName);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800566 }
Jamie Gennis50c4efc2011-06-27 15:41:52 -0700567
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800568 return OK;
569}
570
Mathias Agopian7a042bf2011-04-11 21:19:55 -0700571bool SurfaceTexture::isExternalFormat(uint32_t format)
572{
573 switch (format) {
574 // supported YUV formats
575 case HAL_PIXEL_FORMAT_YV12:
576 // Legacy/deprecated YUV formats
577 case HAL_PIXEL_FORMAT_YCbCr_422_SP:
578 case HAL_PIXEL_FORMAT_YCrCb_420_SP:
579 case HAL_PIXEL_FORMAT_YCbCr_422_I:
580 return true;
581 }
582
583 // Any OEM format needs to be considered
584 if (format>=0x100 && format<=0x1FF)
585 return true;
586
587 return false;
588}
589
590GLenum SurfaceTexture::getTextureTarget(uint32_t format)
591{
592 GLenum target = GL_TEXTURE_2D;
593#if defined(GL_OES_EGL_image_external)
594 if (isExternalFormat(format)) {
595 target = GL_TEXTURE_EXTERNAL_OES;
596 }
597#endif
598 return target;
599}
600
601GLenum SurfaceTexture::getCurrentTextureTarget() const {
602 Mutex::Autolock lock(mMutex);
603 return mCurrentTextureTarget;
604}
605
Jamie Gennisf238e282011-01-09 16:33:17 -0800606void SurfaceTexture::getTransformMatrix(float mtx[16]) {
Jamie Gennisf238e282011-01-09 16:33:17 -0800607 Mutex::Autolock lock(mMutex);
Jamie Gennis736aa952011-06-12 17:03:06 -0700608 memcpy(mtx, mCurrentTransformMatrix, sizeof(mCurrentTransformMatrix));
609}
610
611void SurfaceTexture::computeCurrentTransformMatrix() {
612 LOGV("SurfaceTexture::computeCurrentTransformMatrix");
Jamie Gennisf238e282011-01-09 16:33:17 -0800613
Jamie Gennisa214c642011-01-14 13:53:31 -0800614 float xform[16];
615 for (int i = 0; i < 16; i++) {
616 xform[i] = mtxIdentity[i];
617 }
618 if (mCurrentTransform & NATIVE_WINDOW_TRANSFORM_FLIP_H) {
619 float result[16];
620 mtxMul(result, xform, mtxFlipH);
621 for (int i = 0; i < 16; i++) {
622 xform[i] = result[i];
623 }
624 }
625 if (mCurrentTransform & NATIVE_WINDOW_TRANSFORM_FLIP_V) {
626 float result[16];
627 mtxMul(result, xform, mtxFlipV);
628 for (int i = 0; i < 16; i++) {
629 xform[i] = result[i];
630 }
631 }
632 if (mCurrentTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) {
633 float result[16];
634 mtxMul(result, xform, mtxRot90);
635 for (int i = 0; i < 16; i++) {
636 xform[i] = result[i];
637 }
Jamie Gennisf238e282011-01-09 16:33:17 -0800638 }
639
640 sp<GraphicBuffer>& buf(mSlots[mCurrentTexture].mGraphicBuffer);
Jamie Gennisa214c642011-01-14 13:53:31 -0800641 float tx, ty, sx, sy;
642 if (!mCurrentCrop.isEmpty()) {
Jamie Gennisd99c0882011-03-10 16:24:46 -0800643 // In order to prevent bilinear sampling at the of the crop rectangle we
644 // may need to shrink it by 2 texels in each direction. Normally this
645 // would just need to take 1/2 a texel off each end, but because the
646 // chroma channels will likely be subsampled we need to chop off a whole
647 // texel. This will cause artifacts if someone does nearest sampling
648 // with 1:1 pixel:texel ratio, but it's impossible to simultaneously
649 // accomodate the bilinear and nearest sampling uses.
650 //
651 // If nearest sampling turns out to be a desirable usage of these
652 // textures then we could add the ability to switch a SurfaceTexture to
653 // nearest-mode. Preferably, however, the image producers (video
654 // decoder, camera, etc.) would simply not use a crop rectangle (or at
655 // least not tell the framework about it) so that the GPU can do the
656 // correct edge behavior.
657 int xshrink = 0, yshrink = 0;
658 if (mCurrentCrop.left > 0) {
659 tx = float(mCurrentCrop.left + 1) / float(buf->getWidth());
660 xshrink++;
661 } else {
662 tx = 0.0f;
663 }
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700664 if (mCurrentCrop.right < int32_t(buf->getWidth())) {
Jamie Gennisd99c0882011-03-10 16:24:46 -0800665 xshrink++;
666 }
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700667 if (mCurrentCrop.bottom < int32_t(buf->getHeight())) {
Jamie Gennisd99c0882011-03-10 16:24:46 -0800668 ty = (float(buf->getHeight() - mCurrentCrop.bottom) + 1.0f) /
669 float(buf->getHeight());
670 yshrink++;
671 } else {
672 ty = 0.0f;
673 }
674 if (mCurrentCrop.top > 0) {
675 yshrink++;
676 }
677 sx = float(mCurrentCrop.width() - xshrink) / float(buf->getWidth());
678 sy = float(mCurrentCrop.height() - yshrink) / float(buf->getHeight());
Jamie Gennisa214c642011-01-14 13:53:31 -0800679 } else {
680 tx = 0.0f;
681 ty = 0.0f;
682 sx = 1.0f;
683 sy = 1.0f;
684 }
Jamie Gennisf238e282011-01-09 16:33:17 -0800685 float crop[16] = {
Jamie Gennisa214c642011-01-14 13:53:31 -0800686 sx, 0, 0, 0,
687 0, sy, 0, 0,
Jamie Gennisf238e282011-01-09 16:33:17 -0800688 0, 0, 1, 0,
Jamie Gennisd99c0882011-03-10 16:24:46 -0800689 tx, ty, 0, 1,
Jamie Gennisf238e282011-01-09 16:33:17 -0800690 };
691
Jamie Gennisa214c642011-01-14 13:53:31 -0800692 float mtxBeforeFlipV[16];
693 mtxMul(mtxBeforeFlipV, crop, xform);
694
695 // SurfaceFlinger expects the top of its window textures to be at a Y
696 // coordinate of 0, so SurfaceTexture must behave the same way. We don't
697 // want to expose this to applications, however, so we must add an
698 // additional vertical flip to the transform after all the other transforms.
Jamie Gennis736aa952011-06-12 17:03:06 -0700699 mtxMul(mCurrentTransformMatrix, mtxFlipV, mtxBeforeFlipV);
Jamie Gennisf238e282011-01-09 16:33:17 -0800700}
701
Eino-Ville Talvala1d01a122011-02-18 11:02:42 -0800702nsecs_t SurfaceTexture::getTimestamp() {
703 LOGV("SurfaceTexture::getTimestamp");
704 Mutex::Autolock lock(mMutex);
705 return mCurrentTimestamp;
706}
707
Jamie Gennisc4d4aea2011-01-13 14:43:36 -0800708void SurfaceTexture::setFrameAvailableListener(
Pannag Sanketi292a31a2011-06-24 09:56:27 -0700709 const sp<FrameAvailableListener>& listener) {
Jamie Gennisc4d4aea2011-01-13 14:43:36 -0800710 LOGV("SurfaceTexture::setFrameAvailableListener");
711 Mutex::Autolock lock(mMutex);
Pannag Sanketi292a31a2011-06-24 09:56:27 -0700712 mFrameAvailableListener = listener;
Jamie Gennisc4d4aea2011-01-13 14:43:36 -0800713}
714
Jamie Gennis1b20cde2011-02-02 15:31:47 -0800715sp<IBinder> SurfaceTexture::getAllocator() {
716 LOGV("SurfaceTexture::getAllocator");
717 return mGraphicBufferAlloc->asBinder();
718}
719
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800720void SurfaceTexture::freeAllBuffers() {
721 for (int i = 0; i < NUM_BUFFER_SLOTS; i++) {
722 mSlots[i].mGraphicBuffer = 0;
Mathias Agopianb3e518c2011-04-21 18:52:51 -0700723 mSlots[i].mBufferState = BufferSlot::FREE;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800724 if (mSlots[i].mEglImage != EGL_NO_IMAGE_KHR) {
725 eglDestroyImageKHR(mSlots[i].mEglDisplay, mSlots[i].mEglImage);
726 mSlots[i].mEglImage = EGL_NO_IMAGE_KHR;
727 mSlots[i].mEglDisplay = EGL_NO_DISPLAY;
728 }
729 }
730}
731
732EGLImageKHR SurfaceTexture::createImage(EGLDisplay dpy,
733 const sp<GraphicBuffer>& graphicBuffer) {
734 EGLClientBuffer cbuf = (EGLClientBuffer)graphicBuffer->getNativeBuffer();
735 EGLint attrs[] = {
736 EGL_IMAGE_PRESERVED_KHR, EGL_TRUE,
737 EGL_NONE,
738 };
739 EGLImageKHR image = eglCreateImageKHR(dpy, EGL_NO_CONTEXT,
740 EGL_NATIVE_BUFFER_ANDROID, cbuf, attrs);
Mathias Agopian3cd5a112011-04-26 14:57:40 -0700741 if (image == EGL_NO_IMAGE_KHR) {
742 EGLint error = eglGetError();
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800743 LOGE("error creating EGLImage: %#x", error);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800744 }
745 return image;
746}
747
Mathias Agopian7a042bf2011-04-11 21:19:55 -0700748sp<GraphicBuffer> SurfaceTexture::getCurrentBuffer() const {
749 Mutex::Autolock lock(mMutex);
750 return mCurrentTextureBuf;
751}
752
753Rect SurfaceTexture::getCurrentCrop() const {
754 Mutex::Autolock lock(mMutex);
755 return mCurrentCrop;
756}
757
758uint32_t SurfaceTexture::getCurrentTransform() const {
759 Mutex::Autolock lock(mMutex);
760 return mCurrentTransform;
761}
762
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700763int SurfaceTexture::query(int what, int* outValue)
764{
765 Mutex::Autolock lock(mMutex);
766 int value;
767 switch (what) {
768 case NATIVE_WINDOW_WIDTH:
769 value = mDefaultWidth;
770 if (!mDefaultWidth && !mDefaultHeight && mCurrentTextureBuf!=0)
771 value = mCurrentTextureBuf->width;
772 break;
773 case NATIVE_WINDOW_HEIGHT:
774 value = mDefaultHeight;
775 if (!mDefaultWidth && !mDefaultHeight && mCurrentTextureBuf!=0)
776 value = mCurrentTextureBuf->height;
777 break;
778 case NATIVE_WINDOW_FORMAT:
779 value = mPixelFormat;
780 break;
781 case NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS:
782 value = mSynchronousMode ?
783 (MIN_UNDEQUEUED_BUFFERS-1) : MIN_UNDEQUEUED_BUFFERS;
784 break;
785 default:
786 return BAD_VALUE;
787 }
788 outValue[0] = value;
789 return NO_ERROR;
790}
Mathias Agopian7a042bf2011-04-11 21:19:55 -0700791
Mathias Agopian68c77942011-05-09 19:08:33 -0700792void SurfaceTexture::dump(String8& result) const
793{
794 char buffer[1024];
795 dump(result, "", buffer, 1024);
796}
797
798void SurfaceTexture::dump(String8& result, const char* prefix,
799 char* buffer, size_t SIZE) const
800{
801 Mutex::Autolock _l(mMutex);
802 snprintf(buffer, SIZE,
803 "%smBufferCount=%d, mSynchronousMode=%d, default-size=[%dx%d], "
804 "mPixelFormat=%d, mTexName=%d\n",
805 prefix, mBufferCount, mSynchronousMode, mDefaultWidth, mDefaultHeight,
806 mPixelFormat, mTexName);
807 result.append(buffer);
808
809 String8 fifo;
810 int fifoSize = 0;
811 Fifo::const_iterator i(mQueue.begin());
812 while (i != mQueue.end()) {
813 snprintf(buffer, SIZE, "%02d ", *i++);
814 fifoSize++;
815 fifo.append(buffer);
816 }
817
818 snprintf(buffer, SIZE,
819 "%scurrent: {crop=[%d,%d,%d,%d], transform=0x%02x, current=%d, target=0x%04x}\n"
820 "%snext : {crop=[%d,%d,%d,%d], transform=0x%02x, FIFO(%d)={%s}}\n"
821 ,
822 prefix, mCurrentCrop.left,
823 mCurrentCrop.top, mCurrentCrop.right, mCurrentCrop.bottom,
824 mCurrentTransform, mCurrentTexture, mCurrentTextureTarget,
825 prefix, mNextCrop.left, mNextCrop.top, mNextCrop.right, mNextCrop.bottom,
826 mCurrentTransform, fifoSize, fifo.string()
827 );
828 result.append(buffer);
829
830 struct {
831 const char * operator()(int state) const {
832 switch (state) {
833 case BufferSlot::DEQUEUED: return "DEQUEUED";
834 case BufferSlot::QUEUED: return "QUEUED";
835 case BufferSlot::FREE: return "FREE";
836 default: return "Unknown";
837 }
838 }
839 } stateName;
840
841 for (int i=0 ; i<mBufferCount ; i++) {
842 const BufferSlot& slot(mSlots[i]);
843 snprintf(buffer, SIZE,
844 "%s%s[%02d] state=%-8s, crop=[%d,%d,%d,%d], transform=0x%02x, "
Jamie Gennis8cd5ba42011-05-19 13:33:00 -0700845 "timestamp=%lld\n",
Mathias Agopian68c77942011-05-09 19:08:33 -0700846 prefix, (i==mCurrentTexture)?">":" ", i, stateName(slot.mBufferState),
Jamie Gennis8cd5ba42011-05-19 13:33:00 -0700847 slot.mCrop.left, slot.mCrop.top, slot.mCrop.right, slot.mCrop.bottom,
848 slot.mTransform, slot.mTimestamp
Mathias Agopian68c77942011-05-09 19:08:33 -0700849 );
850 result.append(buffer);
851 }
852}
853
Jamie Gennisf238e282011-01-09 16:33:17 -0800854static void mtxMul(float out[16], const float a[16], const float b[16]) {
855 out[0] = a[0]*b[0] + a[4]*b[1] + a[8]*b[2] + a[12]*b[3];
856 out[1] = a[1]*b[0] + a[5]*b[1] + a[9]*b[2] + a[13]*b[3];
857 out[2] = a[2]*b[0] + a[6]*b[1] + a[10]*b[2] + a[14]*b[3];
858 out[3] = a[3]*b[0] + a[7]*b[1] + a[11]*b[2] + a[15]*b[3];
859
860 out[4] = a[0]*b[4] + a[4]*b[5] + a[8]*b[6] + a[12]*b[7];
861 out[5] = a[1]*b[4] + a[5]*b[5] + a[9]*b[6] + a[13]*b[7];
862 out[6] = a[2]*b[4] + a[6]*b[5] + a[10]*b[6] + a[14]*b[7];
863 out[7] = a[3]*b[4] + a[7]*b[5] + a[11]*b[6] + a[15]*b[7];
864
865 out[8] = a[0]*b[8] + a[4]*b[9] + a[8]*b[10] + a[12]*b[11];
866 out[9] = a[1]*b[8] + a[5]*b[9] + a[9]*b[10] + a[13]*b[11];
867 out[10] = a[2]*b[8] + a[6]*b[9] + a[10]*b[10] + a[14]*b[11];
868 out[11] = a[3]*b[8] + a[7]*b[9] + a[11]*b[10] + a[15]*b[11];
869
870 out[12] = a[0]*b[12] + a[4]*b[13] + a[8]*b[14] + a[12]*b[15];
871 out[13] = a[1]*b[12] + a[5]*b[13] + a[9]*b[14] + a[13]*b[15];
872 out[14] = a[2]*b[12] + a[6]*b[13] + a[10]*b[14] + a[14]*b[15];
873 out[15] = a[3]*b[12] + a[7]*b[13] + a[11]*b[14] + a[15]*b[15];
874}
875
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800876}; // namespace android