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" |
11 | 11 |
12 #include "SkData.h" | 12 #include "SkData.h" |
| 13 #include "SkOncePtr.h" |
13 #include "SkPDFCanon.h" | 14 #include "SkPDFCanon.h" |
14 #include "SkPDFDevice.h" | 15 #include "SkPDFDevice.h" |
15 #include "SkPDFFormXObject.h" | 16 #include "SkPDFFormXObject.h" |
16 #include "SkPDFGraphicState.h" | 17 #include "SkPDFGraphicState.h" |
17 #include "SkPDFResourceDict.h" | 18 #include "SkPDFResourceDict.h" |
18 #include "SkPDFUtils.h" | 19 #include "SkPDFUtils.h" |
19 #include "SkScalar.h" | 20 #include "SkScalar.h" |
20 #include "SkStream.h" | 21 #include "SkStream.h" |
21 #include "SkTemplates.h" | 22 #include "SkTemplates.h" |
22 #include "SkTypes.h" | 23 #include "SkTypes.h" |
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 zero, one, zero, | 671 zero, one, zero, |
671 -p0/p2, -p1/p2, 1/p2); | 672 -p0/p2, -p1/p2, 1/p2); |
672 | 673 |
673 affine->setAll(sx - p0 * tx / p2, kx - p1 * tx / p2, tx / p2, | 674 affine->setAll(sx - p0 * tx / p2, kx - p1 * tx / p2, tx / p2, |
674 ky - p0 * ty / p2, sy - p1 * ty / p2, ty / p2, | 675 ky - p0 * ty / p2, sy - p1 * ty / p2, ty / p2, |
675 zero, zero, one); | 676 zero, zero, one); |
676 | 677 |
677 return true; | 678 return true; |
678 } | 679 } |
679 | 680 |
680 namespace { | 681 static SkPDFObject* create_range_object() { |
681 SkPDFObject* create_range_object() { | |
682 SkPDFArray* range = new SkPDFArray; | 682 SkPDFArray* range = new SkPDFArray; |
683 range->reserve(6); | 683 range->reserve(6); |
684 range->appendInt(0); | 684 range->appendInt(0); |
685 range->appendInt(1); | 685 range->appendInt(1); |
686 range->appendInt(0); | 686 range->appendInt(0); |
687 range->appendInt(1); | 687 range->appendInt(1); |
688 range->appendInt(0); | 688 range->appendInt(0); |
689 range->appendInt(1); | 689 range->appendInt(1); |
690 return range; | 690 return range; |
691 } | 691 } |
692 | 692 SK_DECLARE_STATIC_ONCE_PTR(SkPDFObject, rangeObject); |
693 template <typename T> void unref(T* ptr) { ptr->unref();} | |
694 } // namespace | |
695 | |
696 SK_DECLARE_STATIC_LAZY_PTR(SkPDFObject, rangeObject, | |
697 create_range_object, unref<SkPDFObject>); | |
698 | 693 |
699 static SkPDFStream* make_ps_function(const SkString& psCode, | 694 static SkPDFStream* make_ps_function(const SkString& psCode, |
700 SkPDFArray* domain) { | 695 SkPDFArray* domain) { |
701 SkAutoDataUnref funcData( | 696 SkAutoDataUnref funcData( |
702 SkData::NewWithCopy(psCode.c_str(), psCode.size())); | 697 SkData::NewWithCopy(psCode.c_str(), psCode.size())); |
703 SkPDFStream* result = new SkPDFStream(funcData.get()); | 698 SkPDFStream* result = new SkPDFStream(funcData.get()); |
704 result->insertInt("FunctionType", 4); | 699 result->insertInt("FunctionType", 4); |
705 result->insertObject("Domain", SkRef(domain)); | 700 result->insertObject("Domain", SkRef(domain)); |
706 result->insertObject("Range", SkRef(rangeObject.get())); | 701 result->insertObject("Range", SkRef(rangeObject.get(create_range_object))); |
707 return result; | 702 return result; |
708 } | 703 } |
709 | 704 |
710 SkPDFFunctionShader* SkPDFFunctionShader::Create( | 705 SkPDFFunctionShader* SkPDFFunctionShader::Create( |
711 SkPDFCanon* canon, SkAutoTDelete<SkPDFShader::State>* autoState) { | 706 SkPDFCanon* canon, SkAutoTDelete<SkPDFShader::State>* autoState) { |
712 const SkPDFShader::State& state = **autoState; | 707 const SkPDFShader::State& state = **autoState; |
713 | 708 |
714 SkString (*codeFunction)(const SkShader::GradientInfo& info, | 709 SkString (*codeFunction)(const SkShader::GradientInfo& info, |
715 const SkMatrix& perspectiveRemover) = nullptr; | 710 const SkMatrix& perspectiveRemover) = nullptr; |
716 SkPoint transformPoints[2]; | 711 SkPoint transformPoints[2]; |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1229 return false; | 1224 return false; |
1230 } | 1225 } |
1231 | 1226 |
1232 void SkPDFShader::State::AllocateGradientInfoStorage() { | 1227 void SkPDFShader::State::AllocateGradientInfoStorage() { |
1233 fColorData.set(sk_malloc_throw( | 1228 fColorData.set(sk_malloc_throw( |
1234 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); | 1229 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); |
1235 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); | 1230 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); |
1236 fInfo.fColorOffsets = | 1231 fInfo.fColorOffsets = |
1237 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); | 1232 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); |
1238 } | 1233 } |
OLD | NEW |