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

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

surfaceflinger: use Vulkan coordinate system

In Vulkan coordinate system, (0, 0) always maps to memory address 0.
In GL coordinate system, (0, 0) maps to the bottom-left corner.  The
two agree when doing offscreen rendering.  But when rendering to a
window, GL maps (0, 0) to memory address (winHeight-1)*rowStride,
because that is where the bottom-left pixel is.

Let's pick the simpler one for RenderEngine in preparation for
multiple backends.  As a result, we don't need yswap when rendering
to offscreen buffers (it is hidden behind the RenderEngine API).  It
also makes no sense to flip Y coordinate for both vertex postions
and the viewing volume.

Test: chrome, youtube, camera, screen rotation, screenshots, recents
Change-Id: I6d6317bac3de6f208700a67e518011362c600ced
parent 8730ba81
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -834,10 +834,10 @@ void GLConsumer::computeTransformMatrix(float outTransform[16],
        xform = crop * xform;
    }

    // SurfaceFlinger expects the top of its window textures to be at a Y
    // coordinate of 0, so GLConsumer must behave the same way.  We don't
    // want to expose this to applications, however, so we must add an
    // additional vertical flip to the transform after all the other transforms.
    // GLConsumer uses the GL convention where (0, 0) is the bottom-left
    // corner and (1, 1) is the top-right corner.  Add an additional vertical
    // flip after all other transforms to map from GL convention to buffer
    // queue memory layout, where (0, 0) is the top-left corner.
    xform = mtxFlipV * xform;

    memcpy(outTransform, xform.asArray(), sizeof(xform));
+1 −0
Original line number Diff line number Diff line
@@ -609,6 +609,7 @@ void BufferLayer::drawWithOpenGL(const RenderArea& renderArea, bool useIdentityT
    // TODO: we probably want to generate the texture coords with the mesh
    // here we assume that we only have 4 vertices
    renderengine::Mesh::VertexArray<vec2> texCoords(getBE().mMesh.getTexCoordArray<vec2>());
    // flip texcoords vertically because BufferLayerConsumer expects them to be in GL convention
    texCoords[0] = vec2(left, 1.0f - top);
    texCoords[1] = vec2(left, 1.0f - bottom);
    texCoords[2] = vec2(right, 1.0f - bottom);
+1 −2
Original line number Diff line number Diff line
@@ -386,8 +386,7 @@ void DisplayDevice::setViewportAndProjection() const {
    size_t w = mDisplayWidth;
    size_t h = mDisplayHeight;
    Rect sourceCrop(0, 0, w, h);
    mFlinger->getRenderEngine().setViewportAndProjection(w, h, sourceCrop, h,
        false, ui::Transform::ROT_0);
    mFlinger->getRenderEngine().setViewportAndProjection(w, h, sourceCrop, ui::Transform::ROT_0);
}

const sp<Fence>& DisplayDevice::getClientTargetAcquireFence() const {
+0 −4
Original line number Diff line number Diff line
@@ -791,7 +791,6 @@ void Layer::computeGeometry(const RenderArea& renderArea,
                            bool useIdentityTransform) const {
    const Layer::State& s(getDrawingState());
    const ui::Transform renderAreaTransform(renderArea.getTransform());
    const uint32_t height = renderArea.getHeight();
    FloatRect win = computeBounds();

    vec2 lt = vec2(win.left, win.top);
@@ -820,9 +819,6 @@ void Layer::computeGeometry(const RenderArea& renderArea,
    position[1] = renderAreaTransform.transform(lb);
    position[2] = renderAreaTransform.transform(rb);
    position[3] = renderAreaTransform.transform(rt);
    for (size_t i = 0; i < 4; i++) {
        position[i].y = height - position[i].y;
    }
}

bool Layer::isSecure() const {
+9 −11
Original line number Diff line number Diff line
@@ -160,21 +160,15 @@ size_t GLES20RenderEngine::getMaxViewportDims() const {
}

void GLES20RenderEngine::setViewportAndProjection(size_t vpw, size_t vph, Rect sourceCrop,
                                                  size_t hwh, bool yswap,
                                                  ui::Transform::orientation_flags rotation) {
    int32_t l = sourceCrop.left;
    int32_t r = sourceCrop.right;

    // In GL, (0, 0) is the bottom-left corner, so flip y coordinates
    int32_t t = hwh - sourceCrop.top;
    int32_t b = hwh - sourceCrop.bottom;

    mat4 m;
    if (yswap) {
        m = mat4::ortho(l, r, t, b, 0, 1);
    } else {
        m = mat4::ortho(l, r, b, t, 0, 1);
    int32_t b = sourceCrop.bottom;
    int32_t t = sourceCrop.top;
    if (mRenderToFbo) {
        std::swap(t, b);
    }
    mat4 m = mat4::ortho(l, r, b, t, 0, 1);

    // Apply custom rotation to the projection.
    float rot90InRadians = 2.0f * static_cast<float>(M_PI) / 4.0f;
@@ -284,9 +278,13 @@ void GLES20RenderEngine::bindImageAsFramebuffer(EGLImageKHR image, uint32_t* tex
    *status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
    *texName = tname;
    *fbName = name;

    mRenderToFbo = true;
}

void GLES20RenderEngine::unbindFramebuffer(uint32_t texName, uint32_t fbName) {
    mRenderToFbo = false;

    glBindFramebuffer(GL_FRAMEBUFFER, 0);
    glDeleteFramebuffers(1, &fbName);
    glDeleteTextures(1, &texName);
Loading