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

Commit a8cb3e34 authored by feifanz's avatar feifanz Committed by Gerrit - the friendly Code Review server
Browse files

SF: Add support to draw S3D framebuffer target

Add support to draw S3D framebuffer target in case HWC driver
can not handle due to resource or capability issue.

CRs-fixed: 999055
Change-Id: I536fa4a03e246d51891045b692d5dc5be88f2adf
parent 8eafc8ac
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -145,6 +145,7 @@ ifeq ($(TARGET_USES_QCOM_BSP), true)
    LOCAL_C_INCLUDES += hardware/qcom/display/libqdutils
  endif
    LOCAL_SHARED_LIBRARIES += libqdutils
    LOCAL_SHARED_LIBRARIES += libqdMetaData
    LOCAL_CFLAGS += -DQTI_BSP
endif

+168 −3
Original line number Diff line number Diff line
/* Copyright (c) 2015, The Linux Foundation. All rights reserved.
/* Copyright (c) 2015-2016, The Linux Foundation. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
@@ -36,10 +36,12 @@
#include <ui/GraphicBuffer.h>
#ifdef QTI_BSP
#include <gralloc_priv.h>
#include <qdMetaData.h>
#include <hardware/display_defs.h>
#endif

#include "ExLayer.h"
#include "RenderEngine/RenderEngine.h"

namespace android {

@@ -70,8 +72,9 @@ static Rect getAspectRatio(const sp<const DisplayDevice>& hw,

ExLayer::ExLayer(SurfaceFlinger* flinger, const sp<Client>& client,
                 const String8& name, uint32_t w, uint32_t h, uint32_t flags)
    : Layer(flinger, client, name, w, h, flags) {

    : Layer(flinger, client, name, w, h, flags),
      mMeshLeftTop(Mesh::TRIANGLE_FAN, 4, 2, 2),
      mMeshRightBottom(Mesh::TRIANGLE_FAN, 4, 2, 2) {
    char property[PROPERTY_VALUE_MAX] = {0};

    mDebugLogs = false;
@@ -204,4 +207,166 @@ bool ExLayer::canAllowGPUForProtected() const {
    }
}

#ifdef QTI_BSP
uint32_t ExLayer::getS3dFormat(const sp<const DisplayDevice>& hw) const {
    uint32_t s3d_fmt = HWC_S3DMODE_NONE;
    const sp<GraphicBuffer>& activeBuffer(mActiveBuffer);

    if (activeBuffer != 0) {
        ANativeWindowBuffer* buffer = activeBuffer->getNativeBuffer();
        if (buffer) {
            private_handle_t* hnd = static_cast<private_handle_t*>
                    (const_cast<native_handle_t*>(buffer->handle));
            if (hnd != NULL) {
                struct S3DGpuComp_t s3dComp;
                getMetaData(hnd, GET_S3D_COMP, &s3dComp);
                if (s3dComp.displayId == hw->getHwcDisplayId()) {
                    s3d_fmt = s3dComp.s3dMode;
                }
            }
        }
    }
    return s3d_fmt;
}

void ExLayer::clearS3dFormat(const sp<const DisplayDevice>& hw) const {
    const sp<GraphicBuffer>& activeBuffer(mActiveBuffer);
    if (activeBuffer != 0) {
        ANativeWindowBuffer* buffer = activeBuffer->getNativeBuffer();
        if (buffer) {
            private_handle_t* hnd = static_cast<private_handle_t*>
                (const_cast<native_handle_t*>(buffer->handle));
            if (hnd != NULL) {
                struct S3DGpuComp_t s3dComp;
                getMetaData(hnd, GET_S3D_COMP, &s3dComp);
                if (s3dComp.displayId == hw->getHwcDisplayId()) {
                    clearMetaData(hnd, SET_S3D_COMP);
                }
            }
        }
    }
}

void ExLayer::computeGeometryS3D(const sp<const DisplayDevice>& hw, Mesh& mesh,
        Mesh& meshLeftTop, Mesh& meshRightBottom, uint32_t s3d_fmt) const
{
    Mesh::VertexArray<vec2> position(mesh.getPositionArray<vec2>());
    Mesh::VertexArray<vec2> positionLeftTop(meshLeftTop.getPositionArray<vec2>());
    Mesh::VertexArray<vec2> positionRightBottom(meshRightBottom.getPositionArray<vec2>());
    Mesh::VertexArray<vec2> texCoords(mesh.getTexCoordArray<vec2>());
    Mesh::VertexArray<vec2> texCoordsLeftTop(meshLeftTop.getTexCoordArray<vec2>());
    Mesh::VertexArray<vec2> texCoordsRightBottom(meshRightBottom.getTexCoordArray<vec2>());

    Rect scissor = hw->getBounds();

    uint32_t count = mesh.getVertexCount();
    while(count--) {
        positionLeftTop[count] = positionRightBottom[count] = position[count];
        texCoordsLeftTop[count] = texCoordsRightBottom[count] = texCoords[count];
    }

    switch (s3d_fmt) {
        case HWC_S3DMODE_LR:
        case HWC_S3DMODE_RL:
        {
            positionLeftTop[0].x  = (position[0].x - scissor.left) / 2.0f + scissor.left;
            positionLeftTop[1].x  = (position[1].x - scissor.left) / 2.0f + scissor.left;
            positionLeftTop[2].x  = (position[2].x - scissor.left) / 2.0f + scissor.left;
            positionLeftTop[3].x  = (position[3].x - scissor.left) / 2.0f + scissor.left;

            positionRightBottom[0].x = positionLeftTop[0].x + scissor.getWidth()/2;
            positionRightBottom[1].x = positionLeftTop[1].x + scissor.getWidth()/2;
            positionRightBottom[2].x = positionLeftTop[2].x + scissor.getWidth()/2;
            positionRightBottom[3].x = positionLeftTop[3].x + scissor.getWidth()/2;

            if(isYuvLayer()) {
                texCoordsLeftTop[0].x  =  texCoords[0].x / 2.0f;
                texCoordsLeftTop[1].x  =  texCoords[1].x / 2.0f;
                texCoordsLeftTop[2].x  =  texCoords[2].x / 2.0f;
                texCoordsLeftTop[3].x  =  texCoords[3].x / 2.0f;

                texCoordsRightBottom[0].x  =  texCoordsLeftTop[0].x + 0.5f;
                texCoordsRightBottom[1].x  =  texCoordsLeftTop[1].x + 0.5f;
                texCoordsRightBottom[2].x  =  texCoordsLeftTop[2].x + 0.5f;
                texCoordsRightBottom[3].x  =  texCoordsLeftTop[3].x + 0.5f;
            }
            break;
        }
        case HWC_S3DMODE_TB:
        {
            positionRightBottom[0].y  = (position[0].y - scissor.top) / 2.0f + scissor.top;
            positionRightBottom[1].y  = (position[1].y - scissor.top) / 2.0f + scissor.top;
            positionRightBottom[2].y  = (position[2].y - scissor.top) / 2.0f + scissor.top;
            positionRightBottom[3].y  = (position[3].y - scissor.top) / 2.0f + scissor.top;

            positionLeftTop[0].y = positionRightBottom[0].y + scissor.getHeight() / 2.0f;
            positionLeftTop[1].y = positionRightBottom[1].y + scissor.getHeight() / 2.0f;
            positionLeftTop[2].y = positionRightBottom[2].y + scissor.getHeight() / 2.0f;
            positionLeftTop[3].y = positionRightBottom[3].y + scissor.getHeight() / 2.0f;

            positionLeftTop[0].x = positionRightBottom[0].x = position[0].x;
            positionLeftTop[1].x = positionRightBottom[1].x = position[1].x;
            positionLeftTop[2].x = positionRightBottom[2].x = position[2].x;
            positionLeftTop[3].x = positionRightBottom[3].x = position[3].x;

            if(isYuvLayer()) {
                texCoordsRightBottom[0].y  =  texCoords[0].y / 2.0f;
                texCoordsRightBottom[1].y  =  texCoords[1].y / 2.0f;
                texCoordsRightBottom[2].y  =  texCoords[2].y / 2.0f;
                texCoordsRightBottom[3].y  =  texCoords[3].y / 2.0f;

                texCoordsLeftTop[0].y  =  texCoordsRightBottom[0].y + 0.5f;
                texCoordsLeftTop[1].y  =  texCoordsRightBottom[1].y + 0.5f;
                texCoordsLeftTop[2].y  =  texCoordsRightBottom[2].y + 0.5f;
                texCoordsLeftTop[3].y  =  texCoordsRightBottom[3].y + 0.5f;
            }
            break;
        }
        default:
            break;
    }
}

void ExLayer::handleOpenGLDraw(const sp<const DisplayDevice>& hw,
    Mesh& mesh) const
{
    const State& s(getDrawingState());
    RenderEngine& engine(mFlinger->getRenderEngine());
    engine.setupLayerBlending(mPremultipliedAlpha, isOpaque(s), s.alpha);
    uint32_t s3d_fmt = getS3dFormat(hw);
    if (s3d_fmt == HWC_S3DMODE_NONE) {
        engine.drawMesh(mesh);
    } else {
        computeGeometryS3D(hw, mesh, mMeshLeftTop, mMeshRightBottom, s3d_fmt);
        // in non-primary case scissor might be not equal to hw bounds
        engine.setScissor(0, 0, hw->getWidth(), hw->getHeight());
        engine.drawMesh(mMeshLeftTop);
        engine.drawMesh(mMeshRightBottom);
        clearS3dFormat(hw);
    }
    engine.disableBlending();
}
#else
uint32_t ExLayer::getS3dFormat(const sp<const DisplayDevice>&) const {
    return 0;
}

void ExLayer::clearS3dFormat(const sp<const DisplayDevice>&) const {
}

void ExLayer::computeGeometryS3D(const sp<const DisplayDevice>&, Mesh&,
        Mesh&, Mesh&, uint32_t) const {
}

void ExLayer::handleOpenGLDraw(const sp<const DisplayDevice>& /* hw */,
            Mesh& mesh) const {
    const State& s(getDrawingState());
    RenderEngine& engine(mFlinger->getRenderEngine());

    engine.setupLayerBlending(mPremultipliedAlpha, isOpaque(s), s.alpha);
    engine.drawMesh(mesh);
    engine.disableBlending();
}
#endif

}; // namespace android
+13 −1
Original line number Diff line number Diff line
/* Copyright (c) 2015, The Linux Foundation. All rights reserved.
/* Copyright (c) 2015-2016, The Linux Foundation. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
@@ -51,16 +51,28 @@ public:
    virtual bool isIntOnly() const;
    virtual bool isSecureDisplay() const;
    virtual bool isYuvLayer() const;
    virtual uint32_t getS3dFormat(const sp<const DisplayDevice>& hw) const;
    virtual void clearS3dFormat(const sp<const DisplayDevice>& hw) const;
    virtual void setPosition(const sp<const DisplayDevice>& hw,
                             HWComposer::HWCLayerInterface& layer, const State& state);
    virtual void setAcquiredFenceIfBlit(int &fenceFd,
                             HWComposer::HWCLayerInterface& layer);
    virtual bool canAllowGPUForProtected() const;
    virtual void handleOpenGLDraw(const sp<const DisplayDevice>& hw, Mesh& mesh) const;

protected:
    bool mDebugLogs;
    bool isDebug() { return mDebugLogs; }
    bool mIsGPUAllowedForProtected;

private:
    // The mesh used to draw the layer in GLES composition for s3d left/top
    mutable Mesh mMeshLeftTop;
    // The mesh used to draw the layer in GLES composition for s3d right/bottom
    mutable Mesh mMeshRightBottom;
    // split mesh into right/bottom or left/right parts for s3d
    void computeGeometryS3D(const sp<const DisplayDevice>& hw, Mesh& mesh,
        Mesh& meshLeftTop, Mesh &meshRightBottom, uint32_t s3d_fmt) const;
};

}; // namespace android
+25 −1
Original line number Diff line number Diff line
/* Copyright (c) 2015, The Linux Foundation. All rights reserved.
/* Copyright (c) 2015-2016, The Linux Foundation. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
@@ -33,6 +33,7 @@
#ifdef QTI_BSP
#include <hardware/display_defs.h>
#endif

#define ATRACE_TAG ATRACE_TAG_GRAPHICS

namespace android {
@@ -269,6 +270,29 @@ void ExSurfaceFlinger::drawWormHoleIfRequired(HWComposer::LayerListIterator& cur
    }
}

#ifdef QTI_BSP
bool ExSurfaceFlinger::isS3DLayerPresent(const sp<const DisplayDevice>& hw) {
    const Vector< sp<Layer> >& visibleLayersSortedByZ =
                hw->getVisibleLayersSortedByZ();
    for (size_t i = 0 ; i < visibleLayersSortedByZ.size() ; i++) {
        const sp<Layer>& layer(visibleLayersSortedByZ[i]);
        // LayerDim doesn't have getS3dFormat. This is to avoid RTTI.
        if(strncmp(layer->getTypeId(), "LayerDim", strlen("LayerDim"))) {
            const sp<ExLayer>& exLayer =
                reinterpret_cast<const sp<ExLayer>&>(layer);
            if (exLayer->getS3dFormat(hw) != HWC_S3DMODE_NONE) {
                return true;
            }
        }
    }
    return false;
}
#else
bool ExSurfaceFlinger::isS3DLayerPresent(const sp<const DisplayDevice>&) {
    return false;
}
#endif

#ifdef DEBUG_CONT_DUMPSYS
status_t ExSurfaceFlinger::dump(int fd, const Vector<String16>& args) {
    // Format: adb shell dumpsys SurfaceFlinger --file --no-limit
+2 −1
Original line number Diff line number Diff line
/* Copyright (c) 2015, The Linux Foundation. All rights reserved.
/* Copyright (c) 2015-2016, The Linux Foundation. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
@@ -68,6 +68,7 @@ protected:
                     const HWComposer::LayerListIterator& /*end*/,
                     const sp<const DisplayDevice>& hw,
                     const Region& region);
    virtual bool isS3DLayerPresent(const sp<const DisplayDevice>& hw);
    virtual ~ExSurfaceFlinger();

    /* Extended Mode
Loading