Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef GrRenderTargetContextPriv_DEFINED |
| 9 | #define GrRenderTargetContextPriv_DEFINED |
| 10 | |
| 11 | #include "GrRenderTargetContext.h" |
| 12 | #include "GrRenderTargetOpList.h" |
| 13 | #include "GrPathRendering.h" |
| 14 | |
| 15 | class GrFixedClip; |
| 16 | class GrPath; |
| 17 | struct GrUserStencilSettings; |
| 18 | |
| 19 | /** Class that adds methods to GrRenderTargetContext that are only intended for use internal to |
| 20 | Skia. This class is purely a privileged window into GrRenderTargetContext. It should never have |
| 21 | additional data members or virtual methods. */ |
| 22 | class GrRenderTargetContextPriv { |
| 23 | public: |
| 24 | gr_instanced::InstancedRendering* accessInstancedRendering() const { |
| 25 | return fRenderTargetContext->getOpList()->instancedRendering(); |
| 26 | } |
| 27 | |
csmartdalton | 7cdda99 | 2016-11-01 07:03:03 -0700 | [diff] [blame] | 28 | // called to note the last clip drawn to the stencil buffer. |
| 29 | // TODO: remove after clipping overhaul. |
| 30 | void setLastClip(int32_t clipStackGenID, |
| 31 | const SkIRect& clipSpaceRect, |
| 32 | const SkIPoint clipOrigin) { |
| 33 | GrRenderTargetOpList* opList = fRenderTargetContext->getOpList(); |
| 34 | opList->fLastClipStackGenID = clipStackGenID; |
| 35 | opList->fLastClipStackRect = clipSpaceRect; |
| 36 | opList->fLastClipOrigin = clipOrigin; |
| 37 | } |
| 38 | |
| 39 | // called to determine if we have to render the clip into SB. |
| 40 | // TODO: remove after clipping overhaul. |
| 41 | bool mustRenderClip(int32_t clipStackGenID, |
| 42 | const SkIRect& clipSpaceRect, |
| 43 | const SkIPoint& clipOrigin) const { |
| 44 | GrRenderTargetOpList* opList = fRenderTargetContext->getOpList(); |
| 45 | return opList->fLastClipStackGenID != clipStackGenID || |
| 46 | opList->fLastClipOrigin != clipOrigin || |
| 47 | !opList->fLastClipStackRect.contains(clipSpaceRect); |
| 48 | } |
| 49 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 50 | void clear(const GrFixedClip&, const GrColor, bool canIgnoreClip); |
| 51 | |
| 52 | void clearStencilClip(const GrFixedClip&, bool insideStencilMask); |
| 53 | |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 54 | /* |
| 55 | * Some portions of the code, which use approximate-match rendertargets (i.e., ImageFilters), |
| 56 | * rely on clears that lie outside of the content region to still have an effect. |
| 57 | * For example, when sampling a decimated blurred image back up to full size, the GaussianBlur |
| 58 | * code draws 1-pixel rects along the left and bottom edges to be able to use bilerp for |
| 59 | * upsampling. The "absClear" entry point ignores the content bounds but does use the |
| 60 | * worst case (instantiated) bounds. |
| 61 | * |
| 62 | * @param rect if (!null) the rect to clear, otherwise it is a full screen clear |
| 63 | * @param color the color to clear to |
| 64 | */ |
| 65 | void absClear(const SkIRect* rect, const GrColor color); |
| 66 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 67 | void stencilRect(const GrClip& clip, |
| 68 | const GrUserStencilSettings* ss, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 69 | GrAAType, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 70 | const SkMatrix& viewMatrix, |
| 71 | const SkRect& rect); |
| 72 | |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 73 | void stencilPath(const GrClip&, GrAAType, const SkMatrix& viewMatrix, const GrPath*); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 74 | |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 75 | /** |
| 76 | * Draws a rect, either AA or not, and touches the stencil buffer with the user stencil settings |
| 77 | * for each color sample written. |
| 78 | */ |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 79 | bool drawAndStencilRect(const GrClip&, |
| 80 | const GrUserStencilSettings*, |
| 81 | SkRegion::Op op, |
| 82 | bool invert, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 83 | GrAA, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 84 | const SkMatrix& viewMatrix, |
| 85 | const SkRect&); |
| 86 | |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 87 | /** |
| 88 | * Draws a path, either AA or not, and touches the stencil buffer with the user stencil settings |
| 89 | * for each color sample written. |
| 90 | */ |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 91 | bool drawAndStencilPath(const GrClip&, |
| 92 | const GrUserStencilSettings*, |
| 93 | SkRegion::Op op, |
| 94 | bool invert, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 95 | GrAA, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 96 | const SkMatrix& viewMatrix, |
| 97 | const SkPath&); |
| 98 | |
| 99 | SkBudgeted isBudgeted() const; |
| 100 | |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 101 | int maxWindowRectangles() const; |
| 102 | |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 103 | /* |
| 104 | * This unique ID will not change for a given RenderTargetContext. However, it is _NOT_ |
| 105 | * guaranteed to match the uniqueID of the underlying GrRenderTarget - beware! |
| 106 | */ |
| 107 | GrSurfaceProxy::UniqueID uniqueID() const { |
| 108 | return fRenderTargetContext->fRenderTargetProxy->uniqueID(); |
| 109 | } |
| 110 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 111 | void testingOnly_addDrawOp(GrPaint&&, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 112 | GrAAType, |
Brian Salomon | f833478 | 2017-01-03 09:42:58 -0500 | [diff] [blame] | 113 | std::unique_ptr<GrDrawOp>, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 114 | const GrUserStencilSettings* = nullptr, |
| 115 | bool snapToCenters = false); |
| 116 | |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 117 | bool refsWrappedObjects() const { |
| 118 | return fRenderTargetContext->fRenderTargetProxy->refsWrappedObjects(); |
| 119 | } |
| 120 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 121 | private: |
| 122 | explicit GrRenderTargetContextPriv(GrRenderTargetContext* renderTargetContext) |
| 123 | : fRenderTargetContext(renderTargetContext) {} |
| 124 | GrRenderTargetContextPriv(const GrRenderTargetPriv&) {} // unimpl |
| 125 | GrRenderTargetContextPriv& operator=(const GrRenderTargetPriv&); // unimpl |
| 126 | |
| 127 | // No taking addresses of this type. |
| 128 | const GrRenderTargetContextPriv* operator&() const; |
| 129 | GrRenderTargetContextPriv* operator&(); |
| 130 | |
| 131 | GrRenderTargetContext* fRenderTargetContext; |
| 132 | |
| 133 | friend class GrRenderTargetContext; // to construct/copy this type. |
| 134 | }; |
| 135 | |
Brian Osman | 693a540 | 2016-10-27 15:13:22 -0400 | [diff] [blame] | 136 | inline GrRenderTargetContextPriv GrRenderTargetContext::priv() { |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 137 | return GrRenderTargetContextPriv(this); |
| 138 | } |
| 139 | |
Brian Osman | 693a540 | 2016-10-27 15:13:22 -0400 | [diff] [blame] | 140 | inline const GrRenderTargetContextPriv GrRenderTargetContext::priv() const { |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 141 | return GrRenderTargetContextPriv(const_cast<GrRenderTargetContext*>(this)); |
| 142 | } |
| 143 | |
| 144 | #endif |