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

Side by Side Diff: dm/DMSrcSink.cpp

Issue 1718273004: Add an SkImageGeneratorCG (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Use CGCopyProperties to perform a deferred decode Created 4 years, 9 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') | gyp/ports.gyp » ('j') | gyp/ports.gyp » ('J')
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 "SkAndroidCodec.h" 9 #include "SkAndroidCodec.h"
10 #include "SkCodec.h" 10 #include "SkCodec.h"
11 #include "SkCodecImageGenerator.h" 11 #include "SkCodecImageGenerator.h"
12 #include "SkCommonFlags.h" 12 #include "SkCommonFlags.h"
13 #include "SkData.h" 13 #include "SkData.h"
14 #include "SkDocument.h" 14 #include "SkDocument.h"
15 #include "SkError.h" 15 #include "SkError.h"
16 #include "SkImageGenerator.h" 16 #include "SkImageGenerator.h"
17 #include "SkImageGeneratorCG.h"
17 #include "SkMallocPixelRef.h" 18 #include "SkMallocPixelRef.h"
18 #include "SkMultiPictureDraw.h" 19 #include "SkMultiPictureDraw.h"
19 #include "SkNullCanvas.h" 20 #include "SkNullCanvas.h"
20 #include "SkOSFile.h" 21 #include "SkOSFile.h"
21 #include "SkOpts.h" 22 #include "SkOpts.h"
22 #include "SkPictureData.h" 23 #include "SkPictureData.h"
23 #include "SkPictureRecorder.h" 24 #include "SkPictureRecorder.h"
24 #include "SkRandom.h" 25 #include "SkRandom.h"
25 #include "SkRecordDraw.h" 26 #include "SkRecordDraw.h"
26 #include "SkRecorder.h" 27 #include "SkRecorder.h"
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 float scale) 258 float scale)
258 : fPath(path) 259 : fPath(path)
259 , fMode(mode) 260 , fMode(mode)
260 , fDstColorType(dstColorType) 261 , fDstColorType(dstColorType)
261 , fDstAlphaType(dstAlphaType) 262 , fDstAlphaType(dstAlphaType)
262 , fScale(scale) 263 , fScale(scale)
263 , fRunSerially(serial_from_path_name(path)) 264 , fRunSerially(serial_from_path_name(path))
264 {} 265 {}
265 266
266 bool CodecSrc::veto(SinkFlags flags) const { 267 bool CodecSrc::veto(SinkFlags flags) const {
267 // Test CodecImageGenerator on 8888, 565, and gpu 268 // Test to direct raster backends (8888 and 565).
268 if (kGen_Mode == fMode) {
269 // For image generator, we want to test kDirect approaches for kRaster a nd kGPU,
270 // while skipping everything else.
271 return (flags.type != SinkFlags::kRaster && flags.type != SinkFlags::kGP U) ||
272 flags.approach != SinkFlags::kDirect;
273 }
274
275 // Test all other modes to direct raster backends (8888 and 565).
276 return flags.type != SinkFlags::kRaster || flags.approach != SinkFlags::kDir ect; 269 return flags.type != SinkFlags::kRaster || flags.approach != SinkFlags::kDir ect;
277 } 270 }
278 271
279 // FIXME: Currently we cannot draw unpremultiplied sources. skbug.com/3338 and s kbug.com/3339. 272 // FIXME: Currently we cannot draw unpremultiplied sources. skbug.com/3338 and s kbug.com/3339.
280 // This allows us to still test unpremultiplied decodes. 273 // This allows us to still test unpremultiplied decodes.
281 void premultiply_if_necessary(SkBitmap& bitmap) { 274 void premultiply_if_necessary(SkBitmap& bitmap) {
282 if (kUnpremul_SkAlphaType != bitmap.alphaType()) { 275 if (kUnpremul_SkAlphaType != bitmap.alphaType()) {
283 return; 276 return;
284 } 277 }
285 278
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 kOpaque_SkAlphaType != decodeInfo->alphaType()) { 320 kOpaque_SkAlphaType != decodeInfo->alphaType()) {
328 return false; 321 return false;
329 } 322 }
330 *decodeInfo = decodeInfo->makeColorType(canvasColorType); 323 *decodeInfo = decodeInfo->makeColorType(canvasColorType);
331 break; 324 break;
332 } 325 }
333 326
334 return true; 327 return true;
335 } 328 }
336 329
337 Error test_gen(SkCanvas* canvas, SkData* data) {
338 SkAutoTDelete<SkImageGenerator> gen = SkCodecImageGenerator::NewFromEncodedC odec(data);
339 if (!gen) {
340 return "Could not create image generator.";
341 }
342
343 // FIXME: The gpu backend does not draw kGray sources correctly. (skbug.com/ 4822)
344 // Currently, we will avoid creating a CodecSrc for this case (see DM.cpp).
345 SkASSERT(kGray_8_SkColorType != gen->getInfo().colorType());
346
347 if (kOpaque_SkAlphaType != gen->getInfo().alphaType() &&
348 kRGB_565_SkColorType == canvas->imageInfo().colorType()) {
349 return Error::Nonfatal("Skip testing non-opaque images to 565.");
350 }
351
352 SkAutoTDelete<SkImage> image(SkImage::NewFromGenerator(gen.detach(), nullptr ));
353 if (!image) {
354 return "Could not create image from codec image generator.";
355 }
356
357 canvas->drawImage(image, 0, 0);
358 return "";
359 }
360
361 Error CodecSrc::draw(SkCanvas* canvas) const { 330 Error CodecSrc::draw(SkCanvas* canvas) const {
362 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); 331 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
363 if (!encoded) { 332 if (!encoded) {
364 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); 333 return SkStringPrintf("Couldn't read %s.", fPath.c_str());
365 } 334 }
366 335
367 // The CodecImageGenerator test does not share much code with the other test s,
368 // so we will handle it in its own function.
369 if (kGen_Mode == fMode) {
370 return test_gen(canvas, encoded);
371 }
372
373 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); 336 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
374 if (nullptr == codec.get()) { 337 if (nullptr == codec.get()) {
375 return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str()); 338 return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str());
376 } 339 }
377 340
378 SkImageInfo decodeInfo = codec->getInfo().makeAlphaType(fDstAlphaType); 341 SkImageInfo decodeInfo = codec->getInfo().makeAlphaType(fDstAlphaType);
379 if (!get_decode_info(&decodeInfo, canvas->imageInfo().colorType(), fDstColor Type)) { 342 if (!get_decode_info(&decodeInfo, canvas->imageInfo().colorType(), fDstColor Type)) {
380 return Error::Nonfatal("Testing non-565 to 565 is uninteresting."); 343 return Error::Nonfatal("Testing non-565 to 565 is uninteresting.");
381 } 344 }
382 345
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 // We will replicate the names used by CodecSrc so that images can 759 // We will replicate the names used by CodecSrc so that images can
797 // be compared in Gold. 760 // be compared in Gold.
798 if (1 == fSampleSize) { 761 if (1 == fSampleSize) {
799 return SkOSPath::Basename(fPath.c_str()); 762 return SkOSPath::Basename(fPath.c_str());
800 } 763 }
801 return get_scaled_name(fPath, 1.0f / (float) fSampleSize); 764 return get_scaled_name(fPath, 1.0f / (float) fSampleSize);
802 } 765 }
803 766
804 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 767 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
805 768
769 ImageGenSrc::ImageGenSrc(Path path, Mode mode)
770 : fPath(path)
771 , fMode(mode)
772 , fRunSerially(serial_from_path_name(path))
773 {}
774
775 bool ImageGenSrc::veto(SinkFlags flags) const {
776 // For image generators, we want to test kDirect approaches for
777 // kRaster and kGPU (8888, 565, gpu).
778 return (flags.type != SinkFlags::kRaster && flags.type != SinkFlags::kGPU) | |
779 flags.approach != SinkFlags::kDirect;
780 }
781
782 Error ImageGenSrc::draw(SkCanvas* canvas) const {
783 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
784 if (!encoded) {
785 return SkStringPrintf("Couldn't read %s.", fPath.c_str());
786 }
787
788 SkAutoTDelete<SkImageGenerator> gen(nullptr);
789 switch (fMode) {
790 case kCodec_Mode:
791 gen.reset(SkCodecImageGenerator::NewFromEncodedCodec(encoded));
792 if (!gen) {
793 return "Could not create codec image generator.";
794 }
795 break;
796 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
797 case kCG_Mode:
798 gen.reset(SkImageGeneratorCG::NewFromEncodedCG(encoded));
799 if (!gen) {
800 return "Could not create CG image generator.";
801 }
802 break;
803 #endif
804 default:
805 SkASSERT(false);
806 return "Invalid image generator mode";
807 }
808
809 // FIXME: The gpu backend does not draw kGray sources correctly. (skbug.com/ 4822)
810 // Currently, we will avoid creating a CodecSrc for this case (see DM.cpp).
811 SkASSERT(kGray_8_SkColorType != gen->getInfo().colorType());
812
813 if (kOpaque_SkAlphaType != gen->getInfo().alphaType() &&
814 kRGB_565_SkColorType == canvas->imageInfo().colorType()) {
815 return Error::Nonfatal("Skip testing non-opaque images to 565.");
816 }
817
818 SkAutoTDelete<SkImage> image(SkImage::NewFromGenerator(gen.detach(), nullptr ));
819 if (!image) {
820 return "Could not create image from codec image generator.";
821 }
822
823 canvas->drawImage(image, 0, 0);
824 return "";
825 }
826
827 SkISize ImageGenSrc::size() const {
828 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
829 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
830 if (nullptr == codec) {
831 return SkISize::Make(0, 0);
832 }
833 return codec->getInfo().dimensions();
834 }
835
836 Name ImageGenSrc::name() const {
837 return SkOSPath::Basename(fPath.c_str());
838 }
839
840 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
841
806 static const SkRect kSKPViewport = {0,0, 1000,1000}; 842 static const SkRect kSKPViewport = {0,0, 1000,1000};
807 843
808 SKPSrc::SKPSrc(Path path) : fPath(path) {} 844 SKPSrc::SKPSrc(Path path) : fPath(path) {}
809 845
810 Error SKPSrc::draw(SkCanvas* canvas) const { 846 Error SKPSrc::draw(SkCanvas* canvas) const {
811 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(fPath.c_str())); 847 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(fPath.c_str()));
812 if (!stream) { 848 if (!stream) {
813 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); 849 return SkStringPrintf("Couldn't read %s.", fPath.c_str());
814 } 850 }
815 SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream)); 851 SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream));
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after
1419 skr.visit<void>(i, drawsAsSingletonPictures); 1455 skr.visit<void>(i, drawsAsSingletonPictures);
1420 } 1456 }
1421 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); 1457 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture());
1422 1458
1423 canvas->drawPicture(macroPic); 1459 canvas->drawPicture(macroPic);
1424 return check_against_reference(bitmap, src, fSink); 1460 return check_against_reference(bitmap, src, fSink);
1425 }); 1461 });
1426 } 1462 }
1427 1463
1428 } // namespace DM 1464 } // namespace DM
OLDNEW
« no previous file with comments | « dm/DMSrcSink.h ('k') | gyp/ports.gyp » ('j') | gyp/ports.gyp » ('J')

Powered by Google App Engine
This is Rietveld 408576698