Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(287)

Side by Side Diff: src/core/SkTileGrid.cpp

Issue 13493016: Fixing SkTileGrid to clamp rather than clip content and querries that are outside the bounds of the… (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2012 Google Inc. 3 * Copyright 2012 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "SkTileGrid.h" 9 #include "SkTileGrid.h"
10 10
(...skipping 21 matching lines...) Expand all
32 32
33 SkTDArray<void *>& SkTileGrid::tile(int x, int y) { 33 SkTDArray<void *>& SkTileGrid::tile(int x, int y) {
34 return fTileData[y * fXTileCount + x]; 34 return fTileData[y * fXTileCount + x];
35 } 35 }
36 36
37 void SkTileGrid::insert(void* data, const SkIRect& bounds, bool) { 37 void SkTileGrid::insert(void* data, const SkIRect& bounds, bool) {
38 SkASSERT(!bounds.isEmpty()); 38 SkASSERT(!bounds.isEmpty());
39 SkIRect dilatedBounds = bounds; 39 SkIRect dilatedBounds = bounds;
40 dilatedBounds.outset(fInfo.fMargin.width(), fInfo.fMargin.height()); 40 dilatedBounds.outset(fInfo.fMargin.width(), fInfo.fMargin.height());
41 dilatedBounds.offset(fInfo.fOffset); 41 dilatedBounds.offset(fInfo.fOffset);
42 if (!SkIRect::Intersects(dilatedBounds, fGridBounds)) {
Tom Hudson 2013/04/09 10:10:50 Either this code was erroneous, or the new version
43 return;
44 }
45 42
46 // Note: SkIRects are non-inclusive of the right() column and bottom() row, 43 // Note: SkIRects are non-inclusive of the right() column and bottom() row,
47 // hence the "-1"s in the computations of maxTileX and maxTileY. 44 // hence the "-1"s in the computations of maxTileX and maxTileY.
48 int minTileX = SkMax32(SkMin32(dilatedBounds.left() / fInfo.fTileInterval.wi dth(), 45 int minTileX = SkMax32(SkMin32(dilatedBounds.left() / fInfo.fTileInterval.wi dth(),
49 fXTileCount - 1), 0); 46 fXTileCount - 1), 0);
50 int maxTileX = SkMax32(SkMin32((dilatedBounds.right() - 1) / fInfo.fTileInte rval.width(), 47 int maxTileX = SkMax32(SkMin32((dilatedBounds.right() - 1) / fInfo.fTileInte rval.width(),
51 fXTileCount - 1), 0); 48 fXTileCount - 1), 0);
52 int minTileY = SkMax32(SkMin32(dilatedBounds.top() / fInfo.fTileInterval.hei ght(), 49 int minTileY = SkMax32(SkMin32(dilatedBounds.top() / fInfo.fTileInterval.hei ght(),
53 fYTileCount -1), 0); 50 fYTileCount -1), 0);
54 int maxTileY = SkMax32(SkMin32((dilatedBounds.bottom() -1) / fInfo.fTileInte rval.height(), 51 int maxTileY = SkMax32(SkMin32((dilatedBounds.bottom() -1) / fInfo.fTileInte rval.height(),
(...skipping 13 matching lines...) Expand all
68 adjustedQuery.offset(fInfo.fOffset); 65 adjustedQuery.offset(fInfo.fOffset);
69 // Convert the query rectangle from device coordinates to tile coordinates 66 // Convert the query rectangle from device coordinates to tile coordinates
70 // by rounding outwards to the nearest tile boundary so that the resulting t ile 67 // by rounding outwards to the nearest tile boundary so that the resulting t ile
71 // region includes the query rectangle. (using truncating division to "floor ") 68 // region includes the query rectangle. (using truncating division to "floor ")
72 int tileStartX = adjustedQuery.left() / fInfo.fTileInterval.width(); 69 int tileStartX = adjustedQuery.left() / fInfo.fTileInterval.width();
73 int tileEndX = (adjustedQuery.right() + fInfo.fTileInterval.width() - 1) / 70 int tileEndX = (adjustedQuery.right() + fInfo.fTileInterval.width() - 1) /
74 fInfo.fTileInterval.width(); 71 fInfo.fTileInterval.width();
75 int tileStartY = adjustedQuery.top() / fInfo.fTileInterval.height(); 72 int tileStartY = adjustedQuery.top() / fInfo.fTileInterval.height();
76 int tileEndY = (adjustedQuery.bottom() + fInfo.fTileInterval.height() - 1) / 73 int tileEndY = (adjustedQuery.bottom() + fInfo.fTileInterval.height() - 1) /
77 fInfo.fTileInterval.height(); 74 fInfo.fTileInterval.height();
78 if (tileStartX >= fXTileCount || tileStartY >= fYTileCount || tileEndX <= 0 || tileEndY <= 0) { 75
79 return; // query does not intersect the grid 76 tileStartX = SkClampMinMax(tileStartX, 0, fXTileCount - 1);
80 } 77 tileEndX = SkClampMinMax(tileEndX, 1, fXTileCount);
81 // clamp to grid 78 tileStartY = SkClampMinMax(tileStartY, 0, fYTileCount - 1);
82 if (tileStartX < 0) tileStartX = 0; 79 tileEndY = SkClampMinMax(tileEndY, 1, fYTileCount);
83 if (tileStartY < 0) tileStartY = 0;
84 if (tileEndX > fXTileCount) tileEndX = fXTileCount;
85 if (tileEndY > fYTileCount) tileEndY = fYTileCount;
86 80
87 int queryTileCount = (tileEndX - tileStartX) * (tileEndY - tileStartY); 81 int queryTileCount = (tileEndX - tileStartX) * (tileEndY - tileStartY);
82 SkASSERT(queryTileCount);
88 if (queryTileCount == 1) { 83 if (queryTileCount == 1) {
89 *results = this->tile(tileStartX, tileStartY); 84 *results = this->tile(tileStartX, tileStartY);
90 } else { 85 } else {
91 results->reset(); 86 results->reset();
92 SkTDArray<int> curPositions; 87 SkTDArray<int> curPositions;
93 curPositions.setCount(queryTileCount); 88 curPositions.setCount(queryTileCount);
94 // Note: Reserving space for 1024 tile pointers on the stack. If the 89 // Note: Reserving space for 1024 tile pointers on the stack. If the
95 // malloc becomes a bottleneck, we may consider increasing that number. 90 // malloc becomes a bottleneck, we may consider increasing that number.
96 // Typical large web page, say 2k x 16k, would require 512 tiles of 91 // Typical large web page, say 2k x 16k, would require 512 tiles of
97 // size 256 x 256 pixels. 92 // size 256 x 256 pixels.
(...skipping 25 matching lines...) Expand all
123 } 118 }
124 119
125 void SkTileGrid::rewindInserts() { 120 void SkTileGrid::rewindInserts() {
126 SkASSERT(fClient); 121 SkASSERT(fClient);
127 for (int i = 0; i < fTileCount; ++i) { 122 for (int i = 0; i < fTileCount; ++i) {
128 while (!fTileData[i].isEmpty() && fClient->shouldRewind(fTileData[i].top ())) { 123 while (!fTileData[i].isEmpty() && fClient->shouldRewind(fTileData[i].top ())) {
129 fTileData[i].pop(); 124 fTileData[i].pop();
130 } 125 }
131 } 126 }
132 } 127 }
OLDNEW
« include/core/SkMath.h ('K') | « include/core/SkMath.h ('k') | tests/TileGridTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698