gfx/skia/trunk/src/core/SkTileGrid.cpp

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 #include "SkTileGrid.h"
michael@0 10
michael@0 11 SkTileGrid::SkTileGrid(int xTileCount, int yTileCount, const SkTileGridPicture::TileGridInfo& info,
michael@0 12 SkTileGridNextDatumFunctionPtr nextDatumFunction)
michael@0 13 {
michael@0 14 fXTileCount = xTileCount;
michael@0 15 fYTileCount = yTileCount;
michael@0 16 fInfo = info;
michael@0 17 // Margin is offset by 1 as a provision for AA and
michael@0 18 // to cancel-out the outset applied by getClipDeviceBounds.
michael@0 19 fInfo.fMargin.fHeight++;
michael@0 20 fInfo.fMargin.fWidth++;
michael@0 21 fTileCount = fXTileCount * fYTileCount;
michael@0 22 fInsertionCount = 0;
michael@0 23 fGridBounds = SkIRect::MakeXYWH(0, 0, fInfo.fTileInterval.width() * fXTileCount,
michael@0 24 fInfo.fTileInterval.height() * fYTileCount);
michael@0 25 fNextDatumFunction = nextDatumFunction;
michael@0 26 fTileData = SkNEW_ARRAY(SkTDArray<void *>, fTileCount);
michael@0 27 }
michael@0 28
michael@0 29 SkTileGrid::~SkTileGrid() {
michael@0 30 SkDELETE_ARRAY(fTileData);
michael@0 31 }
michael@0 32
michael@0 33 int SkTileGrid::tileCount(int x, int y) {
michael@0 34 return this->tile(x, y).count();
michael@0 35 }
michael@0 36
michael@0 37 SkTDArray<void *>& SkTileGrid::tile(int x, int y) {
michael@0 38 return fTileData[y * fXTileCount + x];
michael@0 39 }
michael@0 40
michael@0 41 void SkTileGrid::insert(void* data, const SkIRect& bounds, bool) {
michael@0 42 SkASSERT(!bounds.isEmpty());
michael@0 43 SkIRect dilatedBounds = bounds;
michael@0 44 dilatedBounds.outset(fInfo.fMargin.width(), fInfo.fMargin.height());
michael@0 45 dilatedBounds.offset(fInfo.fOffset);
michael@0 46 if (!SkIRect::Intersects(dilatedBounds, fGridBounds)) {
michael@0 47 return;
michael@0 48 }
michael@0 49
michael@0 50 // Note: SkIRects are non-inclusive of the right() column and bottom() row,
michael@0 51 // hence the "-1"s in the computations of maxTileX and maxTileY.
michael@0 52 int minTileX = SkMax32(SkMin32(dilatedBounds.left() / fInfo.fTileInterval.width(),
michael@0 53 fXTileCount - 1), 0);
michael@0 54 int maxTileX = SkMax32(SkMin32((dilatedBounds.right() - 1) / fInfo.fTileInterval.width(),
michael@0 55 fXTileCount - 1), 0);
michael@0 56 int minTileY = SkMax32(SkMin32(dilatedBounds.top() / fInfo.fTileInterval.height(),
michael@0 57 fYTileCount -1), 0);
michael@0 58 int maxTileY = SkMax32(SkMin32((dilatedBounds.bottom() -1) / fInfo.fTileInterval.height(),
michael@0 59 fYTileCount -1), 0);
michael@0 60
michael@0 61 for (int x = minTileX; x <= maxTileX; x++) {
michael@0 62 for (int y = minTileY; y <= maxTileY; y++) {
michael@0 63 this->tile(x, y).push(data);
michael@0 64 }
michael@0 65 }
michael@0 66 fInsertionCount++;
michael@0 67 }
michael@0 68
michael@0 69 void SkTileGrid::search(const SkIRect& query, SkTDArray<void*>* results) {
michael@0 70 SkIRect adjustedQuery = query;
michael@0 71 // The inset is to counteract the outset that was applied in 'insert'
michael@0 72 // The outset/inset is to optimize for lookups of size
michael@0 73 // 'tileInterval + 2 * margin' that are aligned with the tile grid.
michael@0 74 adjustedQuery.inset(fInfo.fMargin.width(), fInfo.fMargin.height());
michael@0 75 adjustedQuery.offset(fInfo.fOffset);
michael@0 76 adjustedQuery.sort(); // in case the inset inverted the rectangle
michael@0 77 // Convert the query rectangle from device coordinates to tile coordinates
michael@0 78 // by rounding outwards to the nearest tile boundary so that the resulting tile
michael@0 79 // region includes the query rectangle. (using truncating division to "floor")
michael@0 80 int tileStartX = adjustedQuery.left() / fInfo.fTileInterval.width();
michael@0 81 int tileEndX = (adjustedQuery.right() + fInfo.fTileInterval.width() - 1) /
michael@0 82 fInfo.fTileInterval.width();
michael@0 83 int tileStartY = adjustedQuery.top() / fInfo.fTileInterval.height();
michael@0 84 int tileEndY = (adjustedQuery.bottom() + fInfo.fTileInterval.height() - 1) /
michael@0 85 fInfo.fTileInterval.height();
michael@0 86
michael@0 87 tileStartX = SkPin32(tileStartX, 0, fXTileCount - 1);
michael@0 88 tileEndX = SkPin32(tileEndX, tileStartX+1, fXTileCount);
michael@0 89 tileStartY = SkPin32(tileStartY, 0, fYTileCount - 1);
michael@0 90 tileEndY = SkPin32(tileEndY, tileStartY+1, fYTileCount);
michael@0 91
michael@0 92 int queryTileCount = (tileEndX - tileStartX) * (tileEndY - tileStartY);
michael@0 93 SkASSERT(queryTileCount);
michael@0 94 if (queryTileCount == 1) {
michael@0 95 *results = this->tile(tileStartX, tileStartY);
michael@0 96 } else {
michael@0 97 results->reset();
michael@0 98 SkAutoSTArray<kStackAllocationTileCount, int> curPositions(queryTileCount);
michael@0 99 SkAutoSTArray<kStackAllocationTileCount, SkTDArray<void *>*> storage(queryTileCount);
michael@0 100 SkTDArray<void *>** tileRange = storage.get();
michael@0 101 int tile = 0;
michael@0 102 for (int x = tileStartX; x < tileEndX; ++x) {
michael@0 103 for (int y = tileStartY; y < tileEndY; ++y) {
michael@0 104 tileRange[tile] = &this->tile(x, y);
michael@0 105 curPositions[tile] = tileRange[tile]->count() ? 0 : kTileFinished;
michael@0 106 ++tile;
michael@0 107 }
michael@0 108 }
michael@0 109 void *nextElement;
michael@0 110 while(NULL != (nextElement = fNextDatumFunction(tileRange, curPositions))) {
michael@0 111 results->push(nextElement);
michael@0 112 }
michael@0 113 }
michael@0 114 }
michael@0 115
michael@0 116 void SkTileGrid::clear() {
michael@0 117 for (int i = 0; i < fTileCount; i++) {
michael@0 118 fTileData[i].reset();
michael@0 119 }
michael@0 120 }
michael@0 121
michael@0 122 int SkTileGrid::getCount() const {
michael@0 123 return fInsertionCount;
michael@0 124 }
michael@0 125
michael@0 126 void SkTileGrid::rewindInserts() {
michael@0 127 SkASSERT(fClient);
michael@0 128 for (int i = 0; i < fTileCount; ++i) {
michael@0 129 while (!fTileData[i].isEmpty() && fClient->shouldRewind(fTileData[i].top())) {
michael@0 130 fTileData[i].pop();
michael@0 131 }
michael@0 132 }
michael@0 133 }

mercurial