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 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 bool GradientHasAlpha() const; | 499 bool GradientHasAlpha() const; |
500 | 500 |
501 private: | 501 private: |
502 State(const State& other); | 502 State(const State& other); |
503 State operator=(const State& rhs); | 503 State operator=(const State& rhs); |
504 void AllocateGradientInfoStorage(); | 504 void AllocateGradientInfoStorage(); |
505 }; | 505 }; |
506 | 506 |
507 //////////////////////////////////////////////////////////////////////////////// | 507 //////////////////////////////////////////////////////////////////////////////// |
508 | 508 |
509 SkPDFFunctionShader::SkPDFFunctionShader(SkPDFCanon* canon, | 509 SkPDFFunctionShader::SkPDFFunctionShader(SkPDFShader::State* state) |
510 SkPDFShader::State* state) | 510 : SkPDFDict("Pattern"), fShaderState(state) {} |
511 : SkPDFDict("Pattern"), fCanon(canon), fShaderState(state) {} | |
512 | 511 |
513 SkPDFFunctionShader::~SkPDFFunctionShader() { | 512 SkPDFFunctionShader::~SkPDFFunctionShader() { |
514 fCanon->removeFunctionShader(this); | |
515 fResources.unrefAll(); | 513 fResources.unrefAll(); |
516 } | 514 } |
517 | 515 |
518 bool SkPDFFunctionShader::equals(const SkPDFShader::State& state) const { | 516 bool SkPDFFunctionShader::equals(const SkPDFShader::State& state) const { |
519 return state == *fShaderState; | 517 return state == *fShaderState; |
520 } | 518 } |
521 | 519 |
522 //////////////////////////////////////////////////////////////////////////////// | 520 //////////////////////////////////////////////////////////////////////////////// |
523 | 521 |
524 SkPDFAlphaFunctionShader::SkPDFAlphaFunctionShader(SkPDFCanon* canon, | 522 SkPDFAlphaFunctionShader::SkPDFAlphaFunctionShader(SkPDFShader::State* state) |
525 SkPDFShader::State* state) | 523 : fShaderState(state) {} |
526 : fCanon(canon), fShaderState(state) {} | |
527 | 524 |
528 bool SkPDFAlphaFunctionShader::equals(const SkPDFShader::State& state) const { | 525 bool SkPDFAlphaFunctionShader::equals(const SkPDFShader::State& state) const { |
529 return state == *fShaderState; | 526 return state == *fShaderState; |
530 } | 527 } |
531 | 528 |
532 SkPDFAlphaFunctionShader::~SkPDFAlphaFunctionShader() { | 529 SkPDFAlphaFunctionShader::~SkPDFAlphaFunctionShader() {} |
533 fCanon->removeAlphaShader(this); | |
534 } | |
535 | 530 |
536 //////////////////////////////////////////////////////////////////////////////// | 531 //////////////////////////////////////////////////////////////////////////////// |
537 | 532 |
538 SkPDFImageShader::SkPDFImageShader(SkPDFCanon* canon, SkPDFShader::State* state) | 533 SkPDFImageShader::SkPDFImageShader(SkPDFShader::State* state) |
539 : fCanon(canon), fShaderState(state) {} | 534 : fShaderState(state) {} |
540 | 535 |
541 bool SkPDFImageShader::equals(const SkPDFShader::State& state) const { | 536 bool SkPDFImageShader::equals(const SkPDFShader::State& state) const { |
542 return state == *fShaderState; | 537 return state == *fShaderState; |
543 } | 538 } |
544 | 539 |
545 SkPDFImageShader::~SkPDFImageShader() { | 540 SkPDFImageShader::~SkPDFImageShader() { |
546 fCanon->removeImageShader(this); | |
547 fResources.unrefAll(); | 541 fResources.unrefAll(); |
548 } | 542 } |
549 | 543 |
550 //////////////////////////////////////////////////////////////////////////////// | 544 //////////////////////////////////////////////////////////////////////////////// |
551 | 545 |
552 static SkPDFObject* get_pdf_shader_by_state( | 546 static SkPDFObject* get_pdf_shader_by_state( |
553 SkPDFCanon* canon, | 547 SkPDFCanon* canon, |
554 SkScalar dpi, | 548 SkScalar dpi, |
555 SkAutoTDelete<SkPDFShader::State>* autoState) { | 549 SkAutoTDelete<SkPDFShader::State>* autoState) { |
556 const SkPDFShader::State& state = **autoState; | 550 const SkPDFShader::State& state = **autoState; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 if (!colorShader) { | 678 if (!colorShader) { |
685 return NULL; | 679 return NULL; |
686 } | 680 } |
687 | 681 |
688 // Create resource dict with alpha graphics state as G0 and | 682 // Create resource dict with alpha graphics state as G0 and |
689 // pattern shader as P0, then write content stream. | 683 // pattern shader as P0, then write content stream. |
690 SkAutoTUnref<SkPDFGraphicState> alphaGs( | 684 SkAutoTUnref<SkPDFGraphicState> alphaGs( |
691 create_smask_graphic_state(canon, dpi, state)); | 685 create_smask_graphic_state(canon, dpi, state)); |
692 | 686 |
693 SkPDFAlphaFunctionShader* alphaFunctionShader = | 687 SkPDFAlphaFunctionShader* alphaFunctionShader = |
694 SkNEW_ARGS(SkPDFAlphaFunctionShader, (canon, autoState->detach())); | 688 SkNEW_ARGS(SkPDFAlphaFunctionShader, (autoState->detach())); |
695 | 689 |
696 alphaFunctionShader->fColorShader.reset(colorShader); | 690 alphaFunctionShader->fColorShader.reset(colorShader); |
697 | 691 |
698 alphaFunctionShader->fResourceDict.reset(get_gradient_resource_dict( | 692 alphaFunctionShader->fResourceDict.reset(get_gradient_resource_dict( |
699 alphaFunctionShader->fColorShader.get(), alphaGs.get())); | 693 alphaFunctionShader->fColorShader.get(), alphaGs.get())); |
700 | 694 |
701 SkAutoTDelete<SkStream> colorStream( | 695 SkAutoTDelete<SkStream> colorStream( |
702 create_pattern_fill_content(0, bbox)); | 696 create_pattern_fill_content(0, bbox)); |
703 alphaFunctionShader->setData(colorStream.get()); | 697 alphaFunctionShader->setData(colorStream.get()); |
704 | 698 |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
890 pdfShader->insertName("ColorSpace", "DeviceRGB"); | 884 pdfShader->insertName("ColorSpace", "DeviceRGB"); |
891 pdfShader->insert("Domain", domain.get()); | 885 pdfShader->insert("Domain", domain.get()); |
892 | 886 |
893 SkPDFStream* function = make_ps_function(functionCode, domain.get()); | 887 SkPDFStream* function = make_ps_function(functionCode, domain.get()); |
894 pdfShader->insert("Function", new SkPDFObjRef(function))->unref(); | 888 pdfShader->insert("Function", new SkPDFObjRef(function))->unref(); |
895 | 889 |
896 SkAutoTUnref<SkPDFArray> matrixArray( | 890 SkAutoTUnref<SkPDFArray> matrixArray( |
897 SkPDFUtils::MatrixToArray(finalMatrix)); | 891 SkPDFUtils::MatrixToArray(finalMatrix)); |
898 | 892 |
899 SkPDFFunctionShader* pdfFunctionShader = | 893 SkPDFFunctionShader* pdfFunctionShader = |
900 SkNEW_ARGS(SkPDFFunctionShader, (canon, autoState->detach())); | 894 SkNEW_ARGS(SkPDFFunctionShader, (autoState->detach())); |
901 | 895 |
902 pdfFunctionShader->fResources.push(function); | 896 pdfFunctionShader->fResources.push(function); |
903 // Pass ownership to resource list. | 897 // Pass ownership to resource list. |
904 | 898 |
905 pdfFunctionShader->insertInt("PatternType", 2); | 899 pdfFunctionShader->insertInt("PatternType", 2); |
906 pdfFunctionShader->insert("Matrix", matrixArray.get()); | 900 pdfFunctionShader->insert("Matrix", matrixArray.get()); |
907 pdfFunctionShader->insert("Shading", pdfShader.get()); | 901 pdfFunctionShader->insert("Shading", pdfShader.get()); |
908 | 902 |
909 canon->addFunctionShader(pdfFunctionShader); | 903 canon->addFunctionShader(pdfFunctionShader); |
910 return pdfFunctionShader; | 904 return pdfFunctionShader; |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1106 drawBitmapMatrix(&canvas, bottom, bottomMatrix); | 1100 drawBitmapMatrix(&canvas, bottom, bottomMatrix); |
1107 } | 1101 } |
1108 patternBBox.fBottom = deviceBounds.height(); | 1102 patternBBox.fBottom = deviceBounds.height(); |
1109 } | 1103 } |
1110 } | 1104 } |
1111 | 1105 |
1112 // Put the canvas into the pattern stream (fContent). | 1106 // Put the canvas into the pattern stream (fContent). |
1113 SkAutoTDelete<SkStreamAsset> content(patternDevice->content()); | 1107 SkAutoTDelete<SkStreamAsset> content(patternDevice->content()); |
1114 | 1108 |
1115 SkPDFImageShader* imageShader = | 1109 SkPDFImageShader* imageShader = |
1116 SkNEW_ARGS(SkPDFImageShader, (canon, autoState->detach())); | 1110 SkNEW_ARGS(SkPDFImageShader, (autoState->detach())); |
1117 imageShader->setData(content.get()); | 1111 imageShader->setData(content.get()); |
1118 | 1112 |
1119 populate_tiling_pattern_dict(imageShader, patternBBox, | 1113 populate_tiling_pattern_dict(imageShader, patternBBox, |
1120 patternDevice->getResourceDict(), finalMatrix); | 1114 patternDevice->getResourceDict(), finalMatrix); |
1121 | 1115 |
1122 imageShader->fShaderState->fImage.unlockPixels(); | 1116 imageShader->fShaderState->fImage.unlockPixels(); |
1123 | 1117 |
1124 canon->addImageShader(imageShader); | 1118 canon->addImageShader(imageShader); |
1125 return imageShader; | 1119 return imageShader; |
1126 } | 1120 } |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1317 return false; | 1311 return false; |
1318 } | 1312 } |
1319 | 1313 |
1320 void SkPDFShader::State::AllocateGradientInfoStorage() { | 1314 void SkPDFShader::State::AllocateGradientInfoStorage() { |
1321 fColorData.set(sk_malloc_throw( | 1315 fColorData.set(sk_malloc_throw( |
1322 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); | 1316 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); |
1323 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); | 1317 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); |
1324 fInfo.fColorOffsets = | 1318 fInfo.fColorOffsets = |
1325 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); | 1319 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); |
1326 } | 1320 } |
OLD | NEW |