robertphillips@google.com | f4c2c52 | 2012-04-27 12:08:47 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2012 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
| 9 | #include "GrSoftwarePathRenderer.h" |
robertphillips@google.com | ed4155d | 2012-05-01 14:30:24 +0000 | [diff] [blame] | 10 | #include "GrPaint.h" |
| 11 | #include "SkPaint.h" |
| 12 | #include "GrRenderTarget.h" |
| 13 | #include "GrContext.h" |
| 14 | #include "SkDraw.h" |
| 15 | #include "SkRasterClip.h" |
robertphillips@google.com | c82a8b7 | 2012-06-21 20:15:48 +0000 | [diff] [blame^] | 16 | #include "GrGpu.h" |
robertphillips@google.com | f4c2c52 | 2012-04-27 12:08:47 +0000 | [diff] [blame] | 17 | |
robertphillips@google.com | ed4155d | 2012-05-01 14:30:24 +0000 | [diff] [blame] | 18 | //////////////////////////////////////////////////////////////////////////////// |
robertphillips@google.com | f4c2c52 | 2012-04-27 12:08:47 +0000 | [diff] [blame] | 19 | bool GrSoftwarePathRenderer::canDrawPath(const SkPath& path, |
| 20 | GrPathFill fill, |
| 21 | const GrDrawTarget* target, |
| 22 | bool antiAlias) const { |
robertphillips@google.com | ed4155d | 2012-05-01 14:30:24 +0000 | [diff] [blame] | 23 | if (!antiAlias || NULL == fContext) { |
| 24 | // TODO: We could allow the SW path to also handle non-AA paths but |
| 25 | // this would mean that GrDefaultPathRenderer would never be called |
| 26 | // (since it appears after the SW renderer in the path renderer |
| 27 | // chain). Some testing would need to be done r.e. performance |
| 28 | // and consistency of the resulting images before removing |
| 29 | // the "!antiAlias" clause from the above test |
robertphillips@google.com | f4c2c52 | 2012-04-27 12:08:47 +0000 | [diff] [blame] | 30 | return false; |
| 31 | } |
| 32 | |
robertphillips@google.com | ed4155d | 2012-05-01 14:30:24 +0000 | [diff] [blame] | 33 | return true; |
robertphillips@google.com | f4c2c52 | 2012-04-27 12:08:47 +0000 | [diff] [blame] | 34 | } |
| 35 | |
robertphillips@google.com | ed4155d | 2012-05-01 14:30:24 +0000 | [diff] [blame] | 36 | namespace { |
| 37 | |
| 38 | //////////////////////////////////////////////////////////////////////////////// |
| 39 | SkPath::FillType gr_fill_to_sk_fill(GrPathFill fill) { |
| 40 | switch (fill) { |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 41 | case kWinding_GrPathFill: |
robertphillips@google.com | ed4155d | 2012-05-01 14:30:24 +0000 | [diff] [blame] | 42 | return SkPath::kWinding_FillType; |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 43 | case kEvenOdd_GrPathFill: |
robertphillips@google.com | ed4155d | 2012-05-01 14:30:24 +0000 | [diff] [blame] | 44 | return SkPath::kEvenOdd_FillType; |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 45 | case kInverseWinding_GrPathFill: |
robertphillips@google.com | ed4155d | 2012-05-01 14:30:24 +0000 | [diff] [blame] | 46 | return SkPath::kInverseWinding_FillType; |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 47 | case kInverseEvenOdd_GrPathFill: |
robertphillips@google.com | ed4155d | 2012-05-01 14:30:24 +0000 | [diff] [blame] | 48 | return SkPath::kInverseEvenOdd_FillType; |
| 49 | default: |
| 50 | GrCrash("Unexpected fill."); |
| 51 | return SkPath::kWinding_FillType; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | //////////////////////////////////////////////////////////////////////////////// |
| 56 | // gets device coord bounds of path (not considering the fill) and clip. The |
| 57 | // path bounds will be a subset of the clip bounds. returns false if |
| 58 | // path bounds would be empty. |
| 59 | bool get_path_and_clip_bounds(const GrDrawTarget* target, |
| 60 | const SkPath& path, |
| 61 | const GrVec* translate, |
| 62 | GrIRect* pathBounds, |
| 63 | GrIRect* clipBounds) { |
| 64 | // compute bounds as intersection of rt size, clip, and path |
| 65 | const GrRenderTarget* rt = target->getDrawState().getRenderTarget(); |
| 66 | if (NULL == rt) { |
| 67 | return false; |
| 68 | } |
| 69 | *pathBounds = GrIRect::MakeWH(rt->width(), rt->height()); |
| 70 | const GrClip& clip = target->getClip(); |
| 71 | if (clip.hasConservativeBounds()) { |
| 72 | clip.getConservativeBounds().roundOut(clipBounds); |
| 73 | if (!pathBounds->intersect(*clipBounds)) { |
| 74 | return false; |
| 75 | } |
| 76 | } else { |
| 77 | // pathBounds is currently the rt extent, set clip bounds to that rect. |
| 78 | *clipBounds = *pathBounds; |
| 79 | } |
| 80 | GrRect pathSBounds = path.getBounds(); |
| 81 | if (!pathSBounds.isEmpty()) { |
| 82 | if (NULL != translate) { |
| 83 | pathSBounds.offset(*translate); |
| 84 | } |
| 85 | target->getDrawState().getViewMatrix().mapRect(&pathSBounds, |
| 86 | pathSBounds); |
| 87 | GrIRect pathIBounds; |
| 88 | pathSBounds.roundOut(&pathIBounds); |
| 89 | if (!pathBounds->intersect(pathIBounds)) { |
bsalomon@google.com | 276c1fa | 2012-06-19 13:22:45 +0000 | [diff] [blame] | 90 | // set the correct path bounds, as this would be used later. |
| 91 | *pathBounds = pathIBounds; |
robertphillips@google.com | ed4155d | 2012-05-01 14:30:24 +0000 | [diff] [blame] | 92 | return false; |
| 93 | } |
| 94 | } else { |
bsalomon@google.com | 276c1fa | 2012-06-19 13:22:45 +0000 | [diff] [blame] | 95 | *pathBounds = GrIRect::EmptyIRect(); |
robertphillips@google.com | ed4155d | 2012-05-01 14:30:24 +0000 | [diff] [blame] | 96 | return false; |
| 97 | } |
| 98 | return true; |
| 99 | } |
| 100 | |
robertphillips@google.com | b4f06d7 | 2012-05-15 12:10:05 +0000 | [diff] [blame] | 101 | |
| 102 | /* |
| 103 | * Convert a boolean operation into a transfer mode code |
robertphillips@google.com | 6f31a3b | 2012-05-14 17:37:05 +0000 | [diff] [blame] | 104 | */ |
robertphillips@google.com | b4f06d7 | 2012-05-15 12:10:05 +0000 | [diff] [blame] | 105 | SkXfermode::Mode op_to_mode(SkRegion::Op op) { |
robertphillips@google.com | 6f31a3b | 2012-05-14 17:37:05 +0000 | [diff] [blame] | 106 | |
robertphillips@google.com | b4f06d7 | 2012-05-15 12:10:05 +0000 | [diff] [blame] | 107 | static const SkXfermode::Mode modeMap[] = { |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 108 | SkXfermode::kDstOut_Mode, // kDifference_Op |
robertphillips@google.com | b4f06d7 | 2012-05-15 12:10:05 +0000 | [diff] [blame] | 109 | SkXfermode::kMultiply_Mode, // kIntersect_Op |
| 110 | SkXfermode::kSrcOver_Mode, // kUnion_Op |
| 111 | SkXfermode::kXor_Mode, // kXOR_Op |
| 112 | SkXfermode::kClear_Mode, // kReverseDifference_Op |
| 113 | SkXfermode::kSrc_Mode, // kReplace_Op |
| 114 | }; |
| 115 | |
| 116 | return modeMap[op]; |
| 117 | } |
| 118 | |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Draw a single rect element of the clip stack into the accumulation bitmap |
| 123 | */ |
| 124 | void GrSWMaskHelper::draw(const GrRect& clientRect, SkRegion::Op op, |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 125 | bool antiAlias, GrColor color) { |
robertphillips@google.com | b4f06d7 | 2012-05-15 12:10:05 +0000 | [diff] [blame] | 126 | SkPaint paint; |
| 127 | |
| 128 | SkXfermode* mode = SkXfermode::Create(op_to_mode(op)); |
| 129 | |
| 130 | paint.setXfermode(mode); |
| 131 | paint.setAntiAlias(antiAlias); |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 132 | paint.setColor(color); |
robertphillips@google.com | b4f06d7 | 2012-05-15 12:10:05 +0000 | [diff] [blame] | 133 | |
| 134 | fDraw.drawRect(clientRect, paint); |
| 135 | |
| 136 | SkSafeUnref(mode); |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Draw a single path element of the clip stack into the accumulation bitmap |
| 141 | */ |
| 142 | void GrSWMaskHelper::draw(const SkPath& clientPath, SkRegion::Op op, |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 143 | GrPathFill fill, bool antiAlias, GrColor color) { |
robertphillips@google.com | b4f06d7 | 2012-05-15 12:10:05 +0000 | [diff] [blame] | 144 | |
| 145 | SkPaint paint; |
| 146 | SkPath tmpPath; |
| 147 | const SkPath* pathToDraw = &clientPath; |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 148 | if (kHairLine_GrPathFill == fill) { |
robertphillips@google.com | b4f06d7 | 2012-05-15 12:10:05 +0000 | [diff] [blame] | 149 | paint.setStyle(SkPaint::kStroke_Style); |
| 150 | paint.setStrokeWidth(SK_Scalar1); |
| 151 | } else { |
| 152 | paint.setStyle(SkPaint::kFill_Style); |
| 153 | SkPath::FillType skfill = gr_fill_to_sk_fill(fill); |
| 154 | if (skfill != pathToDraw->getFillType()) { |
| 155 | tmpPath = *pathToDraw; |
| 156 | tmpPath.setFillType(skfill); |
| 157 | pathToDraw = &tmpPath; |
| 158 | } |
| 159 | } |
| 160 | SkXfermode* mode = SkXfermode::Create(op_to_mode(op)); |
| 161 | |
| 162 | paint.setXfermode(mode); |
| 163 | paint.setAntiAlias(antiAlias); |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 164 | paint.setColor(color); |
robertphillips@google.com | b4f06d7 | 2012-05-15 12:10:05 +0000 | [diff] [blame] | 165 | |
| 166 | fDraw.drawPath(*pathToDraw, paint); |
| 167 | |
| 168 | SkSafeUnref(mode); |
| 169 | } |
| 170 | |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 171 | bool GrSWMaskHelper::init(const GrIRect& pathDevBounds, |
| 172 | const GrPoint* translate, |
| 173 | bool useMatrix) { |
| 174 | if (useMatrix) { |
| 175 | fMatrix = fContext->getMatrix(); |
| 176 | } else { |
| 177 | fMatrix.setIdentity(); |
| 178 | } |
| 179 | |
robertphillips@google.com | b4f06d7 | 2012-05-15 12:10:05 +0000 | [diff] [blame] | 180 | if (NULL != translate) { |
| 181 | fMatrix.postTranslate(translate->fX, translate->fY); |
robertphillips@google.com | 6f31a3b | 2012-05-14 17:37:05 +0000 | [diff] [blame] | 182 | } |
| 183 | |
robertphillips@google.com | b4f06d7 | 2012-05-15 12:10:05 +0000 | [diff] [blame] | 184 | fMatrix.postTranslate(-pathDevBounds.fLeft * SK_Scalar1, |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 185 | -pathDevBounds.fTop * SK_Scalar1); |
robertphillips@google.com | b4f06d7 | 2012-05-15 12:10:05 +0000 | [diff] [blame] | 186 | GrIRect bounds = GrIRect::MakeWH(pathDevBounds.width(), |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 187 | pathDevBounds.height()); |
robertphillips@google.com | 6f31a3b | 2012-05-14 17:37:05 +0000 | [diff] [blame] | 188 | |
robertphillips@google.com | b4f06d7 | 2012-05-15 12:10:05 +0000 | [diff] [blame] | 189 | fBM.setConfig(SkBitmap::kA8_Config, bounds.fRight, bounds.fBottom); |
| 190 | if (!fBM.allocPixels()) { |
| 191 | return false; |
| 192 | } |
| 193 | sk_bzero(fBM.getPixels(), fBM.getSafeSize()); |
| 194 | |
| 195 | sk_bzero(&fDraw, sizeof(fDraw)); |
| 196 | fRasterClip.setRect(bounds); |
| 197 | fDraw.fRC = &fRasterClip; |
| 198 | fDraw.fClip = &fRasterClip.bwRgn(); |
| 199 | fDraw.fMatrix = &fMatrix; |
| 200 | fDraw.fBitmap = &fBM; |
| 201 | return true; |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * Get a texture (from the texture cache) of the correct size & format |
| 206 | */ |
| 207 | bool GrSWMaskHelper::getTexture(GrAutoScratchTexture* tex) { |
robertphillips@google.com | 75b3c96 | 2012-06-07 12:08:45 +0000 | [diff] [blame] | 208 | GrTextureDesc desc; |
| 209 | desc.fWidth = fBM.width(); |
| 210 | desc.fHeight = fBM.height(); |
| 211 | desc.fConfig = kAlpha_8_GrPixelConfig; |
robertphillips@google.com | b4f06d7 | 2012-05-15 12:10:05 +0000 | [diff] [blame] | 212 | |
| 213 | tex->set(fContext, desc); |
| 214 | GrTexture* texture = tex->texture(); |
| 215 | |
| 216 | if (NULL == texture) { |
| 217 | return false; |
robertphillips@google.com | 6f31a3b | 2012-05-14 17:37:05 +0000 | [diff] [blame] | 218 | } |
| 219 | |
robertphillips@google.com | b4f06d7 | 2012-05-15 12:10:05 +0000 | [diff] [blame] | 220 | return true; |
| 221 | } |
robertphillips@google.com | 6f31a3b | 2012-05-14 17:37:05 +0000 | [diff] [blame] | 222 | |
robertphillips@google.com | b4f06d7 | 2012-05-15 12:10:05 +0000 | [diff] [blame] | 223 | /** |
| 224 | * Move the result of the software mask generation back to the gpu |
| 225 | */ |
robertphillips@google.com | c82a8b7 | 2012-06-21 20:15:48 +0000 | [diff] [blame^] | 226 | void GrSWMaskHelper::toTexture(GrTexture *texture, bool clearToWhite) { |
robertphillips@google.com | b4f06d7 | 2012-05-15 12:10:05 +0000 | [diff] [blame] | 227 | SkAutoLockPixels alp(fBM); |
robertphillips@google.com | c82a8b7 | 2012-06-21 20:15:48 +0000 | [diff] [blame^] | 228 | |
| 229 | // The destination texture is almost always larger than "fBM". Clear |
| 230 | // it appropriately so we don't get mask artifacts outside of the path's |
| 231 | // bounding box |
| 232 | |
| 233 | // "texture" needs to be installed as the render target for the clear |
| 234 | // and the texture upload but cannot remain the render target upon |
| 235 | // returned. Callers typically use it as a texture and it would then |
| 236 | // be both source and dest. |
| 237 | GrDrawState::AutoRenderTargetRestore artr(fContext->getGpu()->drawState(), |
| 238 | texture->asRenderTarget()); |
| 239 | |
| 240 | if (clearToWhite) { |
| 241 | fContext->getGpu()->clear(NULL, SK_ColorWHITE); |
| 242 | } else { |
| 243 | fContext->getGpu()->clear(NULL, 0x00000000); |
| 244 | } |
| 245 | |
robertphillips@google.com | b4f06d7 | 2012-05-15 12:10:05 +0000 | [diff] [blame] | 246 | texture->writePixels(0, 0, fBM.width(), fBM.height(), |
| 247 | kAlpha_8_GrPixelConfig, |
| 248 | fBM.getPixels(), fBM.rowBytes()); |
| 249 | } |
robertphillips@google.com | 6f31a3b | 2012-05-14 17:37:05 +0000 | [diff] [blame] | 250 | |
robertphillips@google.com | b4f06d7 | 2012-05-15 12:10:05 +0000 | [diff] [blame] | 251 | namespace { |
robertphillips@google.com | ed4155d | 2012-05-01 14:30:24 +0000 | [diff] [blame] | 252 | //////////////////////////////////////////////////////////////////////////////// |
| 253 | /** |
| 254 | * sw rasterizes path to A8 mask using the context's matrix and uploads to a |
| 255 | * scratch texture. |
| 256 | */ |
robertphillips@google.com | ed4155d | 2012-05-01 14:30:24 +0000 | [diff] [blame] | 257 | bool sw_draw_path_to_mask_texture(const SkPath& clientPath, |
| 258 | const GrIRect& pathDevBounds, |
| 259 | GrPathFill fill, |
| 260 | GrContext* context, |
| 261 | const GrPoint* translate, |
| 262 | GrAutoScratchTexture* tex, |
| 263 | bool antiAlias) { |
robertphillips@google.com | 6f31a3b | 2012-05-14 17:37:05 +0000 | [diff] [blame] | 264 | GrSWMaskHelper helper(context); |
robertphillips@google.com | ed4155d | 2012-05-01 14:30:24 +0000 | [diff] [blame] | 265 | |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 266 | if (!helper.init(pathDevBounds, translate, true)) { |
robertphillips@google.com | ed4155d | 2012-05-01 14:30:24 +0000 | [diff] [blame] | 267 | return false; |
| 268 | } |
robertphillips@google.com | ed4155d | 2012-05-01 14:30:24 +0000 | [diff] [blame] | 269 | |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 270 | helper.draw(clientPath, SkRegion::kReplace_Op, |
| 271 | fill, antiAlias, SK_ColorWHITE); |
robertphillips@google.com | ed4155d | 2012-05-01 14:30:24 +0000 | [diff] [blame] | 272 | |
robertphillips@google.com | b4f06d7 | 2012-05-15 12:10:05 +0000 | [diff] [blame] | 273 | if (!helper.getTexture(tex)) { |
robertphillips@google.com | ed4155d | 2012-05-01 14:30:24 +0000 | [diff] [blame] | 274 | return false; |
| 275 | } |
robertphillips@google.com | 6f31a3b | 2012-05-14 17:37:05 +0000 | [diff] [blame] | 276 | |
robertphillips@google.com | c82a8b7 | 2012-06-21 20:15:48 +0000 | [diff] [blame^] | 277 | helper.toTexture(tex->texture(), false); |
robertphillips@google.com | b4f06d7 | 2012-05-15 12:10:05 +0000 | [diff] [blame] | 278 | |
robertphillips@google.com | ed4155d | 2012-05-01 14:30:24 +0000 | [diff] [blame] | 279 | return true; |
| 280 | } |
| 281 | |
| 282 | //////////////////////////////////////////////////////////////////////////////// |
| 283 | void draw_around_inv_path(GrDrawTarget* target, |
| 284 | GrDrawState::StageMask stageMask, |
| 285 | const GrIRect& clipBounds, |
| 286 | const GrIRect& pathBounds) { |
| 287 | GrDrawTarget::AutoDeviceCoordDraw adcd(target, stageMask); |
| 288 | GrRect rect; |
| 289 | if (clipBounds.fTop < pathBounds.fTop) { |
| 290 | rect.iset(clipBounds.fLeft, clipBounds.fTop, |
| 291 | clipBounds.fRight, pathBounds.fTop); |
| 292 | target->drawSimpleRect(rect, NULL, stageMask); |
| 293 | } |
| 294 | if (clipBounds.fLeft < pathBounds.fLeft) { |
| 295 | rect.iset(clipBounds.fLeft, pathBounds.fTop, |
| 296 | pathBounds.fLeft, pathBounds.fBottom); |
| 297 | target->drawSimpleRect(rect, NULL, stageMask); |
| 298 | } |
| 299 | if (clipBounds.fRight > pathBounds.fRight) { |
| 300 | rect.iset(pathBounds.fRight, pathBounds.fTop, |
| 301 | clipBounds.fRight, pathBounds.fBottom); |
| 302 | target->drawSimpleRect(rect, NULL, stageMask); |
| 303 | } |
| 304 | if (clipBounds.fBottom > pathBounds.fBottom) { |
| 305 | rect.iset(clipBounds.fLeft, pathBounds.fBottom, |
| 306 | clipBounds.fRight, clipBounds.fBottom); |
| 307 | target->drawSimpleRect(rect, NULL, stageMask); |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | } |
| 312 | |
| 313 | //////////////////////////////////////////////////////////////////////////////// |
| 314 | // return true on success; false on failure |
robertphillips@google.com | f4c2c52 | 2012-04-27 12:08:47 +0000 | [diff] [blame] | 315 | bool GrSoftwarePathRenderer::onDrawPath(const SkPath& path, |
| 316 | GrPathFill fill, |
| 317 | const GrVec* translate, |
| 318 | GrDrawTarget* target, |
| 319 | GrDrawState::StageMask stageMask, |
| 320 | bool antiAlias) { |
| 321 | |
robertphillips@google.com | ed4155d | 2012-05-01 14:30:24 +0000 | [diff] [blame] | 322 | if (NULL == fContext) { |
| 323 | return false; |
| 324 | } |
| 325 | |
| 326 | GrAutoScratchTexture ast; |
| 327 | GrIRect pathBounds, clipBounds; |
| 328 | if (!get_path_and_clip_bounds(target, path, translate, |
| 329 | &pathBounds, &clipBounds)) { |
bsalomon@google.com | 276c1fa | 2012-06-19 13:22:45 +0000 | [diff] [blame] | 330 | if (GrIsFillInverted(fill)) { |
| 331 | draw_around_inv_path(target, stageMask, |
| 332 | clipBounds, pathBounds); |
| 333 | } |
| 334 | return true; |
robertphillips@google.com | ed4155d | 2012-05-01 14:30:24 +0000 | [diff] [blame] | 335 | } |
| 336 | if (sw_draw_path_to_mask_texture(path, pathBounds, |
| 337 | fill, fContext, |
| 338 | translate, &ast, antiAlias)) { |
| 339 | GrTexture* texture = ast.texture(); |
| 340 | GrAssert(NULL != texture); |
| 341 | GrDrawTarget::AutoDeviceCoordDraw adcd(target, stageMask); |
| 342 | enum { |
robertphillips@google.com | 7ff2e37 | 2012-05-02 19:27:44 +0000 | [diff] [blame] | 343 | // the SW path renderer shares this stage with glyph |
| 344 | // rendering (kGlyphMaskStage in GrBatchedTextContext) |
| 345 | kPathMaskStage = GrPaint::kTotalStages, |
robertphillips@google.com | ed4155d | 2012-05-01 14:30:24 +0000 | [diff] [blame] | 346 | }; |
robertphillips@google.com | beeb97c | 2012-05-09 21:15:28 +0000 | [diff] [blame] | 347 | GrAssert(NULL == target->drawState()->getTexture(kPathMaskStage)); |
robertphillips@google.com | ed4155d | 2012-05-01 14:30:24 +0000 | [diff] [blame] | 348 | target->drawState()->setTexture(kPathMaskStage, texture); |
| 349 | target->drawState()->sampler(kPathMaskStage)->reset(); |
| 350 | GrScalar w = GrIntToScalar(pathBounds.width()); |
| 351 | GrScalar h = GrIntToScalar(pathBounds.height()); |
| 352 | GrRect maskRect = GrRect::MakeWH(w / texture->width(), |
| 353 | h / texture->height()); |
| 354 | const GrRect* srcRects[GrDrawState::kNumStages] = {NULL}; |
| 355 | srcRects[kPathMaskStage] = &maskRect; |
| 356 | stageMask |= 1 << kPathMaskStage; |
| 357 | GrRect dstRect = GrRect::MakeLTRB( |
| 358 | SK_Scalar1* pathBounds.fLeft, |
| 359 | SK_Scalar1* pathBounds.fTop, |
| 360 | SK_Scalar1* pathBounds.fRight, |
| 361 | SK_Scalar1* pathBounds.fBottom); |
| 362 | target->drawRect(dstRect, NULL, stageMask, srcRects, NULL); |
| 363 | target->drawState()->setTexture(kPathMaskStage, NULL); |
| 364 | if (GrIsFillInverted(fill)) { |
| 365 | draw_around_inv_path(target, stageMask, |
| 366 | clipBounds, pathBounds); |
| 367 | } |
| 368 | return true; |
| 369 | } |
| 370 | |
robertphillips@google.com | f4c2c52 | 2012-04-27 12:08:47 +0000 | [diff] [blame] | 371 | return false; |
| 372 | } |