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 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 state.CreateAlphaToLuminosityState()); | 697 state.CreateAlphaToLuminosityState()); |
698 sk_sp<SkPDFObject> luminosityShader( | 698 sk_sp<SkPDFObject> luminosityShader( |
699 get_pdf_shader_by_state(doc, dpi, &alphaToLuminosityState)); | 699 get_pdf_shader_by_state(doc, dpi, &alphaToLuminosityState)); |
700 | 700 |
701 std::unique_ptr<SkStreamAsset> alphaStream(create_pattern_fill_content(-1, b
box)); | 701 std::unique_ptr<SkStreamAsset> alphaStream(create_pattern_fill_content(-1, b
box)); |
702 | 702 |
703 auto resources = | 703 auto resources = |
704 get_gradient_resource_dict(luminosityShader.get(), nullptr); | 704 get_gradient_resource_dict(luminosityShader.get(), nullptr); |
705 | 705 |
706 sk_sp<SkPDFFormXObject> alphaMask( | 706 sk_sp<SkPDFFormXObject> alphaMask( |
707 new SkPDFFormXObject(alphaStream.get(), bbox, resources.get())); | 707 new SkPDFFormXObject(std::move(alphaStream), bbox, resources.get()))
; |
708 | 708 |
709 return SkPDFGraphicState::GetSMaskGraphicState( | 709 return SkPDFGraphicState::GetSMaskGraphicState( |
710 alphaMask.get(), false, | 710 alphaMask.get(), false, |
711 SkPDFGraphicState::kLuminosity_SMaskMode, doc->canon()); | 711 SkPDFGraphicState::kLuminosity_SMaskMode, doc->canon()); |
712 } | 712 } |
713 | 713 |
714 SkPDFAlphaFunctionShader* SkPDFAlphaFunctionShader::Create( | 714 SkPDFAlphaFunctionShader* SkPDFAlphaFunctionShader::Create( |
715 SkPDFDocument* doc, | 715 SkPDFDocument* doc, |
716 SkScalar dpi, | 716 SkScalar dpi, |
717 std::unique_ptr<SkPDFShader::State>* autoState) { | 717 std::unique_ptr<SkPDFShader::State>* autoState) { |
(...skipping 14 matching lines...) Expand all Loading... |
732 auto alphaGs = create_smask_graphic_state(doc, dpi, state); | 732 auto alphaGs = create_smask_graphic_state(doc, dpi, state); |
733 | 733 |
734 SkPDFAlphaFunctionShader* alphaFunctionShader = | 734 SkPDFAlphaFunctionShader* alphaFunctionShader = |
735 new SkPDFAlphaFunctionShader(autoState->release()); | 735 new SkPDFAlphaFunctionShader(autoState->release()); |
736 | 736 |
737 auto resourceDict = | 737 auto resourceDict = |
738 get_gradient_resource_dict(colorShader.get(), alphaGs.get()); | 738 get_gradient_resource_dict(colorShader.get(), alphaGs.get()); |
739 | 739 |
740 std::unique_ptr<SkStreamAsset> colorStream( | 740 std::unique_ptr<SkStreamAsset> colorStream( |
741 create_pattern_fill_content(0, bbox)); | 741 create_pattern_fill_content(0, bbox)); |
742 alphaFunctionShader->setData(colorStream.get()); | 742 alphaFunctionShader->setData(std::move(colorStream)); |
743 | 743 |
744 populate_tiling_pattern_dict(alphaFunctionShader, bbox, resourceDict.get(), | 744 populate_tiling_pattern_dict(alphaFunctionShader, bbox, resourceDict.get(), |
745 SkMatrix::I()); | 745 SkMatrix::I()); |
746 doc->canon()->addAlphaShader(alphaFunctionShader); | 746 doc->canon()->addAlphaShader(alphaFunctionShader); |
747 return alphaFunctionShader; | 747 return alphaFunctionShader; |
748 } | 748 } |
749 | 749 |
750 // Finds affine and persp such that in = affine * persp. | 750 // Finds affine and persp such that in = affine * persp. |
751 // but it returns the inverse of perspective matrix. | 751 // but it returns the inverse of perspective matrix. |
752 static bool split_perspective(const SkMatrix in, SkMatrix* affine, | 752 static bool split_perspective(const SkMatrix in, SkMatrix* affine, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 range->appendInt(1); | 794 range->appendInt(1); |
795 range->appendInt(0); | 795 range->appendInt(0); |
796 range->appendInt(1); | 796 range->appendInt(1); |
797 return range; | 797 return range; |
798 } | 798 } |
799 | 799 |
800 static sk_sp<SkPDFStream> make_ps_function( | 800 static sk_sp<SkPDFStream> make_ps_function( |
801 std::unique_ptr<SkStreamAsset> psCode, | 801 std::unique_ptr<SkStreamAsset> psCode, |
802 SkPDFArray* domain, | 802 SkPDFArray* domain, |
803 sk_sp<SkPDFObject> range) { | 803 sk_sp<SkPDFObject> range) { |
804 auto result = sk_make_sp<SkPDFStream>(psCode.get()); | 804 auto result = sk_make_sp<SkPDFStream>(std::move(psCode)); |
805 result->insertInt("FunctionType", 4); | 805 result->insertInt("FunctionType", 4); |
806 result->insertObject("Domain", sk_ref_sp(domain)); | 806 result->insertObject("Domain", sk_ref_sp(domain)); |
807 result->insertObject("Range", std::move(range)); | 807 result->insertObject("Range", std::move(range)); |
808 return result; | 808 return result; |
809 } | 809 } |
810 | 810 |
811 // catch cases where the inner just touches the outer circle | 811 // catch cases where the inner just touches the outer circle |
812 // and make the inner circle just inside the outer one to match raster | 812 // and make the inner circle just inside the outer one to match raster |
813 static void FixUpRadius(const SkPoint& p1, SkScalar& r1, const SkPoint& p2, SkSc
alar& r2) { | 813 static void FixUpRadius(const SkPoint& p1, SkScalar& r1, const SkPoint& p2, SkSc
alar& r2) { |
814 // detect touching circles | 814 // detect touching circles |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1200 if (tileModes[0] == SkShader::kMirror_TileMode) { | 1200 if (tileModes[0] == SkShader::kMirror_TileMode) { |
1201 bottomMatrix.postScale(-1, 1); | 1201 bottomMatrix.postScale(-1, 1); |
1202 bottomMatrix.postTranslate(2 * width, 0); | 1202 bottomMatrix.postTranslate(2 * width, 0); |
1203 drawBitmapMatrix(&canvas, bottom, bottomMatrix); | 1203 drawBitmapMatrix(&canvas, bottom, bottomMatrix); |
1204 } | 1204 } |
1205 patternBBox.fBottom = deviceBounds.height(); | 1205 patternBBox.fBottom = deviceBounds.height(); |
1206 } | 1206 } |
1207 } | 1207 } |
1208 | 1208 |
1209 // Put the canvas into the pattern stream (fContent). | 1209 // Put the canvas into the pattern stream (fContent). |
1210 auto content = patternDevice->content(); | |
1211 | |
1212 SkPDFImageShader* imageShader = new SkPDFImageShader(autoState->release()); | 1210 SkPDFImageShader* imageShader = new SkPDFImageShader(autoState->release()); |
1213 imageShader->setData(content.get()); | 1211 imageShader->setData(patternDevice->content()); |
1214 | 1212 |
1215 auto resourceDict = patternDevice->makeResourceDict(); | 1213 auto resourceDict = patternDevice->makeResourceDict(); |
1216 populate_tiling_pattern_dict(imageShader, patternBBox, | 1214 populate_tiling_pattern_dict(imageShader, patternBBox, |
1217 resourceDict.get(), finalMatrix); | 1215 resourceDict.get(), finalMatrix); |
1218 | 1216 |
1219 imageShader->fShaderState->fImage.unlockPixels(); | 1217 imageShader->fShaderState->fImage.unlockPixels(); |
1220 | 1218 |
1221 doc->canon()->addImageShader(imageShader); | 1219 doc->canon()->addImageShader(imageShader); |
1222 return imageShader; | 1220 return imageShader; |
1223 } | 1221 } |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1410 return false; | 1408 return false; |
1411 } | 1409 } |
1412 | 1410 |
1413 void SkPDFShader::State::AllocateGradientInfoStorage() { | 1411 void SkPDFShader::State::AllocateGradientInfoStorage() { |
1414 fColorData.set(sk_malloc_throw( | 1412 fColorData.set(sk_malloc_throw( |
1415 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); | 1413 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); |
1416 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); | 1414 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); |
1417 fInfo.fColorOffsets = | 1415 fInfo.fColorOffsets = |
1418 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); | 1416 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); |
1419 } | 1417 } |
OLD | NEW |