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 "GrTypesPriv.h" 12 #include "SkAutoPixmapStorage.h" 13 #include "SkDraw.h" 14 #include "SkMatrix.h" 15 #include "SkRasterClip.h" 16 #include "SkRegion.h" 17 #include "SkTypes.h" 18 19 class GrShape; 20 class GrTextureProxy; 21 22 /** 23 * The GrSWMaskHelper helps generate clip masks using the software rendering 24 * 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 * 31 * toTextureProxy(); // to get it from the internal bitmap to the GPU 32 * 33 * The result of this process will be the final mask (on the GPU) in the 34 * upper left hand corner of the texture. 35 */ 36 class GrSWMaskHelper : SkNoncopyable { 37 public: 38 GrSWMaskHelper(SkAutoPixmapStorage* pixels = nullptr) 39 : fPixels(pixels ? pixels : &fPixelsStorage) { } 40 41 // set up the internal state in preparation for draws. Since many masks 42 // may be accumulated in the helper during creation, "resultBounds" 43 // allows the caller to specify the region of interest - to limit the 44 // amount of work. 45 bool init(const SkIRect& resultBounds); 46 47 // Draw a single rect into the accumulation bitmap using the specified op 48 void drawRect(const SkRect& rect, const SkMatrix& matrix, SkRegion::Op op, GrAA, uint8_t alpha); 49 50 // Draw a single path into the accumuation bitmap using the specified op 51 void drawShape(const GrShape&, const SkMatrix& matrix, SkRegion::Op op, GrAA, uint8_t alpha); 52 53 sk_sp<GrTextureProxy> toTextureProxy(GrContext*, SkBackingFit fit); 54 55 // Reset the internal bitmap clear(uint8_t alpha)56 void clear(uint8_t alpha) { 57 fPixels->erase(SkColorSetARGB(alpha, 0xFF, 0xFF, 0xFF)); 58 } 59 60 private: 61 SkVector fTranslate; 62 SkAutoPixmapStorage* fPixels; 63 SkAutoPixmapStorage fPixelsStorage; 64 SkDraw fDraw; 65 SkRasterClip fRasterClip; 66 67 typedef SkNoncopyable INHERITED; 68 }; 69 70 #endif // GrSWMaskHelper_DEFINED 71