diff options
Diffstat (limited to 'include/core')
-rw-r--r-- | include/core/Sk64.h | 7 | ||||
-rw-r--r-- | include/core/SkBitmap.h | 51 | ||||
-rw-r--r-- | include/core/SkMath.h | 26 | ||||
-rw-r--r-- | include/core/SkTypes.h | 4 |
4 files changed, 68 insertions, 20 deletions
diff --git a/include/core/Sk64.h b/include/core/Sk64.h index 009744938f..c12a97c8a1 100644 --- a/include/core/Sk64.h +++ b/include/core/Sk64.h @@ -1,4 +1,3 @@ - /* * Copyright 2006 The Android Open Source Project * @@ -6,7 +5,6 @@ * found in the LICENSE file. */ - #ifndef Sk64_DEFINED #define Sk64_DEFINED @@ -28,6 +26,11 @@ public: int64_t as64() const { return ((int64_t)fHi << 32) | fLo; } int64_t getLongLong() const { return this->as64(); } + void set64(int64_t value) { + fHi = (int32_t)(value >> 32); + fLo = (uint32_t)value; + } + /** Returns non-zero if the Sk64 can be represented as a signed 32 bit integer */ SkBool is32() const { return fHi == ((int32_t)fLo >> 31); } diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h index c0e299ab94..2b900bef34 100644 --- a/include/core/SkBitmap.h +++ b/include/core/SkBitmap.h @@ -1,4 +1,3 @@ - /* * Copyright 2006 The Android Open Source Project * @@ -6,17 +5,19 @@ * found in the LICENSE file. */ - #ifndef SkBitmap_DEFINED #define SkBitmap_DEFINED -#include "Sk64.h" #include "SkColor.h" #include "SkColorTable.h" #include "SkImageInfo.h" #include "SkPoint.h" #include "SkRefCnt.h" +#ifdef SK_SUPPORT_LEGACY_SK64 + #include "Sk64.h" +#endif + struct SkIRect; struct SkRect; class SkPaint; @@ -149,19 +150,37 @@ public: */ size_t getSafeSize() const ; - /** Return the byte size of the pixels, based on the height and rowBytes. - This routine is slightly slower than getSize(), but does not truncate - the answer to 32bits. - */ + /** + * Return the full size of the bitmap, in bytes. + */ + int64_t computeSize64() const { + return sk_64_mul(fHeight, fRowBytes); + } + + /** + * Return the number of bytes from the pointer returned by getPixels() + * to the end of the allocated space in the buffer. This may be smaller + * than computeSize64() if there is any rowbytes padding beyond the width. + */ + int64_t computeSafeSize64() const { + return ComputeSafeSize64((Config)fConfig, fWidth, fHeight, fRowBytes); + } + +#ifdef SK_SUPPORT_LEGACY_SK64 + SK_ATTR_DEPRECATED("use getSize64()") Sk64 getSize64() const { Sk64 size; - size.setMul(fHeight, fRowBytes); + size.set64(this->computeSize64()); return size; } - /** Same as getSafeSize(), but does not truncate the answer to 32bits. - */ - Sk64 getSafeSize64() const ; + SK_ATTR_DEPRECATED("use getSafeSize64()") + Sk64 getSafeSize64() const { + Sk64 size; + size.set64(this->computeSafeSize64()); + return size; + } +#endif /** Returns true if this bitmap is marked as immutable, meaning that the contents of its pixels will not change for the lifetime of the bitmap. @@ -217,7 +236,7 @@ public: return ComputeBytesPerPixel(c) >> 1; } - static Sk64 ComputeSize64(Config, int width, int height); + static int64_t ComputeSize64(Config, int width, int height); static size_t ComputeSize(Config, int width, int height); /** @@ -678,10 +697,10 @@ private: /* Internal computations for safe size. */ - static Sk64 ComputeSafeSize64(Config config, - uint32_t width, - uint32_t height, - size_t rowBytes); + static int64_t ComputeSafeSize64(Config config, + uint32_t width, + uint32_t height, + size_t rowBytes); static size_t ComputeSafeSize(Config config, uint32_t width, uint32_t height, diff --git a/include/core/SkMath.h b/include/core/SkMath.h index affcadaf2c..ba6223ed06 100644 --- a/include/core/SkMath.h +++ b/include/core/SkMath.h @@ -35,6 +35,32 @@ int32_t SkSqrtBits(int32_t value, int bitBias); */ #define SkSqrt32(n) SkSqrtBits(n, 15) +// 64bit -> 32bit utilities + +/** + * Return true iff the 64bit value can exactly be represented in signed 32bits + */ +static inline bool sk_64_isS32(int64_t value) { + return (int32_t)value == value; +} + +/** + * Return the 64bit argument as signed 32bits, asserting in debug that the arg + * exactly fits in signed 32bits. In the release build, no checks are preformed + * and the return value if the arg does not fit is undefined. + */ +static inline int32_t sk_64_asS32(int64_t value) { + SkASSERT(sk_64_isS32(value)); + return (int32_t)value; +} + +// Handy util that can be passed two ints, and will automatically promote to +// 64bits before the multiply, so the caller doesn't have to remember to cast +// e.g. (int64_t)a * b; +static inline int64_t sk_64_mul(int64_t a, int64_t b) { + return a * b; +} + /////////////////////////////////////////////////////////////////////////////// //! Returns the number of leading zero bits (0...32) diff --git a/include/core/SkTypes.h b/include/core/SkTypes.h index c30a8a2d66..06c8583a61 100644 --- a/include/core/SkTypes.h +++ b/include/core/SkTypes.h @@ -1,4 +1,3 @@ - /* * Copyright 2006 The Android Open Source Project * @@ -6,7 +5,6 @@ * found in the LICENSE file. */ - #ifndef SkTypes_DEFINED #define SkTypes_DEFINED @@ -15,6 +13,8 @@ #include "SkPostConfig.h" #include <stdint.h> +//#define SK_SUPPORT_LEGACY_SK64 + /** \file SkTypes.h */ |