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

Commit 46f247eb authored by ezterry's avatar ezterry Committed by Steve Kondik
Browse files

AVOID_DRAW_TEXTURE_EXTENSION speedups

For some slower chips such as in the Dream/Sapphire
AVOID_DRAW_TEXTURE_EXTENSION and some other similar operations
are slow.

This ports logic back in from AOSP froyo when
AVOID_DRAW_TEXTURE_EXTENSION = true
resulting in faster on screen drawing
parent 29f40ea8
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -36,6 +36,9 @@ ifeq ($(BOARD_HAS_LIMITED_EGL), true)
	LOCAL_CFLAGS += -DHAS_LIMITED_EGL
endif

ifeq ($(AVOID_DRAW_TEXTURE_EXTENSION), true)
	LOCAL_CFLAGS += -DAVOID_DRAW_TEXTURE
endif

# need "-lrt" on Linux simulator to pick up clock_gettime
ifeq ($(TARGET_SIMULATOR),true)
+6 −0
Original line number Diff line number Diff line
@@ -60,6 +60,9 @@ LayerBase::LayerBase(SurfaceFlinger* flinger, DisplayID display)
      mTransactionFlags(0),
      mPremultipliedAlpha(true), mName("unnamed"), mDebug(false),
      mInvalidate(0)
#ifdef AVOID_DRAW_TEXTURE
      ,mTransformed(false)
#endif
{
    const DisplayHardware& hw(flinger->graphicPlane(0).displayHardware());
    mFlags = hw.getFlags();
@@ -266,6 +269,9 @@ void LayerBase::validateVisibility(const Transform& planeTransform)
    // cache a few things...
    mOrientation = tr.getOrientation();
    mTransformedBounds = tr.makeBounds(w, h);
#ifdef AVOID_DRAW_TEXTURE
    mTransformed = transformed;
#endif
    mLeft = tr.tx();
    mTop  = tr.ty();
}
+10 −1
Original line number Diff line number Diff line
@@ -190,6 +190,13 @@ public:
        return (!(mFlags & DisplayHardware::SLOW_CONFIG)) && mNeedsFiltering;
    }

#ifdef AVOID_DRAW_TEXTURE
    /**
     * transformed -- true is this surface needs a to be transformed
     */
    virtual bool transformed() const    { return mTransformed; }
#endif

    /**
     * isSecure - true if this surface is secure, that is if it prevents
     * screenshots or VNC servers.
@@ -263,7 +270,9 @@ protected:

                // atomic
    volatile    int32_t         mInvalidate;
                
#ifdef AVOID_DRAW_TEXTURE
                bool            mTransformed;
#endif

protected:
    virtual ~LayerBase();
+32 −13
Original line number Diff line number Diff line
@@ -227,6 +227,10 @@ void LayerBlur::onDraw(const Region& clip) const
        glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

#ifdef AVOID_DRAW_TEXTURE
        if(UNLIKELY(transformed()))
#endif
        {
            glMatrixMode(GL_TEXTURE);
            glLoadIdentity();
            glScalef(mWidthScale, mHeightScale, 1);
@@ -241,6 +245,21 @@ void LayerBlur::onDraw(const Region& clip) const
                glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
            }
            glDisableClientState(GL_TEXTURE_COORD_ARRAY);
        }
#ifdef AVOID_DRAW_TEXTURE
        else{
            Rect r;
            GLint crop[4] = { 0, 0, w, h };
            glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
            y = fbHeight - (y + h);
            while (it != end) {
                const Rect& r = *it++;
                const GLint sy = fbHeight - (r.top + r.height());
                glScissor(r.left, sy, r.width(), r.height());
                glDrawTexiOES(x, y, 0, w, h);
            }
        }
#endif
        glLoadIdentity();
        glMatrixMode(GL_MODELVIEW);
    }
+56 −1
Original line number Diff line number Diff line
@@ -51,6 +51,41 @@ void LayerDim::initDimmer(SurfaceFlinger* flinger, uint32_t w, uint32_t h)
    sWidth = w;
    sHeight = h;
    sUseTexture = false;

#ifdef AVOID_DRAW_TEXTURE
    if(LIKELY(GLExtensions::getInstance().haveDirectTexture())){
        sp<GraphicBuffer> buffer = new GraphicBuffer(w, h, PIXEL_FORMAT_RGB_565,
                 GraphicBuffer::USAGE_SW_WRITE_OFTEN |
                 GraphicBuffer::USAGE_HW_TEXTURE);
        android_native_buffer_t* clientBuf = buffer->getNativeBuffer();

        glGenTextures(1, &sTexId);
        glBindTexture(GL_TEXTURE_2D, sTexId);

        EGLDisplay dpy = eglGetCurrentDisplay();
        sImage = eglCreateImageKHR(dpy, EGL_NO_CONTEXT,
                EGL_NATIVE_BUFFER_ANDROID, (EGLClientBuffer)clientBuf, 0);
        if (sImage == EGL_NO_IMAGE_KHR) {
            LOGE("eglCreateImageKHR() failed. err=0x%4x", eglGetError());
            return;
        }

        glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, (GLeglImageOES)sImage);
        GLint error = glGetError();
        if (error != GL_NO_ERROR) {
            eglDestroyImageKHR(dpy, sImage);
            LOGE("glEGLImageTargetTexture2DOES() failed. err=0x%4x", error);
            return;
        }

        // initialize the texture with zeros
        GGLSurface t;
        buffer->lock(&t, GRALLOC_USAGE_SW_WRITE_OFTEN);
        memset(t.data, 0, t.stride * t.height * 2);
        buffer->unlock();
        sUseTexture = true;
    }
#endif
}

LayerDim::~LayerDim()
@@ -76,8 +111,28 @@ void LayerDim::onDraw(const Region& clip) const
            glDisable(GL_TEXTURE_EXTERNAL_OES);
        }
#endif
#ifdef AVOID_DRAW_TEXTURE
        if (!sUseTexture) {
            glDisable(GL_TEXTURE_2D);

        }
        else{
            glBindTexture(GL_TEXTURE_2D, sTexId);
            glEnable(GL_TEXTURE_2D);
            glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
            const GLshort texCoords[4][2] = {
                  { 0,  0 },
                  { 0,  1 },
                  { 1,  1 },
                  { 1,  0 }
            };
            glMatrixMode(GL_TEXTURE);
            glLoadIdentity();
            glEnableClientState(GL_TEXTURE_COORD_ARRAY);
            glTexCoordPointer(2, GL_SHORT, 0, texCoords);
        }
#else
        glDisable(GL_TEXTURE_2D);
#endif
        GLshort w = sWidth;
        GLshort h = sHeight;
        const GLshort vertices[4][2] = {