Chromium Code Reviews| 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(NULL)); | 61 SkAutoTDelete<skiagm::GM> gm(fFactory(NULL)); |
| 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, S kColorType dstColorType, uint32_t sampleSize) | |
|
scroggo
2015/08/13 16:53:06
nit: too many chars
msarett
2015/08/13 18:10:22
Done.
| |
| 68 : fPath(path) | |
| 69 , fStrategy(strategy) | |
| 70 , fMode(mode) | |
| 71 , fColorType(dstColorType) | |
| 72 , fSampleSize(sampleSize) | |
| 73 {} | |
| 74 | |
| 75 bool BRDSrc::veto(SinkFlags flags) const { | |
| 76 // It is interesting to test different dstColorTypes instead of different si nks | |
|
scroggo
2015/08/13 16:53:06
Huh?
msarett
2015/08/13 18:10:22
I changed this comment.
The original comment was
| |
| 77 return flags.type != SinkFlags::kRaster | |
| 78 || flags.approach != SinkFlags::kDirect; | |
| 79 } | |
| 80 | |
| 81 Error BRDSrc::draw(SkCanvas* canvas) const { | |
| 82 if (kRGB_565_SkColorType == canvas->imageInfo().colorType()) { | |
| 83 return Error::Nonfatal("Testing to multiple backends is uninteresting.") ; | |
| 84 } | |
| 85 | |
| 86 switch (fMode) { | |
| 87 case kNormal_Mode: { | |
| 88 SkAutoTDelete<SkBitmapRegionDecoder> brd( | |
| 89 SkBitmapRegionDecoder::CreateBitmapRegionDecoder( | |
| 90 SkNEW_ARGS(SkMemoryStream, (SkData::NewFromFileName( fPath.c_str()))), | |
| 91 fStrategy)); | |
| 92 if (NULL == brd.get()) { | |
| 93 return "Error: Could not CreateBRD.\n"; | |
|
scroggo
2015/08/13 16:53:06
nit: I don't think "Error: " is necessary here. I
msarett
2015/08/13 18:10:22
Done.
| |
| 94 } | |
| 95 SkAutoTDelete<SkBitmap> bitmap(brd->decodeRegion(0, 0, brd->width(), | |
| 96 brd->height(), fSampleSize, fColorType)); | |
| 97 if (NULL == bitmap.get() || fColorType != bitmap->colorType()) { | |
| 98 return Error::Nonfatal("Cannot convert to color type.\n"); | |
| 99 } | |
| 100 canvas->drawBitmap(*bitmap, 0, 0); | |
| 101 return ""; | |
| 102 } | |
| 103 case kSubset_Mode: { | |
| 104 SkAutoTDelete<SkBitmapRegionDecoder> brd( | |
|
scroggo
2015/08/13 16:53:06
It looks like these two are the same? Why not crea
msarett
2015/08/13 18:10:22
Done.
| |
| 105 SkBitmapRegionDecoder::CreateBitmapRegionDecoder( | |
| 106 SkNEW_ARGS(SkMemoryStream, (SkData::NewFromFileName( fPath.c_str()))), | |
| 107 fStrategy)); | |
| 108 if (NULL == brd.get()) { | |
| 109 return "Error: Could not CreateBRD.\n"; | |
| 110 } | |
| 111 | |
| 112 // Use a border to test what happens when we ask for subsets that ex tend outside the image | |
|
msarett
2015/08/13 15:16:34
This leads to outputs that are a bit strange for 5
scroggo
2015/08/13 16:53:06
Wait, so if the subset is bigger than 5 pixels, th
msarett
2015/08/13 18:10:22
So I think my comment was completely wrong.
We ar
scroggo
2015/08/28 13:49:43
+1
msarett
2015/08/28 18:45:50
I've fixed this. I had an off by one error that w
| |
| 113 uint32_t scaledBorder = 5; | |
| 114 uint32_t unscaledBorder = 5 * fSampleSize; | |
| 115 uint32_t divisor = 2; | |
| 116 uint32_t width = brd->width(); | |
| 117 uint32_t height = brd->height(); | |
| 118 for (uint32_t x = 0; x < divisor; x++) { | |
| 119 for (uint32_t y = 0; y < divisor; y++) { | |
| 120 // Calculate the subset dimensions | |
| 121 uint32_t subsetWidth = width / divisor; | |
| 122 uint32_t subsetHeight = height / divisor; | |
| 123 int left = x * subsetWidth; | |
| 124 int top = y * subsetHeight; | |
| 125 | |
| 126 // Increase the size of the last subset in each row or colum n, when the | |
| 127 // divisor does not divide evenly into the image dimensions | |
| 128 subsetWidth += (x + 1 == divisor) ? (width % divisor) : 0; | |
| 129 subsetHeight += (y + 1 == divisor) ? (height % divisor) : 0; | |
| 130 | |
| 131 // Increase the size of the subset in order to have a border on each side | |
| 132 int decodeLeft = left - unscaledBorder; | |
| 133 int decodeTop = top - unscaledBorder; | |
| 134 uint32_t decodeWidth = subsetWidth + unscaledBorder * 2; | |
| 135 uint32_t decodeHeight = subsetHeight + unscaledBorder * 2; | |
| 136 | |
| 137 SkAutoTDelete<SkBitmap> bitmap(brd->decodeRegion(decodeLeft, | |
| 138 decodeTop, decodeWidth, decodeHeight, fSampleSize, f ColorType)); | |
| 139 if (NULL == bitmap.get() || fColorType != bitmap->colorType( )) { | |
| 140 return Error::Nonfatal("Cannot convert to color type.\n" ); | |
| 141 } | |
| 142 canvas->drawBitmapRect(*bitmap, | |
| 143 SkRect::MakeXYWH(scaledBorder, scaledBorder, | |
| 144 subsetWidth / fSampleSize, subsetHeight / fS ampleSize), | |
| 145 SkRect::MakeXYWH(left / fSampleSize, top / fSampleSi ze, | |
| 146 subsetWidth / fSampleSize, subsetHeight / fS ampleSize), | |
| 147 NULL); | |
| 148 } | |
| 149 } | |
| 150 return ""; | |
| 151 } | |
| 152 default: | |
| 153 SkASSERT(false); | |
| 154 return "Error: Should not be reached.\n"; | |
| 155 } | |
| 156 } | |
| 157 | |
| 158 SkISize BRDSrc::size() const { | |
| 159 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | |
| 160 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); | |
| 161 if (NULL != codec) { | |
|
scroggo
2015/08/13 16:53:06
nit: checking !condition seems odd to me, if there
msarett
2015/08/13 18:10:22
Done.
| |
| 162 return SkISize::Make(codec->getInfo().width() / fSampleSize, | |
| 163 codec->getInfo().height() / fSampleSize); | |
| 164 } else { | |
|
scroggo
2015/08/13 16:53:06
This else is unnecessary, since the earlier condit
msarett
2015/08/13 18:10:23
Done.
| |
| 165 return SkISize::Make(0, 0); | |
| 166 } | |
| 167 } | |
| 168 | |
| 169 Name BRDSrc::name() const { | |
| 170 // We will try to replicate the names used by CodecSrc so that images can | |
|
scroggo
2015/08/13 16:53:06
Try to? Do we ever fail?
msarett
2015/08/13 18:10:22
Nope :)
| |
| 171 // be compared in Gold. | |
| 172 if (1.0f == fSampleSize) { | |
| 173 return SkOSPath::Basename(fPath.c_str()); | |
| 174 } else { | |
| 175 float scale = 1.0f / fSampleSize; | |
| 176 return SkStringPrintf("%s_%.3f", SkOSPath::Basename(fPath.c_str()).c_str (), scale); | |
| 177 } | |
| 178 } | |
| 179 | |
| 180 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ | |
| 181 | |
| 67 CodecSrc::CodecSrc(Path path, Mode mode, DstColorType dstColorType, float scale) | 182 CodecSrc::CodecSrc(Path path, Mode mode, DstColorType dstColorType, float scale) |
| 68 : fPath(path) | 183 : fPath(path) |
| 69 , fMode(mode) | 184 , fMode(mode) |
| 70 , fDstColorType(dstColorType) | 185 , fDstColorType(dstColorType) |
| 71 , fScale(scale) | 186 , fScale(scale) |
| 72 {} | 187 {} |
| 73 | 188 |
| 74 bool CodecSrc::veto(SinkFlags flags) const { | 189 bool CodecSrc::veto(SinkFlags flags) const { |
| 75 // No need to test decoding to non-raster or indirect backend. | 190 // 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 | 191 // TODO: Once we implement GPU paths (e.g. JPEG YUV), we should use a deferr ed decode to |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 441 return ""; | 556 return ""; |
| 442 } | 557 } |
| 443 } | 558 } |
| 444 return ""; | 559 return ""; |
| 445 } | 560 } |
| 446 | 561 |
| 447 SkISize CodecSrc::size() const { | 562 SkISize CodecSrc::size() const { |
| 448 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 563 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
| 449 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); | 564 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
| 450 if (NULL != codec) { | 565 if (NULL != codec) { |
| 451 SkISize size = codec->getScaledDimensions(fScale); | 566 return codec->getScaledDimensions(fScale); |
| 452 return size; | |
| 453 } else { | 567 } else { |
| 454 return SkISize::Make(0, 0); | 568 return SkISize::Make(0, 0); |
| 455 } | 569 } |
| 456 } | 570 } |
| 457 | 571 |
| 458 Name CodecSrc::name() const { | 572 Name CodecSrc::name() const { |
| 459 if (1.0f == fScale) { | 573 if (1.0f == fScale) { |
| 460 return SkOSPath::Basename(fPath.c_str()); | 574 return SkOSPath::Basename(fPath.c_str()); |
| 461 } else { | 575 } else { |
| 462 return SkStringPrintf("%s_%.3f", SkOSPath::Basename(fPath.c_str()).c_str (), fScale); | 576 return SkStringPrintf("%s_%.3f", SkOSPath::Basename(fPath.c_str()).c_str (), fScale); |
| (...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1075 skr.visit<void>(i, drawsAsSingletonPictures); | 1189 skr.visit<void>(i, drawsAsSingletonPictures); |
| 1076 } | 1190 } |
| 1077 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); | 1191 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); |
| 1078 | 1192 |
| 1079 canvas->drawPicture(macroPic); | 1193 canvas->drawPicture(macroPic); |
| 1080 return ""; | 1194 return ""; |
| 1081 }); | 1195 }); |
| 1082 } | 1196 } |
| 1083 | 1197 |
| 1084 } // namespace DM | 1198 } // namespace DM |
| OLD | NEW |