Debian Codegraph @

src/gpu/ganesh/GrSWMaskHelper.h

raw
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
11 #include "include/core/SkColor.h"
12 #include "include/core/SkPoint.h"
13 #include "include/core/SkTypes.h"
14 #include "include/private/base/SkNoncopyable.h"
15 #include "src/core/SkAutoPixmapStorage.h"
16 #include "src/core/SkDraw.h"
17 #include "src/core/SkRasterClip.h"
18 #include "src/gpu/ganesh/GrSurfaceProxyView.h"
19
20 #include <cstdint>
21
22 class GrRecordingContext;
23 class GrShape;
24 class GrStyledShape;
25 class SkMatrix;
26 class SkRRect;
27 enum class GrAA : bool;
28 enum class SkBackingFit;
29 struct SkIRect;
30 struct SkRect;
31
32 /**
33 * The GrSWMaskHelper helps generate clip masks using the software rendering
34 * path. It is intended to be used as:
35 *
36 * GrSWMaskHelper helper(context);
37 * helper.init(...);
38 *
39 * draw one or more paths/rects specifying the required boolean ops
40 *
41 * toTextureView(); // to get it from the internal bitmap to the GPU
42 *
43 * The result of this process will be the final mask (on the GPU) in the
44 * upper left hand corner of the texture.
45 */
46 class GrSWMaskHelper : SkNoncopyable {
47 public:
48 GrSWMaskHelper(SkAutoPixmapStorage* pixels = nullptr)
49 : fPixels(pixels ? pixels : &fPixelsStorage) { }
50
51 // set up the internal state in preparation for draws. Since many masks
52 // may be accumulated in the helper during creation, "resultBounds"
53 // allows the caller to specify the region of interest - to limit the
54 // amount of work.
55 bool init(const SkIRect& resultBounds);
56
57 // Draw a single rect into the accumulation bitmap using the specified op
58 void drawRect(const SkRect& rect, const SkMatrix& matrix, GrAA, uint8_t alpha);
59
60 // Draw a single rrect into the accumulation bitmap using the specified op
61 void drawRRect(const SkRRect& rrect, const SkMatrix& matrix, GrAA,
62 uint8_t alpha);
63
64 // Draw a single path into the accumuation bitmap using the specified op
65 void drawShape(const GrStyledShape&, const SkMatrix& matrix, GrAA,
66 uint8_t alpha);
67 // Like the GrStyledShape variant, but assumes a simple fill style
68 void drawShape(const GrShape&, const SkMatrix& matrix, GrAA, uint8_t alpha);
69
70 GrSurfaceProxyView toTextureView(GrRecordingContext*, SkBackingFit fit);
71
72 // Reset the internal bitmap
73 void clear(uint8_t alpha) {
74 fPixels->erase(SkColorSetARGB(alpha, 0xFF, 0xFF, 0xFF));
75 }
76
77 private:
78 SkVector fTranslate;
79 SkAutoPixmapStorage* fPixels;
80 SkAutoPixmapStorage fPixelsStorage;
81 skcpu::Draw fDraw;
82 SkRasterClip fRasterClip;
83
84 using INHERITED = SkNoncopyable;
85 };
86
87 #endif // GrSWMaskHelper_DEFINED