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

Commit 9c5a3335 authored by Alan Viverette's avatar Alan Viverette
Browse files

Add API for pushing color transforms to SurfaceFlinger

BUG: 9057596
Change-Id: Iea0953366eac875b7968897a75472c25a137edb5
parent cf1eb71a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -169,7 +169,7 @@ String8 ProgramCache::generateFragmentShader(const Key& needs) {
            fs << "gl_FragColor.rgb = gl_FragColor.rgb/gl_FragColor.a;";
        }
        fs << "gl_FragColor.rgb = pow(gl_FragColor.rgb, vec3(2.2));";
        fs << "gl_FragColor     = colorMatrix*gl_FragColor;";
        fs << "gl_FragColor.rgb = mat3(colorMatrix) * gl_FragColor.rgb + vec3(colorMatrix[3]);";
        fs << "gl_FragColor.rgb = pow(gl_FragColor.rgb, vec3(1.0 / 2.2));";
        if (!needs.isOpaque() && needs.isPremultiplied()) {
            // and re-premultiply if needed after gamma correction
+39 −6
Original line number Diff line number Diff line
@@ -114,7 +114,8 @@ SurfaceFlinger::SurfaceFlinger()
        mDebugInTransaction(0),
        mLastTransactionTime(0),
        mBootFinished(false),
        mDaltonize(false)
        mDaltonize(false),
        mHasColorMatrix(false)
{
    ALOGI("SurfaceFlinger is starting");

@@ -869,7 +870,7 @@ void SurfaceFlinger::setUpHWComposer() {
                        for (size_t i=0 ; cur!=end && i<count ; ++i, ++cur) {
                            const sp<Layer>& layer(currentLayers[i]);
                            layer->setGeometry(hw, *cur);
                            if (mDebugDisableHWC || mDebugRegion || mDaltonize) {
                            if (mDebugDisableHWC || mDebugRegion || mDaltonize || mHasColorMatrix) {
                                cur->setSkip(true);
                            }
                        }
@@ -1483,11 +1484,17 @@ void SurfaceFlinger::doDisplayComposition(const sp<const DisplayDevice>& hw,
        }
    }

    if (CC_LIKELY(!mDaltonize)) {
    if (CC_LIKELY(!mDaltonize && !mHasColorMatrix)) {
        doComposeSurfaces(hw, dirtyRegion);
    } else {
        RenderEngine& engine(getRenderEngine());
        engine.beginGroup(mDaltonizer());
        mat4 colorMatrix = mColorMatrix;
        if (mDaltonize) {
            // preserve last row of color matrix
            colorMatrix = colorMatrix * mDaltonizer();
            colorMatrix[3] = mColorMatrix[3];
        }
        engine.beginGroup(colorMatrix);
        doComposeSurfaces(hw, dirtyRegion);
        engine.endGroup();
    }
@@ -2371,7 +2378,8 @@ void SurfaceFlinger::dumpAllLocked(const Vector<String16>& args, size_t& index,
    colorizer.reset(result);
    result.appendFormat("  h/w composer %s and %s\n",
            hwc.initCheck()==NO_ERROR ? "present" : "not present",
                    (mDebugDisableHWC || mDebugRegion || mDaltonize) ? "disabled" : "enabled");
                    (mDebugDisableHWC || mDebugRegion || mDaltonize
                            || mHasColorMatrix) ? "disabled" : "enabled");
    hwc.dump(result);

    /*
@@ -2534,10 +2542,35 @@ status_t SurfaceFlinger::onTransact(
                mDaltonize = n > 0;
                invalidateHwcGeometry();
                repaintEverything();
                return NO_ERROR;
            }
            case 1015: {
                // apply a color matrix
                n = data.readInt32();
                mHasColorMatrix = n ? 1 : 0;
                if (n) {
                    // color matrix is sent as mat3 matrix followed by vec3
                    // offset, then packed into a mat4 where the last row is
                    // the offset and extra values are 0
                    for (size_t i = 0 ; i < 3 ; i++) {
                        for (size_t j = 0; j < 3; j++) {
                            mColorMatrix[i][j] = data.readFloat();
                        }
                        mColorMatrix[i][3] = 0;
                    }
                    for (size_t i = 0; i < 3; i++) {
                        mColorMatrix[3][i] = data.readFloat();
                    }
                    mColorMatrix[3][3] = 0;
                } else {
                    mColorMatrix = mat4();
                }
                invalidateHwcGeometry();
                repaintEverything();
                return NO_ERROR;
            }
        }
    }
    return err;
}

+4 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@
#include <binder/IMemory.h>

#include <ui/PixelFormat.h>
#include <ui/mat4.h>

#include <gui/ISurfaceComposer.h>
#include <gui/ISurfaceComposerClient.h>
@@ -461,6 +462,9 @@ private:

    Daltonizer mDaltonizer;
    bool mDaltonize;

    mat4 mColorMatrix;
    bool mHasColorMatrix;
};

// ---------------------------------------------------------------------------