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