| 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 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 if (!matrix.isIdentity()) { | 665 if (!matrix.isIdentity()) { |
| 666 pattern->insertObject("Matrix", SkPDFUtils::MatrixToArray(matrix)); | 666 pattern->insertObject("Matrix", SkPDFUtils::MatrixToArray(matrix)); |
| 667 } | 667 } |
| 668 } | 668 } |
| 669 | 669 |
| 670 /** | 670 /** |
| 671 * Creates a content stream which fills the pattern P0 across bounds. | 671 * Creates a content stream which fills the pattern P0 across bounds. |
| 672 * @param gsIndex A graphics state resource index to apply, or <0 if no | 672 * @param gsIndex A graphics state resource index to apply, or <0 if no |
| 673 * graphics state to apply. | 673 * graphics state to apply. |
| 674 */ | 674 */ |
| 675 static SkStream* create_pattern_fill_content(int gsIndex, SkRect& bounds) { | 675 static SkStreamAsset* create_pattern_fill_content(int gsIndex, SkRect& bounds) { |
| 676 SkDynamicMemoryWStream content; | 676 SkDynamicMemoryWStream content; |
| 677 if (gsIndex >= 0) { | 677 if (gsIndex >= 0) { |
| 678 SkPDFUtils::ApplyGraphicState(gsIndex, &content); | 678 SkPDFUtils::ApplyGraphicState(gsIndex, &content); |
| 679 } | 679 } |
| 680 SkPDFUtils::ApplyPattern(0, &content); | 680 SkPDFUtils::ApplyPattern(0, &content); |
| 681 SkPDFUtils::AppendRectangle(bounds, &content); | 681 SkPDFUtils::AppendRectangle(bounds, &content); |
| 682 SkPDFUtils::PaintPath(SkPaint::kFill_Style, SkPath::kEvenOdd_FillType, | 682 SkPDFUtils::PaintPath(SkPaint::kFill_Style, SkPath::kEvenOdd_FillType, |
| 683 &content); | 683 &content); |
| 684 | 684 |
| 685 return content.detachAsStream(); | 685 return content.detachAsStream(); |
| 686 } | 686 } |
| 687 | 687 |
| 688 /** | 688 /** |
| 689 * Creates a ExtGState with the SMask set to the luminosityShader in | 689 * Creates a ExtGState with the SMask set to the luminosityShader in |
| 690 * luminosity mode. The shader pattern extends to the bbox. | 690 * luminosity mode. The shader pattern extends to the bbox. |
| 691 */ | 691 */ |
| 692 static sk_sp<SkPDFObject> create_smask_graphic_state( | 692 static sk_sp<SkPDFObject> create_smask_graphic_state( |
| 693 SkPDFDocument* doc, SkScalar dpi, const SkPDFShader::State& state) { | 693 SkPDFDocument* doc, SkScalar dpi, const SkPDFShader::State& state) { |
| 694 SkRect bbox; | 694 SkRect bbox; |
| 695 bbox.set(state.fBBox); | 695 bbox.set(state.fBBox); |
| 696 | 696 |
| 697 std::unique_ptr<SkPDFShader::State> alphaToLuminosityState( | 697 std::unique_ptr<SkPDFShader::State> alphaToLuminosityState( |
| 698 state.CreateAlphaToLuminosityState()); | 698 state.CreateAlphaToLuminosityState()); |
| 699 sk_sp<SkPDFObject> luminosityShader( | 699 sk_sp<SkPDFObject> luminosityShader( |
| 700 get_pdf_shader_by_state(doc, dpi, &alphaToLuminosityState)); | 700 get_pdf_shader_by_state(doc, dpi, &alphaToLuminosityState)); |
| 701 | 701 |
| 702 std::unique_ptr<SkStream> alphaStream(create_pattern_fill_content(-1, bbox))
; | 702 std::unique_ptr<SkStreamAsset> alphaStream(create_pattern_fill_content(-1, b
box)); |
| 703 | 703 |
| 704 auto resources = | 704 auto resources = |
| 705 get_gradient_resource_dict(luminosityShader.get(), nullptr); | 705 get_gradient_resource_dict(luminosityShader.get(), nullptr); |
| 706 | 706 |
| 707 sk_sp<SkPDFFormXObject> alphaMask( | 707 sk_sp<SkPDFFormXObject> alphaMask( |
| 708 new SkPDFFormXObject(alphaStream.get(), bbox, resources.get())); | 708 new SkPDFFormXObject(alphaStream.get(), bbox, resources.get())); |
| 709 | 709 |
| 710 return SkPDFGraphicState::GetSMaskGraphicState( | 710 return SkPDFGraphicState::GetSMaskGraphicState( |
| 711 alphaMask.get(), false, | 711 alphaMask.get(), false, |
| 712 SkPDFGraphicState::kLuminosity_SMaskMode, doc->canon()); | 712 SkPDFGraphicState::kLuminosity_SMaskMode, doc->canon()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 731 // Create resource dict with alpha graphics state as G0 and | 731 // Create resource dict with alpha graphics state as G0 and |
| 732 // pattern shader as P0, then write content stream. | 732 // pattern shader as P0, then write content stream. |
| 733 auto alphaGs = create_smask_graphic_state(doc, dpi, state); | 733 auto alphaGs = create_smask_graphic_state(doc, dpi, state); |
| 734 | 734 |
| 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<SkStream> colorStream( | 741 std::unique_ptr<SkStreamAsset> colorStream( |
| 742 create_pattern_fill_content(0, bbox)); | 742 create_pattern_fill_content(0, bbox)); |
| 743 alphaFunctionShader->setData(colorStream.get()); | 743 alphaFunctionShader->setData(colorStream.get()); |
| 744 | 744 |
| 745 populate_tiling_pattern_dict(alphaFunctionShader, bbox, resourceDict.get(), | 745 populate_tiling_pattern_dict(alphaFunctionShader, bbox, resourceDict.get(), |
| 746 SkMatrix::I()); | 746 SkMatrix::I()); |
| 747 doc->canon()->addAlphaShader(alphaFunctionShader); | 747 doc->canon()->addAlphaShader(alphaFunctionShader); |
| 748 return alphaFunctionShader; | 748 return alphaFunctionShader; |
| 749 } | 749 } |
| 750 | 750 |
| 751 // Finds affine and persp such that in = affine * persp. | 751 // Finds affine and persp such that in = affine * persp. |
| (...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1411 return false; | 1411 return false; |
| 1412 } | 1412 } |
| 1413 | 1413 |
| 1414 void SkPDFShader::State::AllocateGradientInfoStorage() { | 1414 void SkPDFShader::State::AllocateGradientInfoStorage() { |
| 1415 fColorData.set(sk_malloc_throw( | 1415 fColorData.set(sk_malloc_throw( |
| 1416 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); | 1416 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); |
| 1417 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); | 1417 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); |
| 1418 fInfo.fColorOffsets = | 1418 fInfo.fColorOffsets = |
| 1419 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); | 1419 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); |
| 1420 } | 1420 } |
| OLD | NEW |