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

Commit 71bded51 authored by Dan Stoza's avatar Dan Stoza
Browse files

Create libgfx, starting with FloatRect

Creates libgfx, the future home of everything currently in libui and
libgui, which will be rigorously checked with -Weverything (with a few
common-sense exceptions) and clang-tidy and formatted using the included
.clang-format file.

Starts by moving FloatRect out of services/surfaceflinger since it will
be used by other libgfx primitives later.

Test: m
Change-Id: I5045ac089020e6ee380e81e8735117c500264b37
parent c03d283e
Loading
Loading
Loading
Loading
+11 −0
Original line number Original line Diff line number Diff line
BasedOnStyle: Google

AccessModifierOffset: -2
AllowShortFunctionsOnASingleLine: Inline
BinPackParameters: false
ColumnLimit: 100
CommentPragmas: NOLINT:.*
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 8
IndentWidth: 4
+18 −20
Original line number Original line Diff line number Diff line
@@ -14,31 +14,29 @@
 * limitations under the License.
 * limitations under the License.
 */
 */


#ifndef ANDROID_SF_FLOAT_RECT
#pragma once
#define ANDROID_SF_FLOAT_RECT

#include <ui/Rect.h>
#include <utils/TypeHelpers.h>


namespace android {
namespace android {
namespace gfx {


class FloatRect
class FloatRect {
{
  public:
  public:
    float left;
    FloatRect() = default;
    float top;
    constexpr FloatRect(float _left, float _top, float _right, float _bottom)
    float right;
      : left(_left), top(_top), right(_right), bottom(_bottom) {}
    float bottom;


    inline FloatRect()
    float getWidth() const { return right - left; }
        : left(0), top(0), right(0), bottom(0) { }
    float getHeight() const { return bottom - top; }
    inline FloatRect(const Rect& other)  // NOLINT(implicit)
        : left(other.left), top(other.top), right(other.right), bottom(other.bottom) { }


    inline float getWidth() const { return right - left; }
    float left = 0.0f;
    inline float getHeight() const { return bottom - top; }
    float top = 0.0f;
    float right = 0.0f;
    float bottom = 0.0f;
};
};


}; // namespace android
inline bool operator==(const FloatRect& a, const FloatRect& b) {
    return a.left == b.left && a.top == b.top && a.right == b.right && a.bottom == b.bottom;
}


#endif // ANDROID_SF_FLOAT_RECT
}  // namespace gfx
}  // namespace android
+6 −1
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@
#ifndef ANDROID_UI_RECT
#ifndef ANDROID_UI_RECT
#define ANDROID_UI_RECT
#define ANDROID_UI_RECT


#include <gfx/FloatRect.h>
#include <utils/Flattenable.h>
#include <utils/Flattenable.h>
#include <utils/Log.h>
#include <utils/Log.h>
#include <utils/TypeHelpers.h>
#include <utils/TypeHelpers.h>
@@ -177,11 +178,15 @@ public:
    // this calculates (Region(*this) - exclude).bounds() efficiently
    // this calculates (Region(*this) - exclude).bounds() efficiently
    Rect reduce(const Rect& exclude) const;
    Rect reduce(const Rect& exclude) const;



    // for backward compatibility
    // for backward compatibility
    inline int32_t width() const { return getWidth(); }
    inline int32_t width() const { return getWidth(); }
    inline int32_t height() const { return getHeight(); }
    inline int32_t height() const { return getHeight(); }
    inline void set(const Rect& rhs) { operator = (rhs); }
    inline void set(const Rect& rhs) { operator = (rhs); }

    gfx::FloatRect toFloatRect() const {
        return {static_cast<float>(left), static_cast<float>(top),
                static_cast<float>(right), static_cast<float>(bottom)};
    }
};
};


ANDROID_BASIC_TYPES_TRAITS(Rect)
ANDROID_BASIC_TYPES_TRAITS(Rect)
+3 −0
Original line number Original line Diff line number Diff line
@@ -42,6 +42,9 @@ cc_library_shared {
        "-Wno-nested-anon-types",
        "-Wno-nested-anon-types",
        "-Wno-gnu-anonymous-struct",
        "-Wno-gnu-anonymous-struct",


        // We are aware of the risks inherent in comparing floats for equality
        "-Wno-float-equal",

        "-DDEBUG_ONLY_CODE=0",
        "-DDEBUG_ONLY_CODE=0",
    ],
    ],


+3 −0
Original line number Original line Diff line number Diff line
@@ -28,6 +28,9 @@ cc_library_shared {
        // We only care about compiling as C++14
        // We only care about compiling as C++14
        "-Wno-c++98-compat-pedantic",
        "-Wno-c++98-compat-pedantic",


        // We are aware of the risks inherent in comparing floats for equality
        "-Wno-float-equal",

        // We use four-character constants for the GraphicBuffer header, and don't care
        // We use four-character constants for the GraphicBuffer header, and don't care
        // that they're non-portable as long as they're consistent within one execution
        // that they're non-portable as long as they're consistent within one execution
        "-Wno-four-char-constants",
        "-Wno-four-char-constants",
Loading