2010-12-20 19:27:26 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define LOG_TAG "SurfaceTexture"
|
2012-02-24 03:27:23 +00:00
|
|
|
#define ATRACE_TAG ATRACE_TAG_GRAPHICS
|
2011-01-09 21:24:09 +00:00
|
|
|
//#define LOG_NDEBUG 0
|
2010-12-20 19:27:26 +00:00
|
|
|
|
|
|
|
#define GL_GLEXT_PROTOTYPES
|
|
|
|
#define EGL_EGLEXT_PROTOTYPES
|
|
|
|
|
|
|
|
#include <EGL/egl.h>
|
|
|
|
#include <EGL/eglext.h>
|
|
|
|
#include <GLES2/gl2.h>
|
|
|
|
#include <GLES2/gl2ext.h>
|
|
|
|
|
2011-04-12 04:19:55 +00:00
|
|
|
#include <hardware/hardware.h>
|
|
|
|
|
2012-02-26 02:48:35 +00:00
|
|
|
#include <gui/IGraphicBufferAlloc.h>
|
|
|
|
#include <gui/ISurfaceComposer.h>
|
|
|
|
#include <gui/SurfaceComposerClient.h>
|
|
|
|
#include <gui/SurfaceTexture.h>
|
2011-11-18 01:48:35 +00:00
|
|
|
|
2012-02-26 02:48:35 +00:00
|
|
|
#include <private/gui/ComposerService.h>
|
2010-12-20 19:27:26 +00:00
|
|
|
|
|
|
|
#include <utils/Log.h>
|
2011-05-10 02:08:33 +00:00
|
|
|
#include <utils/String8.h>
|
2012-02-24 03:27:23 +00:00
|
|
|
#include <utils/Trace.h>
|
2010-12-20 19:27:26 +00:00
|
|
|
|
2011-11-14 22:51:01 +00:00
|
|
|
// This compile option makes SurfaceTexture use the EGL_KHR_fence_sync extension
|
|
|
|
// to synchronize access to the buffers. It will cause dequeueBuffer to stall,
|
|
|
|
// waiting for the GL reads for the buffer being dequeued to complete before
|
|
|
|
// allowing the buffer to be dequeued.
|
|
|
|
#ifdef USE_FENCE_SYNC
|
|
|
|
#ifdef ALLOW_DEQUEUE_CURRENT_BUFFER
|
|
|
|
#error "USE_FENCE_SYNC and ALLOW_DEQUEUE_CURRENT_BUFFER are incompatible"
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2011-09-17 00:30:26 +00:00
|
|
|
// Macros for including the SurfaceTexture name in log messages
|
2011-10-20 10:56:00 +00:00
|
|
|
#define ST_LOGV(x, ...) ALOGV("[%s] "x, mName.string(), ##__VA_ARGS__)
|
2011-12-20 16:23:08 +00:00
|
|
|
#define ST_LOGD(x, ...) ALOGD("[%s] "x, mName.string(), ##__VA_ARGS__)
|
2012-01-04 20:05:49 +00:00
|
|
|
#define ST_LOGI(x, ...) ALOGI("[%s] "x, mName.string(), ##__VA_ARGS__)
|
2012-01-05 23:22:43 +00:00
|
|
|
#define ST_LOGW(x, ...) ALOGW("[%s] "x, mName.string(), ##__VA_ARGS__)
|
2012-01-06 19:20:56 +00:00
|
|
|
#define ST_LOGE(x, ...) ALOGE("[%s] "x, mName.string(), ##__VA_ARGS__)
|
2011-08-17 22:42:04 +00:00
|
|
|
|
2010-12-20 19:27:26 +00:00
|
|
|
namespace android {
|
|
|
|
|
2011-01-10 00:33:17 +00:00
|
|
|
// Transform matrices
|
|
|
|
static float mtxIdentity[16] = {
|
|
|
|
1, 0, 0, 0,
|
|
|
|
0, 1, 0, 0,
|
|
|
|
0, 0, 1, 0,
|
|
|
|
0, 0, 0, 1,
|
|
|
|
};
|
|
|
|
static float mtxFlipH[16] = {
|
|
|
|
-1, 0, 0, 0,
|
|
|
|
0, 1, 0, 0,
|
|
|
|
0, 0, 1, 0,
|
|
|
|
1, 0, 0, 1,
|
|
|
|
};
|
|
|
|
static float mtxFlipV[16] = {
|
|
|
|
1, 0, 0, 0,
|
|
|
|
0, -1, 0, 0,
|
|
|
|
0, 0, 1, 0,
|
|
|
|
0, 1, 0, 1,
|
|
|
|
};
|
|
|
|
static float mtxRot90[16] = {
|
|
|
|
0, 1, 0, 0,
|
|
|
|
-1, 0, 0, 0,
|
|
|
|
0, 0, 1, 0,
|
|
|
|
1, 0, 0, 1,
|
|
|
|
};
|
|
|
|
static float mtxRot180[16] = {
|
|
|
|
-1, 0, 0, 0,
|
|
|
|
0, -1, 0, 0,
|
|
|
|
0, 0, 1, 0,
|
|
|
|
1, 1, 0, 1,
|
|
|
|
};
|
|
|
|
static float mtxRot270[16] = {
|
|
|
|
0, -1, 0, 0,
|
|
|
|
1, 0, 0, 0,
|
|
|
|
0, 0, 1, 0,
|
|
|
|
0, 1, 0, 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void mtxMul(float out[16], const float a[16], const float b[16]);
|
|
|
|
|
2012-01-22 23:26:27 +00:00
|
|
|
// Get an ID that's unique within this process.
|
|
|
|
static int32_t createProcessUniqueId() {
|
|
|
|
static volatile int32_t globalCounter = 0;
|
|
|
|
return android_atomic_inc(&globalCounter);
|
|
|
|
}
|
2011-09-17 00:30:26 +00:00
|
|
|
|
2011-09-28 19:13:31 +00:00
|
|
|
SurfaceTexture::SurfaceTexture(GLuint tex, bool allowSynchronousMode,
|
2012-02-23 22:35:13 +00:00
|
|
|
GLenum texTarget, bool useFenceSync, const sp<BufferQueue> &bufferQueue) :
|
2011-02-18 19:02:42 +00:00
|
|
|
mCurrentTransform(0),
|
|
|
|
mCurrentTimestamp(0),
|
2011-04-22 01:52:51 +00:00
|
|
|
mTexName(tex),
|
2011-11-14 22:51:01 +00:00
|
|
|
#ifdef USE_FENCE_SYNC
|
|
|
|
mUseFenceSync(useFenceSync),
|
|
|
|
#else
|
|
|
|
mUseFenceSync(false),
|
|
|
|
#endif
|
2012-01-22 23:26:27 +00:00
|
|
|
mTexTarget(texTarget),
|
2012-03-20 01:33:05 +00:00
|
|
|
mEglDisplay(EGL_NO_DISPLAY),
|
|
|
|
mEglContext(EGL_NO_CONTEXT),
|
2012-01-22 23:26:27 +00:00
|
|
|
mAbandoned(false),
|
2012-03-29 02:05:54 +00:00
|
|
|
mCurrentTexture(BufferQueue::INVALID_BUFFER_SLOT),
|
|
|
|
mAttached(true)
|
2012-01-22 23:26:27 +00:00
|
|
|
{
|
2012-01-22 23:26:27 +00:00
|
|
|
// Choose a name using the PID and a process-unique ID.
|
|
|
|
mName = String8::format("unnamed-%d-%d", getpid(), createProcessUniqueId());
|
2011-10-19 20:36:31 +00:00
|
|
|
ST_LOGV("SurfaceTexture");
|
2012-02-23 22:35:13 +00:00
|
|
|
if (bufferQueue == 0) {
|
|
|
|
ST_LOGV("Creating a new BufferQueue");
|
|
|
|
mBufferQueue = new BufferQueue(allowSynchronousMode);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mBufferQueue = bufferQueue;
|
|
|
|
}
|
|
|
|
|
2011-09-17 00:30:26 +00:00
|
|
|
memcpy(mCurrentTransformMatrix, mtxIdentity,
|
|
|
|
sizeof(mCurrentTransformMatrix));
|
2012-03-15 21:01:24 +00:00
|
|
|
|
|
|
|
// Note that we can't create an sp<...>(this) in a ctor that will not keep a
|
|
|
|
// reference once the ctor ends, as that would cause the refcount of 'this'
|
|
|
|
// dropping to 0 at the end of the ctor. Since all we need is a wp<...>
|
|
|
|
// that's what we create.
|
|
|
|
wp<BufferQueue::ConsumerListener> listener;
|
|
|
|
sp<BufferQueue::ConsumerListener> proxy;
|
|
|
|
listener = static_cast<BufferQueue::ConsumerListener*>(this);
|
|
|
|
proxy = new BufferQueue::ProxyConsumerListener(listener);
|
|
|
|
|
|
|
|
status_t err = mBufferQueue->consumerConnect(proxy);
|
|
|
|
if (err != NO_ERROR) {
|
|
|
|
ST_LOGE("SurfaceTexture: error connecting to BufferQueue: %s (%d)",
|
|
|
|
strerror(-err), err);
|
|
|
|
} else {
|
|
|
|
mBufferQueue->setConsumerName(mName);
|
|
|
|
}
|
2010-12-20 19:27:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SurfaceTexture::~SurfaceTexture() {
|
2011-10-19 20:36:31 +00:00
|
|
|
ST_LOGV("~SurfaceTexture");
|
2012-02-23 22:35:13 +00:00
|
|
|
|
2012-01-22 23:26:27 +00:00
|
|
|
abandon();
|
2010-12-20 19:27:26 +00:00
|
|
|
}
|
|
|
|
|
2011-05-03 02:51:12 +00:00
|
|
|
status_t SurfaceTexture::setBufferCountServer(int bufferCount) {
|
|
|
|
Mutex::Autolock lock(mMutex);
|
2012-02-23 22:35:13 +00:00
|
|
|
return mBufferQueue->setBufferCountServer(bufferCount);
|
2011-05-03 02:51:12 +00:00
|
|
|
}
|
|
|
|
|
2010-12-20 19:27:26 +00:00
|
|
|
|
2011-04-01 02:10:24 +00:00
|
|
|
status_t SurfaceTexture::setDefaultBufferSize(uint32_t w, uint32_t h)
|
|
|
|
{
|
2012-02-23 22:35:13 +00:00
|
|
|
Mutex::Autolock lock(mMutex);
|
|
|
|
return mBufferQueue->setDefaultBufferSize(w, h);
|
2011-04-01 02:10:24 +00:00
|
|
|
}
|
|
|
|
|
2010-12-20 19:27:26 +00:00
|
|
|
status_t SurfaceTexture::updateTexImage() {
|
2012-02-24 03:27:23 +00:00
|
|
|
ATRACE_CALL();
|
2011-10-19 20:36:31 +00:00
|
|
|
ST_LOGV("updateTexImage");
|
2010-12-20 19:27:26 +00:00
|
|
|
Mutex::Autolock lock(mMutex);
|
|
|
|
|
2012-03-27 03:37:15 +00:00
|
|
|
status_t err = NO_ERROR;
|
|
|
|
|
2011-08-09 02:35:15 +00:00
|
|
|
if (mAbandoned) {
|
2012-03-29 02:05:54 +00:00
|
|
|
ST_LOGE("updateTexImage: SurfaceTexture is abandoned!");
|
2011-08-11 00:35:09 +00:00
|
|
|
return NO_INIT;
|
2011-08-09 02:35:15 +00:00
|
|
|
}
|
|
|
|
|
2012-03-29 02:05:54 +00:00
|
|
|
if (!mAttached) {
|
|
|
|
ST_LOGE("updateTexImage: SurfaceTexture is not attached to an OpenGL "
|
|
|
|
"ES context");
|
|
|
|
return INVALID_OPERATION;
|
|
|
|
}
|
|
|
|
|
2012-03-20 01:33:05 +00:00
|
|
|
EGLDisplay dpy = eglGetCurrentDisplay();
|
|
|
|
EGLContext ctx = eglGetCurrentContext();
|
|
|
|
|
2012-03-29 02:05:54 +00:00
|
|
|
if ((mEglDisplay != dpy && mEglDisplay != EGL_NO_DISPLAY) ||
|
|
|
|
dpy == EGL_NO_DISPLAY) {
|
2012-03-20 01:33:05 +00:00
|
|
|
ST_LOGE("updateTexImage: invalid current EGLDisplay");
|
2012-03-29 02:05:54 +00:00
|
|
|
return INVALID_OPERATION;
|
2012-03-20 01:33:05 +00:00
|
|
|
}
|
|
|
|
|
2012-03-29 02:05:54 +00:00
|
|
|
if ((mEglContext != ctx && mEglContext != EGL_NO_CONTEXT) ||
|
|
|
|
ctx == EGL_NO_CONTEXT) {
|
2012-03-20 01:33:05 +00:00
|
|
|
ST_LOGE("updateTexImage: invalid current EGLContext");
|
2012-03-29 02:05:54 +00:00
|
|
|
return INVALID_OPERATION;
|
2012-03-20 01:33:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mEglDisplay = dpy;
|
|
|
|
mEglContext = ctx;
|
|
|
|
|
2012-02-23 22:35:13 +00:00
|
|
|
BufferQueue::BufferItem item;
|
2012-01-22 23:26:27 +00:00
|
|
|
|
2011-06-27 22:41:52 +00:00
|
|
|
// In asynchronous mode the list is guaranteed to be one buffer
|
|
|
|
// deep, while in synchronous mode we use the oldest buffer.
|
2012-04-10 05:51:52 +00:00
|
|
|
err = mBufferQueue->acquireBuffer(&item);
|
|
|
|
if (err == NO_ERROR) {
|
2012-01-22 23:26:27 +00:00
|
|
|
int buf = item.mBuf;
|
|
|
|
// This buffer was newly allocated, so we need to clean up on our side
|
|
|
|
if (item.mGraphicBuffer != NULL) {
|
|
|
|
mEGLSlots[buf].mGraphicBuffer = 0;
|
|
|
|
if (mEGLSlots[buf].mEglImage != EGL_NO_IMAGE_KHR) {
|
2012-03-20 01:33:05 +00:00
|
|
|
eglDestroyImageKHR(dpy, mEGLSlots[buf].mEglImage);
|
2012-01-22 23:26:27 +00:00
|
|
|
mEGLSlots[buf].mEglImage = EGL_NO_IMAGE_KHR;
|
|
|
|
}
|
|
|
|
mEGLSlots[buf].mGraphicBuffer = item.mGraphicBuffer;
|
|
|
|
}
|
2011-04-22 01:52:51 +00:00
|
|
|
|
2011-01-10 00:33:17 +00:00
|
|
|
// Update the GL texture object.
|
2012-01-22 23:26:27 +00:00
|
|
|
EGLImageKHR image = mEGLSlots[buf].mEglImage;
|
2010-12-20 19:27:26 +00:00
|
|
|
if (image == EGL_NO_IMAGE_KHR) {
|
2012-01-22 23:26:27 +00:00
|
|
|
if (item.mGraphicBuffer == 0) {
|
2012-03-29 02:05:54 +00:00
|
|
|
ST_LOGE("updateTexImage: buffer at slot %d is null", buf);
|
2011-08-11 00:35:09 +00:00
|
|
|
return BAD_VALUE;
|
2011-08-09 02:35:15 +00:00
|
|
|
}
|
2012-01-22 23:26:27 +00:00
|
|
|
image = createImage(dpy, item.mGraphicBuffer);
|
|
|
|
mEGLSlots[buf].mEglImage = image;
|
2011-04-26 21:57:40 +00:00
|
|
|
if (image == EGL_NO_IMAGE_KHR) {
|
|
|
|
// NOTE: if dpy was invalid, createImage() is guaranteed to
|
|
|
|
// fail. so we'd end up here.
|
2012-03-29 02:05:54 +00:00
|
|
|
return UNKNOWN_ERROR;
|
2011-04-26 21:57:40 +00:00
|
|
|
}
|
2010-12-20 19:27:26 +00:00
|
|
|
}
|
2011-01-26 19:52:02 +00:00
|
|
|
|
|
|
|
GLint error;
|
|
|
|
while ((error = glGetError()) != GL_NO_ERROR) {
|
2011-09-17 00:30:26 +00:00
|
|
|
ST_LOGW("updateTexImage: clearing GL error: %#04x", error);
|
2011-01-26 19:52:02 +00:00
|
|
|
}
|
2011-04-12 04:19:55 +00:00
|
|
|
|
2011-09-28 19:13:31 +00:00
|
|
|
glBindTexture(mTexTarget, mTexName);
|
|
|
|
glEGLImageTargetTexture2DOES(mTexTarget, (GLeglImageOES)image);
|
2011-04-12 04:19:55 +00:00
|
|
|
|
2011-01-26 19:52:02 +00:00
|
|
|
while ((error = glGetError()) != GL_NO_ERROR) {
|
2012-03-29 02:05:54 +00:00
|
|
|
ST_LOGE("updateTexImage: error binding external texture image %p "
|
|
|
|
"(slot %d): %#04x", image, buf, error);
|
|
|
|
err = UNKNOWN_ERROR;
|
2011-01-26 19:52:02 +00:00
|
|
|
}
|
2012-03-29 02:05:54 +00:00
|
|
|
|
|
|
|
if (err == OK) {
|
|
|
|
err = syncForReleaseLocked(dpy);
|
2010-12-20 19:27:26 +00:00
|
|
|
}
|
2011-01-13 02:30:40 +00:00
|
|
|
|
2012-03-29 02:05:54 +00:00
|
|
|
if (err != OK) {
|
|
|
|
// Release the buffer we just acquired. It's not safe to
|
|
|
|
// release the old buffer, so instead we just drop the new frame.
|
|
|
|
mBufferQueue->releaseBuffer(buf, dpy, mEGLSlots[buf].mFence);
|
|
|
|
mEGLSlots[buf].mFence = EGL_NO_SYNC_KHR;
|
|
|
|
return err;
|
2011-11-14 22:51:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ST_LOGV("updateTexImage: (slot=%d buf=%p) -> (slot=%d buf=%p)",
|
|
|
|
mCurrentTexture,
|
|
|
|
mCurrentTextureBuf != NULL ? mCurrentTextureBuf->handle : 0,
|
2012-01-22 23:26:27 +00:00
|
|
|
buf, item.mGraphicBuffer != NULL ? item.mGraphicBuffer->handle : 0);
|
2011-10-19 20:36:31 +00:00
|
|
|
|
2012-03-27 03:37:15 +00:00
|
|
|
// release old buffer
|
2012-03-29 02:05:54 +00:00
|
|
|
if (mCurrentTexture != BufferQueue::INVALID_BUFFER_SLOT) {
|
2012-03-27 03:37:15 +00:00
|
|
|
status_t status = mBufferQueue->releaseBuffer(mCurrentTexture, dpy, mEGLSlots[mCurrentTexture].mFence);
|
|
|
|
|
2012-03-29 02:05:54 +00:00
|
|
|
mEGLSlots[mCurrentTexture].mFence = EGL_NO_SYNC_KHR;
|
2012-03-27 03:37:15 +00:00
|
|
|
if (status == BufferQueue::STALE_BUFFER_SLOT) {
|
|
|
|
freeBufferLocked(mCurrentTexture);
|
|
|
|
} else if (status != OK) {
|
|
|
|
ST_LOGE("updateTexImage: released invalid buffer");
|
|
|
|
err = status;
|
|
|
|
}
|
2012-03-29 02:05:54 +00:00
|
|
|
}
|
2011-04-22 01:52:51 +00:00
|
|
|
|
2011-01-13 02:30:40 +00:00
|
|
|
// Update the SurfaceTexture state.
|
2011-04-22 01:52:51 +00:00
|
|
|
mCurrentTexture = buf;
|
2012-01-22 23:26:27 +00:00
|
|
|
mCurrentTextureBuf = mEGLSlots[buf].mGraphicBuffer;
|
|
|
|
mCurrentCrop = item.mCrop;
|
|
|
|
mCurrentTransform = item.mTransform;
|
|
|
|
mCurrentScalingMode = item.mScalingMode;
|
|
|
|
mCurrentTimestamp = item.mTimestamp;
|
2011-06-13 00:03:06 +00:00
|
|
|
computeCurrentTransformMatrix();
|
2012-04-10 05:51:52 +00:00
|
|
|
} else {
|
|
|
|
if (err < 0) {
|
|
|
|
ALOGE("updateTexImage failed on acquire %d", err);
|
|
|
|
}
|
2011-04-12 04:19:55 +00:00
|
|
|
// We always bind the texture even if we don't update its contents.
|
2011-09-28 19:13:31 +00:00
|
|
|
glBindTexture(mTexTarget, mTexName);
|
2012-04-10 05:51:52 +00:00
|
|
|
return OK;
|
2010-12-20 19:27:26 +00:00
|
|
|
}
|
2011-06-27 22:41:52 +00:00
|
|
|
|
2012-03-27 03:37:15 +00:00
|
|
|
return err;
|
2010-12-20 19:27:26 +00:00
|
|
|
}
|
|
|
|
|
2012-03-29 02:05:54 +00:00
|
|
|
status_t SurfaceTexture::detachFromContext() {
|
|
|
|
ATRACE_CALL();
|
|
|
|
ST_LOGV("detachFromContext");
|
|
|
|
Mutex::Autolock lock(mMutex);
|
|
|
|
|
|
|
|
if (mAbandoned) {
|
|
|
|
ST_LOGE("detachFromContext: abandoned SurfaceTexture");
|
|
|
|
return NO_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mAttached) {
|
|
|
|
ST_LOGE("detachFromContext: SurfaceTexture is not attached to a "
|
|
|
|
"context");
|
|
|
|
return INVALID_OPERATION;
|
|
|
|
}
|
|
|
|
|
|
|
|
EGLDisplay dpy = eglGetCurrentDisplay();
|
|
|
|
EGLContext ctx = eglGetCurrentContext();
|
|
|
|
|
|
|
|
if (mEglDisplay != dpy && mEglDisplay != EGL_NO_DISPLAY) {
|
|
|
|
ST_LOGE("detachFromContext: invalid current EGLDisplay");
|
|
|
|
return INVALID_OPERATION;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mEglContext != ctx && mEglContext != EGL_NO_CONTEXT) {
|
|
|
|
ST_LOGE("detachFromContext: invalid current EGLContext");
|
|
|
|
return INVALID_OPERATION;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dpy != EGL_NO_DISPLAY && ctx != EGL_NO_CONTEXT) {
|
|
|
|
status_t err = syncForReleaseLocked(dpy);
|
|
|
|
if (err != OK) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
glDeleteTextures(1, &mTexName);
|
|
|
|
}
|
|
|
|
|
|
|
|
mEglDisplay = EGL_NO_DISPLAY;
|
|
|
|
mEglContext = EGL_NO_CONTEXT;
|
|
|
|
mAttached = false;
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t SurfaceTexture::attachToContext(GLuint tex) {
|
|
|
|
ATRACE_CALL();
|
|
|
|
ST_LOGV("attachToContext");
|
|
|
|
Mutex::Autolock lock(mMutex);
|
|
|
|
|
|
|
|
if (mAbandoned) {
|
|
|
|
ST_LOGE("attachToContext: abandoned SurfaceTexture");
|
|
|
|
return NO_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mAttached) {
|
|
|
|
ST_LOGE("attachToContext: SurfaceTexture is already attached to a "
|
|
|
|
"context");
|
|
|
|
return INVALID_OPERATION;
|
|
|
|
}
|
|
|
|
|
|
|
|
EGLDisplay dpy = eglGetCurrentDisplay();
|
|
|
|
EGLContext ctx = eglGetCurrentContext();
|
|
|
|
|
|
|
|
if (dpy == EGL_NO_DISPLAY) {
|
|
|
|
ST_LOGE("attachToContext: invalid current EGLDisplay");
|
|
|
|
return INVALID_OPERATION;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ctx == EGL_NO_CONTEXT) {
|
|
|
|
ST_LOGE("attachToContext: invalid current EGLContext");
|
|
|
|
return INVALID_OPERATION;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We need to bind the texture regardless of whether there's a current
|
|
|
|
// buffer.
|
|
|
|
glBindTexture(mTexTarget, tex);
|
|
|
|
|
|
|
|
if (mCurrentTextureBuf != NULL) {
|
|
|
|
// If the current buffer is no longer associated with a slot, then it
|
|
|
|
// doesn't have an EGLImage. In that case we create one now, but we also
|
|
|
|
// destroy it once we've used it to attach the buffer to the OpenGL ES
|
|
|
|
// texture.
|
|
|
|
bool imageNeedsDestroy = false;
|
|
|
|
EGLImageKHR image = EGL_NO_IMAGE_KHR;
|
|
|
|
if (mCurrentTexture != BufferQueue::INVALID_BUFFER_SLOT) {
|
|
|
|
image = mEGLSlots[mCurrentTexture].mEglImage;
|
|
|
|
imageNeedsDestroy = false;
|
|
|
|
} else {
|
|
|
|
image = createImage(dpy, mCurrentTextureBuf);
|
|
|
|
if (image == EGL_NO_IMAGE_KHR) {
|
|
|
|
return UNKNOWN_ERROR;
|
|
|
|
}
|
|
|
|
imageNeedsDestroy = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attach the current buffer to the GL texture.
|
|
|
|
glEGLImageTargetTexture2DOES(mTexTarget, (GLeglImageOES)image);
|
|
|
|
|
|
|
|
GLint error;
|
|
|
|
status_t err = OK;
|
|
|
|
while ((error = glGetError()) != GL_NO_ERROR) {
|
|
|
|
ST_LOGE("attachToContext: error binding external texture image %p "
|
|
|
|
"(slot %d): %#04x", image, mCurrentTexture, error);
|
|
|
|
err = UNKNOWN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (imageNeedsDestroy) {
|
|
|
|
eglDestroyImageKHR(dpy, image);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err != OK) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mEglDisplay = dpy;
|
|
|
|
mEglContext = ctx;
|
|
|
|
mTexName = tex;
|
|
|
|
mAttached = true;
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t SurfaceTexture::syncForReleaseLocked(EGLDisplay dpy) {
|
|
|
|
ST_LOGV("syncForReleaseLocked");
|
|
|
|
|
|
|
|
if (mUseFenceSync && mCurrentTexture != BufferQueue::INVALID_BUFFER_SLOT) {
|
|
|
|
EGLSyncKHR fence = mEGLSlots[mCurrentTexture].mFence;
|
|
|
|
if (fence != EGL_NO_SYNC_KHR) {
|
|
|
|
// There is already a fence for the current slot. We need to wait
|
|
|
|
// on that before replacing it with another fence to ensure that all
|
|
|
|
// outstanding buffer accesses have completed before the producer
|
|
|
|
// accesses it.
|
|
|
|
EGLint result = eglClientWaitSyncKHR(dpy, fence, 0, 1000000000);
|
|
|
|
if (result == EGL_FALSE) {
|
|
|
|
ST_LOGE("syncForReleaseLocked: error waiting for previous "
|
|
|
|
"fence: %#x", eglGetError());
|
|
|
|
return UNKNOWN_ERROR;
|
|
|
|
} else if (result == EGL_TIMEOUT_EXPIRED_KHR) {
|
|
|
|
ST_LOGE("syncForReleaseLocked: timeout waiting for previous "
|
|
|
|
"fence");
|
|
|
|
return TIMED_OUT;
|
|
|
|
}
|
|
|
|
eglDestroySyncKHR(dpy, fence);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a fence for the outstanding accesses in the current OpenGL ES
|
|
|
|
// context.
|
|
|
|
fence = eglCreateSyncKHR(dpy, EGL_SYNC_FENCE_KHR, NULL);
|
|
|
|
if (fence == EGL_NO_SYNC_KHR) {
|
|
|
|
ST_LOGE("syncForReleaseLocked: error creating fence: %#x",
|
|
|
|
eglGetError());
|
|
|
|
return UNKNOWN_ERROR;
|
|
|
|
}
|
|
|
|
glFlush();
|
|
|
|
mEGLSlots[mCurrentTexture].mFence = fence;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2011-04-12 04:19:55 +00:00
|
|
|
bool SurfaceTexture::isExternalFormat(uint32_t format)
|
|
|
|
{
|
|
|
|
switch (format) {
|
|
|
|
// supported YUV formats
|
|
|
|
case HAL_PIXEL_FORMAT_YV12:
|
|
|
|
// Legacy/deprecated YUV formats
|
|
|
|
case HAL_PIXEL_FORMAT_YCbCr_422_SP:
|
|
|
|
case HAL_PIXEL_FORMAT_YCrCb_420_SP:
|
|
|
|
case HAL_PIXEL_FORMAT_YCbCr_422_I:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Any OEM format needs to be considered
|
|
|
|
if (format>=0x100 && format<=0x1FF)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
GLenum SurfaceTexture::getCurrentTextureTarget() const {
|
2011-09-28 19:13:31 +00:00
|
|
|
return mTexTarget;
|
2011-04-12 04:19:55 +00:00
|
|
|
}
|
|
|
|
|
2011-01-10 00:33:17 +00:00
|
|
|
void SurfaceTexture::getTransformMatrix(float mtx[16]) {
|
|
|
|
Mutex::Autolock lock(mMutex);
|
2011-06-13 00:03:06 +00:00
|
|
|
memcpy(mtx, mCurrentTransformMatrix, sizeof(mCurrentTransformMatrix));
|
|
|
|
}
|
|
|
|
|
|
|
|
void SurfaceTexture::computeCurrentTransformMatrix() {
|
2011-10-19 20:36:31 +00:00
|
|
|
ST_LOGV("computeCurrentTransformMatrix");
|
2011-01-10 00:33:17 +00:00
|
|
|
|
2011-01-14 21:53:31 +00:00
|
|
|
float xform[16];
|
|
|
|
for (int i = 0; i < 16; i++) {
|
|
|
|
xform[i] = mtxIdentity[i];
|
|
|
|
}
|
|
|
|
if (mCurrentTransform & NATIVE_WINDOW_TRANSFORM_FLIP_H) {
|
|
|
|
float result[16];
|
|
|
|
mtxMul(result, xform, mtxFlipH);
|
|
|
|
for (int i = 0; i < 16; i++) {
|
|
|
|
xform[i] = result[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mCurrentTransform & NATIVE_WINDOW_TRANSFORM_FLIP_V) {
|
|
|
|
float result[16];
|
|
|
|
mtxMul(result, xform, mtxFlipV);
|
|
|
|
for (int i = 0; i < 16; i++) {
|
|
|
|
xform[i] = result[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mCurrentTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) {
|
|
|
|
float result[16];
|
|
|
|
mtxMul(result, xform, mtxRot90);
|
|
|
|
for (int i = 0; i < 16; i++) {
|
|
|
|
xform[i] = result[i];
|
|
|
|
}
|
2011-01-10 00:33:17 +00:00
|
|
|
}
|
|
|
|
|
2012-01-22 23:26:27 +00:00
|
|
|
sp<GraphicBuffer>& buf(mCurrentTextureBuf);
|
2011-01-14 21:53:31 +00:00
|
|
|
float tx, ty, sx, sy;
|
|
|
|
if (!mCurrentCrop.isEmpty()) {
|
2011-03-11 00:24:46 +00:00
|
|
|
// In order to prevent bilinear sampling at the of the crop rectangle we
|
|
|
|
// may need to shrink it by 2 texels in each direction. Normally this
|
|
|
|
// would just need to take 1/2 a texel off each end, but because the
|
|
|
|
// chroma channels will likely be subsampled we need to chop off a whole
|
|
|
|
// texel. This will cause artifacts if someone does nearest sampling
|
|
|
|
// with 1:1 pixel:texel ratio, but it's impossible to simultaneously
|
|
|
|
// accomodate the bilinear and nearest sampling uses.
|
|
|
|
//
|
|
|
|
// If nearest sampling turns out to be a desirable usage of these
|
|
|
|
// textures then we could add the ability to switch a SurfaceTexture to
|
|
|
|
// nearest-mode. Preferably, however, the image producers (video
|
|
|
|
// decoder, camera, etc.) would simply not use a crop rectangle (or at
|
|
|
|
// least not tell the framework about it) so that the GPU can do the
|
|
|
|
// correct edge behavior.
|
|
|
|
int xshrink = 0, yshrink = 0;
|
|
|
|
if (mCurrentCrop.left > 0) {
|
|
|
|
tx = float(mCurrentCrop.left + 1) / float(buf->getWidth());
|
|
|
|
xshrink++;
|
|
|
|
} else {
|
|
|
|
tx = 0.0f;
|
|
|
|
}
|
2011-04-01 02:10:24 +00:00
|
|
|
if (mCurrentCrop.right < int32_t(buf->getWidth())) {
|
2011-03-11 00:24:46 +00:00
|
|
|
xshrink++;
|
|
|
|
}
|
2011-04-01 02:10:24 +00:00
|
|
|
if (mCurrentCrop.bottom < int32_t(buf->getHeight())) {
|
2011-03-11 00:24:46 +00:00
|
|
|
ty = (float(buf->getHeight() - mCurrentCrop.bottom) + 1.0f) /
|
|
|
|
float(buf->getHeight());
|
|
|
|
yshrink++;
|
|
|
|
} else {
|
|
|
|
ty = 0.0f;
|
|
|
|
}
|
|
|
|
if (mCurrentCrop.top > 0) {
|
|
|
|
yshrink++;
|
|
|
|
}
|
|
|
|
sx = float(mCurrentCrop.width() - xshrink) / float(buf->getWidth());
|
|
|
|
sy = float(mCurrentCrop.height() - yshrink) / float(buf->getHeight());
|
2011-01-14 21:53:31 +00:00
|
|
|
} else {
|
|
|
|
tx = 0.0f;
|
|
|
|
ty = 0.0f;
|
|
|
|
sx = 1.0f;
|
|
|
|
sy = 1.0f;
|
|
|
|
}
|
2011-01-10 00:33:17 +00:00
|
|
|
float crop[16] = {
|
2011-01-14 21:53:31 +00:00
|
|
|
sx, 0, 0, 0,
|
|
|
|
0, sy, 0, 0,
|
2011-01-10 00:33:17 +00:00
|
|
|
0, 0, 1, 0,
|
2011-03-11 00:24:46 +00:00
|
|
|
tx, ty, 0, 1,
|
2011-01-10 00:33:17 +00:00
|
|
|
};
|
|
|
|
|
2011-01-14 21:53:31 +00:00
|
|
|
float mtxBeforeFlipV[16];
|
|
|
|
mtxMul(mtxBeforeFlipV, crop, xform);
|
|
|
|
|
|
|
|
// SurfaceFlinger expects the top of its window textures to be at a Y
|
|
|
|
// coordinate of 0, so SurfaceTexture must behave the same way. We don't
|
|
|
|
// want to expose this to applications, however, so we must add an
|
|
|
|
// additional vertical flip to the transform after all the other transforms.
|
2011-06-13 00:03:06 +00:00
|
|
|
mtxMul(mCurrentTransformMatrix, mtxFlipV, mtxBeforeFlipV);
|
2011-01-10 00:33:17 +00:00
|
|
|
}
|
|
|
|
|
2011-02-18 19:02:42 +00:00
|
|
|
nsecs_t SurfaceTexture::getTimestamp() {
|
2011-10-19 20:36:31 +00:00
|
|
|
ST_LOGV("getTimestamp");
|
2011-02-18 19:02:42 +00:00
|
|
|
Mutex::Autolock lock(mMutex);
|
|
|
|
return mCurrentTimestamp;
|
|
|
|
}
|
|
|
|
|
2011-01-13 22:43:36 +00:00
|
|
|
void SurfaceTexture::setFrameAvailableListener(
|
2011-06-24 16:56:27 +00:00
|
|
|
const sp<FrameAvailableListener>& listener) {
|
2011-10-19 20:36:31 +00:00
|
|
|
ST_LOGV("setFrameAvailableListener");
|
2011-01-13 22:43:36 +00:00
|
|
|
Mutex::Autolock lock(mMutex);
|
2012-03-15 21:01:24 +00:00
|
|
|
mFrameAvailableListener = listener;
|
2011-01-13 22:43:36 +00:00
|
|
|
}
|
|
|
|
|
2010-12-20 19:27:26 +00:00
|
|
|
EGLImageKHR SurfaceTexture::createImage(EGLDisplay dpy,
|
|
|
|
const sp<GraphicBuffer>& graphicBuffer) {
|
|
|
|
EGLClientBuffer cbuf = (EGLClientBuffer)graphicBuffer->getNativeBuffer();
|
|
|
|
EGLint attrs[] = {
|
|
|
|
EGL_IMAGE_PRESERVED_KHR, EGL_TRUE,
|
|
|
|
EGL_NONE,
|
|
|
|
};
|
|
|
|
EGLImageKHR image = eglCreateImageKHR(dpy, EGL_NO_CONTEXT,
|
|
|
|
EGL_NATIVE_BUFFER_ANDROID, cbuf, attrs);
|
2011-04-26 21:57:40 +00:00
|
|
|
if (image == EGL_NO_IMAGE_KHR) {
|
|
|
|
EGLint error = eglGetError();
|
2011-09-17 00:30:26 +00:00
|
|
|
ST_LOGE("error creating EGLImage: %#x", error);
|
2010-12-20 19:27:26 +00:00
|
|
|
}
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
2011-04-12 04:19:55 +00:00
|
|
|
sp<GraphicBuffer> SurfaceTexture::getCurrentBuffer() const {
|
|
|
|
Mutex::Autolock lock(mMutex);
|
|
|
|
return mCurrentTextureBuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect SurfaceTexture::getCurrentCrop() const {
|
|
|
|
Mutex::Autolock lock(mMutex);
|
|
|
|
return mCurrentCrop;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t SurfaceTexture::getCurrentTransform() const {
|
|
|
|
Mutex::Autolock lock(mMutex);
|
|
|
|
return mCurrentTransform;
|
|
|
|
}
|
|
|
|
|
2011-07-13 22:24:42 +00:00
|
|
|
uint32_t SurfaceTexture::getCurrentScalingMode() const {
|
|
|
|
Mutex::Autolock lock(mMutex);
|
|
|
|
return mCurrentScalingMode;
|
|
|
|
}
|
|
|
|
|
2011-11-20 02:04:43 +00:00
|
|
|
bool SurfaceTexture::isSynchronousMode() const {
|
|
|
|
Mutex::Autolock lock(mMutex);
|
2012-02-23 22:35:13 +00:00
|
|
|
return mBufferQueue->isSynchronousMode();
|
2011-11-20 02:04:43 +00:00
|
|
|
}
|
|
|
|
|
2012-03-15 21:01:24 +00:00
|
|
|
void SurfaceTexture::freeBufferLocked(int slotIndex) {
|
|
|
|
ST_LOGV("freeBufferLocked: slotIndex=%d", slotIndex);
|
|
|
|
mEGLSlots[slotIndex].mGraphicBuffer = 0;
|
2012-03-27 03:37:15 +00:00
|
|
|
if (slotIndex == mCurrentTexture) {
|
|
|
|
mCurrentTexture = BufferQueue::INVALID_BUFFER_SLOT;
|
|
|
|
}
|
2012-03-15 21:01:24 +00:00
|
|
|
if (mEGLSlots[slotIndex].mEglImage != EGL_NO_IMAGE_KHR) {
|
|
|
|
EGLImageKHR img = mEGLSlots[slotIndex].mEglImage;
|
|
|
|
if (img != EGL_NO_IMAGE_KHR) {
|
2012-03-20 01:33:05 +00:00
|
|
|
eglDestroyImageKHR(mEglDisplay, img);
|
2012-03-15 21:01:24 +00:00
|
|
|
}
|
|
|
|
mEGLSlots[slotIndex].mEglImage = EGL_NO_IMAGE_KHR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-19 19:08:33 +00:00
|
|
|
void SurfaceTexture::abandon() {
|
2012-03-15 21:01:24 +00:00
|
|
|
ST_LOGV("abandon");
|
2011-07-19 19:08:33 +00:00
|
|
|
Mutex::Autolock lock(mMutex);
|
2012-03-15 21:01:24 +00:00
|
|
|
|
|
|
|
if (!mAbandoned) {
|
|
|
|
mAbandoned = true;
|
|
|
|
mCurrentTextureBuf.clear();
|
|
|
|
|
|
|
|
// destroy all egl buffers
|
|
|
|
for (int i =0; i < BufferQueue::NUM_BUFFER_SLOTS; i++) {
|
|
|
|
freeBufferLocked(i);
|
2012-01-22 23:26:27 +00:00
|
|
|
}
|
|
|
|
|
2012-03-15 21:01:24 +00:00
|
|
|
// disconnect from the BufferQueue
|
|
|
|
mBufferQueue->consumerDisconnect();
|
|
|
|
mBufferQueue.clear();
|
|
|
|
}
|
2011-07-19 19:08:33 +00:00
|
|
|
}
|
|
|
|
|
2011-09-17 00:30:26 +00:00
|
|
|
void SurfaceTexture::setName(const String8& name) {
|
2012-01-22 23:26:27 +00:00
|
|
|
Mutex::Autolock _l(mMutex);
|
2011-09-17 00:30:26 +00:00
|
|
|
mName = name;
|
2012-02-23 22:35:13 +00:00
|
|
|
mBufferQueue->setConsumerName(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t SurfaceTexture::setDefaultBufferFormat(uint32_t defaultFormat) {
|
|
|
|
Mutex::Autolock lock(mMutex);
|
|
|
|
return mBufferQueue->setDefaultBufferFormat(defaultFormat);
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t SurfaceTexture::setConsumerUsageBits(uint32_t usage) {
|
|
|
|
Mutex::Autolock lock(mMutex);
|
|
|
|
return mBufferQueue->setConsumerUsageBits(usage);
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t SurfaceTexture::setTransformHint(uint32_t hint) {
|
|
|
|
Mutex::Autolock lock(mMutex);
|
|
|
|
return mBufferQueue->setTransformHint(hint);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Used for refactoring BufferQueue from SurfaceTexture
|
|
|
|
// Should not be in final interface once users of SurfaceTexture are clean up.
|
|
|
|
status_t SurfaceTexture::setSynchronousMode(bool enabled) {
|
|
|
|
Mutex::Autolock lock(mMutex);
|
|
|
|
return mBufferQueue->setSynchronousMode(enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Used for refactoring, should not be in final interface
|
|
|
|
sp<BufferQueue> SurfaceTexture::getBufferQueue() const {
|
|
|
|
Mutex::Autolock lock(mMutex);
|
|
|
|
return mBufferQueue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Used for refactoring, should not be in final interface
|
|
|
|
status_t SurfaceTexture::connect(int api,
|
|
|
|
uint32_t* outWidth, uint32_t* outHeight, uint32_t* outTransform) {
|
|
|
|
Mutex::Autolock lock(mMutex);
|
|
|
|
return mBufferQueue->connect(api, outWidth, outHeight, outTransform);
|
2011-09-17 00:30:26 +00:00
|
|
|
}
|
|
|
|
|
2012-03-15 21:01:24 +00:00
|
|
|
void SurfaceTexture::onFrameAvailable() {
|
|
|
|
ST_LOGV("onFrameAvailable");
|
|
|
|
|
|
|
|
sp<FrameAvailableListener> listener;
|
|
|
|
{ // scope for the lock
|
|
|
|
Mutex::Autolock lock(mMutex);
|
|
|
|
listener = mFrameAvailableListener;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (listener != NULL) {
|
|
|
|
ST_LOGV("actually calling onFrameAvailable");
|
|
|
|
listener->onFrameAvailable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SurfaceTexture::onBuffersReleased() {
|
|
|
|
ST_LOGV("onBuffersReleased");
|
|
|
|
|
|
|
|
Mutex::Autolock lock(mMutex);
|
|
|
|
|
|
|
|
if (mAbandoned) {
|
|
|
|
// Nothing to do if we're already abandoned.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t mask = 0;
|
|
|
|
mBufferQueue->getReleasedBuffers(&mask);
|
|
|
|
for (int i = 0; i < BufferQueue::NUM_BUFFER_SLOTS; i++) {
|
|
|
|
if (mask & (1 << i)) {
|
|
|
|
freeBufferLocked(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-10 02:08:33 +00:00
|
|
|
void SurfaceTexture::dump(String8& result) const
|
|
|
|
{
|
|
|
|
char buffer[1024];
|
|
|
|
dump(result, "", buffer, 1024);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SurfaceTexture::dump(String8& result, const char* prefix,
|
|
|
|
char* buffer, size_t SIZE) const
|
|
|
|
{
|
|
|
|
Mutex::Autolock _l(mMutex);
|
2012-03-15 21:01:24 +00:00
|
|
|
snprintf(buffer, SIZE, "%smTexName=%d, mAbandoned=%d\n", prefix, mTexName,
|
|
|
|
int(mAbandoned));
|
2011-05-10 02:08:33 +00:00
|
|
|
result.append(buffer);
|
|
|
|
|
|
|
|
snprintf(buffer, SIZE,
|
2012-03-15 21:01:24 +00:00
|
|
|
"%snext : {crop=[%d,%d,%d,%d], transform=0x%02x, current=%d}\n",
|
|
|
|
prefix, mCurrentCrop.left,
|
2011-05-10 02:08:33 +00:00
|
|
|
mCurrentCrop.top, mCurrentCrop.right, mCurrentCrop.bottom,
|
2012-01-22 23:26:27 +00:00
|
|
|
mCurrentTransform, mCurrentTexture
|
2011-05-10 02:08:33 +00:00
|
|
|
);
|
|
|
|
result.append(buffer);
|
|
|
|
|
2012-03-15 21:01:24 +00:00
|
|
|
if (!mAbandoned) {
|
|
|
|
mBufferQueue->dump(result, prefix, buffer, SIZE);
|
|
|
|
}
|
2011-05-10 02:08:33 +00:00
|
|
|
}
|
|
|
|
|
2011-01-10 00:33:17 +00:00
|
|
|
static void mtxMul(float out[16], const float a[16], const float b[16]) {
|
|
|
|
out[0] = a[0]*b[0] + a[4]*b[1] + a[8]*b[2] + a[12]*b[3];
|
|
|
|
out[1] = a[1]*b[0] + a[5]*b[1] + a[9]*b[2] + a[13]*b[3];
|
|
|
|
out[2] = a[2]*b[0] + a[6]*b[1] + a[10]*b[2] + a[14]*b[3];
|
|
|
|
out[3] = a[3]*b[0] + a[7]*b[1] + a[11]*b[2] + a[15]*b[3];
|
|
|
|
|
|
|
|
out[4] = a[0]*b[4] + a[4]*b[5] + a[8]*b[6] + a[12]*b[7];
|
|
|
|
out[5] = a[1]*b[4] + a[5]*b[5] + a[9]*b[6] + a[13]*b[7];
|
|
|
|
out[6] = a[2]*b[4] + a[6]*b[5] + a[10]*b[6] + a[14]*b[7];
|
|
|
|
out[7] = a[3]*b[4] + a[7]*b[5] + a[11]*b[6] + a[15]*b[7];
|
|
|
|
|
|
|
|
out[8] = a[0]*b[8] + a[4]*b[9] + a[8]*b[10] + a[12]*b[11];
|
|
|
|
out[9] = a[1]*b[8] + a[5]*b[9] + a[9]*b[10] + a[13]*b[11];
|
|
|
|
out[10] = a[2]*b[8] + a[6]*b[9] + a[10]*b[10] + a[14]*b[11];
|
|
|
|
out[11] = a[3]*b[8] + a[7]*b[9] + a[11]*b[10] + a[15]*b[11];
|
|
|
|
|
|
|
|
out[12] = a[0]*b[12] + a[4]*b[13] + a[8]*b[14] + a[12]*b[15];
|
|
|
|
out[13] = a[1]*b[12] + a[5]*b[13] + a[9]*b[14] + a[13]*b[15];
|
|
|
|
out[14] = a[2]*b[12] + a[6]*b[13] + a[10]*b[14] + a[14]*b[15];
|
|
|
|
out[15] = a[3]*b[12] + a[7]*b[13] + a[11]*b[14] + a[15]*b[15];
|
|
|
|
}
|
|
|
|
|
2010-12-20 19:27:26 +00:00
|
|
|
}; // namespace android
|