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

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

Issue 1365313002: Merge SkCodec with SkScanlineDecoder (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 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 "SubsetSingleBench.h" 8 #include "SubsetSingleBench.h"
9 #include "SubsetBenchPriv.h" 9 #include "SubsetBenchPriv.h"
10 #include "SkData.h" 10 #include "SkData.h"
11 #include "SkCodec.h" 11 #include "SkCodec.h"
12 #include "SkImageDecoder.h" 12 #include "SkImageDecoder.h"
13 #include "SkOSFile.h" 13 #include "SkOSFile.h"
14 #include "SkScanlineDecoder.h"
15 #include "SkStream.h" 14 #include "SkStream.h"
16 15
17 /* 16 /*
18 * 17 *
19 * This benchmark is designed to test the performance of subset decoding. 18 * This benchmark is designed to test the performance of subset decoding.
20 * It uses an input width, height, left, and top to decode a single subset. 19 * It uses an input width, height, left, and top to decode a single subset.
21 * 20 *
22 */ 21 */
23 22
24 SubsetSingleBench::SubsetSingleBench(const SkString& path, 23 SubsetSingleBench::SubsetSingleBench(const SkString& path,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 return kNonRendering_Backend == backend; 56 return kNonRendering_Backend == backend;
58 } 57 }
59 58
60 void SubsetSingleBench::onDraw(const int n, SkCanvas* canvas) { 59 void SubsetSingleBench::onDraw(const int n, SkCanvas* canvas) {
61 // When the color type is kIndex8, we will need to store the color table. I f it is 60 // When the color type is kIndex8, we will need to store the color table. I f it is
62 // used, it will be initialized by the codec. 61 // used, it will be initialized by the codec.
63 int colorCount; 62 int colorCount;
64 SkPMColor colors[256]; 63 SkPMColor colors[256];
65 if (fUseCodec) { 64 if (fUseCodec) {
66 for (int count = 0; count < n; count++) { 65 for (int count = 0; count < n; count++) {
67 SkAutoTDelete<SkScanlineDecoder> scanlineDecoder( 66 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplica te()));
68 SkScanlineDecoder::NewFromStream(fStream->duplicate())); 67 const SkImageInfo info = codec->getInfo().makeColorType(fColorType);
69 const SkImageInfo info = scanlineDecoder->getInfo().makeColorType(fC olorType);
70 SkAutoTDeleteArray<uint8_t> row(new uint8_t[info.minRowBytes()]); 68 SkAutoTDeleteArray<uint8_t> row(new uint8_t[info.minRowBytes()]);
71 scanlineDecoder->start(info, nullptr, colors, &colorCount); 69 codec->start(info, nullptr, colors, &colorCount);
72 70
73 SkBitmap bitmap; 71 SkBitmap bitmap;
74 SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight); 72 SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight);
75 alloc_pixels(&bitmap, subsetInfo, colors, colorCount); 73 alloc_pixels(&bitmap, subsetInfo, colors, colorCount);
76 74
77 scanlineDecoder->skipScanlines(fOffsetTop); 75 codec->skipScanlines(fOffsetTop);
78 uint32_t bpp = info.bytesPerPixel(); 76 uint32_t bpp = info.bytesPerPixel();
79 for (uint32_t y = 0; y < fSubsetHeight; y++) { 77 for (uint32_t y = 0; y < fSubsetHeight; y++) {
80 scanlineDecoder->getScanlines(row.get(), 1, 0); 78 codec->getScanlines(row.get(), 1, 0);
81 memcpy(bitmap.getAddr(0, y), row.get() + fOffsetLeft * bpp, 79 memcpy(bitmap.getAddr(0, y), row.get() + fOffsetLeft * bpp,
82 fSubsetWidth * bpp); 80 fSubsetWidth * bpp);
83 } 81 }
84 } 82 }
85 } else { 83 } else {
86 for (int count = 0; count < n; count++) { 84 for (int count = 0; count < n; count++) {
87 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStrea m)); 85 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStrea m));
88 int width, height; 86 int width, height;
89 decoder->buildTileIndex(fStream->duplicate(), &width, &height); 87 decoder->buildTileIndex(fStream->duplicate(), &width, &height);
90 SkBitmap bitmap; 88 SkBitmap bitmap;
91 SkIRect rect = SkIRect::MakeXYWH(fOffsetLeft, fOffsetTop, fSubsetWid th, 89 SkIRect rect = SkIRect::MakeXYWH(fOffsetLeft, fOffsetTop, fSubsetWid th,
92 fSubsetHeight); 90 fSubsetHeight);
93 decoder->decodeSubset(&bitmap, rect, fColorType); 91 decoder->decodeSubset(&bitmap, rect, fColorType);
94 } 92 }
95 } 93 }
96 } 94 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698