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/SkWriter32.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/SkWriter32.h')
-rw-r--r-- | skia/include/SkWriter32.h | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/skia/include/SkWriter32.h b/skia/include/SkWriter32.h new file mode 100644 index 0000000..66910d1 --- /dev/null +++ b/skia/include/SkWriter32.h @@ -0,0 +1,96 @@ +#ifndef SkWriter32_DEFINED +#define SkWriter32_DEFINED + +#include "SkTypes.h" + +#include "SkScalar.h" +#include "SkPoint.h" +#include "SkRect.h" + +class SkStream; +class SkWStream; + +class SkWriter32 : SkNoncopyable { +public: + SkWriter32(size_t minSize) { + fMinSize = minSize; + fSize = 0; + fHead = fTail = NULL; + } + ~SkWriter32(); + + bool writeBool(bool value) { + this->writeInt(value); + return value; + } + + void writeInt(int32_t value) { + *(int32_t*)this->reserve(sizeof(value)) = value; + } + + void write8(int32_t value) { + *(int32_t*)this->reserve(sizeof(value)) = value & 0xFF; + } + + void write16(int32_t value) { + *(int32_t*)this->reserve(sizeof(value)) = value & 0xFFFF; + } + + void write32(int32_t value) { + *(int32_t*)this->reserve(sizeof(value)) = value; + } + + void writeScalar(SkScalar value) { + *(SkScalar*)this->reserve(sizeof(value)) = value; + } + + void writePoint(const SkPoint& pt) { + *(SkPoint*)this->reserve(sizeof(pt)) = pt; + } + + void writeRect(const SkRect& rect) { + *(SkRect*)this->reserve(sizeof(rect)) = rect; + } + + // write count bytes (must be a multiple of 4) + void writeMul4(const void* values, size_t size) { + SkASSERT(SkAlign4(size) == size); + // if we could query how much is avail in the current block, we might + // copy that much, and then alloc the rest. That would reduce the waste + // in the current block + memcpy(this->reserve(size), values, size); + } + + void writePad(const void* src, size_t size); + + // return the current offset (will always be a multiple of 4) + uint32_t size() const { return fSize; } + void reset(); + uint32_t* reserve(size_t size); // size MUST be multiple of 4 + + // return the address of the 4byte int at the specified offset (which must + // be a multiple of 4. This does not allocate any new space, so the returned + // address is only valid for 1 int. + uint32_t* peek32(size_t offset); + + // copy into a single buffer (allocated by caller). Must be at least size() + void flatten(void* dst) const; + + // read from the stream, and write up to length bytes. Return the actual + // number of bytes written. + size_t readFromStream(SkStream*, size_t length); + + bool writeToStream(SkWStream*); + +private: + size_t fMinSize; + uint32_t fSize; + + struct Block; + Block* fHead; + Block* fTail; + + Block* newBlock(size_t bytes); +}; + +#endif |