diff options
author | halcanary <halcanary@google.com> | 2015-12-09 11:36:59 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-12-09 11:36:59 -0800 |
commit | e36ec871768eb4f5372540c1167ff7ec592f2bec (patch) | |
tree | f3da0b29547ac67af113c9d90de6d66745c4c887 | |
parent | cd0749144383d78a10a5df00e2e96e76456b412b (diff) |
SkBitmap::installPixels(const SkPixmap&);
Review URL: https://codereview.chromium.org/1505333002
-rw-r--r-- | bench/ImageBench.cpp | 2 | ||||
-rw-r--r-- | gm/image.cpp | 2 | ||||
-rw-r--r-- | include/core/SkBitmap.h | 8 | ||||
-rw-r--r-- | src/core/SkBitmap.cpp | 6 | ||||
-rw-r--r-- | src/core/SkPictureImageGenerator.cpp | 3 | ||||
-rw-r--r-- | src/core/SkPixmap.cpp | 4 |
6 files changed, 18 insertions, 7 deletions
diff --git a/bench/ImageBench.cpp b/bench/ImageBench.cpp index 0263758da5..40de28121f 100644 --- a/bench/ImageBench.cpp +++ b/bench/ImageBench.cpp @@ -125,7 +125,7 @@ protected: if (!fImage->peekPixels(&pmap)) { sk_throw(); } - fBitmap.installPixels(pmap.info(), pmap.writable_addr(), pmap.rowBytes()); + fBitmap.installPixels(pmap); } } diff --git a/gm/image.cpp b/gm/image.cpp index ac72f63b36..60c1f11418 100644 --- a/gm/image.cpp +++ b/gm/image.cpp @@ -199,7 +199,7 @@ DEF_GM( return new ImageGM; ) static void draw_pixmap(SkCanvas* canvas, const SkPixmap& pmap) { SkBitmap bitmap; - bitmap.installPixels(pmap.info(), (void*)pmap.addr(), pmap.rowBytes()); + bitmap.installPixels(pmap); canvas->drawBitmap(bitmap, 0, 0, nullptr); } diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h index eda13b3c52..cf1c4c77f2 100644 --- a/include/core/SkBitmap.h +++ b/include/core/SkBitmap.h @@ -295,6 +295,14 @@ public: } /** + * Call installPixels with no ReleaseProc specified. This means + * that the caller must ensure that the specified pixels and + * colortable are valid for the lifetime of the created bitmap + * (and its pixelRef). + */ + bool installPixels(const SkPixmap&); + + /** * Calls installPixels() with the value in the SkMask. The caller must * ensure that the specified mask pixels are valid for the lifetime * of the created bitmap (and its pixelRef). diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp index 1691c9d0af..e8a235597d 100644 --- a/src/core/SkBitmap.cpp +++ b/src/core/SkBitmap.cpp @@ -372,6 +372,12 @@ bool SkBitmap::installPixels(const SkImageInfo& requestedInfo, void* pixels, siz return true; } +bool SkBitmap::installPixels(const SkPixmap& pixmap) { + return this->installPixels(pixmap.info(), pixmap.writable_addr(), + pixmap.rowBytes(), pixmap.ctable(), + nullptr, nullptr); +} + bool SkBitmap::installMaskPixels(const SkMask& mask) { if (SkMask::kA8_Format != mask.fFormat) { this->reset(); diff --git a/src/core/SkPictureImageGenerator.cpp b/src/core/SkPictureImageGenerator.cpp index 39caa55d0c..398c6eb5df 100644 --- a/src/core/SkPictureImageGenerator.cpp +++ b/src/core/SkPictureImageGenerator.cpp @@ -108,8 +108,7 @@ bool SkPictureImageGenerator::onGenerateScaledPixels(const SkISize& scaledSize, matrix.postTranslate(-SkIntToScalar(scaledOrigin.x()), -SkIntToScalar(scaledOrigin.y())); SkBitmap bitmap; - if (!bitmap.installPixels(scaledPixels.info(), scaledPixels.writable_addr(), - scaledPixels.rowBytes())) { + if (!bitmap.installPixels(scaledPixels)) { return false; } diff --git a/src/core/SkPixmap.cpp b/src/core/SkPixmap.cpp index 718be88c57..0098b1b282 100644 --- a/src/core/SkPixmap.cpp +++ b/src/core/SkPixmap.cpp @@ -222,9 +222,7 @@ bool SkPixmap::scalePixels(const SkPixmap& dst, SkFilterQuality quality) const { } SkBitmap bitmap; - // we will only ready from this pixmap, but the bitmap setting takes void*, hence the cast - void* readOnlyAddr = const_cast<void*>(this->addr()); - if (!bitmap.installPixels(this->info(), readOnlyAddr, this->rowBytes())) { + if (!bitmap.installPixels(*this)) { return false; } bitmap.setIsVolatile(true); // so we don't try to cache it |