*/
class SK_API SkPixelRef : public SkRefCnt {
public:
-#ifdef SK_SUPPORT_LEGACY_PIXELREF_API
- SkPixelRef(const SkImageInfo&, void* addr, size_t rowBytes, sk_sp<SkColorTable> = 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<SkColorTable>);
-#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<SkColorTable> = 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; }
#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<SkColorTable> fCTable;
void* fPixels;
size_t fRowBytes;
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<SkColorTable> 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<SkColorTable> ctable)
- : fInfo(SkImageInfo::MakeUnknown(width, height))
+ : fWidth(width)
+ , fHeight(height)
, fCTable(std::move(ctable))
, fPixels(pixels)
, fRowBytes(rowBytes)
#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
-
// 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);
+ fWidth = width;
+ fHeight = height;
fRowBytes = rowBytes;
fCTable = std::move(ctable);
// note: we do not change fPixels
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;
}