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" |
11 #include "SkCommonFlags.h" | 11 #include "SkCommonFlags.h" |
12 #include "SkData.h" | 12 #include "SkData.h" |
13 #include "SkDeferredCanvas.h" | 13 #include "SkDeferredCanvas.h" |
14 #include "SkDocument.h" | 14 #include "SkDocument.h" |
15 #include "SkError.h" | 15 #include "SkError.h" |
16 #include "SkFunction.h" | 16 #include "SkFunction.h" |
17 #include "SkImageGenerator.h" | 17 #include "SkImageGenerator.h" |
18 #include "SkMultiPictureDraw.h" | 18 #include "SkMultiPictureDraw.h" |
19 #include "SkNullCanvas.h" | 19 #include "SkNullCanvas.h" |
20 #include "SkOSFile.h" | 20 #include "SkOSFile.h" |
21 #include "SkPictureData.h" | 21 #include "SkPictureData.h" |
22 #include "SkPictureRecorder.h" | 22 #include "SkPictureRecorder.h" |
23 #include "SkRandom.h" | 23 #include "SkRandom.h" |
24 #include "SkRecordDraw.h" | 24 #include "SkRecordDraw.h" |
25 #include "SkRecorder.h" | 25 #include "SkRecorder.h" |
26 #include "SkSVGCanvas.h" | 26 #include "SkSVGCanvas.h" |
27 #include "SkScanlineDecoder.h" | 27 #include "SkScanlineDecoder.h" |
28 #include "SkStream.h" | 28 #include "SkStream.h" |
29 #include "SkXMLWriter.h" | 29 #include "SkXMLWriter.h" |
| 30 #include "SkScaledCodec.h" |
30 | 31 |
31 DEFINE_bool(multiPage, false, "For document-type backends, render the source" | 32 DEFINE_bool(multiPage, false, "For document-type backends, render the source" |
32 " into multiple pages"); | 33 " into multiple pages"); |
33 | 34 |
34 static bool lazy_decode_bitmap(const void* src, size_t size, SkBitmap* dst) { | 35 static bool lazy_decode_bitmap(const void* src, size_t size, SkBitmap* dst) { |
35 SkAutoTUnref<SkData> encoded(SkData::NewWithCopy(src, size)); | 36 SkAutoTUnref<SkData> encoded(SkData::NewWithCopy(src, size)); |
36 return encoded && SkInstallDiscardablePixelRef(encoded, dst); | 37 return encoded && SkInstallDiscardablePixelRef(encoded, dst); |
37 } | 38 } |
38 | 39 |
39 namespace DM { | 40 namespace DM { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 // let the GPU handle it. | 78 // let the GPU handle it. |
78 return flags.type != SinkFlags::kRaster | 79 return flags.type != SinkFlags::kRaster |
79 || flags.approach != SinkFlags::kDirect; | 80 || flags.approach != SinkFlags::kDirect; |
80 } | 81 } |
81 | 82 |
82 Error CodecSrc::draw(SkCanvas* canvas) const { | 83 Error CodecSrc::draw(SkCanvas* canvas) const { |
83 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 84 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
84 if (!encoded) { | 85 if (!encoded) { |
85 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); | 86 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); |
86 } | 87 } |
87 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); | 88 SkAutoTDelete<SkCodec> codec(SkScaledCodec::NewFromData(encoded)); |
88 if (NULL == codec.get()) { | 89 if (NULL == codec.get()) { |
89 return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str()); | 90 // scaledCodec not supported, try normal codec |
| 91 codec.reset(SkCodec::NewFromData(encoded)); |
| 92 if (NULL == codec.get()) { |
| 93 return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str()
); |
| 94 } |
90 } | 95 } |
91 | 96 |
92 // Choose the color type to decode to | 97 // Choose the color type to decode to |
93 SkImageInfo decodeInfo = codec->getInfo(); | 98 SkImageInfo decodeInfo = codec->getInfo(); |
94 SkColorType canvasColorType = canvas->imageInfo().colorType(); | 99 SkColorType canvasColorType = canvas->imageInfo().colorType(); |
95 switch (fDstColorType) { | 100 switch (fDstColorType) { |
96 case kIndex8_Always_DstColorType: | 101 case kIndex8_Always_DstColorType: |
97 decodeInfo = codec->getInfo().makeColorType(kIndex_8_SkColorType); | 102 decodeInfo = codec->getInfo().makeColorType(kIndex_8_SkColorType); |
98 if (kRGB_565_SkColorType == canvasColorType) { | 103 if (kRGB_565_SkColorType == canvasColorType) { |
99 return Error::Nonfatal("Testing non-565 to 565 is uninteresting.
"); | 104 return Error::Nonfatal("Testing non-565 to 565 is uninteresting.
"); |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 left += decodeInfo.width(); | 444 left += decodeInfo.width(); |
440 } | 445 } |
441 return ""; | 446 return ""; |
442 } | 447 } |
443 } | 448 } |
444 return ""; | 449 return ""; |
445 } | 450 } |
446 | 451 |
447 SkISize CodecSrc::size() const { | 452 SkISize CodecSrc::size() const { |
448 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 453 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
449 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); | 454 SkAutoTDelete<SkCodec> codec(SkScaledCodec::NewFromData(encoded)); |
450 if (NULL != codec) { | 455 if (NULL == codec) { |
451 SkISize size = codec->getScaledDimensions(fScale); | 456 // scaledCodec not supported, try regular codec |
452 return size; | 457 codec.reset(SkCodec::NewFromData(encoded)); |
453 } else { | 458 if (NULL == codec) { |
454 return SkISize::Make(0, 0); | 459 return SkISize::Make(0, 0); |
| 460 } |
455 } | 461 } |
| 462 SkISize size = codec->getScaledDimensions(fScale); |
| 463 return size; |
456 } | 464 } |
457 | 465 |
458 Name CodecSrc::name() const { | 466 Name CodecSrc::name() const { |
459 if (1.0f == fScale) { | 467 if (1.0f == fScale) { |
460 return SkOSPath::Basename(fPath.c_str()); | 468 return SkOSPath::Basename(fPath.c_str()); |
461 } else { | 469 } else { |
462 return SkStringPrintf("%s_%.3f", SkOSPath::Basename(fPath.c_str()).c_str
(), fScale); | 470 return SkStringPrintf("%s_%.3f", SkOSPath::Basename(fPath.c_str()).c_str
(), fScale); |
463 } | 471 } |
464 } | 472 } |
465 | 473 |
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1075 skr.visit<void>(i, drawsAsSingletonPictures); | 1083 skr.visit<void>(i, drawsAsSingletonPictures); |
1076 } | 1084 } |
1077 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); | 1085 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); |
1078 | 1086 |
1079 canvas->drawPicture(macroPic); | 1087 canvas->drawPicture(macroPic); |
1080 return ""; | 1088 return ""; |
1081 }); | 1089 }); |
1082 } | 1090 } |
1083 | 1091 |
1084 } // namespace DM | 1092 } // namespace DM |
OLD | NEW |