blob: e2346f060ecfdc562028c877f28a3c1cf1f039e6 [file] [log] [blame]
Jamie Gennis68e4a7a2010-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 Gennis7dc00d52011-01-09 13:24:09 -080018//#define LOG_NDEBUG 0
Jamie Gennis68e4a7a2010-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
30#include <surfaceflinger/ISurfaceComposer.h>
31#include <surfaceflinger/SurfaceComposerClient.h>
Jamie Gennisf7acf162011-01-12 18:30:40 -080032#include <surfaceflinger/IGraphicBufferAlloc.h>
Jamie Gennis68e4a7a2010-12-20 11:27:26 -080033
34#include <utils/Log.h>
35
36namespace android {
37
Jamie Gennisb598fb92011-01-09 16:33:17 -080038// Transform matrices
39static float mtxIdentity[16] = {
40 1, 0, 0, 0,
41 0, 1, 0, 0,
42 0, 0, 1, 0,
43 0, 0, 0, 1,
44};
45static float mtxFlipH[16] = {
46 -1, 0, 0, 0,
47 0, 1, 0, 0,
48 0, 0, 1, 0,
49 1, 0, 0, 1,
50};
51static float mtxFlipV[16] = {
52 1, 0, 0, 0,
53 0, -1, 0, 0,
54 0, 0, 1, 0,
55 0, 1, 0, 1,
56};
57static float mtxRot90[16] = {
58 0, 1, 0, 0,
59 -1, 0, 0, 0,
60 0, 0, 1, 0,
61 1, 0, 0, 1,
62};
63static float mtxRot180[16] = {
64 -1, 0, 0, 0,
65 0, -1, 0, 0,
66 0, 0, 1, 0,
67 1, 1, 0, 1,
68};
69static 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
76static void mtxMul(float out[16], const float a[16], const float b[16]);
77
Jamie Gennis68e4a7a2010-12-20 11:27:26 -080078SurfaceTexture::SurfaceTexture(GLuint tex) :
Mathias Agopiane5a1bff2011-03-31 19:10:24 -070079 mDefaultWidth(1),
80 mDefaultHeight(1),
81 mPixelFormat(PIXEL_FORMAT_RGBA_8888),
82 mUseDefaultSize(true),
Eino-Ville Talvalac5f94d82011-02-18 11:02:42 -080083 mBufferCount(MIN_BUFFER_SLOTS),
84 mCurrentTexture(INVALID_BUFFER_SLOT),
85 mCurrentTransform(0),
86 mCurrentTimestamp(0),
87 mLastQueued(INVALID_BUFFER_SLOT),
88 mLastQueuedTransform(0),
89 mLastQueuedTimestamp(0),
90 mNextTransform(0),
91 mTexName(tex) {
Jamie Gennis7dc00d52011-01-09 13:24:09 -080092 LOGV("SurfaceTexture::SurfaceTexture");
Jamie Gennisfd804f32011-01-07 16:05:47 -080093 for (int i = 0; i < NUM_BUFFER_SLOTS; i++) {
94 mSlots[i].mEglImage = EGL_NO_IMAGE_KHR;
95 mSlots[i].mEglDisplay = EGL_NO_DISPLAY;
96 mSlots[i].mOwnedByClient = false;
97 }
Jamie Gennisf7acf162011-01-12 18:30:40 -080098 sp<ISurfaceComposer> composer(ComposerService::getComposerService());
99 mGraphicBufferAlloc = composer->createGraphicBufferAlloc();
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800100}
101
102SurfaceTexture::~SurfaceTexture() {
Jamie Gennis7dc00d52011-01-09 13:24:09 -0800103 LOGV("SurfaceTexture::~SurfaceTexture");
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800104 freeAllBuffers();
105}
106
107status_t SurfaceTexture::setBufferCount(int bufferCount) {
Jamie Gennis7dc00d52011-01-09 13:24:09 -0800108 LOGV("SurfaceTexture::setBufferCount");
Jamie Gennis96dcc972011-02-27 14:10:20 -0800109
110 if (bufferCount < MIN_BUFFER_SLOTS) {
111 return BAD_VALUE;
112 }
113
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800114 Mutex::Autolock lock(mMutex);
115 freeAllBuffers();
116 mBufferCount = bufferCount;
Jamie Gennisd369dc42011-01-09 13:25:39 -0800117 mCurrentTexture = INVALID_BUFFER_SLOT;
118 mLastQueued = INVALID_BUFFER_SLOT;
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800119 return OK;
120}
121
Mathias Agopiane5a1bff2011-03-31 19:10:24 -0700122status_t SurfaceTexture::setDefaultBufferSize(uint32_t w, uint32_t h)
123{
124 Mutex::Autolock lock(mMutex);
125 if ((w != mDefaultWidth) || (h != mDefaultHeight)) {
126 mDefaultWidth = w;
127 mDefaultHeight = h;
128 }
129 return OK;
130}
131
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800132sp<GraphicBuffer> SurfaceTexture::requestBuffer(int buf,
133 uint32_t w, uint32_t h, uint32_t format, uint32_t usage) {
Jamie Gennis7dc00d52011-01-09 13:24:09 -0800134 LOGV("SurfaceTexture::requestBuffer");
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800135 Mutex::Autolock lock(mMutex);
136 if (buf < 0 || mBufferCount <= buf) {
137 LOGE("requestBuffer: slot index out of range [0, %d]: %d",
138 mBufferCount, buf);
139 return 0;
140 }
Mathias Agopiane5a1bff2011-03-31 19:10:24 -0700141 if ((w && !h) || (!w & h)) {
142 LOGE("requestBuffer: invalid size: w=%u, h=%u: %d", w, h, buf);
143 return 0;
144 }
145
146 const bool useDefaultSize = !w && !h;
147 if (useDefaultSize) {
148 // use the default size
149 w = mDefaultWidth;
150 h = mDefaultHeight;
151 }
152
153 const bool updateFormat = (format != 0);
154 if (!updateFormat) {
155 // keep the current (or default) format
156 format = mPixelFormat;
157 }
158
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800159 usage |= GraphicBuffer::USAGE_HW_TEXTURE;
Jamie Gennisf7acf162011-01-12 18:30:40 -0800160 sp<GraphicBuffer> graphicBuffer(
161 mGraphicBufferAlloc->createGraphicBuffer(w, h, format, usage));
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800162 if (graphicBuffer == 0) {
163 LOGE("requestBuffer: SurfaceComposer::createGraphicBuffer failed");
164 } else {
Mathias Agopiane5a1bff2011-03-31 19:10:24 -0700165 mUseDefaultSize = useDefaultSize;
166 if (updateFormat) {
167 mPixelFormat = format;
168 }
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800169 mSlots[buf].mGraphicBuffer = graphicBuffer;
170 if (mSlots[buf].mEglImage != EGL_NO_IMAGE_KHR) {
171 eglDestroyImageKHR(mSlots[buf].mEglDisplay, mSlots[buf].mEglImage);
172 mSlots[buf].mEglImage = EGL_NO_IMAGE_KHR;
173 mSlots[buf].mEglDisplay = EGL_NO_DISPLAY;
174 }
175 }
176 return graphicBuffer;
177}
178
179status_t SurfaceTexture::dequeueBuffer(int *buf) {
Jamie Gennis7dc00d52011-01-09 13:24:09 -0800180 LOGV("SurfaceTexture::dequeueBuffer");
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800181 Mutex::Autolock lock(mMutex);
182 int found = INVALID_BUFFER_SLOT;
183 for (int i = 0; i < mBufferCount; i++) {
Jamie Gennisa7eacc12011-01-11 15:00:09 -0800184 if (!mSlots[i].mOwnedByClient && i != mCurrentTexture && i != mLastQueued) {
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800185 mSlots[i].mOwnedByClient = true;
186 found = i;
187 break;
188 }
189 }
190 if (found == INVALID_BUFFER_SLOT) {
191 return -EBUSY;
192 }
Mathias Agopiane5a1bff2011-03-31 19:10:24 -0700193
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800194 *buf = found;
Mathias Agopiane5a1bff2011-03-31 19:10:24 -0700195
196 const sp<GraphicBuffer>& buffer(mSlots[found].mGraphicBuffer);
197 if (buffer == NULL) {
198 return ISurfaceTexture::BUFFER_NEEDS_REALLOCATION;
199 }
200 if ((mUseDefaultSize) &&
201 ((uint32_t(buffer->width) != mDefaultWidth) ||
202 (uint32_t(buffer->height) != mDefaultHeight))) {
203 return ISurfaceTexture::BUFFER_NEEDS_REALLOCATION;
204 }
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800205 return OK;
206}
207
Eino-Ville Talvalac5f94d82011-02-18 11:02:42 -0800208status_t SurfaceTexture::queueBuffer(int buf, int64_t timestamp) {
Jamie Gennis7dc00d52011-01-09 13:24:09 -0800209 LOGV("SurfaceTexture::queueBuffer");
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800210 Mutex::Autolock lock(mMutex);
211 if (buf < 0 || mBufferCount <= buf) {
212 LOGE("queueBuffer: slot index out of range [0, %d]: %d",
213 mBufferCount, buf);
214 return -EINVAL;
215 } else if (!mSlots[buf].mOwnedByClient) {
216 LOGE("queueBuffer: slot %d is not owned by the client", buf);
217 return -EINVAL;
218 } else if (mSlots[buf].mGraphicBuffer == 0) {
219 LOGE("queueBuffer: slot %d was enqueued without requesting a buffer",
220 buf);
221 return -EINVAL;
222 }
223 mSlots[buf].mOwnedByClient = false;
224 mLastQueued = buf;
Jamie Gennisb598fb92011-01-09 16:33:17 -0800225 mLastQueuedCrop = mNextCrop;
226 mLastQueuedTransform = mNextTransform;
Eino-Ville Talvalac5f94d82011-02-18 11:02:42 -0800227 mLastQueuedTimestamp = timestamp;
Jamie Gennis376590d2011-01-13 14:43:36 -0800228 if (mFrameAvailableListener != 0) {
229 mFrameAvailableListener->onFrameAvailable();
230 }
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800231 return OK;
232}
233
234void SurfaceTexture::cancelBuffer(int buf) {
Jamie Gennis7dc00d52011-01-09 13:24:09 -0800235 LOGV("SurfaceTexture::cancelBuffer");
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800236 Mutex::Autolock lock(mMutex);
237 if (buf < 0 || mBufferCount <= buf) {
238 LOGE("cancelBuffer: slot index out of range [0, %d]: %d", mBufferCount,
239 buf);
240 return;
241 } else if (!mSlots[buf].mOwnedByClient) {
242 LOGE("cancelBuffer: slot %d is not owned by the client", buf);
243 return;
244 }
245 mSlots[buf].mOwnedByClient = false;
246}
247
Jamie Gennisb598fb92011-01-09 16:33:17 -0800248status_t SurfaceTexture::setCrop(const Rect& crop) {
Jamie Gennis7dc00d52011-01-09 13:24:09 -0800249 LOGV("SurfaceTexture::setCrop");
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800250 Mutex::Autolock lock(mMutex);
Jamie Gennisb598fb92011-01-09 16:33:17 -0800251 mNextCrop = crop;
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800252 return OK;
253}
254
255status_t SurfaceTexture::setTransform(uint32_t transform) {
Jamie Gennis7dc00d52011-01-09 13:24:09 -0800256 LOGV("SurfaceTexture::setTransform");
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800257 Mutex::Autolock lock(mMutex);
Jamie Gennisb598fb92011-01-09 16:33:17 -0800258 mNextTransform = transform;
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800259 return OK;
260}
261
262status_t SurfaceTexture::updateTexImage() {
Jamie Gennis7dc00d52011-01-09 13:24:09 -0800263 LOGV("SurfaceTexture::updateTexImage");
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800264 Mutex::Autolock lock(mMutex);
265
266 // We always bind the texture even if we don't update its contents.
267 glBindTexture(GL_TEXTURE_EXTERNAL_OES, mTexName);
268
269 // Initially both mCurrentTexture and mLastQueued are INVALID_BUFFER_SLOT,
270 // so this check will fail until a buffer gets queued.
271 if (mCurrentTexture != mLastQueued) {
Jamie Gennisb598fb92011-01-09 16:33:17 -0800272 // Update the GL texture object.
Jamie Gennisf7acf162011-01-12 18:30:40 -0800273 EGLImageKHR image = mSlots[mLastQueued].mEglImage;
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800274 if (image == EGL_NO_IMAGE_KHR) {
275 EGLDisplay dpy = eglGetCurrentDisplay();
Jamie Gennisf7acf162011-01-12 18:30:40 -0800276 sp<GraphicBuffer> graphicBuffer = mSlots[mLastQueued].mGraphicBuffer;
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800277 image = createImage(dpy, graphicBuffer);
Jamie Gennisf7acf162011-01-12 18:30:40 -0800278 mSlots[mLastQueued].mEglImage = image;
279 mSlots[mLastQueued].mEglDisplay = dpy;
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800280 }
Jamie Gennis79d01fe2011-01-26 11:52:02 -0800281
282 GLint error;
283 while ((error = glGetError()) != GL_NO_ERROR) {
284 LOGE("GL error cleared before updating SurfaceTexture: %#04x", error);
285 }
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800286 glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, (GLeglImageOES)image);
Jamie Gennis79d01fe2011-01-26 11:52:02 -0800287 bool failed = false;
288 while ((error = glGetError()) != GL_NO_ERROR) {
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800289 LOGE("error binding external texture image %p (slot %d): %#04x",
Jamie Gennisf7acf162011-01-12 18:30:40 -0800290 image, mLastQueued, error);
Jamie Gennis79d01fe2011-01-26 11:52:02 -0800291 failed = true;
292 }
293 if (failed) {
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800294 return -EINVAL;
295 }
Jamie Gennisf7acf162011-01-12 18:30:40 -0800296
297 // Update the SurfaceTexture state.
298 mCurrentTexture = mLastQueued;
299 mCurrentTextureBuf = mSlots[mCurrentTexture].mGraphicBuffer;
300 mCurrentCrop = mLastQueuedCrop;
301 mCurrentTransform = mLastQueuedTransform;
Eino-Ville Talvalac5f94d82011-02-18 11:02:42 -0800302 mCurrentTimestamp = mLastQueuedTimestamp;
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800303 }
304 return OK;
305}
306
Jamie Gennisb598fb92011-01-09 16:33:17 -0800307void SurfaceTexture::getTransformMatrix(float mtx[16]) {
Eino-Ville Talvalac5f94d82011-02-18 11:02:42 -0800308 LOGV("SurfaceTexture::getTransformMatrix");
Jamie Gennisb598fb92011-01-09 16:33:17 -0800309 Mutex::Autolock lock(mMutex);
310
Jamie Gennis0fb736c2011-01-14 13:53:31 -0800311 float xform[16];
312 for (int i = 0; i < 16; i++) {
313 xform[i] = mtxIdentity[i];
314 }
315 if (mCurrentTransform & NATIVE_WINDOW_TRANSFORM_FLIP_H) {
316 float result[16];
317 mtxMul(result, xform, mtxFlipH);
318 for (int i = 0; i < 16; i++) {
319 xform[i] = result[i];
320 }
321 }
322 if (mCurrentTransform & NATIVE_WINDOW_TRANSFORM_FLIP_V) {
323 float result[16];
324 mtxMul(result, xform, mtxFlipV);
325 for (int i = 0; i < 16; i++) {
326 xform[i] = result[i];
327 }
328 }
329 if (mCurrentTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) {
330 float result[16];
331 mtxMul(result, xform, mtxRot90);
332 for (int i = 0; i < 16; i++) {
333 xform[i] = result[i];
334 }
Jamie Gennisb598fb92011-01-09 16:33:17 -0800335 }
336
337 sp<GraphicBuffer>& buf(mSlots[mCurrentTexture].mGraphicBuffer);
Jamie Gennis0fb736c2011-01-14 13:53:31 -0800338 float tx, ty, sx, sy;
339 if (!mCurrentCrop.isEmpty()) {
Jamie Gennisf3cedb62011-03-10 16:24:46 -0800340 // In order to prevent bilinear sampling at the of the crop rectangle we
341 // may need to shrink it by 2 texels in each direction. Normally this
342 // would just need to take 1/2 a texel off each end, but because the
343 // chroma channels will likely be subsampled we need to chop off a whole
344 // texel. This will cause artifacts if someone does nearest sampling
345 // with 1:1 pixel:texel ratio, but it's impossible to simultaneously
346 // accomodate the bilinear and nearest sampling uses.
347 //
348 // If nearest sampling turns out to be a desirable usage of these
349 // textures then we could add the ability to switch a SurfaceTexture to
350 // nearest-mode. Preferably, however, the image producers (video
351 // decoder, camera, etc.) would simply not use a crop rectangle (or at
352 // least not tell the framework about it) so that the GPU can do the
353 // correct edge behavior.
354 int xshrink = 0, yshrink = 0;
355 if (mCurrentCrop.left > 0) {
356 tx = float(mCurrentCrop.left + 1) / float(buf->getWidth());
357 xshrink++;
358 } else {
359 tx = 0.0f;
360 }
Mathias Agopiane5a1bff2011-03-31 19:10:24 -0700361 if (mCurrentCrop.right < int32_t(buf->getWidth())) {
Jamie Gennisf3cedb62011-03-10 16:24:46 -0800362 xshrink++;
363 }
Mathias Agopiane5a1bff2011-03-31 19:10:24 -0700364 if (mCurrentCrop.bottom < int32_t(buf->getHeight())) {
Jamie Gennisf3cedb62011-03-10 16:24:46 -0800365 ty = (float(buf->getHeight() - mCurrentCrop.bottom) + 1.0f) /
366 float(buf->getHeight());
367 yshrink++;
368 } else {
369 ty = 0.0f;
370 }
371 if (mCurrentCrop.top > 0) {
372 yshrink++;
373 }
374 sx = float(mCurrentCrop.width() - xshrink) / float(buf->getWidth());
375 sy = float(mCurrentCrop.height() - yshrink) / float(buf->getHeight());
Jamie Gennis0fb736c2011-01-14 13:53:31 -0800376 } else {
377 tx = 0.0f;
378 ty = 0.0f;
379 sx = 1.0f;
380 sy = 1.0f;
381 }
Jamie Gennisb598fb92011-01-09 16:33:17 -0800382 float crop[16] = {
Jamie Gennis0fb736c2011-01-14 13:53:31 -0800383 sx, 0, 0, 0,
384 0, sy, 0, 0,
Jamie Gennisb598fb92011-01-09 16:33:17 -0800385 0, 0, 1, 0,
Jamie Gennisf3cedb62011-03-10 16:24:46 -0800386 tx, ty, 0, 1,
Jamie Gennisb598fb92011-01-09 16:33:17 -0800387 };
388
Jamie Gennis0fb736c2011-01-14 13:53:31 -0800389 float mtxBeforeFlipV[16];
390 mtxMul(mtxBeforeFlipV, crop, xform);
391
392 // SurfaceFlinger expects the top of its window textures to be at a Y
393 // coordinate of 0, so SurfaceTexture must behave the same way. We don't
394 // want to expose this to applications, however, so we must add an
395 // additional vertical flip to the transform after all the other transforms.
396 mtxMul(mtx, mtxFlipV, mtxBeforeFlipV);
Jamie Gennisb598fb92011-01-09 16:33:17 -0800397}
398
Eino-Ville Talvalac5f94d82011-02-18 11:02:42 -0800399nsecs_t SurfaceTexture::getTimestamp() {
400 LOGV("SurfaceTexture::getTimestamp");
401 Mutex::Autolock lock(mMutex);
402 return mCurrentTimestamp;
403}
404
Jamie Gennis376590d2011-01-13 14:43:36 -0800405void SurfaceTexture::setFrameAvailableListener(
406 const sp<FrameAvailableListener>& l) {
407 LOGV("SurfaceTexture::setFrameAvailableListener");
408 Mutex::Autolock lock(mMutex);
409 mFrameAvailableListener = l;
410}
411
Jamie Gennis83bac212011-02-02 15:31:47 -0800412sp<IBinder> SurfaceTexture::getAllocator() {
413 LOGV("SurfaceTexture::getAllocator");
414 return mGraphicBufferAlloc->asBinder();
415}
416
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800417void SurfaceTexture::freeAllBuffers() {
418 for (int i = 0; i < NUM_BUFFER_SLOTS; i++) {
419 mSlots[i].mGraphicBuffer = 0;
420 mSlots[i].mOwnedByClient = false;
421 if (mSlots[i].mEglImage != EGL_NO_IMAGE_KHR) {
422 eglDestroyImageKHR(mSlots[i].mEglDisplay, mSlots[i].mEglImage);
423 mSlots[i].mEglImage = EGL_NO_IMAGE_KHR;
424 mSlots[i].mEglDisplay = EGL_NO_DISPLAY;
425 }
426 }
427}
428
429EGLImageKHR SurfaceTexture::createImage(EGLDisplay dpy,
430 const sp<GraphicBuffer>& graphicBuffer) {
431 EGLClientBuffer cbuf = (EGLClientBuffer)graphicBuffer->getNativeBuffer();
432 EGLint attrs[] = {
433 EGL_IMAGE_PRESERVED_KHR, EGL_TRUE,
434 EGL_NONE,
435 };
436 EGLImageKHR image = eglCreateImageKHR(dpy, EGL_NO_CONTEXT,
437 EGL_NATIVE_BUFFER_ANDROID, cbuf, attrs);
438 EGLint error = eglGetError();
439 if (error != EGL_SUCCESS) {
440 LOGE("error creating EGLImage: %#x", error);
441 } else if (image == EGL_NO_IMAGE_KHR) {
442 LOGE("no error reported, but no image was returned by "
443 "eglCreateImageKHR");
444 }
445 return image;
446}
447
Jamie Gennisb598fb92011-01-09 16:33:17 -0800448static void mtxMul(float out[16], const float a[16], const float b[16]) {
449 out[0] = a[0]*b[0] + a[4]*b[1] + a[8]*b[2] + a[12]*b[3];
450 out[1] = a[1]*b[0] + a[5]*b[1] + a[9]*b[2] + a[13]*b[3];
451 out[2] = a[2]*b[0] + a[6]*b[1] + a[10]*b[2] + a[14]*b[3];
452 out[3] = a[3]*b[0] + a[7]*b[1] + a[11]*b[2] + a[15]*b[3];
453
454 out[4] = a[0]*b[4] + a[4]*b[5] + a[8]*b[6] + a[12]*b[7];
455 out[5] = a[1]*b[4] + a[5]*b[5] + a[9]*b[6] + a[13]*b[7];
456 out[6] = a[2]*b[4] + a[6]*b[5] + a[10]*b[6] + a[14]*b[7];
457 out[7] = a[3]*b[4] + a[7]*b[5] + a[11]*b[6] + a[15]*b[7];
458
459 out[8] = a[0]*b[8] + a[4]*b[9] + a[8]*b[10] + a[12]*b[11];
460 out[9] = a[1]*b[8] + a[5]*b[9] + a[9]*b[10] + a[13]*b[11];
461 out[10] = a[2]*b[8] + a[6]*b[9] + a[10]*b[10] + a[14]*b[11];
462 out[11] = a[3]*b[8] + a[7]*b[9] + a[11]*b[10] + a[15]*b[11];
463
464 out[12] = a[0]*b[12] + a[4]*b[13] + a[8]*b[14] + a[12]*b[15];
465 out[13] = a[1]*b[12] + a[5]*b[13] + a[9]*b[14] + a[13]*b[15];
466 out[14] = a[2]*b[12] + a[6]*b[13] + a[10]*b[14] + a[14]*b[15];
467 out[15] = a[3]*b[12] + a[7]*b[13] + a[11]*b[14] + a[15]*b[15];
468}
469
Jamie Gennis68e4a7a2010-12-20 11:27:26 -0800470}; // namespace android