diff options
author | Hal Canary <halcanary@google.com> | 2016-12-07 15:24:59 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2016-12-07 21:44:39 +0000 |
commit | 58a769490a4593a93b08031365b88be7a5ecfa0e (patch) | |
tree | 62906a1b64a6a6a1db8ab56e137b66cd1a9e5c02 /include | |
parent | e1f29c7b3c301ba8aa649ca8fb74237b4960fd4f (diff) |
SkBitmap::ComputeIsOpaque -> SkPixmap::computeIsOpaque
Motivation: Twice internal Skia clients have to do something awkward like this:
bool ComputeIsOpaque(const SkPixmap& pixmap) {
SkBitmap bm;
return bm.installPixels(pixmap) && SkBitmap::ComputeIsOpaque(bm);
}
Change-Id: I7263c06f754c1305ecb07c4c005d9cfb9d1f523d
Reviewed-on: https://skia-review.googlesource.com/5684
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Hal Canary <halcanary@google.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/core/SkBitmap.h | 5 | ||||
-rw-r--r-- | include/core/SkPixmap.h | 6 |
2 files changed, 10 insertions, 1 deletions
diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h index 061f0e5c95..7c3cd7f9b7 100644 --- a/include/core/SkBitmap.h +++ b/include/core/SkBitmap.h @@ -215,7 +215,10 @@ public: * this (isOpaque). Only call this if you need to compute this value from * "unknown" pixels. */ - static bool ComputeIsOpaque(const SkBitmap&); + static bool ComputeIsOpaque(const SkBitmap& bm) { + SkAutoPixmapUnlock result; + return bm.requestLock(&result) && result.pixmap().computeIsOpaque(); + } /** * Return the bitmap's bounds [0, 0, width, height] as an SkRect diff --git a/include/core/SkPixmap.h b/include/core/SkPixmap.h index ce13297fb9..6cf948e601 100644 --- a/include/core/SkPixmap.h +++ b/include/core/SkPixmap.h @@ -91,6 +91,12 @@ public: size_t getSafeSize() const { return fInfo.getSafeSize(fRowBytes); } /** + * This will brute-force return true if all of the pixels in the pixmap + * are opaque. If there are no pixels, or encounters an error, returns false. + */ + bool computeIsOpaque() const; + + /** * Converts the pixel at the specified coordinate to an unpremultiplied * SkColor. Note: this ignores any SkColorSpace information, and may return * lower precision data than is actually in the pixel. Alpha only |