| 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 753 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 sk_sp<SkPDFArray> domain(new SkPDFArray); | 774 auto domain = sk_make_sp<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 sk_sp<SkPDFDict> pdfShader(new 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", 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", function.release()); |
| 810 | 810 |
| 811 sk_sp<SkPDFFunctionShader> pdfFunctionShader(new SkPDFFunctionShader(autoSta
te->detach())); | 811 sk_sp<SkPDFFunctionShader> pdfFunctionShader( |
| 812 | 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", 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 |
| 822 SkPDFImageShader* SkPDFImageShader::Create( | 822 SkPDFImageShader* SkPDFImageShader::Create( |
| (...skipping 401 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 |