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

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

Issue 1390213002: Add subsetting to SkScanlineDecoder (Closed) Base URL: https://skia.googlesource.com/skia.git@fill-refactor
Patch Set: Response to comments 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 | « bench/subset/SubsetSingleBench.cpp ('k') | bench/subset/SubsetZoomBench.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 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 "CodecBenchPriv.h" 8 #include "CodecBenchPriv.h"
9 #include "SubsetTranslateBench.h" 9 #include "SubsetTranslateBench.h"
10 #include "SubsetBenchPriv.h" 10 #include "SubsetBenchPriv.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 } 64 }
65 65
66 void SubsetTranslateBench::onDraw(int n, SkCanvas* canvas) { 66 void SubsetTranslateBench::onDraw(int n, SkCanvas* canvas) {
67 // When the color type is kIndex8, we will need to store the color table. I f it is 67 // When the color type is kIndex8, we will need to store the color table. I f it is
68 // used, it will be initialized by the codec. 68 // used, it will be initialized by the codec.
69 int colorCount = 256; 69 int colorCount = 256;
70 SkPMColor colors[256]; 70 SkPMColor colors[256];
71 if (fUseCodec) { 71 if (fUseCodec) {
72 for (int count = 0; count < n; count++) { 72 for (int count = 0; count < n; count++) {
73 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplica te())); 73 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplica te()));
74 SkASSERT(SkCodec::kOutOfOrder_SkScanlineOrder != codec->getScanlineO rder());
74 const SkImageInfo info = codec->getInfo().makeColorType(fColorType); 75 const SkImageInfo info = codec->getInfo().makeColorType(fColorType);
75 SkAutoTDeleteArray<uint8_t> row(nullptr);
76 if (codec->getScanlineOrder() == SkCodec::kTopDown_SkScanlineOrder) {
77 row.reset(new uint8_t[info.minRowBytes()]);
78 }
79 76
80 SkBitmap bitmap; 77 SkBitmap bitmap;
81 // Note that we use the same bitmap for all of the subsets. 78 // Note that we use the same bitmap for all of the subsets.
82 // It might be larger than necessary for the end subsets. 79 // It might be larger than necessary for the end subsets.
83 SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight); 80 SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight);
84 alloc_pixels(&bitmap, subsetInfo, colors, colorCount); 81 alloc_pixels(&bitmap, subsetInfo, colors, colorCount);
85 82
86 const uint32_t bpp = info.bytesPerPixel();
87
88 for (int x = 0; x < info.width(); x += fSubsetWidth) { 83 for (int x = 0; x < info.width(); x += fSubsetWidth) {
89 for (int y = 0; y < info.height(); y += fSubsetHeight) { 84 for (int y = 0; y < info.height(); y += fSubsetHeight) {
90 SkDEBUGCODE(SkCodec::Result result =)
91 codec->startScanlineDecode(info, nullptr, get_colors(&bitmap ), &colorCount);
92 SkASSERT(SkCodec::kSuccess == result);
93
94 SkDEBUGCODE(int lines =) codec->skipScanlines(y);
95 SkASSERT(y == lines);
96
97 const uint32_t currSubsetWidth = 85 const uint32_t currSubsetWidth =
98 x + (int) fSubsetWidth > info.width() ? 86 x + (int) fSubsetWidth > info.width() ?
99 info.width() - x : fSubsetWidth; 87 info.width() - x : fSubsetWidth;
100 const uint32_t currSubsetHeight = 88 const uint32_t currSubsetHeight =
101 y + (int) fSubsetHeight > info.height() ? 89 y + (int) fSubsetHeight > info.height() ?
102 info.height() - y : fSubsetHeight; 90 info.height() - y : fSubsetHeight;
103 91
104 switch (codec->getScanlineOrder()) { 92 // The scanline decoder will handle subsetting in the x-dime nsion.
105 case SkCodec::kTopDown_SkScanlineOrder: 93 SkIRect subset = SkIRect::MakeXYWH(x, 0, currSubsetWidth,
106 for (uint32_t y = 0; y < currSubsetHeight; y++) { 94 codec->getInfo().height());
107 SkDEBUGCODE(lines =) codec->getScanlines(row.get (), 1, 0); 95 SkCodec::Options options;
108 SkASSERT(1 == lines); 96 options.fSubset = &subset;
109 97
110 memcpy(bitmap.getAddr(0, y), row.get() + x * bpp , 98 SkDEBUGCODE(SkCodec::Result result =)
111 currSubsetWidth * bpp); 99 codec->startScanlineDecode(info, &options, get_colors(&bitma p), &colorCount);
112 } 100 SkASSERT(SkCodec::kSuccess == result);
113 break;
114 case SkCodec::kNone_SkScanlineOrder: {
115 // decode all scanlines that intersect the subset, a nd copy the subset
116 // into the output.
117 SkImageInfo stripeInfo = info.makeWH(info.width(), c urrSubsetHeight);
118 SkBitmap stripeBm;
119 alloc_pixels(&stripeBm, stripeInfo, colors, colorCou nt);
120 101
121 SkDEBUGCODE(lines =) codec->getScanlines(stripeBm.ge tPixels(), 102 SkDEBUGCODE(bool success =) codec->skipScanlines(y);
122 currSubsetHeight, stripeBm.rowBytes()); 103 SkASSERT(success);
123 SkASSERT(currSubsetHeight == (uint32_t) lines);
124 104
125 for (uint32_t subsetY = 0; subsetY < currSubsetHeigh t; subsetY++) { 105 SkDEBUGCODE(uint32_t lines =) codec->getScanlines(bitmap.get Pixels(),
126 memcpy(bitmap.getAddr(0, subsetY), stripeBm.getA ddr(x, subsetY), 106 currSubsetHeight, bitmap.rowBytes());
127 currSubsetWidth * bpp); 107 SkASSERT(currSubsetHeight == lines);
128 }
129 break;
130 }
131 default:
132 // We currently are only testing kTopDown and kNone, which are the only
133 // two used by the subsets we care about. skbug.com/ 4428
134 SkASSERT(false);
135 }
136 } 108 }
137 } 109 }
138 } 110 }
139 } else { 111 } else {
140 // We create a color table here to satisfy allocPixels() when the output 112 // We create a color table here to satisfy allocPixels() when the output
141 // type is kIndex8. It's okay that this is uninitialized since we never 113 // type is kIndex8. It's okay that this is uninitialized since we never
142 // use it. 114 // use it.
143 SkAutoTUnref<SkColorTable> colorTable(new SkColorTable(colors, 0)); 115 SkAutoTUnref<SkColorTable> colorTable(new SkColorTable(colors, 0));
144 for (int count = 0; count < n; count++) { 116 for (int count = 0; count < n; count++) {
145 int width, height; 117 int width, height;
(...skipping 17 matching lines...) Expand all
163 const uint32_t currSubsetHeight = y + (int) fSubsetHeight > height ? 135 const uint32_t currSubsetHeight = y + (int) fSubsetHeight > height ?
164 height - y : fSubsetHeight; 136 height - y : fSubsetHeight;
165 SkIRect rect = SkIRect::MakeXYWH(x, y, currSubsetWidth, 137 SkIRect rect = SkIRect::MakeXYWH(x, y, currSubsetWidth,
166 currSubsetHeight); 138 currSubsetHeight);
167 SkAssertResult(decoder->decodeSubset(&bitmap, rect, fColorTy pe)); 139 SkAssertResult(decoder->decodeSubset(&bitmap, rect, fColorTy pe));
168 } 140 }
169 } 141 }
170 } 142 }
171 } 143 }
172 } 144 }
OLDNEW
« no previous file with comments | « bench/subset/SubsetSingleBench.cpp ('k') | bench/subset/SubsetZoomBench.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698