gfx/skia/trunk/include/core/SkWriteBuffer.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/include/core/SkWriteBuffer.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,120 @@
     1.4 +
     1.5 +/*
     1.6 + * Copyright 2011 Google Inc.
     1.7 + *
     1.8 + * Use of this source code is governed by a BSD-style license that can be
     1.9 + * found in the LICENSE file.
    1.10 + */
    1.11 +
    1.12 +#ifndef SkWriteBuffer_DEFINED
    1.13 +#define SkWriteBuffer_DEFINED
    1.14 +
    1.15 +#include "SkBitmapHeap.h"
    1.16 +#include "SkData.h"
    1.17 +#include "SkPath.h"
    1.18 +#include "SkPicture.h"
    1.19 +#include "SkRefCnt.h"
    1.20 +#include "SkWriter32.h"
    1.21 +
    1.22 +class SkBitmap;
    1.23 +class SkFactorySet;
    1.24 +class SkFlattenable;
    1.25 +class SkNamedFactorySet;
    1.26 +class SkRefCntSet;
    1.27 +
    1.28 +class SkWriteBuffer {
    1.29 +public:
    1.30 +    enum Flags {
    1.31 +        kCrossProcess_Flag  = 1 << 0,
    1.32 +        kValidation_Flag    = 1 << 1,
    1.33 +    };
    1.34 +
    1.35 +    SkWriteBuffer(uint32_t flags = 0);
    1.36 +    SkWriteBuffer(void* initialStorage, size_t storageSize, uint32_t flags = 0);
    1.37 +    ~SkWriteBuffer();
    1.38 +
    1.39 +    bool isCrossProcess() const {
    1.40 +        return this->isValidating() || SkToBool(fFlags & kCrossProcess_Flag);
    1.41 +    }
    1.42 +
    1.43 +    SkWriter32* getWriter32() { return &fWriter; }
    1.44 +    void reset(void* storage = NULL, size_t storageSize = 0) {
    1.45 +        fWriter.reset(storage, storageSize);
    1.46 +    }
    1.47 +
    1.48 +    uint32_t* reserve(size_t size) { return fWriter.reserve(size); }
    1.49 +
    1.50 +    size_t bytesWritten() const { return fWriter.bytesWritten(); }
    1.51 +
    1.52 +    void writeByteArray(const void* data, size_t size);
    1.53 +    void writeDataAsByteArray(SkData* data) { this->writeByteArray(data->data(), data->size()); }
    1.54 +    void writeBool(bool value);
    1.55 +    void writeFixed(SkFixed value);
    1.56 +    void writeScalar(SkScalar value);
    1.57 +    void writeScalarArray(const SkScalar* value, uint32_t count);
    1.58 +    void writeInt(int32_t value);
    1.59 +    void writeIntArray(const int32_t* value, uint32_t count);
    1.60 +    void writeUInt(uint32_t value);
    1.61 +    void write32(int32_t value);
    1.62 +    void writeString(const char* value);
    1.63 +    void writeEncodedString(const void* value, size_t byteLength, SkPaint::TextEncoding encoding);
    1.64 +    void writeFunctionPtr(void* ptr) { this->writeByteArray(&ptr, sizeof(ptr)); }
    1.65 +
    1.66 +    void writeFlattenable(const SkFlattenable* flattenable);
    1.67 +    void writeColor(const SkColor& color);
    1.68 +    void writeColorArray(const SkColor* color, uint32_t count);
    1.69 +    void writePoint(const SkPoint& point);
    1.70 +    void writePointArray(const SkPoint* point, uint32_t count);
    1.71 +    void writeMatrix(const SkMatrix& matrix);
    1.72 +    void writeIRect(const SkIRect& rect);
    1.73 +    void writeRect(const SkRect& rect);
    1.74 +    void writeRegion(const SkRegion& region);
    1.75 +    void writePath(const SkPath& path);
    1.76 +    size_t writeStream(SkStream* stream, size_t length);
    1.77 +    void writeBitmap(const SkBitmap& bitmap);
    1.78 +    void writeTypeface(SkTypeface* typeface);
    1.79 +    void writePaint(const SkPaint& paint) { paint.flatten(*this); }
    1.80 +
    1.81 +    bool writeToStream(SkWStream*);
    1.82 +    void writeToMemory(void* dst) { fWriter.flatten(dst); }
    1.83 +
    1.84 +    SkFactorySet* setFactoryRecorder(SkFactorySet*);
    1.85 +    SkNamedFactorySet* setNamedFactoryRecorder(SkNamedFactorySet*);
    1.86 +
    1.87 +    SkRefCntSet* getTypefaceRecorder() const { return fTFSet; }
    1.88 +    SkRefCntSet* setTypefaceRecorder(SkRefCntSet*);
    1.89 +
    1.90 +    /**
    1.91 +     * Set an SkBitmapHeap to store bitmaps rather than flattening.
    1.92 +     *
    1.93 +     * Incompatible with an EncodeBitmap function. If an EncodeBitmap function is set, setting an
    1.94 +     * SkBitmapHeap will set the function to NULL in release mode and crash in debug.
    1.95 +     */
    1.96 +    void setBitmapHeap(SkBitmapHeap*);
    1.97 +
    1.98 +    /**
    1.99 +     * Provide a function to encode an SkBitmap to an SkData. writeBitmap will attempt to use
   1.100 +     * bitmapEncoder to store the SkBitmap. If the reader does not provide a function to decode, it
   1.101 +     * will not be able to restore SkBitmaps, but will still be able to read the rest of the stream.
   1.102 +     * bitmapEncoder will never be called with a NULL pixelRefOffset.
   1.103 +     *
   1.104 +     * Incompatible with the SkBitmapHeap. If an encoder is set fBitmapHeap will be set to NULL in
   1.105 +     * release and crash in debug.
   1.106 +     */
   1.107 +    void setBitmapEncoder(SkPicture::EncodeBitmap bitmapEncoder);
   1.108 +
   1.109 +private:
   1.110 +    bool isValidating() const { return SkToBool(fFlags & kValidation_Flag); }
   1.111 +
   1.112 +    const uint32_t fFlags;
   1.113 +    SkFactorySet* fFactorySet;
   1.114 +    SkNamedFactorySet* fNamedFactorySet;
   1.115 +    SkWriter32 fWriter;
   1.116 +
   1.117 +    SkBitmapHeap* fBitmapHeap;
   1.118 +    SkRefCntSet* fTFSet;
   1.119 +
   1.120 +    SkPicture::EncodeBitmap fBitmapEncoder;
   1.121 +};
   1.122 +
   1.123 +#endif // SkWriteBuffer_DEFINED

mercurial