#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_GEOMETRY_LAYOUT_UNIT_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_GEOMETRY_LAYOUT_UNIT_H_
#include <climits>
#include <iosfwd>
#include <limits>
#include <optional>
#include "base/check_op.h"
#include "base/compiler_specific.h"
#include "base/dcheck_is_on.h"
#include "base/logging.h"
#include "base/numerics/clamped_math.h"
#include "base/numerics/safe_conversions.h"
#include "build/build_config.h"
#include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#include "third_party/blink/renderer/platform/wtf/forward.h"
#include "third_party/blink/renderer/platform/wtf/vector_traits.h"
namespace WTF {
class String;
}
namespace blink {
#if DCHECK_IS_ON()
#define REPORT_OVERFLOW(doesOverflow) …
#else
#define REPORT_OVERFLOW …
#endif
template <unsigned fractional_bits, typename Storage>
class PLATFORM_EXPORT FixedPoint { … };
LayoutUnit;
TextRunLayoutUnit;
InlineLayoutUnit;
inline constexpr LayoutUnit kIndefiniteSize(-1);
inline bool operator<=(const LayoutUnit& a, int b) { … }
inline bool operator<=(const int a, const LayoutUnit& b) { … }
inline bool operator>=(const LayoutUnit& a, int b) { … }
inline bool operator>=(const int a, const LayoutUnit& b) { … }
inline bool operator<(const LayoutUnit& a, int b) { … }
inline bool operator<(const int a, const LayoutUnit& b) { … }
inline bool operator>(const LayoutUnit& a, int b) { … }
inline bool operator>(const int a, const LayoutUnit& b) { … }
inline bool operator!=(const int a, const LayoutUnit& b) { … }
inline bool operator!=(const LayoutUnit& a, int b) { … }
inline bool operator==(const LayoutUnit& a, int b) { … }
inline bool operator==(const int a, const LayoutUnit& b) { … }
template <unsigned fractional_bits, typename RawValue>
requires(std::is_same_v<RawValue, int32_t>)
inline FixedPoint<fractional_bits, RawValue> BoundedMultiply(
const FixedPoint<fractional_bits, RawValue>& a,
const FixedPoint<fractional_bits, RawValue>& b) { … }
template <unsigned fractional_bits, typename RawValue>
requires(std::is_same_v<RawValue, int32_t>)
inline FixedPoint<fractional_bits, RawValue> operator*(
const FixedPoint<fractional_bits, RawValue>& a,
const FixedPoint<fractional_bits, RawValue>& b) { … }
inline double operator*(const LayoutUnit& a, double b) { … }
inline float operator*(const LayoutUnit& a, float b) { … }
template <unsigned fractional_bits, typename RawValue>
inline FixedPoint<fractional_bits, RawValue> operator*(
const FixedPoint<fractional_bits, RawValue> a,
std::integral auto b) { … }
inline LayoutUnit operator*(std::integral auto a, const LayoutUnit& b) {
return LayoutUnit(a) * b;
}
constexpr float operator*(const float a, const LayoutUnit& b) { … }
constexpr double operator*(const double a, const LayoutUnit& b) { … }
template <unsigned fractional_bits, typename RawValue>
requires(std::is_same_v<RawValue, int32_t>)
inline FixedPoint<fractional_bits, RawValue> operator/(
const FixedPoint<fractional_bits, RawValue>& a,
const FixedPoint<fractional_bits, RawValue>& b) { … }
template <unsigned fractional_bits, typename RawValue>
inline FixedPoint<fractional_bits, RawValue>
FixedPoint<fractional_bits, RawValue>::MulDiv(FixedPoint m,
FixedPoint d) const { … }
constexpr float operator/(const LayoutUnit& a, float b) { … }
constexpr double operator/(const LayoutUnit& a, double b) { … }
template <unsigned fractional_bits, typename RawValue>
inline FixedPoint<fractional_bits, RawValue> operator/(
const FixedPoint<fractional_bits, RawValue>& a,
std::integral auto b) { … }
constexpr float operator/(const float a, const LayoutUnit& b) { … }
constexpr double operator/(const double a, const LayoutUnit& b) { … }
inline LayoutUnit operator/(std::integral auto a, const LayoutUnit& b) {
return LayoutUnit(a) / b;
}
template <unsigned fractional_bits, typename RawValue>
ALWAYS_INLINE FixedPoint<fractional_bits, RawValue> operator+(
const FixedPoint<fractional_bits, RawValue>& a,
const FixedPoint<fractional_bits, RawValue>& b) { … }
inline LayoutUnit operator+(const LayoutUnit& a, std::integral auto b) {
return a + LayoutUnit(b);
}
template <unsigned fractional_bits, typename RawValue>
inline float operator+(const FixedPoint<fractional_bits, RawValue>& a,
float b) { … }
inline double operator+(const LayoutUnit& a, double b) { … }
inline LayoutUnit operator+(std::integral auto a, const LayoutUnit& b) {
return LayoutUnit(a) + b;
}
constexpr float operator+(const float a, const LayoutUnit& b) { … }
constexpr double operator+(const double a, const LayoutUnit& b) { … }
ALWAYS_INLINE LayoutUnit operator-(const LayoutUnit& a, const LayoutUnit& b) { … }
inline LayoutUnit operator-(const LayoutUnit& a, std::integral auto b) {
return a - LayoutUnit(b);
}
constexpr float operator-(const LayoutUnit& a, float b) { … }
constexpr double operator-(const LayoutUnit& a, double b) { … }
inline LayoutUnit operator-(std::integral auto a, const LayoutUnit& b) {
return LayoutUnit(a) - b;
}
constexpr float operator-(const float a, const LayoutUnit& b) { … }
template <unsigned fractional_bits, typename RawValue>
inline FixedPoint<fractional_bits, RawValue> operator-(
const FixedPoint<fractional_bits, RawValue>& a) { … }
inline LayoutUnit IntMod(const LayoutUnit& a, const LayoutUnit& b) { … }
template <unsigned fractional_bits, typename RawValue, typename SourceStorage>
requires(sizeof(SourceStorage) <= sizeof(RawValue))
inline FixedPoint<fractional_bits, RawValue>& operator+=(
FixedPoint<fractional_bits, RawValue>& a,
const FixedPoint<fractional_bits, SourceStorage>& b) { … }
inline LayoutUnit& operator+=(LayoutUnit& a, std::integral auto b) {
a = a + LayoutUnit(b);
return a;
}
inline LayoutUnit& operator+=(LayoutUnit& a, float b) { … }
inline float& operator+=(float& a, const LayoutUnit& b) { … }
inline LayoutUnit& operator-=(LayoutUnit& a, std::integral auto b) {
a = a - LayoutUnit(b);
return a;
}
template <unsigned fractional_bits, typename RawValue>
inline FixedPoint<fractional_bits, RawValue>& operator-=(
FixedPoint<fractional_bits, RawValue>& a,
const FixedPoint<fractional_bits, RawValue>& b) { … }
inline LayoutUnit& operator-=(LayoutUnit& a, float b) { … }
inline float& operator-=(float& a, const LayoutUnit& b) { … }
inline LayoutUnit& operator*=(LayoutUnit& a, const LayoutUnit& b) { … }
inline LayoutUnit& operator*=(LayoutUnit& a, float b) { … }
inline float& operator*=(float& a, const LayoutUnit& b) { … }
inline LayoutUnit& operator/=(LayoutUnit& a, const LayoutUnit& b) { … }
inline LayoutUnit& operator/=(LayoutUnit& a, float b) { … }
inline float& operator/=(float& a, const LayoutUnit& b) { … }
inline int SnapSizeToPixel(LayoutUnit size, LayoutUnit location) { … }
inline int SnapSizeToPixelAllowingZero(LayoutUnit size, LayoutUnit location) { … }
inline int RoundToInt(LayoutUnit value) { … }
inline int FloorToInt(LayoutUnit value) { … }
inline int CeilToInt(LayoutUnit value) { … }
inline LayoutUnit AbsoluteValue(const LayoutUnit& value) { … }
template <unsigned fractional_bits, typename RawValue>
inline std::optional<FixedPoint<fractional_bits, RawValue>>
FixedPoint<fractional_bits, RawValue>::NullOptIf(FixedPoint null_value) const { … }
#if defined(ARCH_CPU_ARM_FAMILY) && defined(ARCH_CPU_32_BITS) && \
defined(COMPILER_GCC) && !BUILDFLAG(IS_NACL) && __OPTIMIZE__
inline int GetMaxSaturatedSetResultForTesting() {
return LayoutUnit::kRawValueMax & ~(LayoutUnit::kFixedPointDenominator - 1);
}
inline int GetMinSaturatedSetResultForTesting() {
return LayoutUnit::kRawValueMin;
}
#else
ALWAYS_INLINE int GetMaxSaturatedSetResultForTesting() { … }
ALWAYS_INLINE int GetMinSaturatedSetResultForTesting() { … }
#endif
template <unsigned fractional_bits, typename RawValue>
PLATFORM_EXPORT std::ostream& operator<<(
std::ostream&,
const FixedPoint<fractional_bits, RawValue>&);
template <unsigned fractional_bits, typename RawValue>
PLATFORM_EXPORT WTF::TextStream& operator<<(
WTF::TextStream&,
const FixedPoint<fractional_bits, RawValue>&);
}
WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS(…)
#endif