Merge "Add API for pushing color transforms to SurfaceFlinger"

This commit is contained in:
Alan Viverette 2013-09-16 19:27:21 +00:00 committed by Android (Google) Code Review
commit ff735dd2b8
3 changed files with 44 additions and 7 deletions

View File

@ -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

View File

@ -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,8 +2542,33 @@ 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 NO_ERROR;
}
}
return err;

View File

@ -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;
};
// ---------------------------------------------------------------------------