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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 if (NULL == canvas->peekPixels(&canvasInfo, NULL)) { | 77 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 // 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 // let the GPU handle it. |
79 return Error::Nonfatal("No need to test decoding to non-raster backend."
); | 80 return Error::Nonfatal("No need to test decoding to non-raster backend."
); |
80 } | 81 } |
81 | 82 |
82 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 83 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
83 if (!encoded) { | 84 if (!encoded) { |
84 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); | 85 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); |
85 } | 86 } |
86 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); | 87 SkAutoTDelete<SkCodec> codec(SkScaledCodec::NewFromData(encoded)); |
87 if (NULL == codec.get()) { | 88 if (NULL == codec.get()) { |
88 return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str()); | 89 return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str()); |
89 } | 90 } |
90 | 91 |
91 // Choose the color type to decode to | 92 // Choose the color type to decode to |
92 SkImageInfo decodeInfo = codec->getInfo(); | 93 SkImageInfo decodeInfo = codec->getInfo(); |
93 SkColorType canvasColorType = canvasInfo.colorType(); | 94 SkColorType canvasColorType = canvasInfo.colorType(); |
94 switch (fDstColorType) { | 95 switch (fDstColorType) { |
95 case kIndex8_Always_DstColorType: | 96 case kIndex8_Always_DstColorType: |
96 decodeInfo = codec->getInfo().makeColorType(kIndex_8_SkColorType); | 97 decodeInfo = codec->getInfo().makeColorType(kIndex_8_SkColorType); |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 left += decodeInfo.width(); | 432 left += decodeInfo.width(); |
432 } | 433 } |
433 return ""; | 434 return ""; |
434 } | 435 } |
435 } | 436 } |
436 return ""; | 437 return ""; |
437 } | 438 } |
438 | 439 |
439 SkISize CodecSrc::size() const { | 440 SkISize CodecSrc::size() const { |
440 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 441 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
441 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); | 442 SkAutoTDelete<SkCodec> codec(SkScaledCodec::NewFromData(encoded)); |
442 if (NULL != codec) { | 443 if (NULL != codec) { |
443 SkISize size = codec->getScaledDimensions(fScale); | 444 SkISize size = codec->getScaledDimensions(fScale); |
444 return size; | 445 return size; |
445 } else { | 446 } else { |
446 return SkISize::Make(0, 0); | 447 return SkISize::Make(0, 0); |
447 } | 448 } |
448 } | 449 } |
449 | 450 |
450 Name CodecSrc::name() const { | 451 Name CodecSrc::name() const { |
451 if (1.0f == fScale) { | 452 if (1.0f == fScale) { |
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1066 skr.visit<void>(i, drawsAsSingletonPictures); | 1067 skr.visit<void>(i, drawsAsSingletonPictures); |
1067 } | 1068 } |
1068 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); | 1069 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); |
1069 | 1070 |
1070 canvas->drawPicture(macroPic); | 1071 canvas->drawPicture(macroPic); |
1071 return ""; | 1072 return ""; |
1072 }); | 1073 }); |
1073 } | 1074 } |
1074 | 1075 |
1075 } // namespace DM | 1076 } // namespace DM |
OLD | NEW |