diff options
author | 2017-04-17 11:02:51 -0400 | |
---|---|---|
committer | 2017-04-17 15:33:36 +0000 | |
commit | 4edb5d219eb99aa1e8fbe5e37260d3b34314e54b (patch) | |
tree | 5e9fedc4e0e59db2467a19fe7d4f36030d0d6694 /include | |
parent | 12e946b4bfdf598bffb276776ea6e25439e25265 (diff) |
hide lockpixels api behind flag
guarded by SK_SUPPORT_OBSOLETE_LOCKPIXELS
needs https://codereview.chromium.org/2820873002/# to land first
Bug: skia:6481
Change-Id: I1c39902cbf6fe99f622adfa8192733b95f7fea09
Change-Id: I1c39902cbf6fe99f622adfa8192733b95f7fea09
Reviewed-on: https://skia-review.googlesource.com/13580
Reviewed-by: Florin Malita <fmalita@chromium.org>
Reviewed-by: Leon Scroggins <scroggo@google.com>
Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/core/SkBitmap.h | 27 | ||||
-rw-r--r-- | include/core/SkImageEncoder.h | 1 | ||||
-rw-r--r-- | include/core/SkPixelRef.h | 80 | ||||
-rw-r--r-- | include/core/SkPixmap.h | 4 |
4 files changed, 45 insertions, 67 deletions
diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h index 9520210888..e19f45232e 100644 --- a/include/core/SkBitmap.h +++ b/include/core/SkBitmap.h @@ -217,8 +217,8 @@ public: * "unknown" pixels. */ static bool ComputeIsOpaque(const SkBitmap& bm) { - SkAutoPixmapUnlock result; - return bm.requestLock(&result) && result.pixmap().computeIsOpaque(); + SkPixmap pmap; + return bm.peekPixels(&pmap) && pmap.computeIsOpaque(); } /** @@ -419,10 +419,11 @@ public: */ void setPixelRef(sk_sp<SkPixelRef>, int dx, int dy); +#ifdef SK_SUPPORT_OBSOLETE_LOCKPIXELS void lockPixels() const {} void unlockPixels() const {} - bool requestLock(SkAutoPixmapUnlock* result) const; +#endif /** Call this to be sure that the bitmap is valid enough to be drawn (i.e. it has non-null pixels, and if required by its colortype, it has a @@ -755,26 +756,12 @@ private: friend class SkBinaryWriteBuffer; // rawpixels }; +#ifdef SK_SUPPORT_OBSOLETE_LOCKPIXELS class SkAutoLockPixels : SkNoncopyable { public: - SkAutoLockPixels(const SkBitmap& bm, bool doLock = true) : fBitmap(bm) { - fDidLock = doLock; - if (doLock) { - bm.lockPixels(); - } - } - ~SkAutoLockPixels() { - if (fDidLock) { - fBitmap.unlockPixels(); - } - } - -private: - const SkBitmap& fBitmap; - bool fDidLock; + SkAutoLockPixels(const SkBitmap&, bool = true) {} }; -//TODO(mtklein): uncomment when 71713004 lands and Chromium's fixed. -//#define SkAutoLockPixels(...) SK_REQUIRE_LOCAL_VAR(SkAutoLockPixels) +#endif /////////////////////////////////////////////////////////////////////////////// diff --git a/include/core/SkImageEncoder.h b/include/core/SkImageEncoder.h index e4f746ab96..5cd5f4a60f 100644 --- a/include/core/SkImageEncoder.h +++ b/include/core/SkImageEncoder.h @@ -34,7 +34,6 @@ SK_API bool SkEncodeImage(SkWStream* dst, const SkPixmap& src, * The following helper function wraps SkEncodeImage(). */ inline bool SkEncodeImage(SkWStream* dst, const SkBitmap& src, SkEncodedImageFormat f, int q) { - SkAutoLockPixels autoLockPixels(src); SkPixmap pixmap; return src.peekPixels(&pixmap) && SkEncodeImage(dst, pixmap, f, q); } diff --git a/include/core/SkPixelRef.h b/include/core/SkPixelRef.h index 0e66f25d31..56e0caf7c8 100644 --- a/include/core/SkPixelRef.h +++ b/include/core/SkPixelRef.h @@ -32,22 +32,18 @@ class SkDiscardableMemory; */ class SK_API SkPixelRef : public SkRefCnt { public: - explicit SkPixelRef(const SkImageInfo&, void* addr, size_t rowBytes, - sk_sp<SkColorTable> = nullptr); - virtual ~SkPixelRef(); + SkPixelRef(const SkImageInfo&, void* addr, size_t rowBytes, sk_sp<SkColorTable> = nullptr); + ~SkPixelRef() override; const SkImageInfo& info() const { return fInfo; } - void* pixels() const { return fRec.fPixels; } - SkColorTable* colorTable() const { return fRec.fColorTable; } - size_t rowBytes() const { return fRec.fRowBytes; } + void* pixels() const { return fPixels; } + SkColorTable* colorTable() const { return fCTable.get(); } + size_t rowBytes() const { return fRowBytes; } - /** - * To access the actual pixels of a pixelref, it must be "locked". - * Calling lockPixels returns a LockRec struct (on success). - */ +#ifdef SK_SUPPORT_OBSOLETE_LOCKPIXELS struct LockRec { LockRec() : fPixels(NULL), fColorTable(NULL) {} @@ -72,6 +68,33 @@ public: */ bool lockPixels(LockRec* rec); + struct LockRequest { + SkISize fSize; + SkFilterQuality fQuality; + }; + + struct LockResult { + LockResult() : fPixels(NULL), fCTable(NULL) {} + + void (*fUnlockProc)(void* ctx); + void* fUnlockContext; + + const void* fPixels; + SkColorTable* fCTable; // should be NULL unless colortype is kIndex8 + size_t fRowBytes; + SkISize fSize; + + void unlock() { + if (fUnlockProc) { + fUnlockProc(fUnlockContext); + fUnlockProc = NULL; // can't unlock twice! + } + } + }; + + bool requestLock(const LockRequest&, LockResult*); +#endif + /** Returns a non-zero, unique value corresponding to the pixels in this pixelref. Each time the pixels are changed (and notifyPixelsChanged is @@ -116,32 +139,6 @@ public: */ void setImmutable(); - struct LockRequest { - SkISize fSize; - SkFilterQuality fQuality; - }; - - struct LockResult { - LockResult() : fPixels(NULL), fCTable(NULL) {} - - void (*fUnlockProc)(void* ctx); - void* fUnlockContext; - - const void* fPixels; - SkColorTable* fCTable; // should be NULL unless colortype is kIndex8 - size_t fRowBytes; - SkISize fSize; - - void unlock() { - if (fUnlockProc) { - fUnlockProc(fUnlockContext); - fUnlockProc = NULL; // can't unlock twice! - } - } - }; - - bool requestLock(const LockRequest&, LockResult*); - // Register a listener that may be called the next time our generation ID changes. // // We'll only call the listener if we're confident that we are the only SkPixelRef with this @@ -188,10 +185,9 @@ protected: private: // mostly const. fInfo.fAlpahType can be changed at runtime. const SkImageInfo fInfo; - sk_sp<SkColorTable> fCTable; // duplicated in LockRec, will unify later - - // LockRec is only valid if we're in a locked state (isLocked()) - LockRec fRec; + sk_sp<SkColorTable> fCTable; + void* fPixels; + size_t fRowBytes; // Bottom bit indicates the Gen ID is unique. bool genIDIsUnique() const { return SkToBool(fTaggedGenID.load() & 1); } @@ -212,9 +208,6 @@ private: kImmutable, // Once set to this state, it never leaves. } fMutability : 8; // easily fits inside a byte - // only ever set in constructor, const after that - bool fPreLocked; - void needsNewGenID(); void callGenIDChangeListeners(); @@ -222,7 +215,6 @@ private: void restoreMutability(); friend class SkSurface_Raster; // For the two methods above. - bool isPreLocked() const { return fPreLocked; } friend class SkImage_Raster; friend class SkSpecialImage_Raster; diff --git a/include/core/SkPixmap.h b/include/core/SkPixmap.h index 6cf948e601..d028124222 100644 --- a/include/core/SkPixmap.h +++ b/include/core/SkPixmap.h @@ -221,8 +221,7 @@ private: ///////////////////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////////////////// - +#ifdef SK_SUPPORT_OBSOLETE_LOCKPIXELS class SK_API SkAutoPixmapUnlock : ::SkNoncopyable { public: SkAutoPixmapUnlock() : fUnlockProc(NULL), fIsLocked(false) {} @@ -268,5 +267,6 @@ private: friend class SkBitmap; }; +#endif #endif |