blob: b29011d85550e43de799fa98e91096f7dbe412ba [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
Greg Danielf41b2bd2019-08-22 16:19:24 -040011#include "src/gpu/GrOpsTask.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "src/gpu/GrPathRendering.h"
13#include "src/gpu/GrRenderTargetContext.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) {
Greg Danielf41b2bd2019-08-22 16:19:24 -040030 GrOpsTask* opsTask = fRenderTargetContext->getOpsTask();
31 opsTask->fLastClipStackGenID = clipStackGenID;
32 opsTask->fLastDevClipBounds = devClipBounds;
33 opsTask->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 {
Greg Danielf41b2bd2019-08-22 16:19:24 -040040 GrOpsTask* opsTask = fRenderTargetContext->getOpsTask();
41 return opsTask->fLastClipStackGenID != clipStackGenID ||
42 !opsTask->fLastDevClipBounds.contains(devClipBounds) ||
43 opsTask->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
Chris Dalton69371032019-09-18 15:44:25 +000052 /*
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 * This call will always clear to transparent black.
61 *
62 * @param rect if (!null) the rect to clear, otherwise it is a full screen clear
63 */
64 void absClear(const SkIRect* rect);
65
Michael Ludwigaa1b6b32019-05-29 14:43:13 -040066 // While this can take a general clip, since GrReducedClip relies on this function, it must take
67 // care to only provide hard clips or we could get stuck in a loop. The general clip is needed
68 // so that path renderers can use this function.
Chris Dalton09e56892019-03-13 00:22:01 -060069 void stencilRect(
Michael Ludwig61328202019-06-19 14:48:58 +000070 const GrClip& clip, const GrUserStencilSettings* ss, GrPaint&& paint,
71 GrAA doStencilMSAA, const SkMatrix& viewMatrix, const SkRect& rect,
72 const SkMatrix* localMatrix = nullptr) {
73 // Since this provides stencil settings to drawFilledQuad, it performs a different AA type
74 // resolution compared to regular rect draws, which is the main reason it remains separate.
75 GrQuad localQuad = localMatrix ? GrQuad::MakeFromRect(rect, *localMatrix) : GrQuad(rect);
76 fRenderTargetContext->drawFilledQuad(
77 clip, std::move(paint), doStencilMSAA, GrQuadAAFlags::kNone,
78 GrQuad::MakeFromRect(rect, viewMatrix), localQuad, ss);
79 }
Brian Osman11052242016-10-27 14:47:55 -040080
Chris Dalton09e56892019-03-13 00:22:01 -060081 void stencilPath(
Robert Phillipse1efd382019-08-21 10:07:10 -040082 const GrHardClip&, GrAA doStencilMSAA, const SkMatrix& viewMatrix, sk_sp<const GrPath>);
Brian Osman11052242016-10-27 14:47:55 -040083
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050084 /**
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050085 * Draws a path, either AA or not, and touches the stencil buffer with the user stencil settings
86 * for each color sample written.
87 */
Chris Daltonbbfd5162017-11-07 13:35:22 -070088 bool drawAndStencilPath(const GrHardClip&,
Brian Osman11052242016-10-27 14:47:55 -040089 const GrUserStencilSettings*,
90 SkRegion::Op op,
91 bool invert,
Chris Dalton09e56892019-03-13 00:22:01 -060092 GrAA doStencilMSAA,
Brian Osman11052242016-10-27 14:47:55 -040093 const SkMatrix& viewMatrix,
94 const SkPath&);
95
96 SkBudgeted isBudgeted() const;
97
Robert Phillipsec2249f2016-11-09 08:54:35 -050098 int maxWindowRectangles() const;
99
Robert Phillips294870f2016-11-11 12:38:40 -0500100 /*
101 * This unique ID will not change for a given RenderTargetContext. However, it is _NOT_
102 * guaranteed to match the uniqueID of the underlying GrRenderTarget - beware!
103 */
104 GrSurfaceProxy::UniqueID uniqueID() const {
105 return fRenderTargetContext->fRenderTargetProxy->uniqueID();
106 }
107
Greg Danielf41b2bd2019-08-22 16:19:24 -0400108 uint32_t testingOnly_getOpsTaskID();
Brian Salomon348a0372018-10-31 10:42:18 -0400109
110 using WillAddOpFn = GrRenderTargetContext::WillAddOpFn;
111 void testingOnly_addDrawOp(std::unique_ptr<GrDrawOp>);
112 void testingOnly_addDrawOp(const GrClip&, std::unique_ptr<GrDrawOp>,
113 const std::function<WillAddOpFn>& = std::function<WillAddOpFn>());
Brian Salomonac70f842017-05-08 10:43:33 -0400114
Robert Phillipse2f7d182016-12-15 09:23:05 -0500115 bool refsWrappedObjects() const {
116 return fRenderTargetContext->fRenderTargetProxy->refsWrappedObjects();
117 }
118
Brian Osman11052242016-10-27 14:47:55 -0400119private:
120 explicit GrRenderTargetContextPriv(GrRenderTargetContext* renderTargetContext)
121 : fRenderTargetContext(renderTargetContext) {}
122 GrRenderTargetContextPriv(const GrRenderTargetPriv&) {} // unimpl
123 GrRenderTargetContextPriv& operator=(const GrRenderTargetPriv&); // unimpl
124
125 // No taking addresses of this type.
126 const GrRenderTargetContextPriv* operator&() const;
127 GrRenderTargetContextPriv* operator&();
128
129 GrRenderTargetContext* fRenderTargetContext;
130
131 friend class GrRenderTargetContext; // to construct/copy this type.
132};
133
Brian Osman693a5402016-10-27 15:13:22 -0400134inline GrRenderTargetContextPriv GrRenderTargetContext::priv() {
Brian Osman11052242016-10-27 14:47:55 -0400135 return GrRenderTargetContextPriv(this);
136}
137
Brian Osman693a5402016-10-27 15:13:22 -0400138inline const GrRenderTargetContextPriv GrRenderTargetContext::priv() const {
Brian Osman11052242016-10-27 14:47:55 -0400139 return GrRenderTargetContextPriv(const_cast<GrRenderTargetContext*>(this));
140}
141
142#endif