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, |
| 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.")
; |
| 85 } |
| 86 |
| 87 SkAutoTDelete<SkBitmapRegionDecoder> brd( |
| 88 SkBitmapRegionDecoder::CreateBitmapRegionDecoder( |
| 89 SkNEW_ARGS(SkMemoryStream, (SkData::NewFromFileName(fPath.c_
str()))), |
| 90 fStrategy)); |
| 91 if (NULL == brd.get()) { |
| 92 return SkStringPrintf("Could not create brd for %s.", fPath.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 (NULL == 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 // Use a border to test what happens when we ask for subsets that ex
tend outside the image |
| 107 uint32_t scaledBorder = 5; |
| 108 uint32_t unscaledBorder = 5 * fSampleSize; |
| 109 uint32_t divisor = 2; |
| 110 uint32_t width = brd->width(); |
| 111 uint32_t height = brd->height(); |
| 112 for (uint32_t x = 0; x < divisor; x++) { |
| 113 for (uint32_t y = 0; y < divisor; y++) { |
| 114 // Calculate the subset dimensions |
| 115 uint32_t subsetWidth = width / divisor; |
| 116 uint32_t subsetHeight = height / divisor; |
| 117 int left = x * subsetWidth; |
| 118 int top = y * subsetHeight; |
| 119 |
| 120 // Increase the size of the last subset in each row or colum
n, when the |
| 121 // divisor does not divide evenly into the image dimensions |
| 122 subsetWidth += (x + 1 == divisor) ? (width % divisor) : 0; |
| 123 subsetHeight += (y + 1 == divisor) ? (height % divisor) : 0; |
| 124 |
| 125 // Increase the size of the subset in order to have a border
on each side |
| 126 int decodeLeft = left - unscaledBorder; |
| 127 int decodeTop = top - unscaledBorder; |
| 128 uint32_t decodeWidth = subsetWidth + unscaledBorder * 2; |
| 129 uint32_t decodeHeight = subsetHeight + unscaledBorder * 2; |
| 130 |
| 131 SkAutoTDelete<SkBitmap> bitmap(brd->decodeRegion(decodeLeft, |
| 132 decodeTop, decodeWidth, decodeHeight, fSampleSize, f
ColorType)); |
| 133 if (NULL == bitmap.get() || fColorType != bitmap->colorType(
)) { |
| 134 return Error::Nonfatal("Cannot convert to color type.\n"
); |
| 135 } |
| 136 canvas->drawBitmapRect(*bitmap, |
| 137 SkRect::MakeXYWH(scaledBorder, scaledBorder, |
| 138 subsetWidth / fSampleSize, subsetHeight / fS
ampleSize), |
| 139 SkRect::MakeXYWH(left / fSampleSize, top / fSampleSi
ze, |
| 140 subsetWidth / fSampleSize, subsetHeight / fS
ampleSize), |
| 141 NULL); |
| 142 } |
| 143 } |
| 144 return ""; |
| 145 } |
| 146 default: |
| 147 SkASSERT(false); |
| 148 return "Error: Should not be reached.\n"; |
| 149 } |
| 150 } |
| 151 |
| 152 SkISize BRDSrc::size() const { |
| 153 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
| 154 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
| 155 if (codec) { |
| 156 return SkISize::Make(codec->getInfo().width() / fSampleSize, |
| 157 codec->getInfo().height() / fSampleSize); |
| 158 } |
| 159 return SkISize::Make(0, 0); |
| 160 } |
| 161 |
| 162 Name BRDSrc::name() const { |
| 163 // We will replicate the names used by CodecSrc so that images can |
| 164 // be compared in Gold. |
| 165 if (1.0f == fSampleSize) { |
| 166 return SkOSPath::Basename(fPath.c_str()); |
| 167 } |
| 168 float scale = 1.0f / fSampleSize; |
| 169 return SkStringPrintf("%s_%.3f", SkOSPath::Basename(fPath.c_str()).c_str(),
scale); |
| 170 } |
| 171 |
| 172 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ |
| 173 |
67 CodecSrc::CodecSrc(Path path, Mode mode, DstColorType dstColorType, float scale) | 174 CodecSrc::CodecSrc(Path path, Mode mode, DstColorType dstColorType, float scale) |
68 : fPath(path) | 175 : fPath(path) |
69 , fMode(mode) | 176 , fMode(mode) |
70 , fDstColorType(dstColorType) | 177 , fDstColorType(dstColorType) |
71 , fScale(scale) | 178 , fScale(scale) |
72 {} | 179 {} |
73 | 180 |
74 bool CodecSrc::veto(SinkFlags flags) const { | 181 bool CodecSrc::veto(SinkFlags flags) const { |
75 // No need to test decoding to non-raster or indirect backend. | 182 // 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 | 183 // TODO: Once we implement GPU paths (e.g. JPEG YUV), we should use a deferr
ed decode to |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 } | 547 } |
441 return ""; | 548 return ""; |
442 } | 549 } |
443 } | 550 } |
444 return ""; | 551 return ""; |
445 } | 552 } |
446 | 553 |
447 SkISize CodecSrc::size() const { | 554 SkISize CodecSrc::size() const { |
448 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 555 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
449 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); | 556 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
450 if (NULL != codec) { | 557 if (codec) { |
451 SkISize size = codec->getScaledDimensions(fScale); | 558 return codec->getScaledDimensions(fScale); |
452 return size; | |
453 } else { | |
454 return SkISize::Make(0, 0); | |
455 } | 559 } |
| 560 return SkISize::Make(0, 0); |
456 } | 561 } |
457 | 562 |
458 Name CodecSrc::name() const { | 563 Name CodecSrc::name() const { |
459 if (1.0f == fScale) { | 564 if (1.0f == fScale) { |
460 return SkOSPath::Basename(fPath.c_str()); | 565 return SkOSPath::Basename(fPath.c_str()); |
461 } else { | |
462 return SkStringPrintf("%s_%.3f", SkOSPath::Basename(fPath.c_str()).c_str
(), fScale); | |
463 } | 566 } |
| 567 return SkStringPrintf("%s_%.3f", SkOSPath::Basename(fPath.c_str()).c_str(),
fScale); |
464 } | 568 } |
465 | 569 |
466 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ | 570 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ |
467 | 571 |
468 ImageSrc::ImageSrc(Path path, int divisor) : fPath(path), fDivisor(divisor) {} | 572 ImageSrc::ImageSrc(Path path, int divisor) : fPath(path), fDivisor(divisor) {} |
469 | 573 |
470 bool ImageSrc::veto(SinkFlags flags) const { | 574 bool ImageSrc::veto(SinkFlags flags) const { |
471 // No need to test decoding to non-raster or indirect backend. | 575 // No need to test decoding to non-raster or indirect backend. |
472 // TODO: Instead, use lazy decoding to allow the GPU to handle cases like YU
V. | 576 // TODO: Instead, use lazy decoding to allow the GPU to handle cases like YU
V. |
473 return flags.type != SinkFlags::kRaster | 577 return flags.type != SinkFlags::kRaster |
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1075 skr.visit<void>(i, drawsAsSingletonPictures); | 1179 skr.visit<void>(i, drawsAsSingletonPictures); |
1076 } | 1180 } |
1077 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); | 1181 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); |
1078 | 1182 |
1079 canvas->drawPicture(macroPic); | 1183 canvas->drawPicture(macroPic); |
1080 return ""; | 1184 return ""; |
1081 }); | 1185 }); |
1082 } | 1186 } |
1083 | 1187 |
1084 } // namespace DM | 1188 } // namespace DM |
OLD | NEW |