blob: a7f00706f2865335316eafadf3669b0f96d5b7a8 [file] [log] [blame]
Brian Osman11052242016-10-27 14:47:55 -04001/*
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
15class GrFixedClip;
16class GrPath;
Robert Phillips2890fbf2017-07-26 15:48:41 -040017class GrRenderTargetPriv;
Brian Osman11052242016-10-27 14:47:55 -040018struct GrUserStencilSettings;
19
20/** Class that adds methods to GrRenderTargetContext that are only intended for use internal to
21 Skia. This class is purely a privileged window into GrRenderTargetContext. It should never have
22 additional data members or virtual methods. */
23class GrRenderTargetContextPriv {
24public:
25 gr_instanced::InstancedRendering* accessInstancedRendering() const {
Robert Phillips2de8cfa2017-06-28 10:33:41 -040026 return fRenderTargetContext->getRTOpList()->instancedRendering();
Brian Osman11052242016-10-27 14:47:55 -040027 }
28
csmartdalton7cdda992016-11-01 07:03:03 -070029 // called to note the last clip drawn to the stencil buffer.
30 // TODO: remove after clipping overhaul.
Chris Daltond8d15932017-11-01 19:21:24 +000031 void setLastClip(uint32_t clipStackGenID, const SkIRect& devClipBounds) {
Robert Phillips2de8cfa2017-06-28 10:33:41 -040032 GrRenderTargetOpList* opList = fRenderTargetContext->getRTOpList();
csmartdalton7cdda992016-11-01 07:03:03 -070033 opList->fLastClipStackGenID = clipStackGenID;
Brian Salomon9a767722017-03-13 17:57:28 -040034 opList->fLastDevClipBounds = devClipBounds;
csmartdalton7cdda992016-11-01 07:03:03 -070035 }
36
37 // called to determine if we have to render the clip into SB.
38 // TODO: remove after clipping overhaul.
Chris Daltond8d15932017-11-01 19:21:24 +000039 bool mustRenderClip(uint32_t clipStackGenID, const SkIRect& devClipBounds) const {
Robert Phillips2de8cfa2017-06-28 10:33:41 -040040 GrRenderTargetOpList* opList = fRenderTargetContext->getRTOpList();
csmartdalton7cdda992016-11-01 07:03:03 -070041 return opList->fLastClipStackGenID != clipStackGenID ||
Chris Daltond8d15932017-11-01 19:21:24 +000042 !opList->fLastDevClipBounds.contains(devClipBounds);
csmartdalton7cdda992016-11-01 07:03:03 -070043 }
44
Brian Osman11052242016-10-27 14:47:55 -040045 void clear(const GrFixedClip&, const GrColor, bool canIgnoreClip);
46
Chris Dalton94c04682017-11-01 17:15:06 -060047 void clearStencilClip(const GrFixedClip&, bool insideStencilMask, bool canIgnoreClip);
Brian Osman11052242016-10-27 14:47:55 -040048
Robert Phillips784b7bf2016-12-09 13:35:02 -050049 /*
50 * Some portions of the code, which use approximate-match rendertargets (i.e., ImageFilters),
51 * rely on clears that lie outside of the content region to still have an effect.
52 * For example, when sampling a decimated blurred image back up to full size, the GaussianBlur
53 * code draws 1-pixel rects along the left and bottom edges to be able to use bilerp for
54 * upsampling. The "absClear" entry point ignores the content bounds but does use the
55 * worst case (instantiated) bounds.
56 *
57 * @param rect if (!null) the rect to clear, otherwise it is a full screen clear
58 * @param color the color to clear to
59 */
60 void absClear(const SkIRect* rect, const GrColor color);
61
Brian Osman11052242016-10-27 14:47:55 -040062 void stencilRect(const GrClip& clip,
63 const GrUserStencilSettings* ss,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050064 GrAAType,
Brian Osman11052242016-10-27 14:47:55 -040065 const SkMatrix& viewMatrix,
66 const SkRect& rect);
67
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050068 void stencilPath(const GrClip&, GrAAType, const SkMatrix& viewMatrix, const GrPath*);
Brian Osman11052242016-10-27 14:47:55 -040069
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050070 /**
71 * Draws a rect, either AA or not, and touches the stencil buffer with the user stencil settings
72 * for each color sample written.
73 */
Brian Osman11052242016-10-27 14:47:55 -040074 bool drawAndStencilRect(const GrClip&,
75 const GrUserStencilSettings*,
76 SkRegion::Op op,
77 bool invert,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050078 GrAA,
Brian Osman11052242016-10-27 14:47:55 -040079 const SkMatrix& viewMatrix,
80 const SkRect&);
81
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050082 /**
83 * Draws a path, either AA or not, and touches the stencil buffer with the user stencil settings
84 * for each color sample written.
85 */
Brian Osman11052242016-10-27 14:47:55 -040086 bool drawAndStencilPath(const GrClip&,
87 const GrUserStencilSettings*,
88 SkRegion::Op op,
89 bool invert,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050090 GrAA,
Brian Osman11052242016-10-27 14:47:55 -040091 const SkMatrix& viewMatrix,
92 const SkPath&);
93
94 SkBudgeted isBudgeted() const;
95
Robert Phillipsec2249f2016-11-09 08:54:35 -050096 int maxWindowRectangles() const;
97
Robert Phillips294870f2016-11-11 12:38:40 -050098 /*
99 * This unique ID will not change for a given RenderTargetContext. However, it is _NOT_
100 * guaranteed to match the uniqueID of the underlying GrRenderTarget - beware!
101 */
102 GrSurfaceProxy::UniqueID uniqueID() const {
103 return fRenderTargetContext->fRenderTargetProxy->uniqueID();
104 }
105
Brian Salomonac70f842017-05-08 10:43:33 -0400106 uint32_t testingOnly_addDrawOp(std::unique_ptr<GrDrawOp>);
107
Robert Phillipse2f7d182016-12-15 09:23:05 -0500108 bool refsWrappedObjects() const {
109 return fRenderTargetContext->fRenderTargetProxy->refsWrappedObjects();
110 }
111
Brian Osman11052242016-10-27 14:47:55 -0400112private:
113 explicit GrRenderTargetContextPriv(GrRenderTargetContext* renderTargetContext)
114 : fRenderTargetContext(renderTargetContext) {}
115 GrRenderTargetContextPriv(const GrRenderTargetPriv&) {} // unimpl
116 GrRenderTargetContextPriv& operator=(const GrRenderTargetPriv&); // unimpl
117
118 // No taking addresses of this type.
119 const GrRenderTargetContextPriv* operator&() const;
120 GrRenderTargetContextPriv* operator&();
121
122 GrRenderTargetContext* fRenderTargetContext;
123
124 friend class GrRenderTargetContext; // to construct/copy this type.
125};
126
Brian Osman693a5402016-10-27 15:13:22 -0400127inline GrRenderTargetContextPriv GrRenderTargetContext::priv() {
Brian Osman11052242016-10-27 14:47:55 -0400128 return GrRenderTargetContextPriv(this);
129}
130
Brian Osman693a5402016-10-27 15:13:22 -0400131inline const GrRenderTargetContextPriv GrRenderTargetContext::priv() const {
Brian Osman11052242016-10-27 14:47:55 -0400132 return GrRenderTargetContextPriv(const_cast<GrRenderTargetContext*>(this));
133}
134
135#endif