Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | |
michael@0 | 2 | /* |
michael@0 | 3 | * Copyright 2012 Google Inc. |
michael@0 | 4 | * |
michael@0 | 5 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 6 | * found in the LICENSE file. |
michael@0 | 7 | */ |
michael@0 | 8 | |
michael@0 | 9 | #include "GrSoftwarePathRenderer.h" |
michael@0 | 10 | #include "GrContext.h" |
michael@0 | 11 | #include "GrSWMaskHelper.h" |
michael@0 | 12 | |
michael@0 | 13 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 14 | bool GrSoftwarePathRenderer::canDrawPath(const SkPath&, |
michael@0 | 15 | const SkStrokeRec&, |
michael@0 | 16 | const GrDrawTarget*, |
michael@0 | 17 | bool antiAlias) const { |
michael@0 | 18 | if (!antiAlias || NULL == fContext) { |
michael@0 | 19 | // TODO: We could allow the SW path to also handle non-AA paths but |
michael@0 | 20 | // this would mean that GrDefaultPathRenderer would never be called |
michael@0 | 21 | // (since it appears after the SW renderer in the path renderer |
michael@0 | 22 | // chain). Some testing would need to be done r.e. performance |
michael@0 | 23 | // and consistency of the resulting images before removing |
michael@0 | 24 | // the "!antiAlias" clause from the above test |
michael@0 | 25 | return false; |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | return true; |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | GrPathRenderer::StencilSupport GrSoftwarePathRenderer::onGetStencilSupport( |
michael@0 | 32 | const SkPath&, |
michael@0 | 33 | const SkStrokeRec&, |
michael@0 | 34 | const GrDrawTarget*) const { |
michael@0 | 35 | return GrPathRenderer::kNoSupport_StencilSupport; |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | namespace { |
michael@0 | 39 | |
michael@0 | 40 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 41 | // gets device coord bounds of path (not considering the fill) and clip. The |
michael@0 | 42 | // path bounds will be a subset of the clip bounds. returns false if |
michael@0 | 43 | // path bounds would be empty. |
michael@0 | 44 | bool get_path_and_clip_bounds(const GrDrawTarget* target, |
michael@0 | 45 | const SkPath& path, |
michael@0 | 46 | const SkMatrix& matrix, |
michael@0 | 47 | SkIRect* devPathBounds, |
michael@0 | 48 | SkIRect* devClipBounds) { |
michael@0 | 49 | // compute bounds as intersection of rt size, clip, and path |
michael@0 | 50 | const GrRenderTarget* rt = target->getDrawState().getRenderTarget(); |
michael@0 | 51 | if (NULL == rt) { |
michael@0 | 52 | return false; |
michael@0 | 53 | } |
michael@0 | 54 | *devPathBounds = SkIRect::MakeWH(rt->width(), rt->height()); |
michael@0 | 55 | |
michael@0 | 56 | target->getClip()->getConservativeBounds(rt, devClipBounds); |
michael@0 | 57 | |
michael@0 | 58 | // TODO: getConservativeBounds already intersects with the |
michael@0 | 59 | // render target's bounding box. Remove this next line |
michael@0 | 60 | if (!devPathBounds->intersect(*devClipBounds)) { |
michael@0 | 61 | return false; |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | if (!path.getBounds().isEmpty()) { |
michael@0 | 65 | SkRect pathSBounds; |
michael@0 | 66 | matrix.mapRect(&pathSBounds, path.getBounds()); |
michael@0 | 67 | SkIRect pathIBounds; |
michael@0 | 68 | pathSBounds.roundOut(&pathIBounds); |
michael@0 | 69 | if (!devPathBounds->intersect(pathIBounds)) { |
michael@0 | 70 | // set the correct path bounds, as this would be used later. |
michael@0 | 71 | *devPathBounds = pathIBounds; |
michael@0 | 72 | return false; |
michael@0 | 73 | } |
michael@0 | 74 | } else { |
michael@0 | 75 | *devPathBounds = SkIRect::EmptyIRect(); |
michael@0 | 76 | return false; |
michael@0 | 77 | } |
michael@0 | 78 | return true; |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 82 | void draw_around_inv_path(GrDrawTarget* target, |
michael@0 | 83 | const SkIRect& devClipBounds, |
michael@0 | 84 | const SkIRect& devPathBounds) { |
michael@0 | 85 | GrDrawState::AutoViewMatrixRestore avmr; |
michael@0 | 86 | if (!avmr.setIdentity(target->drawState())) { |
michael@0 | 87 | return; |
michael@0 | 88 | } |
michael@0 | 89 | SkRect rect; |
michael@0 | 90 | if (devClipBounds.fTop < devPathBounds.fTop) { |
michael@0 | 91 | rect.iset(devClipBounds.fLeft, devClipBounds.fTop, |
michael@0 | 92 | devClipBounds.fRight, devPathBounds.fTop); |
michael@0 | 93 | target->drawSimpleRect(rect, NULL); |
michael@0 | 94 | } |
michael@0 | 95 | if (devClipBounds.fLeft < devPathBounds.fLeft) { |
michael@0 | 96 | rect.iset(devClipBounds.fLeft, devPathBounds.fTop, |
michael@0 | 97 | devPathBounds.fLeft, devPathBounds.fBottom); |
michael@0 | 98 | target->drawSimpleRect(rect, NULL); |
michael@0 | 99 | } |
michael@0 | 100 | if (devClipBounds.fRight > devPathBounds.fRight) { |
michael@0 | 101 | rect.iset(devPathBounds.fRight, devPathBounds.fTop, |
michael@0 | 102 | devClipBounds.fRight, devPathBounds.fBottom); |
michael@0 | 103 | target->drawSimpleRect(rect, NULL); |
michael@0 | 104 | } |
michael@0 | 105 | if (devClipBounds.fBottom > devPathBounds.fBottom) { |
michael@0 | 106 | rect.iset(devClipBounds.fLeft, devPathBounds.fBottom, |
michael@0 | 107 | devClipBounds.fRight, devClipBounds.fBottom); |
michael@0 | 108 | target->drawSimpleRect(rect, NULL); |
michael@0 | 109 | } |
michael@0 | 110 | } |
michael@0 | 111 | |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 115 | // return true on success; false on failure |
michael@0 | 116 | bool GrSoftwarePathRenderer::onDrawPath(const SkPath& path, |
michael@0 | 117 | const SkStrokeRec& stroke, |
michael@0 | 118 | GrDrawTarget* target, |
michael@0 | 119 | bool antiAlias) { |
michael@0 | 120 | |
michael@0 | 121 | if (NULL == fContext) { |
michael@0 | 122 | return false; |
michael@0 | 123 | } |
michael@0 | 124 | |
michael@0 | 125 | GrDrawState* drawState = target->drawState(); |
michael@0 | 126 | |
michael@0 | 127 | SkMatrix vm = drawState->getViewMatrix(); |
michael@0 | 128 | |
michael@0 | 129 | SkIRect devPathBounds, devClipBounds; |
michael@0 | 130 | if (!get_path_and_clip_bounds(target, path, vm, |
michael@0 | 131 | &devPathBounds, &devClipBounds)) { |
michael@0 | 132 | if (path.isInverseFillType()) { |
michael@0 | 133 | draw_around_inv_path(target, devClipBounds, devPathBounds); |
michael@0 | 134 | } |
michael@0 | 135 | return true; |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | SkAutoTUnref<GrTexture> texture( |
michael@0 | 139 | GrSWMaskHelper::DrawPathMaskToTexture(fContext, path, stroke, |
michael@0 | 140 | devPathBounds, |
michael@0 | 141 | antiAlias, &vm)); |
michael@0 | 142 | if (NULL == texture) { |
michael@0 | 143 | return false; |
michael@0 | 144 | } |
michael@0 | 145 | |
michael@0 | 146 | GrSWMaskHelper::DrawToTargetWithPathMask(texture, target, devPathBounds); |
michael@0 | 147 | |
michael@0 | 148 | if (path.isInverseFillType()) { |
michael@0 | 149 | draw_around_inv_path(target, devClipBounds, devPathBounds); |
michael@0 | 150 | } |
michael@0 | 151 | |
michael@0 | 152 | return true; |
michael@0 | 153 | } |