Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d99c088f authored by Jamie Gennis's avatar Jamie Gennis
Browse files

SurfaceTexture: fix transform matrix computation.

This change fixes the transform matrix computation in SurfaceTexture
when a crop rectangle is specified by the image producer.  It also adds
a test for this case as well as a basic test for the uncropped case.

Bug: 4070775
Change-Id: I1481c9ce9d08fe7f2bff86d3afdeab7d4002b157
parent 181f1c33
Loading
Loading
Loading
Loading
+37 −6
Original line number Original line Diff line number Diff line
@@ -283,11 +283,42 @@ void SurfaceTexture::getTransformMatrix(float mtx[16]) {
    sp<GraphicBuffer>& buf(mSlots[mCurrentTexture].mGraphicBuffer);
    sp<GraphicBuffer>& buf(mSlots[mCurrentTexture].mGraphicBuffer);
    float tx, ty, sx, sy;
    float tx, ty, sx, sy;
    if (!mCurrentCrop.isEmpty()) {
    if (!mCurrentCrop.isEmpty()) {
        tx = float(mCurrentCrop.left) / float(buf->getWidth());
        // In order to prevent bilinear sampling at the of the crop rectangle we
        ty = float(buf->getHeight() - mCurrentCrop.bottom) /
        // 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;
        }
        if (mCurrentCrop.right < buf->getWidth()) {
            xshrink++;
        }
        if (mCurrentCrop.bottom < buf->getHeight()) {
            ty = (float(buf->getHeight() - mCurrentCrop.bottom) + 1.0f) /
                    float(buf->getHeight());
                    float(buf->getHeight());
        sx = float(mCurrentCrop.width()) / float(buf->getWidth());
            yshrink++;
        sy = float(mCurrentCrop.height()) / float(buf->getHeight());
        } 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());
    } else {
    } else {
        tx = 0.0f;
        tx = 0.0f;
        ty = 0.0f;
        ty = 0.0f;
@@ -298,7 +329,7 @@ void SurfaceTexture::getTransformMatrix(float mtx[16]) {
        sx, 0, 0, 0,
        sx, 0, 0, 0,
        0, sy, 0, 0,
        0, sy, 0, 0,
        0, 0, 1, 0,
        0, 0, 1, 0,
        sx*tx, sy*ty, 0, 1,
        tx, ty, 0, 1,
    };
    };


    float mtxBeforeFlipV[16];
    float mtxBeforeFlipV[16];
+17 −19
Original line number Original line Diff line number Diff line
@@ -4,39 +4,37 @@ include $(CLEAR_VARS)


ifneq ($(TARGET_SIMULATOR),true)
ifneq ($(TARGET_SIMULATOR),true)


# Build the unit tests.
LOCAL_MODULE := SurfaceTexture_test
test_src_files := \

LOCAL_MODULE_TAGS := tests

LOCAL_SRC_FILES := \
    SurfaceTextureClient_test.cpp \
    SurfaceTextureClient_test.cpp \
    SurfaceTexture_test.cpp \


shared_libraries := \
LOCAL_SHARED_LIBRARIES := \
	libcutils \
	libEGL \
	libutils \
	libGLESv2 \
	libandroid \
	libbinder \
	libbinder \
	libcutils \
	libgui \
	libgui \
	libstlport \
	libstlport \
	libsurfaceflinger_client \
	libui \
	libutils \


static_libraries := \
LOCAL_STATIC_LIBRARIES := \
	libgtest \
	libgtest \
	libgtest_main \
	libgtest_main \


c_includes := \
LOCAL_C_INCLUDES := \
    bionic \
    bionic \
    bionic/libstdc++/include \
    bionic/libstdc++/include \
    external/gtest/include \
    external/gtest/include \
    external/stlport/stlport \
    external/stlport/stlport \


module_tags := tests
include $(BUILD_EXECUTABLE)

$(foreach file,$(test_src_files), \
    $(eval include $(CLEAR_VARS)) \
    $(eval LOCAL_SHARED_LIBRARIES := $(shared_libraries)) \
    $(eval LOCAL_STATIC_LIBRARIES := $(static_libraries)) \
    $(eval LOCAL_C_INCLUDES := $(c_includes)) \
    $(eval LOCAL_SRC_FILES := $(file)) \
    $(eval LOCAL_MODULE := $(notdir $(file:%.cpp=%))) \
    $(eval LOCAL_MODULE_TAGS := $(module_tags)) \
    $(eval include $(BUILD_EXECUTABLE)) \
)


# Build the manual test programs.
# Build the manual test programs.
include $(call all-subdir-makefiles)
include $(call all-subdir-makefiles)
+621 −0

File added.

Preview size limit exceeded, changes collapsed.