aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2017-09-26 12:47:08 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-09-26 17:07:16 +0000
commit98a6216b18b57c2f7a0d58f542c60503686aed69 (patch)
tree646c987b18faa16aba1db40ea3f98684ad5946d6 /include
parent106b5c4917636d3df70ee6f59661ac5fa506d087 (diff)
guard old apis for querying byte-size of a bitmap/imageinfo/pixmap
Previously we had size_t and uint64_t variations. The new (simpler) API always.. - returns size_t, or 0 if the calculation overflowed - returns the trimmed size (does not include rowBytes padding for the last row) Bug: skia: Change-Id: I05173e877918327c7b207d2f7f1ab0db36892e2e Reviewed-on: https://skia-review.googlesource.com/50980 Commit-Queue: Mike Reed <reed@google.com> Reviewed-by: Florin Malita <fmalita@chromium.org> Reviewed-by: Leon Scroggins <scroggo@google.com>
Diffstat (limited to 'include')
-rw-r--r--include/core/SkBitmap.h12
-rw-r--r--include/core/SkImageInfo.h17
-rw-r--r--include/core/SkPixmap.h8
3 files changed, 33 insertions, 4 deletions
diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h
index 7425eb03d5..cea50b8886 100644
--- a/include/core/SkBitmap.h
+++ b/include/core/SkBitmap.h
@@ -141,10 +141,13 @@ public:
*/
void* getPixels() const { return fPixels; }
- /** Return the byte size of the pixels, based on the height and rowBytes.
- Note this truncates the result to 32bits. Call getSize64() to detect
- if the real size exceeds 32bits.
- */
+ /**
+ * Returns the size (in bytes) of the bitmap's image buffer.
+ * If the calculation overflows, or if the height is 0, this returns 0.
+ */
+ size_t computeByteSize() const { return fInfo.computeByteSize(fRowBytes); }
+
+#ifdef SK_SUPPORT_LEGACY_SAFESIZE64
size_t getSize() const { return fInfo.height() * fRowBytes; }
/** Return the number of bytes from the pointer returned by getPixels()
@@ -168,6 +171,7 @@ public:
int64_t computeSafeSize64() const {
return fInfo.getSafeSize64(fRowBytes);
}
+#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.
diff --git a/include/core/SkImageInfo.h b/include/core/SkImageInfo.h
index f659bf7742..e8a06cb0d1 100644
--- a/include/core/SkImageInfo.h
+++ b/include/core/SkImageInfo.h
@@ -300,6 +300,7 @@ public:
void unflatten(SkReadBuffer&);
void flatten(SkWriteBuffer&) const;
+#ifdef SK_SUPPORT_LEGACY_SAFESIZE64
int64_t getSafeSize64(size_t rowBytes) const {
if (0 == fHeight) {
return 0;
@@ -314,6 +315,22 @@ public:
}
return sk_64_asS32(size);
}
+#endif
+
+ /**
+ * Returns the size (in bytes) of the image buffer that this info needs, given the specified
+ * rowBytes. The rowBytes must be >= this->minRowBytes().
+ * If the calculation overflows, or if the height is 0, this returns 0.
+ */
+ size_t computeByteSize(size_t rowBytes) const;
+
+ /**
+ * Returns the minimum size (in bytes) of the image buffer that this info needs.
+ * If the calculation overflows, or if the height is 0, this returns 0.
+ */
+ size_t computeMinByteSize() const {
+ return this->computeByteSize(this->minRowBytes());
+ }
bool validRowBytes(size_t rowBytes) const {
uint64_t rb = sk_64_mul(fWidth, this->bytesPerPixel());
diff --git a/include/core/SkPixmap.h b/include/core/SkPixmap.h
index aa43b3441f..f304bde933 100644
--- a/include/core/SkPixmap.h
+++ b/include/core/SkPixmap.h
@@ -206,6 +206,7 @@ public:
*/
int shiftPerPixel() const { return fInfo.shiftPerPixel(); }
+#ifdef SK_SUPPORT_LEGACY_SAFESIZE64
/** Returns conservative memory required for pixel storage.
Includes unused memory on last row when rowBytesAsPixels() exceeds width().
@@ -228,6 +229,13 @@ public:
@return exact pixel storage size if size fits in signed 32 bits
*/
size_t getSafeSize() const { return fInfo.getSafeSize(fRowBytes); }
+#endif
+
+ /**
+ * Returns the size (in bytes) of the pixmap's image buffer.
+ * If the calculation overflows, or if the height is 0, this returns 0.
+ */
+ size_t computeByteSize() const { return fInfo.computeByteSize(fRowBytes); }
/** Returns true if all pixels are opaque. SkColorType determines how pixels
are encoded, and whether pixel describes alpha. Returns true for SkColorType