gfx/skia/trunk/src/core/SkPictureStateTree.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 2012 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
michael@0 9 #ifndef SkPictureStateTree_DEFINED
michael@0 10 #define SkPictureStateTree_DEFINED
michael@0 11
michael@0 12 #include "SkTDArray.h"
michael@0 13 #include "SkChunkAlloc.h"
michael@0 14 #include "SkDeque.h"
michael@0 15 #include "SkMatrix.h"
michael@0 16 #include "SkRefCnt.h"
michael@0 17
michael@0 18 class SkCanvas;
michael@0 19
michael@0 20 /**
michael@0 21 * Provides an interface that, given a sequence of draws into an SkPicture with corresponding
michael@0 22 * offsets, allows for playback of an arbitrary subset of the draws (note that Z-order is only
michael@0 23 * guaranteed if the draws are explicitly sorted).
michael@0 24 */
michael@0 25 class SkPictureStateTree : public SkRefCnt {
michael@0 26 private:
michael@0 27 struct Node;
michael@0 28 public:
michael@0 29 SK_DECLARE_INST_COUNT(SkPictureStateTree)
michael@0 30
michael@0 31 /**
michael@0 32 * A draw call, stores offset into command buffer, a pointer to the matrix, and a pointer to
michael@0 33 * the node in the tree that corresponds to its clip/layer state
michael@0 34 */
michael@0 35 struct Draw {
michael@0 36 SkMatrix* fMatrix;
michael@0 37 Node* fNode;
michael@0 38 uint32_t fOffset;
michael@0 39 bool operator<(const Draw& other) const { return fOffset < other.fOffset; }
michael@0 40 };
michael@0 41
michael@0 42 class Iterator;
michael@0 43
michael@0 44 SkPictureStateTree();
michael@0 45 ~SkPictureStateTree();
michael@0 46
michael@0 47 /**
michael@0 48 * Creates and returns a struct representing a draw at the given offset.
michael@0 49 */
michael@0 50 Draw* appendDraw(size_t offset);
michael@0 51
michael@0 52 /**
michael@0 53 * Given a list of draws, and a canvas, returns an iterator that produces the correct sequence
michael@0 54 * of offsets into the command buffer to carry out those calls with correct matrix/clip state.
michael@0 55 * This handles saves/restores, and does all necessary matrix setup.
michael@0 56 */
michael@0 57 Iterator getIterator(const SkTDArray<void*>& draws, SkCanvas* canvas);
michael@0 58
michael@0 59 void appendSave();
michael@0 60 void appendSaveLayer(size_t offset);
michael@0 61 void appendRestore();
michael@0 62 void appendTransform(const SkMatrix& trans);
michael@0 63 void appendClip(size_t offset);
michael@0 64
michael@0 65 /**
michael@0 66 * Call this immediately after an appendRestore call that is associated
michael@0 67 * a save or saveLayer that was removed from the command stream
michael@0 68 * due to a command pattern optimization in SkPicture.
michael@0 69 */
michael@0 70 void saveCollapsed();
michael@0 71
michael@0 72 /**
michael@0 73 * Playback helper
michael@0 74 */
michael@0 75 class Iterator {
michael@0 76 public:
michael@0 77 /** Returns the next offset into the picture stream, or kDrawComplete if complete. */
michael@0 78 uint32_t draw();
michael@0 79 static const uint32_t kDrawComplete = SK_MaxU32;
michael@0 80 Iterator() : fPlaybackMatrix(), fValid(false) { }
michael@0 81 bool isValid() const { return fValid; }
michael@0 82 private:
michael@0 83 Iterator(const SkTDArray<void*>& draws, SkCanvas* canvas, Node* root);
michael@0 84 // The draws this iterator is associated with
michael@0 85 const SkTDArray<void*>* fDraws;
michael@0 86
michael@0 87 // canvas this is playing into (so we can insert saves/restores as necessary)
michael@0 88 SkCanvas* fCanvas;
michael@0 89
michael@0 90 // current state node
michael@0 91 Node* fCurrentNode;
michael@0 92
michael@0 93 // List of nodes whose state we need to apply to reach TargetNode
michael@0 94 SkTDArray<Node*> fNodes;
michael@0 95
michael@0 96 // The matrix of the canvas we're playing back into
michael@0 97 const SkMatrix fPlaybackMatrix;
michael@0 98
michael@0 99 // Cache of current matrix, so we can avoid redundantly setting it
michael@0 100 SkMatrix* fCurrentMatrix;
michael@0 101
michael@0 102 // current position in the array of draws
michael@0 103 int fPlaybackIndex;
michael@0 104 // Whether or not we need to do a save next iteration
michael@0 105 bool fSave;
michael@0 106
michael@0 107 // Whether or not this is a valid iterator (the default public constructor sets this false)
michael@0 108 bool fValid;
michael@0 109
michael@0 110 friend class SkPictureStateTree;
michael@0 111 };
michael@0 112
michael@0 113 private:
michael@0 114
michael@0 115 void appendNode(size_t offset);
michael@0 116
michael@0 117 SkChunkAlloc fAlloc;
michael@0 118 // Needed by saveCollapsed() because nodes do not currently store
michael@0 119 // references to their children. If they did, we could just retrieve the
michael@0 120 // last added child.
michael@0 121 Node* fLastRestoredNode;
michael@0 122
michael@0 123 // The currently active state
michael@0 124 Draw fCurrentState;
michael@0 125 // A stack of states for tracking save/restores
michael@0 126 SkDeque fStateStack;
michael@0 127
michael@0 128 // Represents a notable piece of state that requires an offset into the command buffer,
michael@0 129 // corresponding to a clip/saveLayer/etc call, to apply.
michael@0 130 struct Node {
michael@0 131 Node* fParent;
michael@0 132 uint32_t fOffset;
michael@0 133 uint16_t fLevel;
michael@0 134 uint16_t fFlags;
michael@0 135 SkMatrix* fMatrix;
michael@0 136 enum Flags {
michael@0 137 kSave_Flag = 0x1,
michael@0 138 kSaveLayer_Flag = 0x2
michael@0 139 };
michael@0 140 };
michael@0 141
michael@0 142 Node fRoot;
michael@0 143 SkMatrix fRootMatrix;
michael@0 144
michael@0 145 typedef SkRefCnt INHERITED;
michael@0 146 };
michael@0 147
michael@0 148 #endif

mercurial