Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: dm/DMSrcSink.cpp

Issue 1260673002: SkScaledCodec class (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add get_row_bytes function to SkJpegCodec Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str());
90 } 91 }
91 92
92 // Choose the color type to decode to 93 // Choose the color type to decode to
93 SkImageInfo decodeInfo = codec->getInfo(); 94 SkImageInfo decodeInfo = codec->getInfo();
94 SkColorType canvasColorType = canvas->imageInfo().colorType(); 95 SkColorType canvasColorType = canvas->imageInfo().colorType();
95 switch (fDstColorType) { 96 switch (fDstColorType) {
96 case kIndex8_Always_DstColorType: 97 case kIndex8_Always_DstColorType:
97 decodeInfo = codec->getInfo().makeColorType(kIndex_8_SkColorType); 98 decodeInfo = codec->getInfo().makeColorType(kIndex_8_SkColorType);
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 left += decodeInfo.width(); 434 left += decodeInfo.width();
434 } 435 }
435 return ""; 436 return "";
436 } 437 }
437 } 438 }
438 return ""; 439 return "";
439 } 440 }
440 441
441 SkISize CodecSrc::size() const { 442 SkISize CodecSrc::size() const {
442 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); 443 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
443 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); 444 SkAutoTDelete<SkCodec> codec(SkScaledCodec::NewFromData(encoded));
444 if (NULL != codec) { 445 if (NULL != codec) {
445 SkISize size = codec->getScaledDimensions(fScale); 446 SkISize size = codec->getScaledDimensions(fScale);
446 return size; 447 return size;
447 } else { 448 } else {
448 return SkISize::Make(0, 0); 449 return SkISize::Make(0, 0);
449 } 450 }
450 } 451 }
451 452
452 Name CodecSrc::name() const { 453 Name CodecSrc::name() const {
453 if (1.0f == fScale) { 454 if (1.0f == fScale) {
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after
1069 skr.visit<void>(i, drawsAsSingletonPictures); 1070 skr.visit<void>(i, drawsAsSingletonPictures);
1070 } 1071 }
1071 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); 1072 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture());
1072 1073
1073 canvas->drawPicture(macroPic); 1074 canvas->drawPicture(macroPic);
1074 return ""; 1075 return "";
1075 }); 1076 });
1076 } 1077 }
1077 1078
1078 } // namespace DM 1079 } // namespace DM
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698