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 Error BRDSrc::draw(SkCanvas* canvas) const { | |
83 if (kRGB_565_SkColorType == canvas->imageInfo().colorType()) { | |
84 return Error::Nonfatal("Testing to multiple backends is uninteresting.") ; | |
scroggo
2015/09/01 22:05:28
More importantly, I think we never run this for 56
msarett
2015/09/02 18:02:23
Sorry, forgot about this. Otherwise I might have
scroggo
2015/09/02 21:32:24
I agree that it is a little awkward. I assume your
msarett
2015/09/03 19:20:51
I like this idea.
| |
85 } | |
86 | |
87 SkAutoTDelete<SkBitmapRegionDecoder> brd( | |
88 SkBitmapRegionDecoder::CreateBitmapRegionDecoder( | |
89 SkNEW_ARGS(SkMemoryStream, (SkData::NewFromFileName(fPath.c_ str()))), | |
scroggo
2015/09/01 22:05:28
nit: no need for SkNEW anymore
msarett
2015/09/02 18:02:23
Done.
| |
90 fStrategy)); | |
91 if (nullptr == brd.get()) { | |
92 return Error::Nonfatal(SkStringPrintf("Could not create brd for %s.", fP ath.c_str())); | |
93 } | |
94 | |
95 switch (fMode) { | |
96 case kFullImage_Mode: { | |
97 SkAutoTDelete<SkBitmap> bitmap(brd->decodeRegion(0, 0, brd->width(), | |
98 brd->height(), fSampleSize, fColorType)); | |
99 if (nullptr == bitmap.get() || fColorType != bitmap->colorType()) { | |
100 return Error::Nonfatal("Cannot convert to color type.\n"); | |
101 } | |
102 canvas->drawBitmap(*bitmap, 0, 0); | |
103 return ""; | |
104 } | |
105 case kDivisor_Mode: { | |
106 uint32_t divisor = 2; | |
107 // Use a border to test subsets that extend outside the image. | |
108 // We will not allow the border to be larger than the image dimensio ns. Allowing | |
109 // these large borders causes off by one errors that indicate a prob lem with the | |
110 // test suite, not a problem with the implementation. | |
111 uint32_t maxBorder = SkTMin(brd->width(), brd->height()) / (fSampleS ize * divisor); | |
112 uint32_t scaledBorder = SkTMin(5u, maxBorder); | |
113 uint32_t unscaledBorder = scaledBorder * fSampleSize; | |
114 | |
115 uint32_t width = brd->width(); | |
116 uint32_t height = brd->height(); | |
117 for (uint32_t x = 0; x < divisor; x++) { | |
118 for (uint32_t y = 0; y < divisor; y++) { | |
119 // Calculate the subset dimensions | |
120 uint32_t subsetWidth = width / divisor; | |
121 uint32_t subsetHeight = height / divisor; | |
122 int left = x * subsetWidth; | |
123 int top = y * subsetHeight; | |
124 | |
125 // Increase the size of the last subset in each row or colum n, when the | |
126 // divisor does not divide evenly into the image dimensions | |
127 subsetWidth += (x + 1 == divisor) ? (width % divisor) : 0; | |
128 subsetHeight += (y + 1 == divisor) ? (height % divisor) : 0; | |
129 | |
130 // Increase the size of the subset in order to have a border on each side | |
131 int decodeLeft = left - unscaledBorder; | |
132 int decodeTop = top - unscaledBorder; | |
133 uint32_t decodeWidth = subsetWidth + unscaledBorder * 2; | |
134 uint32_t decodeHeight = subsetHeight + unscaledBorder * 2; | |
135 | |
136 SkAutoTDelete<SkBitmap> bitmap(brd->decodeRegion(decodeLeft, | |
137 decodeTop, decodeWidth, decodeHeight, fSampleSize, f ColorType)); | |
138 if (nullptr == bitmap.get() || fColorType != bitmap->colorTy pe()) { | |
139 return Error::Nonfatal("Cannot convert to color type.\n" ); | |
140 } | |
141 canvas->drawBitmapRect(*bitmap, | |
142 SkRect::MakeXYWH(scaledBorder, scaledBorder, | |
143 subsetWidth / fSampleSize, subsetHeight / fS ampleSize), | |
144 SkRect::MakeXYWH(left / fSampleSize, top / fSampleSi ze, | |
145 subsetWidth / fSampleSize, subsetHeight / fS ampleSize), | |
146 nullptr); | |
147 } | |
148 } | |
149 return ""; | |
150 } | |
151 default: | |
152 SkASSERT(false); | |
153 return "Error: Should not be reached.\n"; | |
154 } | |
155 } | |
156 | |
157 SkISize BRDSrc::size() const { | |
158 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | |
159 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); | |
160 if (codec) { | |
161 return SkISize::Make(SkTMax(1, codec->getInfo().width() / (int) fSampleS ize), | |
scroggo
2015/09/01 22:05:28
It seems a little weird that we calculate this usi
msarett
2015/09/02 18:02:23
Agreed. Fixed to use a BRD.
| |
162 SkTMax(1, codec->getInfo().height() / (int) fSampleSize)); | |
163 } | |
164 return SkISize::Make(0, 0); | |
165 } | |
166 | |
167 Name BRDSrc::name() const { | |
168 // We will replicate the names used by CodecSrc so that images can | |
169 // be compared in Gold. | |
170 if (1.0f == fSampleSize) { | |
171 return SkOSPath::Basename(fPath.c_str()); | |
172 } | |
173 float scale = 1.0f / fSampleSize; | |
174 return SkStringPrintf("%s_%.3f", SkOSPath::Basename(fPath.c_str()).c_str(), scale); | |
scroggo
2015/09/01 22:05:28
Maybe this should be in a helper function?
msarett
2015/09/02 18:02:23
Yeah I think so.
| |
175 } | |
176 | |
177 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ | |
178 | |
67 CodecSrc::CodecSrc(Path path, Mode mode, DstColorType dstColorType, float scale) | 179 CodecSrc::CodecSrc(Path path, Mode mode, DstColorType dstColorType, float scale) |
68 : fPath(path) | 180 : fPath(path) |
69 , fMode(mode) | 181 , fMode(mode) |
70 , fDstColorType(dstColorType) | 182 , fDstColorType(dstColorType) |
71 , fScale(scale) | 183 , fScale(scale) |
72 {} | 184 {} |
73 | 185 |
74 bool CodecSrc::veto(SinkFlags flags) const { | 186 bool CodecSrc::veto(SinkFlags flags) const { |
75 // No need to test decoding to non-raster or indirect backend. | 187 // 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 | 188 // TODO: Once we implement GPU paths (e.g. JPEG YUV), we should use a deferr ed decode to |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
464 return SkISize::Make(0, 0); | 576 return SkISize::Make(0, 0); |
465 } | 577 } |
466 } | 578 } |
467 SkISize size = codec->getScaledDimensions(fScale); | 579 SkISize size = codec->getScaledDimensions(fScale); |
468 return size; | 580 return size; |
469 } | 581 } |
470 | 582 |
471 Name CodecSrc::name() const { | 583 Name CodecSrc::name() const { |
472 if (1.0f == fScale) { | 584 if (1.0f == fScale) { |
473 return SkOSPath::Basename(fPath.c_str()); | 585 return SkOSPath::Basename(fPath.c_str()); |
474 } else { | |
475 return SkStringPrintf("%s_%.3f", SkOSPath::Basename(fPath.c_str()).c_str (), fScale); | |
476 } | 586 } |
587 return SkStringPrintf("%s_%.3f", SkOSPath::Basename(fPath.c_str()).c_str(), fScale); | |
477 } | 588 } |
478 | 589 |
479 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ | 590 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ |
480 | 591 |
481 ImageSrc::ImageSrc(Path path, int divisor) : fPath(path), fDivisor(divisor) {} | 592 ImageSrc::ImageSrc(Path path, int divisor) : fPath(path), fDivisor(divisor) {} |
482 | 593 |
483 bool ImageSrc::veto(SinkFlags flags) const { | 594 bool ImageSrc::veto(SinkFlags flags) const { |
484 // No need to test decoding to non-raster or indirect backend. | 595 // No need to test decoding to non-raster or indirect backend. |
485 // TODO: Instead, use lazy decoding to allow the GPU to handle cases like YU V. | 596 // TODO: Instead, use lazy decoding to allow the GPU to handle cases like YU V. |
486 return flags.type != SinkFlags::kRaster | 597 return flags.type != SinkFlags::kRaster |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1064 skr.visit<void>(i, drawsAsSingletonPictures); | 1175 skr.visit<void>(i, drawsAsSingletonPictures); |
1065 } | 1176 } |
1066 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); | 1177 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); |
1067 | 1178 |
1068 canvas->drawPicture(macroPic); | 1179 canvas->drawPicture(macroPic); |
1069 return ""; | 1180 return ""; |
1070 }); | 1181 }); |
1071 } | 1182 } |
1072 | 1183 |
1073 } // namespace DM | 1184 } // namespace DM |
OLD | NEW |