| 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 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 void AllocateGradientInfoStorage(); | 504 void AllocateGradientInfoStorage(); |
| 505 }; | 505 }; |
| 506 | 506 |
| 507 //////////////////////////////////////////////////////////////////////////////// | 507 //////////////////////////////////////////////////////////////////////////////// |
| 508 | 508 |
| 509 SkPDFFunctionShader::SkPDFFunctionShader(SkPDFCanon* canon, | 509 SkPDFFunctionShader::SkPDFFunctionShader(SkPDFCanon* canon, |
| 510 SkPDFShader::State* state) | 510 SkPDFShader::State* state) |
| 511 : SkPDFDict("Pattern"), fCanon(canon), fShaderState(state) {} | 511 : SkPDFDict("Pattern"), fCanon(canon), fShaderState(state) {} |
| 512 | 512 |
| 513 SkPDFFunctionShader::~SkPDFFunctionShader() { | 513 SkPDFFunctionShader::~SkPDFFunctionShader() { |
| 514 fCanon->removeFunctionShader(this); | |
| 515 fResources.unrefAll(); | 514 fResources.unrefAll(); |
| 516 } | 515 } |
| 517 | 516 |
| 518 bool SkPDFFunctionShader::equals(const SkPDFShader::State& state) const { | 517 bool SkPDFFunctionShader::equals(const SkPDFShader::State& state) const { |
| 519 return state == *fShaderState; | 518 return state == *fShaderState; |
| 520 } | 519 } |
| 521 | 520 |
| 522 //////////////////////////////////////////////////////////////////////////////// | 521 //////////////////////////////////////////////////////////////////////////////// |
| 523 | 522 |
| 524 SkPDFAlphaFunctionShader::SkPDFAlphaFunctionShader(SkPDFCanon* canon, | 523 SkPDFAlphaFunctionShader::SkPDFAlphaFunctionShader(SkPDFCanon* canon, |
| 525 SkPDFShader::State* state) | 524 SkPDFShader::State* state) |
| 526 : fCanon(canon), fShaderState(state) {} | 525 : fCanon(canon), fShaderState(state) {} |
| 527 | 526 |
| 528 bool SkPDFAlphaFunctionShader::equals(const SkPDFShader::State& state) const { | 527 bool SkPDFAlphaFunctionShader::equals(const SkPDFShader::State& state) const { |
| 529 return state == *fShaderState; | 528 return state == *fShaderState; |
| 530 } | 529 } |
| 531 | 530 |
| 532 SkPDFAlphaFunctionShader::~SkPDFAlphaFunctionShader() { | 531 SkPDFAlphaFunctionShader::~SkPDFAlphaFunctionShader() {} |
| 533 fCanon->removeAlphaShader(this); | |
| 534 } | |
| 535 | 532 |
| 536 //////////////////////////////////////////////////////////////////////////////// | 533 //////////////////////////////////////////////////////////////////////////////// |
| 537 | 534 |
| 538 SkPDFImageShader::SkPDFImageShader(SkPDFCanon* canon, SkPDFShader::State* state) | 535 SkPDFImageShader::SkPDFImageShader(SkPDFCanon* canon, SkPDFShader::State* state) |
| 539 : fCanon(canon), fShaderState(state) {} | 536 : fCanon(canon), fShaderState(state) {} |
| 540 | 537 |
| 541 bool SkPDFImageShader::equals(const SkPDFShader::State& state) const { | 538 bool SkPDFImageShader::equals(const SkPDFShader::State& state) const { |
| 542 return state == *fShaderState; | 539 return state == *fShaderState; |
| 543 } | 540 } |
| 544 | 541 |
| 545 SkPDFImageShader::~SkPDFImageShader() { | 542 SkPDFImageShader::~SkPDFImageShader() { |
| 546 fCanon->removeImageShader(this); | |
| 547 fResources.unrefAll(); | 543 fResources.unrefAll(); |
| 548 } | 544 } |
| 549 | 545 |
| 550 //////////////////////////////////////////////////////////////////////////////// | 546 //////////////////////////////////////////////////////////////////////////////// |
| 551 | 547 |
| 552 static SkPDFObject* get_pdf_shader_by_state( | 548 static SkPDFObject* get_pdf_shader_by_state( |
| 553 SkPDFCanon* canon, | 549 SkPDFCanon* canon, |
| 554 SkScalar dpi, | 550 SkScalar dpi, |
| 555 SkAutoTDelete<SkPDFShader::State>* autoState) { | 551 SkAutoTDelete<SkPDFShader::State>* autoState) { |
| 556 const SkPDFShader::State& state = **autoState; | 552 const SkPDFShader::State& state = **autoState; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 alphaFunctionShader->fResourceDict.reset(get_gradient_resource_dict( | 694 alphaFunctionShader->fResourceDict.reset(get_gradient_resource_dict( |
| 699 alphaFunctionShader->fColorShader.get(), alphaGs.get())); | 695 alphaFunctionShader->fColorShader.get(), alphaGs.get())); |
| 700 | 696 |
| 701 SkAutoTDelete<SkStream> colorStream( | 697 SkAutoTDelete<SkStream> colorStream( |
| 702 create_pattern_fill_content(0, bbox)); | 698 create_pattern_fill_content(0, bbox)); |
| 703 alphaFunctionShader->setData(colorStream.get()); | 699 alphaFunctionShader->setData(colorStream.get()); |
| 704 | 700 |
| 705 populate_tiling_pattern_dict(alphaFunctionShader, bbox, | 701 populate_tiling_pattern_dict(alphaFunctionShader, bbox, |
| 706 alphaFunctionShader->fResourceDict.get(), | 702 alphaFunctionShader->fResourceDict.get(), |
| 707 SkMatrix::I()); | 703 SkMatrix::I()); |
| 708 canon->addAlphaShader(alphaFunctionShader); | 704 canon->addAlphaShader(SkRef(alphaFunctionShader)); |
| 709 return alphaFunctionShader; | 705 return alphaFunctionShader; |
| 710 } | 706 } |
| 711 | 707 |
| 712 // Finds affine and persp such that in = affine * persp. | 708 // Finds affine and persp such that in = affine * persp. |
| 713 // but it returns the inverse of perspective matrix. | 709 // but it returns the inverse of perspective matrix. |
| 714 static bool split_perspective(const SkMatrix in, SkMatrix* affine, | 710 static bool split_perspective(const SkMatrix in, SkMatrix* affine, |
| 715 SkMatrix* perspectiveInverse) { | 711 SkMatrix* perspectiveInverse) { |
| 716 const SkScalar p2 = in[SkMatrix::kMPersp2]; | 712 const SkScalar p2 = in[SkMatrix::kMPersp2]; |
| 717 | 713 |
| 718 if (SkScalarNearlyZero(p2)) { | 714 if (SkScalarNearlyZero(p2)) { |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 899 SkPDFFunctionShader* pdfFunctionShader = | 895 SkPDFFunctionShader* pdfFunctionShader = |
| 900 SkNEW_ARGS(SkPDFFunctionShader, (canon, autoState->detach())); | 896 SkNEW_ARGS(SkPDFFunctionShader, (canon, autoState->detach())); |
| 901 | 897 |
| 902 pdfFunctionShader->fResources.push(function); | 898 pdfFunctionShader->fResources.push(function); |
| 903 // Pass ownership to resource list. | 899 // Pass ownership to resource list. |
| 904 | 900 |
| 905 pdfFunctionShader->insertInt("PatternType", 2); | 901 pdfFunctionShader->insertInt("PatternType", 2); |
| 906 pdfFunctionShader->insert("Matrix", matrixArray.get()); | 902 pdfFunctionShader->insert("Matrix", matrixArray.get()); |
| 907 pdfFunctionShader->insert("Shading", pdfShader.get()); | 903 pdfFunctionShader->insert("Shading", pdfShader.get()); |
| 908 | 904 |
| 909 canon->addFunctionShader(pdfFunctionShader); | 905 canon->addFunctionShader(SkRef(pdfFunctionShader)); |
| 910 return pdfFunctionShader; | 906 return pdfFunctionShader; |
| 911 } | 907 } |
| 912 | 908 |
| 913 SkPDFImageShader* SkPDFImageShader::Create( | 909 SkPDFImageShader* SkPDFImageShader::Create( |
| 914 SkPDFCanon* canon, | 910 SkPDFCanon* canon, |
| 915 SkScalar dpi, | 911 SkScalar dpi, |
| 916 SkAutoTDelete<SkPDFShader::State>* autoState) { | 912 SkAutoTDelete<SkPDFShader::State>* autoState) { |
| 917 const SkPDFShader::State& state = **autoState; | 913 const SkPDFShader::State& state = **autoState; |
| 918 | 914 |
| 919 state.fImage.lockPixels(); | 915 state.fImage.lockPixels(); |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1114 | 1110 |
| 1115 SkPDFImageShader* imageShader = | 1111 SkPDFImageShader* imageShader = |
| 1116 SkNEW_ARGS(SkPDFImageShader, (canon, autoState->detach())); | 1112 SkNEW_ARGS(SkPDFImageShader, (canon, autoState->detach())); |
| 1117 imageShader->setData(content.get()); | 1113 imageShader->setData(content.get()); |
| 1118 | 1114 |
| 1119 populate_tiling_pattern_dict(imageShader, patternBBox, | 1115 populate_tiling_pattern_dict(imageShader, patternBBox, |
| 1120 patternDevice->getResourceDict(), finalMatrix); | 1116 patternDevice->getResourceDict(), finalMatrix); |
| 1121 | 1117 |
| 1122 imageShader->fShaderState->fImage.unlockPixels(); | 1118 imageShader->fShaderState->fImage.unlockPixels(); |
| 1123 | 1119 |
| 1124 canon->addImageShader(imageShader); | 1120 canon->addImageShader(SkRef(imageShader)); |
| 1125 return imageShader; | 1121 return imageShader; |
| 1126 } | 1122 } |
| 1127 | 1123 |
| 1128 bool SkPDFShader::State::operator==(const SkPDFShader::State& b) const { | 1124 bool SkPDFShader::State::operator==(const SkPDFShader::State& b) const { |
| 1129 if (fType != b.fType || | 1125 if (fType != b.fType || |
| 1130 fCanvasTransform != b.fCanvasTransform || | 1126 fCanvasTransform != b.fCanvasTransform || |
| 1131 fShaderTransform != b.fShaderTransform || | 1127 fShaderTransform != b.fShaderTransform || |
| 1132 fBBox != b.fBBox) { | 1128 fBBox != b.fBBox) { |
| 1133 return false; | 1129 return false; |
| 1134 } | 1130 } |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1317 return false; | 1313 return false; |
| 1318 } | 1314 } |
| 1319 | 1315 |
| 1320 void SkPDFShader::State::AllocateGradientInfoStorage() { | 1316 void SkPDFShader::State::AllocateGradientInfoStorage() { |
| 1321 fColorData.set(sk_malloc_throw( | 1317 fColorData.set(sk_malloc_throw( |
| 1322 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); | 1318 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); |
| 1323 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); | 1319 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); |
| 1324 fInfo.fColorOffsets = | 1320 fInfo.fColorOffsets = |
| 1325 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); | 1321 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); |
| 1326 } | 1322 } |
| OLD | NEW |