OLD | NEW |
---|---|
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 "DMSrcSink.h" | 8 #include "DMSrcSink.h" |
9 #include "SamplePipeControllers.h" | 9 #include "SamplePipeControllers.h" |
10 #include "SkCodec.h" | 10 #include "SkCodec.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 return gm->getName(); | 57 return gm->getName(); |
58 } | 58 } |
59 | 59 |
60 void GMSrc::modifyGrContextOptions(GrContextOptions* options) const { | 60 void GMSrc::modifyGrContextOptions(GrContextOptions* options) const { |
61 SkAutoTDelete<skiagm::GM> gm(fFactory(nullptr)); | 61 SkAutoTDelete<skiagm::GM> gm(fFactory(nullptr)); |
62 gm->modifyGrContextOptions(options); | 62 gm->modifyGrContextOptions(options); |
63 } | 63 } |
64 | 64 |
65 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ | 65 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ |
66 | 66 |
67 BRDSrc::BRDSrc(Path path, SkBitmapRegionDecoder::Strategy strategy, Mode mode, | |
68 CodecSrc::DstColorType dstColorType, uint32_t sampleSize) | |
69 : fPath(path) | |
70 , fStrategy(strategy) | |
71 , fMode(mode) | |
72 , fDstColorType(dstColorType) | |
73 , fSampleSize(sampleSize) | |
74 {} | |
75 | |
76 bool BRDSrc::veto(SinkFlags flags) const { | |
77 // No need to test to non-raster or indirect backends. | |
78 return flags.type != SinkFlags::kRaster | |
79 || flags.approach != SinkFlags::kDirect; | |
80 } | |
81 | |
82 static SkBitmapRegionDecoder* create_brd(Path path, SkBitmapRegionDecoder::Strat egy strategy) { | |
83 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); | |
84 if (!encoded) { | |
85 return NULL; | |
86 } | |
87 return SkBitmapRegionDecoder::CreateBitmapRegionDecoder(new SkMemoryStream(e ncoded), strategy); | |
88 } | |
89 | |
90 Error BRDSrc::draw(SkCanvas* canvas) const { | |
91 SkColorType colorType = canvas->imageInfo().colorType(); | |
92 switch (fDstColorType) { | |
93 case CodecSrc::kGetFromCanvas_DstColorType: | |
94 break; | |
95 case CodecSrc::kIndex8_Always_DstColorType: | |
96 if (kRGB_565_SkColorType == colorType) { | |
scroggo
2015/09/03 20:07:41
Instead of repeating this three times, can we move
msarett
2015/09/03 22:10:30
Yes this is better.
| |
97 return Error::Nonfatal("Testing non-565 to 565 is uninteresting. "); | |
98 } | |
99 colorType = kIndex_8_SkColorType; | |
100 break; | |
101 case CodecSrc::kGrayscale_Always_DstColorType: | |
102 if (kRGB_565_SkColorType == colorType) { | |
103 return Error::Nonfatal("Testing non-565 to 565 is uninteresting. "); | |
104 } | |
105 colorType = kGray_8_SkColorType; | |
106 break; | |
107 case CodecSrc::kAlpha_Always_DstColorType: | |
108 if (kRGB_565_SkColorType == colorType) { | |
109 return Error::Nonfatal("Testing non-565 to 565 is uninteresting. "); | |
110 } | |
111 colorType = kAlpha_8_SkColorType; | |
112 break; | |
113 } | |
114 | |
115 SkAutoTDelete<SkBitmapRegionDecoder> brd(create_brd(fPath, fStrategy)); | |
116 if (nullptr == brd.get()) { | |
117 return Error::Nonfatal(SkStringPrintf("Could not create brd for %s.", fP ath.c_str())); | |
118 } | |
119 | |
120 const uint32_t width = brd->width(); | |
121 const uint32_t height = brd->height(); | |
122 switch (fMode) { | |
123 case kFullImage_Mode: { | |
124 SkAutoTDelete<SkBitmap> bitmap(brd->decodeRegion(0, 0, width, height , fSampleSize, | |
125 colorType)); | |
126 if (nullptr == bitmap.get() || colorType != bitmap->colorType()) { | |
127 return Error::Nonfatal("Cannot convert to color type.\n"); | |
128 } | |
129 canvas->drawBitmap(*bitmap, 0, 0); | |
130 return ""; | |
131 } | |
132 case kDivisor_Mode: { | |
133 const uint32_t divisor = 2; | |
134 // Use a border to test subsets that extend outside the image. | |
135 // We will not allow the border to be larger than the image dimensio ns. Allowing | |
136 // these large borders causes off by one errors that indicate a prob lem with the | |
137 // test suite, not a problem with the implementation. | |
138 const uint32_t maxBorder = SkTMin(width, height) / (fSampleSize * di visor); | |
139 const uint32_t scaledBorder = SkTMin(5u, maxBorder); | |
140 const uint32_t unscaledBorder = scaledBorder * fSampleSize; | |
141 | |
142 | |
143 for (uint32_t x = 0; x < divisor; x++) { | |
144 for (uint32_t y = 0; y < divisor; y++) { | |
145 // Calculate the subset dimensions | |
146 uint32_t subsetWidth = width / divisor; | |
147 uint32_t subsetHeight = height / divisor; | |
148 const int left = x * subsetWidth; | |
149 const int top = y * subsetHeight; | |
150 | |
151 // Increase the size of the last subset in each row or colum n, when the | |
152 // divisor does not divide evenly into the image dimensions | |
153 subsetWidth += (x + 1 == divisor) ? (width % divisor) : 0; | |
154 subsetHeight += (y + 1 == divisor) ? (height % divisor) : 0; | |
155 | |
156 // Increase the size of the subset in order to have a border on each side | |
157 const int decodeLeft = left - unscaledBorder; | |
158 const int decodeTop = top - unscaledBorder; | |
159 const uint32_t decodeWidth = subsetWidth + unscaledBorder * 2; | |
160 const uint32_t decodeHeight = subsetHeight + unscaledBorder * 2; | |
161 SkAutoTDelete<SkBitmap> bitmap(brd->decodeRegion(decodeLeft, | |
162 decodeTop, decodeWidth, decodeHeight, fSampleSize, c olorType)); | |
163 if (nullptr == bitmap.get() || colorType != bitmap->colorTyp e()) { | |
164 return Error::Nonfatal("Cannot convert to color type.\n" ); | |
165 } | |
166 canvas->drawBitmapRect(*bitmap, | |
167 SkRect::MakeXYWH(scaledBorder, scaledBorder, | |
168 subsetWidth / fSampleSize, subsetHeight / fS ampleSize), | |
169 SkRect::MakeXYWH(left / fSampleSize, top / fSampleSi ze, | |
170 subsetWidth / fSampleSize, subsetHeight / fS ampleSize), | |
171 nullptr); | |
172 } | |
173 } | |
174 return ""; | |
175 } | |
176 default: | |
177 SkASSERT(false); | |
178 return "Error: Should not be reached.\n"; | |
179 } | |
180 } | |
181 | |
182 SkISize BRDSrc::size() const { | |
183 SkAutoTDelete<SkBitmapRegionDecoder> brd(create_brd(fPath, fStrategy)); | |
184 if (brd) { | |
185 return SkISize::Make(SkTMax(1, brd->width() / (int) fSampleSize), | |
186 SkTMax(1, brd->height() / (int) fSampleSize)); | |
187 } | |
188 return SkISize::Make(0, 0); | |
189 } | |
190 | |
191 static SkString get_scaled_name(const Path& path, float scale) { | |
192 return SkStringPrintf("%s_%.3f", SkOSPath::Basename(path.c_str()).c_str(), s cale); | |
193 } | |
194 | |
195 Name BRDSrc::name() const { | |
196 // We will replicate the names used by CodecSrc so that images can | |
197 // be compared in Gold. | |
198 if (1 == fSampleSize) { | |
199 return SkOSPath::Basename(fPath.c_str()); | |
200 } | |
201 return get_scaled_name(fPath, BRDSrc::GetScale(fSampleSize)); | |
202 } | |
203 | |
204 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ | |
205 | |
67 CodecSrc::CodecSrc(Path path, Mode mode, DstColorType dstColorType, float scale) | 206 CodecSrc::CodecSrc(Path path, Mode mode, DstColorType dstColorType, float scale) |
68 : fPath(path) | 207 : fPath(path) |
69 , fMode(mode) | 208 , fMode(mode) |
70 , fDstColorType(dstColorType) | 209 , fDstColorType(dstColorType) |
71 , fScale(scale) | 210 , fScale(scale) |
72 {} | 211 {} |
73 | 212 |
74 bool CodecSrc::veto(SinkFlags flags) const { | 213 bool CodecSrc::veto(SinkFlags flags) const { |
75 // No need to test decoding to non-raster or indirect backend. | 214 // No need to test decoding to non-raster or indirect backend. |
76 // TODO: Once we implement GPU paths (e.g. JPEG YUV), we should use a deferr ed decode to | 215 // TODO: Once we implement GPU paths (e.g. JPEG YUV), we should use a deferr ed decode to |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
486 return SkISize::Make(0, 0); | 625 return SkISize::Make(0, 0); |
487 } | 626 } |
488 } | 627 } |
489 SkISize size = codec->getScaledDimensions(fScale); | 628 SkISize size = codec->getScaledDimensions(fScale); |
490 return size; | 629 return size; |
491 } | 630 } |
492 | 631 |
493 Name CodecSrc::name() const { | 632 Name CodecSrc::name() const { |
494 if (1.0f == fScale) { | 633 if (1.0f == fScale) { |
495 return SkOSPath::Basename(fPath.c_str()); | 634 return SkOSPath::Basename(fPath.c_str()); |
496 } else { | |
497 return SkStringPrintf("%s_%.3f", SkOSPath::Basename(fPath.c_str()).c_str (), fScale); | |
498 } | 635 } |
636 return get_scaled_name(fPath, fScale); | |
499 } | 637 } |
500 | 638 |
501 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ | 639 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ |
502 | 640 |
503 ImageSrc::ImageSrc(Path path, int divisor) : fPath(path), fDivisor(divisor) {} | 641 ImageSrc::ImageSrc(Path path, int divisor) : fPath(path), fDivisor(divisor) {} |
504 | 642 |
505 bool ImageSrc::veto(SinkFlags flags) const { | 643 bool ImageSrc::veto(SinkFlags flags) const { |
506 // No need to test decoding to non-raster or indirect backend. | 644 // No need to test decoding to non-raster or indirect backend. |
507 // TODO: Instead, use lazy decoding to allow the GPU to handle cases like YU V. | 645 // TODO: Instead, use lazy decoding to allow the GPU to handle cases like YU V. |
508 return flags.type != SinkFlags::kRaster | 646 return flags.type != SinkFlags::kRaster |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1086 skr.visit<void>(i, drawsAsSingletonPictures); | 1224 skr.visit<void>(i, drawsAsSingletonPictures); |
1087 } | 1225 } |
1088 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); | 1226 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); |
1089 | 1227 |
1090 canvas->drawPicture(macroPic); | 1228 canvas->drawPicture(macroPic); |
1091 return ""; | 1229 return ""; |
1092 }); | 1230 }); |
1093 } | 1231 } |
1094 | 1232 |
1095 } // namespace DM | 1233 } // namespace DM |
OLD | NEW |