OLD | NEW |
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 "picture_utils.h" | 8 #include "picture_utils.h" |
9 #include "CopyTilesRenderer.h" | 9 #include "CopyTilesRenderer.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
11 #include "SkDevice.h" | 11 #include "SkDevice.h" |
12 #include "SkImageEncoder.h" | 12 #include "SkImageEncoder.h" |
| 13 #include "SkMultiPictureDraw.h" |
13 #include "SkPicture.h" | 14 #include "SkPicture.h" |
14 #include "SkPixelRef.h" | 15 #include "SkPixelRef.h" |
15 #include "SkRect.h" | 16 #include "SkRect.h" |
16 #include "SkString.h" | 17 #include "SkString.h" |
17 | 18 |
18 namespace sk_tools { | 19 namespace sk_tools { |
19 #if SK_SUPPORT_GPU | 20 #if SK_SUPPORT_GPU |
20 CopyTilesRenderer::CopyTilesRenderer(const GrContext::Options& opts, int x,
int y) | 21 CopyTilesRenderer::CopyTilesRenderer(const GrContext::Options& opts, int x,
int y) |
21 : INHERITED(opts) | 22 : INHERITED(opts) |
22 , fXTilesPerLargeTile(x) | 23 , fXTilesPerLargeTile(x) |
23 , fYTilesPerLargeTile(y) { } | 24 , fYTilesPerLargeTile(y) { } |
24 #else | 25 #else |
25 CopyTilesRenderer::CopyTilesRenderer(int x, int y) | 26 CopyTilesRenderer::CopyTilesRenderer(int x, int y) |
26 : fXTilesPerLargeTile(x) | 27 : fXTilesPerLargeTile(x) |
27 , fYTilesPerLargeTile(y) { } | 28 , fYTilesPerLargeTile(y) { } |
28 #endif | 29 #endif |
29 void CopyTilesRenderer::init(const SkPicture* pict, const SkString* writePat
h, | 30 void CopyTilesRenderer::init(const SkPicture* pict, const SkString* writePat
h, |
30 const SkString* mismatchPath, const SkString* i
nputFilename, | 31 const SkString* mismatchPath, const SkString* i
nputFilename, |
31 bool useChecksumBasedFilenames) { | 32 bool useChecksumBasedFilenames, bool useMultiPi
ctureDraw) { |
32 // Do not call INHERITED::init(), which would create a (potentially larg
e) canvas which is | 33 // Do not call INHERITED::init(), which would create a (potentially larg
e) canvas which is |
33 // not used by bench_pictures. | 34 // not used by bench_pictures. |
34 SkASSERT(pict != NULL); | 35 SkASSERT(pict != NULL); |
35 // Only work with absolute widths (as opposed to percentages). | 36 // Only work with absolute widths (as opposed to percentages). |
36 SkASSERT(this->getTileWidth() != 0 && this->getTileHeight() != 0); | 37 SkASSERT(this->getTileWidth() != 0 && this->getTileHeight() != 0); |
37 fPicture.reset(pict)->ref(); | 38 fPicture.reset(pict)->ref(); |
38 this->CopyString(&fWritePath, writePath); | 39 this->CopyString(&fWritePath, writePath); |
39 this->CopyString(&fMismatchPath, mismatchPath); | 40 this->CopyString(&fMismatchPath, mismatchPath); |
40 this->CopyString(&fInputFilename, inputFilename); | 41 this->CopyString(&fInputFilename, inputFilename); |
41 fUseChecksumBasedFilenames = useChecksumBasedFilenames; | 42 fUseChecksumBasedFilenames = useChecksumBasedFilenames; |
| 43 fUseMultiPictureDraw = useMultiPictureDraw; |
42 this->buildBBoxHierarchy(); | 44 this->buildBBoxHierarchy(); |
43 // In order to avoid allocating a large canvas (particularly important f
or GPU), create one | 45 // In order to avoid allocating a large canvas (particularly important f
or GPU), create one |
44 // canvas that is a multiple of the tile size, and draw portions of the
picture. | 46 // canvas that is a multiple of the tile size, and draw portions of the
picture. |
45 fLargeTileWidth = fXTilesPerLargeTile * this->getTileWidth(); | 47 fLargeTileWidth = fXTilesPerLargeTile * this->getTileWidth(); |
46 fLargeTileHeight = fYTilesPerLargeTile * this->getTileHeight(); | 48 fLargeTileHeight = fYTilesPerLargeTile * this->getTileHeight(); |
47 fCanvas.reset(this->INHERITED::setupCanvas(fLargeTileWidth, fLargeTileHe
ight)); | 49 fCanvas.reset(this->INHERITED::setupCanvas(fLargeTileWidth, fLargeTileHe
ight)); |
48 } | 50 } |
49 | 51 |
50 bool CopyTilesRenderer::render(SkBitmap** out) { | 52 bool CopyTilesRenderer::render(SkBitmap** out) { |
51 int i = 0; | 53 int i = 0; |
52 bool success = true; | 54 bool success = true; |
53 SkBitmap dst; | 55 SkBitmap dst; |
54 for (int x = 0; x < this->getViewWidth(); x += fLargeTileWidth) { | 56 for (int x = 0; x < this->getViewWidth(); x += fLargeTileWidth) { |
55 for (int y = 0; y < this->getViewHeight(); y += fLargeTileHeight) { | 57 for (int y = 0; y < this->getViewHeight(); y += fLargeTileHeight) { |
56 SkAutoCanvasRestore autoRestore(fCanvas, true); | 58 SkAutoCanvasRestore autoRestore(fCanvas, true); |
57 // Translate so that we draw the correct portion of the picture. | 59 // Translate so that we draw the correct portion of the picture. |
58 // Perform a postTranslate so that the scaleFactor does not inte
rfere with the | 60 // Perform a postTranslate so that the scaleFactor does not inte
rfere with the |
59 // positioning. | 61 // positioning. |
60 SkMatrix mat(fCanvas->getTotalMatrix()); | 62 SkMatrix mat(fCanvas->getTotalMatrix()); |
61 mat.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y)); | 63 mat.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y)); |
62 fCanvas->setMatrix(mat); | 64 fCanvas->setMatrix(mat); |
63 // Draw the picture | 65 // Draw the picture |
64 fCanvas->drawPicture(fPicture); | 66 if (fUseMultiPictureDraw) { |
| 67 SkMultiPictureDraw mpd; |
| 68 |
| 69 mpd.add(fCanvas, fPicture); |
| 70 |
| 71 mpd.draw(); |
| 72 } else { |
| 73 fCanvas->drawPicture(fPicture); |
| 74 } |
65 // Now extract the picture into tiles | 75 // Now extract the picture into tiles |
66 SkBitmap baseBitmap; | 76 SkBitmap baseBitmap; |
67 fCanvas->readPixels(SkIRect::MakeSize(fCanvas->getBaseLayerSize(
)), &baseBitmap); | 77 fCanvas->readPixels(SkIRect::MakeSize(fCanvas->getBaseLayerSize(
)), &baseBitmap); |
68 SkIRect subset; | 78 SkIRect subset; |
69 for (int tileY = 0; tileY < fLargeTileHeight; tileY += this->get
TileHeight()) { | 79 for (int tileY = 0; tileY < fLargeTileHeight; tileY += this->get
TileHeight()) { |
70 for (int tileX = 0; tileX < fLargeTileWidth; tileX += this->
getTileWidth()) { | 80 for (int tileX = 0; tileX < fLargeTileWidth; tileX += this->
getTileWidth()) { |
71 subset.set(tileX, tileY, tileX + this->getTileWidth(), | 81 subset.set(tileX, tileY, tileX + this->getTileWidth(), |
72 tileY + this->getTileHeight()); | 82 tileY + this->getTileHeight()); |
73 SkDEBUGCODE(bool extracted =) | 83 SkDEBUGCODE(bool extracted =) |
74 baseBitmap.extractSubset(&dst, subset); | 84 baseBitmap.extractSubset(&dst, subset); |
(...skipping 24 matching lines...) Expand all Loading... |
99 } | 109 } |
100 } | 110 } |
101 } | 111 } |
102 return success; | 112 return success; |
103 } | 113 } |
104 | 114 |
105 SkString CopyTilesRenderer::getConfigNameInternal() { | 115 SkString CopyTilesRenderer::getConfigNameInternal() { |
106 return SkString("copy_tiles"); | 116 return SkString("copy_tiles"); |
107 } | 117 } |
108 } | 118 } |
OLD | NEW |