summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Dan Stoza <stoza@google.com> 2016-10-19 11:10:33 -0700
committer Dan Stoza <stoza@google.com> 2016-12-29 15:16:41 -0800
commit71bded513d37a6c1260b4a62c69ecc0d24be95f7 (patch)
tree7ffd1730954cd23844985dcd3c956d9ac2aa3a60
parentc03d283e8b3f830d76dd94822b2a13872c05c730 (diff)
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
-rw-r--r--include/gfx/.clang-format11
-rw-r--r--include/gfx/FloatRect.h (renamed from services/surfaceflinger/DisplayHardware/FloatRect.h)38
-rw-r--r--include/ui/Rect.h7
-rw-r--r--libs/gui/Android.bp3
-rw-r--r--libs/ui/Android.bp3
-rw-r--r--services/surfaceflinger/DisplayHardware/HWC2.cpp4
-rw-r--r--services/surfaceflinger/DisplayHardware/HWC2.h8
-rw-r--r--services/surfaceflinger/DisplayHardware/HWComposer_hwc1.cpp2
-rw-r--r--services/surfaceflinger/DisplayHardware/HWComposer_hwc1.h6
-rw-r--r--services/surfaceflinger/Layer.cpp8
-rw-r--r--services/surfaceflinger/Layer.h7
-rw-r--r--vulkan/libvulkan/Android.bp1
12 files changed, 62 insertions, 36 deletions
diff --git a/include/gfx/.clang-format b/include/gfx/.clang-format
new file mode 100644
index 0000000000..86763a0cb4
--- /dev/null
+++ b/include/gfx/.clang-format
@@ -0,0 +1,11 @@
+BasedOnStyle: Google
+
+AccessModifierOffset: -2
+AllowShortFunctionsOnASingleLine: Inline
+BinPackParameters: false
+ColumnLimit: 100
+CommentPragmas: NOLINT:.*
+ConstructorInitializerAllOnOneLineOrOnePerLine: true
+ConstructorInitializerIndentWidth: 2
+ContinuationIndentWidth: 8
+IndentWidth: 4
diff --git a/services/surfaceflinger/DisplayHardware/FloatRect.h b/include/gfx/FloatRect.h
index 151eaaa622..6be5e22ef5 100644
--- a/services/surfaceflinger/DisplayHardware/FloatRect.h
+++ b/include/gfx/FloatRect.h
@@ -14,31 +14,29 @@
* limitations under the License.
*/
-#ifndef ANDROID_SF_FLOAT_RECT
-#define ANDROID_SF_FLOAT_RECT
-
-#include <ui/Rect.h>
-#include <utils/TypeHelpers.h>
+#pragma once
namespace android {
+namespace gfx {
-class FloatRect
-{
-public:
- float left;
- float top;
- float right;
- float bottom;
+class FloatRect {
+ public:
+ FloatRect() = default;
+ constexpr FloatRect(float _left, float _top, float _right, float _bottom)
+ : left(_left), top(_top), right(_right), bottom(_bottom) {}
- inline FloatRect()
- : left(0), top(0), right(0), bottom(0) { }
- inline FloatRect(const Rect& other) // NOLINT(implicit)
- : left(other.left), top(other.top), right(other.right), bottom(other.bottom) { }
+ float getWidth() const { return right - left; }
+ float getHeight() const { return bottom - top; }
- inline float getWidth() const { return right - left; }
- inline float getHeight() const { return bottom - top; }
+ float left = 0.0f;
+ 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
diff --git a/include/ui/Rect.h b/include/ui/Rect.h
index a8513a9004..d4eea025b4 100644
--- a/include/ui/Rect.h
+++ b/include/ui/Rect.h
@@ -17,6 +17,7 @@
#ifndef ANDROID_UI_RECT
#define ANDROID_UI_RECT
+#include <gfx/FloatRect.h>
#include <utils/Flattenable.h>
#include <utils/Log.h>
#include <utils/TypeHelpers.h>
@@ -177,11 +178,15 @@ public:
// this calculates (Region(*this) - exclude).bounds() efficiently
Rect reduce(const Rect& exclude) const;
-
// for backward compatibility
inline int32_t width() const { return getWidth(); }
inline int32_t height() const { return getHeight(); }
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)
diff --git a/libs/gui/Android.bp b/libs/gui/Android.bp
index bf758cea4b..57fc268b36 100644
--- a/libs/gui/Android.bp
+++ b/libs/gui/Android.bp
@@ -42,6 +42,9 @@ cc_library_shared {
"-Wno-nested-anon-types",
"-Wno-gnu-anonymous-struct",
+ // We are aware of the risks inherent in comparing floats for equality
+ "-Wno-float-equal",
+
"-DDEBUG_ONLY_CODE=0",
],
diff --git a/libs/ui/Android.bp b/libs/ui/Android.bp
index c207a7996b..4cd0d3aa32 100644
--- a/libs/ui/Android.bp
+++ b/libs/ui/Android.bp
@@ -28,6 +28,9 @@ cc_library_shared {
// We only care about compiling as C++14
"-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
// that they're non-portable as long as they're consistent within one execution
"-Wno-four-char-constants",
diff --git a/services/surfaceflinger/DisplayHardware/HWC2.cpp b/services/surfaceflinger/DisplayHardware/HWC2.cpp
index 85c21b2ae1..1502eeb806 100644
--- a/services/surfaceflinger/DisplayHardware/HWC2.cpp
+++ b/services/surfaceflinger/DisplayHardware/HWC2.cpp
@@ -23,7 +23,7 @@
#include "HWC2.h"
#include "ComposerHal.h"
-#include "FloatRect.h"
+#include <gfx/FloatRect.h>
#include <ui/Fence.h>
#include <ui/GraphicBuffer.h>
@@ -74,12 +74,12 @@ extern "C" {
}
using android::Fence;
-using android::FloatRect;
using android::GraphicBuffer;
using android::HdrCapabilities;
using android::Rect;
using android::Region;
using android::sp;
+using android::gfx::FloatRect;
using android::hardware::Return;
using android::hardware::Void;
diff --git a/services/surfaceflinger/DisplayHardware/HWC2.h b/services/surfaceflinger/DisplayHardware/HWC2.h
index 7e8f94b4d1..5b894badf0 100644
--- a/services/surfaceflinger/DisplayHardware/HWC2.h
+++ b/services/surfaceflinger/DisplayHardware/HWC2.h
@@ -38,13 +38,15 @@
namespace android {
class Fence;
- class FloatRect;
class GraphicBuffer;
class Rect;
class Region;
+ namespace gfx {
+ class FloatRect;
+ }
namespace Hwc2 {
class Composer;
- };
+ }
}
namespace HWC2 {
@@ -398,7 +400,7 @@ public:
[[clang::warn_unused_result]] Error setSidebandStream(
const native_handle_t* stream);
[[clang::warn_unused_result]] Error setSourceCrop(
- const android::FloatRect& crop);
+ const android::gfx::FloatRect& crop);
[[clang::warn_unused_result]] Error setTransform(Transform transform);
[[clang::warn_unused_result]] Error setVisibleRegion(
const android::Region& region);
diff --git a/services/surfaceflinger/DisplayHardware/HWComposer_hwc1.cpp b/services/surfaceflinger/DisplayHardware/HWComposer_hwc1.cpp
index facf82080e..af280a4e32 100644
--- a/services/surfaceflinger/DisplayHardware/HWComposer_hwc1.cpp
+++ b/services/surfaceflinger/DisplayHardware/HWComposer_hwc1.cpp
@@ -1031,7 +1031,7 @@ public:
virtual void setFrame(const Rect& frame) {
getLayer()->displayFrame = reinterpret_cast<hwc_rect_t const&>(frame);
}
- virtual void setCrop(const FloatRect& crop) {
+ virtual void setCrop(const gfx::FloatRect& crop) {
if (hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_3)) {
getLayer()->sourceCropf = reinterpret_cast<hwc_frect_t const&>(crop);
} else {
diff --git a/services/surfaceflinger/DisplayHardware/HWComposer_hwc1.h b/services/surfaceflinger/DisplayHardware/HWComposer_hwc1.h
index 170e382330..bca25ac448 100644
--- a/services/surfaceflinger/DisplayHardware/HWComposer_hwc1.h
+++ b/services/surfaceflinger/DisplayHardware/HWComposer_hwc1.h
@@ -48,12 +48,14 @@ namespace android {
// ---------------------------------------------------------------------------
class Fence;
-class FloatRect;
class GraphicBuffer;
class NativeHandle;
class Region;
class String8;
class SurfaceFlinger;
+namespace gfx {
+ class FloatRect;
+}
class HWComposer
{
@@ -168,7 +170,7 @@ public:
virtual void setBlending(uint32_t blending) = 0;
virtual void setTransform(uint32_t transform) = 0;
virtual void setFrame(const Rect& frame) = 0;
- virtual void setCrop(const FloatRect& crop) = 0;
+ virtual void setCrop(const gfx::FloatRect& crop) = 0;
virtual void setVisibleRegionScreen(const Region& reg) = 0;
virtual void setSurfaceDamage(const Region& reg) = 0;
virtual void setSidebandStream(const sp<NativeHandle>& stream) = 0;
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index c7d37a561f..22d01ae0b3 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -377,10 +377,10 @@ Rect Layer::computeBounds(const Region& activeTransparentRegion) const {
return reduce(win, activeTransparentRegion);
}
-FloatRect Layer::computeCrop(const sp<const DisplayDevice>& hw) const {
+gfx::FloatRect Layer::computeCrop(const sp<const DisplayDevice>& hw) const {
// the content crop is the area of the content that gets scaled to the
// layer's size.
- FloatRect crop(getContentCrop());
+ gfx::FloatRect crop = getContentCrop().toFloatRect();
// the crop is the area of the window that gets cropped, but not
// scaled in any ways.
@@ -585,7 +585,7 @@ void Layer::setGeometry(
hwcInfo.displayFrame = transformedFrame;
}
- FloatRect sourceCrop = computeCrop(displayDevice);
+ gfx::FloatRect sourceCrop = computeCrop(displayDevice);
error = hwcLayer->setSourceCrop(sourceCrop);
if (error != HWC2::Error::None) {
ALOGE("[%s] Failed to set source crop [%.3f, %.3f, %.3f, %.3f]: "
@@ -2179,7 +2179,7 @@ void Layer::miniDump(String8& result, int32_t hwcId) const {
const Rect& frame = hwcInfo.displayFrame;
result.appendFormat("%4d %4d %4d %4d | ", frame.left, frame.top,
frame.right, frame.bottom);
- const FloatRect& crop = hwcInfo.sourceCrop;
+ const gfx::FloatRect& crop = hwcInfo.sourceCrop;
result.appendFormat("%6.1f %6.1f %6.1f %6.1f\n", crop.left, crop.top,
crop.right, crop.bottom);
diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h
index b1e3298230..15a9552a14 100644
--- a/services/surfaceflinger/Layer.h
+++ b/services/surfaceflinger/Layer.h
@@ -27,6 +27,8 @@
#include <utils/String8.h>
#include <utils/Timers.h>
+#include <gfx/FloatRect.h>
+
#include <ui/FrameStats.h>
#include <ui/GraphicBuffer.h>
#include <ui/PixelFormat.h>
@@ -46,7 +48,6 @@
#include "Transform.h"
#include "DisplayHardware/HWComposer.h"
-#include "DisplayHardware/FloatRect.h"
#include "RenderEngine/Mesh.h"
#include "RenderEngine/Texture.h"
@@ -457,7 +458,7 @@ private:
bool needsFiltering(const sp<const DisplayDevice>& hw) const;
uint32_t getEffectiveUsage(uint32_t usage) const;
- FloatRect computeCrop(const sp<const DisplayDevice>& hw) const;
+ gfx::FloatRect computeCrop(const sp<const DisplayDevice>& hw) const;
bool isCropped() const;
static bool getOpacityForFormat(uint32_t format);
@@ -629,7 +630,7 @@ private:
HWC2::Composition compositionType;
bool clearClientTarget;
Rect displayFrame;
- FloatRect sourceCrop;
+ gfx::FloatRect sourceCrop;
};
std::unordered_map<int32_t, HWCInfo> mHwcLayers;
#else
diff --git a/vulkan/libvulkan/Android.bp b/vulkan/libvulkan/Android.bp
index 5a0a93bc48..f1c4c83a61 100644
--- a/vulkan/libvulkan/Android.bp
+++ b/vulkan/libvulkan/Android.bp
@@ -46,6 +46,7 @@ cc_library_shared {
"-Wno-c99-extensions",
"-Wno-c++98-compat-pedantic",
"-Wno-exit-time-destructors",
+ "-Wno-float-equal",
"-Wno-global-constructors",
"-Wno-zero-length-array",
],