gfx/skia/trunk/src/core/SkTileGrid.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 SkTileGrid_DEFINED
michael@0 10 #define SkTileGrid_DEFINED
michael@0 11
michael@0 12 #include "SkBBoxHierarchy.h"
michael@0 13 #include "SkPictureStateTree.h"
michael@0 14 #include "SkTileGridPicture.h" // for TileGridInfo
michael@0 15
michael@0 16 /**
michael@0 17 * Subclass of SkBBoxHierarchy that stores elements in buckets that correspond
michael@0 18 * to tile regions, disposed in a regular grid. This is useful when the tile
michael@0 19 * structure that will be use in search() calls is known prior to insertion.
michael@0 20 * Calls to search will return in constant time.
michael@0 21 *
michael@0 22 * Note: Current implementation of search() only supports looking-up regions
michael@0 23 * that are an exact match to a single tile. Implementation could be augmented
michael@0 24 * to support arbitrary rectangles, but performance would be sub-optimal.
michael@0 25 */
michael@0 26 class SkTileGrid : public SkBBoxHierarchy {
michael@0 27 public:
michael@0 28 enum {
michael@0 29 // Number of tiles for which data is allocated on the stack in
michael@0 30 // SkTileGrid::search. If malloc becomes a bottleneck, we may consider
michael@0 31 // increasing this number. Typical large web page, say 2k x 16k, would
michael@0 32 // require 512 tiles of size 256 x 256 pixels.
michael@0 33 kStackAllocationTileCount = 1024
michael@0 34 };
michael@0 35
michael@0 36 typedef void* (*SkTileGridNextDatumFunctionPtr)(SkTDArray<void*>** tileData, SkAutoSTArray<kStackAllocationTileCount, int>& tileIndices);
michael@0 37
michael@0 38 SkTileGrid(int xTileCount, int yTileCount, const SkTileGridPicture::TileGridInfo& info,
michael@0 39 SkTileGridNextDatumFunctionPtr nextDatumFunction);
michael@0 40
michael@0 41 virtual ~SkTileGrid();
michael@0 42
michael@0 43 /**
michael@0 44 * Insert a data pointer and corresponding bounding box
michael@0 45 * @param data The data pointer, may be NULL
michael@0 46 * @param bounds The bounding box, should not be empty
michael@0 47 * @param defer Ignored, TileArray does not defer insertions
michael@0 48 */
michael@0 49 virtual void insert(void* data, const SkIRect& bounds, bool) SK_OVERRIDE;
michael@0 50
michael@0 51 virtual void flushDeferredInserts() SK_OVERRIDE {};
michael@0 52
michael@0 53 /**
michael@0 54 * Populate 'results' with data pointers corresponding to bounding boxes that intersect 'query'
michael@0 55 * The query argument is expected to be an exact match to a tile of the grid
michael@0 56 */
michael@0 57 virtual void search(const SkIRect& query, SkTDArray<void*>* results) SK_OVERRIDE;
michael@0 58
michael@0 59 virtual void clear() SK_OVERRIDE;
michael@0 60
michael@0 61 /**
michael@0 62 * Gets the number of insertions
michael@0 63 */
michael@0 64 virtual int getCount() const SK_OVERRIDE;
michael@0 65
michael@0 66 virtual int getDepth() const SK_OVERRIDE { return -1; }
michael@0 67
michael@0 68 virtual void rewindInserts() SK_OVERRIDE;
michael@0 69
michael@0 70 // Used by search() and in SkTileGridHelper implementations
michael@0 71 enum {
michael@0 72 kTileFinished = -1,
michael@0 73 };
michael@0 74
michael@0 75 int tileCount(int x, int y); // For testing only.
michael@0 76
michael@0 77 private:
michael@0 78 SkTDArray<void*>& tile(int x, int y);
michael@0 79
michael@0 80 int fXTileCount, fYTileCount, fTileCount;
michael@0 81 SkTileGridPicture::TileGridInfo fInfo;
michael@0 82 SkTDArray<void*>* fTileData;
michael@0 83 int fInsertionCount;
michael@0 84 SkIRect fGridBounds;
michael@0 85 SkTileGridNextDatumFunctionPtr fNextDatumFunction;
michael@0 86
michael@0 87 typedef SkBBoxHierarchy INHERITED;
michael@0 88 };
michael@0 89
michael@0 90 /**
michael@0 91 * Generic implementation for SkTileGridNextDatumFunctionPtr. user code may instantiate
michael@0 92 * this template to get a valid SkTileGridNextDatumFunction implementation
michael@0 93 *
michael@0 94 * Returns the next element of tileData[i][tileIndices[i]] for all i and advances
michael@0 95 * tileIndices[] past them. The order in which data are returned by successive
michael@0 96 * calls to this method must reflect the order in which the were originally
michael@0 97 * recorded into the tile grid.
michael@0 98 *
michael@0 99 * \param tileData array of pointers to arrays of tile data
michael@0 100 * \param tileIndices per-tile data indices, indices are incremented for tiles that contain
michael@0 101 * the next datum.
michael@0 102 * \tparam T a type to which it is safe to cast a datum and that has an operator <
michael@0 103 * such that 'a < b' is true if 'a' was inserted into the tile grid before 'b'.
michael@0 104 */
michael@0 105 template <typename T>
michael@0 106 void* SkTileGridNextDatum(SkTDArray<void*>** tileData, SkAutoSTArray<SkTileGrid::kStackAllocationTileCount, int>& tileIndices) {
michael@0 107 T* minVal = NULL;
michael@0 108 int tileCount = tileIndices.count();
michael@0 109 int minIndex = tileCount;
michael@0 110 int maxIndex = 0;
michael@0 111 // Find the next Datum; track where it's found so we reduce the size of the second loop.
michael@0 112 for (int tile = 0; tile < tileCount; ++tile) {
michael@0 113 int pos = tileIndices[tile];
michael@0 114 if (pos != SkTileGrid::kTileFinished) {
michael@0 115 T* candidate = (T*)(*tileData[tile])[pos];
michael@0 116 if (NULL == minVal || (*candidate) < (*minVal)) {
michael@0 117 minVal = candidate;
michael@0 118 minIndex = tile;
michael@0 119 maxIndex = tile;
michael@0 120 } else if (!((*minVal) < (*candidate))) {
michael@0 121 // We don't require operator==; if !(candidate<minVal) && !(minVal<candidate),
michael@0 122 // candidate==minVal and we have to add this tile to the range searched.
michael@0 123 maxIndex = tile;
michael@0 124 }
michael@0 125 }
michael@0 126 }
michael@0 127 // Increment indices past the next datum
michael@0 128 if (minVal != NULL) {
michael@0 129 for (int tile = minIndex; tile <= maxIndex; ++tile) {
michael@0 130 int pos = tileIndices[tile];
michael@0 131 if (pos != SkTileGrid::kTileFinished && (*tileData[tile])[pos] == minVal) {
michael@0 132 if (++(tileIndices[tile]) >= tileData[tile]->count()) {
michael@0 133 tileIndices[tile] = SkTileGrid::kTileFinished;
michael@0 134 }
michael@0 135 }
michael@0 136 }
michael@0 137 return minVal;
michael@0 138 }
michael@0 139 return NULL;
michael@0 140 }
michael@0 141
michael@0 142 #endif

mercurial