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

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

Issue 639823005: Use BBH reserve hook to preallocate space for tiles. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: assert -> early check Created 6 years, 2 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') | no next file » | 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 , fInvWidth( SkScalarInvert(info.fTileInterval.width())) 13 , fInvWidth( SkScalarInvert(info.fTileInterval.width()))
14 , fInvHeight(SkScalarInvert(info.fTileInterval.height())) 14 , fInvHeight(SkScalarInvert(info.fTileInterval.height()))
15 , fMarginWidth (info.fMargin.fWidth +1) // Margin is offset by 1 as a provi sion for AA and 15 , fMarginWidth (info.fMargin.fWidth +1) // Margin is offset by 1 as a provi sion for AA and
16 , fMarginHeight(info.fMargin.fHeight+1) // to cancel the outset applied by getClipDeviceBounds. 16 , fMarginHeight(info.fMargin.fHeight+1) // to cancel the outset applied by getClipDeviceBounds.
17 , fOffset(SkPoint::Make(info.fOffset.fX, info.fOffset.fY)) 17 , fOffset(SkPoint::Make(info.fOffset.fX, info.fOffset.fY))
18 , fGridBounds(SkRect::MakeWH(xTiles * info.fTileInterval.width(), 18 , fGridBounds(SkRect::MakeWH(xTiles * info.fTileInterval.width(),
19 yTiles * info.fTileInterval.height())) 19 yTiles * info.fTileInterval.height()))
20 , fTiles(SkNEW_ARRAY(SkTDArray<unsigned>, xTiles * yTiles)) {} 20 , fTiles(SkNEW_ARRAY(SkTDArray<unsigned>, xTiles * yTiles)) {}
21 21
22 SkTileGrid::~SkTileGrid() { 22 SkTileGrid::~SkTileGrid() {
23 SkDELETE_ARRAY(fTiles); 23 SkDELETE_ARRAY(fTiles);
24 } 24 }
25 25
26 void SkTileGrid::reserve(unsigned opCount) {
27 if (fXTiles * fYTiles == 0) {
28 return; // A tileless tile grid is nonsensical, but happens in at least cc_unittests.
29 }
30
31 // If we assume every op we're about to try to insert() falls within our gri d bounds,
32 // then every op has to hit at least one tile. In fact, a quick scan over o ur small
33 // SKP set shows that in the average SKP, each op hits two 256x256 tiles.
34
35 // If we take those observations and further assume the ops are distributed evenly
36 // across the picture, we get this guess for number of ops per tile:
37 const int opsPerTileGuess = (2 * opCount) / (fXTiles * fYTiles);
38
39 for (SkTDArray<unsigned>* tile = fTiles; tile != fTiles + (fXTiles * fYTiles ); tile++) {
40 tile->setReserve(opsPerTileGuess);
41 }
42
43 // In practice, this heuristic means we'll temporarily allocate about 30% mo re bytes
44 // than if we made no setReserve() calls, but time spent in insert() drops b y about 50%.
45 }
46
47 void SkTileGrid::flushDeferredInserts() {
48 for (SkTDArray<unsigned>* tile = fTiles; tile != fTiles + (fXTiles * fYTiles ); tile++) {
49 tile->shrinkToFit();
50 }
51 }
52
26 // Adjustments to user-provided bounds common to both insert() and search(). 53 // Adjustments to user-provided bounds common to both insert() and search().
27 // Call this after making insert- or search- specific adjustments. 54 // Call this after making insert- or search- specific adjustments.
28 void SkTileGrid::commonAdjust(SkRect* rect) const { 55 void SkTileGrid::commonAdjust(SkRect* rect) const {
29 // Apply our offset. 56 // Apply our offset.
30 rect->offset(fOffset); 57 rect->offset(fOffset);
31 58
32 // Scrunch the bounds in just a little to make the right and bottom edges 59 // Scrunch the bounds in just a little to make the right and bottom edges
33 // exclusive. We want bounds of exactly one tile to hit exactly one tile. 60 // exclusive. We want bounds of exactly one tile to hit exactly one tile.
34 rect->fRight -= SK_ScalarNearlyZero; 61 rect->fRight -= SK_ScalarNearlyZero;
35 rect->fBottom -= SK_ScalarNearlyZero; 62 rect->fBottom -= SK_ScalarNearlyZero;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 // We did find an earliest op. Output it, and step forward every tile th at contains it. 158 // We did find an earliest op. Output it, and step forward every tile th at contains it.
132 results->push(earliest); 159 results->push(earliest);
133 for (int i = 0; i < starts.count(); i++) { 160 for (int i = 0; i < starts.count(); i++) {
134 if (starts[i] < ends[i] && *starts[i] == earliest) { 161 if (starts[i] < ends[i] && *starts[i] == earliest) {
135 starts[i]++; 162 starts[i]++;
136 } 163 }
137 } 164 }
138 } 165 }
139 } 166 }
140 167
OLDNEW
« no previous file with comments | « src/core/SkTileGrid.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698