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) { |
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 = |
596 resources(get_gradient_resource_dict(luminosityShader.get(), nullptr)); | 596 get_gradient_resource_dict(luminosityShader.get(), nullptr); |
597 | 597 |
598 sk_sp<SkPDFFormXObject> alphaMask( | 598 sk_sp<SkPDFFormXObject> alphaMask( |
599 new SkPDFFormXObject(alphaStream.get(), bbox, resources.get())); | 599 new SkPDFFormXObject(alphaStream.get(), bbox, resources.get())); |
600 | 600 |
601 return SkPDFGraphicState::GetSMaskGraphicState( | 601 return SkPDFGraphicState::GetSMaskGraphicState( |
602 alphaMask.get(), false, | 602 alphaMask.get(), false, |
603 SkPDFGraphicState::kLuminosity_SMaskMode); | 603 SkPDFGraphicState::kLuminosity_SMaskMode); |
604 } | 604 } |
605 | 605 |
606 SkPDFAlphaFunctionShader* SkPDFAlphaFunctionShader::Create( | 606 SkPDFAlphaFunctionShader* SkPDFAlphaFunctionShader::Create( |
(...skipping 13 matching lines...) Expand all Loading... |
620 } | 620 } |
621 | 621 |
622 // Create resource dict with alpha graphics state as G0 and | 622 // Create resource dict with alpha graphics state as G0 and |
623 // pattern shader as P0, then write content stream. | 623 // pattern shader as P0, then write content stream. |
624 sk_sp<SkPDFObject> alphaGs( | 624 sk_sp<SkPDFObject> alphaGs( |
625 create_smask_graphic_state(canon, dpi, state)); | 625 create_smask_graphic_state(canon, dpi, state)); |
626 | 626 |
627 SkPDFAlphaFunctionShader* alphaFunctionShader = | 627 SkPDFAlphaFunctionShader* alphaFunctionShader = |
628 new SkPDFAlphaFunctionShader(autoState->detach()); | 628 new SkPDFAlphaFunctionShader(autoState->detach()); |
629 | 629 |
630 sk_sp<SkPDFDict> resourceDict( | 630 auto resourceDict = |
631 get_gradient_resource_dict(colorShader.get(), alphaGs.get())); | 631 get_gradient_resource_dict(colorShader.get(), alphaGs.get()); |
632 | 632 |
633 SkAutoTDelete<SkStream> colorStream( | 633 SkAutoTDelete<SkStream> colorStream( |
634 create_pattern_fill_content(0, bbox)); | 634 create_pattern_fill_content(0, bbox)); |
635 alphaFunctionShader->setData(colorStream.get()); | 635 alphaFunctionShader->setData(colorStream.get()); |
636 | 636 |
637 populate_tiling_pattern_dict(alphaFunctionShader, bbox, resourceDict.get(), | 637 populate_tiling_pattern_dict(alphaFunctionShader, bbox, resourceDict.get(), |
638 SkMatrix::I()); | 638 SkMatrix::I()); |
639 canon->addAlphaShader(alphaFunctionShader); | 639 canon->addAlphaShader(alphaFunctionShader); |
640 return alphaFunctionShader; | 640 return alphaFunctionShader; |
641 } | 641 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 return range; | 690 return range; |
691 } | 691 } |
692 SK_DECLARE_STATIC_ONCE_PTR(SkPDFObject, rangeObject); | 692 SK_DECLARE_STATIC_ONCE_PTR(SkPDFObject, rangeObject); |
693 | 693 |
694 static SkPDFStream* make_ps_function(const SkString& psCode, | 694 static SkPDFStream* make_ps_function(const SkString& psCode, |
695 SkPDFArray* domain) { | 695 SkPDFArray* domain) { |
696 SkAutoDataUnref funcData( | 696 SkAutoDataUnref funcData( |
697 SkData::NewWithCopy(psCode.c_str(), psCode.size())); | 697 SkData::NewWithCopy(psCode.c_str(), psCode.size())); |
698 SkPDFStream* result = new SkPDFStream(funcData.get()); | 698 SkPDFStream* result = new SkPDFStream(funcData.get()); |
699 result->insertInt("FunctionType", 4); | 699 result->insertInt("FunctionType", 4); |
700 result->insertObject("Domain", SkRef(domain)); | 700 result->insertObject("Domain", sk_sp<SkPDFObject>(SkRef(domain))); |
701 result->insertObject("Range", SkRef(rangeObject.get(create_range_object))); | 701 result->insertObject("Range", sk_sp<SkPDFObject>(SkRef(rangeObject.get(creat
e_range_object)))); |
702 return result; | 702 return result; |
703 } | 703 } |
704 | 704 |
705 SkPDFFunctionShader* SkPDFFunctionShader::Create( | 705 SkPDFFunctionShader* SkPDFFunctionShader::Create( |
706 SkPDFCanon* canon, SkAutoTDelete<SkPDFShader::State>* autoState) { | 706 SkPDFCanon* canon, SkAutoTDelete<SkPDFShader::State>* autoState) { |
707 const SkPDFShader::State& state = **autoState; | 707 const SkPDFShader::State& state = **autoState; |
708 | 708 |
709 SkString (*codeFunction)(const SkShader::GradientInfo& info, | 709 SkString (*codeFunction)(const SkShader::GradientInfo& info, |
710 const SkMatrix& perspectiveRemover) = nullptr; | 710 const SkMatrix& perspectiveRemover) = nullptr; |
711 SkPoint transformPoints[2]; | 711 SkPoint transformPoints[2]; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
795 twoPointRadialInfo.fRadius[1] = | 795 twoPointRadialInfo.fRadius[1] = |
796 inverseMapperMatrix.mapRadius(info->fRadius[1]); | 796 inverseMapperMatrix.mapRadius(info->fRadius[1]); |
797 functionCode = codeFunction(twoPointRadialInfo, perspectiveInverseOnly); | 797 functionCode = codeFunction(twoPointRadialInfo, perspectiveInverseOnly); |
798 } else { | 798 } else { |
799 functionCode = codeFunction(*info, perspectiveInverseOnly); | 799 functionCode = codeFunction(*info, perspectiveInverseOnly); |
800 } | 800 } |
801 | 801 |
802 auto pdfShader = sk_make_sp<SkPDFDict>(); | 802 auto pdfShader = sk_make_sp<SkPDFDict>(); |
803 pdfShader->insertInt("ShadingType", 1); | 803 pdfShader->insertInt("ShadingType", 1); |
804 pdfShader->insertName("ColorSpace", "DeviceRGB"); | 804 pdfShader->insertName("ColorSpace", "DeviceRGB"); |
805 pdfShader->insertObject("Domain", SkRef(domain.get())); | 805 pdfShader->insertObject("Domain", sk_sp<SkPDFObject>(SkRef(domain.get()))); |
806 | 806 |
807 sk_sp<SkPDFStream> function( | 807 sk_sp<SkPDFStream> function( |
808 make_ps_function(functionCode, domain.get())); | 808 make_ps_function(functionCode, domain.get())); |
809 pdfShader->insertObjRef("Function", function.release()); | 809 pdfShader->insertObjRef("Function", std::move(function)); |
810 | 810 |
811 sk_sp<SkPDFFunctionShader> pdfFunctionShader( | 811 sk_sp<SkPDFFunctionShader> pdfFunctionShader( |
812 new SkPDFFunctionShader(autoState->detach())); | 812 new SkPDFFunctionShader(autoState->detach())); |
813 pdfFunctionShader->insertInt("PatternType", 2); | 813 pdfFunctionShader->insertInt("PatternType", 2); |
814 pdfFunctionShader->insertObject("Matrix", | 814 pdfFunctionShader->insertObject("Matrix", |
815 SkPDFUtils::MatrixToArray(finalMatrix)); | 815 SkPDFUtils::MatrixToArray(finalMatrix)); |
816 pdfFunctionShader->insertObject("Shading", pdfShader.release()); | 816 pdfFunctionShader->insertObject("Shading", std::move(pdfShader)); |
817 | 817 |
818 canon->addFunctionShader(pdfFunctionShader.get()); | 818 canon->addFunctionShader(pdfFunctionShader.get()); |
819 return pdfFunctionShader.release(); | 819 return pdfFunctionShader.release(); |
820 } | 820 } |
821 | 821 |
822 SkPDFImageShader* SkPDFImageShader::Create( | 822 SkPDFImageShader* SkPDFImageShader::Create( |
823 SkPDFCanon* canon, | 823 SkPDFCanon* canon, |
824 SkScalar dpi, | 824 SkScalar dpi, |
825 SkAutoTDelete<SkPDFShader::State>* autoState) { | 825 SkAutoTDelete<SkPDFShader::State>* autoState) { |
826 const SkPDFShader::State& state = **autoState; | 826 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) { | 1012 if (tileModes[0] == SkShader::kMirror_TileMode) { |
1013 bottomMatrix.postScale(-1, 1); | 1013 bottomMatrix.postScale(-1, 1); |
1014 bottomMatrix.postTranslate(2 * width, 0); | 1014 bottomMatrix.postTranslate(2 * width, 0); |
1015 drawBitmapMatrix(&canvas, bottom, bottomMatrix); | 1015 drawBitmapMatrix(&canvas, bottom, bottomMatrix); |
1016 } | 1016 } |
1017 patternBBox.fBottom = deviceBounds.height(); | 1017 patternBBox.fBottom = deviceBounds.height(); |
1018 } | 1018 } |
1019 } | 1019 } |
1020 | 1020 |
1021 // Put the canvas into the pattern stream (fContent). | 1021 // Put the canvas into the pattern stream (fContent). |
1022 SkAutoTDelete<SkStreamAsset> content(patternDevice->content()); | 1022 auto content = patternDevice->content(); |
1023 | 1023 |
1024 SkPDFImageShader* imageShader = new SkPDFImageShader(autoState->detach()); | 1024 SkPDFImageShader* imageShader = new SkPDFImageShader(autoState->detach()); |
1025 imageShader->setData(content.get()); | 1025 imageShader->setData(content.get()); |
1026 | 1026 |
1027 sk_sp<SkPDFDict> resourceDict( | 1027 auto resourceDict = patternDevice->makeResourceDict(); |
1028 patternDevice->createResourceDict()); | |
1029 populate_tiling_pattern_dict(imageShader, patternBBox, | 1028 populate_tiling_pattern_dict(imageShader, patternBBox, |
1030 resourceDict.get(), finalMatrix); | 1029 resourceDict.get(), finalMatrix); |
1031 | 1030 |
1032 imageShader->fShaderState->fImage.unlockPixels(); | 1031 imageShader->fShaderState->fImage.unlockPixels(); |
1033 | 1032 |
1034 canon->addImageShader(imageShader); | 1033 canon->addImageShader(imageShader); |
1035 return imageShader; | 1034 return imageShader; |
1036 } | 1035 } |
1037 | 1036 |
1038 bool SkPDFShader::State::operator==(const SkPDFShader::State& b) const { | 1037 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; | 1223 return false; |
1225 } | 1224 } |
1226 | 1225 |
1227 void SkPDFShader::State::AllocateGradientInfoStorage() { | 1226 void SkPDFShader::State::AllocateGradientInfoStorage() { |
1228 fColorData.set(sk_malloc_throw( | 1227 fColorData.set(sk_malloc_throw( |
1229 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); | 1228 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); |
1230 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); | 1229 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); |
1231 fInfo.fColorOffsets = | 1230 fInfo.fColorOffsets = |
1232 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); | 1231 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); |
1233 } | 1232 } |
OLD | NEW |