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/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" 18 #include "src/gpu/GrSurfaceProxyView.h" 19 20 class GrShape; 21 class GrStyledShape; 22 class GrRecordingContext; 23 class GrTextureProxy; 24 25 /** 26 * The GrSWMaskHelper helps generate clip masks using the software rendering 27 * path. It is intended to be used as: 28 * 29 * 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 35 * 36 * The result of this process will be the final mask (on the GPU) in the 37 * upper left hand corner of the texture. 38 */ 39 class GrSWMaskHelper : SkNoncopyable { 40 public: 41 GrSWMaskHelper(SkAutoPixmapStorage* pixels = nullptr) 42 : fPixels(pixels ? pixels : &fPixelsStorage) { } 43 44 // 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); 49 50 // Draw a single rect into the accumulation bitmap using the specified op 51 void drawRect(const SkRect& rect, const SkMatrix& matrix, SkRegion::Op op, GrAA, uint8_t alpha); 52 53 // 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 57 // Draw a single path into the accumuation bitmap using the specified op 58 void drawShape(const GrStyledShape&, const SkMatrix& matrix, SkRegion::Op op, GrAA, 59 uint8_t alpha); 60 // 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); 62 63 GrSurfaceProxyView toTextureView(GrRecordingContext*, SkBackingFit fit); 64 65 // Reset the internal bitmap clear(uint8_t alpha)66 void clear(uint8_t alpha) { 67 fPixels->erase(SkColorSetARGB(alpha, 0xFF, 0xFF, 0xFF)); 68 } 69 70 private: 71 SkVector fTranslate; 72 SkAutoPixmapStorage* fPixels; 73 SkAutoPixmapStorage fPixelsStorage; 74 SkDraw fDraw; 75 SkRasterClip fRasterClip; 76 77 using INHERITED = SkNoncopyable; 78 }; 79 80 #endif // GrSWMaskHelper_DEFINED 81