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 #ifndef SkPDFShader_DEFINED | 10 #ifndef SkPDFShader_DEFINED |
11 #define SkPDFShader_DEFINED | 11 #define SkPDFShader_DEFINED |
12 | 12 |
13 #include "SkPDFResourceDict.h" | 13 #include "SkPDFResourceDict.h" |
14 #include "SkPDFStream.h" | 14 #include "SkPDFStream.h" |
15 #include "SkPDFTypes.h" | 15 #include "SkPDFTypes.h" |
16 | 16 |
| 17 class SkPDFCanon; |
17 class SkMatrix; | 18 class SkMatrix; |
18 class SkShader; | 19 class SkShader; |
19 struct SkIRect; | 20 struct SkIRect; |
20 | 21 |
21 /** \class SkPDFShader | 22 /** \class SkPDFShader |
22 | 23 |
23 In PDF parlance, this is a pattern, used in place of a color when the | 24 In PDF parlance, this is a pattern, used in place of a color when the |
24 pattern color space is selected. | 25 pattern color space is selected. |
25 */ | 26 */ |
26 | 27 |
27 class SkPDFShader { | 28 class SkPDFShader { |
28 public: | 29 public: |
29 class State; | 30 class State; |
30 | 31 |
31 /** Get the PDF shader for the passed SkShader. If the SkShader is | 32 /** Get the PDF shader for the passed SkShader. If the SkShader is |
32 * invalid in some way, returns NULL. The reference count of | 33 * invalid in some way, returns NULL. The reference count of |
33 * the object is incremented and it is the caller's responsibility to | 34 * the object is incremented and it is the caller's responsibility to |
34 * unreference it when done. This is needed to accommodate the weak | 35 * unreference it when done. This is needed to accommodate the weak |
35 * reference pattern used when the returned object is new and has no | 36 * reference pattern used when the returned object is new and has no |
36 * other references. | 37 * other references. |
37 * @param shader The SkShader to emulate. | 38 * @param shader The SkShader to emulate. |
38 * @param matrix The current transform. (PDF shaders are absolutely | 39 * @param matrix The current transform. (PDF shaders are absolutely |
39 * positioned, relative to where the page is drawn.) | 40 * positioned, relative to where the page is drawn.) |
40 * @param surfceBBox The bounding box of the drawing surface (with matrix | 41 * @param surfceBBox The bounding box of the drawing surface (with matrix |
41 * already applied). | 42 * already applied). |
42 * @param rasterScale Additional scale to be applied for early | 43 * @param rasterScale Additional scale to be applied for early |
43 * rasterization. | 44 * rasterization. |
44 */ | 45 */ |
45 static SkPDFObject* GetPDFShader(const SkShader& shader, | 46 static SkPDFObject* GetPDFShader(SkPDFCanon* canon, |
| 47 SkScalar dpi, |
| 48 const SkShader& shader, |
46 const SkMatrix& matrix, | 49 const SkMatrix& matrix, |
47 const SkIRect& surfaceBBox, | 50 const SkIRect& surfaceBBox, |
48 SkScalar rasterScale); | 51 SkScalar rasterScale); |
49 }; | 52 }; |
50 | 53 |
51 class SkPDFFunctionShader : public SkPDFDict { | 54 class SkPDFFunctionShader : public SkPDFDict { |
52 SK_DECLARE_INST_COUNT(SkPDFFunctionShader); | 55 SK_DECLARE_INST_COUNT(SkPDFFunctionShader); |
53 | 56 |
54 public: | 57 public: |
55 static SkPDFFunctionShader* Create(SkAutoTDelete<SkPDFShader::State>*); | 58 static SkPDFFunctionShader* Create(SkPDFCanon*, |
| 59 SkAutoTDelete<SkPDFShader::State>*); |
56 virtual ~SkPDFFunctionShader(); | 60 virtual ~SkPDFFunctionShader(); |
57 bool equals(const SkPDFShader::State&) const; | 61 bool equals(const SkPDFShader::State&) const; |
58 | 62 |
59 private: | 63 private: |
| 64 SkPDFCanon* fCanon; |
60 SkAutoTDelete<const SkPDFShader::State> fShaderState; | 65 SkAutoTDelete<const SkPDFShader::State> fShaderState; |
61 SkTDArray<SkPDFObject*> fResources; | 66 SkTDArray<SkPDFObject*> fResources; |
62 explicit SkPDFFunctionShader(SkPDFShader::State* state); | 67 SkPDFFunctionShader(SkPDFCanon*, SkPDFShader::State*); |
63 typedef SkPDFDict INHERITED; | 68 typedef SkPDFDict INHERITED; |
64 }; | 69 }; |
65 | 70 |
66 /** | 71 /** |
67 * A shader for PDF gradients. This encapsulates the function shader | 72 * A shader for PDF gradients. This encapsulates the function shader |
68 * inside a tiling pattern while providing a common pattern interface. | 73 * inside a tiling pattern while providing a common pattern interface. |
69 * The encapsulation allows the use of a SMask for transparency gradients. | 74 * The encapsulation allows the use of a SMask for transparency gradients. |
70 */ | 75 */ |
71 class SkPDFAlphaFunctionShader : public SkPDFStream { | 76 class SkPDFAlphaFunctionShader : public SkPDFStream { |
72 public: | 77 public: |
73 static SkPDFAlphaFunctionShader* Create(SkAutoTDelete<SkPDFShader::State>*); | 78 static SkPDFAlphaFunctionShader* Create(SkPDFCanon*, |
| 79 SkScalar dpi, |
| 80 SkAutoTDelete<SkPDFShader::State>*); |
74 virtual ~SkPDFAlphaFunctionShader(); | 81 virtual ~SkPDFAlphaFunctionShader(); |
75 bool equals(const SkPDFShader::State&) const; | 82 bool equals(const SkPDFShader::State&) const; |
76 | 83 |
77 private: | 84 private: |
| 85 SkPDFCanon* fCanon; |
78 SkAutoTDelete<const SkPDFShader::State> fShaderState; | 86 SkAutoTDelete<const SkPDFShader::State> fShaderState; |
79 SkAutoTUnref<SkPDFObject> fColorShader; | 87 SkAutoTUnref<SkPDFObject> fColorShader; |
80 SkAutoTUnref<SkPDFResourceDict> fResourceDict; | 88 SkAutoTUnref<SkPDFResourceDict> fResourceDict; |
81 explicit SkPDFAlphaFunctionShader(SkPDFShader::State* state); | 89 SkPDFAlphaFunctionShader(SkPDFCanon*, SkPDFShader::State*); |
82 }; | 90 }; |
83 | 91 |
84 class SkPDFImageShader : public SkPDFStream { | 92 class SkPDFImageShader : public SkPDFStream { |
85 public: | 93 public: |
86 static SkPDFImageShader* Create(SkAutoTDelete<SkPDFShader::State>*); | 94 static SkPDFImageShader* Create(SkPDFCanon*, |
| 95 SkScalar dpi, |
| 96 SkAutoTDelete<SkPDFShader::State>*); |
87 virtual ~SkPDFImageShader(); | 97 virtual ~SkPDFImageShader(); |
88 bool equals(const SkPDFShader::State&) const; | 98 bool equals(const SkPDFShader::State&) const; |
89 | 99 |
90 private: | 100 private: |
| 101 SkPDFCanon* fCanon; |
91 SkAutoTDelete<const SkPDFShader::State> fShaderState; | 102 SkAutoTDelete<const SkPDFShader::State> fShaderState; |
92 SkTSet<SkPDFObject*> fResources; | 103 SkTSet<SkPDFObject*> fResources; |
93 explicit SkPDFImageShader(SkPDFShader::State* state); | 104 SkPDFImageShader(SkPDFCanon*, SkPDFShader::State*); |
94 }; | 105 }; |
95 | 106 |
96 #endif | 107 #endif |
OLD | NEW |