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 "GrRenderTargetContext.h"
12 #include "GrRenderTargetOpList.h"
13 #include "GrPathRendering.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         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.
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     void stencilRect(const GrHardClip&,
66                      const GrUserStencilSettings* ss,
67                      GrAAType,
68                      const SkMatrix& viewMatrix,
69                      const SkRect& rect);
70 
71     void stencilPath(const GrHardClip&, GrAAType, const SkMatrix& viewMatrix, const GrPath*);
72 
73     /**
74      * Draws a rect, either AA or not, and touches the stencil buffer with the user stencil settings
75      * for each color sample written.
76      */
77     bool drawAndStencilRect(const GrHardClip&,
78                             const GrUserStencilSettings*,
79                             SkRegion::Op op,
80                             bool invert,
81                             GrAA,
82                             const SkMatrix& viewMatrix,
83                             const SkRect&);
84 
85     /**
86      * Draws a path, either AA or not, and touches the stencil buffer with the user stencil settings
87      * for each color sample written.
88      */
89     bool drawAndStencilPath(const GrHardClip&,
90                             const GrUserStencilSettings*,
91                             SkRegion::Op op,
92                             bool invert,
93                             GrAA,
94                             const SkMatrix& viewMatrix,
95                             const SkPath&);
96 
97     SkBudgeted isBudgeted() const;
98 
99     int maxWindowRectangles() const;
100 
101     /*
102      * This unique ID will not change for a given RenderTargetContext. However, it is _NOT_
103      * guaranteed to match the uniqueID of the underlying GrRenderTarget - beware!
104      */
105     GrSurfaceProxy::UniqueID uniqueID() const {
106         return fRenderTargetContext->fRenderTargetProxy->uniqueID();
107     }
108 
109     uint32_t testingOnly_getOpListID();
110 
111     using WillAddOpFn = GrRenderTargetContext::WillAddOpFn;
112     void testingOnly_addDrawOp(std::unique_ptr<GrDrawOp>);
113     void testingOnly_addDrawOp(const GrClip&, std::unique_ptr<GrDrawOp>,
114                                const std::function<WillAddOpFn>& = std::function<WillAddOpFn>());
115 
116     bool refsWrappedObjects() const {
117         return fRenderTargetContext->fRenderTargetProxy->refsWrappedObjects();
118     }
119 
120 private:
121     explicit GrRenderTargetContextPriv(GrRenderTargetContext* renderTargetContext)
122         : fRenderTargetContext(renderTargetContext) {}
123     GrRenderTargetContextPriv(const GrRenderTargetPriv&) {} // unimpl
124     GrRenderTargetContextPriv& operator=(const GrRenderTargetPriv&); // unimpl
125 
126     // No taking addresses of this type.
127     const GrRenderTargetContextPriv* operator&() const;
128     GrRenderTargetContextPriv* operator&();
129 
130     GrRenderTargetContext* fRenderTargetContext;
131 
132     friend class GrRenderTargetContext; // to construct/copy this type.
133 };
134 
135 inline GrRenderTargetContextPriv GrRenderTargetContext::priv() {
136     return GrRenderTargetContextPriv(this);
137 }
138 
139 inline const GrRenderTargetContextPriv GrRenderTargetContext::priv() const {
140     return GrRenderTargetContextPriv(const_cast<GrRenderTargetContext*>(this));
141 }
142 
143 #endif
144