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 "SkAutoPixmapStorage.h" | 11 #include "SkAutoPixmapStorage.h" |
12 #include "GrColor.h" | 12 #include "GrColor.h" |
13 #include "GrPipelineBuilder.h" | 13 #include "GrPipelineBuilder.h" |
14 #include "SkBitmap.h" | 14 #include "SkBitmap.h" |
15 #include "SkDraw.h" | 15 #include "SkDraw.h" |
16 #include "SkMatrix.h" | 16 #include "SkMatrix.h" |
17 #include "SkRasterClip.h" | 17 #include "SkRasterClip.h" |
18 #include "SkRegion.h" | 18 #include "SkRegion.h" |
19 #include "SkTypes.h" | 19 #include "SkTypes.h" |
20 | 20 |
21 class GrClip; | 21 class GrClip; |
| 22 class GrShape; |
22 class GrTextureProvider; | 23 class GrTextureProvider; |
23 class GrTexture; | 24 class GrTexture; |
24 class SkPath; | 25 class SkPath; |
25 class SkStrokeRec; | 26 class SkStrokeRec; |
26 | 27 |
27 /** | 28 /** |
28 * The GrSWMaskHelper helps generate clip masks using the software rendering | 29 * The GrSWMaskHelper helps generate clip masks using the software rendering |
29 * path. It is intended to be used as: | 30 * path. It is intended to be used as: |
30 * | 31 * |
31 * GrSWMaskHelper helper(context); | 32 * GrSWMaskHelper helper(context); |
(...skipping 13 matching lines...) Expand all Loading... |
45 // set up the internal state in preparation for draws. Since many masks | 46 // set up the internal state in preparation for draws. Since many masks |
46 // may be accumulated in the helper during creation, "resultBounds" | 47 // may be accumulated in the helper during creation, "resultBounds" |
47 // allows the caller to specify the region of interest - to limit the | 48 // allows the caller to specify the region of interest - to limit the |
48 // amount of work. | 49 // amount of work. |
49 bool init(const SkIRect& resultBounds, const SkMatrix* matrix); | 50 bool init(const SkIRect& resultBounds, const SkMatrix* matrix); |
50 | 51 |
51 // Draw a single rect into the accumulation bitmap using the specified op | 52 // Draw a single rect into the accumulation bitmap using the specified op |
52 void drawRect(const SkRect& rect, SkRegion::Op op, bool antiAlias, uint8_t a
lpha); | 53 void drawRect(const SkRect& rect, SkRegion::Op op, bool antiAlias, uint8_t a
lpha); |
53 | 54 |
54 // Draw a single path into the accumuation bitmap using the specified op | 55 // Draw a single path into the accumuation bitmap using the specified op |
55 void drawPath(const SkPath& path, const GrStyle& style, SkRegion::Op op, | 56 void drawShape(const GrShape&, SkRegion::Op op, bool antiAlias, uint8_t alph
a); |
56 bool antiAlias, uint8_t alpha); | |
57 | 57 |
58 // Move the mask generation results from the internal bitmap to the gpu. | 58 // Move the mask generation results from the internal bitmap to the gpu. |
59 void toTexture(GrTexture* texture); | 59 void toTexture(GrTexture* texture); |
60 | 60 |
61 // Convert mask generation results to a signed distance field | 61 // Convert mask generation results to a signed distance field |
62 void toSDF(unsigned char* sdf); | 62 void toSDF(unsigned char* sdf); |
63 | 63 |
64 // Reset the internal bitmap | 64 // Reset the internal bitmap |
65 void clear(uint8_t alpha) { | 65 void clear(uint8_t alpha) { |
66 fPixels.erase(SkColorSetARGB(alpha, 0xFF, 0xFF, 0xFF)); | 66 fPixels.erase(SkColorSetARGB(alpha, 0xFF, 0xFF, 0xFF)); |
67 } | 67 } |
68 | 68 |
69 // Canonical usage utility that draws a single path and uploads it | 69 // Canonical usage utility that draws a single path and uploads it |
70 // to the GPU. The result is returned. | 70 // to the GPU. The result is returned. |
71 static GrTexture* DrawPathMaskToTexture(GrTextureProvider*, | 71 static GrTexture* DrawShapeMaskToTexture(GrTextureProvider*, |
72 const SkPath& path, | 72 const GrShape&, |
73 const GrStyle& style, | 73 const SkIRect& resultBounds, |
74 const SkIRect& resultBounds, | 74 bool antiAlias, |
75 bool antiAlias, | 75 const SkMatrix* matrix); |
76 const SkMatrix* matrix); | |
77 | 76 |
78 // This utility routine is used to add a path's mask to some other draw. | 77 // This utility routine is used to add a shape's mask to some other draw. |
79 // The ClipMaskManager uses it to accumulate clip masks while the | 78 // The ClipMaskManager uses it to accumulate clip masks while the |
80 // GrSoftwarePathRenderer uses it to fulfill a drawPath call. | 79 // GrSoftwarePathRenderer uses it to fulfill a drawPath call. |
81 // It draws with "texture" as a path mask into "target" using "rect" as | 80 // It draws with "texture" as a path mask into "target" using "rect" as |
82 // geometry and the current drawState. The current drawState is altered to | 81 // geometry and the current drawState. The current drawState is altered to |
83 // accommodate the mask. | 82 // accommodate the mask. |
84 // Note that this method assumes that the GrPaint::kTotalStages slot in | 83 // Note that this method assumes that the GrPaint::kTotalStages slot in |
85 // the draw state can be used to hold the mask texture stage. | 84 // the draw state can be used to hold the mask texture stage. |
86 // This method is really only intended to be used with the | 85 // This method is really only intended to be used with the |
87 // output of DrawPathMaskToTexture. | 86 // output of DrawPathMaskToTexture. |
88 static void DrawToTargetWithPathMask(GrTexture* texture, | 87 static void DrawToTargetWithShapeMask(GrTexture* texture, |
89 GrDrawContext*, | 88 GrDrawContext*, |
90 const GrPaint* paint, | 89 const GrPaint* paint, |
91 const GrUserStencilSettings* userStenci
lSettings, | 90 const GrUserStencilSettings* userStenc
ilSettings, |
92 const GrClip&, | 91 const GrClip&, |
93 GrColor, | 92 GrColor, |
94 const SkMatrix& viewMatrix, | 93 const SkMatrix& viewMatrix, |
95 const SkIRect& rect); | 94 const SkIRect& rect); |
96 | 95 |
97 private: | 96 private: |
98 // Helper function to get a scratch texture suitable for capturing the | 97 // Helper function to get a scratch texture suitable for capturing the |
99 // result (i.e., right size & format) | 98 // result (i.e., right size & format) |
100 GrTexture* createTexture(); | 99 GrTexture* createTexture(); |
101 | 100 |
102 GrTextureProvider* fTexProvider; | 101 GrTextureProvider* fTexProvider; |
103 SkMatrix fMatrix; | 102 SkMatrix fMatrix; |
104 SkAutoPixmapStorage fPixels; | 103 SkAutoPixmapStorage fPixels; |
105 SkDraw fDraw; | 104 SkDraw fDraw; |
106 SkRasterClip fRasterClip; | 105 SkRasterClip fRasterClip; |
107 | 106 |
108 typedef SkNoncopyable INHERITED; | 107 typedef SkNoncopyable INHERITED; |
109 }; | 108 }; |
110 | 109 |
111 #endif // GrSWMaskHelper_DEFINED | 110 #endif // GrSWMaskHelper_DEFINED |
OLD | NEW |