aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Hal Canary <halcanary@google.com>2017-12-14 21:13:47 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-01-09 16:46:22 +0000
commit99578d24c0abd5b0e4fa2fc40b44fbec0c2bd627 (patch)
tree0a1f00691905194d45e70aeea82835c0b2661407
parent7e6dc6394518252ae6acd56eea0ac2d19fbc361b (diff)
SkBitmap now *has* a SkPixmap.
Before: class SkBitmap { sk_sp<SkPixelRef> fPixelRef; void* fPixels; SkImageInfo fInfo; uint32_t fRowBytes; uint8_t fFlags; }; After: class SkBitmap { sk_sp<SkPixelRef> fPixelRef; SkPixmap fPixmap; uint8_t fFlags; }; Change-Id: I62d59ca3e702b7adea022cd3cfbf0cc3186af957 Reviewed-on: https://skia-review.googlesource.com/85560 Commit-Queue: Hal Canary <halcanary@google.com> Reviewed-by: Cary Clark <caryclark@google.com> Reviewed-by: Leon Scroggins <scroggo@google.com>
-rw-r--r--docs/SkBitmap_Reference.bmh25
-rw-r--r--gm/all_bitmap_configs.cpp2
-rw-r--r--include/core/SkBitmap.h68
-rw-r--r--include/core/SkPixmap.h2
-rw-r--r--src/core/SkBitmap.cpp114
-rw-r--r--src/core/SkPixmapPriv.h5
-rw-r--r--src/image/SkImage_Raster.cpp5
7 files changed, 96 insertions, 125 deletions
diff --git a/docs/SkBitmap_Reference.bmh b/docs/SkBitmap_Reference.bmh
index 94a993ce89..5eba984ebb 100644
--- a/docs/SkBitmap_Reference.bmh
+++ b/docs/SkBitmap_Reference.bmh
@@ -122,7 +122,7 @@ is useful to position one or more Bitmaps within a shared pixel array.
# peekPixels # Returns Pixmap if possible. ##
# pixelRef # Returns Pixel_Ref, or nullptr. ##
# pixelRefOrigin # Returns offset within Pixel_Ref. ##
-# pixmap() # Returns Pixmap if possible. ##
+# pixmap() # Returns Pixmap. ##
# readPixels # Copies and converts pixels. ##
# readyToDraw # Returns true if address of pixels is not nullptr. ##
# refColorSpace # Returns Image_Info Color_Space. ##
@@ -448,16 +448,12 @@ two width:1 height:1 colorType:kRGBA_8888_SkColorType alphaType:kOpaque_SkAlphaT
# ------------------------------------------------------------------------------
-#Method SkPixmap pixmap() const
+#Method const SkPixmap& pixmap() const
-Returns Pixmap with Bitmap pixel address, row bytes, and Image_Info, if address
-is available. If pixel address is not available, returns default constructed
-Pixmap: nullptr pixels, kUnknown_SkColorType, kUnknown_SkAlphaType, width and
-height of zero.
+Returns a constant reference to the Pixmap holding the Bitmap pixel
+address, row bytes, and Image_Info.
-Returned Pixmap becomes invalid on any future change to Bitmap
-
-#Return Pixmap describing Bitmap, if pixels are readable; otherwise containing zeroes ##
+#Return reference to Pixmap describing this Bitmap. ##
#Example
SkBitmap bitmap;
@@ -466,13 +462,12 @@ Returned Pixmap becomes invalid on any future change to Bitmap
offscreen.clear(SK_ColorWHITE);
SkPaint paint;
offscreen.drawString("&", 0, 10, paint);
- SkPixmap pixmap = bitmap.pixmap();
+ const SkPixmap& pixmap = bitmap.pixmap();
if (pixmap.addr()) {
- const SkPMColor* pixels = pixmap.addr32();
- SkPMColor pmWhite = pixels[0];
- for (int y = 0; y < bitmap.height(); ++y) {
- for (int x = 0; x < bitmap.width(); ++x) {
- SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x');
+ SkPMColor pmWhite = *pixmap.addr32(0, 0);
+ for (int y = 0; y < pixmap.height(); ++y) {
+ for (int x = 0; x < pixmap.width(); ++x) {
+ SkDebugf("%c", *pixmap.addr32(x, y) == pmWhite ? '-' : 'x');
}
SkDebugf("\n");
}
diff --git a/gm/all_bitmap_configs.cpp b/gm/all_bitmap_configs.cpp
index 1374186ce2..44727a4563 100644
--- a/gm/all_bitmap_configs.cpp
+++ b/gm/all_bitmap_configs.cpp
@@ -211,7 +211,7 @@ static void make_color_test_bitmap_variant(
SkASSERT(alphaType == kPremul_SkAlphaType || alphaType == kUnpremul_SkAlphaType);
bm->allocPixels(
SkImageInfo::Make(SCALE, SCALE, colorType, alphaType, colorSpace));
- SkPixmap pm = bm->pixmap();
+ const SkPixmap& pm = bm->pixmap();
for (int y = 0; y < pm.height(); y++) {
for (int x = 0; x < pm.width(); x++) {
*pm.writable_addr32(x, y) = make_pixel(x, y, alphaType);
diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h
index c0287b393b..1ab9bf2984 100644
--- a/include/core/SkBitmap.h
+++ b/include/core/SkBitmap.h
@@ -99,22 +99,18 @@ public:
*/
void swap(SkBitmap& other);
- /** Returns SkPixmap with SkBitmap pixel address, row bytes, and SkImageInfo, if address
- is available. If pixel address is not available, returns default constructed
- SkPixmap: nullptr pixels, kUnknown_SkColorType, kUnknown_SkAlphaType, width and
- height of zero.
+ /** Returns a constant reference to the SkPixmap holding the SkBitmap pixel
+ address, row bytes, and SkImageInfo.
- Returned SkPixmap becomes invalid on any future change to SkBitmap
-
- @return SkPixmap describing SkBitmap, if pixels are readable; otherwise containing zeroes
+ @return reference to SkPixmap describing this SkBitmap.
*/
- SkPixmap pixmap() const { return fPixels ? SkPixmap(fInfo, fPixels, fRowBytes) : SkPixmap(); }
+ const SkPixmap& pixmap() const { return fPixmap; }
/** Returns width, height, SkAlphaType, SkColorType, and SkColorSpace.
@return reference to SkImageInfo
*/
- const SkImageInfo& info() const { return fInfo; }
+ const SkImageInfo& info() const { return fPixmap.info(); }
/** Returns pixel count in each row. Should be equal or less than:
rowBytes() / info().bytesPerPixel().
@@ -124,7 +120,7 @@ public:
@return pixel width in SkImageInfo
*/
- int width() const { return fInfo.width(); }
+ int width() const { return fPixmap.width(); }
/** Returns pixel row count.
@@ -133,7 +129,7 @@ public:
@return pixel height in SkImageInfo
*/
- int height() const { return fInfo.height(); }
+ int height() const { return fPixmap.height(); }
/** Returns SkColorType, one of: kUnknown_SkColorType, kAlpha_8_SkColorType,
kRGB_565_SkColorType, kARGB_4444_SkColorType, kRGBA_8888_SkColorType,
@@ -141,14 +137,14 @@ public:
@return SkColorType in SkImageInfo
*/
- SkColorType colorType() const { return fInfo.colorType(); }
+ SkColorType colorType() const { return fPixmap.colorType(); }
/** Returns SkAlphaType, one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType,
kPremul_SkAlphaType, kUnpremul_SkAlphaType.
@return SkAlphaType in SkImageInfo
*/
- SkAlphaType alphaType() const { return fInfo.alphaType(); }
+ SkAlphaType alphaType() const { return fPixmap.alphaType(); }
/** Returns SkColorSpace, the range of colors, associated with SkImageInfo. The
reference count of SkColorSpace is unchanged. The returned SkColorSpace is
@@ -156,7 +152,7 @@ public:
@return SkColorSpace in SkImageInfo, or nullptr
*/
- SkColorSpace* colorSpace() const { return fInfo.colorSpace(); }
+ SkColorSpace* colorSpace() const { return fPixmap.colorSpace(); }
/** Returns a smart pointer to SkColorSpace, the range of colors, associated with
SkImageInfo. The smart pointer tracks the number of objects sharing this
@@ -166,30 +162,28 @@ public:
@return SkColorSpace in SkImageInfo wrapped in a smart pointer
*/
- sk_sp<SkColorSpace> refColorSpace() const { return fInfo.refColorSpace(); }
+ sk_sp<SkColorSpace> refColorSpace() const { return fPixmap.info().refColorSpace(); }
/** Returns number of bytes per pixel required by SkColorType.
Returns zero if colorType( is kUnknown_SkColorType.
@return bytes in pixel
*/
- int bytesPerPixel() const { return fInfo.bytesPerPixel(); }
+ int bytesPerPixel() const { return fPixmap.info().bytesPerPixel(); }
/** Returns number of pixels that fit on row. Should be greater than or equal to
width().
@return maximum pixels per row
*/
- int rowBytesAsPixels() const {
- return fRowBytes >> this->shiftPerPixel();
- }
+ int rowBytesAsPixels() const { return fPixmap.rowBytesAsPixels(); }
/** Returns bit shift converting row bytes to row pixels.
Returns zero for kUnknown_SkColorType.
@return one of: 0, 1, 2, 3; left shift to convert pixels to bytes
*/
- int shiftPerPixel() const { return this->fInfo.shiftPerPixel(); }
+ int shiftPerPixel() const { return fPixmap.shiftPerPixel(); }
/** Returns true if either width() or height() are zero.
@@ -198,7 +192,7 @@ public:
@return true if dimensions do not enclose area
*/
- bool empty() const { return fInfo.isEmpty(); }
+ bool empty() const { return fPixmap.info().isEmpty(); }
/** Return true if SkPixelRef is nullptr.
@@ -226,7 +220,7 @@ public:
@return byte length of pixel row
*/
- size_t rowBytes() const { return fRowBytes; }
+ size_t rowBytes() const { return fPixmap.rowBytes(); }
/** Sets SkAlphaType, if alphaType is compatible with SkColorType.
Returns true unless alphaType is kUnknown_SkAlphaType and current SkAlphaType
@@ -261,7 +255,7 @@ public:
@return pixel address
*/
- void* getPixels() const { return fPixels; }
+ void* getPixels() const { return fPixmap.writable_addr(); }
/** Returns minimum memory required for pixel storage.
Does not include unused memory on last row when rowBytesAsPixels() exceeds width().
@@ -271,7 +265,7 @@ public:
@return size in bytes of image buffer
*/
- size_t computeByteSize() const { return fInfo.computeByteSize(fRowBytes); }
+ size_t computeByteSize() const { return fPixmap.computeByteSize(); }
/** Returns true if pixels can not change.
@@ -367,13 +361,13 @@ public:
@return integral rectangle from origin to width() and height()
*/
- SkIRect bounds() const { return fInfo.bounds(); }
+ SkIRect bounds() const { return fPixmap.info().bounds(); }
/** Returns SkISize { width(), height() }.
@return integral size of width() and height()
*/
- SkISize dimensions() const { return fInfo.dimensions(); }
+ SkISize dimensions() const { return fPixmap.info().dimensions(); }
/** Returns the bounds of this bitmap, offset by its SkPixelRef origin.
@@ -1281,9 +1275,7 @@ private:
};
sk_sp<SkPixelRef> fPixelRef;
- void* fPixels;
- SkImageInfo fInfo;
- uint32_t fRowBytes;
+ SkPixmap fPixmap;
uint8_t fFlags;
friend class SkReadBuffer; // unflatten
@@ -1292,24 +1284,18 @@ private:
///////////////////////////////////////////////////////////////////////////////
inline uint32_t* SkBitmap::getAddr32(int x, int y) const {
- SkASSERT(fPixels);
- SkASSERT(4 == this->bytesPerPixel());
- SkASSERT((unsigned)x < (unsigned)this->width() && (unsigned)y < (unsigned)this->height());
- return (uint32_t*)((char*)fPixels + y * fRowBytes + (x << 2));
+ SkASSERT(fPixmap.addr());
+ return fPixmap.writable_addr32(x, y);
}
inline uint16_t* SkBitmap::getAddr16(int x, int y) const {
- SkASSERT(fPixels);
- SkASSERT(2 == this->bytesPerPixel());
- SkASSERT((unsigned)x < (unsigned)this->width() && (unsigned)y < (unsigned)this->height());
- return (uint16_t*)((char*)fPixels + y * fRowBytes + (x << 1));
+ SkASSERT(fPixmap.addr());
+ return fPixmap.writable_addr16(x, y);
}
inline uint8_t* SkBitmap::getAddr8(int x, int y) const {
- SkASSERT(fPixels);
- SkASSERT(1 == this->bytesPerPixel());
- SkASSERT((unsigned)x < (unsigned)this->width() && (unsigned)y < (unsigned)this->height());
- return (uint8_t*)fPixels + y * fRowBytes + x;
+ SkASSERT(fPixmap.addr());
+ return fPixmap.writable_addr8(x, y);
}
#endif
diff --git a/include/core/SkPixmap.h b/include/core/SkPixmap.h
index e6d84c5d9d..f7fe710c6e 100644
--- a/include/core/SkPixmap.h
+++ b/include/core/SkPixmap.h
@@ -723,6 +723,8 @@ private:
const void* fPixels;
size_t fRowBytes;
SkImageInfo fInfo;
+
+ friend class SkPixmapPriv;
};
#endif
diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp
index 7baf47db5f..92d445396c 100644
--- a/src/core/SkBitmap.cpp
+++ b/src/core/SkBitmap.cpp
@@ -18,6 +18,7 @@
#include "SkMask.h"
#include "SkMath.h"
#include "SkPixelRef.h"
+#include "SkPixmapPriv.h"
#include "SkReadBuffer.h"
#include "SkRect.h"
#include "SkScalar.h"
@@ -33,16 +34,11 @@ static bool reset_return_false(SkBitmap* bm) {
return false;
}
-SkBitmap::SkBitmap()
- : fPixels (nullptr)
- , fRowBytes (0)
- , fFlags (0) {}
+SkBitmap::SkBitmap() : fFlags(0) {}
SkBitmap::SkBitmap(const SkBitmap& src)
: fPixelRef (src.fPixelRef)
- , fPixels (src.fPixels)
- , fInfo (src.fInfo)
- , fRowBytes (src.fRowBytes)
+ , fPixmap (src.fPixmap)
, fFlags (src.fFlags)
{
SkDEBUGCODE(src.validate();)
@@ -51,15 +47,11 @@ SkBitmap::SkBitmap(const SkBitmap& src)
SkBitmap::SkBitmap(SkBitmap&& other)
: fPixelRef (std::move(other.fPixelRef))
- , fPixels (other.fPixels)
- , fInfo (std::move(other.fInfo))
- , fRowBytes (other.fRowBytes)
+ , fPixmap (std::move(other.fPixmap))
, fFlags (other.fFlags)
{
SkASSERT(!other.fPixelRef);
- other.fInfo.reset();
- other.fPixels = nullptr;
- other.fRowBytes = 0;
+ other.fPixmap.reset();
other.fFlags = 0;
}
@@ -68,9 +60,7 @@ SkBitmap::~SkBitmap() {}
SkBitmap& SkBitmap::operator=(const SkBitmap& src) {
if (this != &src) {
fPixelRef = src.fPixelRef;
- fPixels = src.fPixels;
- fInfo = src.fInfo;
- fRowBytes = src.fRowBytes;
+ fPixmap = src.fPixmap;
fFlags = src.fFlags;
}
SkDEBUGCODE(this->validate();)
@@ -80,14 +70,10 @@ SkBitmap& SkBitmap::operator=(const SkBitmap& src) {
SkBitmap& SkBitmap::operator=(SkBitmap&& other) {
if (this != &other) {
fPixelRef = std::move(other.fPixelRef);
- fInfo = std::move(other.fInfo);
- fPixels = other.fPixels;
- fRowBytes = other.fRowBytes;
+ fPixmap = std::move(other.fPixmap);
fFlags = other.fFlags;
SkASSERT(!other.fPixelRef);
- other.fInfo.reset();
- other.fPixels = nullptr;
- other.fRowBytes = 0;
+ other.fPixmap.reset();
other.fFlags = 0;
}
return *this;
@@ -100,21 +86,18 @@ void SkBitmap::swap(SkBitmap& other) {
void SkBitmap::reset() {
fPixelRef = nullptr; // Free pixels.
- fPixels = nullptr;
- fInfo.reset();
- fRowBytes = 0;
+ fPixmap.reset();
fFlags = 0;
}
void SkBitmap::getBounds(SkRect* bounds) const {
SkASSERT(bounds);
- bounds->set(0, 0,
- SkIntToScalar(fInfo.width()), SkIntToScalar(fInfo.height()));
+ *bounds = SkRect::Make(this->dimensions());
}
void SkBitmap::getBounds(SkIRect* bounds) const {
SkASSERT(bounds);
- bounds->set(0, 0, fInfo.width(), fInfo.height());
+ *bounds = fPixmap.bounds();
}
///////////////////////////////////////////////////////////////////////////////
@@ -148,27 +131,27 @@ bool SkBitmap::setInfo(const SkImageInfo& info, size_t rowBytes) {
}
fPixelRef = nullptr; // Free pixels.
- fPixels = nullptr;
-
- fInfo = info.makeAlphaType(newAT);
- fRowBytes = SkToU32(rowBytes);
+ fPixmap.reset(info.makeAlphaType(newAT), nullptr, SkToU32(rowBytes));
SkDEBUGCODE(this->validate();)
return true;
}
+
+
bool SkBitmap::setAlphaType(SkAlphaType newAlphaType) {
- if (!SkColorTypeValidateAlphaType(fInfo.colorType(), newAlphaType, &newAlphaType)) {
+ if (!SkColorTypeValidateAlphaType(this->colorType(), newAlphaType, &newAlphaType)) {
return false;
}
- if (fInfo.alphaType() != newAlphaType) {
- fInfo = fInfo.makeAlphaType(newAlphaType);
+ if (this->alphaType() != newAlphaType) {
+ auto newInfo = fPixmap.info().makeAlphaType(newAlphaType);
+ fPixmap.reset(std::move(newInfo), fPixmap.addr(), fPixmap.rowBytes());
}
SkDEBUGCODE(this->validate();)
return true;
}
SkIPoint SkBitmap::pixelRefOrigin() const {
- const char* addr = (const char*)fPixels;
+ const char* addr = (const char*)fPixmap.addr();
const char* pix = (const char*)(fPixelRef ? fPixelRef->pixels() : nullptr);
size_t rb = this->rowBytes();
if (!pix || 0 == rb) {
@@ -184,25 +167,25 @@ SkIPoint SkBitmap::pixelRefOrigin() const {
void SkBitmap::setPixelRef(sk_sp<SkPixelRef> pr, int dx, int dy) {
#ifdef SK_DEBUG
if (pr) {
- if (kUnknown_SkColorType != fInfo.colorType()) {
- SkASSERT(dx >= 0 && fInfo.width() + dx <= pr->width());
- SkASSERT(dy >= 0 && fInfo.height() + dy <= pr->height());
+ if (kUnknown_SkColorType != this->colorType()) {
+ SkASSERT(dx >= 0 && this->width() + dx <= pr->width());
+ SkASSERT(dy >= 0 && this->height() + dy <= pr->height());
}
}
#endif
- fPixelRef = kUnknown_SkColorType != fInfo.colorType() ? std::move(pr) : nullptr;
+ fPixelRef = kUnknown_SkColorType != this->colorType() ? std::move(pr) : nullptr;
+ void* p = nullptr;
+ size_t rowBytes = 0;
+ // ignore dx,dy if there is no pixelref
if (fPixelRef) {
- fRowBytes = fPixelRef->rowBytes();
+ rowBytes = fPixelRef->rowBytes();
// TODO(reed): Enforce that PixelRefs must have non-null pixels.
- if (void* p = fPixelRef->pixels()) {
- fPixels = (char*)p + dy * fRowBytes + dx * fInfo.bytesPerPixel();
- } else {
- fPixels = nullptr;
+ p = fPixelRef->pixels();
+ if (p) {
+ p = (char*)p + dy * rowBytes + dx * this->bytesPerPixel();
}
- } else {
- fPixels = nullptr;
}
-
+ SkPixmapPriv::ResetPixmapKeepInfo(&fPixmap, p, rowBytes);
SkDEBUGCODE(this->validate();)
}
@@ -212,12 +195,12 @@ void SkBitmap::setPixels(void* p) {
return;
}
- if (kUnknown_SkColorType == fInfo.colorType()) {
+ if (kUnknown_SkColorType == this->colorType()) {
this->setPixelRef(nullptr, 0, 0);
return;
}
- this->setPixelRef(SkMallocPixelRef::MakeDirect(fInfo, p, fRowBytes), 0, 0);
+ this->setPixelRef(SkMallocPixelRef::MakeDirect(this->info(), p, this->rowBytes()), 0, 0);
if (!fPixelRef) {
return;
}
@@ -427,7 +410,7 @@ void* SkBitmap::getAddr(int x, int y) const {
void SkBitmap::erase(SkColor c, const SkIRect& area) const {
SkDEBUGCODE(this->validate();)
- switch (fInfo.colorType()) {
+ switch (this->colorType()) {
case kUnknown_SkColorType:
// TODO: can we ASSERT that we never get here?
return; // can't erase. Should we bzero so the memory is not uninitialized?
@@ -503,17 +486,17 @@ bool SkBitmap::readPixels(const SkPixmap& dst, int srcX, int srcY) const {
bool SkBitmap::writePixels(const SkPixmap& src, int dstX, int dstY,
SkTransferFunctionBehavior behavior) {
- if (!SkImageInfoValidConversion(fInfo, src.info())) {
+ if (!SkImageInfoValidConversion(this->info(), src.info())) {
return false;
}
SkWritePixelsRec rec(src.info(), src.addr(), src.rowBytes(), dstX, dstY);
- if (!rec.trim(fInfo.width(), fInfo.height())) {
+ if (!rec.trim(this->width(), this->height())) {
return false;
}
void* dstPixels = this->getAddr(rec.fX, rec.fY);
- const SkImageInfo dstInfo = fInfo.makeWH(rec.fInfo.width(), rec.fInfo.height());
+ const SkImageInfo dstInfo = this->info().makeWH(rec.fInfo.width(), rec.fInfo.height());
SkConvertPixels(dstInfo, dstPixels, this->rowBytes(), rec.fInfo, rec.fPixels, rec.fRowBytes,
nullptr, behavior);
return true;
@@ -611,15 +594,15 @@ bool SkBitmap::extractAlpha(SkBitmap* dst, const SkPaint* paint,
#ifdef SK_DEBUG
void SkBitmap::validate() const {
- fInfo.validate();
+ this->info().validate();
// ImageInfo may not require this, but Bitmap ensures that opaque-only
// colorTypes report opaque for their alphatype
- if (kRGB_565_SkColorType == fInfo.colorType()) {
- SkASSERT(kOpaque_SkAlphaType == fInfo.alphaType());
+ if (kRGB_565_SkColorType == this->colorType()) {
+ SkASSERT(kOpaque_SkAlphaType == this->alphaType());
}
- SkASSERT(fInfo.validRowBytes(fRowBytes));
+ SkASSERT(this->info().validRowBytes(this->rowBytes()));
uint8_t allFlags = kImageIsVolatile_Flag;
#ifdef SK_BUILD_FOR_ANDROID
allFlags |= kHasHardwareMipMap_Flag;
@@ -627,19 +610,20 @@ void SkBitmap::validate() const {
SkASSERT((~allFlags & fFlags) == 0);
if (fPixelRef && fPixelRef->pixels()) {
- SkASSERT(fPixels);
+ SkASSERT(this->getPixels());
} else {
- SkASSERT(!fPixels);
+ SkASSERT(!this->getPixels());
}
- if (fPixels) {
+ if (this->getPixels()) {
SkASSERT(fPixelRef);
- SkASSERT(fPixelRef->rowBytes() == fRowBytes);
+ SkASSERT(fPixelRef->rowBytes() == this->rowBytes());
SkIPoint origin = this->pixelRefOrigin();
+ SkASSERT(origin.fX >= 0);
SkASSERT(origin.fY >= 0);
SkASSERT(fPixelRef->width() >= (int)this->width() + origin.fX);
SkASSERT(fPixelRef->height() >= (int)this->height() + origin.fY);
- SkASSERT(fPixelRef->rowBytes() >= fInfo.minRowBytes());
+ SkASSERT(fPixelRef->rowBytes() >= this->info().minRowBytes());
}
}
#endif
@@ -676,9 +660,9 @@ void SkBitmap::toString(SkString* str) const {
///////////////////////////////////////////////////////////////////////////////
bool SkBitmap::peekPixels(SkPixmap* pmap) const {
- if (fPixels) {
+ if (this->getPixels()) {
if (pmap) {
- pmap->reset(fInfo, fPixels, fRowBytes);
+ *pmap = fPixmap;
}
return true;
}
diff --git a/src/core/SkPixmapPriv.h b/src/core/SkPixmapPriv.h
index 9941862676..cced3e20b9 100644
--- a/src/core/SkPixmapPriv.h
+++ b/src/core/SkPixmapPriv.h
@@ -63,6 +63,11 @@ public:
}
return true;
}
+
+ static void ResetPixmapKeepInfo(SkPixmap* pm, const void* address, size_t rowBytes) {
+ pm->fRowBytes = rowBytes;
+ pm->fPixels = address;
+ }
};
#endif
diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp
index fc9e16743a..e803ce44e4 100644
--- a/src/image/SkImage_Raster.cpp
+++ b/src/image/SkImage_Raster.cpp
@@ -364,10 +364,9 @@ bool SkImage_Raster::onAsLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) c
// pixelref since the caller might call setImmutable() themselves
// (thus changing our state).
if (fBitmap.isImmutable()) {
+ SkIPoint origin = fBitmap.pixelRefOrigin();
bitmap->setInfo(fBitmap.info(), fBitmap.rowBytes());
- bitmap->setPixelRef(sk_ref_sp(fBitmap.pixelRef()),
- fBitmap.pixelRefOrigin().x(),
- fBitmap.pixelRefOrigin().y());
+ bitmap->setPixelRef(sk_ref_sp(fBitmap.pixelRef()), origin.x(), origin.y());
return true;
}
}