Skip to content

Commit

Permalink
surfaceflinger: Enable dithering if persist.sys.use_dithering=1|2
Browse files Browse the repository at this point in the history
* Fixes color banding(1) and blur effect(2)

0 : surface doesn't need dithering
1 : enable dithering if necessary (default)
2 : enable dithering (always)
  • Loading branch information
gntcs committed Dec 23, 2012
1 parent d8c7714 commit db5cb80
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 2 deletions.
20 changes: 20 additions & 0 deletions services/surfaceflinger/Layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Layer::Layer(SurfaceFlinger* flinger, const sp<Client>& client)
mFormat(PIXEL_FORMAT_NONE),
mGLExtensions(GLExtensions::getInstance()),
mOpaqueLayer(true),
mNeedsDithering(false),
mSecure(false),
mProtectedByApp(false)
{
Expand Down Expand Up @@ -182,6 +183,10 @@ status_t Layer::setBuffers( uint32_t w, uint32_t h,
return BAD_VALUE;
}

// the display's pixel format
//sp<const DisplayDevice> hw(mFlinger->getDefaultDisplayDevice());
//getPixelFormatInfo(PixelFormat(hw->getFormat()), &info->pixelFormatInfo);

mFormat = format;

mSecure = (flags & ISurfaceComposerClient::eSecure) ? true : false;
Expand All @@ -193,6 +198,21 @@ status_t Layer::setBuffers( uint32_t w, uint32_t h,
mSurfaceTexture->setDefaultBufferFormat(format);
mSurfaceTexture->setConsumerUsageBits(getEffectiveUsage(0));

int useDither = mFlinger->getUseDithering();
if (useDither) {
if (useDither == 2) {
mNeedsDithering = true;
}
else {
// we use the red index
//int displayRedSize = info->pixelFormatInfo->getSize(PixelFormatInfo::INDEX_RED);
//int layerRedsize = info->pixelFormatInfo->getSize(PixelFormatInfo::INDEX_RED);
mNeedsDithering = true; // (layerRedsize > displayRedSize);
}
} else {
mNeedsDithering = false;
}

return NO_ERROR;
}

Expand Down
2 changes: 2 additions & 0 deletions services/surfaceflinger/Layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class Layer : public LayerBaseClient
virtual uint32_t doTransaction(uint32_t transactionFlags);
virtual Region latchBuffer(bool& recomputeVisibleRegions);
virtual bool isOpaque() const;
virtual bool needsDithering() const { return mNeedsDithering; }
virtual bool isSecure() const { return mSecure; }
virtual bool isProtected() const;
virtual void onRemoved();
Expand Down Expand Up @@ -142,6 +143,7 @@ class Layer : public LayerBaseClient
PixelFormat mFormat;
const GLExtensions& mGLExtensions;
bool mOpaqueLayer;
bool mNeedsDithering;

// page-flip thread (currently main thread)
bool mSecure; // no screenshots
Expand Down
7 changes: 7 additions & 0 deletions services/surfaceflinger/LayerBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ void LayerBase::clearWithOpenGL(const sp<const DisplayDevice>& hw, const Region&
glDisable(GL_TEXTURE_EXTERNAL_OES);
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
glDisable(GL_DITHER);

LayerMesh mesh;
computeGeometry(hw, &mesh);
Expand Down Expand Up @@ -427,6 +428,12 @@ void LayerBase::drawWithOpenGL(const sp<const DisplayDevice>& hw, const Region&
texCoords[i].v = 1.0f - texCoords[i].v;
}

if (needsDithering()) {
glEnable(GL_DITHER);
} else {
glDisable(GL_DITHER);
}

glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
glVertexPointer(2, GL_FLOAT, 0, mesh.getVertices());
Expand Down
15 changes: 13 additions & 2 deletions services/surfaceflinger/SurfaceFlinger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ SurfaceFlinger::SurfaceFlinger()
mLastSwapBufferTime(0),
mDebugInTransaction(0),
mLastTransactionTime(0),
mBootFinished(false)
mBootFinished(false),
mUseDithering(0)
{
ALOGI("SurfaceFlinger is starting");

Expand All @@ -119,8 +120,13 @@ SurfaceFlinger::SurfaceFlinger()
mDebugDDMS = 0;
}
}

property_get("persist.sys.use_dithering", value, "1");
mUseDithering = atoi(value);

ALOGI_IF(mDebugRegion, "showupdates enabled");
ALOGI_IF(mDebugDDMS, "DDMS debugging enabled");
ALOGI_IF(mUseDithering, "use dithering");
}

void SurfaceFlinger::onFirstRef()
Expand Down Expand Up @@ -417,7 +423,12 @@ void SurfaceFlinger::initializeGL(EGLDisplay display) {
glPixelStorei(GL_PACK_ALIGNMENT, 4);
glEnableClientState(GL_VERTEX_ARRAY);
glShadeModel(GL_FLAT);
glDisable(GL_DITHER);
if (mUseDithering == 0 || mUseDithering == 1) {
glDisable(GL_DITHER);
}
else if (mUseDithering == 2) {
glEnable(GL_DITHER);
}
glDisable(GL_CULL_FACE);

struct pack565 {
Expand Down
4 changes: 4 additions & 0 deletions services/surfaceflinger/SurfaceFlinger.h
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,9 @@ class SurfaceFlinger : public BinderService<SurfaceFlinger>,
return mProtectedTexName;
}

// 0: surface doesn't need dithering, 1: use if necessary, 2: use permanently
inline int getUseDithering() const { return mUseDithering; }

/* ------------------------------------------------------------------------
* Display management
*/
Expand Down Expand Up @@ -444,6 +447,7 @@ class SurfaceFlinger : public BinderService<SurfaceFlinger>,
volatile nsecs_t mDebugInTransaction;
nsecs_t mLastTransactionTime;
bool mBootFinished;
int mUseDithering;

// these are thread safe
mutable MessageQueue mEventQueue;
Expand Down

0 comments on commit db5cb80

Please sign in to comment.