blob: 8a1061c0d0f93a8ae4bdcb2329e8dc34f3f3e2de [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.
30 void setLastClip(int32_t clipStackGenID,
31 const SkIRect& clipSpaceRect,
32 const SkIPoint clipOrigin) {
33 GrRenderTargetOpList* opList = fRenderTargetContext->getOpList();
34 opList->fLastClipStackGenID = clipStackGenID;
35 opList->fLastClipStackRect = clipSpaceRect;
36 opList->fLastClipOrigin = clipOrigin;
37 }
38
39 // called to determine if we have to render the clip into SB.
40 // TODO: remove after clipping overhaul.
41 bool mustRenderClip(int32_t clipStackGenID,
42 const SkIRect& clipSpaceRect,
43 const SkIPoint& clipOrigin) const {
44 GrRenderTargetOpList* opList = fRenderTargetContext->getOpList();
45 return opList->fLastClipStackGenID != clipStackGenID ||
46 opList->fLastClipOrigin != clipOrigin ||
47 !opList->fLastClipStackRect.contains(clipSpaceRect);
48 }
49
Brian Osman11052242016-10-27 14:47:55 -040050 void clear(const GrFixedClip&, const GrColor, bool canIgnoreClip);
51
52 void clearStencilClip(const GrFixedClip&, bool insideStencilMask);
53
Robert Phillips784b7bf2016-12-09 13:35:02 -050054 /*
55 * Some portions of the code, which use approximate-match rendertargets (i.e., ImageFilters),
56 * rely on clears that lie outside of the content region to still have an effect.
57 * For example, when sampling a decimated blurred image back up to full size, the GaussianBlur
58 * code draws 1-pixel rects along the left and bottom edges to be able to use bilerp for
59 * upsampling. The "absClear" entry point ignores the content bounds but does use the
60 * worst case (instantiated) bounds.
61 *
62 * @param rect if (!null) the rect to clear, otherwise it is a full screen clear
63 * @param color the color to clear to
64 */
65 void absClear(const SkIRect* rect, const GrColor color);
66
Brian Osman11052242016-10-27 14:47:55 -040067 void stencilRect(const GrClip& clip,
68 const GrUserStencilSettings* ss,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050069 GrAAType,
Brian Osman11052242016-10-27 14:47:55 -040070 const SkMatrix& viewMatrix,
71 const SkRect& rect);
72
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050073 void stencilPath(const GrClip&, GrAAType, const SkMatrix& viewMatrix, const GrPath*);
Brian Osman11052242016-10-27 14:47:55 -040074
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050075 /**
76 * Draws a rect, either AA or not, and touches the stencil buffer with the user stencil settings
77 * for each color sample written.
78 */
Brian Osman11052242016-10-27 14:47:55 -040079 bool drawAndStencilRect(const GrClip&,
80 const GrUserStencilSettings*,
81 SkRegion::Op op,
82 bool invert,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050083 GrAA,
Brian Osman11052242016-10-27 14:47:55 -040084 const SkMatrix& viewMatrix,
85 const SkRect&);
86
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050087 /**
88 * Draws a path, either AA or not, and touches the stencil buffer with the user stencil settings
89 * for each color sample written.
90 */
Brian Osman11052242016-10-27 14:47:55 -040091 bool drawAndStencilPath(const GrClip&,
92 const GrUserStencilSettings*,
93 SkRegion::Op op,
94 bool invert,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050095 GrAA,
Brian Osman11052242016-10-27 14:47:55 -040096 const SkMatrix& viewMatrix,
97 const SkPath&);
98
99 SkBudgeted isBudgeted() const;
100
Robert Phillipsec2249f2016-11-09 08:54:35 -0500101 int maxWindowRectangles() const;
102
Robert Phillips294870f2016-11-11 12:38:40 -0500103 /*
104 * This unique ID will not change for a given RenderTargetContext. However, it is _NOT_
105 * guaranteed to match the uniqueID of the underlying GrRenderTarget - beware!
106 */
107 GrSurfaceProxy::UniqueID uniqueID() const {
108 return fRenderTargetContext->fRenderTargetProxy->uniqueID();
109 }
110
Brian Salomon82f44312017-01-11 13:42:54 -0500111 void testingOnly_addDrawOp(GrPaint&&,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500112 GrAAType,
Brian Salomonf8334782017-01-03 09:42:58 -0500113 std::unique_ptr<GrDrawOp>,
Brian Osman11052242016-10-27 14:47:55 -0400114 const GrUserStencilSettings* = nullptr,
115 bool snapToCenters = false);
116
Robert Phillipse2f7d182016-12-15 09:23:05 -0500117 bool refsWrappedObjects() const {
118 return fRenderTargetContext->fRenderTargetProxy->refsWrappedObjects();
119 }
120
Brian Osman11052242016-10-27 14:47:55 -0400121private:
122 explicit GrRenderTargetContextPriv(GrRenderTargetContext* renderTargetContext)
123 : fRenderTargetContext(renderTargetContext) {}
124 GrRenderTargetContextPriv(const GrRenderTargetPriv&) {} // unimpl
125 GrRenderTargetContextPriv& operator=(const GrRenderTargetPriv&); // unimpl
126
127 // No taking addresses of this type.
128 const GrRenderTargetContextPriv* operator&() const;
129 GrRenderTargetContextPriv* operator&();
130
131 GrRenderTargetContext* fRenderTargetContext;
132
133 friend class GrRenderTargetContext; // to construct/copy this type.
134};
135
Brian Osman693a5402016-10-27 15:13:22 -0400136inline GrRenderTargetContextPriv GrRenderTargetContext::priv() {
Brian Osman11052242016-10-27 14:47:55 -0400137 return GrRenderTargetContextPriv(this);
138}
139
Brian Osman693a5402016-10-27 15:13:22 -0400140inline const GrRenderTargetContextPriv GrRenderTargetContext::priv() const {
Brian Osman11052242016-10-27 14:47:55 -0400141 return GrRenderTargetContextPriv(const_cast<GrRenderTargetContext*>(this));
142}
143
144#endif