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

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: 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') | no next file » | 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; 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
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
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
OLDNEW
« no previous file with comments | « dm/DMSrcSink.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698