diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkBitmap.cpp | 32 | ||||
-rw-r--r-- | src/core/SkMallocPixelRef.cpp | 6 | ||||
-rw-r--r-- | src/core/SkPixelRef.cpp | 55 | ||||
-rw-r--r-- | src/core/SkSpecialSurface.cpp | 11 |
4 files changed, 47 insertions, 57 deletions
diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp index 8bd268476e..1ba2968466 100644 --- a/src/core/SkBitmap.cpp +++ b/src/core/SkBitmap.cpp @@ -171,6 +171,9 @@ bool SkBitmap::setAlphaType(SkAlphaType newAlphaType) { } if (fInfo.alphaType() != newAlphaType) { fInfo = fInfo.makeAlphaType(newAlphaType); + if (fPixelRef) { + fPixelRef->changeAlphaType(newAlphaType); + } } SkDEBUGCODE(this->validate();) return true; @@ -195,15 +198,32 @@ void SkBitmap::setPixelRef(sk_sp<SkPixelRef> pr, int dx, int dy) { #ifdef SK_DEBUG if (pr) { if (kUnknown_SkColorType != fInfo.colorType()) { - SkASSERT(fInfo.width() <= pr->width()); - SkASSERT(fInfo.height() <= pr->height()); + const SkImageInfo& prInfo = pr->info(); + SkASSERT(fInfo.width() <= prInfo.width()); + SkASSERT(fInfo.height() <= prInfo.height()); + SkASSERT(fInfo.colorType() == prInfo.colorType()); + switch (prInfo.alphaType()) { + case kUnknown_SkAlphaType: + SkASSERT(fInfo.alphaType() == kUnknown_SkAlphaType); + break; + case kOpaque_SkAlphaType: + case kPremul_SkAlphaType: + SkASSERT(fInfo.alphaType() == kOpaque_SkAlphaType || + fInfo.alphaType() == kPremul_SkAlphaType); + break; + case kUnpremul_SkAlphaType: + SkASSERT(fInfo.alphaType() == kOpaque_SkAlphaType || + fInfo.alphaType() == kUnpremul_SkAlphaType); + break; + } } } #endif fPixelRef = std::move(pr); if (fPixelRef) { - fPixelRefOrigin.set(SkTPin(dx, 0, fPixelRef->width()), SkTPin(dy, 0, fPixelRef->height())); + const SkImageInfo& info = fPixelRef->info(); + fPixelRefOrigin.set(SkTPin(dx, 0, info.width()), SkTPin(dy, 0, info.height())); this->updatePixelsFromRef(); } else { // ignore dx,dy if there is no pixelref @@ -823,7 +843,7 @@ bool SkBitmap::ReadRawPixels(SkReadBuffer* buffer, SkBitmap* bitmap) { if (!pr) { return false; } - bitmap->setInfo(info); + bitmap->setInfo(pr->info()); bitmap->setPixelRef(std::move(pr), 0, 0); return true; } @@ -863,8 +883,8 @@ void SkBitmap::validate() const { SkASSERT(fPixelRef->rowBytes() == fRowBytes); SkASSERT(fPixelRefOrigin.fX >= 0); SkASSERT(fPixelRefOrigin.fY >= 0); - SkASSERT(fPixelRef->width() >= (int)this->width() + fPixelRefOrigin.fX); - SkASSERT(fPixelRef->height() >= (int)this->height() + fPixelRefOrigin.fY); + SkASSERT(fPixelRef->info().width() >= (int)this->width() + fPixelRefOrigin.fX); + SkASSERT(fPixelRef->info().height() >= (int)this->height() + fPixelRefOrigin.fY); SkASSERT(fPixelRef->rowBytes() >= fInfo.minRowBytes()); } } diff --git a/src/core/SkMallocPixelRef.cpp b/src/core/SkMallocPixelRef.cpp index cf4fac7929..cdc555b748 100644 --- a/src/core/SkMallocPixelRef.cpp +++ b/src/core/SkMallocPixelRef.cpp @@ -156,7 +156,7 @@ SkMallocPixelRef::SkMallocPixelRef(const SkImageInfo& info, void* storage, size_t rowBytes, sk_sp<SkColorTable> ctable, SkMallocPixelRef::ReleaseProc proc, void* context) - : INHERITED(info.width(), info.height(), storage, rowBytes, sanitize(info, std::move(ctable))) + : INHERITED(info, storage, rowBytes, sanitize(info, std::move(ctable))) , fReleaseProc(proc) , fReleaseProcContext(context) {} @@ -167,3 +167,7 @@ SkMallocPixelRef::~SkMallocPixelRef() { fReleaseProc(this->pixels(), fReleaseProcContext); } } + +size_t SkMallocPixelRef::getAllocatedSizeInBytes() const { + return this->info().getSafeSize(this->rowBytes()); +} diff --git a/src/core/SkPixelRef.cpp b/src/core/SkPixelRef.cpp index 487779c67f..c6d59eab19 100644 --- a/src/core/SkPixelRef.cpp +++ b/src/core/SkPixelRef.cpp @@ -26,12 +26,6 @@ uint32_t SkNextID::ImageID() { /////////////////////////////////////////////////////////////////////////////// -#ifdef SK_TRACE_PIXELREF_LIFETIME - static int32_t gInstCounter; -#endif - -#ifdef SK_SUPPORT_LEGACY_PIXELREF_API - static SkImageInfo validate_info(const SkImageInfo& info) { SkAlphaType newAlphaType = info.alphaType(); SkAssertResult(SkColorTypeValidateAlphaType(info.colorType(), info.alphaType(), &newAlphaType)); @@ -49,6 +43,10 @@ static void validate_pixels_ctable(const SkImageInfo& info, const SkColorTable* } } +#ifdef SK_TRACE_PIXELREF_LIFETIME + static int32_t gInstCounter; +#endif + SkPixelRef::SkPixelRef(const SkImageInfo& info, void* pixels, size_t rowBytes, sk_sp<SkColorTable> ctable) : fInfo(validate_info(info)) @@ -70,27 +68,6 @@ SkPixelRef::SkPixelRef(const SkImageInfo& info, void* pixels, size_t rowBytes, fAddedToCache.store(false); } -#endif - -SkPixelRef::SkPixelRef(int width, int height, void* pixels, size_t rowBytes, - sk_sp<SkColorTable> ctable) - : fInfo(SkImageInfo::MakeUnknown(width, height)) - , fCTable(std::move(ctable)) - , fPixels(pixels) - , fRowBytes(rowBytes) -#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK - , fStableID(SkNextID::ImageID()) -#endif -{ -#ifdef SK_TRACE_PIXELREF_LIFETIME - SkDebugf(" pixelref %d\n", sk_atomic_inc(&gInstCounter)); -#endif - - this->needsNewGenID(); - fMutability = kMutable; - fAddedToCache.store(false); -} - SkPixelRef::~SkPixelRef() { #ifdef SK_TRACE_PIXELREF_LIFETIME SkDebugf("~pixelref %d\n", sk_atomic_dec(&gInstCounter) - 1); @@ -99,25 +76,12 @@ SkPixelRef::~SkPixelRef() { } #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK - -#ifdef SK_SUPPORT_LEGACY_PIXELREF_API // This is undefined if there are clients in-flight trying to use us void SkPixelRef::android_only_reset(const SkImageInfo& info, size_t rowBytes, sk_sp<SkColorTable> ctable) { - *const_cast<SkImageInfo*>(&fInfo) = info; - fRowBytes = rowBytes; - fCTable = std::move(ctable); - // note: we do not change fPixels - - // conservative, since its possible the "new" settings are the same as the old. - this->notifyPixelsChanged(); -} -#endif + validate_pixels_ctable(info, ctable.get()); -// This is undefined if there are clients in-flight trying to use us -void SkPixelRef::android_only_reset(int width, int height, size_t rowBytes, - sk_sp<SkColorTable> ctable) { - *const_cast<SkImageInfo*>(&fInfo) = fInfo.makeWH(width, height); + *const_cast<SkImageInfo*>(&fInfo) = info; fRowBytes = rowBytes; fCTable = std::move(ctable); // note: we do not change fPixels @@ -125,7 +89,6 @@ void SkPixelRef::android_only_reset(int width, int height, size_t rowBytes, // conservative, since its possible the "new" settings are the same as the old. this->notifyPixelsChanged(); } - #endif void SkPixelRef::needsNewGenID() { @@ -186,11 +149,9 @@ void SkPixelRef::notifyPixelsChanged() { this->onNotifyPixelsChanged(); } -#ifdef SK_SUPPORT_LEGACY_PIXELREF_API void SkPixelRef::changeAlphaType(SkAlphaType at) { *const_cast<SkImageInfo*>(&fInfo) = fInfo.makeAlphaType(at); } -#endif void SkPixelRef::setImmutable() { fMutability = kImmutable; @@ -218,3 +179,7 @@ void SkPixelRef::restoreMutability() { } void SkPixelRef::onNotifyPixelsChanged() { } + +size_t SkPixelRef::getAllocatedSizeInBytes() const { + return 0; +} diff --git a/src/core/SkSpecialSurface.cpp b/src/core/SkSpecialSurface.cpp index 9564a14f48..33ef97e5bd 100644 --- a/src/core/SkSpecialSurface.cpp +++ b/src/core/SkSpecialSurface.cpp @@ -63,11 +63,12 @@ sk_sp<SkSpecialImage> SkSpecialSurface::makeImageSnapshot() { class SkSpecialSurface_Raster : public SkSpecialSurface_Base { public: - SkSpecialSurface_Raster(const SkImageInfo& info, - sk_sp<SkPixelRef> pr, + SkSpecialSurface_Raster(sk_sp<SkPixelRef> pr, const SkIRect& subset, const SkSurfaceProps* props) : INHERITED(subset, props) { + const SkImageInfo& info = pr->info(); + fBitmap.setInfo(info, info.minRowBytes()); fBitmap.setPixelRef(std::move(pr), 0, 0); @@ -92,7 +93,7 @@ private: sk_sp<SkSpecialSurface> SkSpecialSurface::MakeFromBitmap(const SkIRect& subset, SkBitmap& bm, const SkSurfaceProps* props) { - return sk_make_sp<SkSpecialSurface_Raster>(bm.info(), sk_ref_sp(bm.pixelRef()), subset, props); + return sk_make_sp<SkSpecialSurface_Raster>(sk_ref_sp(bm.pixelRef()), subset, props); } sk_sp<SkSpecialSurface> SkSpecialSurface::MakeRaster(const SkImageInfo& info, @@ -102,9 +103,9 @@ sk_sp<SkSpecialSurface> SkSpecialSurface::MakeRaster(const SkImageInfo& info, return nullptr; } - const SkIRect subset = SkIRect::MakeWH(info.width(), info.height()); + const SkIRect subset = SkIRect::MakeWH(pr->info().width(), pr->info().height()); - return sk_make_sp<SkSpecialSurface_Raster>(info, std::move(pr), subset, props); + return sk_make_sp<SkSpecialSurface_Raster>(std::move(pr), subset, props); } #if SK_SUPPORT_GPU |