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

Side by Side Diff: dm/DMSrcSink.cpp

Issue 1239953004: Allow Srcs to veto Sinks based on their broad type. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: scroggo Created 5 years, 5 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
« no previous file with comments | « dm/DMSrcSink.h ('k') | tools/dm_flags.json » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
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;
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
82 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); 82 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
83 if (!encoded) { 83 if (!encoded) {
84 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); 84 return SkStringPrintf("Couldn't read %s.", fPath.c_str());
85 } 85 }
86 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); 86 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
87 if (NULL == codec.get()) { 87 if (NULL == codec.get()) {
88 return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str()); 88 return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str());
89 } 89 }
90 90
91 // Choose the color type to decode to 91 // Choose the color type to decode to
92 SkImageInfo decodeInfo = codec->getInfo(); 92 SkImageInfo decodeInfo = codec->getInfo();
93 SkColorType canvasColorType = canvasInfo.colorType(); 93 SkColorType canvasColorType = canvas->imageInfo().colorType();
94 switch (fDstColorType) { 94 switch (fDstColorType) {
95 case kIndex8_Always_DstColorType: 95 case kIndex8_Always_DstColorType:
96 decodeInfo = codec->getInfo().makeColorType(kIndex_8_SkColorType); 96 decodeInfo = codec->getInfo().makeColorType(kIndex_8_SkColorType);
97 if (kRGB_565_SkColorType == canvasColorType) { 97 if (kRGB_565_SkColorType == canvasColorType) {
98 return Error::Nonfatal("Testing non-565 to 565 is uninteresting. "); 98 return Error::Nonfatal("Testing non-565 to 565 is uninteresting. ");
99 } 99 }
100 break; 100 break;
101 case kGrayscale_Always_DstColorType: 101 case kGrayscale_Always_DstColorType:
102 decodeInfo = codec->getInfo().makeColorType(kGray_8_SkColorType); 102 decodeInfo = codec->getInfo().makeColorType(kGray_8_SkColorType);
103 if (kRGB_565_SkColorType == canvasColorType) { 103 if (kRGB_565_SkColorType == canvasColorType) {
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 return SkOSPath::Basename(fPath.c_str()); 375 return SkOSPath::Basename(fPath.c_str());
376 } else { 376 } else {
377 return SkStringPrintf("%s_%.3f", SkOSPath::Basename(fPath.c_str()).c_str (), fScale); 377 return SkStringPrintf("%s_%.3f", SkOSPath::Basename(fPath.c_str()).c_str (), fScale);
378 } 378 }
379 } 379 }
380 380
381 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 381 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
382 382
383 ImageSrc::ImageSrc(Path path, int divisor) : fPath(path), fDivisor(divisor) {} 383 ImageSrc::ImageSrc(Path path, int divisor) : fPath(path), fDivisor(divisor) {}
384 384
385 bool ImageSrc::veto(SinkType type) const {
386 // No need to test decoding to non-raster backend.
387 // TODO: Instead, use lazy decoding to allow the GPU to handle cases like YU V.
388 return type != kRaster_SinkType;
389 }
390
385 Error ImageSrc::draw(SkCanvas* canvas) const { 391 Error ImageSrc::draw(SkCanvas* canvas) const {
386 SkImageInfo canvasInfo;
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
392 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); 392 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
393 if (!encoded) { 393 if (!encoded) {
394 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); 394 return SkStringPrintf("Couldn't read %s.", fPath.c_str());
395 } 395 }
396 const SkColorType dstColorType = canvasInfo.colorType(); 396 const SkColorType dstColorType = canvas->imageInfo().colorType();
397 if (fDivisor == 0) { 397 if (fDivisor == 0) {
398 // Decode the full image. 398 // Decode the full image.
399 SkBitmap bitmap; 399 SkBitmap bitmap;
400 if (!SkImageDecoder::DecodeMemory(encoded->data(), encoded->size(), &bit map, 400 if (!SkImageDecoder::DecodeMemory(encoded->data(), encoded->size(), &bit map,
401 dstColorType, SkImageDecoder::kDecodeP ixels_Mode)) { 401 dstColorType, SkImageDecoder::kDecodeP ixels_Mode)) {
402 return SkStringPrintf("Couldn't decode %s.", fPath.c_str()); 402 return SkStringPrintf("Couldn't decode %s.", fPath.c_str());
403 } 403 }
404 if (kRGB_565_SkColorType == dstColorType && !bitmap.isOpaque()) { 404 if (kRGB_565_SkColorType == dstColorType && !bitmap.isOpaque()) {
405 // Do not draw a bitmap with alpha to a destination without alpha. 405 // 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."); 406 return Error::Nonfatal("Uninteresting to decode image with alpha int o 565.");
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 skr.visit<void>(i, drawsAsSingletonPictures); 989 skr.visit<void>(i, drawsAsSingletonPictures);
990 } 990 }
991 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); 991 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture());
992 992
993 canvas->drawPicture(macroPic); 993 canvas->drawPicture(macroPic);
994 return ""; 994 return "";
995 }); 995 });
996 } 996 }
997 997
998 } // namespace DM 998 } // namespace DM
OLDNEW
« no previous file with comments | « dm/DMSrcSink.h ('k') | tools/dm_flags.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698