| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrSWMaskHelper_DEFINED | 8 #ifndef GrSWMaskHelper_DEFINED |
| 9 #define GrSWMaskHelper_DEFINED | 9 #define GrSWMaskHelper_DEFINED |
| 10 | 10 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 class GrSWMaskHelper : public GrNoncopyable { | 41 class GrSWMaskHelper : public GrNoncopyable { |
| 42 public: | 42 public: |
| 43 GrSWMaskHelper(GrContext* context) | 43 GrSWMaskHelper(GrContext* context) |
| 44 : fContext(context) { | 44 : fContext(context) { |
| 45 } | 45 } |
| 46 | 46 |
| 47 // set up the internal state in preparation for draws. Since many masks | 47 // set up the internal state in preparation for draws. Since many masks |
| 48 // may be accumulated in the helper during creation, "resultBounds" | 48 // may be accumulated in the helper during creation, "resultBounds" |
| 49 // allows the caller to specify the region of interest - to limit the | 49 // allows the caller to specify the region of interest - to limit the |
| 50 // amount of work. | 50 // amount of work. |
| 51 bool init(const GrIRect& resultBounds, const SkMatrix* matrix); | 51 bool init(const SkIRect& resultBounds, const SkMatrix* matrix); |
| 52 | 52 |
| 53 // Draw a single rect into the accumulation bitmap using the specified op | 53 // Draw a single rect into the accumulation bitmap using the specified op |
| 54 void draw(const GrRect& rect, SkRegion::Op op, | 54 void draw(const SkRect& rect, SkRegion::Op op, |
| 55 bool antiAlias, uint8_t alpha); | 55 bool antiAlias, uint8_t alpha); |
| 56 | 56 |
| 57 // Draw a single path into the accumuation bitmap using the specified op | 57 // Draw a single path into the accumuation bitmap using the specified op |
| 58 void draw(const SkPath& path, const SkStrokeRec& stroke, SkRegion::Op op, | 58 void draw(const SkPath& path, const SkStrokeRec& stroke, SkRegion::Op op, |
| 59 bool antiAlias, uint8_t alpha); | 59 bool antiAlias, uint8_t alpha); |
| 60 | 60 |
| 61 // Helper function to get a scratch texture suitable for capturing the | 61 // Helper function to get a scratch texture suitable for capturing the |
| 62 // result (i.e., right size & format) | 62 // result (i.e., right size & format) |
| 63 bool getTexture(GrAutoScratchTexture* texture); | 63 bool getTexture(GrAutoScratchTexture* texture); |
| 64 | 64 |
| 65 // Move the mask generation results from the internal bitmap to the gpu. | 65 // Move the mask generation results from the internal bitmap to the gpu. |
| 66 // The space outside of the mask is cleared using "alpha" | 66 // The space outside of the mask is cleared using "alpha" |
| 67 void toTexture(GrTexture* texture, uint8_t alpha); | 67 void toTexture(GrTexture* texture, uint8_t alpha); |
| 68 | 68 |
| 69 // Reset the internal bitmap | 69 // Reset the internal bitmap |
| 70 void clear(uint8_t alpha) { | 70 void clear(uint8_t alpha) { |
| 71 fBM.eraseColor(SkColorSetARGB(alpha, alpha, alpha, alpha)); | 71 fBM.eraseColor(SkColorSetARGB(alpha, alpha, alpha, alpha)); |
| 72 } | 72 } |
| 73 | 73 |
| 74 // Canonical usage utility that draws a single path and uploads it | 74 // Canonical usage utility that draws a single path and uploads it |
| 75 // to the GPU. The result is returned in "result". | 75 // to the GPU. The result is returned in "result". |
| 76 static GrTexture* DrawPathMaskToTexture(GrContext* context, | 76 static GrTexture* DrawPathMaskToTexture(GrContext* context, |
| 77 const SkPath& path, | 77 const SkPath& path, |
| 78 const SkStrokeRec& stroke, | 78 const SkStrokeRec& stroke, |
| 79 const GrIRect& resultBounds, | 79 const SkIRect& resultBounds, |
| 80 bool antiAlias, | 80 bool antiAlias, |
| 81 SkMatrix* matrix); | 81 SkMatrix* matrix); |
| 82 | 82 |
| 83 // This utility routine is used to add a path's mask to some other draw. | 83 // This utility routine is used to add a path's mask to some other draw. |
| 84 // The ClipMaskManager uses it to accumulate clip masks while the | 84 // The ClipMaskManager uses it to accumulate clip masks while the |
| 85 // GrSoftwarePathRenderer uses it to fulfill a drawPath call. | 85 // GrSoftwarePathRenderer uses it to fulfill a drawPath call. |
| 86 // It draws with "texture" as a path mask into "target" using "rect" as | 86 // It draws with "texture" as a path mask into "target" using "rect" as |
| 87 // geometry and the current drawState. The current drawState is altered to | 87 // geometry and the current drawState. The current drawState is altered to |
| 88 // accommodate the mask. | 88 // accommodate the mask. |
| 89 // Note that this method assumes that the GrPaint::kTotalStages slot in | 89 // Note that this method assumes that the GrPaint::kTotalStages slot in |
| 90 // the draw state can be used to hold the mask texture stage. | 90 // the draw state can be used to hold the mask texture stage. |
| 91 // This method is really only intended to be used with the | 91 // This method is really only intended to be used with the |
| 92 // output of DrawPathMaskToTexture. | 92 // output of DrawPathMaskToTexture. |
| 93 static void DrawToTargetWithPathMask(GrTexture* texture, | 93 static void DrawToTargetWithPathMask(GrTexture* texture, |
| 94 GrDrawTarget* target, | 94 GrDrawTarget* target, |
| 95 const GrIRect& rect); | 95 const SkIRect& rect); |
| 96 | 96 |
| 97 protected: | 97 protected: |
| 98 private: | 98 private: |
| 99 GrContext* fContext; | 99 GrContext* fContext; |
| 100 SkMatrix fMatrix; | 100 SkMatrix fMatrix; |
| 101 SkBitmap fBM; | 101 SkBitmap fBM; |
| 102 SkDraw fDraw; | 102 SkDraw fDraw; |
| 103 SkRasterClip fRasterClip; | 103 SkRasterClip fRasterClip; |
| 104 | 104 |
| 105 typedef GrNoncopyable INHERITED; | 105 typedef GrNoncopyable INHERITED; |
| 106 }; | 106 }; |
| 107 | 107 |
| 108 #endif // GrSWMaskHelper_DEFINED | 108 #endif // GrSWMaskHelper_DEFINED |
| OLD | NEW |