From bc6e5ff7cfbacc28659c0aecbe9f2989cad80336 Mon Sep 17 00:00:00 2001 From: Matt Sarett Date: Tue, 2 May 2017 11:41:30 -0400 Subject: [PATCH] Finish removal of SkImageInfo from SkPixelRef All of the clients are updated. We don't need this anymore. Bug: skia:6535 Change-Id: I1399a08b7dda8f29c4f4016a1de50ee8310c1fef Reviewed-on: https://skia-review.googlesource.com/15106 Reviewed-by: Matt Sarett Commit-Queue: Matt Sarett --- gn/android_framework_defines.gni | 1 - include/core/SkPixelRef.h | 39 ++---------------- src/core/SkPixelRef.cpp | 69 ++------------------------------ 3 files changed, 8 insertions(+), 101 deletions(-) diff --git a/gn/android_framework_defines.gni b/gn/android_framework_defines.gni index bc49f4be45..67c6a2d5e2 100644 --- a/gn/android_framework_defines.gni +++ b/gn/android_framework_defines.gni @@ -9,7 +9,6 @@ android_framework_defines = [ "SK_IGNORE_LINEONLY_AA_CONVEX_PATH_OPTS", "SK_SUPPORT_LEGACY_GRADIENT_DITHERING", "SK_SUPPORT_LEGACY_DRAWFILTER", - "SK_SUPPORT_LEGACY_PIXELREF_API", "SK_IGNORE_GPU_DITHER", "SK_SUPPORT_LEGACY_SHADER_ISABITMAP", "SK_SUPPORT_LEGACY_EMBOSSMASKFILTER", diff --git a/include/core/SkPixelRef.h b/include/core/SkPixelRef.h index bf4609865f..4613209f06 100644 --- a/include/core/SkPixelRef.h +++ b/include/core/SkPixelRef.h @@ -32,43 +32,13 @@ class SkDiscardableMemory; */ class SK_API SkPixelRef : public SkRefCnt { public: -#ifdef SK_SUPPORT_LEGACY_PIXELREF_API - SkPixelRef(const SkImageInfo&, void* addr, size_t rowBytes, sk_sp = nullptr); - - const SkImageInfo& info() const { - return fInfo; - } - -#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK - // This is undefined if there are clients in-flight trying to use us - void android_only_reset(const SkImageInfo&, size_t rowBytes, sk_sp); -#endif - - /** - * Change the info's AlphaType. Note that this does not automatically - * invalidate the generation ID. If the pixel values themselves have - * changed, then you must explicitly call notifyPixelsChanged() as well. - */ - void changeAlphaType(SkAlphaType at); - - /** - * Returns the size (in bytes) of the internally allocated memory. - * This should be implemented in all serializable SkPixelRef derived classes. - * SkBitmap::fPixelRefOffset + SkBitmap::getSafeSize() should never overflow this value, - * otherwise the rendering code may attempt to read memory out of bounds. - * - * @return default impl returns 0. - */ - virtual size_t getAllocatedSizeInBytes() const { return 0; } - -#endif SkPixelRef(int width, int height, void* addr, size_t rowBytes, sk_sp = nullptr); ~SkPixelRef() override; - int width() const { return fInfo.width(); } - int height() const { return fInfo.height(); } + int width() const { return fWidth; } + int height() const { return fHeight; } void* pixels() const { return fPixels; } SkColorTable* colorTable() const { return fCTable.get(); } size_t rowBytes() const { return fRowBytes; } @@ -143,9 +113,8 @@ protected: #endif private: - // TODO (msarett): After we remove legacy APIs, we should replace |fInfo| with just a width - // and height. - const SkImageInfo fInfo; + int fWidth; + int fHeight; sk_sp fCTable; void* fPixels; size_t fRowBytes; diff --git a/src/core/SkPixelRef.cpp b/src/core/SkPixelRef.cpp index 7d8b12d2ff..4583c18978 100644 --- a/src/core/SkPixelRef.cpp +++ b/src/core/SkPixelRef.cpp @@ -30,51 +30,10 @@ uint32_t SkNextID::ImageID() { 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)); - return info.makeAlphaType(newAlphaType); -} - -static void validate_pixels_ctable(const SkImageInfo& info, const SkColorTable* ctable) { - if (info.isEmpty()) { - return; // can't require ctable if the dimensions are empty - } - if (kIndex_8_SkColorType == info.colorType()) { - SkASSERT(ctable); - } else { - SkASSERT(nullptr == ctable); - } -} - -SkPixelRef::SkPixelRef(const SkImageInfo& info, void* pixels, size_t rowBytes, - sk_sp ctable) - : fInfo(validate_info(info)) - , fCTable(std::move(ctable)) - , fPixels(pixels) - , fRowBytes(rowBytes) -#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK - , fStableID(SkNextID::ImageID()) -#endif -{ - validate_pixels_ctable(fInfo, fCTable.get()); - SkASSERT(rowBytes >= info.minRowBytes()); -#ifdef SK_TRACE_PIXELREF_LIFETIME - SkDebugf(" pixelref %d\n", sk_atomic_inc(&gInstCounter)); -#endif - - this->needsNewGenID(); - fMutability = kMutable; - fAddedToCache.store(false); -} - -#endif - SkPixelRef::SkPixelRef(int width, int height, void* pixels, size_t rowBytes, sk_sp ctable) - : fInfo(SkImageInfo::MakeUnknown(width, height)) + : fWidth(width) + , fHeight(height) , fCTable(std::move(ctable)) , fPixels(pixels) , fRowBytes(rowBytes) @@ -100,25 +59,11 @@ 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 ctable) { - *const_cast(&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 - // 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 ctable) { - *const_cast(&fInfo) = fInfo.makeWH(width, height); + fWidth = width; + fHeight = height; fRowBytes = rowBytes; fCTable = std::move(ctable); // note: we do not change fPixels @@ -187,12 +132,6 @@ void SkPixelRef::notifyPixelsChanged() { this->onNotifyPixelsChanged(); } -#ifdef SK_SUPPORT_LEGACY_PIXELREF_API -void SkPixelRef::changeAlphaType(SkAlphaType at) { - *const_cast(&fInfo) = fInfo.makeAlphaType(at); -} -#endif - void SkPixelRef::setImmutable() { fMutability = kImmutable; }