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