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

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

Issue 508873004: Revert of Convert BBH APIs to use SkRect. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 3 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
« no previous file with comments | « src/core/SkTileGrid.h ('k') | src/gpu/SkGpuDevice.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 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkTileGrid.h" 8 #include "SkTileGrid.h"
9 9
10 SkTileGrid::SkTileGrid(int xTiles, int yTiles, const SkTileGridFactory::TileGrid Info& info) 10 SkTileGrid::SkTileGrid(int xTiles, int yTiles, const SkTileGridFactory::TileGrid Info& info)
11 : fXTiles(xTiles) 11 : fXTiles(xTiles)
12 , fYTiles(yTiles) 12 , fYTiles(yTiles)
13 , fInfo(info) 13 , fInfo(info)
14 , fCount(0) 14 , fCount(0)
15 , fTiles(SkNEW_ARRAY(SkTDArray<Entry>, xTiles * yTiles)) { 15 , fTiles(SkNEW_ARRAY(SkTDArray<Entry>, xTiles * yTiles)) {
16 // Margin is offset by 1 as a provision for AA and 16 // Margin is offset by 1 as a provision for AA and
17 // to cancel-out the outset applied by getClipDeviceBounds. 17 // to cancel-out the outset applied by getClipDeviceBounds.
18 fInfo.fMargin.fHeight++; 18 fInfo.fMargin.fHeight++;
19 fInfo.fMargin.fWidth++; 19 fInfo.fMargin.fWidth++;
20 } 20 }
21 21
22 SkTileGrid::~SkTileGrid() { 22 SkTileGrid::~SkTileGrid() {
23 SkDELETE_ARRAY(fTiles); 23 SkDELETE_ARRAY(fTiles);
24 } 24 }
25 25
26 void SkTileGrid::insert(void* data, const SkRect& fbounds, bool) { 26 void SkTileGrid::insert(void* data, const SkIRect& bounds, bool) {
27 SkASSERT(!fbounds.isEmpty()); 27 SkASSERT(!bounds.isEmpty());
28 SkIRect dilatedBounds; 28 SkIRect dilatedBounds = bounds;
29 if (fbounds.isLargest()) { 29
30 // Dilating the largest SkIRect will overflow. Other nearly-largest rec ts may overflow too, 30 // Dilating the largest SkIRect will overflow. Other nearly-largest rects m ay overflow too,
31 // but we don't make active use of them like we do the largest. 31 // but we don't make active use of them like we do the largest.
32 dilatedBounds.setLargest(); 32 if (!bounds.isLargest()) {
33 } else {
34 fbounds.roundOut(&dilatedBounds);
35 dilatedBounds.outset(fInfo.fMargin.width(), fInfo.fMargin.height()); 33 dilatedBounds.outset(fInfo.fMargin.width(), fInfo.fMargin.height());
36 dilatedBounds.offset(fInfo.fOffset); 34 dilatedBounds.offset(fInfo.fOffset);
37 } 35 }
38 36
39 const SkIRect gridBounds = 37 const SkIRect gridBounds =
40 { 0, 0, fInfo.fTileInterval.width() * fXTiles, fInfo.fTileInterval.heigh t() * fYTiles }; 38 { 0, 0, fInfo.fTileInterval.width() * fXTiles, fInfo.fTileInterval.heigh t() * fYTiles };
41 if (!SkIRect::Intersects(dilatedBounds, gridBounds)) { 39 if (!SkIRect::Intersects(dilatedBounds, gridBounds)) {
42 return; 40 return;
43 } 41 }
44 42
(...skipping 17 matching lines...) Expand all
62 static int divide_ceil(int x, int y) { 60 static int divide_ceil(int x, int y) {
63 return (x + y - 1) / y; 61 return (x + y - 1) / y;
64 } 62 }
65 63
66 // Number of tiles for which data is allocated on the stack in 64 // Number of tiles for which data is allocated on the stack in
67 // SkTileGrid::search. If malloc becomes a bottleneck, we may consider 65 // SkTileGrid::search. If malloc becomes a bottleneck, we may consider
68 // increasing this number. Typical large web page, say 2k x 16k, would 66 // increasing this number. Typical large web page, say 2k x 16k, would
69 // require 512 tiles of size 256 x 256 pixels. 67 // require 512 tiles of size 256 x 256 pixels.
70 static const int kStackAllocationTileCount = 1024; 68 static const int kStackAllocationTileCount = 1024;
71 69
72 void SkTileGrid::search(const SkRect& query, SkTDArray<void*>* results) const { 70 void SkTileGrid::search(const SkIRect& query, SkTDArray<void*>* results) const {
73 SkIRect adjusted; 71 SkIRect adjusted = query;
74 query.roundOut(&adjusted);
75 72
76 // The inset is to counteract the outset that was applied in 'insert' 73 // The inset is to counteract the outset that was applied in 'insert'
77 // The outset/inset is to optimize for lookups of size 74 // The outset/inset is to optimize for lookups of size
78 // 'tileInterval + 2 * margin' that are aligned with the tile grid. 75 // 'tileInterval + 2 * margin' that are aligned with the tile grid.
79 adjusted.inset(fInfo.fMargin.width(), fInfo.fMargin.height()); 76 adjusted.inset(fInfo.fMargin.width(), fInfo.fMargin.height());
80 adjusted.offset(fInfo.fOffset); 77 adjusted.offset(fInfo.fOffset);
81 adjusted.sort(); // in case the inset inverted the rectangle 78 adjusted.sort(); // in case the inset inverted the rectangle
82 79
83 // Convert the query rectangle from device coordinates to tile coordinates 80 // Convert the query rectangle from device coordinates to tile coordinates
84 // by rounding outwards to the nearest tile boundary so that the resulting t ile 81 // by rounding outwards to the nearest tile boundary so that the resulting t ile
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 } 157 }
161 158
162 void SkTileGrid::rewindInserts() { 159 void SkTileGrid::rewindInserts() {
163 SkASSERT(fClient); 160 SkASSERT(fClient);
164 for (int i = 0; i < fXTiles * fYTiles; i++) { 161 for (int i = 0; i < fXTiles * fYTiles; i++) {
165 while (!fTiles[i].isEmpty() && fClient->shouldRewind(fTiles[i].top().dat a)) { 162 while (!fTiles[i].isEmpty() && fClient->shouldRewind(fTiles[i].top().dat a)) {
166 fTiles[i].pop(); 163 fTiles[i].pop();
167 } 164 }
168 } 165 }
169 } 166 }
OLDNEW
« no previous file with comments | « src/core/SkTileGrid.h ('k') | src/gpu/SkGpuDevice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698