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

Commit 05f952e8 authored by Steven Luo's avatar Steven Luo Committed by Ricardo Cerqueira
Browse files

Forward-port surface dithering from CM10.1

This allows the use of 16-bit color displays without excessive color
banding;

Change-Id: Icb469b9cb4beb686516c60bb576dbd0a73f505e0
parent d08f4467
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -68,6 +68,7 @@ Layer::Layer(SurfaceFlinger* flinger, const sp<Client>& client,
        mFormat(PIXEL_FORMAT_NONE),
        mGLExtensions(GLExtensions::getInstance()),
        mOpaqueLayer(true),
        mNeedsDithering(false),
        mTransactionFlags(0),
        mQueuedFrames(0),
        mCurrentTransform(0),
@@ -204,6 +205,14 @@ status_t Layer::setBuffers( uint32_t w, uint32_t h,
    mSurfaceFlingerConsumer->setDefaultBufferFormat(format);
    mSurfaceFlingerConsumer->setConsumerUsageBits(getEffectiveUsage(0));

    if (mFlinger->getUseDithering()) {
        int displayMinColorDepth = mFlinger->getMinColorDepth();
        // we use the red index
        int layerRedsize = info.getSize(PixelFormatInfo::INDEX_RED);

        mNeedsDithering = (layerRedsize > displayMinColorDepth);
    }

    return NO_ERROR;
}

@@ -544,6 +553,7 @@ void Layer::clearWithOpenGL(const sp<const DisplayDevice>& hw, const Region& cli
    glDisable(GL_TEXTURE_EXTERNAL_OES);
    glDisable(GL_TEXTURE_2D);
    glDisable(GL_BLEND);
    glDisable(GL_DITHER);

    LayerMesh mesh;
    computeGeometry(hw, &mesh);
@@ -630,6 +640,12 @@ void Layer::drawWithOpenGL(
        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());
+6 −0
Original line number Diff line number Diff line
@@ -244,6 +244,11 @@ public:
     */
    virtual bool isOpaque() const;

    /*
     * needsDithering - true if this surface needs dithering
     */
    virtual bool needsDithering() const     { return mNeedsDithering; }

    /*
     * isSecure - true if this surface is secure, that is if it prevents
     * screenshots or VNC servers.
@@ -360,6 +365,7 @@ private:
    PixelFormat mFormat;
    const GLExtensions& mGLExtensions;
    bool mOpaqueLayer;
    bool mNeedsDithering;

    // these are protected by an external lock
    State mCurrentState;
+14 −1
Original line number Diff line number Diff line
@@ -106,7 +106,8 @@ SurfaceFlinger::SurfaceFlinger()
        mLastSwapBufferTime(0),
        mDebugInTransaction(0),
        mLastTransactionTime(0),
        mBootFinished(false)
        mBootFinished(false),
        mUseDithering(0)
{
    ALOGI("SurfaceFlinger is starting");

@@ -127,6 +128,7 @@ SurfaceFlinger::SurfaceFlinger()
            mDebugDDMS = 0;
        }
    }

    ALOGI_IF(mDebugRegion, "showupdates enabled");
    ALOGI_IF(mDebugDDMS, "DDMS debugging enabled");

@@ -482,6 +484,8 @@ void SurfaceFlinger::initializeGL(EGLDisplay display) {
    ALOGI("extensions: %s", extensions.getExtension());
    ALOGI("GL_MAX_TEXTURE_SIZE = %d", mMaxTextureSize);
    ALOGI("GL_MAX_VIEWPORT_DIMS = %d x %d", mMaxViewportDims[0], mMaxViewportDims[1]);

    mMinColorDepth = r;
}

status_t SurfaceFlinger::readyToRun()
@@ -534,6 +538,11 @@ status_t SurfaceFlinger::readyToRun()
                hw->acquireScreen();
            }
            mDisplays.add(token, hw);
            PixelFormatInfo info;
            getPixelFormatInfo(mHwc->getFormat(i), &info);
            if (!mUseDithering && info.bitsPerPixel <= 16) {
                mUseDithering = 1;
            }
        }
    }

@@ -583,6 +592,10 @@ uint32_t SurfaceFlinger::getMaxTextureSize() const {
    return mMaxTextureSize;
}

uint32_t SurfaceFlinger::getMinColorDepth() const {
    return mMinColorDepth;
}

uint32_t SurfaceFlinger::getMaxViewportDims() const {
    return mMaxViewportDims[0] < mMaxViewportDims[1] ?
            mMaxViewportDims[0] : mMaxViewportDims[1];
+6 −0
Original line number Diff line number Diff line
@@ -334,8 +334,12 @@ private:
    static EGLContext createGLContext(EGLDisplay disp, EGLConfig config);
    void initializeGL(EGLDisplay display);
    uint32_t getMaxTextureSize() const;
    uint32_t getMinColorDepth() const;
    uint32_t getMaxViewportDims() const;

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

    /* ------------------------------------------------------------------------
     * Display and layer stack management
     */
@@ -440,6 +444,7 @@ private:
    sp<EventThread> mEventThread;
    GLint mMaxViewportDims[2];
    GLint mMaxTextureSize;
    GLint mMinColorDepth;
    EGLContext mEGLContext;
    EGLConfig mEGLConfig;
    EGLDisplay mEGLDisplay;
@@ -467,6 +472,7 @@ private:
    volatile nsecs_t mDebugInTransaction;
    nsecs_t mLastTransactionTime;
    bool mBootFinished;
    int mUseDithering;

    // these are thread safe
    mutable MessageQueue mEventQueue;