gfx/skia/trunk/src/core/SkPicturePlayback.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1
michael@0 2 /*
michael@0 3 * Copyright 2011 Google Inc.
michael@0 4 *
michael@0 5 * Use of this source code is governed by a BSD-style license that can be
michael@0 6 * found in the LICENSE file.
michael@0 7 */
michael@0 8 #ifndef SkPicturePlayback_DEFINED
michael@0 9 #define SkPicturePlayback_DEFINED
michael@0 10
michael@0 11 #include "SkPicture.h"
michael@0 12 #include "SkReader32.h"
michael@0 13
michael@0 14 #include "SkBitmap.h"
michael@0 15 #include "SkData.h"
michael@0 16 #include "SkMatrix.h"
michael@0 17 #include "SkReadBuffer.h"
michael@0 18 #include "SkPaint.h"
michael@0 19 #include "SkPath.h"
michael@0 20 #include "SkPathHeap.h"
michael@0 21 #include "SkRegion.h"
michael@0 22 #include "SkRRect.h"
michael@0 23 #include "SkPictureFlat.h"
michael@0 24
michael@0 25 #ifdef SK_BUILD_FOR_ANDROID
michael@0 26 #include "SkThread.h"
michael@0 27 #endif
michael@0 28
michael@0 29 class SkPictureRecord;
michael@0 30 class SkStream;
michael@0 31 class SkWStream;
michael@0 32 class SkBBoxHierarchy;
michael@0 33 class SkPictureStateTree;
michael@0 34 class SkOffsetTable;
michael@0 35
michael@0 36 struct SkPictInfo {
michael@0 37 enum Flags {
michael@0 38 kCrossProcess_Flag = 1 << 0,
michael@0 39 kScalarIsFloat_Flag = 1 << 1,
michael@0 40 kPtrIs64Bit_Flag = 1 << 2,
michael@0 41 };
michael@0 42
michael@0 43 char fMagic[8];
michael@0 44 uint32_t fVersion;
michael@0 45 uint32_t fWidth;
michael@0 46 uint32_t fHeight;
michael@0 47 uint32_t fFlags;
michael@0 48 };
michael@0 49
michael@0 50 #define SK_PICT_READER_TAG SkSetFourByteTag('r', 'e', 'a', 'd')
michael@0 51 #define SK_PICT_FACTORY_TAG SkSetFourByteTag('f', 'a', 'c', 't')
michael@0 52 #define SK_PICT_TYPEFACE_TAG SkSetFourByteTag('t', 'p', 'f', 'c')
michael@0 53 #define SK_PICT_PICTURE_TAG SkSetFourByteTag('p', 'c', 't', 'r')
michael@0 54
michael@0 55 // This tag specifies the size of the ReadBuffer, needed for the following tags
michael@0 56 #define SK_PICT_BUFFER_SIZE_TAG SkSetFourByteTag('a', 'r', 'a', 'y')
michael@0 57 // these are all inside the ARRAYS tag
michael@0 58 #define SK_PICT_BITMAP_BUFFER_TAG SkSetFourByteTag('b', 't', 'm', 'p')
michael@0 59 #define SK_PICT_PAINT_BUFFER_TAG SkSetFourByteTag('p', 'n', 't', ' ')
michael@0 60 #define SK_PICT_PATH_BUFFER_TAG SkSetFourByteTag('p', 't', 'h', ' ')
michael@0 61
michael@0 62 // Always write this guy last (with no length field afterwards)
michael@0 63 #define SK_PICT_EOF_TAG SkSetFourByteTag('e', 'o', 'f', ' ')
michael@0 64
michael@0 65 /**
michael@0 66 * Container for data that is needed to deep copy a SkPicture. The container
michael@0 67 * enables the data to be generated once and reused for subsequent copies.
michael@0 68 */
michael@0 69 struct SkPictCopyInfo {
michael@0 70 SkPictCopyInfo() : initialized(false), controller(1024) {}
michael@0 71
michael@0 72 bool initialized;
michael@0 73 SkChunkFlatController controller;
michael@0 74 SkTDArray<SkFlatData*> paintData;
michael@0 75 };
michael@0 76
michael@0 77 class SkPicturePlayback {
michael@0 78 public:
michael@0 79 SkPicturePlayback();
michael@0 80 SkPicturePlayback(const SkPicturePlayback& src, SkPictCopyInfo* deepCopyInfo = NULL);
michael@0 81 explicit SkPicturePlayback(const SkPictureRecord& record, bool deepCopy = false);
michael@0 82 static SkPicturePlayback* CreateFromStream(SkStream*, const SkPictInfo&,
michael@0 83 SkPicture::InstallPixelRefProc);
michael@0 84 static SkPicturePlayback* CreateFromBuffer(SkReadBuffer&);
michael@0 85
michael@0 86 virtual ~SkPicturePlayback();
michael@0 87
michael@0 88 void draw(SkCanvas& canvas, SkDrawPictureCallback*);
michael@0 89
michael@0 90 void serialize(SkWStream*, SkPicture::EncodeBitmap) const;
michael@0 91 void flatten(SkWriteBuffer&) const;
michael@0 92
michael@0 93 void dumpSize() const;
michael@0 94
michael@0 95 bool containsBitmaps() const;
michael@0 96
michael@0 97 #ifdef SK_BUILD_FOR_ANDROID
michael@0 98 // Can be called in the middle of playback (the draw() call). WIll abort the
michael@0 99 // drawing and return from draw() after the "current" op code is done
michael@0 100 void abort() { fAbortCurrentPlayback = true; }
michael@0 101 #endif
michael@0 102
michael@0 103 protected:
michael@0 104 bool parseStream(SkStream*, const SkPictInfo&,
michael@0 105 SkPicture::InstallPixelRefProc);
michael@0 106 bool parseBuffer(SkReadBuffer& buffer);
michael@0 107 #ifdef SK_DEVELOPER
michael@0 108 virtual bool preDraw(int opIndex, int type);
michael@0 109 virtual void postDraw(int opIndex);
michael@0 110 #endif
michael@0 111
michael@0 112 void preLoadBitmaps(const SkTDArray<void*>& results);
michael@0 113
michael@0 114 private:
michael@0 115 class TextContainer {
michael@0 116 public:
michael@0 117 size_t length() { return fByteLength; }
michael@0 118 const void* text() { return (const void*) fText; }
michael@0 119 size_t fByteLength;
michael@0 120 const char* fText;
michael@0 121 };
michael@0 122
michael@0 123 const SkBitmap& getBitmap(SkReader32& reader) {
michael@0 124 const int index = reader.readInt();
michael@0 125 if (SkBitmapHeap::INVALID_SLOT == index) {
michael@0 126 #ifdef SK_DEBUG
michael@0 127 SkDebugf("An invalid bitmap was recorded!\n");
michael@0 128 #endif
michael@0 129 return fBadBitmap;
michael@0 130 }
michael@0 131 return (*fBitmaps)[index];
michael@0 132 }
michael@0 133
michael@0 134 void getMatrix(SkReader32& reader, SkMatrix* matrix) {
michael@0 135 reader.readMatrix(matrix);
michael@0 136 }
michael@0 137
michael@0 138 const SkPath& getPath(SkReader32& reader) {
michael@0 139 return (*fPathHeap)[reader.readInt() - 1];
michael@0 140 }
michael@0 141
michael@0 142 SkPicture& getPicture(SkReader32& reader) {
michael@0 143 int index = reader.readInt();
michael@0 144 SkASSERT(index > 0 && index <= fPictureCount);
michael@0 145 return *fPictureRefs[index - 1];
michael@0 146 }
michael@0 147
michael@0 148 const SkPaint* getPaint(SkReader32& reader) {
michael@0 149 int index = reader.readInt();
michael@0 150 if (index == 0) {
michael@0 151 return NULL;
michael@0 152 }
michael@0 153 return &(*fPaints)[index - 1];
michael@0 154 }
michael@0 155
michael@0 156 const SkRect* getRectPtr(SkReader32& reader) {
michael@0 157 if (reader.readBool()) {
michael@0 158 return &reader.skipT<SkRect>();
michael@0 159 } else {
michael@0 160 return NULL;
michael@0 161 }
michael@0 162 }
michael@0 163
michael@0 164 const SkIRect* getIRectPtr(SkReader32& reader) {
michael@0 165 if (reader.readBool()) {
michael@0 166 return &reader.skipT<SkIRect>();
michael@0 167 } else {
michael@0 168 return NULL;
michael@0 169 }
michael@0 170 }
michael@0 171
michael@0 172 void getRegion(SkReader32& reader, SkRegion* region) {
michael@0 173 reader.readRegion(region);
michael@0 174 }
michael@0 175
michael@0 176 void getText(SkReader32& reader, TextContainer* text) {
michael@0 177 size_t length = text->fByteLength = reader.readInt();
michael@0 178 text->fText = (const char*)reader.skip(length);
michael@0 179 }
michael@0 180
michael@0 181 void init();
michael@0 182
michael@0 183 #ifdef SK_DEBUG_SIZE
michael@0 184 public:
michael@0 185 int size(size_t* sizePtr);
michael@0 186 int bitmaps(size_t* size);
michael@0 187 int paints(size_t* size);
michael@0 188 int paths(size_t* size);
michael@0 189 #endif
michael@0 190
michael@0 191 #ifdef SK_DEBUG_DUMP
michael@0 192 private:
michael@0 193 void dumpBitmap(const SkBitmap& bitmap) const;
michael@0 194 void dumpMatrix(const SkMatrix& matrix) const;
michael@0 195 void dumpPaint(const SkPaint& paint) const;
michael@0 196 void dumpPath(const SkPath& path) const;
michael@0 197 void dumpPicture(const SkPicture& picture) const;
michael@0 198 void dumpRegion(const SkRegion& region) const;
michael@0 199 int dumpDrawType(char* bufferPtr, char* buffer, DrawType drawType);
michael@0 200 int dumpInt(char* bufferPtr, char* buffer, char* name);
michael@0 201 int dumpRect(char* bufferPtr, char* buffer, char* name);
michael@0 202 int dumpPoint(char* bufferPtr, char* buffer, char* name);
michael@0 203 void dumpPointArray(char** bufferPtrPtr, char* buffer, int count);
michael@0 204 int dumpPtr(char* bufferPtr, char* buffer, char* name, void* ptr);
michael@0 205 int dumpRectPtr(char* bufferPtr, char* buffer, char* name);
michael@0 206 int dumpScalar(char* bufferPtr, char* buffer, char* name);
michael@0 207 void dumpText(char** bufferPtrPtr, char* buffer);
michael@0 208 void dumpStream();
michael@0 209
michael@0 210 public:
michael@0 211 void dump() const;
michael@0 212 #endif
michael@0 213
michael@0 214 private: // these help us with reading/writing
michael@0 215 bool parseStreamTag(SkStream*, const SkPictInfo&, uint32_t tag, size_t size,
michael@0 216 SkPicture::InstallPixelRefProc);
michael@0 217 bool parseBufferTag(SkReadBuffer&, uint32_t tag, size_t size);
michael@0 218 void flattenToBuffer(SkWriteBuffer&) const;
michael@0 219
michael@0 220 private:
michael@0 221 // Only used by getBitmap() if the passed in index is SkBitmapHeap::INVALID_SLOT. This empty
michael@0 222 // bitmap allows playback to draw nothing and move on.
michael@0 223 SkBitmap fBadBitmap;
michael@0 224
michael@0 225 SkAutoTUnref<SkBitmapHeap> fBitmapHeap;
michael@0 226 SkAutoTUnref<SkPathHeap> fPathHeap;
michael@0 227
michael@0 228 SkTRefArray<SkBitmap>* fBitmaps;
michael@0 229 SkTRefArray<SkPaint>* fPaints;
michael@0 230
michael@0 231 SkData* fOpData; // opcodes and parameters
michael@0 232 SkAutoTUnref<SkOffsetTable> fBitmapUseOffsets;
michael@0 233
michael@0 234 SkPicture** fPictureRefs;
michael@0 235 int fPictureCount;
michael@0 236
michael@0 237 SkBBoxHierarchy* fBoundingHierarchy;
michael@0 238 SkPictureStateTree* fStateTree;
michael@0 239
michael@0 240 SkTypefacePlayback fTFPlayback;
michael@0 241 SkFactoryPlayback* fFactoryPlayback;
michael@0 242 #ifdef SK_BUILD_FOR_ANDROID
michael@0 243 SkMutex fDrawMutex;
michael@0 244 bool fAbortCurrentPlayback;
michael@0 245 #endif
michael@0 246 };
michael@0 247
michael@0 248 #endif

mercurial