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