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 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 * luminosity mode. The shader pattern extends to the bbox. | 756 * luminosity mode. The shader pattern extends to the bbox. |
757 */ | 757 */ |
758 SkPDFGraphicState* SkPDFAlphaFunctionShader::CreateSMaskGraphicState() { | 758 SkPDFGraphicState* SkPDFAlphaFunctionShader::CreateSMaskGraphicState() { |
759 SkRect bbox; | 759 SkRect bbox; |
760 bbox.set(fState.get()->fBBox); | 760 bbox.set(fState.get()->fBBox); |
761 | 761 |
762 SkAutoTUnref<SkPDFObject> luminosityShader( | 762 SkAutoTUnref<SkPDFObject> luminosityShader( |
763 SkPDFShader::GetPDFShaderByState( | 763 SkPDFShader::GetPDFShaderByState( |
764 fState->CreateAlphaToLuminosityState())); | 764 fState->CreateAlphaToLuminosityState())); |
765 | 765 |
766 SkAutoTUnref<SkStream> alphaStream(create_pattern_fill_content(-1, bbox)); | 766 SkAutoTDelete<SkStream> alphaStream(create_pattern_fill_content(-1, bbox)); |
767 | 767 |
768 SkAutoTUnref<SkPDFResourceDict> | 768 SkAutoTUnref<SkPDFResourceDict> |
769 resources(get_gradient_resource_dict(luminosityShader, NULL)); | 769 resources(get_gradient_resource_dict(luminosityShader, NULL)); |
770 | 770 |
771 SkAutoTUnref<SkPDFFormXObject> alphaMask( | 771 SkAutoTUnref<SkPDFFormXObject> alphaMask( |
772 new SkPDFFormXObject(alphaStream.get(), bbox, resources.get())); | 772 new SkPDFFormXObject(alphaStream.get(), bbox, resources.get())); |
773 | 773 |
774 return SkPDFGraphicState::GetSMaskGraphicState( | 774 return SkPDFGraphicState::GetSMaskGraphicState( |
775 alphaMask.get(), false, | 775 alphaMask.get(), false, |
776 SkPDFGraphicState::kLuminosity_SMaskMode); | 776 SkPDFGraphicState::kLuminosity_SMaskMode); |
777 } | 777 } |
778 | 778 |
779 SkPDFAlphaFunctionShader::SkPDFAlphaFunctionShader(SkPDFShader::State* state) | 779 SkPDFAlphaFunctionShader::SkPDFAlphaFunctionShader(SkPDFShader::State* state) |
780 : fState(state) { | 780 : fState(state) { |
781 SkRect bbox; | 781 SkRect bbox; |
782 bbox.set(fState.get()->fBBox); | 782 bbox.set(fState.get()->fBBox); |
783 | 783 |
784 fColorShader.reset( | 784 fColorShader.reset( |
785 SkPDFShader::GetPDFShaderByState(state->CreateOpaqueState())); | 785 SkPDFShader::GetPDFShaderByState(state->CreateOpaqueState())); |
786 | 786 |
787 // Create resource dict with alpha graphics state as G0 and | 787 // Create resource dict with alpha graphics state as G0 and |
788 // pattern shader as P0, then write content stream. | 788 // pattern shader as P0, then write content stream. |
789 SkAutoTUnref<SkPDFGraphicState> alphaGs(CreateSMaskGraphicState()); | 789 SkAutoTUnref<SkPDFGraphicState> alphaGs(CreateSMaskGraphicState()); |
790 fResourceDict.reset( | 790 fResourceDict.reset( |
791 get_gradient_resource_dict(fColorShader.get(), alphaGs.get())); | 791 get_gradient_resource_dict(fColorShader.get(), alphaGs.get())); |
792 | 792 |
793 SkAutoTUnref<SkStream> colorStream( | 793 SkAutoTDelete<SkStream> colorStream( |
794 create_pattern_fill_content(0, bbox)); | 794 create_pattern_fill_content(0, bbox)); |
795 setData(colorStream.get()); | 795 setData(colorStream.get()); |
796 | 796 |
797 populate_tiling_pattern_dict(this, bbox, fResourceDict.get(), | 797 populate_tiling_pattern_dict(this, bbox, fResourceDict.get(), |
798 SkMatrix::I()); | 798 SkMatrix::I()); |
799 } | 799 } |
800 | 800 |
801 // Finds affine and persp such that in = affine * persp. | 801 // Finds affine and persp such that in = affine * persp. |
802 // but it returns the inverse of perspective matrix. | 802 // but it returns the inverse of perspective matrix. |
803 static bool split_perspective(const SkMatrix in, SkMatrix* affine, | 803 static bool split_perspective(const SkMatrix in, SkMatrix* affine, |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1149 if (tileModes[0] == SkShader::kMirror_TileMode) { | 1149 if (tileModes[0] == SkShader::kMirror_TileMode) { |
1150 bottomMatrix.postScale(-1, 1); | 1150 bottomMatrix.postScale(-1, 1); |
1151 bottomMatrix.postTranslate(2 * width, 0); | 1151 bottomMatrix.postTranslate(2 * width, 0); |
1152 drawBitmapMatrix(&canvas, bottom, bottomMatrix); | 1152 drawBitmapMatrix(&canvas, bottom, bottomMatrix); |
1153 } | 1153 } |
1154 patternBBox.fBottom = deviceBounds.height(); | 1154 patternBBox.fBottom = deviceBounds.height(); |
1155 } | 1155 } |
1156 } | 1156 } |
1157 | 1157 |
1158 // Put the canvas into the pattern stream (fContent). | 1158 // Put the canvas into the pattern stream (fContent). |
1159 SkAutoTUnref<SkStream> content(pattern.content()); | 1159 SkAutoTDelete<SkStream> content(pattern.content()); |
1160 setData(content.get()); | 1160 setData(content.get()); |
1161 SkPDFResourceDict* resourceDict = pattern.getResourceDict(); | 1161 SkPDFResourceDict* resourceDict = pattern.getResourceDict(); |
1162 resourceDict->getReferencedResources(fResources, &fResources, false); | 1162 resourceDict->getReferencedResources(fResources, &fResources, false); |
1163 | 1163 |
1164 populate_tiling_pattern_dict(this, patternBBox, | 1164 populate_tiling_pattern_dict(this, patternBBox, |
1165 pattern.getResourceDict(), finalMatrix); | 1165 pattern.getResourceDict(), finalMatrix); |
1166 | 1166 |
1167 fState.get()->fImage.unlockPixels(); | 1167 fState.get()->fImage.unlockPixels(); |
1168 } | 1168 } |
1169 | 1169 |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1369 return false; | 1369 return false; |
1370 } | 1370 } |
1371 | 1371 |
1372 void SkPDFShader::State::AllocateGradientInfoStorage() { | 1372 void SkPDFShader::State::AllocateGradientInfoStorage() { |
1373 fColorData.set(sk_malloc_throw( | 1373 fColorData.set(sk_malloc_throw( |
1374 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); | 1374 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); |
1375 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); | 1375 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); |
1376 fInfo.fColorOffsets = | 1376 fInfo.fColorOffsets = |
1377 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); | 1377 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); |
1378 } | 1378 } |
OLD | NEW |