OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 #ifndef GrSWMaskHelper_DEFINED | 8 #ifndef GrSWMaskHelper_DEFINED |
9 #define GrSWMaskHelper_DEFINED | 9 #define GrSWMaskHelper_DEFINED |
10 | 10 |
| 11 #include "GrColor.h" |
| 12 #include "GrTextureProvider.h" |
11 #include "SkAutoPixmapStorage.h" | 13 #include "SkAutoPixmapStorage.h" |
12 #include "GrColor.h" | |
13 #include "SkBitmap.h" | 14 #include "SkBitmap.h" |
14 #include "SkDraw.h" | 15 #include "SkDraw.h" |
15 #include "SkMatrix.h" | 16 #include "SkMatrix.h" |
16 #include "SkRasterClip.h" | 17 #include "SkRasterClip.h" |
17 #include "SkRegion.h" | 18 #include "SkRegion.h" |
18 #include "SkTypes.h" | 19 #include "SkTypes.h" |
19 | 20 |
20 class GrClip; | 21 class GrClip; |
21 class GrPaint; | 22 class GrPaint; |
22 class GrShape; | 23 class GrShape; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 void toTexture(GrTexture* texture); | 60 void toTexture(GrTexture* texture); |
60 | 61 |
61 // Convert mask generation results to a signed distance field | 62 // Convert mask generation results to a signed distance field |
62 void toSDF(unsigned char* sdf); | 63 void toSDF(unsigned char* sdf); |
63 | 64 |
64 // Reset the internal bitmap | 65 // Reset the internal bitmap |
65 void clear(uint8_t alpha) { | 66 void clear(uint8_t alpha) { |
66 fPixels.erase(SkColorSetARGB(alpha, 0xFF, 0xFF, 0xFF)); | 67 fPixels.erase(SkColorSetARGB(alpha, 0xFF, 0xFF, 0xFF)); |
67 } | 68 } |
68 | 69 |
| 70 |
| 71 enum class TextureType { |
| 72 kExactFit, |
| 73 kApproximateFit |
| 74 }; |
| 75 |
69 // Canonical usage utility that draws a single path and uploads it | 76 // Canonical usage utility that draws a single path and uploads it |
70 // to the GPU. The result is returned. | 77 // to the GPU. The result is returned. |
71 static GrTexture* DrawShapeMaskToTexture(GrTextureProvider*, | 78 static GrTexture* DrawShapeMaskToTexture(GrTextureProvider*, |
72 const GrShape&, | 79 const GrShape&, |
73 const SkIRect& resultBounds, | 80 const SkIRect& resultBounds, |
74 bool antiAlias, | 81 bool antiAlias, |
| 82 TextureType, |
75 const SkMatrix* matrix); | 83 const SkMatrix* matrix); |
76 | 84 |
77 // This utility routine is used to add a shape's mask to some other draw. | 85 // This utility draws a path mask generated by DrawShapeMaskToTexture using
a provided paint. |
78 // The GrClipStackClip uses it to accumulate clip masks while the | 86 // The rectangle is drawn in device space. The 'viewMatrix' will be used to
ensure the correct |
79 // GrSoftwarePathRenderer uses it to fulfill a drawPath call. | 87 // local coords are provided to any fragment processors in the paint. |
80 // It draws with "texture" as a path mask into "target" using "rect" as | |
81 // geometry and the current drawState. The current drawState is altered to | |
82 // accommodate the mask. | |
83 // Note that this method assumes that the GrPaint::kTotalStages slot in | |
84 // the draw state can be used to hold the mask texture stage. | |
85 // This method is really only intended to be used with the | |
86 // output of DrawPathMaskToTexture. | |
87 static void DrawToTargetWithShapeMask(GrTexture* texture, | 88 static void DrawToTargetWithShapeMask(GrTexture* texture, |
88 GrDrawContext*, | 89 GrDrawContext*, |
89 const GrPaint& paint, | 90 const GrPaint& paint, |
90 const GrUserStencilSettings& userStenc
ilSettings, | 91 const GrUserStencilSettings& userStenc
ilSettings, |
91 const GrClip&, | 92 const GrClip&, |
92 const SkMatrix& viewMatrix, | 93 const SkMatrix& viewMatrix, |
93 const SkIRect& rect); | 94 const SkIPoint& textureOriginInDeviceS
pace, |
| 95 const SkIRect& deviceSpaceRectToDraw); |
94 | 96 |
95 private: | 97 private: |
96 // Helper function to get a scratch texture suitable for capturing the | 98 // Helper function to get a scratch texture suitable for capturing the |
97 // result (i.e., right size & format) | 99 // result (i.e., right size & format) |
98 GrTexture* createTexture(); | 100 GrTexture* createTexture(TextureType); |
99 | 101 |
100 GrTextureProvider* fTexProvider; | 102 GrTextureProvider* fTexProvider; |
101 SkMatrix fMatrix; | 103 SkMatrix fMatrix; |
102 SkAutoPixmapStorage fPixels; | 104 SkAutoPixmapStorage fPixels; |
103 SkDraw fDraw; | 105 SkDraw fDraw; |
104 SkRasterClip fRasterClip; | 106 SkRasterClip fRasterClip; |
105 | 107 |
106 typedef SkNoncopyable INHERITED; | 108 typedef SkNoncopyable INHERITED; |
107 }; | 109 }; |
108 | 110 |
109 #endif // GrSWMaskHelper_DEFINED | 111 #endif // GrSWMaskHelper_DEFINED |
OLD | NEW |