| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 | 8 |
| 9 #include "SkPDFShader.h" | 9 #include "SkPDFShader.h" |
| 10 | 10 |
| (...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 736 SkPDFAlphaFunctionShader* alphaFunctionShader = | 736 SkPDFAlphaFunctionShader* alphaFunctionShader = |
| 737 new SkPDFAlphaFunctionShader(autoState->release()); | 737 new SkPDFAlphaFunctionShader(autoState->release()); |
| 738 | 738 |
| 739 auto resourceDict = | 739 auto resourceDict = |
| 740 get_gradient_resource_dict(colorShader.get(), alphaGs.get()); | 740 get_gradient_resource_dict(colorShader.get(), alphaGs.get()); |
| 741 | 741 |
| 742 std::unique_ptr<SkStreamAsset> colorStream( | 742 std::unique_ptr<SkStreamAsset> colorStream( |
| 743 create_pattern_fill_content(0, bbox)); | 743 create_pattern_fill_content(0, bbox)); |
| 744 alphaFunctionShader->setData(std::move(colorStream)); | 744 alphaFunctionShader->setData(std::move(colorStream)); |
| 745 | 745 |
| 746 populate_tiling_pattern_dict(alphaFunctionShader, bbox, resourceDict.get(), | 746 populate_tiling_pattern_dict( |
| 747 SkMatrix::I()); | 747 alphaFunctionShader->dict(), bbox, resourceDict.get(), |
| 748 SkMatrix::I()); |
| 748 doc->canon()->addAlphaShader(alphaFunctionShader); | 749 doc->canon()->addAlphaShader(alphaFunctionShader); |
| 749 return alphaFunctionShader; | 750 return alphaFunctionShader; |
| 750 } | 751 } |
| 751 | 752 |
| 752 // Finds affine and persp such that in = affine * persp. | 753 // Finds affine and persp such that in = affine * persp. |
| 753 // but it returns the inverse of perspective matrix. | 754 // but it returns the inverse of perspective matrix. |
| 754 static bool split_perspective(const SkMatrix in, SkMatrix* affine, | 755 static bool split_perspective(const SkMatrix in, SkMatrix* affine, |
| 755 SkMatrix* perspectiveInverse) { | 756 SkMatrix* perspectiveInverse) { |
| 756 const SkScalar p2 = in[SkMatrix::kMPersp2]; | 757 const SkScalar p2 = in[SkMatrix::kMPersp2]; |
| 757 | 758 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 797 range->appendInt(0); | 798 range->appendInt(0); |
| 798 range->appendInt(1); | 799 range->appendInt(1); |
| 799 return range; | 800 return range; |
| 800 } | 801 } |
| 801 | 802 |
| 802 static sk_sp<SkPDFStream> make_ps_function( | 803 static sk_sp<SkPDFStream> make_ps_function( |
| 803 std::unique_ptr<SkStreamAsset> psCode, | 804 std::unique_ptr<SkStreamAsset> psCode, |
| 804 SkPDFArray* domain, | 805 SkPDFArray* domain, |
| 805 sk_sp<SkPDFObject> range) { | 806 sk_sp<SkPDFObject> range) { |
| 806 auto result = sk_make_sp<SkPDFStream>(std::move(psCode)); | 807 auto result = sk_make_sp<SkPDFStream>(std::move(psCode)); |
| 807 result->insertInt("FunctionType", 4); | 808 result->dict()->insertInt("FunctionType", 4); |
| 808 result->insertObject("Domain", sk_ref_sp(domain)); | 809 result->dict()->insertObject("Domain", sk_ref_sp(domain)); |
| 809 result->insertObject("Range", std::move(range)); | 810 result->dict()->insertObject("Range", std::move(range)); |
| 810 return result; | 811 return result; |
| 811 } | 812 } |
| 812 | 813 |
| 813 // catch cases where the inner just touches the outer circle | 814 // catch cases where the inner just touches the outer circle |
| 814 // and make the inner circle just inside the outer one to match raster | 815 // and make the inner circle just inside the outer one to match raster |
| 815 static void FixUpRadius(const SkPoint& p1, SkScalar& r1, const SkPoint& p2, SkSc
alar& r2) { | 816 static void FixUpRadius(const SkPoint& p1, SkScalar& r1, const SkPoint& p2, SkSc
alar& r2) { |
| 816 // detect touching circles | 817 // detect touching circles |
| 817 SkScalar distance = SkPoint::Distance(p1, p2); | 818 SkScalar distance = SkPoint::Distance(p1, p2); |
| 818 SkScalar subtractRadii = fabs(r1 - r2); | 819 SkScalar subtractRadii = fabs(r1 - r2); |
| 819 if (fabs(distance - subtractRadii) < 0.002f) { | 820 if (fabs(distance - subtractRadii) < 0.002f) { |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1206 } | 1207 } |
| 1207 patternBBox.fBottom = deviceBounds.height(); | 1208 patternBBox.fBottom = deviceBounds.height(); |
| 1208 } | 1209 } |
| 1209 } | 1210 } |
| 1210 | 1211 |
| 1211 // Put the canvas into the pattern stream (fContent). | 1212 // Put the canvas into the pattern stream (fContent). |
| 1212 SkPDFImageShader* imageShader = new SkPDFImageShader(autoState->release()); | 1213 SkPDFImageShader* imageShader = new SkPDFImageShader(autoState->release()); |
| 1213 imageShader->setData(patternDevice->content()); | 1214 imageShader->setData(patternDevice->content()); |
| 1214 | 1215 |
| 1215 auto resourceDict = patternDevice->makeResourceDict(); | 1216 auto resourceDict = patternDevice->makeResourceDict(); |
| 1216 populate_tiling_pattern_dict(imageShader, patternBBox, | 1217 populate_tiling_pattern_dict(imageShader->dict(), patternBBox, |
| 1217 resourceDict.get(), finalMatrix); | 1218 resourceDict.get(), finalMatrix); |
| 1218 | 1219 |
| 1219 imageShader->fShaderState->fImage.unlockPixels(); | 1220 imageShader->fShaderState->fImage.unlockPixels(); |
| 1220 | 1221 |
| 1221 doc->canon()->addImageShader(imageShader); | 1222 doc->canon()->addImageShader(imageShader); |
| 1222 return imageShader; | 1223 return imageShader; |
| 1223 } | 1224 } |
| 1224 | 1225 |
| 1225 bool SkPDFShader::State::operator==(const SkPDFShader::State& b) const { | 1226 bool SkPDFShader::State::operator==(const SkPDFShader::State& b) const { |
| 1226 if (fType != b.fType || | 1227 if (fType != b.fType || |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1410 return false; | 1411 return false; |
| 1411 } | 1412 } |
| 1412 | 1413 |
| 1413 void SkPDFShader::State::AllocateGradientInfoStorage() { | 1414 void SkPDFShader::State::AllocateGradientInfoStorage() { |
| 1414 fColorData.set(sk_malloc_throw( | 1415 fColorData.set(sk_malloc_throw( |
| 1415 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); | 1416 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); |
| 1416 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); | 1417 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); |
| 1417 fInfo.fColorOffsets = | 1418 fInfo.fColorOffsets = |
| 1418 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); | 1419 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); |
| 1419 } | 1420 } |
| OLD | NEW |