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

Commit 71d4b376 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes Idcd4808c,I108ccb75,I446e5795,Idae2d3d9,I2a81817c

* changes:
  SF: Separate out display color handling
  SF: Separate out render surface code
  SF: Move DisplaySurface into CompositionEngine
  SF: Move state out of DisplayDevice to a new Output class
  SF: Setup CompositionEngine::Display
parents 85fda419 3d0c02e7
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@ cc_library_shared {
        "PixelFormat.cpp",
        "Rect.cpp",
        "Region.cpp",
        "Size.cpp",
        "Transform.cpp",
        "UiConfig.cpp",
    ],

libs/ui/Size.cpp

0 → 100644
+24 −0
Original line number Diff line number Diff line
/*
 * Copyright 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <ui/Size.h>

namespace android::ui {

const Size Size::INVALID{-1, -1};
const Size Size::EMPTY{0, 0};

} // namespace android::ui
+35 −31
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

#include <math.h>

#include <android-base/stringprintf.h>
#include <cutils/compiler.h>
#include <ui/Region.h>
#include <ui/Transform.h>
@@ -380,44 +381,47 @@ bool Transform::preserveRects() const
    return (getOrientation() & ROT_INVALID) ? false : true;
}

void Transform::dump(const char* name) const
{
    type(); // updates the type
void Transform::dump(std::string& out, const char* name) const {
    using android::base::StringAppendF;

    type(); // Ensure the information in mType is up to date

    String8 flags, type;
    const mat33& m(mMatrix);
    uint32_t orient = mType >> 8;
    const uint32_t type = mType;
    const uint32_t orient = type >> 8;

    StringAppendF(&out, "%s 0x%08x (", name, orient);

    if (orient & ROT_INVALID) {
        flags.append("ROT_INVALID ");
        out.append("ROT_INVALID ");
    } else {
        if (orient & ROT_90) {
            flags.append("ROT_90 ");
            out.append("ROT_90 ");
        } else {
            flags.append("ROT_0 ");
        }
        if (orient&FLIP_V)
            flags.append("FLIP_V ");
        if (orient&FLIP_H)
            flags.append("FLIP_H ");
    }

    if (!(mType&(SCALE|ROTATE|TRANSLATE)))
        type.append("IDENTITY ");
    if (mType&SCALE)
        type.append("SCALE ");
    if (mType&ROTATE)
        type.append("ROTATE ");
    if (mType&TRANSLATE)
        type.append("TRANSLATE ");

    ALOGD("%s 0x%08x (%s, %s)", name, mType, flags.string(), type.string());
    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]));
            out.append("ROT_0 ");
        }
        if (orient & FLIP_V) out.append("FLIP_V ");
        if (orient & FLIP_H) out.append("FLIP_H ");
    }

    StringAppendF(&out, ") 0x%02x (", type);

    if (!(type & (SCALE | ROTATE | TRANSLATE))) out.append("IDENTITY ");
    if (type & SCALE) out.append("SCALE ");
    if (type & ROTATE) out.append("ROTATE ");
    if (type & TRANSLATE) out.append("TRANSLATE ");

    out.append(")\n");

    for (size_t i = 0; i < 3; i++) {
        StringAppendF(&out, "    %.4f  %.4f  %.4f\n", static_cast<double>(mMatrix[0][i]),
                      static_cast<double>(mMatrix[1][i]), static_cast<double>(mMatrix[2][i]));
    }
}

void Transform::dump(const char* name) const {
    std::string out;
    dump(out, name);
    ALOGD("%s", out.c_str());
}

}  // namespace ui
+10 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@

#include <ui/FloatRect.h>
#include <ui/Point.h>
#include <ui/Size.h>

#include <android/rect.h>

@@ -78,6 +79,13 @@ public:
        bottom = static_cast<int32_t>(floatRect.bottom + 0.5f);
    }

    inline explicit Rect(const ui::Size& size) {
        left = 0;
        top = 0;
        right = size.width;
        bottom = size.height;
    }

    void makeInvalid();

    inline void clear() {
@@ -106,6 +114,8 @@ public:
        return bottom - top;
    }

    ui::Size getSize() const { return ui::Size(getWidth(), getHeight()); }

    __attribute__((no_sanitize("signed-integer-overflow")))
    inline Rect getBounds() const {
        return Rect(right - left, bottom - top);
+158 −0
Original line number Diff line number Diff line
/*
 * Copyright 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <algorithm>
#include <cstdint>
#include <limits>
#include <type_traits>
#include <utility>

namespace android {
namespace ui {

// Forward declare a few things.
struct Size;
bool operator==(const Size& lhs, const Size& rhs);

/**
 * A simple value type representing a two-dimensional size
 */
struct Size {
    int32_t width;
    int32_t height;

    // Special values
    static const Size INVALID;
    static const Size EMPTY;

    // ------------------------------------------------------------------------
    // Construction
    // ------------------------------------------------------------------------

    Size() : Size(INVALID) {}
    template <typename T>
    Size(T&& w, T&& h)
          : width(Size::clamp<int32_t, T>(std::forward<T>(w))),
            height(Size::clamp<int32_t, T>(std::forward<T>(h))) {}

    // ------------------------------------------------------------------------
    // Accessors
    // ------------------------------------------------------------------------

    int32_t getWidth() const { return width; }
    int32_t getHeight() const { return height; }

    template <typename T>
    void setWidth(T&& v) {
        width = Size::clamp<int32_t, T>(std::forward<T>(v));
    }
    template <typename T>
    void setHeight(T&& v) {
        height = Size::clamp<int32_t, T>(std::forward<T>(v));
    }

    // ------------------------------------------------------------------------
    // Assignment
    // ------------------------------------------------------------------------

    void set(const Size& size) { *this = size; }
    template <typename T>
    void set(T&& w, T&& h) {
        set(Size(std::forward<T>(w), std::forward<T>(h)));
    }

    // Sets the value to INVALID
    void makeInvalid() { set(INVALID); }

    // Sets the value to EMPTY
    void clear() { set(EMPTY); }

    // ------------------------------------------------------------------------
    // Semantic checks
    // ------------------------------------------------------------------------

    // Valid means non-negative width and height
    bool isValid() const { return width >= 0 && height >= 0; }

    // Empty means zero width and height
    bool isEmpty() const { return *this == EMPTY; }

    // ------------------------------------------------------------------------
    // Clamp Helpers
    // ------------------------------------------------------------------------

    // Note: We use only features available in C++11 here for compatibility with
    // external targets which include this file directly or indirectly and which
    // themselves use C++11.

    // C++11 compatible replacement for std::remove_cv_reference_t [C++20]
    template <typename T>
    using remove_cv_reference_t =
            typename std::remove_cv<typename std::remove_reference<T>::type>::type;

    // Takes a value of type FromType, and ensures it can be represented as a value of type ToType,
    // clamping the input value to the output range if necessary.
    template <typename ToType, typename FromType>
    static Size::remove_cv_reference_t<ToType> clamp(
            typename std::enable_if<
                    std::numeric_limits<Size::remove_cv_reference_t<ToType>>::is_bounded &&
                            std::numeric_limits<Size::remove_cv_reference_t<FromType>>::is_bounded,
                    FromType&&>::type v) {
        static constexpr auto toHighest = std::numeric_limits<remove_cv_reference_t<ToType>>::max();
        static constexpr auto toLowest =
                std::numeric_limits<remove_cv_reference_t<ToType>>::lowest();
        static constexpr auto fromHighest =
                std::numeric_limits<remove_cv_reference_t<FromType>>::max();
        static constexpr auto fromLowest =
                std::numeric_limits<remove_cv_reference_t<FromType>>::lowest();

        // A clamp is needed if the range of FromType is not a subset of the range of ToType
        static constexpr bool isClampNeeded = (toLowest > fromLowest) || (toHighest < fromHighest);

        // If a clamp is not needed, the conversion is just a trivial cast.
        if (!isClampNeeded) {
            return static_cast<ToType>(v);
        }

        // Otherwise we leverage implicit conversion to safely compare values of
        // different types, to ensure we return a value clamped to the range of
        // ToType.
        return v < toLowest ? toLowest : (v > toHighest ? toHighest : static_cast<ToType>(v));
    }
};

// ------------------------------------------------------------------------
// Comparisons
// ------------------------------------------------------------------------

inline bool operator==(const Size& lhs, const Size& rhs) {
    return lhs.width == rhs.width && lhs.height == rhs.height;
}

inline bool operator!=(const Size& lhs, const Size& rhs) {
    return !operator==(lhs, rhs);
}

inline bool operator<(const Size& lhs, const Size& rhs) {
    // Orders by increasing width, then height.
    if (lhs.width != rhs.width) return lhs.width < rhs.width;
    return lhs.height < rhs.height;
}

} // namespace ui
} // namespace android
Loading