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

Commit f846a35a authored by Chia-I Wu's avatar Chia-I Wu
Browse files

surfaceflinger: use RE::Surface in DisplayDevice

This allows us to eliminate all direct use of EGL from
DisplayDevice.

Test: SurfaceFlinger_test
Change-Id: Ic7b006dfd8e3f067625896c3020b55914b9fc65b
parent 7e60ecc2
Loading
Loading
Loading
Loading
+16 −61
Original line number Diff line number Diff line
@@ -83,8 +83,7 @@ DisplayDevice::DisplayDevice(
      mHwcDisplayId(hwcId),
      mDisplayToken(displayToken),
      mDisplaySurface(displaySurface),
      mDisplay(EGL_NO_DISPLAY),
      mSurface(EGL_NO_SURFACE),
      mSurface{flinger->getRenderEngine()},
      mDisplayWidth(),
      mDisplayHeight(),
      mPageFlipCount(),
@@ -104,18 +103,11 @@ DisplayDevice::DisplayDevice(
    /*
     * Create our display's surface
     */

    EGLSurface eglSurface;
    EGLDisplay display = mFlinger->getRenderEngine().getEGLDisplay();
    EGLConfig config = mFlinger->getRenderEngine().getEGLConfig();

    if (config == EGL_NO_CONFIG) {
        config = RenderEngine::chooseEglConfig(display, PIXEL_FORMAT_RGBA_8888,
                                               /*logConfig*/ false);
    }
    eglSurface = eglCreateWindowSurface(display, config, window, NULL);
    eglQuerySurface(display, eglSurface, EGL_WIDTH,  &mDisplayWidth);
    eglQuerySurface(display, eglSurface, EGL_HEIGHT, &mDisplayHeight);
    mSurface.setCritical(mType == DisplayDevice::DISPLAY_PRIMARY);
    mSurface.setAsync(mType >= DisplayDevice::DISPLAY_VIRTUAL);
    mSurface.setNativeWindow(window);
    mDisplayWidth = mSurface.queryWidth();
    mDisplayHeight = mSurface.queryHeight();

    // Make sure that composition can never be stalled by a virtual display
    // consumer that isn't processing buffers fast enough. We have to do this
@@ -127,9 +119,6 @@ DisplayDevice::DisplayDevice(
    if (mType >= DisplayDevice::DISPLAY_VIRTUAL)
        window->setSwapInterval(window, 0);

    mConfig = config;
    mDisplay = display;
    mSurface = eglSurface;
    mPageFlipCount = 0;
    mViewport.makeInvalid();
    mFrame.makeInvalid();
@@ -161,10 +150,6 @@ DisplayDevice::DisplayDevice(
}

DisplayDevice::~DisplayDevice() {
    if (mSurface != EGL_NO_SURFACE) {
        eglDestroySurface(mDisplay, mSurface);
        mSurface = EGL_NO_SURFACE;
    }
}

void DisplayDevice::disconnect(HWComposer& hwc) {
@@ -186,10 +171,6 @@ int DisplayDevice::getHeight() const {
    return mDisplayHeight;
}

EGLSurface DisplayDevice::getEGLSurface() const {
    return mSurface;
}

void DisplayDevice::setDisplayName(const String8& displayName) {
    if (!displayName.isEmpty()) {
        // never override the name with an empty name
@@ -237,18 +218,7 @@ status_t DisplayDevice::prepareFrame(HWComposer& hwc) {

void DisplayDevice::swapBuffers(HWComposer& hwc) const {
    if (hwc.hasClientComposition(mHwcDisplayId)) {
        EGLBoolean success = eglSwapBuffers(mDisplay, mSurface);
        if (!success) {
            EGLint error = eglGetError();
            if (error == EGL_CONTEXT_LOST ||
                    mType == DisplayDevice::DISPLAY_PRIMARY) {
                LOG_ALWAYS_FATAL("eglSwapBuffers(%p, %p) failed with 0x%08x",
                        mDisplay, mSurface, error);
            } else {
                ALOGE("eglSwapBuffers(%p, %p) failed with 0x%08x",
                        mDisplay, mSurface, error);
            }
        }
        mSurface.swapBuffers();
    }

    status_t result = mDisplaySurface->advanceFrame();
@@ -262,18 +232,10 @@ void DisplayDevice::onSwapBuffersCompleted() const {
    mDisplaySurface->onFrameCommitted();
}

EGLBoolean DisplayDevice::makeCurrent() const {
    EGLBoolean result = EGL_TRUE;
    EGLSurface sur = eglGetCurrentSurface(EGL_DRAW);
    if (sur != mSurface) {
        result = mFlinger->getRenderEngine().setCurrentSurface(mSurface);
        if (result == EGL_TRUE) {
            if (mType >= DisplayDevice::DISPLAY_VIRTUAL)
                eglSwapInterval(mDisplay, 0);
        }
    }
bool DisplayDevice::makeCurrent() const {
    bool success = mFlinger->getRenderEngine().setCurrentSurface(mSurface);
    setViewportAndProjection();
    return result;
    return success;
}

void DisplayDevice::setViewportAndProjection() const {
@@ -409,17 +371,14 @@ status_t DisplayDevice::orientationToTransfrom(
void DisplayDevice::setDisplaySize(const int newWidth, const int newHeight) {
    dirtyRegion.set(getBounds());

    if (mSurface != EGL_NO_SURFACE) {
        eglDestroySurface(mDisplay, mSurface);
        mSurface = EGL_NO_SURFACE;
    }
    mSurface.setNativeWindow(nullptr);

    mDisplaySurface->resizeBuffers(newWidth, newHeight);

    ANativeWindow* const window = mNativeWindow.get();
    mSurface = eglCreateWindowSurface(mDisplay, mConfig, window, NULL);
    eglQuerySurface(mDisplay, mSurface, EGL_WIDTH,  &mDisplayWidth);
    eglQuerySurface(mDisplay, mSurface, EGL_HEIGHT, &mDisplayHeight);
    mSurface.setNativeWindow(window);
    mDisplayWidth = mSurface.queryWidth();
    mDisplayHeight = mSurface.queryHeight();

    LOG_FATAL_IF(mDisplayWidth != newWidth,
                "Unable to set new width to %d", newWidth);
@@ -521,17 +480,13 @@ uint32_t DisplayDevice::getPrimaryDisplayOrientationTransform() {
void DisplayDevice::dump(String8& result) const {
    const Transform& tr(mGlobalTransform);
    ANativeWindow* const window = mNativeWindow.get();
    EGLint redSize, greenSize, blueSize, alphaSize;
    eglGetConfigAttrib(mDisplay, mConfig, EGL_RED_SIZE, &redSize);
    eglGetConfigAttrib(mDisplay, mConfig, EGL_GREEN_SIZE, &greenSize);
    eglGetConfigAttrib(mDisplay, mConfig, EGL_BLUE_SIZE, &blueSize);
    eglGetConfigAttrib(mDisplay, mConfig, EGL_ALPHA_SIZE, &alphaSize);
    result.appendFormat("+ DisplayDevice: %s\n", mDisplayName.string());
    result.appendFormat("   type=%x, hwcId=%d, layerStack=%u, (%4dx%4d), ANativeWindow=%p "
                        "(%d:%d:%d:%d), orient=%2d (type=%08x), "
                        "flips=%u, isSecure=%d, powerMode=%d, activeConfig=%d, numLayers=%zu\n",
                        mType, mHwcDisplayId, mLayerStack, mDisplayWidth, mDisplayHeight, window,
                        redSize, greenSize, blueSize, alphaSize, mOrientation, tr.getType(),
                        mSurface.queryRedSize(), mSurface.queryGreenSize(), mSurface.queryBlueSize(),
                        mSurface.queryAlphaSize(), mOrientation, tr.getType(),
                        getPageFlipCount(), mIsSecure, mPowerMode, mActiveConfig,
                        mVisibleLayersSortedByZ.size());
    result.appendFormat("   v:[%d,%d,%d,%d], f:[%d,%d,%d,%d], s:[%d,%d,%d,%d],"
+3 −9
Original line number Diff line number Diff line
@@ -23,9 +23,6 @@

#include <ui/Region.h>

#include <EGL/egl.h>
#include <EGL/eglext.h>

#include <binder/IBinder.h>
#include <utils/RefBase.h>
#include <utils/Mutex.h>
@@ -35,6 +32,7 @@
#include <gui/ISurfaceComposer.h>
#include <hardware/hwcomposer_defs.h>
#include "RenderArea.h"
#include "RenderEngine/Surface.h"

#include <memory>

@@ -100,8 +98,6 @@ public:
    int         getWidth() const;
    int         getHeight() const;

    EGLSurface  getEGLSurface() const;

    void                    setVisibleLayersSortedByZ(const Vector< sp<Layer> >& layers);
    const Vector< sp<Layer> >& getVisibleLayersSortedByZ() const;
    void                    setLayersNeedingFences(const Vector< sp<Layer> >& layers);
@@ -146,7 +142,7 @@ public:
    void setDisplayName(const String8& displayName);
    const String8& getDisplayName() const { return mDisplayName; }

    EGLBoolean makeCurrent() const;
    bool makeCurrent() const;
    void setViewportAndProjection() const;

    const sp<Fence>& getClientTargetAcquireFence() const;
@@ -190,9 +186,7 @@ private:
    sp<ANativeWindow> mNativeWindow;
    sp<DisplaySurface> mDisplaySurface;

    EGLConfig       mConfig;
    EGLDisplay      mDisplay;
    EGLSurface      mSurface;
    RE::Surface     mSurface;
    int             mDisplayWidth;
    int             mDisplayHeight;
    mutable uint32_t mPageFlipCount;
+11 −2
Original line number Diff line number Diff line
@@ -183,8 +183,17 @@ EGLConfig RenderEngine::getEGLConfig() const {
    return mEGLConfig;
}

bool RenderEngine::setCurrentSurface(EGLSurface surface) {
    return eglMakeCurrent(mEGLDisplay, surface, surface, mEGLContext) == EGL_TRUE;
bool RenderEngine::setCurrentSurface(const RE::Surface& surface) {
    bool success = true;
    EGLSurface eglSurface = surface.getEGLSurface();
    if (eglSurface != eglGetCurrentSurface(EGL_DRAW)) {
        success = eglMakeCurrent(mEGLDisplay, eglSurface, eglSurface, mEGLContext) == EGL_TRUE;
        if (success && surface.getAsync()) {
            eglSwapInterval(mEGLDisplay, 0);
        }
    }

    return success;
}

void RenderEngine::resetCurrentSurface() {
+6 −1
Original line number Diff line number Diff line
@@ -43,6 +43,10 @@ class Region;
class Mesh;
class Texture;

namespace RE {
class Surface;
}

class RenderEngine {
    enum GlesVersion {
        GLES_VERSION_1_0    = 0x10000,
@@ -103,7 +107,7 @@ public:
        int getStatus() const;
    };

    bool setCurrentSurface(EGLSurface surface);
    bool setCurrentSurface(const RE::Surface& surface);
    void resetCurrentSurface();

    // set-up
@@ -134,6 +138,7 @@ public:
    virtual size_t getMaxTextureSize() const = 0;
    virtual size_t getMaxViewportDims() const = 0;

    // internal to RenderEngine
    EGLDisplay getEGLDisplay() const;
    EGLConfig getEGLConfig() const;
};