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

Side by Side Diff: bench/subset/SubsetZoomBench.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 "SubsetZoomBench.h" 8 #include "SubsetZoomBench.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 * Choose subsets to mimic a user zooming in or out on a photo. 19 * Choose subsets to mimic a user zooming in or out on a photo.
21 * 20 *
22 */ 21 */
23 22
24 SubsetZoomBench::SubsetZoomBench(const SkString& path, 23 SubsetZoomBench::SubsetZoomBench(const SkString& path,
(...skipping 28 matching lines...) Expand all
53 return kNonRendering_Backend == backend; 52 return kNonRendering_Backend == backend;
54 } 53 }
55 54
56 void SubsetZoomBench::onDraw(const int n, SkCanvas* canvas) { 55 void SubsetZoomBench::onDraw(const int n, SkCanvas* canvas) {
57 // When the color type is kIndex8, we will need to store the color table. I f it is 56 // When the color type is kIndex8, we will need to store the color table. I f it is
58 // used, it will be initialized by the codec. 57 // used, it will be initialized by the codec.
59 int colorCount; 58 int colorCount;
60 SkPMColor colors[256]; 59 SkPMColor colors[256];
61 if (fUseCodec) { 60 if (fUseCodec) {
62 for (int count = 0; count < n; count++) { 61 for (int count = 0; count < n; count++) {
63 SkAutoTDelete<SkScanlineDecoder> scanlineDecoder( 62 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplica te()));
64 SkScanlineDecoder::NewFromStream(fStream->duplicate())); 63 const SkImageInfo info = codec->getInfo().makeColorType(fColorType);
65 const SkImageInfo info = scanlineDecoder->getInfo().makeColorType(fC olorType);
66 SkAutoTDeleteArray<uint8_t> row(new uint8_t[info.minRowBytes()]); 64 SkAutoTDeleteArray<uint8_t> row(new uint8_t[info.minRowBytes()]);
67 scanlineDecoder->start(info, nullptr, colors, &colorCount); 65 codec->start(info, nullptr, colors, &colorCount);
68 66
69 const int centerX = info.width() / 2; 67 const int centerX = info.width() / 2;
70 const int centerY = info.height() / 2; 68 const int centerY = info.height() / 2;
71 int w = fSubsetWidth; 69 int w = fSubsetWidth;
72 int h = fSubsetHeight; 70 int h = fSubsetHeight;
73 do { 71 do {
74 const int subsetStartX = SkTMax(0, centerX - w / 2); 72 const int subsetStartX = SkTMax(0, centerX - w / 2);
75 const int subsetStartY = SkTMax(0, centerY - h / 2); 73 const int subsetStartY = SkTMax(0, centerY - h / 2);
76 const int subsetWidth = SkTMin(w, info.width() - subsetStartX); 74 const int subsetWidth = SkTMin(w, info.width() - subsetStartX);
77 const int subsetHeight = SkTMin(h, info.height() - subsetStartY) ; 75 const int subsetHeight = SkTMin(h, info.height() - subsetStartY) ;
78 // Note that if we subsetted and scaled in a single step, we cou ld use the 76 // Note that if we subsetted and scaled in a single step, we cou ld use the
79 // same bitmap - as is often done in actual use cases. 77 // same bitmap - as is often done in actual use cases.
80 SkBitmap bitmap; 78 SkBitmap bitmap;
81 SkImageInfo subsetInfo = info.makeWH(subsetWidth, subsetHeight); 79 SkImageInfo subsetInfo = info.makeWH(subsetWidth, subsetHeight);
82 alloc_pixels(&bitmap, subsetInfo, colors, colorCount); 80 alloc_pixels(&bitmap, subsetInfo, colors, colorCount);
83 81
84 uint32_t bpp = info.bytesPerPixel(); 82 uint32_t bpp = info.bytesPerPixel();
85 scanlineDecoder->skipScanlines(subsetStartY); 83 codec->skipScanlines(subsetStartY);
86 for (int y = 0; y < subsetHeight; y++) { 84 for (int y = 0; y < subsetHeight; y++) {
87 scanlineDecoder->getScanlines(row.get(), 1, 0); 85 codec->getScanlines(row.get(), 1, 0);
88 memcpy(bitmap.getAddr(0, y), row.get() + subsetStartX * bpp, 86 memcpy(bitmap.getAddr(0, y), row.get() + subsetStartX * bpp,
89 subsetWidth * bpp); 87 subsetWidth * bpp);
90 } 88 }
91 w <<= 1; 89 w <<= 1;
92 h <<= 1; 90 h <<= 1;
93 } while (w < 2 * info.width() || h < 2 * info.height()); 91 } while (w < 2 * info.width() || h < 2 * info.height());
94 } 92 }
95 } else { 93 } else {
96 for (int count = 0; count < n; count++) { 94 for (int count = 0; count < n; count++) {
97 int width, height; 95 int width, height;
(...skipping 12 matching lines...) Expand all
110 SkBitmap bitmap; 108 SkBitmap bitmap;
111 SkIRect rect = SkIRect::MakeXYWH(subsetStartX, subsetStartY, sub setWidth, 109 SkIRect rect = SkIRect::MakeXYWH(subsetStartX, subsetStartY, sub setWidth,
112 subsetHeight); 110 subsetHeight);
113 decoder->decodeSubset(&bitmap, rect, fColorType); 111 decoder->decodeSubset(&bitmap, rect, fColorType);
114 w <<= 1; 112 w <<= 1;
115 h <<= 1; 113 h <<= 1;
116 } while (w < 2 * width || h < 2 * height); 114 } while (w < 2 * width || h < 2 * height);
117 } 115 }
118 } 116 }
119 } 117 }
OLDNEW
« no previous file with comments | « bench/subset/SubsetTranslateBench.cpp ('k') | dm/DMSrcSink.cpp » ('j') | include/codec/SkCodec.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698