blob: c2df5db17a28a6fd3171a605f8face25a69d0810 [file] [log] [blame]
robertphillips@google.com58b20212012-06-27 20:44:52 +00001/*
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 Salomonf4a00e42018-03-23 15:15:03 -040011#include "GrTypesPriv.h"
bsalomon39ef7fb2016-09-21 11:16:05 -070012#include "SkAutoPixmapStorage.h"
robertphillips@google.com58b20212012-06-27 20:44:52 +000013#include "SkDraw.h"
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +000014#include "SkMatrix.h"
robertphillips@google.com58b20212012-06-27 20:44:52 +000015#include "SkRasterClip.h"
16#include "SkRegion.h"
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +000017#include "SkTypes.h"
robertphillips@google.com58b20212012-06-27 20:44:52 +000018
bsalomon8acedde2016-06-24 10:42:16 -070019class GrShape;
Robert Phillips6f0e02f2019-02-13 11:02:28 -050020class GrRecordingContext;
Brian Osmanf9810662017-08-30 10:02:10 -040021class GrTextureProxy;
robertphillips@google.com58b20212012-06-27 20:44:52 +000022
23/**
24 * The GrSWMaskHelper helps generate clip masks using the software rendering
robertphillips@google.com366f1c62012-06-29 21:38:47 +000025 * 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 Osmanf9810662017-08-30 10:02:10 -040032 * toTextureProxy(); // to get it from the internal bitmap to the GPU
robertphillips@google.com366f1c62012-06-29 21:38:47 +000033 *
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.com58b20212012-06-27 20:44:52 +000036 */
commit-bot@chromium.orge3beb6b2014-04-07 19:34:38 +000037class GrSWMaskHelper : SkNoncopyable {
robertphillips@google.com58b20212012-06-27 20:44:52 +000038public:
Brian Osmanf9810662017-08-30 10:02:10 -040039 GrSWMaskHelper(SkAutoPixmapStorage* pixels = nullptr)
40 : fPixels(pixels ? pixels : &fPixelsStorage) { }
robertphillips@google.com58b20212012-06-27 20:44:52 +000041
robertphillips@google.com366f1c62012-06-29 21:38:47 +000042 // set up the internal state in preparation for draws. Since many masks
rmistry@google.comd6176b02012-08-23 18:14:13 +000043 // may be accumulated in the helper during creation, "resultBounds"
44 // allows the caller to specify the region of interest - to limit the
robertphillips98377402016-05-13 05:47:23 -070045 // amount of work.
Brian Salomon74077562017-08-30 13:55:35 -040046 bool init(const SkIRect& resultBounds);
robertphillips@google.com58b20212012-06-27 20:44:52 +000047
robertphillips@google.com366f1c62012-06-29 21:38:47 +000048 // Draw a single rect into the accumulation bitmap using the specified op
Brian Salomon74077562017-08-30 13:55:35 -040049 void drawRect(const SkRect& rect, const SkMatrix& matrix, SkRegion::Op op, GrAA, uint8_t alpha);
robertphillips@google.com58b20212012-06-27 20:44:52 +000050
robertphillips@google.com366f1c62012-06-29 21:38:47 +000051 // Draw a single path into the accumuation bitmap using the specified op
Brian Salomon74077562017-08-30 13:55:35 -040052 void drawShape(const GrShape&, const SkMatrix& matrix, SkRegion::Op op, GrAA, uint8_t alpha);
robertphillips@google.com58b20212012-06-27 20:44:52 +000053
Robert Phillips6f0e02f2019-02-13 11:02:28 -050054 sk_sp<GrTextureProxy> toTextureProxy(GrRecordingContext*, SkBackingFit fit);
robertphillips@google.com58b20212012-06-27 20:44:52 +000055
robertphillips@google.com366f1c62012-06-29 21:38:47 +000056 // Reset the internal bitmap
57 void clear(uint8_t alpha) {
Brian Osmanf9810662017-08-30 10:02:10 -040058 fPixels->erase(SkColorSetARGB(alpha, 0xFF, 0xFF, 0xFF));
robertphillips@google.com58b20212012-06-27 20:44:52 +000059 }
60
robertphillips@google.com58b20212012-06-27 20:44:52 +000061private:
Brian Salomon74077562017-08-30 13:55:35 -040062 SkVector fTranslate;
Brian Osmanf9810662017-08-30 10:02:10 -040063 SkAutoPixmapStorage* fPixels;
64 SkAutoPixmapStorage fPixelsStorage;
65 SkDraw fDraw;
66 SkRasterClip fRasterClip;
robertphillips@google.com58b20212012-06-27 20:44:52 +000067
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +000068 typedef SkNoncopyable INHERITED;
robertphillips@google.com58b20212012-06-27 20:44:52 +000069};
70
robertphillips@google.comfe659432012-06-28 01:01:53 +000071#endif // GrSWMaskHelper_DEFINED