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 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 * Creates a ExtGState with the SMask set to the luminosityShader in | 580 * Creates a ExtGState with the SMask set to the luminosityShader in |
581 * luminosity mode. The shader pattern extends to the bbox. | 581 * luminosity mode. The shader pattern extends to the bbox. |
582 */ | 582 */ |
583 static SkPDFObject* create_smask_graphic_state( | 583 static SkPDFObject* create_smask_graphic_state( |
584 SkPDFCanon* canon, SkScalar dpi, const SkPDFShader::State& state) { | 584 SkPDFCanon* canon, SkScalar dpi, const SkPDFShader::State& state) { |
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 SkAutoTUnref<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 SkAutoTUnref<SkPDFDict> | 595 sk_sp<SkPDFDict> |
596 resources(get_gradient_resource_dict(luminosityShader.get(), nullptr)); | 596 resources(get_gradient_resource_dict(luminosityShader.get(), nullptr)); |
597 | 597 |
598 SkAutoTUnref<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( |
607 SkPDFCanon* canon, | 607 SkPDFCanon* canon, |
608 SkScalar dpi, | 608 SkScalar dpi, |
609 SkAutoTDelete<SkPDFShader::State>* autoState) { | 609 SkAutoTDelete<SkPDFShader::State>* autoState) { |
610 const SkPDFShader::State& state = **autoState; | 610 const SkPDFShader::State& state = **autoState; |
611 SkRect bbox; | 611 SkRect bbox; |
612 bbox.set(state.fBBox); | 612 bbox.set(state.fBBox); |
613 | 613 |
614 SkAutoTDelete<SkPDFShader::State> opaqueState(state.CreateOpaqueState()); | 614 SkAutoTDelete<SkPDFShader::State> opaqueState(state.CreateOpaqueState()); |
615 | 615 |
616 SkAutoTUnref<SkPDFObject> colorShader( | 616 sk_sp<SkPDFObject> colorShader( |
617 get_pdf_shader_by_state(canon, dpi, &opaqueState)); | 617 get_pdf_shader_by_state(canon, dpi, &opaqueState)); |
618 if (!colorShader) { | 618 if (!colorShader) { |
619 return nullptr; | 619 return nullptr; |
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 SkAutoTUnref<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 SkAutoTUnref<SkPDFDict> resourceDict( | 630 sk_sp<SkPDFDict> 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; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 return nullptr; | 764 return nullptr; |
765 } | 765 } |
766 } | 766 } |
767 | 767 |
768 SkRect bbox; | 768 SkRect bbox; |
769 bbox.set(state.fBBox); | 769 bbox.set(state.fBBox); |
770 if (!inverse_transform_bbox(finalMatrix, &bbox)) { | 770 if (!inverse_transform_bbox(finalMatrix, &bbox)) { |
771 return nullptr; | 771 return nullptr; |
772 } | 772 } |
773 | 773 |
774 SkAutoTUnref<SkPDFArray> domain(new SkPDFArray); | 774 sk_sp<SkPDFArray> domain(new SkPDFArray); |
775 domain->reserve(4); | 775 domain->reserve(4); |
776 domain->appendScalar(bbox.fLeft); | 776 domain->appendScalar(bbox.fLeft); |
777 domain->appendScalar(bbox.fRight); | 777 domain->appendScalar(bbox.fRight); |
778 domain->appendScalar(bbox.fTop); | 778 domain->appendScalar(bbox.fTop); |
779 domain->appendScalar(bbox.fBottom); | 779 domain->appendScalar(bbox.fBottom); |
780 | 780 |
781 SkString functionCode; | 781 SkString functionCode; |
782 // The two point radial gradient further references | 782 // The two point radial gradient further references |
783 // state.fInfo | 783 // state.fInfo |
784 // in translating from x, y coordinates to the t parameter. So, we have | 784 // in translating from x, y coordinates to the t parameter. So, we have |
785 // to transform the points and radii according to the calculated matrix. | 785 // to transform the points and radii according to the calculated matrix. |
786 if (state.fType == SkShader::kConical_GradientType) { | 786 if (state.fType == SkShader::kConical_GradientType) { |
787 SkShader::GradientInfo twoPointRadialInfo = *info; | 787 SkShader::GradientInfo twoPointRadialInfo = *info; |
788 SkMatrix inverseMapperMatrix; | 788 SkMatrix inverseMapperMatrix; |
789 if (!mapperMatrix.invert(&inverseMapperMatrix)) { | 789 if (!mapperMatrix.invert(&inverseMapperMatrix)) { |
790 return nullptr; | 790 return nullptr; |
791 } | 791 } |
792 inverseMapperMatrix.mapPoints(twoPointRadialInfo.fPoint, 2); | 792 inverseMapperMatrix.mapPoints(twoPointRadialInfo.fPoint, 2); |
793 twoPointRadialInfo.fRadius[0] = | 793 twoPointRadialInfo.fRadius[0] = |
794 inverseMapperMatrix.mapRadius(info->fRadius[0]); | 794 inverseMapperMatrix.mapRadius(info->fRadius[0]); |
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 SkAutoTUnref<SkPDFDict> pdfShader(new SkPDFDict); | 802 sk_sp<SkPDFDict> pdfShader(new 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", SkRef(domain.get())); |
806 | 806 |
807 SkAutoTUnref<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", function.release()); |
810 | 810 |
811 SkAutoTUnref<SkPDFFunctionShader> pdfFunctionShader(new SkPDFFunctionShader(
autoState->detach())); | 811 sk_sp<SkPDFFunctionShader> pdfFunctionShader(new SkPDFFunctionShader(autoSta
te->detach())); |
812 | 812 |
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", pdfShader.release()); |
817 | 817 |
818 canon->addFunctionShader(pdfFunctionShader.get()); | 818 canon->addFunctionShader(pdfFunctionShader.get()); |
819 return pdfFunctionShader.release(); | 819 return pdfFunctionShader.release(); |
820 } | 820 } |
821 | 821 |
(...skipping 30 matching lines...) Expand all Loading... |
852 SkShader::TileMode tileModes[2]; | 852 SkShader::TileMode tileModes[2]; |
853 tileModes[0] = state.fImageTileModes[0]; | 853 tileModes[0] = state.fImageTileModes[0]; |
854 tileModes[1] = state.fImageTileModes[1]; | 854 tileModes[1] = state.fImageTileModes[1]; |
855 if (tileModes[0] != SkShader::kClamp_TileMode || | 855 if (tileModes[0] != SkShader::kClamp_TileMode || |
856 tileModes[1] != SkShader::kClamp_TileMode) { | 856 tileModes[1] != SkShader::kClamp_TileMode) { |
857 deviceBounds.join(bitmapBounds); | 857 deviceBounds.join(bitmapBounds); |
858 } | 858 } |
859 | 859 |
860 SkISize size = SkISize::Make(SkScalarRoundToInt(deviceBounds.width()), | 860 SkISize size = SkISize::Make(SkScalarRoundToInt(deviceBounds.width()), |
861 SkScalarRoundToInt(deviceBounds.height())); | 861 SkScalarRoundToInt(deviceBounds.height())); |
862 SkAutoTUnref<SkPDFDevice> patternDevice( | 862 sk_sp<SkPDFDevice> patternDevice( |
863 SkPDFDevice::CreateUnflipped(size, dpi, canon)); | 863 SkPDFDevice::CreateUnflipped(size, dpi, canon)); |
864 SkCanvas canvas(patternDevice.get()); | 864 SkCanvas canvas(patternDevice.get()); |
865 | 865 |
866 SkRect patternBBox; | 866 SkRect patternBBox; |
867 image->getBounds(&patternBBox); | 867 image->getBounds(&patternBBox); |
868 | 868 |
869 // Translate the canvas so that the bitmap origin is at (0, 0). | 869 // Translate the canvas so that the bitmap origin is at (0, 0). |
870 canvas.translate(-deviceBounds.left(), -deviceBounds.top()); | 870 canvas.translate(-deviceBounds.left(), -deviceBounds.top()); |
871 patternBBox.offset(-deviceBounds.left(), -deviceBounds.top()); | 871 patternBBox.offset(-deviceBounds.left(), -deviceBounds.top()); |
872 // Undo the translation in the final matrix | 872 // Undo the translation in the final matrix |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 SkAutoTDelete<SkStreamAsset> 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 SkAutoTUnref<SkPDFDict> resourceDict( | 1027 sk_sp<SkPDFDict> resourceDict( |
1028 patternDevice->createResourceDict()); | 1028 patternDevice->createResourceDict()); |
1029 populate_tiling_pattern_dict(imageShader, patternBBox, | 1029 populate_tiling_pattern_dict(imageShader, patternBBox, |
1030 resourceDict.get(), finalMatrix); | 1030 resourceDict.get(), finalMatrix); |
1031 | 1031 |
1032 imageShader->fShaderState->fImage.unlockPixels(); | 1032 imageShader->fShaderState->fImage.unlockPixels(); |
1033 | 1033 |
1034 canon->addImageShader(imageShader); | 1034 canon->addImageShader(imageShader); |
1035 return imageShader; | 1035 return imageShader; |
1036 } | 1036 } |
1037 | 1037 |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1224 return false; | 1224 return false; |
1225 } | 1225 } |
1226 | 1226 |
1227 void SkPDFShader::State::AllocateGradientInfoStorage() { | 1227 void SkPDFShader::State::AllocateGradientInfoStorage() { |
1228 fColorData.set(sk_malloc_throw( | 1228 fColorData.set(sk_malloc_throw( |
1229 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); | 1229 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); |
1230 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); | 1230 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); |
1231 fInfo.fColorOffsets = | 1231 fInfo.fColorOffsets = |
1232 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); | 1232 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); |
1233 } | 1233 } |
OLD | NEW |