Merge "Fix SurfaceTexture transform matrix." into honeycomb

This commit is contained in:
Jamie Gennis 2011-01-16 18:14:07 -08:00 committed by Android (Google) Code Review
commit db088f67b5

View File

@ -237,43 +237,61 @@ void SurfaceTexture::getTransformMatrix(float mtx[16]) {
LOGV("SurfaceTexture::updateTexImage"); LOGV("SurfaceTexture::updateTexImage");
Mutex::Autolock lock(mMutex); Mutex::Autolock lock(mMutex);
float* xform = mtxIdentity; float xform[16];
switch (mCurrentTransform) { for (int i = 0; i < 16; i++) {
case 0: xform[i] = mtxIdentity[i];
xform = mtxIdentity; }
break; if (mCurrentTransform & NATIVE_WINDOW_TRANSFORM_FLIP_H) {
case NATIVE_WINDOW_TRANSFORM_FLIP_H: float result[16];
xform = mtxFlipH; mtxMul(result, xform, mtxFlipH);
break; for (int i = 0; i < 16; i++) {
case NATIVE_WINDOW_TRANSFORM_FLIP_V: xform[i] = result[i];
xform = mtxFlipV; }
break; }
case NATIVE_WINDOW_TRANSFORM_ROT_90: if (mCurrentTransform & NATIVE_WINDOW_TRANSFORM_FLIP_V) {
xform = mtxRot90; float result[16];
break; mtxMul(result, xform, mtxFlipV);
case NATIVE_WINDOW_TRANSFORM_ROT_180: for (int i = 0; i < 16; i++) {
xform = mtxRot180; xform[i] = result[i];
break; }
case NATIVE_WINDOW_TRANSFORM_ROT_270: }
xform = mtxRot270; if (mCurrentTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) {
break; float result[16];
default: mtxMul(result, xform, mtxRot90);
LOGE("getTransformMatrix: unknown transform: %d", mCurrentTransform); for (int i = 0; i < 16; i++) {
xform[i] = result[i];
}
} }
sp<GraphicBuffer>& buf(mSlots[mCurrentTexture].mGraphicBuffer); sp<GraphicBuffer>& buf(mSlots[mCurrentTexture].mGraphicBuffer);
float tx = float(mCurrentCrop.left) / float(buf->getWidth()); float tx, ty, sx, sy;
float ty = float(mCurrentCrop.bottom) / float(buf->getHeight()); if (!mCurrentCrop.isEmpty()) {
float sx = float(mCurrentCrop.width()) / float(buf->getWidth()); tx = float(mCurrentCrop.left) / float(buf->getWidth());
float sy = float(mCurrentCrop.height()) / float(buf->getHeight()); ty = float(buf->getHeight() - mCurrentCrop.bottom) /
float(buf->getHeight());
sx = float(mCurrentCrop.width()) / float(buf->getWidth());
sy = float(mCurrentCrop.height()) / float(buf->getHeight());
} else {
tx = 0.0f;
ty = 0.0f;
sx = 1.0f;
sy = 1.0f;
}
float crop[16] = { float crop[16] = {
sx, 0, 0, sx*tx, sx, 0, 0, 0,
0, sy, 0, sy*ty, 0, sy, 0, 0,
0, 0, 1, 0, 0, 0, 1, 0,
0, 0, 0, 1, sx*tx, sy*ty, 0, 1,
}; };
mtxMul(mtx, crop, xform); 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.
mtxMul(mtx, mtxFlipV, mtxBeforeFlipV);
} }
void SurfaceTexture::freeAllBuffers() { void SurfaceTexture::freeAllBuffers() {