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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "src/gpu/GrPathRendering.h" |
| 12 | #include "src/gpu/GrRenderTargetContext.h" |
| 13 | #include "src/gpu/GrRenderTargetOpList.h" |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 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 | |
Michael Ludwig | aa1b6b3 | 2019-05-29 14:43:13 -0400 | [diff] [blame] | 65 | // While this can take a general clip, since GrReducedClip relies on this function, it must take |
| 66 | // care to only provide hard clips or we could get stuck in a loop. The general clip is needed |
| 67 | // so that path renderers can use this function. |
Chris Dalton | 09e5689 | 2019-03-13 00:22:01 -0600 | [diff] [blame] | 68 | void stencilRect( |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 69 | const GrClip& clip, const GrUserStencilSettings* ss, GrPaint&& paint, |
| 70 | GrAA doStencilMSAA, const SkMatrix& viewMatrix, const SkRect& rect, |
| 71 | const SkMatrix* localMatrix = nullptr) { |
| 72 | // Since this provides stencil settings to drawFilledQuad, it performs a different AA type |
| 73 | // resolution compared to regular rect draws, which is the main reason it remains separate. |
| 74 | GrQuad localQuad = localMatrix ? GrQuad::MakeFromRect(rect, *localMatrix) : GrQuad(rect); |
| 75 | fRenderTargetContext->drawFilledQuad( |
| 76 | clip, std::move(paint), doStencilMSAA, GrQuadAAFlags::kNone, |
| 77 | GrQuad::MakeFromRect(rect, viewMatrix), localQuad, ss); |
| 78 | } |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 79 | |
Chris Dalton | 09e5689 | 2019-03-13 00:22:01 -0600 | [diff] [blame] | 80 | void stencilPath( |
| 81 | const GrHardClip&, GrAA doStencilMSAA, const SkMatrix& viewMatrix, const GrPath*); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 82 | |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 83 | /** |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 84 | * Draws a path, either AA or not, and touches the stencil buffer with the user stencil settings |
| 85 | * for each color sample written. |
| 86 | */ |
Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 87 | bool drawAndStencilPath(const GrHardClip&, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 88 | const GrUserStencilSettings*, |
| 89 | SkRegion::Op op, |
| 90 | bool invert, |
Chris Dalton | 09e5689 | 2019-03-13 00:22:01 -0600 | [diff] [blame] | 91 | GrAA doStencilMSAA, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 92 | const SkMatrix& viewMatrix, |
| 93 | const SkPath&); |
| 94 | |
| 95 | SkBudgeted isBudgeted() const; |
| 96 | |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 97 | int maxWindowRectangles() const; |
| 98 | |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 99 | /* |
| 100 | * This unique ID will not change for a given RenderTargetContext. However, it is _NOT_ |
| 101 | * guaranteed to match the uniqueID of the underlying GrRenderTarget - beware! |
| 102 | */ |
| 103 | GrSurfaceProxy::UniqueID uniqueID() const { |
| 104 | return fRenderTargetContext->fRenderTargetProxy->uniqueID(); |
| 105 | } |
| 106 | |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 107 | uint32_t testingOnly_getOpListID(); |
Brian Salomon | 348a037 | 2018-10-31 10:42:18 -0400 | [diff] [blame] | 108 | |
| 109 | using WillAddOpFn = GrRenderTargetContext::WillAddOpFn; |
| 110 | void testingOnly_addDrawOp(std::unique_ptr<GrDrawOp>); |
| 111 | void testingOnly_addDrawOp(const GrClip&, std::unique_ptr<GrDrawOp>, |
| 112 | const std::function<WillAddOpFn>& = std::function<WillAddOpFn>()); |
Brian Salomon | ac70f84 | 2017-05-08 10:43:33 -0400 | [diff] [blame] | 113 | |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 114 | bool refsWrappedObjects() const { |
| 115 | return fRenderTargetContext->fRenderTargetProxy->refsWrappedObjects(); |
| 116 | } |
| 117 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 118 | private: |
| 119 | explicit GrRenderTargetContextPriv(GrRenderTargetContext* renderTargetContext) |
| 120 | : fRenderTargetContext(renderTargetContext) {} |
| 121 | GrRenderTargetContextPriv(const GrRenderTargetPriv&) {} // unimpl |
| 122 | GrRenderTargetContextPriv& operator=(const GrRenderTargetPriv&); // unimpl |
| 123 | |
| 124 | // No taking addresses of this type. |
| 125 | const GrRenderTargetContextPriv* operator&() const; |
| 126 | GrRenderTargetContextPriv* operator&(); |
| 127 | |
| 128 | GrRenderTargetContext* fRenderTargetContext; |
| 129 | |
| 130 | friend class GrRenderTargetContext; // to construct/copy this type. |
| 131 | }; |
| 132 | |
Brian Osman | 693a540 | 2016-10-27 15:13:22 -0400 | [diff] [blame] | 133 | inline GrRenderTargetContextPriv GrRenderTargetContext::priv() { |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 134 | return GrRenderTargetContextPriv(this); |
| 135 | } |
| 136 | |
Brian Osman | 693a540 | 2016-10-27 15:13:22 -0400 | [diff] [blame] | 137 | inline const GrRenderTargetContextPriv GrRenderTargetContext::priv() const { |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 138 | return GrRenderTargetContextPriv(const_cast<GrRenderTargetContext*>(this)); |
| 139 | } |
| 140 | |
| 141 | #endif |