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

Commit 59182e54 authored by Chia-I Wu's avatar Chia-I Wu Committed by Android (Google) Code Review
Browse files

Merge changes from topic "sf-re"

* changes:
  surfaceflinger: run clang-format on RenderEngine
  surfaceflinger: remove all direct use of EGL
  surfaceflinger: use RE::Surface in DisplayDevice
  surfaceflinger: add surface abstraction to RE
  surfaceflinger: remove DisplayDevice::swapRegion
  surfaceflinger: remove DisplayDevice::mFlags
  surfaceflinger: remove unused EGL data members
  surfaceflinger: remove EGLConfig from DisplayDevice ctor
  surfaceflinger: add RenderEngine::BindNativeBufferAsFramebuffer
  surfaceflinger: return fence fd from RenderEngine::flush
  surfaceflinger: add RenderEngine::setCurrentSurface
  surfaceflinger: move EGL version/extensions dump into RE
  surfaceflinger: move EGL termination into RE
  surfaceflinger: move EGL initialization into RE
  surfaceflinger: add RenderEngine::mEGLDisplay
  surfaceflinger: manage RenderEngine with unique_ptr
parents c5aad50b b027f805
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -187,7 +187,7 @@ protected:
    // ConsumerBase::releaseBufferLocked.
    // ConsumerBase::releaseBufferLocked.
    virtual status_t releaseBufferLocked(int slot,
    virtual status_t releaseBufferLocked(int slot,
            const sp<GraphicBuffer> graphicBuffer,
            const sp<GraphicBuffer> graphicBuffer,
            EGLDisplay display, EGLSyncKHR eglFence);
            EGLDisplay display = EGL_NO_DISPLAY, EGLSyncKHR eglFence = EGL_NO_SYNC_KHR);


    // returns true iff the slot still has the graphicBuffer in it.
    // returns true iff the slot still has the graphicBuffer in it.
    bool stillTracking(int slot, const sp<GraphicBuffer> graphicBuffer);
    bool stillTracking(int slot, const sp<GraphicBuffer> graphicBuffer);
+1 −0
Original line number Original line Diff line number Diff line
@@ -41,6 +41,7 @@ LOCAL_SRC_FILES := \
    RenderEngine/ProgramCache.cpp \
    RenderEngine/ProgramCache.cpp \
    RenderEngine/GLExtensions.cpp \
    RenderEngine/GLExtensions.cpp \
    RenderEngine/RenderEngine.cpp \
    RenderEngine/RenderEngine.cpp \
    RenderEngine/Surface.cpp \
    RenderEngine/Texture.cpp \
    RenderEngine/Texture.cpp \
    RenderEngine/GLES20RenderEngine.cpp \
    RenderEngine/GLES20RenderEngine.cpp \
    LayerProtoHelper.cpp \
    LayerProtoHelper.cpp \
+0 −3
Original line number Original line Diff line number Diff line
@@ -32,9 +32,6 @@
#include <gui/ISurfaceComposerClient.h>
#include <gui/ISurfaceComposerClient.h>
#include <gui/LayerState.h>
#include <gui/LayerState.h>


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

#include <ui/FrameStats.h>
#include <ui/FrameStats.h>
#include <ui/GraphicBuffer.h>
#include <ui/GraphicBuffer.h>
#include <ui/PixelFormat.h>
#include <ui/PixelFormat.h>
+17 −89
Original line number Original line Diff line number Diff line
@@ -53,12 +53,6 @@
using namespace android;
using namespace android;
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------


#ifdef EGL_ANDROID_swap_rectangle
static constexpr bool kEGLAndroidSwapRectangle = true;
#else
static constexpr bool kEGLAndroidSwapRectangle = false;
#endif

// retrieve triple buffer setting from configstore
// retrieve triple buffer setting from configstore
using namespace android::hardware::configstore;
using namespace android::hardware::configstore;
using namespace android::hardware::configstore::V1_0;
using namespace android::hardware::configstore::V1_0;
@@ -66,12 +60,6 @@ using namespace android::hardware::configstore::V1_0;
static bool useTripleFramebuffer = getInt64< ISurfaceFlingerConfigs,
static bool useTripleFramebuffer = getInt64< ISurfaceFlingerConfigs,
        &ISurfaceFlingerConfigs::maxFrameBufferAcquiredBuffers>(2) >= 3;
        &ISurfaceFlingerConfigs::maxFrameBufferAcquiredBuffers>(2) >= 3;


#if !defined(EGL_EGLEXT_PROTOTYPES) || !defined(EGL_ANDROID_swap_rectangle)
// Dummy implementation in case it is missing.
inline void eglSetSwapRectangleANDROID (EGLDisplay, EGLSurface, EGLint, EGLint, EGLint, EGLint) {
}
#endif

/*
/*
 * Initialize the display to the specified values.
 * Initialize the display to the specified values.
 *
 *
@@ -88,7 +76,6 @@ DisplayDevice::DisplayDevice(
        const wp<IBinder>& displayToken,
        const wp<IBinder>& displayToken,
        const sp<DisplaySurface>& displaySurface,
        const sp<DisplaySurface>& displaySurface,
        const sp<IGraphicBufferProducer>& producer,
        const sp<IGraphicBufferProducer>& producer,
        EGLConfig config,
        bool supportWideColor)
        bool supportWideColor)
    : lastCompositionHadVisibleLayers(false),
    : lastCompositionHadVisibleLayers(false),
      mFlinger(flinger),
      mFlinger(flinger),
@@ -96,11 +83,9 @@ DisplayDevice::DisplayDevice(
      mHwcDisplayId(hwcId),
      mHwcDisplayId(hwcId),
      mDisplayToken(displayToken),
      mDisplayToken(displayToken),
      mDisplaySurface(displaySurface),
      mDisplaySurface(displaySurface),
      mDisplay(EGL_NO_DISPLAY),
      mSurface{flinger->getRenderEngine()},
      mSurface(EGL_NO_SURFACE),
      mDisplayWidth(),
      mDisplayWidth(),
      mDisplayHeight(),
      mDisplayHeight(),
      mFlags(),
      mPageFlipCount(),
      mPageFlipCount(),
      mIsSecure(isSecure),
      mIsSecure(isSecure),
      mLayerStack(NO_LAYER_STACK),
      mLayerStack(NO_LAYER_STACK),
@@ -118,16 +103,11 @@ DisplayDevice::DisplayDevice(
    /*
    /*
     * Create our display's surface
     * Create our display's surface
     */
     */

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


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


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


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


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


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

void DisplayDevice::setDisplayName(const String8& displayName) {
void DisplayDevice::setDisplayName(const String8& displayName) {
    if (!displayName.isEmpty()) {
    if (!displayName.isEmpty()) {
        // never override the name with an empty name
        // never override the name with an empty name
@@ -213,19 +182,9 @@ uint32_t DisplayDevice::getPageFlipCount() const {
    return mPageFlipCount;
    return mPageFlipCount;
}
}


void DisplayDevice::flip(const Region& dirty) const
void DisplayDevice::flip() const
{
{
    mFlinger->getRenderEngine().checkErrors();
    mFlinger->getRenderEngine().checkErrors();

    if (kEGLAndroidSwapRectangle) {
        if (mFlags & SWAP_RECTANGLE) {
            const Region newDirty(dirty.intersect(bounds()));
            const Rect b(newDirty.getBounds());
            eglSetSwapRectangleANDROID(mDisplay, mSurface,
                    b.left, b.top, b.width(), b.height());
        }
    }

    mPageFlipCount++;
    mPageFlipCount++;
}
}


@@ -259,18 +218,7 @@ status_t DisplayDevice::prepareFrame(HWComposer& hwc) {


void DisplayDevice::swapBuffers(HWComposer& hwc) const {
void DisplayDevice::swapBuffers(HWComposer& hwc) const {
    if (hwc.hasClientComposition(mHwcDisplayId)) {
    if (hwc.hasClientComposition(mHwcDisplayId)) {
        EGLBoolean success = eglSwapBuffers(mDisplay, mSurface);
        mSurface.swapBuffers();
        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);
            }
        }
    }
    }


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


uint32_t DisplayDevice::getFlags() const
bool DisplayDevice::makeCurrent() const {
{
    bool success = mFlinger->getRenderEngine().setCurrentSurface(mSurface);
    return mFlags;
}

EGLBoolean DisplayDevice::makeCurrent(EGLDisplay dpy, EGLContext ctx) const {
    EGLBoolean result = EGL_TRUE;
    EGLSurface sur = eglGetCurrentSurface(EGL_DRAW);
    if (sur != mSurface) {
        result = eglMakeCurrent(dpy, mSurface, mSurface, ctx);
        if (result == EGL_TRUE) {
            if (mType >= DisplayDevice::DISPLAY_VIRTUAL)
                eglSwapInterval(dpy, 0);
        }
    }
    setViewportAndProjection();
    setViewportAndProjection();
    return result;
    return success;
}
}


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


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


    mDisplaySurface->resizeBuffers(newWidth, newHeight);
    mDisplaySurface->resizeBuffers(newWidth, newHeight);


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


    LOG_FATAL_IF(mDisplayWidth != newWidth,
    LOG_FATAL_IF(mDisplayWidth != newWidth,
                "Unable to set new width to %d", newWidth);
                "Unable to set new width to %d", newWidth);
@@ -548,17 +480,13 @@ uint32_t DisplayDevice::getPrimaryDisplayOrientationTransform() {
void DisplayDevice::dump(String8& result) const {
void DisplayDevice::dump(String8& result) const {
    const Transform& tr(mGlobalTransform);
    const Transform& tr(mGlobalTransform);
    ANativeWindow* const window = mNativeWindow.get();
    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("+ DisplayDevice: %s\n", mDisplayName.string());
    result.appendFormat("   type=%x, hwcId=%d, layerStack=%u, (%4dx%4d), ANativeWindow=%p "
    result.appendFormat("   type=%x, hwcId=%d, layerStack=%u, (%4dx%4d), ANativeWindow=%p "
                        "(%d:%d:%d:%d), orient=%2d (type=%08x), "
                        "(%d:%d:%d:%d), orient=%2d (type=%08x), "
                        "flips=%u, isSecure=%d, powerMode=%d, activeConfig=%d, numLayers=%zu\n",
                        "flips=%u, isSecure=%d, powerMode=%d, activeConfig=%d, numLayers=%zu\n",
                        mType, mHwcDisplayId, mLayerStack, mDisplayWidth, mDisplayHeight, window,
                        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,
                        getPageFlipCount(), mIsSecure, mPowerMode, mActiveConfig,
                        mVisibleLayersSortedByZ.size());
                        mVisibleLayersSortedByZ.size());
    result.appendFormat("   v:[%d,%d,%d,%d], f:[%d,%d,%d,%d], s:[%d,%d,%d,%d],"
    result.appendFormat("   v:[%d,%d,%d,%d], f:[%d,%d,%d,%d], s:[%d,%d,%d,%d],"
+4 −20
Original line number Original line Diff line number Diff line
@@ -23,9 +23,6 @@


#include <ui/Region.h>
#include <ui/Region.h>


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

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


#include <memory>
#include <memory>


@@ -56,8 +54,6 @@ public:
    // region in layer-stack space
    // region in layer-stack space
    mutable Region dirtyRegion;
    mutable Region dirtyRegion;
    // region in screen space
    // region in screen space
    mutable Region swapRegion;
    // region in screen space
    Region undefinedRegion;
    Region undefinedRegion;
    bool lastCompositionHadVisibleLayers;
    bool lastCompositionHadVisibleLayers;


@@ -69,11 +65,6 @@ public:
        NUM_BUILTIN_DISPLAY_TYPES = HWC_NUM_PHYSICAL_DISPLAY_TYPES,
        NUM_BUILTIN_DISPLAY_TYPES = HWC_NUM_PHYSICAL_DISPLAY_TYPES,
    };
    };


    enum {
        PARTIAL_UPDATES = 0x00020000, // video driver feature
        SWAP_RECTANGLE  = 0x00080000,
    };

    enum {
    enum {
        NO_LAYER_STACK = 0xFFFFFFFF,
        NO_LAYER_STACK = 0xFFFFFFFF,
    };
    };
@@ -87,7 +78,6 @@ public:
            const wp<IBinder>& displayToken,
            const wp<IBinder>& displayToken,
            const sp<DisplaySurface>& displaySurface,
            const sp<DisplaySurface>& displaySurface,
            const sp<IGraphicBufferProducer>& producer,
            const sp<IGraphicBufferProducer>& producer,
            EGLConfig config,
            bool supportWideColor);
            bool supportWideColor);
    // clang-format on
    // clang-format on


@@ -103,13 +93,10 @@ public:


    // Flip the front and back buffers if the back buffer is "dirty".  Might
    // Flip the front and back buffers if the back buffer is "dirty".  Might
    // be instantaneous, might involve copying the frame buffer around.
    // be instantaneous, might involve copying the frame buffer around.
    void flip(const Region& dirty) const;
    void flip() const;


    int         getWidth() const;
    int         getWidth() const;
    int         getHeight() const;
    int         getHeight() const;
    uint32_t    getFlags() const;

    EGLSurface  getEGLSurface() const;


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


    EGLBoolean makeCurrent(EGLDisplay dpy, EGLContext ctx) const;
    bool makeCurrent() const;
    void setViewportAndProjection() const;
    void setViewportAndProjection() const;


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


    EGLConfig       mConfig;
    RE::Surface     mSurface;
    EGLDisplay      mDisplay;
    EGLSurface      mSurface;
    int             mDisplayWidth;
    int             mDisplayWidth;
    int             mDisplayHeight;
    int             mDisplayHeight;
    uint32_t        mFlags;
    mutable uint32_t mPageFlipCount;
    mutable uint32_t mPageFlipCount;
    String8         mDisplayName;
    String8         mDisplayName;
    bool            mIsSecure;
    bool            mIsSecure;
Loading