Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #ifndef GrPathRenderer_DEFINED | 9 #ifndef GrPathRenderer_DEFINED |
| 10 #define GrPathRenderer_DEFINED | 10 #define GrPathRenderer_DEFINED |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 */ | 66 */ |
| 67 typedef GrPathRendererChain::StencilSupport StencilSupport; | 67 typedef GrPathRendererChain::StencilSupport StencilSupport; |
| 68 static const StencilSupport kNoSupport_StencilSupport = | 68 static const StencilSupport kNoSupport_StencilSupport = |
| 69 GrPathRendererChain::kNoSupport_StencilSupport; | 69 GrPathRendererChain::kNoSupport_StencilSupport; |
| 70 static const StencilSupport kStencilOnly_StencilSupport = | 70 static const StencilSupport kStencilOnly_StencilSupport = |
| 71 GrPathRendererChain::kStencilOnly_StencilSupport; | 71 GrPathRendererChain::kStencilOnly_StencilSupport; |
| 72 static const StencilSupport kNoRestriction_StencilSupport = | 72 static const StencilSupport kNoRestriction_StencilSupport = |
| 73 GrPathRendererChain::kNoRestriction_StencilSupport; | 73 GrPathRendererChain::kNoRestriction_StencilSupport; |
| 74 | 74 |
| 75 /** | 75 /** |
| 76 * This function is to get the stencil support for a particular path. The pa th's fill must | 76 * This function is to get the stencil support for the current path. The pat h's fill must |
| 77 * not be an inverse type. | 77 * not be an inverse type. |
| 78 * | 78 * |
| 79 * @param stroke the stroke information (width, join, cap). | |
| 79 * @param target target that the path will be rendered to | 80 * @param target target that the path will be rendered to |
| 80 * @param path the path that will be drawn | |
| 81 * @param stroke the stroke information (width, join, cap). | |
| 82 */ | 81 */ |
| 83 StencilSupport getStencilSupport(const SkPath& path, | 82 StencilSupport getStencilSupport(const SkStrokeRec& stroke, |
| 84 const SkStrokeRec& stroke, | |
| 85 const GrDrawTarget* target) const { | 83 const GrDrawTarget* target) const { |
| 86 SkASSERT(!path.isInverseFillType()); | 84 SkASSERT(!fPath.isInverseFillType()); |
| 87 return this->onGetStencilSupport(path, stroke, target); | 85 return this->onGetStencilSupport(stroke, target); |
| 86 } | |
| 87 | |
| 88 // Set the path and fill type the path renderer is to use. | |
| 89 // 'fillType' is included as a parameter b.c. we often want to draw | |
| 90 // inverse filled paths normally filled. | |
| 91 void setPath(const SkPath& path, SkPath::FillType fillType) { | |
| 92 fPath = path; | |
| 93 fPath.setFillType(fillType); | |
| 88 } | 94 } |
| 89 | 95 |
| 90 /** | 96 /** |
| 91 * Returns true if this path renderer is able to render the path. Returning false allows the | 97 * Returns true if this path renderer is able to render the current path. Re turning false |
| 92 * caller to fallback to another path renderer This function is called when searching for a path | 98 * allows the caller to fallback to another path renderer This function is c alled when |
| 93 * renderer capable of rendering a path. | 99 * searching for a path renderer capable of rendering a path. |
| 94 * | 100 * |
| 95 * @param path The path to draw | |
| 96 * @param stroke The stroke information (width, join, cap) | 101 * @param stroke The stroke information (width, join, cap) |
| 97 * @param target The target that the path will be rendered to | 102 * @param target The target that the path will be rendered to |
| 98 * @param antiAlias True if anti-aliasing is required. | 103 * @param antiAlias True if anti-aliasing is required. |
| 99 * | 104 * |
| 100 * @return true if the path can be drawn by this object, false otherwise. | 105 * @return true if the path can be drawn by this object, false otherwise. |
| 101 */ | 106 */ |
| 102 virtual bool canDrawPath(const SkPath& path, | 107 virtual bool canDrawPath(const SkStrokeRec& stroke, |
| 103 const SkStrokeRec& rec, | |
| 104 const GrDrawTarget* target, | 108 const GrDrawTarget* target, |
| 105 bool antiAlias) const = 0; | 109 bool antiAlias) const = 0; |
| 106 /** | 110 /** |
| 107 * Draws the path into the draw target. If getStencilSupport() would return kNoRestriction then | 111 * Draws the current path into the draw target. If getStencilSupport() would return |
| 108 * the subclass must respect the stencil settings of the target's draw state . | 112 * kNoRestriction then the subclass must respect the stencil settings of the |
| 113 * target's draw state. | |
| 109 * | 114 * |
| 110 * @param path the path to draw. | |
| 111 * @param stroke the stroke information (width, join, cap) | 115 * @param stroke the stroke information (width, join, cap) |
| 112 * @param target target that the path will be rendered to | 116 * @param target target that the path will be rendered to |
| 113 * @param antiAlias true if anti-aliasing is required. | 117 * @param antiAlias true if anti-aliasing is required. |
| 114 */ | 118 */ |
| 115 bool drawPath(const SkPath& path, | 119 bool drawPath(const SkStrokeRec& stroke, |
| 116 const SkStrokeRec& stroke, | |
| 117 GrDrawTarget* target, | 120 GrDrawTarget* target, |
| 118 bool antiAlias) { | 121 bool antiAlias) { |
| 119 SkASSERT(!path.isEmpty()); | 122 SkASSERT(!fPath.isEmpty()); |
| 120 SkASSERT(this->canDrawPath(path, stroke, target, antiAlias)); | 123 SkASSERT(this->canDrawPath(stroke, target, antiAlias)); |
| 121 SkASSERT(target->drawState()->getStencil().isDisabled() || | 124 SkASSERT(target->drawState()->getStencil().isDisabled() || |
| 122 kNoRestriction_StencilSupport == this->getStencilSupport(path, stroke, target)); | 125 kNoRestriction_StencilSupport == this->getStencilSupport(stroke , target)); |
| 123 return this->onDrawPath(path, stroke, target, antiAlias); | 126 return this->onDrawPath(stroke, target, antiAlias); |
| 124 } | 127 } |
| 125 | 128 |
| 126 /** | 129 /** |
| 127 * Draws the path to the stencil buffer. Assume the writable stencil bits ar e already | 130 * Draws the current path to the stencil buffer. Assume the writable stencil bits are already |
| 128 * initialized to zero. The pixels inside the path will have non-zero stenci l values afterwards. | 131 * initialized to zero. The pixels inside the path will have non-zero stenci l values |
| 132 * afterwards. | |
| 129 * | 133 * |
| 130 * @param path the path to draw. | |
| 131 * @param stroke the stroke information (width, join, cap) | 134 * @param stroke the stroke information (width, join, cap) |
| 132 * @param target target that the path will be rendered to | 135 * @param target target that the path will be rendered to |
| 133 */ | 136 */ |
| 134 void stencilPath(const SkPath& path, const SkStrokeRec& stroke, GrDrawTarget * target) { | 137 void stencilPath(const SkStrokeRec& stroke, GrDrawTarget* target) { |
| 135 SkASSERT(!path.isEmpty()); | 138 SkASSERT(!fPath.isEmpty()); |
| 136 SkASSERT(kNoSupport_StencilSupport != this->getStencilSupport(path, stro ke, target)); | 139 SkASSERT(kNoSupport_StencilSupport != this->getStencilSupport(stroke, ta rget)); |
| 137 this->onStencilPath(path, stroke, target); | 140 this->onStencilPath(stroke, target); |
| 138 } | 141 } |
| 139 | 142 |
| 140 protected: | 143 protected: |
| 144 SkPath fPath; | |
|
bsalomon
2013/09/17 18:16:49
private w/ a const getter? I wonder if we ever wan
robertphillips
2013/09/17 19:51:16
Done.
| |
| 145 | |
| 141 /** | 146 /** |
| 142 * Subclass overrides if it has any limitations of stenciling support. | 147 * Subclass overrides if it has any limitations of stenciling support. |
| 143 */ | 148 */ |
| 144 virtual StencilSupport onGetStencilSupport(const SkPath&, | 149 virtual StencilSupport onGetStencilSupport(const SkStrokeRec&, |
| 145 const SkStrokeRec&, | |
| 146 const GrDrawTarget*) const { | 150 const GrDrawTarget*) const { |
| 147 return kNoRestriction_StencilSupport; | 151 return kNoRestriction_StencilSupport; |
| 148 } | 152 } |
| 149 | 153 |
| 150 /** | 154 /** |
| 151 * Subclass implementation of drawPath() | 155 * Subclass implementation of drawPath() |
| 152 */ | 156 */ |
| 153 virtual bool onDrawPath(const SkPath& path, | 157 virtual bool onDrawPath(const SkStrokeRec& stroke, |
| 154 const SkStrokeRec& stroke, | |
| 155 GrDrawTarget* target, | 158 GrDrawTarget* target, |
| 156 bool antiAlias) = 0; | 159 bool antiAlias) = 0; |
| 157 | 160 |
| 158 /** | 161 /** |
| 159 * Subclass implementation of stencilPath(). Subclass must override iff it e ver returns | 162 * Subclass implementation of stencilPath(). Subclass must override iff it e ver returns |
| 160 * kStencilOnly in onGetStencilSupport(). | 163 * kStencilOnly in onGetStencilSupport(). |
| 161 */ | 164 */ |
| 162 virtual void onStencilPath(const SkPath& path, const SkStrokeRec& stroke, G rDrawTarget* target) { | 165 virtual void onStencilPath(const SkStrokeRec& stroke, GrDrawTarget* target) { |
| 163 GrDrawTarget::AutoStateRestore asr(target, GrDrawTarget::kPreserve_ASRIn it); | 166 GrDrawTarget::AutoStateRestore asr(target, GrDrawTarget::kPreserve_ASRIn it); |
| 164 GrDrawState* drawState = target->drawState(); | 167 GrDrawState* drawState = target->drawState(); |
| 165 GR_STATIC_CONST_SAME_STENCIL(kIncrementStencil, | 168 GR_STATIC_CONST_SAME_STENCIL(kIncrementStencil, |
| 166 kReplace_StencilOp, | 169 kReplace_StencilOp, |
| 167 kReplace_StencilOp, | 170 kReplace_StencilOp, |
| 168 kAlways_StencilFunc, | 171 kAlways_StencilFunc, |
| 169 0xffff, | 172 0xffff, |
| 170 0xffff, | 173 0xffff, |
| 171 0xffff); | 174 0xffff); |
| 172 drawState->setStencil(kIncrementStencil); | 175 drawState->setStencil(kIncrementStencil); |
| 173 drawState->enableState(GrDrawState::kNoColorWrites_StateBit); | 176 drawState->enableState(GrDrawState::kNoColorWrites_StateBit); |
| 174 this->drawPath(path, stroke, target, false); | 177 this->drawPath(stroke, target, false); |
| 175 } | 178 } |
| 176 | 179 |
| 177 // Helper for getting the device bounds of a path. Inverse filled paths will have bounds set | 180 // Helper for getting the device bounds of a path. Inverse filled paths will have bounds set |
| 178 // by devSize. Non-inverse path bounds will not necessarily be clipped to de vSize. | 181 // by devSize. Non-inverse path bounds will not necessarily be clipped to de vSize. |
| 179 static void GetPathDevBounds(const SkPath& path, | 182 static void GetPathDevBounds(const SkPath& path, |
| 180 int devW, | 183 int devW, |
| 181 int devH, | 184 int devH, |
| 182 const SkMatrix& matrix, | 185 const SkMatrix& matrix, |
| 183 SkRect* bounds); | 186 SkRect* bounds); |
| 184 | 187 |
| 185 // Helper version that gets the dev width and height from a GrSurface. | 188 // Helper version that gets the dev width and height from a GrSurface. |
| 186 static void GetPathDevBounds(const SkPath& path, | 189 static void GetPathDevBounds(const SkPath& path, |
| 187 const GrSurface* device, | 190 const GrSurface* device, |
| 188 const SkMatrix& matrix, | 191 const SkMatrix& matrix, |
| 189 SkRect* bounds) { | 192 SkRect* bounds) { |
| 190 GetPathDevBounds(path, device->width(), device->height(), matrix, bounds ); | 193 GetPathDevBounds(path, device->width(), device->height(), matrix, bounds ); |
| 191 } | 194 } |
| 192 | 195 |
| 193 private: | 196 private: |
| 194 | |
| 195 typedef SkRefCnt INHERITED; | 197 typedef SkRefCnt INHERITED; |
| 196 }; | 198 }; |
| 197 | 199 |
| 198 #endif | 200 #endif |
| OLD | NEW |