| 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 GrFixedClip; | 
|---|
| 16 | class GrHardClip; | 
|---|
| 17 | class GrPath; | 
|---|
| 18 | class GrRenderTargetPriv; | 
|---|
| 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: | 
|---|
| 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 | GrOpsTask* opsTask = fRenderTargetContext->getOpsTask(); | 
|---|
| 31 | opsTask->fLastClipStackGenID = clipStackGenID; | 
|---|
| 32 | opsTask->fLastDevClipBounds = devClipBounds; | 
|---|
| 33 | opsTask->fLastClipNumAnalyticFPs = numClipAnalyticFPs; | 
|---|
| 34 | } | 
|---|
| 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 | GrOpsTask* opsTask = fRenderTargetContext->getOpsTask(); | 
|---|
| 41 | return opsTask->fLastClipStackGenID != clipStackGenID || | 
|---|
| 42 | !opsTask->fLastDevClipBounds.contains(devClipBounds) || | 
|---|
| 43 | opsTask->fLastClipNumAnalyticFPs != numClipAnalyticFPs; | 
|---|
| 44 | } | 
|---|
| 45 |  | 
|---|
| 46 | using CanClearFullscreen = GrRenderTargetContext::CanClearFullscreen; | 
|---|
| 47 |  | 
|---|
| 48 | void clear(const GrFixedClip&, const SkPMColor4f&, CanClearFullscreen); | 
|---|
| 49 |  | 
|---|
| 50 | void clearStencilClip(const GrFixedClip&, bool insideStencilMask); | 
|---|
| 51 |  | 
|---|
| 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. | 
|---|
| 55 | void stencilRect( | 
|---|
| 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 | DrawQuad quad{GrQuad::MakeFromRect(rect, viewMatrix), | 
|---|
| 62 | localMatrix ? GrQuad::MakeFromRect(rect, *localMatrix) : GrQuad(rect), | 
|---|
| 63 | GrQuadAAFlags::kNone}; | 
|---|
| 64 | fRenderTargetContext->drawFilledQuad(clip, std::move(paint), doStencilMSAA, &quad, ss); | 
|---|
| 65 | } | 
|---|
| 66 |  | 
|---|
| 67 | void stencilPath( | 
|---|
| 68 | const GrHardClip&, GrAA doStencilMSAA, const SkMatrix& viewMatrix, sk_sp<const GrPath>); | 
|---|
| 69 |  | 
|---|
| 70 | /** | 
|---|
| 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 | */ | 
|---|
| 74 | bool drawAndStencilPath(const GrHardClip&, | 
|---|
| 75 | const GrUserStencilSettings*, | 
|---|
| 76 | SkRegion::Op op, | 
|---|
| 77 | bool invert, | 
|---|
| 78 | GrAA doStencilMSAA, | 
|---|
| 79 | const SkMatrix& viewMatrix, | 
|---|
| 80 | const SkPath&); | 
|---|
| 81 |  | 
|---|
| 82 | SkBudgeted isBudgeted() const; | 
|---|
| 83 |  | 
|---|
| 84 | int maxWindowRectangles() const; | 
|---|
| 85 |  | 
|---|
| 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 { | 
|---|
| 91 | return fRenderTargetContext->asSurfaceProxy()->uniqueID(); | 
|---|
| 92 | } | 
|---|
| 93 |  | 
|---|
| 94 | uint32_t testingOnly_getOpsTaskID(); | 
|---|
| 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>()); | 
|---|
| 100 |  | 
|---|
| 101 | bool refsWrappedObjects() const { | 
|---|
| 102 | return fRenderTargetContext->asRenderTargetProxy()->refsWrappedObjects(); | 
|---|
| 103 | } | 
|---|
| 104 |  | 
|---|
| 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 |  | 
|---|
| 120 | inline GrRenderTargetContextPriv GrRenderTargetContext::priv() { | 
|---|
| 121 | return GrRenderTargetContextPriv(this); | 
|---|
| 122 | } | 
|---|
| 123 |  | 
|---|
| 124 | inline const GrRenderTargetContextPriv GrRenderTargetContext::priv() const { | 
|---|
| 125 | return GrRenderTargetContextPriv(const_cast<GrRenderTargetContext*>(this)); | 
|---|
| 126 | } | 
|---|
| 127 |  | 
|---|
| 128 | #endif | 
|---|
| 129 |  | 
|---|