robertphillips@google.com | 58b2021 | 2012-06-27 20:44:52 +0000 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 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" |
Herb Derby | a08bde6 | 2020-06-12 15:46:06 -0400 | [diff] [blame] | 18 | #include "src/gpu/GrSurfaceProxyView.h" |
robertphillips@google.com | 58b2021 | 2012-06-27 20:44:52 +0000 | [diff] [blame] | 19 | |
Michael Ludwig | 4fc7c5f | 2020-05-04 14:51:43 -0400 | [diff] [blame] | 20 | class GrShape; |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 21 | class GrStyledShape; |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 22 | class GrRecordingContext; |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 23 | class GrTextureProxy; |
robertphillips@google.com | 58b2021 | 2012-06-27 20:44:52 +0000 | [diff] [blame] | 24 | |
| 25 | /** |
| 26 | * The GrSWMaskHelper helps generate clip masks using the software rendering |
robertphillips@google.com | 366f1c6 | 2012-06-29 21:38:47 +0000 | [diff] [blame] | 27 | * path. It is intended to be used as: |
| 28 | * |
Adlai Holler | cc25d53 | 2021-02-10 13:58:34 +0000 | [diff] [blame] | 29 | * GrSWMaskHelper helper(context); |
| 30 | * helper.init(...); |
| 31 | * |
| 32 | * draw one or more paths/rects specifying the required boolean ops |
| 33 | * |
| 34 | * toTextureView(); // to get it from the internal bitmap to the GPU |
robertphillips@google.com | 366f1c6 | 2012-06-29 21:38:47 +0000 | [diff] [blame] | 35 | * |
| 36 | * The result of this process will be the final mask (on the GPU) in the |
| 37 | * upper left hand corner of the texture. |
robertphillips@google.com | 58b2021 | 2012-06-27 20:44:52 +0000 | [diff] [blame] | 38 | */ |
Adlai Holler | cc25d53 | 2021-02-10 13:58:34 +0000 | [diff] [blame] | 39 | class GrSWMaskHelper : SkNoncopyable { |
robertphillips@google.com | 58b2021 | 2012-06-27 20:44:52 +0000 | [diff] [blame] | 40 | public: |
Adlai Holler | cc25d53 | 2021-02-10 13:58:34 +0000 | [diff] [blame] | 41 | GrSWMaskHelper(SkAutoPixmapStorage* pixels = nullptr) |
| 42 | : fPixels(pixels ? pixels : &fPixelsStorage) { } |
robertphillips@google.com | 58b2021 | 2012-06-27 20:44:52 +0000 | [diff] [blame] | 43 | |
Adlai Holler | cc25d53 | 2021-02-10 13:58:34 +0000 | [diff] [blame] | 44 | // set up the internal state in preparation for draws. Since many masks |
| 45 | // may be accumulated in the helper during creation, "resultBounds" |
| 46 | // allows the caller to specify the region of interest - to limit the |
| 47 | // amount of work. |
| 48 | bool init(const SkIRect& resultBounds); |
robertphillips@google.com | 58b2021 | 2012-06-27 20:44:52 +0000 | [diff] [blame] | 49 | |
robertphillips@google.com | 366f1c6 | 2012-06-29 21:38:47 +0000 | [diff] [blame] | 50 | // Draw a single rect into the accumulation bitmap using the specified op |
Brian Salomon | 7407756 | 2017-08-30 13:55:35 -0400 | [diff] [blame] | 51 | void drawRect(const SkRect& rect, const SkMatrix& matrix, SkRegion::Op op, GrAA, uint8_t alpha); |
robertphillips@google.com | 58b2021 | 2012-06-27 20:44:52 +0000 | [diff] [blame] | 52 | |
Michael Ludwig | 4fc7c5f | 2020-05-04 14:51:43 -0400 | [diff] [blame] | 53 | // Draw a single rrect into the accumulation bitmap using the specified op |
| 54 | void drawRRect(const SkRRect& rrect, const SkMatrix& matrix, SkRegion::Op op, GrAA, |
| 55 | uint8_t alpha); |
| 56 | |
robertphillips@google.com | 366f1c6 | 2012-06-29 21:38:47 +0000 | [diff] [blame] | 57 | // Draw a single path into the accumuation bitmap using the specified op |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 58 | void drawShape(const GrStyledShape&, const SkMatrix& matrix, SkRegion::Op op, GrAA, |
| 59 | uint8_t alpha); |
Michael Ludwig | 4fc7c5f | 2020-05-04 14:51:43 -0400 | [diff] [blame] | 60 | // Like the GrStyledShape variant, but assumes a simple fill style |
| 61 | void drawShape(const GrShape&, const SkMatrix& matrix, SkRegion::Op op, GrAA, uint8_t alpha); |
robertphillips@google.com | 58b2021 | 2012-06-27 20:44:52 +0000 | [diff] [blame] | 62 | |
Adlai Holler | cc25d53 | 2021-02-10 13:58:34 +0000 | [diff] [blame] | 63 | GrSurfaceProxyView toTextureView(GrRecordingContext*, SkBackingFit fit); |
| 64 | |
robertphillips@google.com | 366f1c6 | 2012-06-29 21:38:47 +0000 | [diff] [blame] | 65 | // Reset the internal bitmap |
| 66 | void clear(uint8_t alpha) { |
Adlai Holler | cc25d53 | 2021-02-10 13:58:34 +0000 | [diff] [blame] | 67 | fPixels->erase(SkColorSetARGB(alpha, 0xFF, 0xFF, 0xFF)); |
robertphillips@google.com | 58b2021 | 2012-06-27 20:44:52 +0000 | [diff] [blame] | 68 | } |
| 69 | |
robertphillips@google.com | 58b2021 | 2012-06-27 20:44:52 +0000 | [diff] [blame] | 70 | private: |
Adlai Holler | cc25d53 | 2021-02-10 13:58:34 +0000 | [diff] [blame] | 71 | SkVector fTranslate; |
| 72 | SkAutoPixmapStorage* fPixels; |
| 73 | SkAutoPixmapStorage fPixelsStorage; |
| 74 | SkDraw fDraw; |
| 75 | SkRasterClip fRasterClip; |
robertphillips@google.com | 58b2021 | 2012-06-27 20:44:52 +0000 | [diff] [blame] | 76 | |
Adlai Holler | cc25d53 | 2021-02-10 13:58:34 +0000 | [diff] [blame] | 77 | using INHERITED = SkNoncopyable; |
robertphillips@google.com | 58b2021 | 2012-06-27 20:44:52 +0000 | [diff] [blame] | 78 | }; |
| 79 | |
robertphillips@google.com | fe65943 | 2012-06-28 01:01:53 +0000 | [diff] [blame] | 80 | #endif // GrSWMaskHelper_DEFINED |