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 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 SkScalar dpi, | 568 SkScalar dpi, |
569 const SkShader& shader, | 569 const SkShader& shader, |
570 const SkMatrix& matrix, | 570 const SkMatrix& matrix, |
571 const SkIRect& surfaceBBox, | 571 const SkIRect& surfaceBBox, |
572 SkScalar rasterScale) { | 572 SkScalar rasterScale) { |
573 SkAutoTDelete<SkPDFShader::State> state( | 573 SkAutoTDelete<SkPDFShader::State> state( |
574 SkNEW_ARGS(State, (shader, matrix, surfaceBBox, rasterScale))); | 574 SkNEW_ARGS(State, (shader, matrix, surfaceBBox, rasterScale))); |
575 return get_pdf_shader_by_state(canon, dpi, &state); | 575 return get_pdf_shader_by_state(canon, dpi, &state); |
576 } | 576 } |
577 | 577 |
578 static SkPDFResourceDict* get_gradient_resource_dict( | 578 static SkPDFDict* get_gradient_resource_dict( |
579 SkPDFObject* functionShader, | 579 SkPDFObject* functionShader, |
580 SkPDFObject* gState) { | 580 SkPDFObject* gState) { |
581 SkPDFResourceDict* dict = new SkPDFResourceDict(); | 581 SkTDArray<SkPDFObject*> patterns; |
582 | 582 if (functionShader) { |
583 if (functionShader != NULL) { | 583 patterns.push(functionShader); |
584 dict->insertResourceAsReference( | |
585 SkPDFResourceDict::kPattern_ResourceType, 0, functionShader); | |
586 } | 584 } |
587 if (gState != NULL) { | 585 SkTDArray<SkPDFObject*> graphicStates; |
588 dict->insertResourceAsReference( | 586 if (gState) { |
589 SkPDFResourceDict::kExtGState_ResourceType, 0, gState); | 587 graphicStates.push(gState); |
590 } | 588 } |
591 | 589 return SkPDFResourceDict::Create(&graphicStates, &patterns, NULL, NULL); |
592 return dict; | |
593 } | 590 } |
594 | 591 |
595 static void populate_tiling_pattern_dict(SkPDFDict* pattern, | 592 static void populate_tiling_pattern_dict(SkPDFDict* pattern, |
596 SkRect& bbox, | 593 SkRect& bbox, |
597 SkPDFDict* resources, | 594 SkPDFDict* resources, |
598 const SkMatrix& matrix) { | 595 const SkMatrix& matrix) { |
599 const int kTiling_PatternType = 1; | 596 const int kTiling_PatternType = 1; |
600 const int kColoredTilingPattern_PaintType = 1; | 597 const int kColoredTilingPattern_PaintType = 1; |
601 const int kConstantSpacing_TilingType = 1; | 598 const int kConstantSpacing_TilingType = 1; |
602 | 599 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 SkRect bbox; | 637 SkRect bbox; |
641 bbox.set(state.fBBox); | 638 bbox.set(state.fBBox); |
642 | 639 |
643 SkAutoTDelete<SkPDFShader::State> alphaToLuminosityState( | 640 SkAutoTDelete<SkPDFShader::State> alphaToLuminosityState( |
644 state.CreateAlphaToLuminosityState()); | 641 state.CreateAlphaToLuminosityState()); |
645 SkAutoTUnref<SkPDFObject> luminosityShader( | 642 SkAutoTUnref<SkPDFObject> luminosityShader( |
646 get_pdf_shader_by_state(canon, dpi, &alphaToLuminosityState)); | 643 get_pdf_shader_by_state(canon, dpi, &alphaToLuminosityState)); |
647 | 644 |
648 SkAutoTDelete<SkStream> alphaStream(create_pattern_fill_content(-1, bbox)); | 645 SkAutoTDelete<SkStream> alphaStream(create_pattern_fill_content(-1, bbox)); |
649 | 646 |
650 SkAutoTUnref<SkPDFResourceDict> | 647 SkAutoTUnref<SkPDFDict> |
651 resources(get_gradient_resource_dict(luminosityShader, NULL)); | 648 resources(get_gradient_resource_dict(luminosityShader, NULL)); |
652 | 649 |
653 SkAutoTUnref<SkPDFFormXObject> alphaMask( | 650 SkAutoTUnref<SkPDFFormXObject> alphaMask( |
654 new SkPDFFormXObject(alphaStream.get(), bbox, resources.get())); | 651 new SkPDFFormXObject(alphaStream.get(), bbox, resources.get())); |
655 | 652 |
656 return SkPDFGraphicState::GetSMaskGraphicState( | 653 return SkPDFGraphicState::GetSMaskGraphicState( |
657 alphaMask.get(), false, | 654 alphaMask.get(), false, |
658 SkPDFGraphicState::kLuminosity_SMaskMode); | 655 SkPDFGraphicState::kLuminosity_SMaskMode); |
659 } | 656 } |
660 | 657 |
(...skipping 14 matching lines...) Expand all Loading... |
675 } | 672 } |
676 | 673 |
677 // Create resource dict with alpha graphics state as G0 and | 674 // Create resource dict with alpha graphics state as G0 and |
678 // pattern shader as P0, then write content stream. | 675 // pattern shader as P0, then write content stream. |
679 SkAutoTUnref<SkPDFObject> alphaGs( | 676 SkAutoTUnref<SkPDFObject> alphaGs( |
680 create_smask_graphic_state(canon, dpi, state)); | 677 create_smask_graphic_state(canon, dpi, state)); |
681 | 678 |
682 SkPDFAlphaFunctionShader* alphaFunctionShader = | 679 SkPDFAlphaFunctionShader* alphaFunctionShader = |
683 SkNEW_ARGS(SkPDFAlphaFunctionShader, (autoState->detach())); | 680 SkNEW_ARGS(SkPDFAlphaFunctionShader, (autoState->detach())); |
684 | 681 |
685 SkAutoTUnref<SkPDFResourceDict> resourceDict( | 682 SkAutoTUnref<SkPDFDict> resourceDict( |
686 get_gradient_resource_dict(colorShader.get(), alphaGs.get())); | 683 get_gradient_resource_dict(colorShader.get(), alphaGs.get())); |
687 | 684 |
688 SkAutoTDelete<SkStream> colorStream( | 685 SkAutoTDelete<SkStream> colorStream( |
689 create_pattern_fill_content(0, bbox)); | 686 create_pattern_fill_content(0, bbox)); |
690 alphaFunctionShader->setData(colorStream.get()); | 687 alphaFunctionShader->setData(colorStream.get()); |
691 | 688 |
692 populate_tiling_pattern_dict(alphaFunctionShader, bbox, resourceDict.get(), | 689 populate_tiling_pattern_dict(alphaFunctionShader, bbox, resourceDict.get(), |
693 SkMatrix::I()); | 690 SkMatrix::I()); |
694 canon->addAlphaShader(alphaFunctionShader); | 691 canon->addAlphaShader(alphaFunctionShader); |
695 return alphaFunctionShader; | 692 return alphaFunctionShader; |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1093 } | 1090 } |
1094 } | 1091 } |
1095 | 1092 |
1096 // Put the canvas into the pattern stream (fContent). | 1093 // Put the canvas into the pattern stream (fContent). |
1097 SkAutoTDelete<SkStreamAsset> content(patternDevice->content()); | 1094 SkAutoTDelete<SkStreamAsset> content(patternDevice->content()); |
1098 | 1095 |
1099 SkPDFImageShader* imageShader = | 1096 SkPDFImageShader* imageShader = |
1100 SkNEW_ARGS(SkPDFImageShader, (autoState->detach())); | 1097 SkNEW_ARGS(SkPDFImageShader, (autoState->detach())); |
1101 imageShader->setData(content.get()); | 1098 imageShader->setData(content.get()); |
1102 | 1099 |
1103 SkAutoTUnref<SkPDFResourceDict> resourceDict( | 1100 SkAutoTUnref<SkPDFDict> resourceDict( |
1104 patternDevice->createResourceDict()); | 1101 patternDevice->createResourceDict()); |
1105 populate_tiling_pattern_dict(imageShader, patternBBox, | 1102 populate_tiling_pattern_dict(imageShader, patternBBox, |
1106 resourceDict.get(), finalMatrix); | 1103 resourceDict.get(), finalMatrix); |
1107 | 1104 |
1108 imageShader->fShaderState->fImage.unlockPixels(); | 1105 imageShader->fShaderState->fImage.unlockPixels(); |
1109 | 1106 |
1110 canon->addImageShader(imageShader); | 1107 canon->addImageShader(imageShader); |
1111 return imageShader; | 1108 return imageShader; |
1112 } | 1109 } |
1113 | 1110 |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1303 return false; | 1300 return false; |
1304 } | 1301 } |
1305 | 1302 |
1306 void SkPDFShader::State::AllocateGradientInfoStorage() { | 1303 void SkPDFShader::State::AllocateGradientInfoStorage() { |
1307 fColorData.set(sk_malloc_throw( | 1304 fColorData.set(sk_malloc_throw( |
1308 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); | 1305 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); |
1309 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); | 1306 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); |
1310 fInfo.fColorOffsets = | 1307 fInfo.fColorOffsets = |
1311 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); | 1308 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); |
1312 } | 1309 } |
OLD | NEW |