* Set the bitmap's alphaType, returning true on success. If false is
* returned, then the specified new alphaType is incompatible with the
* Config, and the current alphaType is unchanged.
+ *
+ * Note: this changes the alphatype for the underlying pixels, which means
+ * that all bitmaps that might be sharing (subsets of) the pixels will
+ * be affected. This is an expensive change for some backends (e.g. GPU)
+ * since changing the alphatype can invalidate internal caches. Thus this
+ * call should only be made if it is associated with real changes to the
+ * pixel data.
*/
bool setAlphaType(SkAlphaType);
-
/*
* Copyright 2008 The Android Open Source Project
*
* found in the LICENSE file.
*/
-
#ifndef SkPixelRef_DEFINED
#define SkPixelRef_DEFINED
*/
uint32_t getGenerationID() const;
- /** Call this if you have changed the contents of the pixels. This will in-
- turn cause a different generation ID value to be returned from
- getGenerationID().
- */
- void notifyPixelsChanged();
+ /**
+ * Call this if you have changed the contents of the pixels. This will in-
+ * turn cause a different generation ID value to be returned from
+ * getGenerationID().
+ *
+ * If the alphatype has also changed, specify its new value as well. If
+ * the new pixels' alphatype is the same, this can be called with no
+ * parameter.
+ */
+ void notifyPixelsChanged(SkAlphaType);
+ void notifyPixelsChanged() {
+ this->notifyPixelsChanged(fInfo.fAlphaType);
+ }
/** 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.
private:
SkBaseMutex* fMutex; // must remain in scope for the life of this object
+ // mostly const. fInfo.fAlpahType can be changed at runtime.
const SkImageInfo fInfo;
// LockRec is only valid if we're in a locked state (isLocked())
if (!validate_alphaType(this->config(), alphaType, &alphaType)) {
return false;
}
- fAlphaType = SkToU8(alphaType);
+ if (fAlphaType != alphaType) {
+ fAlphaType = SkToU8(alphaType);
+ if (fPixelRef) {
+ fPixelRef->notifyPixelsChanged(alphaType);
+ }
+ }
return true;
}
fGenIDChangeListeners.deleteAll();
}
-void SkPixelRef::notifyPixelsChanged() {
+void SkPixelRef::notifyPixelsChanged(SkAlphaType at) {
#ifdef SK_DEBUG
if (fIsImmutable) {
SkDebugf("========== notifyPixelsChanged called on immutable pixelref");
}
#endif
+ *const_cast<SkAlphaType*>(&fInfo.fAlphaType) = at;
this->callGenIDChangeListeners();
this->needsNewGenID();
}