blob: ef60655f8a6fbd6718699957b2b151100982ca5c [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "src/gpu/GrPathRendering.h"
12#include "src/gpu/GrRenderTargetContext.h"
13#include "src/gpu/GrRenderTargetOpList.h"
Brian Osman11052242016-10-27 14:47:55 -040014
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
Michael Ludwigaa1b6b32019-05-29 14:43:13 -040065 // While this can take a general clip, since GrReducedClip relies on this function, it must take
66 // care to only provide hard clips or we could get stuck in a loop. The general clip is needed
67 // so that path renderers can use this function.
Chris Dalton09e56892019-03-13 00:22:01 -060068 void stencilRect(
Michael Ludwig61328202019-06-19 14:48:58 +000069 const GrClip& clip, const GrUserStencilSettings* ss, GrPaint&& paint,
70 GrAA doStencilMSAA, const SkMatrix& viewMatrix, const SkRect& rect,
71 const SkMatrix* localMatrix = nullptr) {
72 // Since this provides stencil settings to drawFilledQuad, it performs a different AA type
73 // resolution compared to regular rect draws, which is the main reason it remains separate.
74 GrQuad localQuad = localMatrix ? GrQuad::MakeFromRect(rect, *localMatrix) : GrQuad(rect);
75 fRenderTargetContext->drawFilledQuad(
76 clip, std::move(paint), doStencilMSAA, GrQuadAAFlags::kNone,
77 GrQuad::MakeFromRect(rect, viewMatrix), localQuad, ss);
78 }
Brian Osman11052242016-10-27 14:47:55 -040079
Chris Dalton09e56892019-03-13 00:22:01 -060080 void stencilPath(
81 const GrHardClip&, GrAA doStencilMSAA, const SkMatrix& viewMatrix, const GrPath*);
Brian Osman11052242016-10-27 14:47:55 -040082
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050083 /**
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050084 * Draws a path, either AA or not, and touches the stencil buffer with the user stencil settings
85 * for each color sample written.
86 */
Chris Daltonbbfd5162017-11-07 13:35:22 -070087 bool drawAndStencilPath(const GrHardClip&,
Brian Osman11052242016-10-27 14:47:55 -040088 const GrUserStencilSettings*,
89 SkRegion::Op op,
90 bool invert,
Chris Dalton09e56892019-03-13 00:22:01 -060091 GrAA doStencilMSAA,
Brian Osman11052242016-10-27 14:47:55 -040092 const SkMatrix& viewMatrix,
93 const SkPath&);
94
95 SkBudgeted isBudgeted() const;
96
Robert Phillipsec2249f2016-11-09 08:54:35 -050097 int maxWindowRectangles() const;
98
Robert Phillips294870f2016-11-11 12:38:40 -050099 /*
100 * This unique ID will not change for a given RenderTargetContext. However, it is _NOT_
101 * guaranteed to match the uniqueID of the underlying GrRenderTarget - beware!
102 */
103 GrSurfaceProxy::UniqueID uniqueID() const {
104 return fRenderTargetContext->fRenderTargetProxy->uniqueID();
105 }
106
Chris Daltona32a3c32017-12-05 10:05:21 -0700107 uint32_t testingOnly_getOpListID();
Brian Salomon348a0372018-10-31 10:42:18 -0400108
109 using WillAddOpFn = GrRenderTargetContext::WillAddOpFn;
110 void testingOnly_addDrawOp(std::unique_ptr<GrDrawOp>);
111 void testingOnly_addDrawOp(const GrClip&, std::unique_ptr<GrDrawOp>,
112 const std::function<WillAddOpFn>& = std::function<WillAddOpFn>());
Brian Salomonac70f842017-05-08 10:43:33 -0400113
Robert Phillipse2f7d182016-12-15 09:23:05 -0500114 bool refsWrappedObjects() const {
115 return fRenderTargetContext->fRenderTargetProxy->refsWrappedObjects();
116 }
117
Brian Osman11052242016-10-27 14:47:55 -0400118private:
119 explicit GrRenderTargetContextPriv(GrRenderTargetContext* renderTargetContext)
120 : fRenderTargetContext(renderTargetContext) {}
121 GrRenderTargetContextPriv(const GrRenderTargetPriv&) {} // unimpl
122 GrRenderTargetContextPriv& operator=(const GrRenderTargetPriv&); // unimpl
123
124 // No taking addresses of this type.
125 const GrRenderTargetContextPriv* operator&() const;
126 GrRenderTargetContextPriv* operator&();
127
128 GrRenderTargetContext* fRenderTargetContext;
129
130 friend class GrRenderTargetContext; // to construct/copy this type.
131};
132
Brian Osman693a5402016-10-27 15:13:22 -0400133inline GrRenderTargetContextPriv GrRenderTargetContext::priv() {
Brian Osman11052242016-10-27 14:47:55 -0400134 return GrRenderTargetContextPriv(this);
135}
136
Brian Osman693a5402016-10-27 15:13:22 -0400137inline const GrRenderTargetContextPriv GrRenderTargetContext::priv() const {
Brian Osman11052242016-10-27 14:47:55 -0400138 return GrRenderTargetContextPriv(const_cast<GrRenderTargetContext*>(this));
139}
140
141#endif