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