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