blob: c06c8ca8040ee41d9453433f644fcef4ed8b25fc [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;
Chris Daltonbbfd5162017-11-07 13:35:22 -070016class GrHardClip;
Brian Osman11052242016-10-27 14:47:55 -040017class GrPath;
Robert Phillips2890fbf2017-07-26 15:48:41 -040018class GrRenderTargetPriv;
Brian Osman11052242016-10-27 14:47:55 -040019struct 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. */
24class GrRenderTargetContextPriv {
25public:
Brian Salomonc3833b42018-07-09 18:23:58 +000026 // called to note the last clip drawn to the stencil buffer.
27 // TODO: remove after clipping overhaul.
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;
csmartdalton7cdda992016-11-01 07:03:03 -070034 }
Brian Salomonc3833b42018-07-09 18:23:58 +000035
36 // called to determine if we have to render the clip into SB.
37 // TODO: remove after clipping overhaul.
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;
csmartdalton7cdda992016-11-01 07:03:03 -070044 }
45
Chris Dalton344e9032017-12-11 15:42:09 -070046 using CanClearFullscreen = GrRenderTargetContext::CanClearFullscreen;
47
Brian Osman9a9baae2018-11-05 15:06:26 -050048 void clear(const GrFixedClip&, const SkPMColor4f&, CanClearFullscreen);
Brian Osman11052242016-10-27 14:47:55 -040049
Jim Van Verth6a40abc2017-11-02 16:56:09 +000050 void clearStencilClip(const GrFixedClip&, bool insideStencilMask);
Brian Osman11052242016-10-27 14:47:55 -040051
Robert Phillips784b7bf2016-12-09 13:35:02 -050052 /*
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 */
Brian Osman9a9baae2018-11-05 15:06:26 -050063 void absClear(const SkIRect* rect, const SkPMColor4f& color);
Robert Phillips784b7bf2016-12-09 13:35:02 -050064
Chris Daltonbbfd5162017-11-07 13:35:22 -070065 void stencilRect(const GrHardClip&,
Brian Osman11052242016-10-27 14:47:55 -040066 const GrUserStencilSettings* ss,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050067 GrAAType,
Brian Osman11052242016-10-27 14:47:55 -040068 const SkMatrix& viewMatrix,
69 const SkRect& rect);
70
Chris Daltonbbfd5162017-11-07 13:35:22 -070071 void stencilPath(const GrHardClip&, GrAAType, const SkMatrix& viewMatrix, const GrPath*);
Brian Osman11052242016-10-27 14:47:55 -040072
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050073 /**
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 */
Chris Daltonbbfd5162017-11-07 13:35:22 -070077 bool drawAndStencilRect(const GrHardClip&,
Brian Osman11052242016-10-27 14:47:55 -040078 const GrUserStencilSettings*,
79 SkRegion::Op op,
80 bool invert,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050081 GrAA,
Brian Osman11052242016-10-27 14:47:55 -040082 const SkMatrix& viewMatrix,
83 const SkRect&);
84
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050085 /**
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 */
Chris Daltonbbfd5162017-11-07 13:35:22 -070089 bool drawAndStencilPath(const GrHardClip&,
Brian Osman11052242016-10-27 14:47:55 -040090 const GrUserStencilSettings*,
91 SkRegion::Op op,
92 bool invert,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050093 GrAA,
Brian Osman11052242016-10-27 14:47:55 -040094 const SkMatrix& viewMatrix,
95 const SkPath&);
96
97 SkBudgeted isBudgeted() const;
98
Robert Phillipsec2249f2016-11-09 08:54:35 -050099 int maxWindowRectangles() const;
100
Robert Phillips294870f2016-11-11 12:38:40 -0500101 /*
102 * This unique ID will not change for a given RenderTargetContext. However, it is _NOT_
103 * guaranteed to match the uniqueID of the underlying GrRenderTarget - beware!
104 */
105 GrSurfaceProxy::UniqueID uniqueID() const {
106 return fRenderTargetContext->fRenderTargetProxy->uniqueID();
107 }
108
Chris Daltona32a3c32017-12-05 10:05:21 -0700109 uint32_t testingOnly_getOpListID();
Brian Salomon348a0372018-10-31 10:42:18 -0400110
111 using WillAddOpFn = GrRenderTargetContext::WillAddOpFn;
112 void testingOnly_addDrawOp(std::unique_ptr<GrDrawOp>);
113 void testingOnly_addDrawOp(const GrClip&, std::unique_ptr<GrDrawOp>,
114 const std::function<WillAddOpFn>& = std::function<WillAddOpFn>());
Brian Salomonac70f842017-05-08 10:43:33 -0400115
Robert Phillipse2f7d182016-12-15 09:23:05 -0500116 bool refsWrappedObjects() const {
117 return fRenderTargetContext->fRenderTargetProxy->refsWrappedObjects();
118 }
119
Brian Osman11052242016-10-27 14:47:55 -0400120private:
121 explicit GrRenderTargetContextPriv(GrRenderTargetContext* renderTargetContext)
122 : fRenderTargetContext(renderTargetContext) {}
123 GrRenderTargetContextPriv(const GrRenderTargetPriv&) {} // unimpl
124 GrRenderTargetContextPriv& operator=(const GrRenderTargetPriv&); // unimpl
125
126 // No taking addresses of this type.
127 const GrRenderTargetContextPriv* operator&() const;
128 GrRenderTargetContextPriv* operator&();
129
130 GrRenderTargetContext* fRenderTargetContext;
131
132 friend class GrRenderTargetContext; // to construct/copy this type.
133};
134
Brian Osman693a5402016-10-27 15:13:22 -0400135inline GrRenderTargetContextPriv GrRenderTargetContext::priv() {
Brian Osman11052242016-10-27 14:47:55 -0400136 return GrRenderTargetContextPriv(this);
137}
138
Brian Osman693a5402016-10-27 15:13:22 -0400139inline const GrRenderTargetContextPriv GrRenderTargetContext::priv() const {
Brian Osman11052242016-10-27 14:47:55 -0400140 return GrRenderTargetContextPriv(const_cast<GrRenderTargetContext*>(this));
141}
142
143#endif