| 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 "Resources.h" | 9 #include "Resources.h" |
| 10 #include "SkAndroidCodec.h" | 10 #include "SkAndroidCodec.h" |
| 11 #include "SkCodec.h" | 11 #include "SkCodec.h" |
| 12 #include "SkCodecImageGenerator.h" | 12 #include "SkCodecImageGenerator.h" |
| 13 #include "SkColorSpace.h" | 13 #include "SkColorSpace.h" |
| 14 #include "SkColorSpace_Base.h" | 14 #include "SkColorSpace_Base.h" |
| 15 #include "SkColorSpaceXform.h" | 15 #include "SkColorSpaceXform.h" |
| 16 #include "SkCommonFlags.h" | 16 #include "SkCommonFlags.h" |
| 17 #include "SkData.h" | 17 #include "SkData.h" |
| 18 #include "SkDeferredCanvas.h" |
| 18 #include "SkDocument.h" | 19 #include "SkDocument.h" |
| 19 #include "SkError.h" | 20 #include "SkError.h" |
| 20 #include "SkImageGenerator.h" | 21 #include "SkImageGenerator.h" |
| 21 #include "SkImageGeneratorCG.h" | 22 #include "SkImageGeneratorCG.h" |
| 22 #include "SkImageGeneratorWIC.h" | 23 #include "SkImageGeneratorWIC.h" |
| 23 #include "SkMallocPixelRef.h" | 24 #include "SkMallocPixelRef.h" |
| 24 #include "SkMultiPictureDraw.h" | 25 #include "SkMultiPictureDraw.h" |
| 25 #include "SkNullCanvas.h" | 26 #include "SkNullCanvas.h" |
| 26 #include "SkOSFile.h" | 27 #include "SkOSFile.h" |
| 27 #include "SkOpts.h" | 28 #include "SkOpts.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 42 #endif | 43 #endif |
| 43 | 44 |
| 44 #if defined(SK_TEST_QCMS) | 45 #if defined(SK_TEST_QCMS) |
| 45 #include "qcms.h" | 46 #include "qcms.h" |
| 46 #endif | 47 #endif |
| 47 | 48 |
| 48 DEFINE_bool(multiPage, false, "For document-type backends, render the source" | 49 DEFINE_bool(multiPage, false, "For document-type backends, render the source" |
| 49 " into multiple pages"); | 50 " into multiple pages"); |
| 50 DEFINE_bool(RAW_threading, true, "Allow RAW decodes to run on multiple threads?"
); | 51 DEFINE_bool(RAW_threading, true, "Allow RAW decodes to run on multiple threads?"
); |
| 51 | 52 |
| 53 extern bool gUseDeferredCanvas; |
| 54 |
| 52 using sk_gpu_test::GrContextFactory; | 55 using sk_gpu_test::GrContextFactory; |
| 53 | 56 |
| 54 namespace DM { | 57 namespace DM { |
| 55 | 58 |
| 56 GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {} | 59 GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {} |
| 57 | 60 |
| 58 Error GMSrc::draw(SkCanvas* canvas) const { | 61 Error GMSrc::draw(SkCanvas* canvas) const { |
| 59 SkAutoTDelete<skiagm::GM> gm(fFactory(nullptr)); | 62 SkAutoTDelete<skiagm::GM> gm(fFactory(nullptr)); |
| 60 canvas->concat(gm->getInitialTransform()); | 63 canvas->concat(gm->getInitialTransform()); |
| 61 gm->draw(canvas); | 64 gm->draw(canvas); |
| (...skipping 1160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1222 // If there's an appropriate alpha type for this color type, use it, otherwi
se use premul. | 1225 // If there's an appropriate alpha type for this color type, use it, otherwi
se use premul. |
| 1223 SkAlphaType alphaType = kPremul_SkAlphaType; | 1226 SkAlphaType alphaType = kPremul_SkAlphaType; |
| 1224 (void)SkColorTypeValidateAlphaType(fColorType, alphaType, &alphaType); | 1227 (void)SkColorTypeValidateAlphaType(fColorType, alphaType, &alphaType); |
| 1225 | 1228 |
| 1226 SkMallocPixelRef::ZeroedPRFactory factory; | 1229 SkMallocPixelRef::ZeroedPRFactory factory; |
| 1227 dst->allocPixels(SkImageInfo::Make(size.width(), size.height(), | 1230 dst->allocPixels(SkImageInfo::Make(size.width(), size.height(), |
| 1228 fColorType, alphaType, fColorSpace), | 1231 fColorType, alphaType, fColorSpace), |
| 1229 &factory, | 1232 &factory, |
| 1230 nullptr/*colortable*/); | 1233 nullptr/*colortable*/); |
| 1231 SkCanvas canvas(*dst); | 1234 SkCanvas canvas(*dst); |
| 1232 return src.draw(&canvas); | 1235 SkDeferredCanvas deferred(&canvas); |
| 1236 return src.draw(gUseDeferredCanvas ? &deferred : &canvas); |
| 1233 } | 1237 } |
| 1234 | 1238 |
| 1235 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ | 1239 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ |
| 1236 | 1240 |
| 1237 // Handy for front-patching a Src. Do whatever up-front work you need, then cal
l draw_to_canvas(), | 1241 // Handy for front-patching a Src. Do whatever up-front work you need, then cal
l draw_to_canvas(), |
| 1238 // passing the Sink draw() arguments, a size, and a function draws into an SkCan
vas. | 1242 // passing the Sink draw() arguments, a size, and a function draws into an SkCan
vas. |
| 1239 // Several examples below. | 1243 // Several examples below. |
| 1240 | 1244 |
| 1241 template <typename Fn> | 1245 template <typename Fn> |
| 1242 static Error draw_to_canvas(Sink* sink, SkBitmap* bitmap, SkWStream* stream, SkS
tring* log, | 1246 static Error draw_to_canvas(Sink* sink, SkBitmap* bitmap, SkWStream* stream, SkS
tring* log, |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1393 // surfaces.setReserve(xTiles*yTiles); | 1397 // surfaces.setReserve(xTiles*yTiles); |
| 1394 | 1398 |
| 1395 SkImageInfo info = canvas->imageInfo().makeWH(fW, fH); | 1399 SkImageInfo info = canvas->imageInfo().makeWH(fW, fH); |
| 1396 for (int j = 0; j < yTiles; j++) { | 1400 for (int j = 0; j < yTiles; j++) { |
| 1397 for (int i = 0; i < xTiles; i++) { | 1401 for (int i = 0; i < xTiles; i++) { |
| 1398 // This lets our ultimate Sink determine the best kind of surfac
e. | 1402 // This lets our ultimate Sink determine the best kind of surfac
e. |
| 1399 // E.g., if it's a GpuSink, the surfaces and images are textures
. | 1403 // E.g., if it's a GpuSink, the surfaces and images are textures
. |
| 1400 auto s = canvas->makeSurface(info); | 1404 auto s = canvas->makeSurface(info); |
| 1401 if (!s) { | 1405 if (!s) { |
| 1402 s = SkSurface::MakeRaster(info); // Some canvases can't cre
ate surfaces. | 1406 s = SkSurface::MakeRaster(info); // Some canvases can't cre
ate surfaces. |
| 1407 if (!s) { |
| 1408 // non-pixel canvases return unknown colortype, which wo
uld make |
| 1409 // makesurface fail, so assume that is why we failed, an
d use N32. |
| 1410 SkASSERT(kUnknown_SkColorType == info.colorType()); |
| 1411 info = SkImageInfo::MakeN32Premul(info.width(), info.hei
ght()); |
| 1412 s = SkSurface::MakeRaster(info); |
| 1413 } |
| 1403 } | 1414 } |
| 1404 surfaces.push_back(s); | 1415 surfaces.push_back(s); |
| 1405 SkCanvas* c = s->getCanvas(); | 1416 SkCanvas* c = s->getCanvas(); |
| 1406 c->translate(SkIntToScalar(-i * fW), | 1417 c->translate(SkIntToScalar(-i * fW), |
| 1407 SkIntToScalar(-j * fH)); // Line up the canvas wit
h this tile. | 1418 SkIntToScalar(-j * fH)); // Line up the canvas wit
h this tile. |
| 1408 mpd.add(c, pic.get()); | 1419 mpd.add(c, pic.get()); |
| 1409 } | 1420 } |
| 1410 } | 1421 } |
| 1411 mpd.draw(); | 1422 mpd.draw(); |
| 1412 for (int j = 0; j < yTiles; j++) { | 1423 for (int j = 0; j < yTiles; j++) { |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1543 skr.visit(i, drawsAsSingletonPictures); | 1554 skr.visit(i, drawsAsSingletonPictures); |
| 1544 } | 1555 } |
| 1545 sk_sp<SkPicture> macroPic(macroRec.finishRecordingAsPicture()); | 1556 sk_sp<SkPicture> macroPic(macroRec.finishRecordingAsPicture()); |
| 1546 | 1557 |
| 1547 canvas->drawPicture(macroPic); | 1558 canvas->drawPicture(macroPic); |
| 1548 return check_against_reference(bitmap, src, fSink); | 1559 return check_against_reference(bitmap, src, fSink); |
| 1549 }); | 1560 }); |
| 1550 } | 1561 } |
| 1551 | 1562 |
| 1552 } // namespace DM | 1563 } // namespace DM |
| OLD | NEW |