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 "SkTextureCompressor.h" | |
20 #include "SkTypes.h" | 19 #include "SkTypes.h" |
21 | 20 |
22 class GrClip; | 21 class GrClip; |
23 class GrContext; | 22 class GrContext; |
24 class GrTexture; | 23 class GrTexture; |
25 class SkPath; | 24 class SkPath; |
26 class SkStrokeRec; | 25 class SkStrokeRec; |
27 class GrDrawTarget; | 26 class GrDrawTarget; |
28 | 27 |
29 /** | 28 /** |
30 * The GrSWMaskHelper helps generate clip masks using the software rendering | 29 * The GrSWMaskHelper helps generate clip masks using the software rendering |
31 * path. It is intended to be used as: | 30 * path. It is intended to be used as: |
32 * | 31 * |
33 * GrSWMaskHelper helper(context); | 32 * GrSWMaskHelper helper(context); |
34 * helper.init(...); | 33 * helper.init(...); |
35 * | 34 * |
36 * draw one or more paths/rects specifying the required boolean ops | 35 * draw one or more paths/rects specifying the required boolean ops |
37 * | 36 * |
38 * toTexture(); // to get it from the internal bitmap to the GPU | 37 * toTexture(); // to get it from the internal bitmap to the GPU |
39 * | 38 * |
40 * The result of this process will be the final mask (on the GPU) in the | 39 * The result of this process will be the final mask (on the GPU) in the |
41 * upper left hand corner of the texture. | 40 * upper left hand corner of the texture. |
42 */ | 41 */ |
43 class GrSWMaskHelper : SkNoncopyable { | 42 class GrSWMaskHelper : SkNoncopyable { |
44 public: | 43 public: |
45 GrSWMaskHelper(GrContext* context) | 44 GrSWMaskHelper(GrContext* context) : fContext(context) { } |
46 : fContext(context) | |
47 , fCompressionMode(kNone_CompressionMode) { | |
48 } | |
49 | 45 |
50 // 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 |
51 // may be accumulated in the helper during creation, "resultBounds" | 47 // may be accumulated in the helper during creation, "resultBounds" |
52 // 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 |
53 // amount of work. allowCompression should be set to false if you plan on us
ing | 49 // amount of work. |
54 // your own texture to draw into, and not a scratch texture via getTexture()
. | 50 bool init(const SkIRect& resultBounds, const SkMatrix* matrix); |
55 bool init(const SkIRect& resultBounds, const SkMatrix* matrix, bool allowCom
pression = true); | |
56 | 51 |
57 // 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 |
58 void draw(const SkRect& rect, SkRegion::Op op, bool antiAlias, uint8_t alpha
); | 53 void drawRect(const SkRect& rect, SkRegion::Op op, bool antiAlias, uint8_t a
lpha); |
59 | 54 |
60 // 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 |
61 void draw(const SkPath& path, const GrStyle& style, SkRegion::Op op, | 56 void drawPath(const SkPath& path, const GrStyle& style, SkRegion::Op op, |
62 bool antiAlias, uint8_t alpha); | 57 bool antiAlias, uint8_t alpha); |
63 | 58 |
64 // Move the mask generation results from the internal bitmap to the gpu. | 59 // Move the mask generation results from the internal bitmap to the gpu. |
65 void toTexture(GrTexture* texture); | 60 void toTexture(GrTexture* texture); |
66 | 61 |
67 // Convert mask generation results to a signed distance field | 62 // Convert mask generation results to a signed distance field |
68 void toSDF(unsigned char* sdf); | 63 void toSDF(unsigned char* sdf); |
69 | 64 |
70 // Reset the internal bitmap | 65 // Reset the internal bitmap |
71 void clear(uint8_t alpha) { | 66 void clear(uint8_t alpha) { |
72 fPixels.erase(SkColorSetARGB(alpha, 0xFF, 0xFF, 0xFF)); | 67 fPixels.erase(SkColorSetARGB(alpha, 0xFF, 0xFF, 0xFF)); |
(...skipping 29 matching lines...) Expand all Loading... |
102 // Helper function to get a scratch texture suitable for capturing the | 97 // Helper function to get a scratch texture suitable for capturing the |
103 // result (i.e., right size & format) | 98 // result (i.e., right size & format) |
104 GrTexture* createTexture(); | 99 GrTexture* createTexture(); |
105 | 100 |
106 GrContext* fContext; | 101 GrContext* fContext; |
107 SkMatrix fMatrix; | 102 SkMatrix fMatrix; |
108 SkAutoPixmapStorage fPixels; | 103 SkAutoPixmapStorage fPixels; |
109 SkDraw fDraw; | 104 SkDraw fDraw; |
110 SkRasterClip fRasterClip; | 105 SkRasterClip fRasterClip; |
111 | 106 |
112 // This enum says whether or not we should compress the mask: | |
113 // kNone_CompressionMode: compression is not supported on this device. | |
114 // kCompress_CompressionMode: compress the bitmap before it gets sent to the
gpu | |
115 // kBlitter_CompressionMode: write to the bitmap using a special compressed
blitter. | |
116 enum CompressionMode { | |
117 kNone_CompressionMode, | |
118 kCompress_CompressionMode, | |
119 kBlitter_CompressionMode, | |
120 } fCompressionMode; | |
121 | |
122 // This is the buffer into which we store our compressed data. This buffer i
s | |
123 // only allocated (non-null) if fCompressionMode is kBlitter_CompressionMode | |
124 SkAutoMalloc fCompressedBuffer; | |
125 | |
126 // This is the desired format within which to compress the | |
127 // texture. This value is only valid if fCompressionMode is not kNone_Compre
ssionMode. | |
128 SkTextureCompressor::Format fCompressedFormat; | |
129 | |
130 // Actually sends the texture data to the GPU. This is called from | |
131 // toTexture with the data filled in depending on the texture config. | |
132 void sendTextureData(GrTexture *texture, const GrSurfaceDesc& desc, | |
133 const void *data, size_t rowbytes); | |
134 | |
135 // Compresses the bitmap stored in fBM and sends the compressed data | |
136 // to the GPU to be stored in 'texture' using sendTextureData. | |
137 void compressTextureData(GrTexture *texture, const GrSurfaceDesc& desc); | |
138 | |
139 typedef SkNoncopyable INHERITED; | 107 typedef SkNoncopyable INHERITED; |
140 }; | 108 }; |
141 | 109 |
142 #endif // GrSWMaskHelper_DEFINED | 110 #endif // GrSWMaskHelper_DEFINED |
OLD | NEW |