Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(742)

Side by Side Diff: src/gpu/GrSWMaskHelper.h

Issue 1993403002: GrSWMaskHelper and GrSoftwarePathRenderer only need the textureProvider (not GrContext) (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrDrawingManager.cpp ('k') | src/gpu/GrSWMaskHelper.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 #include "SkAutoPixmapStorage.h" 11 #include "SkAutoPixmapStorage.h"
12 #include "GrColor.h" 12 #include "GrColor.h"
13 #include "GrPipelineBuilder.h" 13 #include "GrPipelineBuilder.h"
14 #include "SkBitmap.h" 14 #include "SkBitmap.h"
15 #include "SkDraw.h" 15 #include "SkDraw.h"
16 #include "SkMatrix.h" 16 #include "SkMatrix.h"
17 #include "SkRasterClip.h" 17 #include "SkRasterClip.h"
18 #include "SkRegion.h" 18 #include "SkRegion.h"
19 #include "SkTypes.h" 19 #include "SkTypes.h"
20 20
21 class GrClip; 21 class GrClip;
22 class GrContext; 22 class GrTextureProvider;
23 class GrTexture; 23 class GrTexture;
24 class SkPath; 24 class SkPath;
25 class SkStrokeRec; 25 class SkStrokeRec;
26 class GrDrawTarget; 26 class GrDrawTarget;
27 27
28 /** 28 /**
29 * The GrSWMaskHelper helps generate clip masks using the software rendering 29 * The GrSWMaskHelper helps generate clip masks using the software rendering
30 * path. It is intended to be used as: 30 * path. It is intended to be used as:
31 * 31 *
32 * GrSWMaskHelper helper(context); 32 * GrSWMaskHelper helper(context);
33 * helper.init(...); 33 * helper.init(...);
34 * 34 *
35 * draw one or more paths/rects specifying the required boolean ops 35 * draw one or more paths/rects specifying the required boolean ops
36 * 36 *
37 * toTexture(); // to get it from the internal bitmap to the GPU 37 * toTexture(); // to get it from the internal bitmap to the GPU
38 * 38 *
39 * The result of this process will be the final mask (on the GPU) in the 39 * The result of this process will be the final mask (on the GPU) in the
40 * upper left hand corner of the texture. 40 * upper left hand corner of the texture.
41 */ 41 */
42 class GrSWMaskHelper : SkNoncopyable { 42 class GrSWMaskHelper : SkNoncopyable {
43 public: 43 public:
44 GrSWMaskHelper(GrContext* context) : fContext(context) { } 44 GrSWMaskHelper(GrTextureProvider* texProvider) : fTexProvider(texProvider) { }
45 45
46 // set up the internal state in preparation for draws. Since many masks 46 // set up the internal state in preparation for draws. Since many masks
47 // may be accumulated in the helper during creation, "resultBounds" 47 // may be accumulated in the helper during creation, "resultBounds"
48 // allows the caller to specify the region of interest - to limit the 48 // allows the caller to specify the region of interest - to limit the
49 // amount of work. 49 // amount of work.
50 bool init(const SkIRect& resultBounds, const SkMatrix* matrix); 50 bool init(const SkIRect& resultBounds, const SkMatrix* matrix);
51 51
52 // Draw a single rect into the accumulation bitmap using the specified op 52 // Draw a single rect into the accumulation bitmap using the specified op
53 void drawRect(const SkRect& rect, SkRegion::Op op, bool antiAlias, uint8_t a lpha); 53 void drawRect(const SkRect& rect, SkRegion::Op op, bool antiAlias, uint8_t a lpha);
54 54
55 // Draw a single path into the accumuation bitmap using the specified op 55 // Draw a single path into the accumuation bitmap using the specified op
56 void drawPath(const SkPath& path, const GrStyle& style, SkRegion::Op op, 56 void drawPath(const SkPath& path, const GrStyle& style, SkRegion::Op op,
57 bool antiAlias, uint8_t alpha); 57 bool antiAlias, uint8_t alpha);
58 58
59 // Move the mask generation results from the internal bitmap to the gpu. 59 // Move the mask generation results from the internal bitmap to the gpu.
60 void toTexture(GrTexture* texture); 60 void toTexture(GrTexture* texture);
61 61
62 // Convert mask generation results to a signed distance field 62 // Convert mask generation results to a signed distance field
63 void toSDF(unsigned char* sdf); 63 void toSDF(unsigned char* sdf);
64 64
65 // Reset the internal bitmap 65 // Reset the internal bitmap
66 void clear(uint8_t alpha) { 66 void clear(uint8_t alpha) {
67 fPixels.erase(SkColorSetARGB(alpha, 0xFF, 0xFF, 0xFF)); 67 fPixels.erase(SkColorSetARGB(alpha, 0xFF, 0xFF, 0xFF));
68 } 68 }
69 69
70 // Canonical usage utility that draws a single path and uploads it 70 // Canonical usage utility that draws a single path and uploads it
71 // to the GPU. The result is returned. 71 // to the GPU. The result is returned.
72 static GrTexture* DrawPathMaskToTexture(GrContext* context, 72 static GrTexture* DrawPathMaskToTexture(GrTextureProvider*,
73 const SkPath& path, 73 const SkPath& path,
74 const GrStyle& style, 74 const GrStyle& style,
75 const SkIRect& resultBounds, 75 const SkIRect& resultBounds,
76 bool antiAlias, 76 bool antiAlias,
77 const SkMatrix* matrix); 77 const SkMatrix* matrix);
78 78
79 // This utility routine is used to add a path's mask to some other draw. 79 // This utility routine is used to add a path's mask to some other draw.
80 // The ClipMaskManager uses it to accumulate clip masks while the 80 // The ClipMaskManager uses it to accumulate clip masks while the
81 // GrSoftwarePathRenderer uses it to fulfill a drawPath call. 81 // GrSoftwarePathRenderer uses it to fulfill a drawPath call.
82 // It draws with "texture" as a path mask into "target" using "rect" as 82 // It draws with "texture" as a path mask into "target" using "rect" as
83 // geometry and the current drawState. The current drawState is altered to 83 // geometry and the current drawState. The current drawState is altered to
84 // accommodate the mask. 84 // accommodate the mask.
85 // Note that this method assumes that the GrPaint::kTotalStages slot in 85 // Note that this method assumes that the GrPaint::kTotalStages slot in
86 // the draw state can be used to hold the mask texture stage. 86 // the draw state can be used to hold the mask texture stage.
87 // This method is really only intended to be used with the 87 // This method is really only intended to be used with the
88 // output of DrawPathMaskToTexture. 88 // output of DrawPathMaskToTexture.
89 static void DrawToTargetWithPathMask(GrTexture* texture, 89 static void DrawToTargetWithPathMask(GrTexture* texture,
90 GrDrawTarget* target, 90 GrDrawTarget* target,
91 GrPipelineBuilder* pipelineBuilder, 91 GrPipelineBuilder* pipelineBuilder,
92 const GrClip&, 92 const GrClip&,
93 GrColor, 93 GrColor,
94 const SkMatrix& viewMatrix, 94 const SkMatrix& viewMatrix,
95 const SkIRect& rect); 95 const SkIRect& rect);
96 96
97 private: 97 private:
98 // Helper function to get a scratch texture suitable for capturing the 98 // Helper function to get a scratch texture suitable for capturing the
99 // result (i.e., right size & format) 99 // result (i.e., right size & format)
100 GrTexture* createTexture(); 100 GrTexture* createTexture();
101 101
102 GrContext* fContext; 102 GrTextureProvider* fTexProvider;
103 SkMatrix fMatrix; 103 SkMatrix fMatrix;
104 SkAutoPixmapStorage fPixels; 104 SkAutoPixmapStorage fPixels;
105 SkDraw fDraw; 105 SkDraw fDraw;
106 SkRasterClip fRasterClip; 106 SkRasterClip fRasterClip;
107 107
108 typedef SkNoncopyable INHERITED; 108 typedef SkNoncopyable INHERITED;
109 }; 109 };
110 110
111 #endif // GrSWMaskHelper_DEFINED 111 #endif // GrSWMaskHelper_DEFINED
OLDNEW
« no previous file with comments | « src/gpu/GrDrawingManager.cpp ('k') | src/gpu/GrSWMaskHelper.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698