Fix libgui crop matrix test.

On devices that have the crop image extension the crop is not applied to the
transform matrix so we have to expect different results in this case.

Change-Id: If62dec1111fb77c9fa2c4332d121665960ce0216
This commit is contained in:
Michael Lentine 2015-05-29 16:05:36 -07:00
parent 1c4537e2e8
commit 04b00cea67
1 changed files with 23 additions and 6 deletions

View File

@ -27,6 +27,9 @@
#include <utils/Log.h>
#include <utils/Thread.h>
EGLAPI const char* eglQueryStringImplementationANDROID(EGLDisplay dpy, EGLint name);
#define CROP_EXT_STR "EGL_ANDROID_image_crop"
namespace android {
class SurfaceTextureClientTest : public ::testing::Test {
@ -615,6 +618,18 @@ TEST_F(SurfaceTextureClientTest, GetTransformMatrixSucceedsAfterFreeingBuffers)
}
TEST_F(SurfaceTextureClientTest, GetTransformMatrixSucceedsAfterFreeingBuffersWithCrop) {
// Query to see if the image crop extension exists
EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
const char* exts = eglQueryStringImplementationANDROID(dpy, EGL_EXTENSIONS);
size_t cropExtLen = strlen(CROP_EXT_STR);
size_t extsLen = strlen(exts);
bool equal = !strcmp(CROP_EXT_STR, exts);
bool atStart = !strncmp(CROP_EXT_STR " ", exts, cropExtLen+1);
bool atEnd = (cropExtLen+1) < extsLen &&
!strcmp(" " CROP_EXT_STR, exts + extsLen - (cropExtLen+1));
bool inMiddle = strstr(exts, " " CROP_EXT_STR " ");
bool hasEglAndroidImageCrop = equal || atStart || atEnd || inMiddle;
android_native_buffer_t* buf[3];
float mtx[16] = {};
android_native_rect_t crop;
@ -633,15 +648,17 @@ TEST_F(SurfaceTextureClientTest, GetTransformMatrixSucceedsAfterFreeingBuffersWi
ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 6)); // frees buffers
mST->getTransformMatrix(mtx);
// This accounts for the .5 texel shrink for each edge that's included in the
// transform matrix to avoid texturing outside the crop region.
EXPECT_EQ(0.5, mtx[0]);
// If the egl image crop extension is not present, this accounts for the
// .5 texel shrink for each edge that's included in the transform matrix
// to avoid texturing outside the crop region. Otherwise the crop is not
// included in the transform matrix.
EXPECT_EQ(hasEglAndroidImageCrop ? 1 : 0.5, mtx[0]);
EXPECT_EQ(0.f, mtx[1]);
EXPECT_EQ(0.f, mtx[2]);
EXPECT_EQ(0.f, mtx[3]);
EXPECT_EQ(0.f, mtx[4]);
EXPECT_EQ(-0.5, mtx[5]);
EXPECT_EQ(hasEglAndroidImageCrop ? -1 : -0.5, mtx[5]);
EXPECT_EQ(0.f, mtx[6]);
EXPECT_EQ(0.f, mtx[7]);
@ -650,8 +667,8 @@ TEST_F(SurfaceTextureClientTest, GetTransformMatrixSucceedsAfterFreeingBuffersWi
EXPECT_EQ(1.f, mtx[10]);
EXPECT_EQ(0.f, mtx[11]);
EXPECT_EQ(0.0625f, mtx[12]);
EXPECT_EQ(0.5625f, mtx[13]);
EXPECT_EQ(hasEglAndroidImageCrop ? 0 : 0.0625f, mtx[12]);
EXPECT_EQ(hasEglAndroidImageCrop ? 1 : 0.5625f, mtx[13]);
EXPECT_EQ(0.f, mtx[14]);
EXPECT_EQ(1.f, mtx[15]);
}