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/GrPathRendering.h"
12 #include "src/gpu/GrRenderTargetContext.h"
13 #include "src/gpu/GrRenderTargetOpList.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.
setLastClip(uint32_t clipStackGenID,const SkIRect & devClipBounds,int numClipAnalyticFPs)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;
34 }
35
36 // called to determine if we have to render the clip into SB.
37 // TODO: remove after clipping overhaul.
mustRenderClip(uint32_t clipStackGenID,const SkIRect & devClipBounds,int numClipAnalyticFPs)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;
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 /*
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 */
63 void absClear(const SkIRect* rect, const SkPMColor4f& color);
64
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.
68 void stencilRect(
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 }
79
80 void stencilPath(
81 const GrHardClip&, GrAA doStencilMSAA, const SkMatrix& viewMatrix, const GrPath*);
82
83 /**
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 */
87 bool drawAndStencilPath(const GrHardClip&,
88 const GrUserStencilSettings*,
89 SkRegion::Op op,
90 bool invert,
91 GrAA doStencilMSAA,
92 const SkMatrix& viewMatrix,
93 const SkPath&);
94
95 SkBudgeted isBudgeted() const;
96
97 int maxWindowRectangles() const;
98
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 */
uniqueID()103 GrSurfaceProxy::UniqueID uniqueID() const {
104 return fRenderTargetContext->fRenderTargetProxy->uniqueID();
105 }
106
107 uint32_t testingOnly_getOpListID();
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>());
113
refsWrappedObjects()114 bool refsWrappedObjects() const {
115 return fRenderTargetContext->fRenderTargetProxy->refsWrappedObjects();
116 }
117
118 private:
GrRenderTargetContextPriv(GrRenderTargetContext * renderTargetContext)119 explicit GrRenderTargetContextPriv(GrRenderTargetContext* renderTargetContext)
120 : fRenderTargetContext(renderTargetContext) {}
GrRenderTargetContextPriv(const GrRenderTargetPriv &)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
priv()133 inline GrRenderTargetContextPriv GrRenderTargetContext::priv() {
134 return GrRenderTargetContextPriv(this);
135 }
136
priv()137 inline const GrRenderTargetContextPriv GrRenderTargetContext::priv() const {
138 return GrRenderTargetContextPriv(const_cast<GrRenderTargetContext*>(this));
139 }
140
141 #endif
142