diff options
author | initial.commit <initial.commit@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-07-27 00:09:42 +0000 |
---|---|---|
committer | initial.commit <initial.commit@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-07-27 00:09:42 +0000 |
commit | ae2c20f398933a9e86c387dcc465ec0f71065ffc (patch) | |
tree | de668b1411e2ee0b4e49b6d8f8b68183134ac990 /skia/include/SkImageRef.h | |
parent | 09911bf300f1a419907a9412154760efd0b7abc3 (diff) | |
download | chromium_src-ae2c20f398933a9e86c387dcc465ec0f71065ffc.zip chromium_src-ae2c20f398933a9e86c387dcc465ec0f71065ffc.tar.gz chromium_src-ae2c20f398933a9e86c387dcc465ec0f71065ffc.tar.bz2 |
Add skia to the repository.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia/include/SkImageRef.h')
-rw-r--r-- | skia/include/SkImageRef.h | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/skia/include/SkImageRef.h b/skia/include/SkImageRef.h new file mode 100644 index 0000000..6ffb340 --- /dev/null +++ b/skia/include/SkImageRef.h @@ -0,0 +1,83 @@ +#ifndef SkImageRef_DEFINED +#define SkImageRef_DEFINED + +#include "SkPixelRef.h" +#include "SkBitmap.h" +#include "SkImageDecoder.h" +#include "SkString.h" + +class SkImageRefPool; +class SkStream; + +// define this to enable dumping whenever we add/remove/purge an imageref +//#define DUMP_IMAGEREF_LIFECYCLE + +class SkImageRef : public SkPixelRef { +public: + /** Create a new imageref from a stream. NOTE: the stream is not copied, but + since it may be accessed from another thread, the caller must ensure + that this imageref is the only owner of the stream. i.e. - sole + ownership of the stream object is transferred to this imageref object. + + @param stream The stream containing the encoded image data. Ownership + of this stream is transferred to the imageref, and + therefore the stream's ownercount must be 1. + @param config The preferred config of the decoded bitmap. + @param sampleSize Requested sampleSize for decoding. Defaults to 1. + */ + SkImageRef(SkStream*, SkBitmap::Config config, int sampleSize = 1); + virtual ~SkImageRef(); + + const char* getName() const { return fName.c_str(); } + void setName(const char name[]) { fName.set(name); } + + /** Return true if the image can be decoded. If so, and bitmap is non-null, + call its setConfig() with the corresponding values, but explicitly will + not set its pixels or colortable. Use SkPixelRef::lockPixels() for that. + */ + bool getInfo(SkBitmap* bm); + + // overrides + virtual void flatten(SkFlattenableWriteBuffer&) const; + +protected: + /** Override if you want to install a custom allocator. + When this is called we will have already acquired the mutex! + */ + virtual bool onDecode(SkImageDecoder* codec, SkStream*, SkBitmap*, + SkBitmap::Config, SkImageDecoder::Mode); + + /* Overrides from SkPixelRef + When these are called, we will have already acquired the mutex! + */ + + virtual void* onLockPixels(SkColorTable**); + // override this in your subclass to clean up when we're unlocking pixels + virtual void onUnlockPixels(); + + SkImageRef(SkFlattenableReadBuffer&); + + SkBitmap fBitmap; + +private: + SkStream* setStream(SkStream*); + // called with mutex already held. returns true if the bitmap is in the + // requested state (or further, i.e. has pixels) + bool prepareBitmap(SkImageDecoder::Mode); + + SkStream* fStream; + SkBitmap::Config fConfig; + int fSampleSize; + bool fErrorInDecoding; + + SkString fName; // for debugging + + friend class SkImageRefPool; + + SkImageRef* fPrev, *fNext; + size_t ramUsed() const; + + typedef SkPixelRef INHERITED; +}; + +#endif |