• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
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     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     void drawFilledRect(
98             const GrClip& clip, GrPaint&& paint, GrAA aa, const SkMatrix& m, const SkRect& rect,
99             const GrUserStencilSettings* ss = nullptr) {
100         fRenderTargetContext->drawFilledRect(clip, std::move(paint), aa, m, rect, ss);
101     }
102 
103     SkBudgeted isBudgeted() const;
104 
105     int maxWindowRectangles() const;
106 
107     /*
108      * This unique ID will not change for a given RenderTargetContext. However, it is _NOT_
109      * guaranteed to match the uniqueID of the underlying GrRenderTarget - beware!
110      */
uniqueID()111     GrSurfaceProxy::UniqueID uniqueID() const {
112         return fRenderTargetContext->fRenderTargetProxy->uniqueID();
113     }
114 
115     uint32_t testingOnly_getOpListID();
116 
117     using WillAddOpFn = GrRenderTargetContext::WillAddOpFn;
118     void testingOnly_addDrawOp(std::unique_ptr<GrDrawOp>);
119     void testingOnly_addDrawOp(const GrClip&, std::unique_ptr<GrDrawOp>,
120                                const std::function<WillAddOpFn>& = std::function<WillAddOpFn>());
121 
refsWrappedObjects()122     bool refsWrappedObjects() const {
123         return fRenderTargetContext->fRenderTargetProxy->refsWrappedObjects();
124     }
125 
126 private:
GrRenderTargetContextPriv(GrRenderTargetContext * renderTargetContext)127     explicit GrRenderTargetContextPriv(GrRenderTargetContext* renderTargetContext)
128         : fRenderTargetContext(renderTargetContext) {}
GrRenderTargetContextPriv(const GrRenderTargetPriv &)129     GrRenderTargetContextPriv(const GrRenderTargetPriv&) {} // unimpl
130     GrRenderTargetContextPriv& operator=(const GrRenderTargetPriv&); // unimpl
131 
132     // No taking addresses of this type.
133     const GrRenderTargetContextPriv* operator&() const;
134     GrRenderTargetContextPriv* operator&();
135 
136     GrRenderTargetContext* fRenderTargetContext;
137 
138     friend class GrRenderTargetContext; // to construct/copy this type.
139 };
140 
priv()141 inline GrRenderTargetContextPriv GrRenderTargetContext::priv() {
142     return GrRenderTargetContextPriv(this);
143 }
144 
priv()145 inline const GrRenderTargetContextPriv GrRenderTargetContext::priv() const {
146     return GrRenderTargetContextPriv(const_cast<GrRenderTargetContext*>(this));
147 }
148 
149 #endif
150