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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 | 64 |
65 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ | 65 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ |
66 | 66 |
67 CodecSrc::CodecSrc(Path path, Mode mode, DstColorType dstColorType, float scale) | 67 CodecSrc::CodecSrc(Path path, Mode mode, DstColorType dstColorType, float scale) |
68 : fPath(path) | 68 : fPath(path) |
69 , fMode(mode) | 69 , fMode(mode) |
70 , fDstColorType(dstColorType) | 70 , fDstColorType(dstColorType) |
71 , fScale(scale) | 71 , fScale(scale) |
72 {} | 72 {} |
73 | 73 |
74 bool CodecSrc::veto(SinkType type) const { | |
75 // No need to test decoding to non-raster backend. | |
76 // TODO: Once we implement GPU paths (e.g. JPEG YUV), we should use a deferr ed decode to | |
77 // let the GPU handle it. | |
78 return type != kRaster_SinkType; | |
79 } | |
80 | |
74 Error CodecSrc::draw(SkCanvas* canvas) const { | 81 Error CodecSrc::draw(SkCanvas* canvas) const { |
75 SkImageInfo canvasInfo; | 82 SkImageInfo canvasInfo = canvas->imageInfo(); |
scroggo
2015/07/17 14:10:48
nit: We now only use canvasInfo once, down below.
| |
76 if (NULL == canvas->peekPixels(&canvasInfo, NULL)) { | |
77 // TODO: Once we implement GPU paths (e.g. JPEG YUV), we should use a de ferred decode to | |
78 // let the GPU handle it. | |
79 return Error::Nonfatal("No need to test decoding to non-raster backend." ); | |
80 } | |
81 | 83 |
82 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 84 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
83 if (!encoded) { | 85 if (!encoded) { |
84 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); | 86 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); |
85 } | 87 } |
86 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); | 88 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
87 if (NULL == codec.get()) { | 89 if (NULL == codec.get()) { |
88 return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str()); | 90 return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str()); |
89 } | 91 } |
90 | 92 |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
375 return SkOSPath::Basename(fPath.c_str()); | 377 return SkOSPath::Basename(fPath.c_str()); |
376 } else { | 378 } else { |
377 return SkStringPrintf("%s_%.3f", SkOSPath::Basename(fPath.c_str()).c_str (), fScale); | 379 return SkStringPrintf("%s_%.3f", SkOSPath::Basename(fPath.c_str()).c_str (), fScale); |
378 } | 380 } |
379 } | 381 } |
380 | 382 |
381 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ | 383 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ |
382 | 384 |
383 ImageSrc::ImageSrc(Path path, int divisor) : fPath(path), fDivisor(divisor) {} | 385 ImageSrc::ImageSrc(Path path, int divisor) : fPath(path), fDivisor(divisor) {} |
384 | 386 |
387 bool ImageSrc::veto(SinkType type) const { | |
388 // No need to test decoding to non-raster backend. | |
389 // TODO: Instead, use lazy decoding to allow the GPU to handle cases like YU V. | |
390 return type != kRaster_SinkType; | |
391 } | |
392 | |
385 Error ImageSrc::draw(SkCanvas* canvas) const { | 393 Error ImageSrc::draw(SkCanvas* canvas) const { |
386 SkImageInfo canvasInfo; | 394 SkImageInfo canvasInfo = canvas->imageInfo(); |
387 if (NULL == canvas->peekPixels(&canvasInfo, NULL)) { | |
388 // TODO: Instead, use lazy decoding to allow the GPU to handle cases lik e YUV. | |
389 return Error::Nonfatal("No need to test decoding to non-raster backend." ); | |
390 } | |
391 | 395 |
392 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 396 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
393 if (!encoded) { | 397 if (!encoded) { |
394 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); | 398 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); |
395 } | 399 } |
396 const SkColorType dstColorType = canvasInfo.colorType(); | 400 const SkColorType dstColorType = canvasInfo.colorType(); |
scroggo
2015/07/17 14:10:48
Again, canvasInfo is not needed as its own variabl
| |
397 if (fDivisor == 0) { | 401 if (fDivisor == 0) { |
398 // Decode the full image. | 402 // Decode the full image. |
399 SkBitmap bitmap; | 403 SkBitmap bitmap; |
400 if (!SkImageDecoder::DecodeMemory(encoded->data(), encoded->size(), &bit map, | 404 if (!SkImageDecoder::DecodeMemory(encoded->data(), encoded->size(), &bit map, |
401 dstColorType, SkImageDecoder::kDecodeP ixels_Mode)) { | 405 dstColorType, SkImageDecoder::kDecodeP ixels_Mode)) { |
402 return SkStringPrintf("Couldn't decode %s.", fPath.c_str()); | 406 return SkStringPrintf("Couldn't decode %s.", fPath.c_str()); |
403 } | 407 } |
404 if (kRGB_565_SkColorType == dstColorType && !bitmap.isOpaque()) { | 408 if (kRGB_565_SkColorType == dstColorType && !bitmap.isOpaque()) { |
405 // Do not draw a bitmap with alpha to a destination without alpha. | 409 // Do not draw a bitmap with alpha to a destination without alpha. |
406 return Error::Nonfatal("Uninteresting to decode image with alpha int o 565."); | 410 return Error::Nonfatal("Uninteresting to decode image with alpha int o 565."); |
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
989 skr.visit<void>(i, drawsAsSingletonPictures); | 993 skr.visit<void>(i, drawsAsSingletonPictures); |
990 } | 994 } |
991 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); | 995 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); |
992 | 996 |
993 canvas->drawPicture(macroPic); | 997 canvas->drawPicture(macroPic); |
994 return ""; | 998 return ""; |
995 }); | 999 }); |
996 } | 1000 } |
997 | 1001 |
998 } // namespace DM | 1002 } // namespace DM |
OLD | NEW |