blob: 2acda23a595c6f779e62b3fba03ab45917e95d79 [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;
17struct 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. */
22class GrRenderTargetContextPriv {
23public:
24 gr_instanced::InstancedRendering* accessInstancedRendering() const {
25 return fRenderTargetContext->getOpList()->instancedRendering();
26 }
27
csmartdalton7cdda992016-11-01 07:03:03 -070028 // called to note the last clip drawn to the stencil buffer.
29 // TODO: remove after clipping overhaul.
Brian Salomon9a767722017-03-13 17:57:28 -040030 void setLastClip(int32_t clipStackGenID, const SkIRect& devClipBounds) {
csmartdalton7cdda992016-11-01 07:03:03 -070031 GrRenderTargetOpList* opList = fRenderTargetContext->getOpList();
32 opList->fLastClipStackGenID = clipStackGenID;
Brian Salomon9a767722017-03-13 17:57:28 -040033 opList->fLastDevClipBounds = devClipBounds;
csmartdalton7cdda992016-11-01 07:03:03 -070034 }
35
36 // called to determine if we have to render the clip into SB.
37 // TODO: remove after clipping overhaul.
Brian Salomon9a767722017-03-13 17:57:28 -040038 bool mustRenderClip(int32_t clipStackGenID, const SkIRect& devClipBounds) const {
csmartdalton7cdda992016-11-01 07:03:03 -070039 GrRenderTargetOpList* opList = fRenderTargetContext->getOpList();
40 return opList->fLastClipStackGenID != clipStackGenID ||
Brian Salomon9a767722017-03-13 17:57:28 -040041 !opList->fLastDevClipBounds.contains(devClipBounds);
csmartdalton7cdda992016-11-01 07:03:03 -070042 }
43
Brian Osman11052242016-10-27 14:47:55 -040044 void clear(const GrFixedClip&, const GrColor, bool canIgnoreClip);
45
46 void clearStencilClip(const GrFixedClip&, bool insideStencilMask);
47
Robert Phillips784b7bf2016-12-09 13:35:02 -050048 /*
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
Brian Osman11052242016-10-27 14:47:55 -040061 void stencilRect(const GrClip& clip,
62 const GrUserStencilSettings* ss,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050063 GrAAType,
Brian Osman11052242016-10-27 14:47:55 -040064 const SkMatrix& viewMatrix,
65 const SkRect& rect);
66
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050067 void stencilPath(const GrClip&, GrAAType, const SkMatrix& viewMatrix, const GrPath*);
Brian Osman11052242016-10-27 14:47:55 -040068
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050069 /**
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 */
Brian Osman11052242016-10-27 14:47:55 -040073 bool drawAndStencilRect(const GrClip&,
74 const GrUserStencilSettings*,
75 SkRegion::Op op,
76 bool invert,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050077 GrAA,
Brian Osman11052242016-10-27 14:47:55 -040078 const SkMatrix& viewMatrix,
79 const SkRect&);
80
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050081 /**
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 */
Brian Osman11052242016-10-27 14:47:55 -040085 bool drawAndStencilPath(const GrClip&,
86 const GrUserStencilSettings*,
87 SkRegion::Op op,
88 bool invert,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050089 GrAA,
Brian Osman11052242016-10-27 14:47:55 -040090 const SkMatrix& viewMatrix,
91 const SkPath&);
92
93 SkBudgeted isBudgeted() const;
94
Robert Phillipsec2249f2016-11-09 08:54:35 -050095 int maxWindowRectangles() const;
96
Robert Phillips294870f2016-11-11 12:38:40 -050097 /*
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 */
101 GrSurfaceProxy::UniqueID uniqueID() const {
102 return fRenderTargetContext->fRenderTargetProxy->uniqueID();
103 }
104
Brian Salomond3ccb0a2017-04-03 10:38:00 -0400105 uint32_t testingOnly_addLegacyMeshDrawOp(GrPaint&&, GrAAType,
106 std::unique_ptr<GrLegacyMeshDrawOp>,
107 const GrUserStencilSettings* = nullptr,
108 bool snapToCenters = false);
Brian Osman11052242016-10-27 14:47:55 -0400109
Brian Salomonac70f842017-05-08 10:43:33 -0400110 uint32_t testingOnly_addDrawOp(std::unique_ptr<GrDrawOp>);
111
Robert Phillipse2f7d182016-12-15 09:23:05 -0500112 bool refsWrappedObjects() const {
113 return fRenderTargetContext->fRenderTargetProxy->refsWrappedObjects();
114 }
115
Brian Osman11052242016-10-27 14:47:55 -0400116private:
117 explicit GrRenderTargetContextPriv(GrRenderTargetContext* renderTargetContext)
118 : fRenderTargetContext(renderTargetContext) {}
119 GrRenderTargetContextPriv(const GrRenderTargetPriv&) {} // unimpl
120 GrRenderTargetContextPriv& operator=(const GrRenderTargetPriv&); // unimpl
121
122 // No taking addresses of this type.
123 const GrRenderTargetContextPriv* operator&() const;
124 GrRenderTargetContextPriv* operator&();
125
126 GrRenderTargetContext* fRenderTargetContext;
127
128 friend class GrRenderTargetContext; // to construct/copy this type.
129};
130
Brian Osman693a5402016-10-27 15:13:22 -0400131inline GrRenderTargetContextPriv GrRenderTargetContext::priv() {
Brian Osman11052242016-10-27 14:47:55 -0400132 return GrRenderTargetContextPriv(this);
133}
134
Brian Osman693a5402016-10-27 15:13:22 -0400135inline const GrRenderTargetContextPriv GrRenderTargetContext::priv() const {
Brian Osman11052242016-10-27 14:47:55 -0400136 return GrRenderTargetContextPriv(const_cast<GrRenderTargetContext*>(this));
137}
138
139#endif