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

Side by Side Diff: tools/CopyTilesRenderer.cpp

Issue 202983003: add --writeChecksumBasedFilenames flag to render_pictures (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: pass SkString pointers to init Created 6 years, 9 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 | « tools/CopyTilesRenderer.h ('k') | tools/PictureBenchmark.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 "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) { 23 void CopyTilesRenderer::init(SkPicture* pict, const SkString* outputDir,
24 const SkString* inputFilename, bool useChecksum BasedFilenames) {
25 // Do not call INHERITED::init(), which would create a (potentially larg e) canvas which is
26 // not used by bench_pictures.
24 SkASSERT(pict != NULL); 27 SkASSERT(pict != NULL);
25 // Only work with absolute widths (as opposed to percentages). 28 // Only work with absolute widths (as opposed to percentages).
26 SkASSERT(this->getTileWidth() != 0 && this->getTileHeight() != 0); 29 SkASSERT(this->getTileWidth() != 0 && this->getTileHeight() != 0);
27 fPicture = pict; 30 fPicture = pict;
31 this->CopyString(&fOutputDir, outputDir);
32 this->CopyString(&fInputFilename, inputFilename);
33 fUseChecksumBasedFilenames = useChecksumBasedFilenames;
28 fPicture->ref(); 34 fPicture->ref();
29 this->buildBBoxHierarchy(); 35 this->buildBBoxHierarchy();
30 // In order to avoid allocating a large canvas (particularly important f or GPU), create one 36 // In order to avoid allocating a large canvas (particularly important f or GPU), create one
31 // canvas that is a multiple of the tile size, and draw portions of the picture. 37 // canvas that is a multiple of the tile size, and draw portions of the picture.
32 fLargeTileWidth = fXTilesPerLargeTile * this->getTileWidth(); 38 fLargeTileWidth = fXTilesPerLargeTile * this->getTileWidth();
33 fLargeTileHeight = fYTilesPerLargeTile * this->getTileHeight(); 39 fLargeTileHeight = fYTilesPerLargeTile * this->getTileHeight();
34 fCanvas.reset(this->INHERITED::setupCanvas(fLargeTileWidth, fLargeTileHe ight)); 40 fCanvas.reset(this->INHERITED::setupCanvas(fLargeTileWidth, fLargeTileHe ight));
35 } 41 }
36 42
37 bool CopyTilesRenderer::render(const SkString* path, SkBitmap** out) { 43 bool CopyTilesRenderer::render(SkBitmap** out) {
38 int i = 0; 44 int i = 0;
39 bool success = true; 45 bool success = true;
40 SkBitmap dst; 46 SkBitmap dst;
41 for (int x = 0; x < this->getViewWidth(); x += fLargeTileWidth) { 47 for (int x = 0; x < this->getViewWidth(); x += fLargeTileWidth) {
42 for (int y = 0; y < this->getViewHeight(); y += fLargeTileHeight) { 48 for (int y = 0; y < this->getViewHeight(); y += fLargeTileHeight) {
43 SkAutoCanvasRestore autoRestore(fCanvas, true); 49 SkAutoCanvasRestore autoRestore(fCanvas, true);
44 // Translate so that we draw the correct portion of the picture. 50 // Translate so that we draw the correct portion of the picture.
45 // Perform a postTranslate so that the scaleFactor does not inte rfere with the 51 // Perform a postTranslate so that the scaleFactor does not inte rfere with the
46 // positioning. 52 // positioning.
47 SkMatrix mat(fCanvas->getTotalMatrix()); 53 SkMatrix mat(fCanvas->getTotalMatrix());
48 mat.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y)); 54 mat.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y));
49 fCanvas->setMatrix(mat); 55 fCanvas->setMatrix(mat);
50 // Draw the picture 56 // Draw the picture
51 fCanvas->drawPicture(*fPicture); 57 fCanvas->drawPicture(*fPicture);
52 // Now extract the picture into tiles 58 // Now extract the picture into tiles
53 const SkBitmap& baseBitmap = fCanvas->getDevice()->accessBitmap( false); 59 const SkBitmap& baseBitmap = fCanvas->getDevice()->accessBitmap( false);
54 SkIRect subset; 60 SkIRect subset;
55 for (int tileY = 0; tileY < fLargeTileHeight; tileY += this->get TileHeight()) { 61 for (int tileY = 0; tileY < fLargeTileHeight; tileY += this->get TileHeight()) {
56 for (int tileX = 0; tileX < fLargeTileWidth; tileX += this-> getTileWidth()) { 62 for (int tileX = 0; tileX < fLargeTileWidth; tileX += this-> getTileWidth()) {
57 subset.set(tileX, tileY, tileX + this->getTileWidth(), 63 subset.set(tileX, tileY, tileX + this->getTileWidth(),
58 tileY + this->getTileHeight()); 64 tileY + this->getTileHeight());
59 SkDEBUGCODE(bool extracted =) 65 SkDEBUGCODE(bool extracted =)
60 baseBitmap.extractSubset(&dst, subset); 66 baseBitmap.extractSubset(&dst, subset);
61 SkASSERT(extracted); 67 SkASSERT(extracted);
62 if (path != NULL) { 68 if (!fOutputDir.isEmpty()) {
63 // Similar to writeAppendNumber in PictureRenderer.c pp, but just encodes 69 // Similar to write() in PictureRenderer.cpp, but ju st encodes
64 // a bitmap directly. 70 // a bitmap directly.
65 SkString pathWithNumber(*path); 71 // TODO: Share more common code with write() to do t his, to properly
72 // write out the JSON summary, etc.
73 SkString pathWithNumber;
74 make_filepath(&pathWithNumber, fOutputDir, fInputFil ename);
75 pathWithNumber.remove(pathWithNumber.size() - 4, 4);
66 pathWithNumber.appendf("%i.png", i++); 76 pathWithNumber.appendf("%i.png", i++);
67 SkBitmap copy; 77 SkBitmap copy;
68 #if SK_SUPPORT_GPU 78 #if SK_SUPPORT_GPU
69 if (isUsingGpuDevice()) { 79 if (isUsingGpuDevice()) {
70 dst.pixelRef()->readPixels(&copy, &subset); 80 dst.pixelRef()->readPixels(&copy, &subset);
71 } else { 81 } else {
72 #endif 82 #endif
73 dst.copyTo(&copy); 83 dst.copyTo(&copy);
74 #if SK_SUPPORT_GPU 84 #if SK_SUPPORT_GPU
75 } 85 }
76 #endif 86 #endif
77 success &= SkImageEncoder::EncodeFile(pathWithNumber .c_str(), copy, 87 success &= SkImageEncoder::EncodeFile(pathWithNumber .c_str(), copy,
78 SkImageEncoder ::kPNG_Type, 100); 88 SkImageEncoder ::kPNG_Type, 100);
79 } 89 }
80 } 90 }
81 } 91 }
82 } 92 }
83 } 93 }
84 return success; 94 return success;
85 } 95 }
86 96
87 SkString CopyTilesRenderer::getConfigNameInternal() { 97 SkString CopyTilesRenderer::getConfigNameInternal() {
88 return SkString("copy_tiles"); 98 return SkString("copy_tiles");
89 } 99 }
90 } 100 }
OLDNEW
« no previous file with comments | « tools/CopyTilesRenderer.h ('k') | tools/PictureBenchmark.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698