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 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 SkPDFDict* resources, | 594 SkPDFDict* resources, |
595 const SkMatrix& matrix) { | 595 const SkMatrix& matrix) { |
596 const int kTiling_PatternType = 1; | 596 const int kTiling_PatternType = 1; |
597 const int kColoredTilingPattern_PaintType = 1; | 597 const int kColoredTilingPattern_PaintType = 1; |
598 const int kConstantSpacing_TilingType = 1; | 598 const int kConstantSpacing_TilingType = 1; |
599 | 599 |
600 pattern->insertName("Type", "Pattern"); | 600 pattern->insertName("Type", "Pattern"); |
601 pattern->insertInt("PatternType", kTiling_PatternType); | 601 pattern->insertInt("PatternType", kTiling_PatternType); |
602 pattern->insertInt("PaintType", kColoredTilingPattern_PaintType); | 602 pattern->insertInt("PaintType", kColoredTilingPattern_PaintType); |
603 pattern->insertInt("TilingType", kConstantSpacing_TilingType); | 603 pattern->insertInt("TilingType", kConstantSpacing_TilingType); |
604 pattern->insert("BBox", SkPDFUtils::RectToArray(bbox))->unref(); | 604 pattern->insertObject("BBox", SkPDFUtils::RectToArray(bbox)); |
605 pattern->insertScalar("XStep", bbox.width()); | 605 pattern->insertScalar("XStep", bbox.width()); |
606 pattern->insertScalar("YStep", bbox.height()); | 606 pattern->insertScalar("YStep", bbox.height()); |
607 pattern->insert("Resources", resources); | 607 pattern->insertObject("Resources", SkRef(resources)); |
608 if (!matrix.isIdentity()) { | 608 if (!matrix.isIdentity()) { |
609 pattern->insert("Matrix", SkPDFUtils::MatrixToArray(matrix))->unref(); | 609 pattern->insertObject("Matrix", SkPDFUtils::MatrixToArray(matrix)); |
610 } | 610 } |
611 } | 611 } |
612 | 612 |
613 /** | 613 /** |
614 * Creates a content stream which fills the pattern P0 across bounds. | 614 * Creates a content stream which fills the pattern P0 across bounds. |
615 * @param gsIndex A graphics state resource index to apply, or <0 if no | 615 * @param gsIndex A graphics state resource index to apply, or <0 if no |
616 * graphics state to apply. | 616 * graphics state to apply. |
617 */ | 617 */ |
618 static SkStream* create_pattern_fill_content(int gsIndex, SkRect& bounds) { | 618 static SkStream* create_pattern_fill_content(int gsIndex, SkRect& bounds) { |
619 SkDynamicMemoryWStream content; | 619 SkDynamicMemoryWStream content; |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 | 748 |
749 SK_DECLARE_STATIC_LAZY_PTR(SkPDFObject, rangeObject, | 749 SK_DECLARE_STATIC_LAZY_PTR(SkPDFObject, rangeObject, |
750 create_range_object, unref<SkPDFObject>); | 750 create_range_object, unref<SkPDFObject>); |
751 | 751 |
752 static SkPDFStream* make_ps_function(const SkString& psCode, | 752 static SkPDFStream* make_ps_function(const SkString& psCode, |
753 SkPDFArray* domain) { | 753 SkPDFArray* domain) { |
754 SkAutoDataUnref funcData( | 754 SkAutoDataUnref funcData( |
755 SkData::NewWithCopy(psCode.c_str(), psCode.size())); | 755 SkData::NewWithCopy(psCode.c_str(), psCode.size())); |
756 SkPDFStream* result = SkNEW_ARGS(SkPDFStream, (funcData.get())); | 756 SkPDFStream* result = SkNEW_ARGS(SkPDFStream, (funcData.get())); |
757 result->insertInt("FunctionType", 4); | 757 result->insertInt("FunctionType", 4); |
758 result->insert("Domain", domain); | 758 result->insertObject("Domain", SkRef(domain)); |
759 result->insert("Range", rangeObject.get()); | 759 result->insertObject("Range", SkRef(rangeObject.get())); |
760 return result; | 760 return result; |
761 } | 761 } |
762 | 762 |
763 SkPDFFunctionShader* SkPDFFunctionShader::Create( | 763 SkPDFFunctionShader* SkPDFFunctionShader::Create( |
764 SkPDFCanon* canon, SkAutoTDelete<SkPDFShader::State>* autoState) { | 764 SkPDFCanon* canon, SkAutoTDelete<SkPDFShader::State>* autoState) { |
765 const SkPDFShader::State& state = **autoState; | 765 const SkPDFShader::State& state = **autoState; |
766 | 766 |
767 SkString (*codeFunction)(const SkShader::GradientInfo& info, | 767 SkString (*codeFunction)(const SkShader::GradientInfo& info, |
768 const SkMatrix& perspectiveRemover) = NULL; | 768 const SkMatrix& perspectiveRemover) = NULL; |
769 SkPoint transformPoints[2]; | 769 SkPoint transformPoints[2]; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
864 twoPointRadialInfo.fRadius[1] = | 864 twoPointRadialInfo.fRadius[1] = |
865 inverseMapperMatrix.mapRadius(info->fRadius[1]); | 865 inverseMapperMatrix.mapRadius(info->fRadius[1]); |
866 functionCode = codeFunction(twoPointRadialInfo, perspectiveInverseOnly); | 866 functionCode = codeFunction(twoPointRadialInfo, perspectiveInverseOnly); |
867 } else { | 867 } else { |
868 functionCode = codeFunction(*info, perspectiveInverseOnly); | 868 functionCode = codeFunction(*info, perspectiveInverseOnly); |
869 } | 869 } |
870 | 870 |
871 SkAutoTUnref<SkPDFDict> pdfShader(new SkPDFDict); | 871 SkAutoTUnref<SkPDFDict> pdfShader(new SkPDFDict); |
872 pdfShader->insertInt("ShadingType", 1); | 872 pdfShader->insertInt("ShadingType", 1); |
873 pdfShader->insertName("ColorSpace", "DeviceRGB"); | 873 pdfShader->insertName("ColorSpace", "DeviceRGB"); |
874 pdfShader->insert("Domain", domain.get()); | 874 pdfShader->insertObject("Domain", SkRef(domain.get())); |
875 | 875 |
876 SkAutoTUnref<SkPDFStream> function( | 876 SkAutoTUnref<SkPDFStream> function( |
877 make_ps_function(functionCode, domain.get())); | 877 make_ps_function(functionCode, domain.get())); |
878 pdfShader->insert("Function", new SkPDFObjRef(function))->unref(); | 878 pdfShader->insertObjRef("Function", function.detach()); |
879 | |
880 SkAutoTUnref<SkPDFArray> matrixArray( | |
881 SkPDFUtils::MatrixToArray(finalMatrix)); | |
882 | 879 |
883 SkPDFFunctionShader* pdfFunctionShader = | 880 SkPDFFunctionShader* pdfFunctionShader = |
884 SkNEW_ARGS(SkPDFFunctionShader, (autoState->detach())); | 881 SkNEW_ARGS(SkPDFFunctionShader, (autoState->detach())); |
885 | 882 |
886 pdfFunctionShader->insertInt("PatternType", 2); | 883 pdfFunctionShader->insertInt("PatternType", 2); |
887 pdfFunctionShader->insert("Matrix", matrixArray.get()); | 884 pdfFunctionShader->insertObject("Matrix", |
888 pdfFunctionShader->insert("Shading", pdfShader.get()); | 885 SkPDFUtils::MatrixToArray(finalMatrix)); |
| 886 pdfFunctionShader->insertObject("Shading", pdfShader.detach()); |
889 | 887 |
890 canon->addFunctionShader(pdfFunctionShader); | 888 canon->addFunctionShader(pdfFunctionShader); |
891 return pdfFunctionShader; | 889 return pdfFunctionShader; |
892 } | 890 } |
893 | 891 |
894 SkPDFImageShader* SkPDFImageShader::Create( | 892 SkPDFImageShader* SkPDFImageShader::Create( |
895 SkPDFCanon* canon, | 893 SkPDFCanon* canon, |
896 SkScalar dpi, | 894 SkScalar dpi, |
897 SkAutoTDelete<SkPDFShader::State>* autoState) { | 895 SkAutoTDelete<SkPDFShader::State>* autoState) { |
898 const SkPDFShader::State& state = **autoState; | 896 const SkPDFShader::State& state = **autoState; |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1300 return false; | 1298 return false; |
1301 } | 1299 } |
1302 | 1300 |
1303 void SkPDFShader::State::AllocateGradientInfoStorage() { | 1301 void SkPDFShader::State::AllocateGradientInfoStorage() { |
1304 fColorData.set(sk_malloc_throw( | 1302 fColorData.set(sk_malloc_throw( |
1305 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); | 1303 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); |
1306 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); | 1304 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); |
1307 fInfo.fColorOffsets = | 1305 fInfo.fColorOffsets = |
1308 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); | 1306 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); |
1309 } | 1307 } |
OLD | NEW |