blob: 1456d400db9567b65ccb37c4559f0b9000454faf [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;
Brian Osmanf9810662017-08-30 10:02:10 -040020class GrTextureProxy;
robertphillips@google.com58b20212012-06-27 20:44:52 +000021
22/**
23 * The GrSWMaskHelper helps generate clip masks using the software rendering
robertphillips@google.com366f1c62012-06-29 21:38:47 +000024 * path. It is intended to be used as:
25 *
26 * GrSWMaskHelper helper(context);
27 * helper.init(...);
28 *
29 * draw one or more paths/rects specifying the required boolean ops
30 *
Brian Osmanf9810662017-08-30 10:02:10 -040031 * toTextureProxy(); // to get it from the internal bitmap to the GPU
robertphillips@google.com366f1c62012-06-29 21:38:47 +000032 *
33 * The result of this process will be the final mask (on the GPU) in the
34 * upper left hand corner of the texture.
robertphillips@google.com58b20212012-06-27 20:44:52 +000035 */
commit-bot@chromium.orge3beb6b2014-04-07 19:34:38 +000036class GrSWMaskHelper : SkNoncopyable {
robertphillips@google.com58b20212012-06-27 20:44:52 +000037public:
Brian Osmanf9810662017-08-30 10:02:10 -040038 GrSWMaskHelper(SkAutoPixmapStorage* pixels = nullptr)
39 : fPixels(pixels ? pixels : &fPixelsStorage) { }
robertphillips@google.com58b20212012-06-27 20:44:52 +000040
robertphillips@google.com366f1c62012-06-29 21:38:47 +000041 // set up the internal state in preparation for draws. Since many masks
rmistry@google.comd6176b02012-08-23 18:14:13 +000042 // may be accumulated in the helper during creation, "resultBounds"
43 // allows the caller to specify the region of interest - to limit the
robertphillips98377402016-05-13 05:47:23 -070044 // amount of work.
Brian Salomon74077562017-08-30 13:55:35 -040045 bool init(const SkIRect& resultBounds);
robertphillips@google.com58b20212012-06-27 20:44:52 +000046
robertphillips@google.com366f1c62012-06-29 21:38:47 +000047 // Draw a single rect into the accumulation bitmap using the specified op
Brian Salomon74077562017-08-30 13:55:35 -040048 void drawRect(const SkRect& rect, const SkMatrix& matrix, SkRegion::Op op, GrAA, uint8_t alpha);
robertphillips@google.com58b20212012-06-27 20:44:52 +000049
robertphillips@google.com366f1c62012-06-29 21:38:47 +000050 // Draw a single path into the accumuation bitmap using the specified op
Brian Salomon74077562017-08-30 13:55:35 -040051 void drawShape(const GrShape&, const SkMatrix& matrix, SkRegion::Op op, GrAA, uint8_t alpha);
robertphillips@google.com58b20212012-06-27 20:44:52 +000052
Robert Phillipsd3749482017-03-14 09:17:43 -040053 sk_sp<GrTextureProxy> toTextureProxy(GrContext*, SkBackingFit fit);
robertphillips@google.com58b20212012-06-27 20:44:52 +000054
robertphillips@google.com366f1c62012-06-29 21:38:47 +000055 // Reset the internal bitmap
56 void clear(uint8_t alpha) {
Brian Osmanf9810662017-08-30 10:02:10 -040057 fPixels->erase(SkColorSetARGB(alpha, 0xFF, 0xFF, 0xFF));
robertphillips@google.com58b20212012-06-27 20:44:52 +000058 }
59
robertphillips@google.com58b20212012-06-27 20:44:52 +000060private:
Brian Salomon74077562017-08-30 13:55:35 -040061 SkVector fTranslate;
Brian Osmanf9810662017-08-30 10:02:10 -040062 SkAutoPixmapStorage* fPixels;
63 SkAutoPixmapStorage fPixelsStorage;
64 SkDraw fDraw;
65 SkRasterClip fRasterClip;
robertphillips@google.com58b20212012-06-27 20:44:52 +000066
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +000067 typedef SkNoncopyable INHERITED;
robertphillips@google.com58b20212012-06-27 20:44:52 +000068};
69
robertphillips@google.comfe659432012-06-28 01:01:53 +000070#endif // GrSWMaskHelper_DEFINED