1 | /* |
2 | * Copyright 2012 Google Inc. |
3 | * |
4 | * Use of this source code is governed by a BSD-style license that can be |
5 | * found in the LICENSE file. |
6 | */ |
7 | |
8 | #ifndef GrSWMaskHelper_DEFINED |
9 | #define GrSWMaskHelper_DEFINED |
10 | |
11 | #include "include/core/SkMatrix.h" |
12 | #include "include/core/SkRegion.h" |
13 | #include "include/core/SkTypes.h" |
14 | #include "include/private/GrTypesPriv.h" |
15 | #include "src/core/SkAutoPixmapStorage.h" |
16 | #include "src/core/SkDraw.h" |
17 | #include "src/core/SkRasterClip.h" |
18 | |
19 | class GrShape; |
20 | class GrRecordingContext; |
21 | class GrTextureProxy; |
22 | |
23 | /** |
24 | * The GrSWMaskHelper helps generate clip masks using the software rendering |
25 | * path. It is intended to be used as: |
26 | * |
27 | * GrSWMaskHelper helper(context); |
28 | * helper.init(...); |
29 | * |
30 | * draw one or more paths/rects specifying the required boolean ops |
31 | * |
32 | * toTextureView(); // to get it from the internal bitmap to the GPU |
33 | * |
34 | * The result of this process will be the final mask (on the GPU) in the |
35 | * upper left hand corner of the texture. |
36 | */ |
37 | class GrSWMaskHelper : SkNoncopyable { |
38 | public: |
39 | GrSWMaskHelper(SkAutoPixmapStorage* pixels = nullptr) |
40 | : fPixels(pixels ? pixels : &fPixelsStorage) { } |
41 | |
42 | // set up the internal state in preparation for draws. Since many masks |
43 | // may be accumulated in the helper during creation, "resultBounds" |
44 | // allows the caller to specify the region of interest - to limit the |
45 | // amount of work. |
46 | bool init(const SkIRect& resultBounds); |
47 | |
48 | // Draw a single rect into the accumulation bitmap using the specified op |
49 | void drawRect(const SkRect& rect, const SkMatrix& matrix, SkRegion::Op op, GrAA, uint8_t alpha); |
50 | |
51 | // Draw a single path into the accumuation bitmap using the specified op |
52 | void drawShape(const GrShape&, const SkMatrix& matrix, SkRegion::Op op, GrAA, uint8_t alpha); |
53 | |
54 | GrSurfaceProxyView toTextureView(GrRecordingContext*, SkBackingFit fit); |
55 | |
56 | // Reset the internal bitmap |
57 | void clear(uint8_t alpha) { |
58 | fPixels->erase(SkColorSetARGB(alpha, 0xFF, 0xFF, 0xFF)); |
59 | } |
60 | |
61 | private: |
62 | SkVector fTranslate; |
63 | SkAutoPixmapStorage* fPixels; |
64 | SkAutoPixmapStorage fPixelsStorage; |
65 | SkDraw fDraw; |
66 | SkRasterClip fRasterClip; |
67 | |
68 | typedef SkNoncopyable INHERITED; |
69 | }; |
70 | |
71 | #endif // GrSWMaskHelper_DEFINED |
72 | |