OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkPDFShader.h" | 10 #include "SkPDFShader.h" |
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
516 SkPDFObject* SkPDFShader::GetPDFShader(SkPDFCanon* canon, | 516 SkPDFObject* SkPDFShader::GetPDFShader(SkPDFCanon* canon, |
517 SkScalar dpi, | 517 SkScalar dpi, |
518 const SkShader& shader, | 518 const SkShader& shader, |
519 const SkMatrix& matrix, | 519 const SkMatrix& matrix, |
520 const SkIRect& surfaceBBox, | 520 const SkIRect& surfaceBBox, |
521 SkScalar rasterScale) { | 521 SkScalar rasterScale) { |
522 SkAutoTDelete<SkPDFShader::State> state(new State(shader, matrix, surfaceBBo x, rasterScale)); | 522 SkAutoTDelete<SkPDFShader::State> state(new State(shader, matrix, surfaceBBo x, rasterScale)); |
523 return get_pdf_shader_by_state(canon, dpi, &state); | 523 return get_pdf_shader_by_state(canon, dpi, &state); |
524 } | 524 } |
525 | 525 |
526 static SkPDFDict* get_gradient_resource_dict( | 526 static sk_sp<SkPDFDict> get_gradient_resource_dict( |
527 SkPDFObject* functionShader, | 527 SkPDFObject* functionShader, |
528 SkPDFObject* gState) { | 528 SkPDFObject* gState = nullptr) { |
bungeman-skia
2016/03/08 19:05:44
Skia doesn't generally like default parameters if
hal.canary
2016/03/08 19:12:51
Done.
| |
529 SkTDArray<SkPDFObject*> patterns; | 529 SkTDArray<SkPDFObject*> patterns; |
530 if (functionShader) { | 530 if (functionShader) { |
531 patterns.push(functionShader); | 531 patterns.push(functionShader); |
532 } | 532 } |
533 SkTDArray<SkPDFObject*> graphicStates; | 533 SkTDArray<SkPDFObject*> graphicStates; |
534 if (gState) { | 534 if (gState) { |
535 graphicStates.push(gState); | 535 graphicStates.push(gState); |
536 } | 536 } |
537 return SkPDFResourceDict::Create(&graphicStates, &patterns, nullptr, nullptr ); | 537 return SkPDFResourceDict::Make(&graphicStates, &patterns, nullptr, nullptr); |
538 } | 538 } |
539 | 539 |
540 static void populate_tiling_pattern_dict(SkPDFDict* pattern, | 540 static void populate_tiling_pattern_dict(SkPDFDict* pattern, |
541 SkRect& bbox, | 541 SkRect& bbox, |
542 SkPDFDict* resources, | 542 SkPDFDict* resources, |
543 const SkMatrix& matrix) { | 543 const SkMatrix& matrix) { |
544 const int kTiling_PatternType = 1; | 544 const int kTiling_PatternType = 1; |
545 const int kColoredTilingPattern_PaintType = 1; | 545 const int kColoredTilingPattern_PaintType = 1; |
546 const int kConstantSpacing_TilingType = 1; | 546 const int kConstantSpacing_TilingType = 1; |
547 | 547 |
548 pattern->insertName("Type", "Pattern"); | 548 pattern->insertName("Type", "Pattern"); |
549 pattern->insertInt("PatternType", kTiling_PatternType); | 549 pattern->insertInt("PatternType", kTiling_PatternType); |
550 pattern->insertInt("PaintType", kColoredTilingPattern_PaintType); | 550 pattern->insertInt("PaintType", kColoredTilingPattern_PaintType); |
551 pattern->insertInt("TilingType", kConstantSpacing_TilingType); | 551 pattern->insertInt("TilingType", kConstantSpacing_TilingType); |
552 pattern->insertObject("BBox", SkPDFUtils::RectToArray(bbox)); | 552 pattern->insertObject("BBox", SkPDFUtils::RectToArray(bbox)); |
553 pattern->insertScalar("XStep", bbox.width()); | 553 pattern->insertScalar("XStep", bbox.width()); |
554 pattern->insertScalar("YStep", bbox.height()); | 554 pattern->insertScalar("YStep", bbox.height()); |
555 pattern->insertObject("Resources", SkRef(resources)); | 555 pattern->insertObject("Resources", sk_sp<SkPDFDict>(SkRef(resources))); |
556 if (!matrix.isIdentity()) { | 556 if (!matrix.isIdentity()) { |
557 pattern->insertObject("Matrix", SkPDFUtils::MatrixToArray(matrix)); | 557 pattern->insertObject("Matrix", SkPDFUtils::MatrixToArray(matrix)); |
558 } | 558 } |
559 } | 559 } |
560 | 560 |
561 /** | 561 /** |
562 * Creates a content stream which fills the pattern P0 across bounds. | 562 * Creates a content stream which fills the pattern P0 across bounds. |
563 * @param gsIndex A graphics state resource index to apply, or <0 if no | 563 * @param gsIndex A graphics state resource index to apply, or <0 if no |
564 * graphics state to apply. | 564 * graphics state to apply. |
565 */ | 565 */ |
(...skipping 19 matching lines...) Expand all Loading... | |
585 SkRect bbox; | 585 SkRect bbox; |
586 bbox.set(state.fBBox); | 586 bbox.set(state.fBBox); |
587 | 587 |
588 SkAutoTDelete<SkPDFShader::State> alphaToLuminosityState( | 588 SkAutoTDelete<SkPDFShader::State> alphaToLuminosityState( |
589 state.CreateAlphaToLuminosityState()); | 589 state.CreateAlphaToLuminosityState()); |
590 sk_sp<SkPDFObject> luminosityShader( | 590 sk_sp<SkPDFObject> luminosityShader( |
591 get_pdf_shader_by_state(canon, dpi, &alphaToLuminosityState)); | 591 get_pdf_shader_by_state(canon, dpi, &alphaToLuminosityState)); |
592 | 592 |
593 SkAutoTDelete<SkStream> alphaStream(create_pattern_fill_content(-1, bbox)); | 593 SkAutoTDelete<SkStream> alphaStream(create_pattern_fill_content(-1, bbox)); |
594 | 594 |
595 sk_sp<SkPDFDict> | 595 auto resources = get_gradient_resource_dict(luminosityShader.get()); |
596 resources(get_gradient_resource_dict(luminosityShader.get(), nullptr)); | |
597 | 596 |
598 sk_sp<SkPDFFormXObject> alphaMask( | 597 sk_sp<SkPDFFormXObject> alphaMask( |
599 new SkPDFFormXObject(alphaStream.get(), bbox, resources.get())); | 598 new SkPDFFormXObject(alphaStream.get(), bbox, resources.get())); |
600 | 599 |
601 return SkPDFGraphicState::GetSMaskGraphicState( | 600 return SkPDFGraphicState::GetSMaskGraphicState( |
602 alphaMask.get(), false, | 601 alphaMask.get(), false, |
603 SkPDFGraphicState::kLuminosity_SMaskMode); | 602 SkPDFGraphicState::kLuminosity_SMaskMode); |
604 } | 603 } |
605 | 604 |
606 SkPDFAlphaFunctionShader* SkPDFAlphaFunctionShader::Create( | 605 SkPDFAlphaFunctionShader* SkPDFAlphaFunctionShader::Create( |
(...skipping 13 matching lines...) Expand all Loading... | |
620 } | 619 } |
621 | 620 |
622 // Create resource dict with alpha graphics state as G0 and | 621 // Create resource dict with alpha graphics state as G0 and |
623 // pattern shader as P0, then write content stream. | 622 // pattern shader as P0, then write content stream. |
624 sk_sp<SkPDFObject> alphaGs( | 623 sk_sp<SkPDFObject> alphaGs( |
625 create_smask_graphic_state(canon, dpi, state)); | 624 create_smask_graphic_state(canon, dpi, state)); |
626 | 625 |
627 SkPDFAlphaFunctionShader* alphaFunctionShader = | 626 SkPDFAlphaFunctionShader* alphaFunctionShader = |
628 new SkPDFAlphaFunctionShader(autoState->detach()); | 627 new SkPDFAlphaFunctionShader(autoState->detach()); |
629 | 628 |
630 sk_sp<SkPDFDict> resourceDict( | 629 auto resourceDict = |
631 get_gradient_resource_dict(colorShader.get(), alphaGs.get())); | 630 get_gradient_resource_dict(colorShader.get(), alphaGs.get()); |
632 | 631 |
633 SkAutoTDelete<SkStream> colorStream( | 632 SkAutoTDelete<SkStream> colorStream( |
634 create_pattern_fill_content(0, bbox)); | 633 create_pattern_fill_content(0, bbox)); |
635 alphaFunctionShader->setData(colorStream.get()); | 634 alphaFunctionShader->setData(colorStream.get()); |
636 | 635 |
637 populate_tiling_pattern_dict(alphaFunctionShader, bbox, resourceDict.get(), | 636 populate_tiling_pattern_dict(alphaFunctionShader, bbox, resourceDict.get(), |
638 SkMatrix::I()); | 637 SkMatrix::I()); |
639 canon->addAlphaShader(alphaFunctionShader); | 638 canon->addAlphaShader(alphaFunctionShader); |
640 return alphaFunctionShader; | 639 return alphaFunctionShader; |
641 } | 640 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
690 return range; | 689 return range; |
691 } | 690 } |
692 SK_DECLARE_STATIC_ONCE_PTR(SkPDFObject, rangeObject); | 691 SK_DECLARE_STATIC_ONCE_PTR(SkPDFObject, rangeObject); |
693 | 692 |
694 static SkPDFStream* make_ps_function(const SkString& psCode, | 693 static SkPDFStream* make_ps_function(const SkString& psCode, |
695 SkPDFArray* domain) { | 694 SkPDFArray* domain) { |
696 SkAutoDataUnref funcData( | 695 SkAutoDataUnref funcData( |
697 SkData::NewWithCopy(psCode.c_str(), psCode.size())); | 696 SkData::NewWithCopy(psCode.c_str(), psCode.size())); |
698 SkPDFStream* result = new SkPDFStream(funcData.get()); | 697 SkPDFStream* result = new SkPDFStream(funcData.get()); |
699 result->insertInt("FunctionType", 4); | 698 result->insertInt("FunctionType", 4); |
700 result->insertObject("Domain", SkRef(domain)); | 699 result->insertObject("Domain", sk_sp<SkPDFObject>(SkRef(domain))); |
701 result->insertObject("Range", SkRef(rangeObject.get(create_range_object))); | 700 result->insertObject("Range", sk_sp<SkPDFObject>(SkRef(rangeObject.get(creat e_range_object)))); |
702 return result; | 701 return result; |
703 } | 702 } |
704 | 703 |
705 SkPDFFunctionShader* SkPDFFunctionShader::Create( | 704 SkPDFFunctionShader* SkPDFFunctionShader::Create( |
706 SkPDFCanon* canon, SkAutoTDelete<SkPDFShader::State>* autoState) { | 705 SkPDFCanon* canon, SkAutoTDelete<SkPDFShader::State>* autoState) { |
707 const SkPDFShader::State& state = **autoState; | 706 const SkPDFShader::State& state = **autoState; |
708 | 707 |
709 SkString (*codeFunction)(const SkShader::GradientInfo& info, | 708 SkString (*codeFunction)(const SkShader::GradientInfo& info, |
710 const SkMatrix& perspectiveRemover) = nullptr; | 709 const SkMatrix& perspectiveRemover) = nullptr; |
711 SkPoint transformPoints[2]; | 710 SkPoint transformPoints[2]; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
795 twoPointRadialInfo.fRadius[1] = | 794 twoPointRadialInfo.fRadius[1] = |
796 inverseMapperMatrix.mapRadius(info->fRadius[1]); | 795 inverseMapperMatrix.mapRadius(info->fRadius[1]); |
797 functionCode = codeFunction(twoPointRadialInfo, perspectiveInverseOnly); | 796 functionCode = codeFunction(twoPointRadialInfo, perspectiveInverseOnly); |
798 } else { | 797 } else { |
799 functionCode = codeFunction(*info, perspectiveInverseOnly); | 798 functionCode = codeFunction(*info, perspectiveInverseOnly); |
800 } | 799 } |
801 | 800 |
802 auto pdfShader = sk_make_sp<SkPDFDict>(); | 801 auto pdfShader = sk_make_sp<SkPDFDict>(); |
803 pdfShader->insertInt("ShadingType", 1); | 802 pdfShader->insertInt("ShadingType", 1); |
804 pdfShader->insertName("ColorSpace", "DeviceRGB"); | 803 pdfShader->insertName("ColorSpace", "DeviceRGB"); |
805 pdfShader->insertObject("Domain", SkRef(domain.get())); | 804 pdfShader->insertObject("Domain", sk_sp<SkPDFObject>(SkRef(domain.get()))); |
806 | 805 |
807 sk_sp<SkPDFStream> function( | 806 sk_sp<SkPDFStream> function( |
808 make_ps_function(functionCode, domain.get())); | 807 make_ps_function(functionCode, domain.get())); |
809 pdfShader->insertObjRef("Function", function.release()); | 808 pdfShader->insertObjRef("Function", std::move(function)); |
810 | 809 |
811 sk_sp<SkPDFFunctionShader> pdfFunctionShader( | 810 sk_sp<SkPDFFunctionShader> pdfFunctionShader( |
812 new SkPDFFunctionShader(autoState->detach())); | 811 new SkPDFFunctionShader(autoState->detach())); |
813 pdfFunctionShader->insertInt("PatternType", 2); | 812 pdfFunctionShader->insertInt("PatternType", 2); |
814 pdfFunctionShader->insertObject("Matrix", | 813 pdfFunctionShader->insertObject("Matrix", |
815 SkPDFUtils::MatrixToArray(finalMatrix)); | 814 SkPDFUtils::MatrixToArray(finalMatrix)); |
816 pdfFunctionShader->insertObject("Shading", pdfShader.release()); | 815 pdfFunctionShader->insertObject("Shading", std::move(pdfShader)); |
817 | 816 |
818 canon->addFunctionShader(pdfFunctionShader.get()); | 817 canon->addFunctionShader(pdfFunctionShader.get()); |
819 return pdfFunctionShader.release(); | 818 return pdfFunctionShader.release(); |
820 } | 819 } |
821 | 820 |
822 SkPDFImageShader* SkPDFImageShader::Create( | 821 SkPDFImageShader* SkPDFImageShader::Create( |
823 SkPDFCanon* canon, | 822 SkPDFCanon* canon, |
824 SkScalar dpi, | 823 SkScalar dpi, |
825 SkAutoTDelete<SkPDFShader::State>* autoState) { | 824 SkAutoTDelete<SkPDFShader::State>* autoState) { |
826 const SkPDFShader::State& state = **autoState; | 825 const SkPDFShader::State& state = **autoState; |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1012 if (tileModes[0] == SkShader::kMirror_TileMode) { | 1011 if (tileModes[0] == SkShader::kMirror_TileMode) { |
1013 bottomMatrix.postScale(-1, 1); | 1012 bottomMatrix.postScale(-1, 1); |
1014 bottomMatrix.postTranslate(2 * width, 0); | 1013 bottomMatrix.postTranslate(2 * width, 0); |
1015 drawBitmapMatrix(&canvas, bottom, bottomMatrix); | 1014 drawBitmapMatrix(&canvas, bottom, bottomMatrix); |
1016 } | 1015 } |
1017 patternBBox.fBottom = deviceBounds.height(); | 1016 patternBBox.fBottom = deviceBounds.height(); |
1018 } | 1017 } |
1019 } | 1018 } |
1020 | 1019 |
1021 // Put the canvas into the pattern stream (fContent). | 1020 // Put the canvas into the pattern stream (fContent). |
1022 SkAutoTDelete<SkStreamAsset> content(patternDevice->content()); | 1021 auto content = patternDevice->content(); |
1023 | 1022 |
1024 SkPDFImageShader* imageShader = new SkPDFImageShader(autoState->detach()); | 1023 SkPDFImageShader* imageShader = new SkPDFImageShader(autoState->detach()); |
1025 imageShader->setData(content.get()); | 1024 imageShader->setData(content.get()); |
1026 | 1025 |
1027 sk_sp<SkPDFDict> resourceDict( | 1026 auto resourceDict = patternDevice->makeResourceDict(); |
1028 patternDevice->createResourceDict()); | |
1029 populate_tiling_pattern_dict(imageShader, patternBBox, | 1027 populate_tiling_pattern_dict(imageShader, patternBBox, |
1030 resourceDict.get(), finalMatrix); | 1028 resourceDict.get(), finalMatrix); |
1031 | 1029 |
1032 imageShader->fShaderState->fImage.unlockPixels(); | 1030 imageShader->fShaderState->fImage.unlockPixels(); |
1033 | 1031 |
1034 canon->addImageShader(imageShader); | 1032 canon->addImageShader(imageShader); |
1035 return imageShader; | 1033 return imageShader; |
1036 } | 1034 } |
1037 | 1035 |
1038 bool SkPDFShader::State::operator==(const SkPDFShader::State& b) const { | 1036 bool SkPDFShader::State::operator==(const SkPDFShader::State& b) const { |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1224 return false; | 1222 return false; |
1225 } | 1223 } |
1226 | 1224 |
1227 void SkPDFShader::State::AllocateGradientInfoStorage() { | 1225 void SkPDFShader::State::AllocateGradientInfoStorage() { |
1228 fColorData.set(sk_malloc_throw( | 1226 fColorData.set(sk_malloc_throw( |
1229 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); | 1227 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); |
1230 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); | 1228 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); |
1231 fInfo.fColorOffsets = | 1229 fInfo.fColorOffsets = |
1232 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); | 1230 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); |
1233 } | 1231 } |
OLD | NEW |