| 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 "SkAndroidCodec.h" | 9 #include "SkAndroidCodec.h" |
| 10 #include "SkCodec.h" | 10 #include "SkCodec.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "SkXMLWriter.h" | 31 #include "SkXMLWriter.h" |
| 32 #include "SkSwizzler.h" | 32 #include "SkSwizzler.h" |
| 33 #include <functional> | 33 #include <functional> |
| 34 | 34 |
| 35 #ifdef SK_MOJO | 35 #ifdef SK_MOJO |
| 36 #include "SkMojo.mojom.h" | 36 #include "SkMojo.mojom.h" |
| 37 #endif | 37 #endif |
| 38 | 38 |
| 39 DEFINE_bool(multiPage, false, "For document-type backends, render the source" | 39 DEFINE_bool(multiPage, false, "For document-type backends, render the source" |
| 40 " into multiple pages"); | 40 " into multiple pages"); |
| 41 #ifdef SK_CODEC_DECODES_RAW |
| 42 DEFINE_bool(RAW_threading, true, "Allow RAW decodes to run on multiple threads?"
); |
| 43 #endif |
| 41 | 44 |
| 42 static bool lazy_decode_bitmap(const void* src, size_t size, SkBitmap* dst) { | 45 static bool lazy_decode_bitmap(const void* src, size_t size, SkBitmap* dst) { |
| 43 SkAutoTUnref<SkData> encoded(SkData::NewWithCopy(src, size)); | 46 SkAutoTUnref<SkData> encoded(SkData::NewWithCopy(src, size)); |
| 44 return encoded && SkDEPRECATED_InstallDiscardablePixelRef(encoded, dst); | 47 return encoded && SkDEPRECATED_InstallDiscardablePixelRef(encoded, dst); |
| 45 } | 48 } |
| 46 | 49 |
| 47 namespace DM { | 50 namespace DM { |
| 48 | 51 |
| 52 const char* SkStringExtension(const SkString& string) { |
| 53 int index = string.findLastOf('.'); |
| 54 if (index >= 0 && (size_t) ++index < string.size()) { |
| 55 return &string.c_str()[index]; |
| 56 } |
| 57 return ""; |
| 58 } |
| 59 |
| 49 GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {} | 60 GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {} |
| 50 | 61 |
| 51 Error GMSrc::draw(SkCanvas* canvas) const { | 62 Error GMSrc::draw(SkCanvas* canvas) const { |
| 52 SkAutoTDelete<skiagm::GM> gm(fFactory(nullptr)); | 63 SkAutoTDelete<skiagm::GM> gm(fFactory(nullptr)); |
| 53 canvas->concat(gm->getInitialTransform()); | 64 canvas->concat(gm->getInitialTransform()); |
| 54 gm->draw(canvas); | 65 gm->draw(canvas); |
| 55 return ""; | 66 return ""; |
| 56 } | 67 } |
| 57 | 68 |
| 58 SkISize GMSrc::size() const { | 69 SkISize GMSrc::size() const { |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 // We will replicate the names used by CodecSrc so that images can | 242 // We will replicate the names used by CodecSrc so that images can |
| 232 // be compared in Gold. | 243 // be compared in Gold. |
| 233 if (1 == fSampleSize) { | 244 if (1 == fSampleSize) { |
| 234 return SkOSPath::Basename(fPath.c_str()); | 245 return SkOSPath::Basename(fPath.c_str()); |
| 235 } | 246 } |
| 236 return get_scaled_name(fPath, 1.0f / (float) fSampleSize); | 247 return get_scaled_name(fPath, 1.0f / (float) fSampleSize); |
| 237 } | 248 } |
| 238 | 249 |
| 239 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ | 250 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ |
| 240 | 251 |
| 252 static int enclave_from_path_name(const SkString& path) { |
| 253 #ifdef SK_CODEC_DECODES_RAW |
| 254 if (!FLAGS_RAW_threading) { |
| 255 static const char* const exts[] = { |
| 256 "arw", "cr2", "dng", "nef", "nrw", "orf", "raf", "rw2", "pef", "srw"
, |
| 257 "ARW", "CR2", "DNG", "NEF", "NRW", "ORF", "RAF", "RW2", "PEF", "SRW"
, |
| 258 }; |
| 259 const char* actualExt = SkStringExtension(path); |
| 260 for (auto* ext : exts) { |
| 261 if (0 == strcmp(ext, actualExt)) { |
| 262 return kRAW_Enclave; |
| 263 } |
| 264 } |
| 265 } |
| 266 #endif |
| 267 return kAnyThread_Enclave; |
| 268 } |
| 269 |
| 241 CodecSrc::CodecSrc(Path path, Mode mode, DstColorType dstColorType, SkAlphaType
dstAlphaType, | 270 CodecSrc::CodecSrc(Path path, Mode mode, DstColorType dstColorType, SkAlphaType
dstAlphaType, |
| 242 float scale) | 271 float scale) |
| 243 : fPath(path) | 272 : fPath(path) |
| 244 , fMode(mode) | 273 , fMode(mode) |
| 245 , fDstColorType(dstColorType) | 274 , fDstColorType(dstColorType) |
| 246 , fDstAlphaType(dstAlphaType) | 275 , fDstAlphaType(dstAlphaType) |
| 247 , fScale(scale) | 276 , fScale(scale) |
| 277 , fEnclave(enclave_from_path_name(path)) |
| 248 {} | 278 {} |
| 249 | 279 |
| 250 bool CodecSrc::veto(SinkFlags flags) const { | 280 bool CodecSrc::veto(SinkFlags flags) const { |
| 251 // Test CodecImageGenerator on 8888, 565, and gpu | 281 // Test CodecImageGenerator on 8888, 565, and gpu |
| 252 if (kGen_Mode == fMode) { | 282 if (kGen_Mode == fMode) { |
| 253 return (flags.type != SinkFlags::kRaster || flags.approach != SinkFlags:
:kDirect) && | 283 return (flags.type != SinkFlags::kRaster || flags.approach != SinkFlags:
:kDirect) && |
| 254 flags.type != SinkFlags::kGPU; | 284 flags.type != SinkFlags::kGPU; |
| 255 } | 285 } |
| 256 | 286 |
| 257 // Test all other modes to direct raster backends (8888 and 565). | 287 // Test all other modes to direct raster backends (8888 and 565). |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 | 635 |
| 606 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ | 636 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ |
| 607 | 637 |
| 608 AndroidCodecSrc::AndroidCodecSrc(Path path, Mode mode, CodecSrc::DstColorType ds
tColorType, | 638 AndroidCodecSrc::AndroidCodecSrc(Path path, Mode mode, CodecSrc::DstColorType ds
tColorType, |
| 609 SkAlphaType dstAlphaType, int sampleSize) | 639 SkAlphaType dstAlphaType, int sampleSize) |
| 610 : fPath(path) | 640 : fPath(path) |
| 611 , fMode(mode) | 641 , fMode(mode) |
| 612 , fDstColorType(dstColorType) | 642 , fDstColorType(dstColorType) |
| 613 , fDstAlphaType(dstAlphaType) | 643 , fDstAlphaType(dstAlphaType) |
| 614 , fSampleSize(sampleSize) | 644 , fSampleSize(sampleSize) |
| 645 , fEnclave(enclave_from_path_name(path)) |
| 615 {} | 646 {} |
| 616 | 647 |
| 617 bool AndroidCodecSrc::veto(SinkFlags flags) const { | 648 bool AndroidCodecSrc::veto(SinkFlags flags) const { |
| 618 // No need to test decoding to non-raster or indirect backend. | 649 // No need to test decoding to non-raster or indirect backend. |
| 619 return flags.type != SinkFlags::kRaster | 650 return flags.type != SinkFlags::kRaster |
| 620 || flags.approach != SinkFlags::kDirect; | 651 || flags.approach != SinkFlags::kDirect; |
| 621 } | 652 } |
| 622 | 653 |
| 623 Error AndroidCodecSrc::draw(SkCanvas* canvas) const { | 654 Error AndroidCodecSrc::draw(SkCanvas* canvas) const { |
| 624 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 655 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
| (...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1390 skr.visit<void>(i, drawsAsSingletonPictures); | 1421 skr.visit<void>(i, drawsAsSingletonPictures); |
| 1391 } | 1422 } |
| 1392 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); | 1423 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); |
| 1393 | 1424 |
| 1394 canvas->drawPicture(macroPic); | 1425 canvas->drawPicture(macroPic); |
| 1395 return check_against_reference(bitmap, src, fSink); | 1426 return check_against_reference(bitmap, src, fSink); |
| 1396 }); | 1427 }); |
| 1397 } | 1428 } |
| 1398 | 1429 |
| 1399 } // namespace DM | 1430 } // namespace DM |
| OLD | NEW |