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