Last active
September 25, 2015 15:03
-
-
Save HalCanary/960d8196d0d40e4e7b02 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SkImmutablePixmap { | |
public: | |
SkImmutablePixmap(const SkImageInfo& info, | |
const void* addr, | |
size_t rowBytes, | |
SkColorTable* ctable = NULL) | |
: fPixels(addr), fCTable(ctable), fRowBytes(rowBytes), fInfo(info) { | |
SkASSERT((kIndex_8_SkColorType == info.colorType()) | |
== (ctable != nullptr)); | |
} | |
virtual ~SkImmutablePixmap() {} | |
const void* const fPixels; | |
const SkColorTable* const fCTable; | |
const size_t fRowBytes; | |
const SkImageInfo fInfo; | |
}; | |
class SkImage_Base : public SkImage { | |
// .............. | |
virtual SkImmutablePixmap* getPixmap() const; | |
// .............. | |
}; | |
// default implementation | |
SkImage_Base::SkImmutablePixmap* getPixmap() const { | |
SkBitmap bitmap; | |
if (!this->getROPixels(&bitmap)) { | |
return nullptr; | |
} | |
SkAutoLockPixels autoLockPixels(bitmap); | |
class SkImmutablePixmap_Bitmap : public SkImmutablePixmap { | |
SkImmutablePixmap_Bitmap(const SkBitmap& bm) | |
: SkImmutablePixmap(bm.info(), | |
bm.getPixels(), | |
bm.rowBytes(), | |
bm.colorTable()) | |
, fBitmap(bm) { | |
SkASSERT(bm.getPixels()); // is locked | |
fBitmap.lock(); // hold that lock | |
} | |
virtual ~SkImmutablePixmap_Bitmap() { fBitmap.unlock(); } | |
private: | |
SkBitmap fBitmap; | |
}; | |
return new SkImmutablePixmap_Bitmap(bitmap); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment