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

Side by Side Diff: tools/CopyTilesRenderer.cpp

Issue 1416913003: Clean up some dead code. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: kill dump-record Created 5 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 | « tools/CopyTilesRenderer.h ('k') | tools/PictureBenchmark.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "picture_utils.h"
9 #include "CopyTilesRenderer.h"
10 #include "SkCanvas.h"
11 #include "SkDevice.h"
12 #include "SkImageEncoder.h"
13 #include "SkMultiPictureDraw.h"
14 #include "SkPicture.h"
15 #include "SkPixelRef.h"
16 #include "SkRect.h"
17 #include "SkString.h"
18
19 namespace sk_tools {
20 #if SK_SUPPORT_GPU
21 CopyTilesRenderer::CopyTilesRenderer(const GrContextOptions& opts, int x, in t y)
22 : INHERITED(opts)
23 , fXTilesPerLargeTile(x)
24 , fYTilesPerLargeTile(y) { }
25 #else
26 CopyTilesRenderer::CopyTilesRenderer(int x, int y)
27 : fXTilesPerLargeTile(x)
28 , fYTilesPerLargeTile(y) { }
29 #endif
30 void CopyTilesRenderer::init(const SkPicture* pict, const SkString* writePat h,
31 const SkString* mismatchPath, const SkString* i nputFilename,
32 bool useChecksumBasedFilenames, bool useMultiPi ctureDraw) {
33 // Do not call INHERITED::init(), which would create a (potentially larg e) canvas which is
34 // not used by bench_pictures.
35 SkASSERT(pict != nullptr);
36 // Only work with absolute widths (as opposed to percentages).
37 SkASSERT(this->getTileWidth() != 0 && this->getTileHeight() != 0);
38 fPicture.reset(SkRef(pict));
39 this->CopyString(&fWritePath, writePath);
40 this->CopyString(&fMismatchPath, mismatchPath);
41 this->CopyString(&fInputFilename, inputFilename);
42 fUseChecksumBasedFilenames = useChecksumBasedFilenames;
43 fUseMultiPictureDraw = useMultiPictureDraw;
44 this->buildBBoxHierarchy();
45 // In order to avoid allocating a large canvas (particularly important f or GPU), create one
46 // canvas that is a multiple of the tile size, and draw portions of the picture.
47 fLargeTileWidth = fXTilesPerLargeTile * this->getTileWidth();
48 fLargeTileHeight = fYTilesPerLargeTile * this->getTileHeight();
49 fCanvas.reset(this->INHERITED::setupCanvas(fLargeTileWidth, fLargeTileHe ight));
50 }
51
52 bool CopyTilesRenderer::render(SkBitmap** out) {
53 int i = 0;
54 bool success = true;
55 SkBitmap dst;
56 for (int x = 0; x < this->getViewWidth(); x += fLargeTileWidth) {
57 for (int y = 0; y < this->getViewHeight(); y += fLargeTileHeight) {
58 SkAutoCanvasRestore autoRestore(fCanvas, true);
59 // Translate so that we draw the correct portion of the picture.
60 // Perform a postTranslate so that the scaleFactor does not inte rfere with the
61 // positioning.
62 SkMatrix mat(fCanvas->getTotalMatrix());
63 mat.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y));
64 fCanvas->setMatrix(mat);
65 // Draw the picture
66 if (fUseMultiPictureDraw) {
67 SkMultiPictureDraw mpd;
68
69 mpd.add(fCanvas, fPicture);
70
71 mpd.draw();
72 } else {
73 fCanvas->drawPicture(fPicture);
74 }
75 // Now extract the picture into tiles
76 SkBitmap baseBitmap;
77 fCanvas->readPixels(SkIRect::MakeSize(fCanvas->getBaseLayerSize( )), &baseBitmap);
78 SkIRect subset;
79 for (int tileY = 0; tileY < fLargeTileHeight; tileY += this->get TileHeight()) {
80 for (int tileX = 0; tileX < fLargeTileWidth; tileX += this-> getTileWidth()) {
81 subset.set(tileX, tileY, tileX + this->getTileWidth(),
82 tileY + this->getTileHeight());
83 SkDEBUGCODE(bool extracted =)
84 baseBitmap.extractSubset(&dst, subset);
85 SkASSERT(extracted);
86 if (!fWritePath.isEmpty()) {
87 // Similar to write() in PictureRenderer.cpp, but ju st encodes
88 // a bitmap directly.
89 // TODO: Share more common code with write() to do t his, to properly
90 // write out the JSON summary, etc.
91 SkString pathWithNumber = SkOSPath::Join(fWritePath. c_str(),
92 fInputFilen ame.c_str());
93 pathWithNumber.remove(pathWithNumber.size() - 4, 4);
94 pathWithNumber.appendf("%i.png", i++);
95 SkBitmap copy;
96 #if SK_SUPPORT_GPU
97 if (isUsingGpuDevice()) {
98 dst.pixelRef()->readPixels(&copy, &subset);
99 } else {
100 #endif
101 dst.copyTo(&copy);
102 #if SK_SUPPORT_GPU
103 }
104 #endif
105 success &= SkImageEncoder::EncodeFile(pathWithNumber .c_str(), copy,
106 SkImageEncoder ::kPNG_Type, 100);
107 }
108 }
109 }
110 }
111 }
112 return success;
113 }
114
115 SkString CopyTilesRenderer::getConfigNameInternal() {
116 return SkString("copy_tiles");
117 }
118 }
OLDNEW
« no previous file with comments | « tools/CopyTilesRenderer.h ('k') | tools/PictureBenchmark.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698