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 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:
accessInstancedRendering()24     gr_instanced::InstancedRendering* accessInstancedRendering() const {
25         return fRenderTargetContext->getOpList()->instancedRendering();
26     }
27 
28     // called to note the last clip drawn to the stencil buffer.
29     // TODO: remove after clipping overhaul.
setLastClip(int32_t clipStackGenID,const SkIRect & devClipBounds)30     void setLastClip(int32_t clipStackGenID, const SkIRect& devClipBounds) {
31         GrRenderTargetOpList* opList = fRenderTargetContext->getOpList();
32         opList->fLastClipStackGenID = clipStackGenID;
33         opList->fLastDevClipBounds = devClipBounds;
34     }
35 
36     // called to determine if we have to render the clip into SB.
37     // TODO: remove after clipping overhaul.
mustRenderClip(int32_t clipStackGenID,const SkIRect & devClipBounds)38     bool mustRenderClip(int32_t clipStackGenID, const SkIRect& devClipBounds) const {
39         GrRenderTargetOpList* opList = fRenderTargetContext->getOpList();
40         return opList->fLastClipStackGenID != clipStackGenID ||
41                !opList->fLastDevClipBounds.contains(devClipBounds);
42     }
43 
44     void clear(const GrFixedClip&, const GrColor, bool canIgnoreClip);
45 
46     void clearStencilClip(const GrFixedClip&, bool insideStencilMask);
47 
48     /*
49      * Some portions of the code, which use approximate-match rendertargets (i.e., ImageFilters),
50      * rely on clears that lie outside of the content region to still have an effect.
51      * For example, when sampling a decimated blurred image back up to full size, the GaussianBlur
52      * code draws 1-pixel rects along the left and bottom edges to be able to use bilerp for
53      * upsampling. The "absClear" entry point ignores the content bounds but does use the
54      * worst case (instantiated) bounds.
55      *
56      * @param rect      if (!null) the rect to clear, otherwise it is a full screen clear
57      * @param color     the color to clear to
58      */
59     void absClear(const SkIRect* rect, const GrColor color);
60 
61     void stencilRect(const GrClip& clip,
62                      const GrUserStencilSettings* ss,
63                      GrAAType,
64                      const SkMatrix& viewMatrix,
65                      const SkRect& rect);
66 
67     void stencilPath(const GrClip&, GrAAType, const SkMatrix& viewMatrix, const GrPath*);
68 
69     /**
70      * Draws a rect, either AA or not, and touches the stencil buffer with the user stencil settings
71      * for each color sample written.
72      */
73     bool drawAndStencilRect(const GrClip&,
74                             const GrUserStencilSettings*,
75                             SkRegion::Op op,
76                             bool invert,
77                             GrAA,
78                             const SkMatrix& viewMatrix,
79                             const SkRect&);
80 
81     /**
82      * Draws a path, either AA or not, and touches the stencil buffer with the user stencil settings
83      * for each color sample written.
84      */
85     bool drawAndStencilPath(const GrClip&,
86                             const GrUserStencilSettings*,
87                             SkRegion::Op op,
88                             bool invert,
89                             GrAA,
90                             const SkMatrix& viewMatrix,
91                             const SkPath&);
92 
93     SkBudgeted isBudgeted() const;
94 
95     int maxWindowRectangles() const;
96 
97     /*
98      * This unique ID will not change for a given RenderTargetContext. However, it is _NOT_
99      * guaranteed to match the uniqueID of the underlying GrRenderTarget - beware!
100      */
uniqueID()101     GrSurfaceProxy::UniqueID uniqueID() const {
102         return fRenderTargetContext->fRenderTargetProxy->uniqueID();
103     }
104 
105     uint32_t testingOnly_addMeshDrawOp(GrPaint&&, GrAAType, std::unique_ptr<GrMeshDrawOp>,
106                                        const GrUserStencilSettings* = nullptr,
107                                        bool snapToCenters = false);
108 
refsWrappedObjects()109     bool refsWrappedObjects() const {
110         return fRenderTargetContext->fRenderTargetProxy->refsWrappedObjects();
111     }
112 
113 private:
GrRenderTargetContextPriv(GrRenderTargetContext * renderTargetContext)114     explicit GrRenderTargetContextPriv(GrRenderTargetContext* renderTargetContext)
115         : fRenderTargetContext(renderTargetContext) {}
GrRenderTargetContextPriv(const GrRenderTargetPriv &)116     GrRenderTargetContextPriv(const GrRenderTargetPriv&) {} // unimpl
117     GrRenderTargetContextPriv& operator=(const GrRenderTargetPriv&); // unimpl
118 
119     // No taking addresses of this type.
120     const GrRenderTargetContextPriv* operator&() const;
121     GrRenderTargetContextPriv* operator&();
122 
123     GrRenderTargetContext* fRenderTargetContext;
124 
125     friend class GrRenderTargetContext; // to construct/copy this type.
126 };
127 
priv()128 inline GrRenderTargetContextPriv GrRenderTargetContext::priv() {
129     return GrRenderTargetContextPriv(this);
130 }
131 
priv()132 inline const GrRenderTargetContextPriv GrRenderTargetContext::priv() const {
133     return GrRenderTargetContextPriv(const_cast<GrRenderTargetContext*>(this));
134 }
135 
136 #endif
137