diff options
author | Matt Sarett <msarett@google.com> | 2017-05-01 10:22:31 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-05-01 15:01:05 +0000 |
commit | f758311c7362d9232b98b6519ec0af1f71ad02f8 (patch) | |
tree | f22ceecc807e265f8f09ef4932afb8757af3e00e /include/core | |
parent | 38a56016b15b989764e855a1d1259aabd67bec72 (diff) |
Only store width and height on SkPixelRef (part 2)
Relanding https://skia-review.googlesource.com/c/14105/
in pieces to try to diagnose problems with the Chrome
roll.
Bug: skia:6535
Change-Id: Iada034fc41ef315f7f00984d8de9d9cc2f361ad2
Reviewed-on: https://skia-review.googlesource.com/14657
Commit-Queue: Matt Sarett <msarett@google.com>
Reviewed-by: Mike Reed <reed@google.com>
Diffstat (limited to 'include/core')
-rw-r--r-- | include/core/SkMallocPixelRef.h | 2 | ||||
-rw-r--r-- | include/core/SkPixelRef.h | 55 |
2 files changed, 32 insertions, 25 deletions
diff --git a/include/core/SkMallocPixelRef.h b/include/core/SkMallocPixelRef.h index 45ab6547f4..e6d9727952 100644 --- a/include/core/SkMallocPixelRef.h +++ b/include/core/SkMallocPixelRef.h @@ -78,8 +78,6 @@ public: protected: ~SkMallocPixelRef() override; - size_t getAllocatedSizeInBytes() const override; - private: // Uses alloc to implement NewAllocate or NewZeroed. static sk_sp<SkPixelRef> MakeUsing(void*(*alloc)(size_t), diff --git a/include/core/SkPixelRef.h b/include/core/SkPixelRef.h index 05b0fbcf9c..3c002dca70 100644 --- a/include/core/SkPixelRef.h +++ b/include/core/SkPixelRef.h @@ -33,12 +33,37 @@ class SkDiscardableMemory; class SK_API SkPixelRef : public SkRefCnt { public: SkPixelRef(const SkImageInfo&, void* addr, size_t rowBytes, sk_sp<SkColorTable> = nullptr); - ~SkPixelRef() override; 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; } + + 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(); } void* pixels() const { return fPixels; } @@ -70,13 +95,6 @@ public: */ void notifyPixelsChanged(); - /** - * 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 true if this pixelref is marked as immutable, meaning that the contents of its pixels will not change for the lifetime of the pixelref. */ @@ -116,27 +134,18 @@ protected: // default impl does nothing. virtual void onNotifyPixelsChanged(); - /** - * 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; - #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>); + void android_only_reset(int width, int height, size_t rowBytes, sk_sp<SkColorTable>); #endif private: - // mostly const. fInfo.fAlpahType can be changed at runtime. - const SkImageInfo fInfo; + // TODO (msarett): After we remove legacy APIs, we should replace |fInfo| with just a width + // and height. + const SkImageInfo fInfo; sk_sp<SkColorTable> fCTable; - void* fPixels; - size_t fRowBytes; + void* fPixels; + size_t fRowBytes; // Bottom bit indicates the Gen ID is unique. bool genIDIsUnique() const { return SkToBool(fTaggedGenID.load() & 1); } |