| 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 "src/gpu/GrOpsTask.h" |
| 12 | #include "src/gpu/GrPathRendering.h" |
| 13 | #include "src/gpu/GrRenderTargetContext.h" |
| 14 | |
| 15 | class GrHardClip; |
| 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 | GrRecordingContext* recordingContext() { return fRenderTargetContext->fContext; } |
| 25 | // called to note the last clip drawn to the stencil buffer. |
| 26 | // TODO: remove after clipping overhaul. |
| 27 | void setLastClip(uint32_t clipStackGenID, const SkIRect& devClipBounds, |
| 28 | int numClipAnalyticElements) { |
| 29 | GrOpsTask* opsTask = fRenderTargetContext->getOpsTask(); |
| 30 | opsTask->fLastClipStackGenID = clipStackGenID; |
| 31 | opsTask->fLastDevClipBounds = devClipBounds; |
| 32 | opsTask->fLastClipNumAnalyticElements = numClipAnalyticElements; |
| 33 | } |
| 34 | |
| 35 | // called to determine if we have to render the clip into SB. |
| 36 | // TODO: remove after clipping overhaul. |
| 37 | bool mustRenderClip(uint32_t clipStackGenID, const SkIRect& devClipBounds, |
| 38 | int numClipAnalyticElements) const { |
| 39 | GrOpsTask* opsTask = fRenderTargetContext->getOpsTask(); |
| 40 | return opsTask->fLastClipStackGenID != clipStackGenID || |
| 41 | !opsTask->fLastDevClipBounds.contains(devClipBounds) || |
| 42 | opsTask->fLastClipNumAnalyticElements != numClipAnalyticElements; |
| 43 | } |
| 44 | |
| 45 | // Clear at minimum the pixels within 'scissor', but is allowed to clear the full render target |
| 46 | // if that is the more performant option. |
| 47 | void clearAtLeast(const SkIRect& scissor, const SkPMColor4f& color) { |
| 48 | fRenderTargetContext->internalClear(&scissor, color, /* upgrade to full */ true); |
| 49 | } |
| 50 | |
| 51 | void clearStencilClip(const SkIRect& scissor, bool insideStencilMask) { |
| 52 | fRenderTargetContext->internalStencilClear(&scissor, insideStencilMask); |
| 53 | } |
| 54 | |
| 55 | // While this can take a general clip, since GrReducedClip relies on this function, it must take |
| 56 | // care to only provide hard clips or we could get stuck in a loop. The general clip is needed |
| 57 | // so that path renderers can use this function. |
| 58 | void stencilRect( |
| 59 | const GrClip* clip, const GrUserStencilSettings* ss, GrPaint&& paint, |
| 60 | GrAA doStencilMSAA, const SkMatrix& viewMatrix, const SkRect& rect, |
| 61 | const SkMatrix* localMatrix = nullptr) { |
| 62 | // Since this provides stencil settings to drawFilledQuad, it performs a different AA type |
| 63 | // resolution compared to regular rect draws, which is the main reason it remains separate. |
| 64 | DrawQuad quad{GrQuad::MakeFromRect(rect, viewMatrix), |
| 65 | localMatrix ? GrQuad::MakeFromRect(rect, *localMatrix) : GrQuad(rect), |
| 66 | GrQuadAAFlags::kNone}; |
| 67 | fRenderTargetContext->drawFilledQuad(clip, std::move(paint), doStencilMSAA, &quad, ss); |
| 68 | } |
| 69 | |
| 70 | void stencilPath( |
| 71 | const GrHardClip*, GrAA doStencilMSAA, const SkMatrix& viewMatrix, sk_sp<const GrPath>); |
| 72 | |
| 73 | /** |
| 74 | * Draws a path, either AA or not, and touches the stencil buffer with the user stencil settings |
| 75 | * for each color sample written. |
| 76 | */ |
| 77 | bool drawAndStencilPath(const GrHardClip*, |
| 78 | const GrUserStencilSettings*, |
| 79 | SkRegion::Op op, |
| 80 | bool invert, |
| 81 | GrAA doStencilMSAA, |
| 82 | const SkMatrix& viewMatrix, |
| 83 | const SkPath&); |
| 84 | |
| 85 | SkBudgeted isBudgeted() const; |
| 86 | |
| 87 | int maxWindowRectangles() const; |
| 88 | |
| 89 | /* |
| 90 | * This unique ID will not change for a given RenderTargetContext. However, it is _NOT_ |
| 91 | * guaranteed to match the uniqueID of the underlying GrRenderTarget - beware! |
| 92 | */ |
| 93 | GrSurfaceProxy::UniqueID uniqueID() const { |
| 94 | return fRenderTargetContext->asSurfaceProxy()->uniqueID(); |
| 95 | } |
| 96 | |
| 97 | uint32_t testingOnly_getOpsTaskID(); |
| 98 | |
| 99 | using WillAddOpFn = GrRenderTargetContext::WillAddOpFn; |
| 100 | void testingOnly_addDrawOp(std::unique_ptr<GrDrawOp>); |
| 101 | void testingOnly_addDrawOp(const GrClip*, std::unique_ptr<GrDrawOp>, |
| 102 | const std::function<WillAddOpFn>& = std::function<WillAddOpFn>()); |
| 103 | |
| 104 | SkGlyphRunListPainter* testingOnly_glyphRunPainter() { |
| 105 | return &fRenderTargetContext->fGlyphPainter; |
| 106 | } |
| 107 | |
| 108 | bool refsWrappedObjects() const { |
| 109 | return fRenderTargetContext->asRenderTargetProxy()->refsWrappedObjects(); |
| 110 | } |
| 111 | |
| 112 | void addDrawOp(const GrClip* clip, std::unique_ptr<GrDrawOp> op) { |
| 113 | fRenderTargetContext->addDrawOp(clip, std::move(op)); |
| 114 | } |
| 115 | |
| 116 | private: |
| 117 | explicit GrRenderTargetContextPriv(GrRenderTargetContext* renderTargetContext) |
| 118 | : fRenderTargetContext(renderTargetContext) {} |
| 119 | GrRenderTargetContextPriv(const GrRenderTargetContextPriv&) = delete; |
| 120 | GrRenderTargetContextPriv& operator=(const GrRenderTargetContextPriv&) = delete; |
| 121 | |
| 122 | // No taking addresses of this type. |
| 123 | const GrRenderTargetContextPriv* operator&() const; |
| 124 | GrRenderTargetContextPriv* operator&(); |
| 125 | |
| 126 | GrRenderTargetContext* fRenderTargetContext; |
| 127 | |
| 128 | friend class GrRenderTargetContext; // to construct/copy this type. |
| 129 | }; |
| 130 | |
| 131 | inline GrRenderTargetContextPriv GrRenderTargetContext::priv() { |
| 132 | return GrRenderTargetContextPriv(this); |
| 133 | } |
| 134 | |
| 135 | inline const GrRenderTargetContextPriv GrRenderTargetContext::priv() const { // NOLINT(readability-const-return-type) |
| 136 | return GrRenderTargetContextPriv(const_cast<GrRenderTargetContext*>(this)); |
| 137 | } |
| 138 | |
| 139 | #endif |
| 140 | |