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 SkColorType dstColorType, uint32_t sampleSize) | |
69 : fPath(path) | |
70 , fStrategy(strategy) | |
71 , fMode(mode) | |
72 , fColorType(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 if (kRGB_565_SkColorType == canvas->imageInfo().colorType()) { | |
92 return Error::Nonfatal("Testing to multiple backends is uninteresting.") ; | |
93 } | |
94 | |
95 SkAutoTDelete<SkBitmapRegionDecoder> brd(create_brd(fPath, fStrategy)); | |
96 if (nullptr == brd.get()) { | |
97 return Error::Nonfatal(SkStringPrintf("Could not create brd for %s.", fP ath.c_str())); | |
98 } | |
99 | |
100 switch (fMode) { | |
101 case kFullImage_Mode: { | |
102 SkAutoTDelete<SkBitmap> bitmap(brd->decodeRegion(0, 0, brd->width(), | |
103 brd->height(), fSampleSize, fColorType)); | |
104 if (nullptr == bitmap.get() || fColorType != bitmap->colorType()) { | |
105 return Error::Nonfatal("Cannot convert to color type.\n"); | |
106 } | |
107 canvas->drawBitmap(*bitmap, 0, 0); | |
108 return ""; | |
109 } | |
110 case kDivisor_Mode: { | |
111 uint32_t divisor = 2; | |
112 // Use a border to test subsets that extend outside the image. | |
113 // We will not allow the border to be larger than the image dimensio ns. Allowing | |
114 // these large borders causes off by one errors that indicate a prob lem with the | |
115 // test suite, not a problem with the implementation. | |
116 uint32_t maxBorder = SkTMin(brd->width(), brd->height()) / (fSampleS ize * divisor); | |
117 uint32_t scaledBorder = SkTMin(5u, maxBorder); | |
118 uint32_t unscaledBorder = scaledBorder * fSampleSize; | |
119 | |
120 uint32_t width = brd->width(); | |
scroggo
2015/09/02 21:32:24
nit: These could have been defined above, so you o
msarett
2015/09/03 19:20:51
Good point! Pretty sure lots of them can be const
| |
121 uint32_t height = brd->height(); | |
122 for (uint32_t x = 0; x < divisor; x++) { | |
123 for (uint32_t y = 0; y < divisor; y++) { | |
124 // Calculate the subset dimensions | |
125 uint32_t subsetWidth = width / divisor; | |
126 uint32_t subsetHeight = height / divisor; | |
127 int left = x * subsetWidth; | |
128 int top = y * subsetHeight; | |
129 | |
130 // Increase the size of the last subset in each row or colum n, when the | |
131 // divisor does not divide evenly into the image dimensions | |
132 subsetWidth += (x + 1 == divisor) ? (width % divisor) : 0; | |
133 subsetHeight += (y + 1 == divisor) ? (height % divisor) : 0; | |
134 | |
135 // Increase the size of the subset in order to have a border on each side | |
136 int decodeLeft = left - unscaledBorder; | |
137 int decodeTop = top - unscaledBorder; | |
138 uint32_t decodeWidth = subsetWidth + unscaledBorder * 2; | |
139 uint32_t decodeHeight = subsetHeight + unscaledBorder * 2; | |
140 | |
141 SkAutoTDelete<SkBitmap> bitmap(brd->decodeRegion(decodeLeft, | |
scroggo
2015/09/02 21:32:24
What should we do about the fact that WEBP gives u
msarett
2015/09/03 19:20:51
I think it should be handled in BRD. We want BRD
| |
142 decodeTop, decodeWidth, decodeHeight, fSampleSize, f ColorType)); | |
143 if (nullptr == bitmap.get() || fColorType != bitmap->colorTy pe()) { | |
144 return Error::Nonfatal("Cannot convert to color type.\n" ); | |
145 } | |
146 canvas->drawBitmapRect(*bitmap, | |
147 SkRect::MakeXYWH(scaledBorder, scaledBorder, | |
148 subsetWidth / fSampleSize, subsetHeight / fS ampleSize), | |
149 SkRect::MakeXYWH(left / fSampleSize, top / fSampleSi ze, | |
150 subsetWidth / fSampleSize, subsetHeight / fS ampleSize), | |
151 nullptr); | |
152 } | |
153 } | |
154 return ""; | |
155 } | |
156 default: | |
157 SkASSERT(false); | |
158 return "Error: Should not be reached.\n"; | |
159 } | |
160 } | |
161 | |
162 SkISize BRDSrc::size() const { | |
163 SkAutoTDelete<SkBitmapRegionDecoder> brd(create_brd(fPath, fStrategy)); | |
164 if (brd) { | |
165 return SkISize::Make(SkTMax(1, brd->width() / (int) fSampleSize), | |
166 SkTMax(1, brd->height() / (int) fSampleSize)); | |
167 } | |
168 return SkISize::Make(0, 0); | |
169 } | |
170 | |
171 static SkString get_scaled_name(Path path, float scale) { | |
scroggo
2015/09/02 21:32:24
Copying SkStrings is cheap, but const &ing them is
msarett
2015/09/03 19:20:51
:)
| |
172 return SkStringPrintf("%s_%.3f", SkOSPath::Basename(path.c_str()).c_str(), s cale); | |
173 } | |
174 | |
175 Name BRDSrc::name() const { | |
176 // We will replicate the names used by CodecSrc so that images can | |
177 // be compared in Gold. | |
178 if (1 == fSampleSize) { | |
179 return SkOSPath::Basename(fPath.c_str()); | |
180 } | |
181 return get_scaled_name(fPath, BRDSrc::GetScale(fSampleSize)); | |
182 } | |
183 | |
184 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ | |
185 | |
67 CodecSrc::CodecSrc(Path path, Mode mode, DstColorType dstColorType, float scale) | 186 CodecSrc::CodecSrc(Path path, Mode mode, DstColorType dstColorType, float scale) |
68 : fPath(path) | 187 : fPath(path) |
69 , fMode(mode) | 188 , fMode(mode) |
70 , fDstColorType(dstColorType) | 189 , fDstColorType(dstColorType) |
71 , fScale(scale) | 190 , fScale(scale) |
72 {} | 191 {} |
73 | 192 |
74 bool CodecSrc::veto(SinkFlags flags) const { | 193 bool CodecSrc::veto(SinkFlags flags) const { |
75 // No need to test decoding to non-raster or indirect backend. | 194 // 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 | 195 // 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); | 605 return SkISize::Make(0, 0); |
487 } | 606 } |
488 } | 607 } |
489 SkISize size = codec->getScaledDimensions(fScale); | 608 SkISize size = codec->getScaledDimensions(fScale); |
490 return size; | 609 return size; |
491 } | 610 } |
492 | 611 |
493 Name CodecSrc::name() const { | 612 Name CodecSrc::name() const { |
494 if (1.0f == fScale) { | 613 if (1.0f == fScale) { |
495 return SkOSPath::Basename(fPath.c_str()); | 614 return SkOSPath::Basename(fPath.c_str()); |
496 } else { | |
497 return SkStringPrintf("%s_%.3f", SkOSPath::Basename(fPath.c_str()).c_str (), fScale); | |
498 } | 615 } |
616 return get_scaled_name(fPath, fScale); | |
499 } | 617 } |
500 | 618 |
501 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ | 619 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ |
502 | 620 |
503 ImageSrc::ImageSrc(Path path, int divisor) : fPath(path), fDivisor(divisor) {} | 621 ImageSrc::ImageSrc(Path path, int divisor) : fPath(path), fDivisor(divisor) {} |
504 | 622 |
505 bool ImageSrc::veto(SinkFlags flags) const { | 623 bool ImageSrc::veto(SinkFlags flags) const { |
506 // No need to test decoding to non-raster or indirect backend. | 624 // 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. | 625 // TODO: Instead, use lazy decoding to allow the GPU to handle cases like YU V. |
508 return flags.type != SinkFlags::kRaster | 626 return flags.type != SinkFlags::kRaster |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1086 skr.visit<void>(i, drawsAsSingletonPictures); | 1204 skr.visit<void>(i, drawsAsSingletonPictures); |
1087 } | 1205 } |
1088 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); | 1206 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); |
1089 | 1207 |
1090 canvas->drawPicture(macroPic); | 1208 canvas->drawPicture(macroPic); |
1091 return ""; | 1209 return ""; |
1092 }); | 1210 }); |
1093 } | 1211 } |
1094 | 1212 |
1095 } // namespace DM | 1213 } // namespace DM |
OLD | NEW |