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

Commit efefaac7 authored by Peiyong Lin's avatar Peiyong Lin
Browse files

[SurfaceFlinger] Move Transform to libs/ui

A bunch of code in SurfaceFlinger uses Transform, so does RenderEngine. In
order to move RenderEngine to its own library, we need to lift Transform to
another place where it's part of VNDK. Since Transform depends on libs/ui, we
move Transform to libs/ui as well.

BUG: 112585051
Test: Build, flash, boot and check transformation.
Change-Id: Ie4d13ee135ba3f71fcbd9f86994a0b048e2c6878
parent 3db42346
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ cc_library_shared {
        "PixelFormat.cpp",
        "Rect.cpp",
        "Region.cpp",
        "Transform.cpp",
        "UiConfig.cpp",
    ],

+33 −47
Original line number Diff line number Diff line
@@ -17,16 +17,12 @@
#include <math.h>

#include <cutils/compiler.h>
#include <utils/String8.h>
#include <ui/Region.h>

#include "Transform.h"

// ---------------------------------------------------------------------------
#include <ui/Transform.h>
#include <utils/String8.h>

namespace android {

// ---------------------------------------------------------------------------
namespace ui {

Transform::Transform() {
    reset();
@@ -40,8 +36,7 @@ Transform::Transform(uint32_t orientation) {
    set(orientation, 0, 0);
}

Transform::~Transform() {
}
Transform::~Transform() = default;

static const float EPSILON = 0.0f;

@@ -66,7 +61,7 @@ Transform Transform::operator * (const Transform& rhs) const
    const mat33& A(mMatrix);
    const mat33& B(rhs.mMatrix);
          mat33& D(r.mMatrix);
    for (int i=0 ; i<3 ; i++) {
    for (size_t i = 0; i < 3; i++) {
        const float v0 = A[0][i];
        const float v1 = A[1][i];
        const float v2 = A[2][i];
@@ -82,6 +77,12 @@ Transform Transform::operator * (const Transform& rhs) const
    return r;
}

Transform& Transform::operator=(const Transform& other) {
    mMatrix = other.mMatrix;
    mType = other.mType;
    return *this;
}

const vec3& Transform::operator [] (size_t i) const {
    return mMatrix[i];
}
@@ -96,9 +97,9 @@ float Transform::ty() const {

void Transform::reset() {
    mType = IDENTITY;
    for(int i=0 ; i<3 ; i++) {
    for(size_t i = 0; i < 3; i++) {
        vec3& v(mMatrix[i]);
        for (int j=0 ; j<3 ; j++)
        for (size_t j = 0; j < 3; j++)
            v[j] = ((i == j) ? 1.0f : 0.0f);
    }
}
@@ -209,15 +210,15 @@ Rect Transform::transform(const Rect& bounds, bool roundOutwards) const
    rb = transform(rb);

    if (roundOutwards) {
        r.left   = floorf(std::min({lt[0], rt[0], lb[0], rb[0]}));
        r.top    = floorf(std::min({lt[1], rt[1], lb[1], rb[1]}));
        r.right  = ceilf(std::max({lt[0], rt[0], lb[0], rb[0]}));
        r.bottom = ceilf(std::max({lt[1], rt[1], lb[1], rb[1]}));
        r.left   = static_cast<int32_t>(floorf(std::min({lt[0], rt[0], lb[0], rb[0]})));
        r.top    = static_cast<int32_t>(floorf(std::min({lt[1], rt[1], lb[1], rb[1]})));
        r.right  = static_cast<int32_t>(ceilf(std::max({lt[0], rt[0], lb[0], rb[0]})));
        r.bottom = static_cast<int32_t>(ceilf(std::max({lt[1], rt[1], lb[1], rb[1]})));
    } else {
        r.left   = floorf(std::min({lt[0], rt[0], lb[0], rb[0]}) + 0.5f);
        r.top    = floorf(std::min({lt[1], rt[1], lb[1], rb[1]}) + 0.5f);
        r.right  = floorf(std::max({lt[0], rt[0], lb[0], rb[0]}) + 0.5f);
        r.bottom = floorf(std::max({lt[1], rt[1], lb[1], rb[1]}) + 0.5f);
        r.left   = static_cast<int32_t>(floorf(std::min({lt[0], rt[0], lb[0], rb[0]}) + 0.5f));
        r.top    = static_cast<int32_t>(floorf(std::min({lt[1], rt[1], lb[1], rb[1]}) + 0.5f));
        r.right  = static_cast<int32_t>(floorf(std::max({lt[0], rt[0], lb[0], rb[0]}) + 0.5f));
        r.bottom = static_cast<int32_t>(floorf(std::max({lt[1], rt[1], lb[1], rb[1]}) + 0.5f));
    }

    return r;
@@ -258,8 +259,8 @@ Region Transform::transform(const Region& reg) const
            out.set(transform(reg.bounds()));
        }
    } else {
        int xpos = floorf(tx() + 0.5f);
        int ypos = floorf(ty() + 0.5f);
        int xpos = static_cast<int>(floorf(tx() + 0.5f));
        int ypos = static_cast<int>(floorf(ty() + 0.5f));
        out = reg.translate(xpos, ypos);
    }
    return out;
@@ -342,7 +343,7 @@ Transform Transform::inverse() const {
        const float x = M[2][0];
        const float y = M[2][1];

        const float idet = 1.0 / (a*d - b*c);
        const float idet = 1.0f / (a*d - b*c);
        result.mMatrix[0][0] =  d*idet;
        result.mMatrix[0][1] = -c*idet;
        result.mMatrix[1][0] = -b*idet;
@@ -403,28 +404,13 @@ void Transform::dump(const char* name) const
        type.append("TRANSLATE ");

    ALOGD("%s 0x%08x (%s, %s)", name, mType, flags.string(), type.string());
    ALOGD("%.4f  %.4f  %.4f", m[0][0], m[1][0], m[2][0]);
    ALOGD("%.4f  %.4f  %.4f", m[0][1], m[1][1], m[2][1]);
    ALOGD("%.4f  %.4f  %.4f", m[0][2], m[1][2], m[2][2]);
}

Transform::orientation_flags Transform::fromRotation(ISurfaceComposer::Rotation rotation) {
    // Convert to surfaceflinger's internal rotation type.
    switch (rotation) {
        case ISurfaceComposer::eRotateNone:
            return Transform::ROT_0;
        case ISurfaceComposer::eRotate90:
            return Transform::ROT_90;
        case ISurfaceComposer::eRotate180:
            return Transform::ROT_180;
        case ISurfaceComposer::eRotate270:
            return Transform::ROT_270;
        default:
            ALOGE("Invalid rotation passed to captureScreen(): %d\n", rotation);
            return Transform::ROT_0;
    }
    ALOGD("%.4f  %.4f  %.4f", static_cast<double>(m[0][0]), static_cast<double>(m[1][0]),
          static_cast<double>(m[2][0]));
    ALOGD("%.4f  %.4f  %.4f", static_cast<double>(m[0][1]), static_cast<double>(m[1][1]),
          static_cast<double>(m[2][1]));
    ALOGD("%.4f  %.4f  %.4f", static_cast<double>(m[0][2]), static_cast<double>(m[1][2]),
          static_cast<double>(m[2][2]));
}

// ---------------------------------------------------------------------------

}; // namespace android
}  // namespace ui
}  // namespace android
+113 −0
Original line number Diff line number Diff line
@@ -20,23 +20,19 @@
#include <stdint.h>
#include <sys/types.h>

#include <ui/Point.h>
#include <ui/Rect.h>
#include <hardware/hardware.h>
#include <math/vec2.h>
#include <math/vec3.h>

#include <gui/ISurfaceComposer.h>

#include <hardware/hardware.h>
#include <ui/Point.h>
#include <ui/Rect.h>

namespace android {

class Region;

// ---------------------------------------------------------------------------
namespace ui {

class Transform
{
class Transform {
public:
    Transform();
    Transform(const Transform&  other);
@@ -53,9 +49,7 @@ public:
        ROT_INVALID = 0x80
    };

            static orientation_flags fromRotation(ISurfaceComposer::Rotation rotation);

            enum type_mask {
    enum type_mask : uint32_t {
        IDENTITY            = 0,
        TRANSLATE           = 0x1,
        ROTATE              = 0x2,
@@ -85,6 +79,7 @@ public:
    Rect    transform(const Rect& bounds,
                      bool roundOutwards = false) const;
    FloatRect transform(const FloatRect& bounds) const;
    Transform& operator = (const Transform& other);
    Transform operator * (const Transform& rhs) const;
    // assumes the last row is < 0 , 0 , 1 >
    vec2 transform(const vec2& v) const;
@@ -98,8 +93,8 @@ public:
private:
    struct mat33 {
        vec3 v[3];
        inline const vec3& operator [] (int i) const { return v[i]; }
        inline vec3& operator [] (int i) { return v[i]; }
        inline const vec3& operator [] (size_t i) const { return v[i]; }
        inline vec3& operator [] (size_t i) { return v[i]; }
    };

    enum { UNKNOWN_TYPE = 0x80000000 };
@@ -112,7 +107,7 @@ private:
    mutable uint32_t    mType;
};

// ---------------------------------------------------------------------------
}; // namespace android
}  // namespace ui
}  // namespace android

#endif /* ANDROID_TRANSFORM_H */
+0 −1
Original line number Diff line number Diff line
@@ -137,7 +137,6 @@ filegroup {
        "SurfaceInterceptor.cpp",
        "SurfaceTracing.cpp",
        "TimeStats/TimeStats.cpp",
        "Transform.cpp",
    ],
}

+2 −2
Original line number Diff line number Diff line
@@ -258,7 +258,7 @@ bool BufferLayer::isHdrY410() const {
void BufferLayer::setPerFrameData(const sp<const DisplayDevice>& display) {
    // Apply this display's projection's viewport to the visible region
    // before giving it to the HWC HAL.
    const Transform& tr = display->getTransform();
    const ui::Transform& tr = display->getTransform();
    const auto& viewport = display->getViewport();
    Region visible = tr.transform(visibleRegion.intersect(viewport));
    const auto displayId = display->getId();
@@ -638,7 +638,7 @@ void BufferLayer::drawWithOpenGL(const RenderArea& renderArea, bool useIdentityT
     */
    const Rect bounds{computeBounds()}; // Rounds from FloatRect

    Transform t = getTransform();
    ui::Transform t = getTransform();
    Rect win = bounds;
    Rect finalCrop = getFinalCrop(s);
    if (!finalCrop.isEmpty()) {
Loading