robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +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 "GrClipMaskManager.h" |
| 10 | #include "GrGpu.h" |
| 11 | #include "GrRenderTarget.h" |
| 12 | #include "GrStencilBuffer.h" |
| 13 | #include "GrPathRenderer.h" |
robertphillips@google.com | a72eef3 | 2012-05-01 17:22:59 +0000 | [diff] [blame] | 14 | #include "GrPaint.h" |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 15 | #include "SkRasterClip.h" |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 16 | #include "GrAAConvexPathRenderer.h" |
| 17 | #include "GrAAHairLinePathRenderer.h" |
| 18 | |
| 19 | // TODO: move GrSWMaskHelper out of GrSoftwarePathRender.h & remove this include |
| 20 | #include "GrSoftwarePathRenderer.h" |
robertphillips@google.com | a72eef3 | 2012-05-01 17:22:59 +0000 | [diff] [blame] | 21 | |
| 22 | //#define GR_AA_CLIP 1 |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 23 | //#define GR_SW_CLIP 1 |
robertphillips@google.com | a72eef3 | 2012-05-01 17:22:59 +0000 | [diff] [blame] | 24 | |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 25 | //////////////////////////////////////////////////////////////////////////////// |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 26 | void ScissoringSettings::setupScissoring(GrGpu* gpu) { |
| 27 | if (!fEnableScissoring) { |
| 28 | gpu->disableScissor(); |
| 29 | return; |
| 30 | } |
| 31 | |
| 32 | gpu->enableScissoring(fScissorRect); |
| 33 | } |
| 34 | |
robertphillips@google.com | a72eef3 | 2012-05-01 17:22:59 +0000 | [diff] [blame] | 35 | namespace { |
| 36 | // set up the draw state to enable the aa clipping mask. Besides setting up the |
| 37 | // sampler matrix this also alters the vertex layout |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 38 | void setup_drawstate_aaclip(GrGpu* gpu, |
| 39 | GrTexture* result, |
robertphillips@google.com | 6623fcd | 2012-05-15 16:47:23 +0000 | [diff] [blame] | 40 | const GrIRect &bound) { |
robertphillips@google.com | a72eef3 | 2012-05-01 17:22:59 +0000 | [diff] [blame] | 41 | GrDrawState* drawState = gpu->drawState(); |
| 42 | GrAssert(drawState); |
| 43 | |
| 44 | static const int maskStage = GrPaint::kTotalStages+1; |
| 45 | |
| 46 | GrMatrix mat; |
| 47 | mat.setIDiv(result->width(), result->height()); |
robertphillips@google.com | 6623fcd | 2012-05-15 16:47:23 +0000 | [diff] [blame] | 48 | mat.preTranslate(SkIntToScalar(-bound.fLeft), SkIntToScalar(-bound.fTop)); |
robertphillips@google.com | a72eef3 | 2012-05-01 17:22:59 +0000 | [diff] [blame] | 49 | mat.preConcat(drawState->getViewMatrix()); |
| 50 | |
| 51 | drawState->sampler(maskStage)->reset(GrSamplerState::kClamp_WrapMode, |
| 52 | GrSamplerState::kNearest_Filter, |
| 53 | mat); |
| 54 | |
| 55 | drawState->setTexture(maskStage, result); |
| 56 | |
| 57 | // The AA clipping determination happens long after the geometry has |
| 58 | // been set up to draw. Here we directly enable the AA clip mask stage |
| 59 | gpu->addToVertexLayout( |
| 60 | GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(maskStage)); |
| 61 | } |
| 62 | |
robertphillips@google.com | 8a4fc40 | 2012-05-24 12:42:24 +0000 | [diff] [blame] | 63 | bool path_needs_SW_renderer(GrContext* context, |
| 64 | GrGpu* gpu, |
| 65 | const SkPath& path, |
| 66 | GrPathFill fill, |
| 67 | bool doAA) { |
| 68 | // last (false) parameter disallows use of the SW path renderer |
| 69 | return NULL == context->getPathRenderer(path, fill, gpu, doAA, false); |
| 70 | } |
| 71 | |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 72 | } |
| 73 | |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 74 | /* |
| 75 | * This method traverses the clip stack to see if the GrSoftwarePathRenderer |
| 76 | * will be used on any element. If so, it returns true to indicate that the |
| 77 | * entire clip should be rendered in SW and then uploaded en masse to the gpu. |
| 78 | */ |
| 79 | bool GrClipMaskManager::useSWOnlyPath(GrGpu* gpu, const GrClip& clipIn) { |
robertphillips@google.com | a3e5c63 | 2012-05-22 18:09:26 +0000 | [diff] [blame] | 80 | |
| 81 | if (!clipIn.requiresAA()) { |
| 82 | // The stencil buffer can handle this case |
| 83 | return false; |
| 84 | } |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 85 | |
robertphillips@google.com | 8a4fc40 | 2012-05-24 12:42:24 +0000 | [diff] [blame] | 86 | // TODO: generalize this function so that when |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 87 | // a clip gets complex enough it can just be done in SW regardless |
| 88 | // of whether it would invoke the GrSoftwarePathRenderer. |
| 89 | bool useSW = false; |
| 90 | |
| 91 | for (int i = 0; i < clipIn.getElementCount(); ++i) { |
| 92 | |
| 93 | if (SkRegion::kReplace_Op == clipIn.getOp(i)) { |
| 94 | // Everything before a replace op can be ignored so start |
| 95 | // afresh w.r.t. determining if any element uses the SW path |
| 96 | useSW = false; |
| 97 | } |
| 98 | |
robertphillips@google.com | f69a11b | 2012-06-15 13:58:07 +0000 | [diff] [blame^] | 99 | // rects can always be drawn directly w/o using the software path |
| 100 | // so only paths need to be checked |
| 101 | if (kPath_ClipType == clipIn.getElementType(i) && |
| 102 | path_needs_SW_renderer(this->getContext(), gpu, |
| 103 | clipIn.getPath(i), |
| 104 | clipIn.getPathFill(i), |
| 105 | clipIn.getDoAA(i))) { |
| 106 | useSW = true; |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 107 | } |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | return useSW; |
robertphillips@google.com | a72eef3 | 2012-05-01 17:22:59 +0000 | [diff] [blame] | 111 | } |
| 112 | |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 113 | //////////////////////////////////////////////////////////////////////////////// |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 114 | // sort out what kind of clip mask needs to be created: alpha, stencil, |
| 115 | // scissor, or entirely software |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 116 | bool GrClipMaskManager::createClipMask(GrGpu* gpu, |
| 117 | const GrClip& clipIn, |
| 118 | ScissoringSettings* scissorSettings) { |
| 119 | |
| 120 | GrAssert(scissorSettings); |
| 121 | |
| 122 | scissorSettings->fEnableScissoring = false; |
| 123 | fClipMaskInStencil = false; |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 124 | fClipMaskInAlpha = false; |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 125 | |
| 126 | GrDrawState* drawState = gpu->drawState(); |
| 127 | if (!drawState->isClipState()) { |
| 128 | return true; |
| 129 | } |
| 130 | |
| 131 | GrRenderTarget* rt = drawState->getRenderTarget(); |
| 132 | |
| 133 | // GrDrawTarget should have filtered this for us |
| 134 | GrAssert(NULL != rt); |
| 135 | |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 136 | #if GR_SW_CLIP |
robertphillips@google.com | a3e5c63 | 2012-05-22 18:09:26 +0000 | [diff] [blame] | 137 | // If MSAA is enabled we can do everything in the stencil buffer. |
| 138 | // Otherwise check if we should just create the entire clip mask |
| 139 | // in software (this will only happen if the clip mask is anti-aliased |
| 140 | // and too complex for the gpu to handle in its entirety) |
| 141 | if (0 == rt->numSamples() && useSWOnlyPath(gpu, clipIn)) { |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 142 | // The clip geometry is complex enough that it will be more |
| 143 | // efficient to create it entirely in software |
| 144 | GrTexture* result = NULL; |
robertphillips@google.com | 6623fcd | 2012-05-15 16:47:23 +0000 | [diff] [blame] | 145 | GrIRect bound; |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 146 | if (this->createSoftwareClipMask(gpu, clipIn, &result, &bound)) { |
| 147 | fClipMaskInAlpha = true; |
| 148 | |
| 149 | setup_drawstate_aaclip(gpu, result, bound); |
| 150 | return true; |
| 151 | } |
robertphillips@google.com | a3e5c63 | 2012-05-22 18:09:26 +0000 | [diff] [blame] | 152 | |
| 153 | // if SW clip mask creation fails fall through to the other |
| 154 | // two possible methods (bottoming out at stencil clipping) |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 155 | } |
robertphillips@google.com | a3e5c63 | 2012-05-22 18:09:26 +0000 | [diff] [blame] | 156 | #endif // GR_SW_CLIP |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 157 | |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 158 | #if GR_AA_CLIP |
| 159 | // If MSAA is enabled use the (faster) stencil path for AA clipping |
| 160 | // otherwise the alpha clip mask is our only option |
robertphillips@google.com | a3e5c63 | 2012-05-22 18:09:26 +0000 | [diff] [blame] | 161 | if (0 == rt->numSamples() && clipIn.requiresAA()) { |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 162 | // Since we are going to create a destination texture of the correct |
| 163 | // size for the mask (rather than being bound by the size of the |
| 164 | // render target) we aren't going to use scissoring like the stencil |
| 165 | // path does (see scissorSettings below) |
robertphillips@google.com | a72eef3 | 2012-05-01 17:22:59 +0000 | [diff] [blame] | 166 | GrTexture* result = NULL; |
robertphillips@google.com | 6623fcd | 2012-05-15 16:47:23 +0000 | [diff] [blame] | 167 | GrIRect bound; |
robertphillips@google.com | a72eef3 | 2012-05-01 17:22:59 +0000 | [diff] [blame] | 168 | if (this->createAlphaClipMask(gpu, clipIn, &result, &bound)) { |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 169 | fClipMaskInAlpha = true; |
robertphillips@google.com | a72eef3 | 2012-05-01 17:22:59 +0000 | [diff] [blame] | 170 | |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 171 | setup_drawstate_aaclip(gpu, result, bound); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 172 | return true; |
| 173 | } |
| 174 | |
| 175 | // if alpha clip mask creation fails fall through to the stencil |
| 176 | // buffer method |
| 177 | } |
| 178 | #endif // GR_AA_CLIP |
| 179 | |
robertphillips@google.com | 5acc0e3 | 2012-05-17 12:01:02 +0000 | [diff] [blame] | 180 | // Either a hard (stencil buffer) clip was explicitly requested or |
| 181 | // an antialiased clip couldn't be created. In either case, free up |
| 182 | // the texture in the antialiased mask cache. |
| 183 | // TODO: this may require more investigation. Ganesh performs a lot of |
robertphillips@google.com | a3e5c63 | 2012-05-22 18:09:26 +0000 | [diff] [blame] | 184 | // utility draws (e.g., clears, InOrderDrawBuffer playbacks) that hit |
| 185 | // the stencil buffer path. These may be "incorrectly" clearing the |
robertphillips@google.com | 5acc0e3 | 2012-05-17 12:01:02 +0000 | [diff] [blame] | 186 | // AA cache. |
| 187 | fAACache.reset(); |
| 188 | |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 189 | GrRect bounds; |
| 190 | GrRect rtRect; |
| 191 | rtRect.setLTRB(0, 0, |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 192 | GrIntToScalar(rt->width()), GrIntToScalar(rt->height())); |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 193 | if (clipIn.hasConservativeBounds()) { |
| 194 | bounds = clipIn.getConservativeBounds(); |
| 195 | if (!bounds.intersect(rtRect)) { |
| 196 | bounds.setEmpty(); |
| 197 | } |
| 198 | } else { |
| 199 | bounds = rtRect; |
| 200 | } |
| 201 | |
| 202 | bounds.roundOut(&scissorSettings->fScissorRect); |
| 203 | if (scissorSettings->fScissorRect.isEmpty()) { |
| 204 | scissorSettings->fScissorRect.setLTRB(0,0,0,0); |
| 205 | // TODO: I think we can do an early exit here - after refactoring try: |
| 206 | // set fEnableScissoring to true but leave fClipMaskInStencil false |
| 207 | // and return - everything is going to be scissored away anyway! |
| 208 | } |
| 209 | scissorSettings->fEnableScissoring = true; |
| 210 | |
| 211 | // use the stencil clip if we can't represent the clip as a rectangle. |
| 212 | fClipMaskInStencil = !clipIn.isRect() && !clipIn.isEmpty() && |
| 213 | !bounds.isEmpty(); |
| 214 | |
| 215 | if (fClipMaskInStencil) { |
| 216 | return this->createStencilClipMask(gpu, clipIn, bounds, scissorSettings); |
| 217 | } |
| 218 | |
| 219 | return true; |
| 220 | } |
| 221 | |
| 222 | #define VISUALIZE_COMPLEX_CLIP 0 |
| 223 | |
| 224 | #if VISUALIZE_COMPLEX_CLIP |
| 225 | #include "GrRandom.h" |
| 226 | GrRandom gRandom; |
| 227 | #define SET_RANDOM_COLOR drawState->setColor(0xff000000 | gRandom.nextU()); |
| 228 | #else |
| 229 | #define SET_RANDOM_COLOR |
| 230 | #endif |
| 231 | |
| 232 | namespace { |
robertphillips@google.com | 6623fcd | 2012-05-15 16:47:23 +0000 | [diff] [blame] | 233 | /** |
| 234 | * Does "container" contain "containee"? If either is empty then |
| 235 | * no containment is possible. |
| 236 | */ |
| 237 | bool contains(const SkRect& container, const SkIRect& containee) { |
| 238 | return !containee.isEmpty() && !container.isEmpty() && |
| 239 | container.fLeft <= SkIntToScalar(containee.fLeft) && |
| 240 | container.fTop <= SkIntToScalar(containee.fTop) && |
| 241 | container.fRight >= SkIntToScalar(containee.fRight) && |
| 242 | container.fBottom >= SkIntToScalar(containee.fBottom); |
| 243 | } |
| 244 | |
| 245 | |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 246 | //////////////////////////////////////////////////////////////////////////////// |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 247 | // determines how many elements at the head of the clip can be skipped and |
| 248 | // whether the initial clear should be to the inside- or outside-the-clip value, |
| 249 | // and what op should be used to draw the first element that isn't skipped. |
| 250 | int process_initial_clip_elements(const GrClip& clip, |
robertphillips@google.com | 6623fcd | 2012-05-15 16:47:23 +0000 | [diff] [blame] | 251 | const GrIRect& bounds, |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 252 | bool* clearToInside, |
robertphillips@google.com | 0f191f3 | 2012-04-25 15:23:36 +0000 | [diff] [blame] | 253 | SkRegion::Op* startOp) { |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 254 | |
| 255 | // logically before the first element of the clip stack is |
| 256 | // processed the clip is entirely open. However, depending on the |
| 257 | // first set op we may prefer to clear to 0 for performance. We may |
| 258 | // also be able to skip the initial clip paths/rects. We loop until |
| 259 | // we cannot skip an element. |
| 260 | int curr; |
| 261 | bool done = false; |
| 262 | *clearToInside = true; |
| 263 | int count = clip.getElementCount(); |
| 264 | |
| 265 | for (curr = 0; curr < count && !done; ++curr) { |
| 266 | switch (clip.getOp(curr)) { |
robertphillips@google.com | 0f191f3 | 2012-04-25 15:23:36 +0000 | [diff] [blame] | 267 | case SkRegion::kReplace_Op: |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 268 | // replace ignores everything previous |
robertphillips@google.com | 0f191f3 | 2012-04-25 15:23:36 +0000 | [diff] [blame] | 269 | *startOp = SkRegion::kReplace_Op; |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 270 | *clearToInside = false; |
| 271 | done = true; |
| 272 | break; |
robertphillips@google.com | 0f191f3 | 2012-04-25 15:23:36 +0000 | [diff] [blame] | 273 | case SkRegion::kIntersect_Op: |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 274 | // if this element contains the entire bounds then we |
| 275 | // can skip it. |
| 276 | if (kRect_ClipType == clip.getElementType(curr) |
robertphillips@google.com | 6623fcd | 2012-05-15 16:47:23 +0000 | [diff] [blame] | 277 | && contains(clip.getRect(curr), bounds)) { |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 278 | break; |
| 279 | } |
| 280 | // if everything is initially clearToInside then intersect is |
| 281 | // same as clear to 0 and treat as a replace. Otherwise, |
| 282 | // set stays empty. |
| 283 | if (*clearToInside) { |
robertphillips@google.com | 0f191f3 | 2012-04-25 15:23:36 +0000 | [diff] [blame] | 284 | *startOp = SkRegion::kReplace_Op; |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 285 | *clearToInside = false; |
| 286 | done = true; |
| 287 | } |
| 288 | break; |
| 289 | // we can skip a leading union. |
robertphillips@google.com | 0f191f3 | 2012-04-25 15:23:36 +0000 | [diff] [blame] | 290 | case SkRegion::kUnion_Op: |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 291 | // if everything is initially outside then union is |
| 292 | // same as replace. Otherwise, every pixel is still |
| 293 | // clearToInside |
| 294 | if (!*clearToInside) { |
robertphillips@google.com | 0f191f3 | 2012-04-25 15:23:36 +0000 | [diff] [blame] | 295 | *startOp = SkRegion::kReplace_Op; |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 296 | done = true; |
| 297 | } |
| 298 | break; |
robertphillips@google.com | 0f191f3 | 2012-04-25 15:23:36 +0000 | [diff] [blame] | 299 | case SkRegion::kXOR_Op: |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 300 | // xor is same as difference or replace both of which |
| 301 | // can be 1-pass instead of 2 for xor. |
| 302 | if (*clearToInside) { |
robertphillips@google.com | 0f191f3 | 2012-04-25 15:23:36 +0000 | [diff] [blame] | 303 | *startOp = SkRegion::kDifference_Op; |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 304 | } else { |
robertphillips@google.com | 0f191f3 | 2012-04-25 15:23:36 +0000 | [diff] [blame] | 305 | *startOp = SkRegion::kReplace_Op; |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 306 | } |
| 307 | done = true; |
| 308 | break; |
robertphillips@google.com | 0f191f3 | 2012-04-25 15:23:36 +0000 | [diff] [blame] | 309 | case SkRegion::kDifference_Op: |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 310 | // if all pixels are clearToInside then we have to process the |
| 311 | // difference, otherwise it has no effect and all pixels |
| 312 | // remain outside. |
| 313 | if (*clearToInside) { |
robertphillips@google.com | 0f191f3 | 2012-04-25 15:23:36 +0000 | [diff] [blame] | 314 | *startOp = SkRegion::kDifference_Op; |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 315 | done = true; |
| 316 | } |
| 317 | break; |
robertphillips@google.com | 0f191f3 | 2012-04-25 15:23:36 +0000 | [diff] [blame] | 318 | case SkRegion::kReverseDifference_Op: |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 319 | // if all pixels are clearToInside then reverse difference |
| 320 | // produces empty set. Otherise it is same as replace |
| 321 | if (*clearToInside) { |
| 322 | *clearToInside = false; |
| 323 | } else { |
robertphillips@google.com | 0f191f3 | 2012-04-25 15:23:36 +0000 | [diff] [blame] | 324 | *startOp = SkRegion::kReplace_Op; |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 325 | done = true; |
| 326 | } |
| 327 | break; |
| 328 | default: |
| 329 | GrCrash("Unknown set op."); |
| 330 | } |
| 331 | } |
| 332 | return done ? curr-1 : count; |
| 333 | } |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 334 | |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 335 | } |
| 336 | |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 337 | |
| 338 | namespace { |
| 339 | |
| 340 | //////////////////////////////////////////////////////////////////////////////// |
| 341 | // set up the OpenGL blend function to perform the specified |
| 342 | // boolean operation for alpha clip mask creation |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 343 | void setup_boolean_blendcoeffs(GrDrawState* drawState, SkRegion::Op op) { |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 344 | |
| 345 | switch (op) { |
| 346 | case SkRegion::kReplace_Op: |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 347 | drawState->setBlendFunc(kOne_GrBlendCoeff, kZero_GrBlendCoeff); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 348 | break; |
| 349 | case SkRegion::kIntersect_Op: |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 350 | drawState->setBlendFunc(kDC_GrBlendCoeff, kZero_GrBlendCoeff); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 351 | break; |
| 352 | case SkRegion::kUnion_Op: |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 353 | drawState->setBlendFunc(kOne_GrBlendCoeff, kISC_GrBlendCoeff); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 354 | break; |
| 355 | case SkRegion::kXOR_Op: |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 356 | drawState->setBlendFunc(kIDC_GrBlendCoeff, kISC_GrBlendCoeff); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 357 | break; |
| 358 | case SkRegion::kDifference_Op: |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 359 | drawState->setBlendFunc(kZero_GrBlendCoeff, kISC_GrBlendCoeff); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 360 | break; |
| 361 | case SkRegion::kReverseDifference_Op: |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 362 | drawState->setBlendFunc(kIDC_GrBlendCoeff, kZero_GrBlendCoeff); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 363 | break; |
| 364 | default: |
| 365 | GrAssert(false); |
| 366 | break; |
| 367 | } |
| 368 | } |
| 369 | |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 370 | //////////////////////////////////////////////////////////////////////////////// |
robertphillips@google.com | 2c75681 | 2012-05-22 20:28:23 +0000 | [diff] [blame] | 371 | bool draw_path(GrContext* context, |
| 372 | GrGpu* gpu, |
| 373 | const SkPath& path, |
| 374 | GrPathFill fill, |
| 375 | bool doAA) { |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 376 | |
robertphillips@google.com | 72176b2 | 2012-05-23 13:19:12 +0000 | [diff] [blame] | 377 | GrPathRenderer* pr = context->getPathRenderer(path, fill, gpu, doAA, true); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 378 | if (NULL == pr) { |
| 379 | return false; |
| 380 | } |
| 381 | |
| 382 | pr->drawPath(path, fill, NULL, gpu, 0, doAA); |
| 383 | return true; |
| 384 | } |
robertphillips@google.com | 72176b2 | 2012-05-23 13:19:12 +0000 | [diff] [blame] | 385 | |
| 386 | } |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 387 | |
| 388 | //////////////////////////////////////////////////////////////////////////////// |
| 389 | bool GrClipMaskManager::drawClipShape(GrGpu* gpu, |
| 390 | GrTexture* target, |
| 391 | const GrClip& clipIn, |
| 392 | int index) { |
| 393 | GrDrawState* drawState = gpu->drawState(); |
| 394 | GrAssert(NULL != drawState); |
| 395 | |
| 396 | drawState->setRenderTarget(target->asRenderTarget()); |
| 397 | |
| 398 | if (kRect_ClipType == clipIn.getElementType(index)) { |
| 399 | if (clipIn.getDoAA(index)) { |
robertphillips@google.com | f69a11b | 2012-06-15 13:58:07 +0000 | [diff] [blame^] | 400 | getContext()->getAARectRenderer()->fillAARect(gpu, gpu, |
| 401 | clipIn.getRect(index), |
| 402 | true); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 403 | } else { |
| 404 | gpu->drawSimpleRect(clipIn.getRect(index), NULL, 0); |
| 405 | } |
| 406 | } else { |
robertphillips@google.com | 2c75681 | 2012-05-22 20:28:23 +0000 | [diff] [blame] | 407 | return draw_path(this->getContext(), gpu, |
| 408 | clipIn.getPath(index), |
| 409 | clipIn.getPathFill(index), |
| 410 | clipIn.getDoAA(index)); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 411 | } |
| 412 | return true; |
| 413 | } |
| 414 | |
| 415 | void GrClipMaskManager::drawTexture(GrGpu* gpu, |
| 416 | GrTexture* target, |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 417 | GrTexture* texture) { |
| 418 | GrDrawState* drawState = gpu->drawState(); |
| 419 | GrAssert(NULL != drawState); |
| 420 | |
| 421 | // no AA here since it is encoded in the texture |
| 422 | drawState->setRenderTarget(target->asRenderTarget()); |
| 423 | |
| 424 | GrMatrix sampleM; |
| 425 | sampleM.setIDiv(texture->width(), texture->height()); |
| 426 | drawState->setTexture(0, texture); |
| 427 | |
| 428 | drawState->sampler(0)->reset(GrSamplerState::kClamp_WrapMode, |
| 429 | GrSamplerState::kNearest_Filter, |
| 430 | sampleM); |
| 431 | |
robertphillips@google.com | f105b10 | 2012-05-14 12:18:26 +0000 | [diff] [blame] | 432 | GrRect rect = GrRect::MakeWH(SkIntToScalar(target->width()), |
| 433 | SkIntToScalar(target->height())); |
| 434 | |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 435 | gpu->drawSimpleRect(rect, NULL, 1 << 0); |
| 436 | |
| 437 | drawState->setTexture(0, NULL); |
| 438 | } |
| 439 | |
| 440 | namespace { |
| 441 | |
| 442 | void clear(GrGpu* gpu, |
| 443 | GrTexture* target, |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 444 | GrColor color) { |
| 445 | GrDrawState* drawState = gpu->drawState(); |
| 446 | GrAssert(NULL != drawState); |
| 447 | |
| 448 | // zap entire target to specified color |
| 449 | drawState->setRenderTarget(target->asRenderTarget()); |
| 450 | gpu->clear(NULL, color); |
| 451 | } |
| 452 | |
robertphillips@google.com | f105b10 | 2012-05-14 12:18:26 +0000 | [diff] [blame] | 453 | } |
| 454 | |
robertphillips@google.com | 6d62df4 | 2012-05-07 18:07:36 +0000 | [diff] [blame] | 455 | // get a texture to act as a temporary buffer for AA clip boolean operations |
| 456 | // TODO: given the expense of createTexture we may want to just cache this too |
robertphillips@google.com | 6623fcd | 2012-05-15 16:47:23 +0000 | [diff] [blame] | 457 | void GrClipMaskManager::getTemp(const GrIRect& bounds, |
robertphillips@google.com | f105b10 | 2012-05-14 12:18:26 +0000 | [diff] [blame] | 458 | GrAutoScratchTexture* temp) { |
| 459 | if (NULL != temp->texture()) { |
robertphillips@google.com | 6d62df4 | 2012-05-07 18:07:36 +0000 | [diff] [blame] | 460 | // we've already allocated the temp texture |
| 461 | return; |
| 462 | } |
| 463 | |
robertphillips@google.com | 75b3c96 | 2012-06-07 12:08:45 +0000 | [diff] [blame] | 464 | GrTextureDesc desc; |
| 465 | desc.fFlags = kRenderTarget_GrTextureFlagBit|kNoStencil_GrTextureFlagBit; |
| 466 | desc.fWidth = bounds.width(); |
| 467 | desc.fHeight = bounds.height(); |
| 468 | desc.fConfig = kAlpha_8_GrPixelConfig; |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 469 | |
robertphillips@google.com | 2c75681 | 2012-05-22 20:28:23 +0000 | [diff] [blame] | 470 | temp->set(this->getContext(), desc); |
robertphillips@google.com | 6d62df4 | 2012-05-07 18:07:36 +0000 | [diff] [blame] | 471 | } |
| 472 | |
robertphillips@google.com | f105b10 | 2012-05-14 12:18:26 +0000 | [diff] [blame] | 473 | |
| 474 | void GrClipMaskManager::setupCache(const GrClip& clipIn, |
robertphillips@google.com | 6623fcd | 2012-05-15 16:47:23 +0000 | [diff] [blame] | 475 | const GrIRect& bounds) { |
robertphillips@google.com | f105b10 | 2012-05-14 12:18:26 +0000 | [diff] [blame] | 476 | // Since we are setting up the cache we know the last lookup was a miss |
| 477 | // Free up the currently cached mask so it can be reused |
| 478 | fAACache.reset(); |
| 479 | |
robertphillips@google.com | 75b3c96 | 2012-06-07 12:08:45 +0000 | [diff] [blame] | 480 | GrTextureDesc desc; |
| 481 | desc.fFlags = kRenderTarget_GrTextureFlagBit|kNoStencil_GrTextureFlagBit; |
| 482 | desc.fWidth = bounds.width(); |
| 483 | desc.fHeight = bounds.height(); |
| 484 | desc.fConfig = kAlpha_8_GrPixelConfig; |
robertphillips@google.com | f105b10 | 2012-05-14 12:18:26 +0000 | [diff] [blame] | 485 | |
| 486 | fAACache.acquireMask(clipIn, desc, bounds); |
robertphillips@google.com | 6d62df4 | 2012-05-07 18:07:36 +0000 | [diff] [blame] | 487 | } |
| 488 | |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 489 | //////////////////////////////////////////////////////////////////////////////// |
| 490 | // Shared preamble between gpu and SW-only AA clip mask creation paths. |
| 491 | // Handles caching, determination of clip mask bound & allocation (if needed) |
| 492 | // of the result texture |
| 493 | // Returns true if there is no more work to be done (i.e., we got a cache hit) |
| 494 | bool GrClipMaskManager::clipMaskPreamble(GrGpu* gpu, |
| 495 | const GrClip& clipIn, |
| 496 | GrTexture** result, |
robertphillips@google.com | 6623fcd | 2012-05-15 16:47:23 +0000 | [diff] [blame] | 497 | GrIRect *resultBounds) { |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 498 | GrDrawState* origDrawState = gpu->drawState(); |
| 499 | GrAssert(origDrawState->isClipState()); |
| 500 | |
| 501 | GrRenderTarget* rt = origDrawState->getRenderTarget(); |
| 502 | GrAssert(NULL != rt); |
| 503 | |
| 504 | GrRect rtRect; |
| 505 | rtRect.setLTRB(0, 0, |
| 506 | GrIntToScalar(rt->width()), GrIntToScalar(rt->height())); |
| 507 | |
| 508 | // unlike the stencil path the alpha path is not bound to the size of the |
| 509 | // render target - determine the minimum size required for the mask |
| 510 | GrRect bounds; |
| 511 | |
| 512 | if (clipIn.hasConservativeBounds()) { |
| 513 | bounds = clipIn.getConservativeBounds(); |
| 514 | if (!bounds.intersect(rtRect)) { |
| 515 | // the mask will be empty in this case |
| 516 | GrAssert(false); |
| 517 | bounds.setEmpty(); |
| 518 | } |
| 519 | } else { |
| 520 | // still locked to the size of the render target |
| 521 | bounds = rtRect; |
| 522 | } |
| 523 | |
robertphillips@google.com | 6623fcd | 2012-05-15 16:47:23 +0000 | [diff] [blame] | 524 | GrIRect intBounds; |
| 525 | bounds.roundOut(&intBounds); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 526 | |
| 527 | // need to outset a pixel since the standard bounding box computation |
| 528 | // path doesn't leave any room for antialiasing (esp. w.r.t. rects) |
robertphillips@google.com | 6623fcd | 2012-05-15 16:47:23 +0000 | [diff] [blame] | 529 | intBounds.outset(1, 1); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 530 | |
robertphillips@google.com | a72eef3 | 2012-05-01 17:22:59 +0000 | [diff] [blame] | 531 | // TODO: make sure we don't outset if bounds are still 0,0 @ min |
| 532 | |
robertphillips@google.com | 8fff356 | 2012-05-11 12:53:50 +0000 | [diff] [blame] | 533 | if (fAACache.canReuse(clipIn, |
robertphillips@google.com | 6623fcd | 2012-05-15 16:47:23 +0000 | [diff] [blame] | 534 | intBounds.width(), |
| 535 | intBounds.height())) { |
robertphillips@google.com | 8fff356 | 2012-05-11 12:53:50 +0000 | [diff] [blame] | 536 | *result = fAACache.getLastMask(); |
| 537 | fAACache.getLastBound(resultBounds); |
| 538 | return true; |
| 539 | } |
| 540 | |
robertphillips@google.com | 6623fcd | 2012-05-15 16:47:23 +0000 | [diff] [blame] | 541 | this->setupCache(clipIn, intBounds); |
robertphillips@google.com | f105b10 | 2012-05-14 12:18:26 +0000 | [diff] [blame] | 542 | |
robertphillips@google.com | 6623fcd | 2012-05-15 16:47:23 +0000 | [diff] [blame] | 543 | *resultBounds = intBounds; |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 544 | return false; |
| 545 | } |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 546 | |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 547 | //////////////////////////////////////////////////////////////////////////////// |
| 548 | // Create a 8-bit clip mask in alpha |
| 549 | bool GrClipMaskManager::createAlphaClipMask(GrGpu* gpu, |
| 550 | const GrClip& clipIn, |
| 551 | GrTexture** result, |
robertphillips@google.com | 6623fcd | 2012-05-15 16:47:23 +0000 | [diff] [blame] | 552 | GrIRect *resultBounds) { |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 553 | |
robertphillips@google.com | f105b10 | 2012-05-14 12:18:26 +0000 | [diff] [blame] | 554 | if (this->clipMaskPreamble(gpu, clipIn, result, resultBounds)) { |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 555 | return true; |
| 556 | } |
| 557 | |
robertphillips@google.com | f105b10 | 2012-05-14 12:18:26 +0000 | [diff] [blame] | 558 | GrTexture* accum = fAACache.getLastMask(); |
robertphillips@google.com | 6d62df4 | 2012-05-07 18:07:36 +0000 | [diff] [blame] | 559 | if (NULL == accum) { |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 560 | fClipMaskInAlpha = false; |
robertphillips@google.com | f105b10 | 2012-05-14 12:18:26 +0000 | [diff] [blame] | 561 | fAACache.reset(); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 562 | return false; |
| 563 | } |
| 564 | |
| 565 | GrDrawTarget::AutoStateRestore asr(gpu, GrDrawTarget::kReset_ASRInit); |
| 566 | GrDrawState* drawState = gpu->drawState(); |
| 567 | |
| 568 | GrDrawTarget::AutoGeometryPush agp(gpu); |
| 569 | |
| 570 | int count = clipIn.getElementCount(); |
| 571 | |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 572 | if (0 != resultBounds->fTop || 0 != resultBounds->fLeft) { |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 573 | // if we were able to trim down the size of the mask we need to |
| 574 | // offset the paths & rects that will be used to compute it |
| 575 | GrMatrix m; |
| 576 | |
robertphillips@google.com | 6623fcd | 2012-05-15 16:47:23 +0000 | [diff] [blame] | 577 | m.setTranslate(SkIntToScalar(-resultBounds->fLeft), |
| 578 | SkIntToScalar(-resultBounds->fTop)); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 579 | |
robertphillips@google.com | 6d62df4 | 2012-05-07 18:07:36 +0000 | [diff] [blame] | 580 | drawState->setViewMatrix(m); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | bool clearToInside; |
| 584 | SkRegion::Op startOp = SkRegion::kReplace_Op; // suppress warning |
| 585 | int start = process_initial_clip_elements(clipIn, |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 586 | *resultBounds, |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 587 | &clearToInside, |
| 588 | &startOp); |
| 589 | |
robertphillips@google.com | 6d62df4 | 2012-05-07 18:07:36 +0000 | [diff] [blame] | 590 | clear(gpu, accum, clearToInside ? 0xffffffff : 0x00000000); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 591 | |
robertphillips@google.com | f105b10 | 2012-05-14 12:18:26 +0000 | [diff] [blame] | 592 | GrAutoScratchTexture temp; |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 593 | |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 594 | // walk through each clip element and perform its set op |
| 595 | for (int c = start; c < count; ++c) { |
| 596 | |
| 597 | SkRegion::Op op = (c == start) ? startOp : clipIn.getOp(c); |
| 598 | |
| 599 | if (SkRegion::kReplace_Op == op) { |
| 600 | // TODO: replace is actually a lot faster then intersection |
| 601 | // for this path - refactor the stencil path so it can handle |
| 602 | // replace ops and alter GrClip to allow them through |
| 603 | |
| 604 | // clear the accumulator and draw the new object directly into it |
robertphillips@google.com | 6d62df4 | 2012-05-07 18:07:36 +0000 | [diff] [blame] | 605 | clear(gpu, accum, 0x00000000); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 606 | |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 607 | setup_boolean_blendcoeffs(drawState, op); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 608 | this->drawClipShape(gpu, accum, clipIn, c); |
| 609 | |
| 610 | } else if (SkRegion::kReverseDifference_Op == op || |
| 611 | SkRegion::kIntersect_Op == op) { |
| 612 | // there is no point in intersecting a screen filling rectangle. |
| 613 | if (SkRegion::kIntersect_Op == op && |
| 614 | kRect_ClipType == clipIn.getElementType(c) && |
robertphillips@google.com | 6623fcd | 2012-05-15 16:47:23 +0000 | [diff] [blame] | 615 | contains(clipIn.getRect(c), *resultBounds)) { |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 616 | continue; |
| 617 | } |
| 618 | |
robertphillips@google.com | f105b10 | 2012-05-14 12:18:26 +0000 | [diff] [blame] | 619 | getTemp(*resultBounds, &temp); |
| 620 | if (NULL == temp.texture()) { |
robertphillips@google.com | 6d62df4 | 2012-05-07 18:07:36 +0000 | [diff] [blame] | 621 | fClipMaskInAlpha = false; |
robertphillips@google.com | f105b10 | 2012-05-14 12:18:26 +0000 | [diff] [blame] | 622 | fAACache.reset(); |
robertphillips@google.com | 6d62df4 | 2012-05-07 18:07:36 +0000 | [diff] [blame] | 623 | return false; |
| 624 | } |
| 625 | |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 626 | // clear the temp target & draw into it |
robertphillips@google.com | f105b10 | 2012-05-14 12:18:26 +0000 | [diff] [blame] | 627 | clear(gpu, temp.texture(), 0x00000000); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 628 | |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 629 | setup_boolean_blendcoeffs(drawState, SkRegion::kReplace_Op); |
robertphillips@google.com | f105b10 | 2012-05-14 12:18:26 +0000 | [diff] [blame] | 630 | this->drawClipShape(gpu, temp.texture(), clipIn, c); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 631 | |
| 632 | // TODO: rather than adding these two translations here |
| 633 | // compute the bounding box needed to render the texture |
| 634 | // into temp |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 635 | if (0 != resultBounds->fTop || 0 != resultBounds->fLeft) { |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 636 | GrMatrix m; |
| 637 | |
robertphillips@google.com | 6623fcd | 2012-05-15 16:47:23 +0000 | [diff] [blame] | 638 | m.setTranslate(SkIntToScalar(resultBounds->fLeft), |
| 639 | SkIntToScalar(resultBounds->fTop)); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 640 | |
| 641 | drawState->preConcatViewMatrix(m); |
| 642 | } |
| 643 | |
| 644 | // Now draw into the accumulator using the real operation |
| 645 | // and the temp buffer as a texture |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 646 | setup_boolean_blendcoeffs(drawState, op); |
robertphillips@google.com | f105b10 | 2012-05-14 12:18:26 +0000 | [diff] [blame] | 647 | this->drawTexture(gpu, accum, temp.texture()); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 648 | |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 649 | if (0 != resultBounds->fTop || 0 != resultBounds->fLeft) { |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 650 | GrMatrix m; |
| 651 | |
robertphillips@google.com | 6623fcd | 2012-05-15 16:47:23 +0000 | [diff] [blame] | 652 | m.setTranslate(SkIntToScalar(-resultBounds->fLeft), |
| 653 | SkIntToScalar(-resultBounds->fTop)); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 654 | |
| 655 | drawState->preConcatViewMatrix(m); |
| 656 | } |
| 657 | |
| 658 | } else { |
| 659 | // all the remaining ops can just be directly draw into |
| 660 | // the accumulation buffer |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 661 | setup_boolean_blendcoeffs(drawState, op); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 662 | this->drawClipShape(gpu, accum, clipIn, c); |
| 663 | } |
| 664 | } |
| 665 | |
robertphillips@google.com | a72eef3 | 2012-05-01 17:22:59 +0000 | [diff] [blame] | 666 | *result = accum; |
robertphillips@google.com | 6d62df4 | 2012-05-07 18:07:36 +0000 | [diff] [blame] | 667 | |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 668 | return true; |
| 669 | } |
| 670 | |
| 671 | //////////////////////////////////////////////////////////////////////////////// |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 672 | // Create a 1-bit clip mask in the stencil buffer |
| 673 | bool GrClipMaskManager::createStencilClipMask(GrGpu* gpu, |
| 674 | const GrClip& clipIn, |
| 675 | const GrRect& bounds, |
| 676 | ScissoringSettings* scissorSettings) { |
| 677 | |
| 678 | GrAssert(fClipMaskInStencil); |
| 679 | |
| 680 | GrDrawState* drawState = gpu->drawState(); |
| 681 | GrAssert(drawState->isClipState()); |
| 682 | |
| 683 | GrRenderTarget* rt = drawState->getRenderTarget(); |
| 684 | GrAssert(NULL != rt); |
| 685 | |
| 686 | // TODO: dynamically attach a SB when needed. |
| 687 | GrStencilBuffer* stencilBuffer = rt->getStencilBuffer(); |
| 688 | if (NULL == stencilBuffer) { |
| 689 | return false; |
| 690 | } |
| 691 | |
| 692 | if (stencilBuffer->mustRenderClip(clipIn, rt->width(), rt->height())) { |
| 693 | |
| 694 | stencilBuffer->setLastClip(clipIn, rt->width(), rt->height()); |
| 695 | |
| 696 | // we set the current clip to the bounds so that our recursive |
| 697 | // draws are scissored to them. We use the copy of the complex clip |
| 698 | // we just stashed on the SB to render from. We set it back after |
| 699 | // we finish drawing it into the stencil. |
| 700 | const GrClip& clipCopy = stencilBuffer->getLastClip(); |
| 701 | gpu->setClip(GrClip(bounds)); |
| 702 | |
| 703 | GrDrawTarget::AutoStateRestore asr(gpu, GrDrawTarget::kReset_ASRInit); |
| 704 | drawState = gpu->drawState(); |
| 705 | drawState->setRenderTarget(rt); |
| 706 | GrDrawTarget::AutoGeometryPush agp(gpu); |
| 707 | |
| 708 | gpu->disableScissor(); |
| 709 | #if !VISUALIZE_COMPLEX_CLIP |
| 710 | drawState->enableState(GrDrawState::kNoColorWrites_StateBit); |
| 711 | #endif |
| 712 | |
| 713 | int count = clipCopy.getElementCount(); |
| 714 | int clipBit = stencilBuffer->bits(); |
| 715 | SkASSERT((clipBit <= 16) && |
| 716 | "Ganesh only handles 16b or smaller stencil buffers"); |
| 717 | clipBit = (1 << (clipBit-1)); |
| 718 | |
robertphillips@google.com | 6623fcd | 2012-05-15 16:47:23 +0000 | [diff] [blame] | 719 | GrIRect rtRect = GrIRect::MakeWH(rt->width(), rt->height()); |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 720 | |
| 721 | bool clearToInside; |
robertphillips@google.com | 0f191f3 | 2012-04-25 15:23:36 +0000 | [diff] [blame] | 722 | SkRegion::Op startOp = SkRegion::kReplace_Op; // suppress warning |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 723 | int start = process_initial_clip_elements(clipCopy, |
| 724 | rtRect, |
| 725 | &clearToInside, |
| 726 | &startOp); |
| 727 | |
| 728 | gpu->clearStencilClip(scissorSettings->fScissorRect, clearToInside); |
| 729 | |
| 730 | // walk through each clip element and perform its set op |
| 731 | // with the existing clip. |
| 732 | for (int c = start; c < count; ++c) { |
| 733 | GrPathFill fill; |
| 734 | bool fillInverted; |
| 735 | // enabled at bottom of loop |
| 736 | drawState->disableState(GrGpu::kModifyStencilClip_StateBit); |
| 737 | |
| 738 | bool canRenderDirectToStencil; // can the clip element be drawn |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 739 | // directly to the stencil buffer |
| 740 | // with a non-inverted fill rule |
| 741 | // without extra passes to |
| 742 | // resolve in/out status. |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 743 | |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 744 | SkRegion::Op op = (c == start) ? startOp : clipCopy.getOp(c); |
| 745 | |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 746 | GrPathRenderer* pr = NULL; |
bsalomon@google.com | 8d033a1 | 2012-04-27 15:52:53 +0000 | [diff] [blame] | 747 | const SkPath* clipPath = NULL; |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 748 | if (kRect_ClipType == clipCopy.getElementType(c)) { |
| 749 | canRenderDirectToStencil = true; |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 750 | fill = kEvenOdd_GrPathFill; |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 751 | fillInverted = false; |
| 752 | // there is no point in intersecting a screen filling |
| 753 | // rectangle. |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 754 | if (SkRegion::kIntersect_Op == op && |
robertphillips@google.com | 6623fcd | 2012-05-15 16:47:23 +0000 | [diff] [blame] | 755 | contains(clipCopy.getRect(c), rtRect)) { |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 756 | continue; |
| 757 | } |
| 758 | } else { |
| 759 | fill = clipCopy.getPathFill(c); |
| 760 | fillInverted = GrIsFillInverted(fill); |
| 761 | fill = GrNonInvertedFill(fill); |
| 762 | clipPath = &clipCopy.getPath(c); |
robertphillips@google.com | 2c75681 | 2012-05-22 20:28:23 +0000 | [diff] [blame] | 763 | pr = this->getContext()->getPathRenderer(*clipPath, |
robertphillips@google.com | 72176b2 | 2012-05-23 13:19:12 +0000 | [diff] [blame] | 764 | fill, gpu, false, |
| 765 | true); |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 766 | if (NULL == pr) { |
| 767 | fClipMaskInStencil = false; |
| 768 | gpu->setClip(clipCopy); // restore to the original |
| 769 | return false; |
| 770 | } |
| 771 | canRenderDirectToStencil = |
| 772 | !pr->requiresStencilPass(*clipPath, fill, gpu); |
| 773 | } |
| 774 | |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 775 | int passes; |
| 776 | GrStencilSettings stencilSettings[GrStencilSettings::kMaxStencilClipPasses]; |
| 777 | |
| 778 | bool canDrawDirectToClip; // Given the renderer, the element, |
| 779 | // fill rule, and set operation can |
| 780 | // we render the element directly to |
| 781 | // stencil bit used for clipping. |
| 782 | canDrawDirectToClip = |
| 783 | GrStencilSettings::GetClipPasses(op, |
| 784 | canRenderDirectToStencil, |
| 785 | clipBit, |
| 786 | fillInverted, |
| 787 | &passes, stencilSettings); |
| 788 | |
| 789 | // draw the element to the client stencil bits if necessary |
| 790 | if (!canDrawDirectToClip) { |
| 791 | GR_STATIC_CONST_SAME_STENCIL(gDrawToStencil, |
| 792 | kIncClamp_StencilOp, |
| 793 | kIncClamp_StencilOp, |
| 794 | kAlways_StencilFunc, |
| 795 | 0xffff, |
| 796 | 0x0000, |
| 797 | 0xffff); |
| 798 | SET_RANDOM_COLOR |
| 799 | if (kRect_ClipType == clipCopy.getElementType(c)) { |
| 800 | *drawState->stencil() = gDrawToStencil; |
| 801 | gpu->drawSimpleRect(clipCopy.getRect(c), NULL, 0); |
| 802 | } else { |
| 803 | if (canRenderDirectToStencil) { |
| 804 | *drawState->stencil() = gDrawToStencil; |
| 805 | pr->drawPath(*clipPath, fill, NULL, gpu, 0, false); |
| 806 | } else { |
| 807 | pr->drawPathToStencil(*clipPath, fill, gpu); |
| 808 | } |
| 809 | } |
| 810 | } |
| 811 | |
| 812 | // now we modify the clip bit by rendering either the clip |
| 813 | // element directly or a bounding rect of the entire clip. |
| 814 | drawState->enableState(GrGpu::kModifyStencilClip_StateBit); |
| 815 | for (int p = 0; p < passes; ++p) { |
| 816 | *drawState->stencil() = stencilSettings[p]; |
| 817 | if (canDrawDirectToClip) { |
| 818 | if (kRect_ClipType == clipCopy.getElementType(c)) { |
| 819 | SET_RANDOM_COLOR |
| 820 | gpu->drawSimpleRect(clipCopy.getRect(c), NULL, 0); |
| 821 | } else { |
| 822 | SET_RANDOM_COLOR |
| 823 | pr->drawPath(*clipPath, fill, NULL, gpu, 0, false); |
| 824 | } |
| 825 | } else { |
| 826 | SET_RANDOM_COLOR |
| 827 | gpu->drawSimpleRect(bounds, NULL, 0); |
| 828 | } |
| 829 | } |
| 830 | } |
| 831 | // restore clip |
| 832 | gpu->setClip(clipCopy); |
| 833 | // recusive draws would have disabled this since they drew with |
| 834 | // the clip bounds as clip. |
| 835 | fClipMaskInStencil = true; |
| 836 | } |
| 837 | |
| 838 | return true; |
| 839 | } |
| 840 | |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 841 | // mapping of clip-respecting stencil funcs to normal stencil funcs |
| 842 | // mapping depends on whether stencil-clipping is in effect. |
| 843 | static const GrStencilFunc |
| 844 | gSpecialToBasicStencilFunc[2][kClipStencilFuncCount] = { |
| 845 | {// Stencil-Clipping is DISABLED, we are effectively always inside the clip |
| 846 | // In the Clip Funcs |
| 847 | kAlways_StencilFunc, // kAlwaysIfInClip_StencilFunc |
| 848 | kEqual_StencilFunc, // kEqualIfInClip_StencilFunc |
| 849 | kLess_StencilFunc, // kLessIfInClip_StencilFunc |
| 850 | kLEqual_StencilFunc, // kLEqualIfInClip_StencilFunc |
| 851 | // Special in the clip func that forces user's ref to be 0. |
| 852 | kNotEqual_StencilFunc, // kNonZeroIfInClip_StencilFunc |
| 853 | // make ref 0 and do normal nequal. |
| 854 | }, |
| 855 | {// Stencil-Clipping is ENABLED |
| 856 | // In the Clip Funcs |
| 857 | kEqual_StencilFunc, // kAlwaysIfInClip_StencilFunc |
| 858 | // eq stencil clip bit, mask |
| 859 | // out user bits. |
| 860 | |
| 861 | kEqual_StencilFunc, // kEqualIfInClip_StencilFunc |
| 862 | // add stencil bit to mask and ref |
| 863 | |
| 864 | kLess_StencilFunc, // kLessIfInClip_StencilFunc |
| 865 | kLEqual_StencilFunc, // kLEqualIfInClip_StencilFunc |
| 866 | // for both of these we can add |
| 867 | // the clip bit to the mask and |
| 868 | // ref and compare as normal |
| 869 | // Special in the clip func that forces user's ref to be 0. |
| 870 | kLess_StencilFunc, // kNonZeroIfInClip_StencilFunc |
| 871 | // make ref have only the clip bit set |
| 872 | // and make comparison be less |
| 873 | // 10..0 < 1..user_bits.. |
| 874 | } |
| 875 | }; |
| 876 | |
| 877 | GrStencilFunc GrClipMaskManager::adjustStencilParams(GrStencilFunc func, |
| 878 | StencilClipMode mode, |
| 879 | unsigned int stencilBitCnt, |
| 880 | unsigned int* ref, |
| 881 | unsigned int* mask, |
| 882 | unsigned int* writeMask) { |
| 883 | GrAssert(stencilBitCnt > 0); |
| 884 | GrAssert((unsigned) func < kStencilFuncCount); |
| 885 | |
| 886 | if (kModifyClip_StencilClipMode == mode) { |
| 887 | // We assume that this class is the client/draw-caller of the GrGpu and |
| 888 | // has already setup the correct values |
| 889 | return func; |
| 890 | } |
| 891 | unsigned int clipBit = (1 << (stencilBitCnt - 1)); |
| 892 | unsigned int userBits = clipBit - 1; |
| 893 | |
| 894 | *writeMask &= userBits; |
| 895 | |
| 896 | if (func >= kBasicStencilFuncCount) { |
| 897 | int respectClip = kRespectClip_StencilClipMode == mode; |
| 898 | if (respectClip) { |
| 899 | // The GrGpu class should have checked this |
| 900 | GrAssert(this->isClipInStencil()); |
| 901 | switch (func) { |
| 902 | case kAlwaysIfInClip_StencilFunc: |
| 903 | *mask = clipBit; |
| 904 | *ref = clipBit; |
| 905 | break; |
| 906 | case kEqualIfInClip_StencilFunc: |
| 907 | case kLessIfInClip_StencilFunc: |
| 908 | case kLEqualIfInClip_StencilFunc: |
| 909 | *mask = (*mask & userBits) | clipBit; |
| 910 | *ref = (*ref & userBits) | clipBit; |
| 911 | break; |
| 912 | case kNonZeroIfInClip_StencilFunc: |
| 913 | *mask = (*mask & userBits) | clipBit; |
| 914 | *ref = clipBit; |
| 915 | break; |
| 916 | default: |
| 917 | GrCrash("Unknown stencil func"); |
| 918 | } |
| 919 | } else { |
| 920 | *mask &= userBits; |
| 921 | *ref &= userBits; |
| 922 | } |
| 923 | const GrStencilFunc* table = gSpecialToBasicStencilFunc[respectClip]; |
| 924 | func = table[func - kBasicStencilFuncCount]; |
| 925 | GrAssert(func >= 0 && func < kBasicStencilFuncCount); |
| 926 | } else { |
| 927 | *mask &= userBits; |
| 928 | *ref &= userBits; |
| 929 | } |
| 930 | return func; |
| 931 | } |
| 932 | |
| 933 | //////////////////////////////////////////////////////////////////////////////// |
| 934 | |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 935 | namespace { |
| 936 | |
| 937 | GrPathFill invert_fill(GrPathFill fill) { |
| 938 | static const GrPathFill gInvertedFillTable[] = { |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 939 | kInverseWinding_GrPathFill, // kWinding_GrPathFill |
| 940 | kInverseEvenOdd_GrPathFill, // kEvenOdd_GrPathFill |
| 941 | kWinding_GrPathFill, // kInverseWinding_GrPathFill |
| 942 | kEvenOdd_GrPathFill, // kInverseEvenOdd_GrPathFill |
| 943 | kHairLine_GrPathFill, // kHairLine_GrPathFill |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 944 | }; |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 945 | GR_STATIC_ASSERT(0 == kWinding_GrPathFill); |
| 946 | GR_STATIC_ASSERT(1 == kEvenOdd_GrPathFill); |
| 947 | GR_STATIC_ASSERT(2 == kInverseWinding_GrPathFill); |
| 948 | GR_STATIC_ASSERT(3 == kInverseEvenOdd_GrPathFill); |
| 949 | GR_STATIC_ASSERT(4 == kHairLine_GrPathFill); |
| 950 | GR_STATIC_ASSERT(5 == kGrPathFillCount); |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 951 | return gInvertedFillTable[fill]; |
| 952 | } |
| 953 | |
| 954 | } |
| 955 | |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 956 | bool GrClipMaskManager::createSoftwareClipMask(GrGpu* gpu, |
| 957 | const GrClip& clipIn, |
| 958 | GrTexture** result, |
robertphillips@google.com | 6623fcd | 2012-05-15 16:47:23 +0000 | [diff] [blame] | 959 | GrIRect *resultBounds) { |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 960 | |
robertphillips@google.com | f105b10 | 2012-05-14 12:18:26 +0000 | [diff] [blame] | 961 | if (this->clipMaskPreamble(gpu, clipIn, result, resultBounds)) { |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 962 | return true; |
| 963 | } |
| 964 | |
robertphillips@google.com | f105b10 | 2012-05-14 12:18:26 +0000 | [diff] [blame] | 965 | GrTexture* accum = fAACache.getLastMask(); |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 966 | if (NULL == accum) { |
| 967 | fClipMaskInAlpha = false; |
robertphillips@google.com | f105b10 | 2012-05-14 12:18:26 +0000 | [diff] [blame] | 968 | fAACache.reset(); |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 969 | return false; |
| 970 | } |
| 971 | |
robertphillips@google.com | 2c75681 | 2012-05-22 20:28:23 +0000 | [diff] [blame] | 972 | GrSWMaskHelper helper(this->getContext()); |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 973 | |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 974 | helper.init(*resultBounds, NULL, false); |
| 975 | |
| 976 | int count = clipIn.getElementCount(); |
| 977 | |
| 978 | bool clearToInside; |
| 979 | SkRegion::Op startOp = SkRegion::kReplace_Op; // suppress warning |
| 980 | int start = process_initial_clip_elements(clipIn, |
| 981 | *resultBounds, |
| 982 | &clearToInside, |
| 983 | &startOp); |
| 984 | |
| 985 | helper.clear(clearToInside ? SK_ColorWHITE : 0x00000000); |
| 986 | |
| 987 | for (int i = start; i < count; ++i) { |
| 988 | |
| 989 | SkRegion::Op op = (i == start) ? startOp : clipIn.getOp(i); |
| 990 | |
| 991 | if (SkRegion::kIntersect_Op == op || |
| 992 | SkRegion::kReverseDifference_Op == op) { |
| 993 | // Intersect and reverse difference require modifying pixels |
| 994 | // outside of the geometry that is being "drawn". In both cases |
| 995 | // we erase all the pixels outside of the geometry but |
| 996 | // leave the pixels inside the geometry alone. For reverse |
| 997 | // difference we invert all the pixels before clearing the ones |
| 998 | // outside the geometry. |
| 999 | if (SkRegion::kReverseDifference_Op == op) { |
| 1000 | SkRect temp = SkRect::MakeLTRB( |
| 1001 | SkIntToScalar(resultBounds->left()), |
| 1002 | SkIntToScalar(resultBounds->top()), |
| 1003 | SkIntToScalar(resultBounds->right()), |
| 1004 | SkIntToScalar(resultBounds->bottom())); |
| 1005 | |
| 1006 | // invert the entire scene |
| 1007 | helper.draw(temp, SkRegion::kXOR_Op, false, SK_ColorWHITE); |
| 1008 | } |
| 1009 | |
| 1010 | if (kRect_ClipType == clipIn.getElementType(i)) { |
| 1011 | |
| 1012 | // convert the rect to a path so we can invert the fill |
| 1013 | SkPath temp; |
| 1014 | temp.addRect(clipIn.getRect(i)); |
| 1015 | |
| 1016 | helper.draw(temp, SkRegion::kReplace_Op, |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 1017 | kInverseEvenOdd_GrPathFill, clipIn.getDoAA(i), |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 1018 | 0x00000000); |
| 1019 | } else { |
| 1020 | GrAssert(kPath_ClipType == clipIn.getElementType(i)); |
| 1021 | |
| 1022 | helper.draw(clipIn.getPath(i), |
| 1023 | SkRegion::kReplace_Op, |
| 1024 | invert_fill(clipIn.getPathFill(i)), |
| 1025 | clipIn.getDoAA(i), |
| 1026 | 0x00000000); |
| 1027 | } |
| 1028 | |
| 1029 | continue; |
| 1030 | } |
| 1031 | |
| 1032 | // The other ops (union, xor, diff) only affect pixels inside |
| 1033 | // the geometry so they can just be drawn normally |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 1034 | if (kRect_ClipType == clipIn.getElementType(i)) { |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 1035 | |
| 1036 | helper.draw(clipIn.getRect(i), |
| 1037 | op, |
| 1038 | clipIn.getDoAA(i), SK_ColorWHITE); |
| 1039 | |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 1040 | } else { |
| 1041 | GrAssert(kPath_ClipType == clipIn.getElementType(i)); |
| 1042 | |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 1043 | helper.draw(clipIn.getPath(i), |
| 1044 | op, |
| 1045 | clipIn.getPathFill(i), |
| 1046 | clipIn.getDoAA(i), SK_ColorWHITE); |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 1047 | } |
| 1048 | } |
| 1049 | |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 1050 | // Because we are using the scratch texture cache, "accum" may be |
| 1051 | // larger than expected and have some cruft in the areas we aren't using. |
| 1052 | // Clear it out. |
| 1053 | |
| 1054 | // TODO: need a simpler way to clear the texture - can we combine |
| 1055 | // the clear and the writePixels (inside toTexture) |
| 1056 | GrDrawState* drawState = gpu->drawState(); |
| 1057 | GrAssert(NULL != drawState); |
| 1058 | GrRenderTarget* temp = drawState->getRenderTarget(); |
| 1059 | clear(gpu, accum, 0x00000000); |
| 1060 | // can't leave the accum bound as a rendertarget |
| 1061 | drawState->setRenderTarget(temp); |
| 1062 | |
| 1063 | helper.toTexture(accum); |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 1064 | |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 1065 | *result = accum; |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 1066 | |
| 1067 | return true; |
| 1068 | } |
| 1069 | |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 1070 | //////////////////////////////////////////////////////////////////////////////// |
robertphillips@google.com | f105b10 | 2012-05-14 12:18:26 +0000 | [diff] [blame] | 1071 | void GrClipMaskManager::releaseResources() { |
robertphillips@google.com | f105b10 | 2012-05-14 12:18:26 +0000 | [diff] [blame] | 1072 | fAACache.releaseResources(); |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 1073 | } |