GrSWMaskHelper.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #ifndef GrSWMaskHelper_DEFINED
  8. #define GrSWMaskHelper_DEFINED
  9. #include "include/core/SkMatrix.h"
  10. #include "include/core/SkRegion.h"
  11. #include "include/core/SkTypes.h"
  12. #include "include/private/GrTypesPriv.h"
  13. #include "src/core/SkAutoPixmapStorage.h"
  14. #include "src/core/SkDraw.h"
  15. #include "src/core/SkRasterClip.h"
  16. class GrShape;
  17. class GrRecordingContext;
  18. class GrTextureProxy;
  19. /**
  20. * The GrSWMaskHelper helps generate clip masks using the software rendering
  21. * path. It is intended to be used as:
  22. *
  23. * GrSWMaskHelper helper(context);
  24. * helper.init(...);
  25. *
  26. * draw one or more paths/rects specifying the required boolean ops
  27. *
  28. * toTextureProxy(); // to get it from the internal bitmap to the GPU
  29. *
  30. * The result of this process will be the final mask (on the GPU) in the
  31. * upper left hand corner of the texture.
  32. */
  33. class GrSWMaskHelper : SkNoncopyable {
  34. public:
  35. GrSWMaskHelper(SkAutoPixmapStorage* pixels = nullptr)
  36. : fPixels(pixels ? pixels : &fPixelsStorage) { }
  37. // set up the internal state in preparation for draws. Since many masks
  38. // may be accumulated in the helper during creation, "resultBounds"
  39. // allows the caller to specify the region of interest - to limit the
  40. // amount of work.
  41. bool init(const SkIRect& resultBounds);
  42. // Draw a single rect into the accumulation bitmap using the specified op
  43. void drawRect(const SkRect& rect, const SkMatrix& matrix, SkRegion::Op op, GrAA, uint8_t alpha);
  44. // Draw a single path into the accumuation bitmap using the specified op
  45. void drawShape(const GrShape&, const SkMatrix& matrix, SkRegion::Op op, GrAA, uint8_t alpha);
  46. sk_sp<GrTextureProxy> toTextureProxy(GrRecordingContext*, SkBackingFit fit);
  47. // Reset the internal bitmap
  48. void clear(uint8_t alpha) {
  49. fPixels->erase(SkColorSetARGB(alpha, 0xFF, 0xFF, 0xFF));
  50. }
  51. private:
  52. SkVector fTranslate;
  53. SkAutoPixmapStorage* fPixels;
  54. SkAutoPixmapStorage fPixelsStorage;
  55. SkDraw fDraw;
  56. SkRasterClip fRasterClip;
  57. typedef SkNoncopyable INHERITED;
  58. };
  59. #endif // GrSWMaskHelper_DEFINED