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

Commit 4297734c authored by Mathias Agopian's avatar Mathias Agopian
Browse files

turn DisplayDevice into a reference-counted object

it's safer this way because this object owns an
EGLSurface which cannot be easily reference-counted.

it also gives us the ability to sub-class it, which
we might want to do soon.

Change-Id: I07358bb052dc5a13b4f2196b2c2b6e6e94c4bb4f
parent d8552d79
Loading
Loading
Loading
Loading
+3 −17
Original line number Diff line number Diff line
@@ -97,14 +97,6 @@ void checkEGLErrors(const char* token)
 *
 */

DisplayDevice::DisplayDevice()
    : mId(0),
      mDisplay(EGL_NO_DISPLAY),
      mSurface(EGL_NO_SURFACE),
      mContext(EGL_NO_CONTEXT)
{
}

DisplayDevice::DisplayDevice(
        const sp<SurfaceFlinger>& flinger,
        int display,
@@ -130,12 +122,6 @@ DisplayDevice::DisplayDevice(
}

DisplayDevice::~DisplayDevice() {
    // DO NOT call terminate() from here, because we create
    // temporaries of this class (on the stack typically), and we don't
    // want to destroy the EGLSurface in that case
}

void DisplayDevice::terminate() {
    if (mSurface != EGL_NO_SURFACE) {
        eglDestroySurface(mDisplay, mSurface);
        mSurface = EGL_NO_SURFACE;
@@ -297,11 +283,11 @@ void DisplayDevice::dump(String8& res) const
    }
}

void DisplayDevice::makeCurrent(const DisplayDevice& hw, EGLContext ctx) {
void DisplayDevice::makeCurrent(const sp<const DisplayDevice>& hw, EGLContext ctx) {
    EGLSurface sur = eglGetCurrentSurface(EGL_DRAW);
    if (sur != hw.mSurface) {
    if (sur != hw->mSurface) {
        EGLDisplay dpy = eglGetCurrentDisplay();
        eglMakeCurrent(dpy, hw.mSurface, hw.mSurface, ctx);
        eglMakeCurrent(dpy, hw->mSurface, hw->mSurface, ctx);
    }
}

+3 −9
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ class FramebufferSurface;
class LayerBase;
class SurfaceFlinger;

class DisplayDevice
class DisplayDevice : public virtual RefBase
{
public:
    // region in layer-stack space
@@ -59,19 +59,13 @@ public:
        SWAP_RECTANGLE  = 0x00080000,
    };

    DisplayDevice();

    DisplayDevice(
            const sp<SurfaceFlinger>& flinger,
            int dpy,
            const sp<ANativeWindow>& surface,
            EGLConfig config);

    ~DisplayDevice();

    // must be called when this object is no longer needed. this will
    // render the associated EGLSurface invalid.
    void terminate();
    virtual ~DisplayDevice();

    // whether this is a valid object. An invalid DisplayDevice is returned
    // when an non existing id is requested
@@ -107,7 +101,7 @@ public:
    }
    inline Rect bounds() const { return getBounds(); }

    static void makeCurrent(const DisplayDevice& hw, EGLContext ctx);
    static void makeCurrent(const sp<const DisplayDevice>& hw, EGLContext ctx);

    /* ------------------------------------------------------------------------
     * blank / unplank management
+9 −10
Original line number Diff line number Diff line
@@ -71,7 +71,7 @@ Layer::Layer(SurfaceFlinger* flinger,
    glGenTextures(1, &mTextureName);
}

void Layer::onLayerDisplayed(const DisplayDevice& hw,
void Layer::onLayerDisplayed(const sp<const DisplayDevice>& hw,
        HWComposer::HWCLayerInterface* layer) {
    if (layer) {
        mSurfaceTexture->setReleaseFence(layer->getAndResetReleaseFenceFd());
@@ -237,7 +237,7 @@ Rect Layer::computeBufferCrop() const {
}

void Layer::setGeometry(
        const DisplayDevice& hw,
    const sp<const DisplayDevice>& hw,
        HWComposer::HWCLayerInterface& layer)
{
    LayerBaseClient::setGeometry(hw, layer);
@@ -260,7 +260,7 @@ void Layer::setGeometry(
     */

    const Transform bufferOrientation(mCurrentTransform);
    const Transform tr(hw.getTransform() * s.transform * bufferOrientation);
    const Transform tr(hw->getTransform() * s.transform * bufferOrientation);

    // this gives us only the "orientation" component of the transform
    const uint32_t finalTransform = tr.getOrientation();
@@ -274,7 +274,7 @@ void Layer::setGeometry(
    layer.setCrop(computeBufferCrop());
}

void Layer::setPerFrameData(const DisplayDevice& hw,
void Layer::setPerFrameData(const sp<const DisplayDevice>& hw,
        HWComposer::HWCLayerInterface& layer) {
    const sp<GraphicBuffer>& buffer(mActiveBuffer);
    // NOTE: buffer can be NULL if the client never drew into this
@@ -282,7 +282,7 @@ void Layer::setPerFrameData(const DisplayDevice& hw,
    layer.setBuffer(buffer);
}

void Layer::setAcquireFence(const DisplayDevice& hw,
void Layer::setAcquireFence(const sp<const DisplayDevice>& hw,
        HWComposer::HWCLayerInterface& layer) {
    int fenceFd = -1;

@@ -301,7 +301,7 @@ void Layer::setAcquireFence(const DisplayDevice& hw,
    layer.setAcquireFenceFd(fenceFd);
}

void Layer::onDraw(const DisplayDevice& hw, const Region& clip) const
void Layer::onDraw(const sp<const DisplayDevice>& hw, const Region& clip) const
{
    ATRACE_CALL();

@@ -323,7 +323,7 @@ void Layer::onDraw(const DisplayDevice& hw, const Region& clip) const
            const sp<LayerBase>& layer(drawingLayers[i]);
            if (layer.get() == static_cast<LayerBase const*>(this))
                break;
            under.orSelf( hw.getTransform().transform(layer->visibleRegion) );
            under.orSelf( hw->getTransform().transform(layer->visibleRegion) );
        }
        // if not everything below us is covered, we plug the holes!
        Region holes(clip.subtract(under));
@@ -728,7 +728,6 @@ void Layer::dumpStats(String8& result, char* buffer, size_t SIZE) const
{
    LayerBaseClient::dumpStats(result, buffer, SIZE);
    const size_t o = mFrameLatencyOffset;
    const DisplayDevice& hw(mFlinger->getDefaultDisplayDevice());
    const nsecs_t period = mFlinger->getHwComposer().getRefreshPeriod();
    result.appendFormat("%lld\n", period);
    for (size_t i=0 ; i<128 ; i++) {
@@ -769,8 +768,8 @@ uint32_t Layer::getTransformHint() const {
        // apply to all displays.
        // This is why we use the default display here. This is not an
        // oversight.
        const DisplayDevice& hw(mFlinger->getDefaultDisplayDevice());
        const Transform& planeTransform(hw.getTransform());
        sp<const DisplayDevice> hw(mFlinger->getDefaultDisplayDevice());
        const Transform& planeTransform(hw->getTransform());
        orientation = planeTransform.getOrientation();
        if (orientation & Transform::ROT_INVALID) {
            orientation = 0;
+5 −5
Original line number Diff line number Diff line
@@ -64,18 +64,18 @@ public:
    bool isFixedSize() const;

    // LayerBase interface
    virtual void setGeometry(const DisplayDevice& hw,
    virtual void setGeometry(const sp<const DisplayDevice>& hw,
            HWComposer::HWCLayerInterface& layer);
    virtual void setPerFrameData(const DisplayDevice& hw,
    virtual void setPerFrameData(const sp<const DisplayDevice>& hw,
            HWComposer::HWCLayerInterface& layer);
    virtual void setAcquireFence(const DisplayDevice& hw,
    virtual void setAcquireFence(const sp<const DisplayDevice>& hw,
            HWComposer::HWCLayerInterface& layer);
    virtual void onLayerDisplayed(const DisplayDevice& hw,
    virtual void onLayerDisplayed(const sp<const DisplayDevice>& hw,
            HWComposer::HWCLayerInterface* layer);
    virtual bool onPreComposition();
    virtual void onPostComposition();

    virtual void onDraw(const DisplayDevice& hw, const Region& clip) const;
    virtual void onDraw(const sp<const DisplayDevice>& hw, const Region& clip) const;
    virtual uint32_t doTransaction(uint32_t transactionFlags);
    virtual Region latchBuffer(bool& recomputeVisibleRegions);
    virtual bool isOpaque() const;
+15 −15
Original line number Diff line number Diff line
@@ -223,11 +223,11 @@ uint32_t LayerBase::doTransaction(uint32_t flags)
    return flags;
}

void LayerBase::computeGeometry(const DisplayDevice& hw, LayerMesh* mesh) const
void LayerBase::computeGeometry(const sp<const DisplayDevice>& hw, LayerMesh* mesh) const
{
    const Layer::State& s(drawingState());
    const Transform tr(hw.getTransform() * s.transform);
    const uint32_t hw_h = hw.getHeight();
    const Transform tr(hw->getTransform() * s.transform);
    const uint32_t hw_h = hw->getHeight();
    const Rect& crop(s.active.crop);
    Rect win(s.active.w, s.active.h);
    if (!crop.isEmpty()) {
@@ -260,7 +260,7 @@ Region LayerBase::latchBuffer(bool& recomputeVisibleRegions) {
}

void LayerBase::setGeometry(
        const DisplayDevice& hw,
    const sp<const DisplayDevice>& hw,
        HWComposer::HWCLayerInterface& layer)
{
    layer.setDefaultState();
@@ -281,7 +281,7 @@ void LayerBase::setGeometry(
                HWC_BLENDING_COVERAGE);
    }

    const Transform& tr = hw.getTransform();
    const Transform& tr = hw->getTransform();
    Rect transformedBounds(computeBounds());
    transformedBounds = tr.transform(transformedBounds);

@@ -291,12 +291,12 @@ void LayerBase::setGeometry(
    layer.setVisibleRegionScreen(tr.transform(visibleRegion));
}

void LayerBase::setPerFrameData(const DisplayDevice& hw,
void LayerBase::setPerFrameData(const sp<const DisplayDevice>& hw,
        HWComposer::HWCLayerInterface& layer) {
    layer.setBuffer(0);
}

void LayerBase::setAcquireFence(const DisplayDevice& hw,
void LayerBase::setAcquireFence(const sp<const DisplayDevice>& hw,
        HWComposer::HWCLayerInterface& layer) {
    layer.setAcquireFenceFd(-1);
}
@@ -311,20 +311,20 @@ bool LayerBase::getFiltering() const
    return mFiltering;
}

void LayerBase::draw(const DisplayDevice& hw, const Region& clip) const
void LayerBase::draw(const sp<const DisplayDevice>& hw, const Region& clip) const
{
    onDraw(hw, clip);
}

void LayerBase::draw(const DisplayDevice& hw)
void LayerBase::draw(const sp<const DisplayDevice>& hw)
{
    onDraw( hw, Region(hw.bounds()) );
    onDraw( hw, Region(hw->bounds()) );
}

void LayerBase::clearWithOpenGL(const DisplayDevice& hw, const Region& clip,
void LayerBase::clearWithOpenGL(const sp<const DisplayDevice>& hw, const Region& clip,
        GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) const
{
    const uint32_t fbHeight = hw.getHeight();
    const uint32_t fbHeight = hw->getHeight();
    glColor4f(red,green,blue,alpha);

    glDisable(GL_TEXTURE_EXTERNAL_OES);
@@ -338,14 +338,14 @@ void LayerBase::clearWithOpenGL(const DisplayDevice& hw, const Region& clip,
    glDrawArrays(GL_TRIANGLE_FAN, 0, mesh.getVertexCount());
}

void LayerBase::clearWithOpenGL(const DisplayDevice& hw, const Region& clip) const
void LayerBase::clearWithOpenGL(const sp<const DisplayDevice>& hw, const Region& clip) const
{
    clearWithOpenGL(hw, clip, 0,0,0,0);
}

void LayerBase::drawWithOpenGL(const DisplayDevice& hw, const Region& clip) const
void LayerBase::drawWithOpenGL(const sp<const DisplayDevice>& hw, const Region& clip) const
{
    const uint32_t fbHeight = hw.getHeight();
    const uint32_t fbHeight = hw->getHeight();
    const State& s(drawingState());

    GLenum src = mPremultipliedAlpha ? GL_ONE : GL_SRC_ALPHA;
Loading