add optional SkAlphaType parameter to notifyPixelsChanged

R=scroggo@google.com, halcanary@google.com, robertphillips@google.com

Author: reed@google.com

Review URL: https://codereview.chromium.org/147213002

git-svn-id: http://skia.googlecode.com/svn/trunk@13192 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
commit-bot@chromium.org 2014-01-27 15:41:07 +00:00
parent 83c39db913
commit 0e8d0d6cdc
4 changed files with 29 additions and 9 deletions

View File

@ -128,6 +128,13 @@ public:
* 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);

View File

@ -1,4 +1,3 @@
/*
* Copyright 2008 The Android Open Source Project
*
@ -6,7 +5,6 @@
* found in the LICENSE file.
*/
#ifndef SkPixelRef_DEFINED
#define SkPixelRef_DEFINED
@ -128,11 +126,19 @@ public:
*/
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.
@ -333,6 +339,7 @@ protected:
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())

View File

@ -321,7 +321,12 @@ bool SkBitmap::setAlphaType(SkAlphaType alphaType) {
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;
}

View File

@ -254,12 +254,13 @@ void SkPixelRef::callGenIDChangeListeners() {
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();
}