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

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
« no previous file with comments | « no previous file | tests/TileGridTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 this->tile(x, y).push(data); 59 this->tile(x, y).push(data);
60 } 60 }
61 } 61 }
62 fInsertionCount++; 62 fInsertionCount++;
63 } 63 }
64 64
65 void SkTileGrid::search(const SkIRect& query, SkTDArray<void*>* results) { 65 void SkTileGrid::search(const SkIRect& query, SkTDArray<void*>* results) {
66 SkIRect adjustedQuery = query; 66 SkIRect adjustedQuery = query;
67 adjustedQuery.inset(fInfo.fMargin.width(), fInfo.fMargin.height()); 67 adjustedQuery.inset(fInfo.fMargin.width(), fInfo.fMargin.height());
68 adjustedQuery.offset(fInfo.fOffset); 68 adjustedQuery.offset(fInfo.fOffset);
69 adjustedQuery.sort(); // in case the inset inverted the rectangle
reed1 2013/04/09 15:56:16 If we might invert, then (I presume) we are making
69 // Convert the query rectangle from device coordinates to tile coordinates 70 // 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 71 // 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 ") 72 // region includes the query rectangle. (using truncating division to "floor ")
72 int tileStartX = adjustedQuery.left() / fInfo.fTileInterval.width(); 73 int tileStartX = adjustedQuery.left() / fInfo.fTileInterval.width();
73 int tileEndX = (adjustedQuery.right() + fInfo.fTileInterval.width() - 1) / 74 int tileEndX = (adjustedQuery.right() + fInfo.fTileInterval.width() - 1) /
74 fInfo.fTileInterval.width(); 75 fInfo.fTileInterval.width();
75 int tileStartY = adjustedQuery.top() / fInfo.fTileInterval.height(); 76 int tileStartY = adjustedQuery.top() / fInfo.fTileInterval.height();
76 int tileEndY = (adjustedQuery.bottom() + fInfo.fTileInterval.height() - 1) / 77 int tileEndY = (adjustedQuery.bottom() + fInfo.fTileInterval.height() - 1) /
77 fInfo.fTileInterval.height(); 78 fInfo.fTileInterval.height();
78 if (tileStartX >= fXTileCount || tileStartY >= fYTileCount || tileEndX <= 0 || tileEndY <= 0) { 79
79 return; // query does not intersect the grid 80 tileStartX = SkPin32(tileStartX, 0, fXTileCount - 1);
80 } 81 tileEndX = SkPin32(tileEndX, 1, fXTileCount);
81 // clamp to grid 82 tileStartY = SkPin32(tileStartY, 0, fYTileCount - 1);
82 if (tileStartX < 0) tileStartX = 0; 83 tileEndY = SkPin32(tileEndY, 1, fYTileCount);
83 if (tileStartY < 0) tileStartY = 0;
84 if (tileEndX > fXTileCount) tileEndX = fXTileCount;
85 if (tileEndY > fYTileCount) tileEndY = fYTileCount;
86 84
87 int queryTileCount = (tileEndX - tileStartX) * (tileEndY - tileStartY); 85 int queryTileCount = (tileEndX - tileStartX) * (tileEndY - tileStartY);
86 SkASSERT(queryTileCount);
88 if (queryTileCount == 1) { 87 if (queryTileCount == 1) {
89 *results = this->tile(tileStartX, tileStartY); 88 *results = this->tile(tileStartX, tileStartY);
90 } else { 89 } else {
91 results->reset(); 90 results->reset();
92 SkTDArray<int> curPositions; 91 SkTDArray<int> curPositions;
93 curPositions.setCount(queryTileCount); 92 curPositions.setCount(queryTileCount);
94 // Note: Reserving space for 1024 tile pointers on the stack. If the 93 // Note: Reserving space for 1024 tile pointers on the stack. If the
95 // malloc becomes a bottleneck, we may consider increasing that number. 94 // malloc becomes a bottleneck, we may consider increasing that number.
96 // Typical large web page, say 2k x 16k, would require 512 tiles of 95 // Typical large web page, say 2k x 16k, would require 512 tiles of
97 // size 256 x 256 pixels. 96 // size 256 x 256 pixels.
(...skipping 25 matching lines...) Expand all
123 } 122 }
124 123
125 void SkTileGrid::rewindInserts() { 124 void SkTileGrid::rewindInserts() {
126 SkASSERT(fClient); 125 SkASSERT(fClient);
127 for (int i = 0; i < fTileCount; ++i) { 126 for (int i = 0; i < fTileCount; ++i) {
128 while (!fTileData[i].isEmpty() && fClient->shouldRewind(fTileData[i].top ())) { 127 while (!fTileData[i].isEmpty() && fClient->shouldRewind(fTileData[i].top ())) {
129 fTileData[i].pop(); 128 fTileData[i].pop();
130 } 129 }
131 } 130 }
132 } 131 }
OLDNEW
« no previous file with comments | « no previous file | tests/TileGridTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698