aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2017-09-29 13:41:58 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-09-29 18:20:14 +0000
commite74dafc74d8d87f10d9be7889349990d11c245f9 (patch)
treea4da76b310f4aa8c06355e275681bbf402c4c1a3 /include
parentc739b7260a36ed4f9ea803991909a438629ca1d2 (diff)
Just add new safe size apis
Update skia (and then hide the older versions) to come later Inspired by https://skia-review.googlesource.com/c/skia/+/52665 Bug: skia: Change-Id: I15c7395557fb49c4163cb3b323b5428abd2c752d Reviewed-on: https://skia-review.googlesource.com/53520 Reviewed-by: Florin Malita <fmalita@chromium.org> Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'include')
-rw-r--r--include/core/SkBitmap.h6
-rw-r--r--include/core/SkImageInfo.h15
-rw-r--r--include/core/SkPixmap.h6
3 files changed, 27 insertions, 0 deletions
diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h
index 7425eb03d5..5b4e1a6863 100644
--- a/include/core/SkBitmap.h
+++ b/include/core/SkBitmap.h
@@ -141,6 +141,12 @@ public:
*/
void* getPixels() const { return fPixels; }
+ /**
+ * 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); }
+
/** 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.
diff --git a/include/core/SkImageInfo.h b/include/core/SkImageInfo.h
index f659bf7742..c47dbb28b1 100644
--- a/include/core/SkImageInfo.h
+++ b/include/core/SkImageInfo.h
@@ -315,6 +315,21 @@ public:
return sk_64_asS32(size);
}
+ /**
+ * 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());
return rowBytes >= rb;
diff --git a/include/core/SkPixmap.h b/include/core/SkPixmap.h
index aa43b3441f..8115756b91 100644
--- a/include/core/SkPixmap.h
+++ b/include/core/SkPixmap.h
@@ -229,6 +229,12 @@ public:
*/
size_t getSafeSize() const { return fInfo.getSafeSize(fRowBytes); }
+ /**
+ * 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
without alpha in each pixel; for other SkColorType, returns true if all