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

Side by Side Diff: bench/subset/SubsetTranslateBench.cpp

Issue 1531833002: Remove Subset*Benches (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years 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 | « bench/subset/SubsetTranslateBench.h ('k') | bench/subset/SubsetZoomBench.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 2015 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 "CodecBenchPriv.h"
9 #include "SubsetTranslateBench.h"
10 #include "SubsetBenchPriv.h"
11 #include "SkData.h"
12 #include "SkCodec.h"
13 #include "SkImageDecoder.h"
14 #include "SkOSFile.h"
15 #include "SkStream.h"
16
17 /*
18 *
19 * This benchmark is designed to test the performance of subset decoding.
20 * It uses input dimensions to decode the entire image where each block is susbe tW x subsetH.
21 *
22 */
23
24 SubsetTranslateBench::SubsetTranslateBench(const SkString& path,
25 SkColorType colorType,
26 uint32_t subsetWidth,
27 uint32_t subsetHeight)
28 : fColorType(colorType)
29 , fSubsetWidth(subsetWidth)
30 , fSubsetHeight(subsetHeight)
31 {
32 // Parse the filename
33 SkString baseName = SkOSPath::Basename(path.c_str());
34
35 // Choose an informative color name
36 const char* colorName = color_type_to_str(fColorType);
37
38 fName.printf("CodecSubsetTranslate_%dx%d_%s_%s", fSubsetWidth,
39 fSubsetHeight, baseName.c_str(), colorName);
40
41 // Perform the decode setup
42 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str()));
43 fStream.reset(new SkMemoryStream(encoded));
44 }
45
46 const char* SubsetTranslateBench::onGetName() {
47 return fName.c_str();
48 }
49
50 bool SubsetTranslateBench::isSuitableFor(Backend backend) {
51 return kNonRendering_Backend == backend;
52 }
53
54 // Allows allocating the bitmap first, and then writing to them later (in startS canlineDecode)
55 static SkPMColor* get_colors(SkBitmap* bm) {
56 SkColorTable* ct = bm->getColorTable();
57 if (!ct) {
58 return nullptr;
59 }
60
61 return const_cast<SkPMColor*>(ct->readColors());
62 }
63
64 void SubsetTranslateBench::onDraw(int n, SkCanvas* canvas) {
65 // When the color type is kIndex8, we will need to store the color table. I f it is
66 // used, it will be initialized by the codec.
67 int colorCount = 256;
68 SkPMColor colors[256];
69 for (int count = 0; count < n; count++) {
70 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplicate() ));
71 SkASSERT(SkCodec::kOutOfOrder_SkScanlineOrder != codec->getScanlineOrder ());
72 const SkImageInfo info = codec->getInfo().makeColorType(fColorType);
73
74 SkBitmap bitmap;
75 // Note that we use the same bitmap for all of the subsets.
76 // It might be larger than necessary for the end subsets.
77 SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight);
78 alloc_pixels(&bitmap, subsetInfo, colors, colorCount);
79
80 for (int x = 0; x < info.width(); x += fSubsetWidth) {
81 for (int y = 0; y < info.height(); y += fSubsetHeight) {
82 const uint32_t currSubsetWidth =
83 x + (int) fSubsetWidth > info.width() ?
84 info.width() - x : fSubsetWidth;
85 const uint32_t currSubsetHeight =
86 y + (int) fSubsetHeight > info.height() ?
87 info.height() - y : fSubsetHeight;
88
89 // The scanline decoder will handle subsetting in the x-dimensio n.
90 SkIRect subset = SkIRect::MakeXYWH(x, 0, currSubsetWidth,
91 codec->getInfo().height());
92 SkCodec::Options options;
93 options.fSubset = &subset;
94
95 SkDEBUGCODE(SkCodec::Result result =)
96 codec->startScanlineDecode(info, &options, get_colors(&bitmap), &colorCount);
97 SkASSERT(SkCodec::kSuccess == result);
98
99 SkDEBUGCODE(bool success =) codec->skipScanlines(y);
100 SkASSERT(success);
101
102 SkDEBUGCODE(uint32_t lines =) codec->getScanlines(bitmap.getPixe ls(),
103 currSubsetHeight, bitmap.rowBytes());
104 SkASSERT(currSubsetHeight == lines);
105 }
106 }
107 }
108 }
OLDNEW
« no previous file with comments | « bench/subset/SubsetTranslateBench.h ('k') | bench/subset/SubsetZoomBench.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698