| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 bool BRDSrc::veto(SinkFlags flags) const { | 79 bool BRDSrc::veto(SinkFlags flags) const { |
| 80 // No need to test to non-raster or indirect backends. | 80 // No need to test to non-raster or indirect backends. |
| 81 return flags.type != SinkFlags::kRaster | 81 return flags.type != SinkFlags::kRaster |
| 82 || flags.approach != SinkFlags::kDirect; | 82 || flags.approach != SinkFlags::kDirect; |
| 83 } | 83 } |
| 84 | 84 |
| 85 static SkBitmapRegionDecoderInterface* create_brd(Path path, | 85 static SkBitmapRegionDecoderInterface* create_brd(Path path, |
| 86 SkBitmapRegionDecoderInterface::Strategy strategy) { | 86 SkBitmapRegionDecoderInterface::Strategy strategy) { |
| 87 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); | 87 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); |
| 88 if (!encoded) { | 88 if (!encoded) { |
| 89 return NULL; | 89 return nullptr; |
| 90 } | 90 } |
| 91 return SkBitmapRegionDecoderInterface::CreateBitmapRegionDecoder(new SkMemor
yStream(encoded), | 91 return SkBitmapRegionDecoderInterface::CreateBitmapRegionDecoder(new SkMemor
yStream(encoded), |
| 92 strategy); | 92 strategy); |
| 93 } | 93 } |
| 94 | 94 |
| 95 Error BRDSrc::draw(SkCanvas* canvas) const { | 95 Error BRDSrc::draw(SkCanvas* canvas) const { |
| 96 SkColorType colorType = canvas->imageInfo().colorType(); | 96 SkColorType colorType = canvas->imageInfo().colorType(); |
| 97 if (kRGB_565_SkColorType == colorType && | 97 if (kRGB_565_SkColorType == colorType && |
| 98 CodecSrc::kGetFromCanvas_DstColorType != fDstColorType) { | 98 CodecSrc::kGetFromCanvas_DstColorType != fDstColorType) { |
| 99 return Error::Nonfatal("Testing non-565 to 565 is uninteresting."); | 99 return Error::Nonfatal("Testing non-565 to 565 is uninteresting."); |
| 100 } | 100 } |
| 101 switch (fDstColorType) { | 101 switch (fDstColorType) { |
| 102 case CodecSrc::kGetFromCanvas_DstColorType: | 102 case CodecSrc::kGetFromCanvas_DstColorType: |
| 103 break; | 103 break; |
| 104 case CodecSrc::kIndex8_Always_DstColorType: | 104 case CodecSrc::kIndex8_Always_DstColorType: |
| 105 colorType = kIndex_8_SkColorType; | 105 colorType = kIndex_8_SkColorType; |
| 106 break; | 106 break; |
| 107 case CodecSrc::kGrayscale_Always_DstColorType: | 107 case CodecSrc::kGrayscale_Always_DstColorType: |
| 108 colorType = kGray_8_SkColorType; | 108 colorType = kGray_8_SkColorType; |
| 109 break; | 109 break; |
| 110 } | 110 } |
| 111 | 111 |
| 112 SkAutoTDelete<SkBitmapRegionDecoderInterface> brd(create_brd(fPath, fStrateg
y)); | 112 SkAutoTDelete<SkBitmapRegionDecoderInterface> brd(create_brd(fPath, fStrateg
y)); |
| 113 if (nullptr == brd.get()) { | 113 if (nullptr == brd.get()) { |
| 114 return Error::Nonfatal(SkStringPrintf("Could not create brd for %s.", fP
ath.c_str())); | 114 return Error::Nonfatal(SkStringPrintf("Could not create brd for %s.", fP
ath.c_str())); |
| 115 } | 115 } |
| 116 | 116 |
| 117 if (!brd->conversionSupported(colorType)) { |
| 118 return Error::Nonfatal("Cannot convert to color type.\n"); |
| 119 } |
| 120 |
| 117 const uint32_t width = brd->width(); | 121 const uint32_t width = brd->width(); |
| 118 const uint32_t height = brd->height(); | 122 const uint32_t height = brd->height(); |
| 119 // Visually inspecting very small output images is not necessary. | 123 // Visually inspecting very small output images is not necessary. |
| 120 if ((width / fSampleSize <= 10 || height / fSampleSize <= 10) && 1 != fSampl
eSize) { | 124 if ((width / fSampleSize <= 10 || height / fSampleSize <= 10) && 1 != fSampl
eSize) { |
| 121 return Error::Nonfatal("Scaling very small images is uninteresting."); | 125 return Error::Nonfatal("Scaling very small images is uninteresting."); |
| 122 } | 126 } |
| 123 switch (fMode) { | 127 switch (fMode) { |
| 124 case kFullImage_Mode: { | 128 case kFullImage_Mode: { |
| 125 SkAutoTDelete<SkBitmap> bitmap(brd->decodeRegion(0, 0, width, height
, fSampleSize, | 129 SkAutoTDelete<SkBitmap> bitmap(brd->decodeRegion(0, 0, width, height
, fSampleSize, |
| 126 colorType)); | 130 colorType)); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 // let the GPU handle it. | 241 // let the GPU handle it. |
| 238 return flags.type != SinkFlags::kRaster | 242 return flags.type != SinkFlags::kRaster |
| 239 || flags.approach != SinkFlags::kDirect; | 243 || flags.approach != SinkFlags::kDirect; |
| 240 } | 244 } |
| 241 | 245 |
| 242 Error CodecSrc::draw(SkCanvas* canvas) const { | 246 Error CodecSrc::draw(SkCanvas* canvas) const { |
| 243 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 247 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
| 244 if (!encoded) { | 248 if (!encoded) { |
| 245 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); | 249 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); |
| 246 } | 250 } |
| 247 SkAutoTDelete<SkCodec> codec(NULL); | 251 SkAutoTDelete<SkCodec> codec(nullptr); |
| 248 if (kScaledCodec_Mode == fMode) { | 252 if (kScaledCodec_Mode == fMode) { |
| 249 codec.reset(SkScaledCodec::NewFromData(encoded)); | 253 codec.reset(SkScaledCodec::NewFromData(encoded)); |
| 250 // TODO (msarett): This should fall through to a fatal error once we sup
port scaled | 254 // TODO (msarett): This should fall through to a fatal error once we sup
port scaled |
| 251 // codecs for all image types. | 255 // codecs for all image types. |
| 252 if (nullptr == codec.get()) { | 256 if (nullptr == codec.get()) { |
| 253 return Error::Nonfatal(SkStringPrintf("Couldn't create scaled codec
for %s.", | 257 return Error::Nonfatal(SkStringPrintf("Couldn't create scaled codec
for %s.", |
| 254 fPath.c_str())); | 258 fPath.c_str())); |
| 255 } | 259 } |
| 256 } else { | 260 } else { |
| 257 codec.reset(SkCodec::NewFromData(encoded)); | 261 codec.reset(SkCodec::NewFromData(encoded)); |
| (...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1202 skr.visit<void>(i, drawsAsSingletonPictures); | 1206 skr.visit<void>(i, drawsAsSingletonPictures); |
| 1203 } | 1207 } |
| 1204 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); | 1208 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); |
| 1205 | 1209 |
| 1206 canvas->drawPicture(macroPic); | 1210 canvas->drawPicture(macroPic); |
| 1207 return ""; | 1211 return ""; |
| 1208 }); | 1212 }); |
| 1209 } | 1213 } |
| 1210 | 1214 |
| 1211 } // namespace DM | 1215 } // namespace DM |
| OLD | NEW |