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 "SkPicture.h" | 13 #include "SkPicture.h" |
14 #include "SkPixelRef.h" | 14 #include "SkPixelRef.h" |
15 #include "SkRect.h" | 15 #include "SkRect.h" |
16 #include "SkString.h" | 16 #include "SkString.h" |
17 | 17 |
18 namespace sk_tools { | 18 namespace sk_tools { |
19 CopyTilesRenderer::CopyTilesRenderer(int x, int y) | 19 CopyTilesRenderer::CopyTilesRenderer(int x, int y) |
20 : fXTilesPerLargeTile(x) | 20 : fXTilesPerLargeTile(x) |
21 , fYTilesPerLargeTile(y) { | 21 , fYTilesPerLargeTile(y) { |
22 } | 22 } |
23 void CopyTilesRenderer::init(SkPicture* pict, const SkString* outputDir, | 23 void CopyTilesRenderer::init(SkPicture* pict, const SkString* writePath, |
24 const SkString* inputFilename, bool useChecksum
BasedFilenames) { | 24 const SkString* mismatchPath, const SkString* i
nputFilename, |
| 25 bool useChecksumBasedFilenames) { |
25 // Do not call INHERITED::init(), which would create a (potentially larg
e) canvas which is | 26 // Do not call INHERITED::init(), which would create a (potentially larg
e) canvas which is |
26 // not used by bench_pictures. | 27 // not used by bench_pictures. |
27 SkASSERT(pict != NULL); | 28 SkASSERT(pict != NULL); |
28 // Only work with absolute widths (as opposed to percentages). | 29 // Only work with absolute widths (as opposed to percentages). |
29 SkASSERT(this->getTileWidth() != 0 && this->getTileHeight() != 0); | 30 SkASSERT(this->getTileWidth() != 0 && this->getTileHeight() != 0); |
30 fPicture.reset(pict)->ref(); | 31 fPicture.reset(pict)->ref(); |
31 this->CopyString(&fOutputDir, outputDir); | 32 this->CopyString(&fWritePath, writePath); |
| 33 this->CopyString(&fMismatchPath, mismatchPath); |
32 this->CopyString(&fInputFilename, inputFilename); | 34 this->CopyString(&fInputFilename, inputFilename); |
33 fUseChecksumBasedFilenames = useChecksumBasedFilenames; | 35 fUseChecksumBasedFilenames = useChecksumBasedFilenames; |
34 this->buildBBoxHierarchy(); | 36 this->buildBBoxHierarchy(); |
35 // In order to avoid allocating a large canvas (particularly important f
or GPU), create one | 37 // In order to avoid allocating a large canvas (particularly important f
or GPU), create one |
36 // canvas that is a multiple of the tile size, and draw portions of the
picture. | 38 // canvas that is a multiple of the tile size, and draw portions of the
picture. |
37 fLargeTileWidth = fXTilesPerLargeTile * this->getTileWidth(); | 39 fLargeTileWidth = fXTilesPerLargeTile * this->getTileWidth(); |
38 fLargeTileHeight = fYTilesPerLargeTile * this->getTileHeight(); | 40 fLargeTileHeight = fYTilesPerLargeTile * this->getTileHeight(); |
39 fCanvas.reset(this->INHERITED::setupCanvas(fLargeTileWidth, fLargeTileHe
ight)); | 41 fCanvas.reset(this->INHERITED::setupCanvas(fLargeTileWidth, fLargeTileHe
ight)); |
40 } | 42 } |
41 | 43 |
(...skipping 15 matching lines...) Expand all Loading... |
57 // Now extract the picture into tiles | 59 // Now extract the picture into tiles |
58 const SkBitmap& baseBitmap = fCanvas->getDevice()->accessBitmap(
false); | 60 const SkBitmap& baseBitmap = fCanvas->getDevice()->accessBitmap(
false); |
59 SkIRect subset; | 61 SkIRect subset; |
60 for (int tileY = 0; tileY < fLargeTileHeight; tileY += this->get
TileHeight()) { | 62 for (int tileY = 0; tileY < fLargeTileHeight; tileY += this->get
TileHeight()) { |
61 for (int tileX = 0; tileX < fLargeTileWidth; tileX += this->
getTileWidth()) { | 63 for (int tileX = 0; tileX < fLargeTileWidth; tileX += this->
getTileWidth()) { |
62 subset.set(tileX, tileY, tileX + this->getTileWidth(), | 64 subset.set(tileX, tileY, tileX + this->getTileWidth(), |
63 tileY + this->getTileHeight()); | 65 tileY + this->getTileHeight()); |
64 SkDEBUGCODE(bool extracted =) | 66 SkDEBUGCODE(bool extracted =) |
65 baseBitmap.extractSubset(&dst, subset); | 67 baseBitmap.extractSubset(&dst, subset); |
66 SkASSERT(extracted); | 68 SkASSERT(extracted); |
67 if (!fOutputDir.isEmpty()) { | 69 if (!fWritePath.isEmpty()) { |
68 // Similar to write() in PictureRenderer.cpp, but ju
st encodes | 70 // Similar to write() in PictureRenderer.cpp, but ju
st encodes |
69 // a bitmap directly. | 71 // a bitmap directly. |
70 // TODO: Share more common code with write() to do t
his, to properly | 72 // TODO: Share more common code with write() to do t
his, to properly |
71 // write out the JSON summary, etc. | 73 // write out the JSON summary, etc. |
72 SkString pathWithNumber; | 74 SkString pathWithNumber; |
73 make_filepath(&pathWithNumber, fOutputDir, fInputFil
ename); | 75 make_filepath(&pathWithNumber, fWritePath, fInputFil
ename); |
74 pathWithNumber.remove(pathWithNumber.size() - 4, 4); | 76 pathWithNumber.remove(pathWithNumber.size() - 4, 4); |
75 pathWithNumber.appendf("%i.png", i++); | 77 pathWithNumber.appendf("%i.png", i++); |
76 SkBitmap copy; | 78 SkBitmap copy; |
77 #if SK_SUPPORT_GPU | 79 #if SK_SUPPORT_GPU |
78 if (isUsingGpuDevice()) { | 80 if (isUsingGpuDevice()) { |
79 dst.pixelRef()->readPixels(©, &subset); | 81 dst.pixelRef()->readPixels(©, &subset); |
80 } else { | 82 } else { |
81 #endif | 83 #endif |
82 dst.copyTo(©); | 84 dst.copyTo(©); |
83 #if SK_SUPPORT_GPU | 85 #if SK_SUPPORT_GPU |
84 } | 86 } |
85 #endif | 87 #endif |
86 success &= SkImageEncoder::EncodeFile(pathWithNumber
.c_str(), copy, | 88 success &= SkImageEncoder::EncodeFile(pathWithNumber
.c_str(), copy, |
87 SkImageEncoder
::kPNG_Type, 100); | 89 SkImageEncoder
::kPNG_Type, 100); |
88 } | 90 } |
89 } | 91 } |
90 } | 92 } |
91 } | 93 } |
92 } | 94 } |
93 return success; | 95 return success; |
94 } | 96 } |
95 | 97 |
96 SkString CopyTilesRenderer::getConfigNameInternal() { | 98 SkString CopyTilesRenderer::getConfigNameInternal() { |
97 return SkString("copy_tiles"); | 99 return SkString("copy_tiles"); |
98 } | 100 } |
99 } | 101 } |
OLD | NEW |