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 | |
Brian Salomon | f4a00e4 | 2018-03-23 15:15:03 -0400 | [diff] [blame] | 11 | #include "GrTypesPriv.h" |
bsalomon | 39ef7fb | 2016-09-21 11:16:05 -0700 | [diff] [blame] | 12 | #include "SkAutoPixmapStorage.h" |
robertphillips@google.com | 58b2021 | 2012-06-27 20:44:52 +0000 | [diff] [blame] | 13 | #include "SkDraw.h" |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 14 | #include "SkMatrix.h" |
robertphillips@google.com | 58b2021 | 2012-06-27 20:44:52 +0000 | [diff] [blame] | 15 | #include "SkRasterClip.h" |
| 16 | #include "SkRegion.h" |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 17 | #include "SkTypes.h" |
robertphillips@google.com | 58b2021 | 2012-06-27 20:44:52 +0000 | [diff] [blame] | 18 | |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 19 | class GrShape; |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 20 | class GrRecordingContext; |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 21 | class GrTextureProxy; |
robertphillips@google.com | 58b2021 | 2012-06-27 20:44:52 +0000 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * The GrSWMaskHelper helps generate clip masks using the software rendering |
robertphillips@google.com | 366f1c6 | 2012-06-29 21:38:47 +0000 | [diff] [blame] | 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 | * |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 32 | * toTextureProxy(); // to get it from the internal bitmap to the GPU |
robertphillips@google.com | 366f1c6 | 2012-06-29 21:38:47 +0000 | [diff] [blame] | 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. |
robertphillips@google.com | 58b2021 | 2012-06-27 20:44:52 +0000 | [diff] [blame] | 36 | */ |
commit-bot@chromium.org | e3beb6b | 2014-04-07 19:34:38 +0000 | [diff] [blame] | 37 | class GrSWMaskHelper : SkNoncopyable { |
robertphillips@google.com | 58b2021 | 2012-06-27 20:44:52 +0000 | [diff] [blame] | 38 | public: |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 39 | GrSWMaskHelper(SkAutoPixmapStorage* pixels = nullptr) |
| 40 | : fPixels(pixels ? pixels : &fPixelsStorage) { } |
robertphillips@google.com | 58b2021 | 2012-06-27 20:44:52 +0000 | [diff] [blame] | 41 | |
robertphillips@google.com | 366f1c6 | 2012-06-29 21:38:47 +0000 | [diff] [blame] | 42 | // set up the internal state in preparation for draws. Since many masks |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 43 | // may be accumulated in the helper during creation, "resultBounds" |
| 44 | // allows the caller to specify the region of interest - to limit the |
robertphillips | 9837740 | 2016-05-13 05:47:23 -0700 | [diff] [blame] | 45 | // amount of work. |
Brian Salomon | 7407756 | 2017-08-30 13:55:35 -0400 | [diff] [blame] | 46 | bool init(const SkIRect& resultBounds); |
robertphillips@google.com | 58b2021 | 2012-06-27 20:44:52 +0000 | [diff] [blame] | 47 | |
robertphillips@google.com | 366f1c6 | 2012-06-29 21:38:47 +0000 | [diff] [blame] | 48 | // Draw a single rect into the accumulation bitmap using the specified op |
Brian Salomon | 7407756 | 2017-08-30 13:55:35 -0400 | [diff] [blame] | 49 | 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] | 50 | |
robertphillips@google.com | 366f1c6 | 2012-06-29 21:38:47 +0000 | [diff] [blame] | 51 | // Draw a single path into the accumuation bitmap using the specified op |
Brian Salomon | 7407756 | 2017-08-30 13:55:35 -0400 | [diff] [blame] | 52 | 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] | 53 | |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 54 | sk_sp<GrTextureProxy> toTextureProxy(GrRecordingContext*, SkBackingFit fit); |
robertphillips@google.com | 58b2021 | 2012-06-27 20:44:52 +0000 | [diff] [blame] | 55 | |
robertphillips@google.com | 366f1c6 | 2012-06-29 21:38:47 +0000 | [diff] [blame] | 56 | // Reset the internal bitmap |
| 57 | void clear(uint8_t alpha) { |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 58 | fPixels->erase(SkColorSetARGB(alpha, 0xFF, 0xFF, 0xFF)); |
robertphillips@google.com | 58b2021 | 2012-06-27 20:44:52 +0000 | [diff] [blame] | 59 | } |
| 60 | |
robertphillips@google.com | 58b2021 | 2012-06-27 20:44:52 +0000 | [diff] [blame] | 61 | private: |
Brian Salomon | 7407756 | 2017-08-30 13:55:35 -0400 | [diff] [blame] | 62 | SkVector fTranslate; |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 63 | SkAutoPixmapStorage* fPixels; |
| 64 | SkAutoPixmapStorage fPixelsStorage; |
| 65 | SkDraw fDraw; |
| 66 | SkRasterClip fRasterClip; |
robertphillips@google.com | 58b2021 | 2012-06-27 20:44:52 +0000 | [diff] [blame] | 67 | |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 68 | typedef SkNoncopyable INHERITED; |
robertphillips@google.com | 58b2021 | 2012-06-27 20:44:52 +0000 | [diff] [blame] | 69 | }; |
| 70 | |
robertphillips@google.com | fe65943 | 2012-06-28 01:01:53 +0000 | [diff] [blame] | 71 | #endif // GrSWMaskHelper_DEFINED |