blob: 502330018590a84a884d3512f3b40da22b68325a [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#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 Derbya08bde62020-06-12 15:46:06 -040018#include "src/gpu/GrSurfaceProxyView.h"
robertphillips@google.com58b20212012-06-27 20:44:52 +000019
Michael Ludwig4fc7c5f2020-05-04 14:51:43 -040020class GrShape;
Michael Ludwig2686d692020-04-17 20:21:37 +000021class GrStyledShape;
Robert Phillips6f0e02f2019-02-13 11:02:28 -050022class GrRecordingContext;
Brian Osmanf9810662017-08-30 10:02:10 -040023class GrTextureProxy;
robertphillips@google.com58b20212012-06-27 20:44:52 +000024
25/**
26 * The GrSWMaskHelper helps generate clip masks using the software rendering
robertphillips@google.com366f1c62012-06-29 21:38:47 +000027 * path. It is intended to be used as:
28 *
Adlai Hollercc25d532021-02-10 13:58:34 +000029 * 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.com366f1c62012-06-29 21:38:47 +000035 *
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.com58b20212012-06-27 20:44:52 +000038 */
Adlai Hollercc25d532021-02-10 13:58:34 +000039class GrSWMaskHelper : SkNoncopyable {
robertphillips@google.com58b20212012-06-27 20:44:52 +000040public:
Adlai Hollercc25d532021-02-10 13:58:34 +000041 GrSWMaskHelper(SkAutoPixmapStorage* pixels = nullptr)
42 : fPixels(pixels ? pixels : &fPixelsStorage) { }
robertphillips@google.com58b20212012-06-27 20:44:52 +000043
Adlai Hollercc25d532021-02-10 13:58:34 +000044 // 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.com58b20212012-06-27 20:44:52 +000049
robertphillips@google.com366f1c62012-06-29 21:38:47 +000050 // Draw a single rect into the accumulation bitmap using the specified op
Brian Salomon74077562017-08-30 13:55:35 -040051 void drawRect(const SkRect& rect, const SkMatrix& matrix, SkRegion::Op op, GrAA, uint8_t alpha);
robertphillips@google.com58b20212012-06-27 20:44:52 +000052
Michael Ludwig4fc7c5f2020-05-04 14:51:43 -040053 // 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.com366f1c62012-06-29 21:38:47 +000057 // Draw a single path into the accumuation bitmap using the specified op
Michael Ludwig2686d692020-04-17 20:21:37 +000058 void drawShape(const GrStyledShape&, const SkMatrix& matrix, SkRegion::Op op, GrAA,
59 uint8_t alpha);
Michael Ludwig4fc7c5f2020-05-04 14:51:43 -040060 // 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.com58b20212012-06-27 20:44:52 +000062
Adlai Hollercc25d532021-02-10 13:58:34 +000063 GrSurfaceProxyView toTextureView(GrRecordingContext*, SkBackingFit fit);
64
robertphillips@google.com366f1c62012-06-29 21:38:47 +000065 // Reset the internal bitmap
66 void clear(uint8_t alpha) {
Adlai Hollercc25d532021-02-10 13:58:34 +000067 fPixels->erase(SkColorSetARGB(alpha, 0xFF, 0xFF, 0xFF));
robertphillips@google.com58b20212012-06-27 20:44:52 +000068 }
69
robertphillips@google.com58b20212012-06-27 20:44:52 +000070private:
Adlai Hollercc25d532021-02-10 13:58:34 +000071 SkVector fTranslate;
72 SkAutoPixmapStorage* fPixels;
73 SkAutoPixmapStorage fPixelsStorage;
74 SkDraw fDraw;
75 SkRasterClip fRasterClip;
robertphillips@google.com58b20212012-06-27 20:44:52 +000076
Adlai Hollercc25d532021-02-10 13:58:34 +000077 using INHERITED = SkNoncopyable;
robertphillips@google.com58b20212012-06-27 20:44:52 +000078};
79
robertphillips@google.comfe659432012-06-28 01:01:53 +000080#endif // GrSWMaskHelper_DEFINED