blob: 68cbf268cc7e0b7f69e5e7c48e2f275083d22730 [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
Michael Ludwigaa1b6b32019-05-29 14:43:13 -040052 // While this can take a general clip, since GrReducedClip relies on this function, it must take
53 // care to only provide hard clips or we could get stuck in a loop. The general clip is needed
54 // so that path renderers can use this function.
Chris Dalton09e56892019-03-13 00:22:01 -060055 void stencilRect(
Michael Ludwig61328202019-06-19 14:48:58 +000056 const GrClip& clip, const GrUserStencilSettings* ss, GrPaint&& paint,
57 GrAA doStencilMSAA, const SkMatrix& viewMatrix, const SkRect& rect,
58 const SkMatrix* localMatrix = nullptr) {
59 // Since this provides stencil settings to drawFilledQuad, it performs a different AA type
60 // resolution compared to regular rect draws, which is the main reason it remains separate.
61 GrQuad localQuad = localMatrix ? GrQuad::MakeFromRect(rect, *localMatrix) : GrQuad(rect);
62 fRenderTargetContext->drawFilledQuad(
63 clip, std::move(paint), doStencilMSAA, GrQuadAAFlags::kNone,
64 GrQuad::MakeFromRect(rect, viewMatrix), localQuad, ss);
65 }
Brian Osman11052242016-10-27 14:47:55 -040066
Chris Dalton09e56892019-03-13 00:22:01 -060067 void stencilPath(
Robert Phillipse1efd382019-08-21 10:07:10 -040068 const GrHardClip&, GrAA doStencilMSAA, const SkMatrix& viewMatrix, sk_sp<const GrPath>);
Brian Osman11052242016-10-27 14:47:55 -040069
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050070 /**
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050071 * Draws a path, either AA or not, and touches the stencil buffer with the user stencil settings
72 * for each color sample written.
73 */
Chris Daltonbbfd5162017-11-07 13:35:22 -070074 bool drawAndStencilPath(const GrHardClip&,
Brian Osman11052242016-10-27 14:47:55 -040075 const GrUserStencilSettings*,
76 SkRegion::Op op,
77 bool invert,
Chris Dalton09e56892019-03-13 00:22:01 -060078 GrAA doStencilMSAA,
Brian Osman11052242016-10-27 14:47:55 -040079 const SkMatrix& viewMatrix,
80 const SkPath&);
81
82 SkBudgeted isBudgeted() const;
83
Robert Phillipsec2249f2016-11-09 08:54:35 -050084 int maxWindowRectangles() const;
85
Robert Phillips294870f2016-11-11 12:38:40 -050086 /*
87 * This unique ID will not change for a given RenderTargetContext. However, it is _NOT_
88 * guaranteed to match the uniqueID of the underlying GrRenderTarget - beware!
89 */
90 GrSurfaceProxy::UniqueID uniqueID() const {
Greg Daniel46e366a2019-12-16 14:38:36 -050091 return fRenderTargetContext->fSurfaceProxy->uniqueID();
Robert Phillips294870f2016-11-11 12:38:40 -050092 }
93
Greg Danielf41b2bd2019-08-22 16:19:24 -040094 uint32_t testingOnly_getOpsTaskID();
Brian Salomon348a0372018-10-31 10:42:18 -040095
96 using WillAddOpFn = GrRenderTargetContext::WillAddOpFn;
97 void testingOnly_addDrawOp(std::unique_ptr<GrDrawOp>);
98 void testingOnly_addDrawOp(const GrClip&, std::unique_ptr<GrDrawOp>,
99 const std::function<WillAddOpFn>& = std::function<WillAddOpFn>());
Brian Salomonac70f842017-05-08 10:43:33 -0400100
Robert Phillipse2f7d182016-12-15 09:23:05 -0500101 bool refsWrappedObjects() const {
Greg Daniel46e366a2019-12-16 14:38:36 -0500102 return fRenderTargetContext->asRenderTargetProxy()->refsWrappedObjects();
Robert Phillipse2f7d182016-12-15 09:23:05 -0500103 }
104
Brian Osman11052242016-10-27 14:47:55 -0400105private:
106 explicit GrRenderTargetContextPriv(GrRenderTargetContext* renderTargetContext)
107 : fRenderTargetContext(renderTargetContext) {}
108 GrRenderTargetContextPriv(const GrRenderTargetPriv&) {} // unimpl
109 GrRenderTargetContextPriv& operator=(const GrRenderTargetPriv&); // unimpl
110
111 // No taking addresses of this type.
112 const GrRenderTargetContextPriv* operator&() const;
113 GrRenderTargetContextPriv* operator&();
114
115 GrRenderTargetContext* fRenderTargetContext;
116
117 friend class GrRenderTargetContext; // to construct/copy this type.
118};
119
Brian Osman693a5402016-10-27 15:13:22 -0400120inline GrRenderTargetContextPriv GrRenderTargetContext::priv() {
Brian Osman11052242016-10-27 14:47:55 -0400121 return GrRenderTargetContextPriv(this);
122}
123
Brian Osman693a5402016-10-27 15:13:22 -0400124inline const GrRenderTargetContextPriv GrRenderTargetContext::priv() const {
Brian Osman11052242016-10-27 14:47:55 -0400125 return GrRenderTargetContextPriv(const_cast<GrRenderTargetContext*>(this));
126}
127
128#endif