blob: 55d3a04a374dec49f9a3723587448488e0df9c83 [file] [log] [blame]
robertphillipsea461502015-05-26 11:38:03 -07001/*
2 * Copyright 2015 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
Brian Osman11052242016-10-27 14:47:55 -04008#ifndef GrRenderTargetContext_DEFINED
9#define GrRenderTargetContext_DEFINED
robertphillipsea461502015-05-26 11:38:03 -070010
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkCanvas.h"
12#include "include/core/SkDrawable.h"
13#include "include/core/SkRefCnt.h"
14#include "include/core/SkSurface.h"
15#include "include/core/SkSurfaceProps.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050016#include "include/private/GrTypesPriv.h"
Herb Derbyd29207a2020-06-08 13:50:19 -040017#include "src/core/SkGlyphRunPainter.h"
Greg Danielf41b2bd2019-08-22 16:19:24 -040018#include "src/gpu/GrOpsTask.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050019#include "src/gpu/GrPaint.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040020#include "src/gpu/GrRenderTargetProxy.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050021#include "src/gpu/GrSurfaceContext.h"
Greg Daniela83de582019-10-22 09:33:25 -040022#include "src/gpu/GrSurfaceProxyView.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050023#include "src/gpu/GrXferProcessor.h"
Michael Ludwig61328202019-06-19 14:48:58 +000024#include "src/gpu/geometry/GrQuad.h"
Herb Derby35c42b92020-07-10 10:48:57 -040025#include "src/gpu/text/GrTextBlob.h"
robertphillipsea461502015-05-26 11:38:03 -070026
Herb Derby411e7aa2020-07-09 16:02:08 -040027#include <tuple>
28
Greg Daniela5cb7812017-06-16 09:45:32 -040029class GrBackendSemaphore;
robertphillipsea461502015-05-26 11:38:03 -070030class GrClip;
Brian Osman2240be92017-10-18 13:15:13 -040031class GrColorSpaceXform;
Chris Dalton1a325d22017-07-14 15:17:41 -060032class GrCoverageCountingPathRenderer;
Brian Salomon9afd3712016-12-01 10:59:09 -050033class GrDrawOp;
Robert Phillips0d075de2019-03-04 11:08:13 -050034class GrOp;
robertphillipsea461502015-05-26 11:38:03 -070035class GrRenderTarget;
Brian Osman45580d32016-11-23 09:37:01 -050036class GrRenderTargetContextPriv;
Michael Ludwig2686d692020-04-17 20:21:37 +000037class GrStyledShape;
bsalomon6663acf2016-05-10 09:14:17 -070038class GrStyle;
Robert Phillipseaa86252016-11-08 13:49:39 +000039class GrTextureProxy;
robertphillips44302392016-07-08 14:43:03 -070040struct GrUserStencilSettings;
Jim Van Verth3af1af92017-05-18 15:06:54 -040041struct SkDrawShadowRec;
Herb Derbycddab252018-07-16 11:19:04 -040042class SkGlyphRunList;
robertphillipsea461502015-05-26 11:38:03 -070043struct SkIPoint;
44struct SkIRect;
msarett10e3d9b2016-08-18 15:46:03 -070045class SkLatticeIter;
Brian Osman449b1152020-04-15 16:43:00 -040046class SkMatrixProvider;
robertphillipsea461502015-05-26 11:38:03 -070047class SkMatrix;
robertphillips2334fb62015-06-17 05:43:33 -070048class SkPaint;
robertphillipsea461502015-05-26 11:38:03 -070049class SkPath;
50struct SkPoint;
51struct SkRect;
Brian Osman45580d32016-11-23 09:37:01 -050052class SkRegion;
robertphillipsea461502015-05-26 11:38:03 -070053class SkRRect;
jvanverth31ff7622015-08-07 10:09:28 -070054struct SkRSXform;
Brian Osman3c358422020-03-23 10:44:12 -040055class SkRuntimeEffect;
robertphillips2334fb62015-06-17 05:43:33 -070056class SkTextBlob;
Brian Salomon199fb872017-02-06 09:41:10 -050057class SkVertices;
robertphillipsea461502015-05-26 11:38:03 -070058
Brian Osman45580d32016-11-23 09:37:01 -050059/**
60 * A helper object to orchestrate commands (draws, etc...) for GrSurfaces that are GrRenderTargets.
robertphillipsea461502015-05-26 11:38:03 -070061 */
Brian Salomon3b8486a2020-04-21 12:43:26 -040062class GrRenderTargetContext : public GrSurfaceContext, public GrOpsTaskClosedObserver {
robertphillipsea461502015-05-26 11:38:03 -070063public:
Greg Daniele20fcad2020-01-08 11:52:34 -050064 static std::unique_ptr<GrRenderTargetContext> Make(
Greg Danielba0ff782020-01-07 15:42:57 -050065 GrRecordingContext*, GrColorType, sk_sp<SkColorSpace>, sk_sp<GrSurfaceProxy>,
66 GrSurfaceOrigin, const SkSurfaceProps*, bool managedOps = true);
67
Brian Salomona56a7462020-02-07 14:17:25 -050068 static std::unique_ptr<GrRenderTargetContext> Make(GrRecordingContext*,
69 GrColorType,
70 sk_sp<SkColorSpace>,
71 SkBackingFit,
72 SkISize dimensions,
73 const GrBackendFormat&,
74 int sampleCnt,
Brian Salomon7e67dca2020-07-21 09:27:25 -040075 GrMipmapped,
Brian Salomona56a7462020-02-07 14:17:25 -050076 GrProtected,
77 GrSurfaceOrigin,
78 SkBudgeted,
79 const SkSurfaceProps*);
Greg Daniele20fcad2020-01-08 11:52:34 -050080
81 // Same as above but will use the default GrBackendFormat for the given GrColorType
82 static std::unique_ptr<GrRenderTargetContext> Make(
Brian Salomona56a7462020-02-07 14:17:25 -050083 GrRecordingContext*,
84 GrColorType,
85 sk_sp<SkColorSpace>,
86 SkBackingFit,
87 SkISize dimensions,
88 int sampleCnt = 1,
Brian Salomon7e67dca2020-07-21 09:27:25 -040089 GrMipmapped = GrMipmapped::kNo,
Brian Salomona56a7462020-02-07 14:17:25 -050090 GrProtected = GrProtected::kNo,
91 GrSurfaceOrigin = kBottomLeft_GrSurfaceOrigin,
92 SkBudgeted = SkBudgeted::kYes,
93 const SkSurfaceProps* = nullptr);
Greg Daniele20fcad2020-01-08 11:52:34 -050094
Brian Salomond005b692020-04-01 15:47:05 -040095 static std::tuple<GrColorType, GrBackendFormat> GetFallbackColorTypeAndFormat(GrImageContext*,
Brian Salomon0029db02020-04-03 10:41:24 -040096 GrColorType,
97 int sampleCnt);
Brian Salomond005b692020-04-01 15:47:05 -040098
Greg Daniele20fcad2020-01-08 11:52:34 -050099 // Same as previous factory but will try to use fallback GrColorTypes if the one passed in
100 // fails. The fallback GrColorType will have at least the number of channels and precision per
101 // channel as the passed in GrColorType. It may also swizzle the changes (e.g., BGRA -> RGBA).
102 // SRGB-ness will be preserved.
103 static std::unique_ptr<GrRenderTargetContext> MakeWithFallback(
Brian Salomona56a7462020-02-07 14:17:25 -0500104 GrRecordingContext*,
105 GrColorType,
106 sk_sp<SkColorSpace>,
107 SkBackingFit,
108 SkISize dimensions,
109 int sampleCnt = 1,
Brian Salomon7e67dca2020-07-21 09:27:25 -0400110 GrMipmapped = GrMipmapped::kNo,
Brian Salomona56a7462020-02-07 14:17:25 -0500111 GrProtected = GrProtected::kNo,
112 GrSurfaceOrigin = kBottomLeft_GrSurfaceOrigin,
113 SkBudgeted = SkBudgeted::kYes,
114 const SkSurfaceProps* = nullptr);
Greg Daniele20fcad2020-01-08 11:52:34 -0500115
Greg Danielba0ff782020-01-07 15:42:57 -0500116 // These match the definitions in SkSurface & GrSurface.h, for whence they came
117 typedef void* ReleaseContext;
118 typedef void (*ReleaseProc)(ReleaseContext);
119
120 // Creates a GrRenderTargetContext that wraps the passed in GrBackendTexture.
121 static std::unique_ptr<GrRenderTargetContext> MakeFromBackendTexture(
122 GrRecordingContext*, GrColorType, sk_sp<SkColorSpace>, const GrBackendTexture&,
Robert Phillipsa1121332020-06-29 13:05:29 -0400123 int sampleCnt, GrSurfaceOrigin, const SkSurfaceProps*,
124 sk_sp<GrRefCntedCallback> releaseHelper);
Greg Danielba0ff782020-01-07 15:42:57 -0500125
126 static std::unique_ptr<GrRenderTargetContext> MakeFromBackendTextureAsRenderTarget(
127 GrRecordingContext*, GrColorType, sk_sp<SkColorSpace>, const GrBackendTexture&,
128 int sampleCnt, GrSurfaceOrigin, const SkSurfaceProps*);
129
130 static std::unique_ptr<GrRenderTargetContext> MakeFromBackendRenderTarget(
131 GrRecordingContext*, GrColorType, sk_sp<SkColorSpace>, const GrBackendRenderTarget&,
132 GrSurfaceOrigin, const SkSurfaceProps*, ReleaseProc releaseProc,
133 ReleaseContext releaseCtx);
134
135 static std::unique_ptr<GrRenderTargetContext> MakeFromVulkanSecondaryCB(
136 GrRecordingContext*, const SkImageInfo&, const GrVkDrawableInfo&,
137 const SkSurfaceProps*);
138
Greg Daniel3912a4b2020-01-14 09:56:04 -0500139 GrRenderTargetContext(GrRecordingContext*, GrSurfaceProxyView readView,
Brian Salomon8afde5f2020-04-01 16:22:00 -0400140 GrSurfaceProxyView writeView, GrColorType, sk_sp<SkColorSpace>,
Greg Daniel3912a4b2020-01-14 09:56:04 -0500141 const SkSurfaceProps*, bool managedOpsTask = true);
Greg Danielbfa19c42019-12-19 16:41:40 -0500142
Brian Osman11052242016-10-27 14:47:55 -0400143 ~GrRenderTargetContext() override;
robertphillips2334fb62015-06-17 05:43:33 -0700144
robertphillipsea461502015-05-26 11:38:03 -0700145 /**
146 * Provides a perfomance hint that the render target's contents are allowed
147 * to become undefined.
148 */
robertphillips2e1e51f2015-10-15 08:01:48 -0700149 void discard();
robertphillipsea461502015-05-26 11:38:03 -0700150
151 /**
Michael Ludwig81d41722020-05-26 16:57:38 -0400152 * Clear the rect of the render target to the given color.
153 * @param rect the rect to clear to
robertphillipsea461502015-05-26 11:38:03 -0700154 * @param color the color to clear to.
robertphillipsea461502015-05-26 11:38:03 -0700155 */
Michael Ludwig81d41722020-05-26 16:57:38 -0400156 void clear(const SkIRect& rect, const SkPMColor4f& color) {
157 this->internalClear(&rect, color);
158 }
159 // Clears the entire render target to the color.
Chris Dalton0493fbd2019-09-18 15:49:46 -0600160 void clear(const SkPMColor4f& color) {
Michael Ludwig81d41722020-05-26 16:57:38 -0400161 this->internalClear(nullptr, color);
Chris Dalton0493fbd2019-09-18 15:49:46 -0600162 }
163
robertphillipsea461502015-05-26 11:38:03 -0700164 /**
165 * Draw everywhere (respecting the clip) with the paint.
166 */
Michael Ludwig7c12e282020-05-29 09:54:07 -0400167 void drawPaint(const GrClip*, GrPaint&&, const SkMatrix& viewMatrix);
robertphillipsea461502015-05-26 11:38:03 -0700168
169 /**
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500170 * Draw the rect using a paint.
171 * @param paint describes how to color pixels.
172 * @param GrAA Controls whether rect is antialiased
173 * @param viewMatrix transformation matrix
174 * @param style The style to apply. Null means fill. Currently path effects are not
175 * allowed.
176 * The rects coords are used to access the paint (through texture matrix)
robertphillipsea461502015-05-26 11:38:03 -0700177 */
Michael Ludwig7c12e282020-05-29 09:54:07 -0400178 void drawRect(const GrClip*,
Brian Salomon82f44312017-01-11 13:42:54 -0500179 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500180 GrAA,
robertphillipsea461502015-05-26 11:38:03 -0700181 const SkMatrix& viewMatrix,
182 const SkRect&,
Brian Salomon82f44312017-01-11 13:42:54 -0500183 const GrStyle* style = nullptr);
robertphillipsea461502015-05-26 11:38:03 -0700184
185 /**
bsalomona2e69fc2015-11-05 10:41:43 -0800186 * Maps a rectangle of shader coordinates to a rectangle and fills that rectangle.
robertphillipsea461502015-05-26 11:38:03 -0700187 *
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500188 * @param paint describes how to color pixels.
189 * @param GrAA Controls whether rect is antialiased
190 * @param viewMatrix transformation matrix which applies to rectToDraw
191 * @param rectToDraw the rectangle to draw
192 * @param localRect the rectangle of shader coordinates applied to rectToDraw
robertphillipsea461502015-05-26 11:38:03 -0700193 */
Michael Ludwig7c12e282020-05-29 09:54:07 -0400194 void fillRectToRect(const GrClip* clip,
Brian Salomon82f44312017-01-11 13:42:54 -0500195 GrPaint&& paint,
Michael Ludwig136f45a2019-02-19 11:44:41 -0500196 GrAA aa,
bsalomona2e69fc2015-11-05 10:41:43 -0800197 const SkMatrix& viewMatrix,
198 const SkRect& rectToDraw,
Michael Ludwig136f45a2019-02-19 11:44:41 -0500199 const SkRect& localRect) {
Michael Ludwig6b45c5d2020-02-07 09:56:38 -0500200 DrawQuad quad{GrQuad::MakeFromRect(rectToDraw, viewMatrix), GrQuad(localRect),
201 aa == GrAA::kYes ? GrQuadAAFlags::kAll : GrQuadAAFlags::kNone};
202 this->drawFilledQuad(clip, std::move(paint), aa, &quad);
Michael Ludwig136f45a2019-02-19 11:44:41 -0500203 }
robertphillipsea461502015-05-26 11:38:03 -0700204
205 /**
bsalomona2e69fc2015-11-05 10:41:43 -0800206 * Fills a rect with a paint and a localMatrix.
robertphillipsea461502015-05-26 11:38:03 -0700207 */
Michael Ludwig7c12e282020-05-29 09:54:07 -0400208 void fillRectWithLocalMatrix(const GrClip* clip,
Brian Salomon82f44312017-01-11 13:42:54 -0500209 GrPaint&& paint,
Michael Ludwig61328202019-06-19 14:48:58 +0000210 GrAA aa,
bsalomona2e69fc2015-11-05 10:41:43 -0800211 const SkMatrix& viewMatrix,
212 const SkRect& rect,
Michael Ludwig61328202019-06-19 14:48:58 +0000213 const SkMatrix& localMatrix) {
Michael Ludwig6b45c5d2020-02-07 09:56:38 -0500214 DrawQuad quad{GrQuad::MakeFromRect(rect, viewMatrix),
215 GrQuad::MakeFromRect(rect, localMatrix),
216 aa == GrAA::kYes ? GrQuadAAFlags::kAll : GrQuadAAFlags::kNone};
217 this->drawFilledQuad(clip, std::move(paint), aa, &quad);
Michael Ludwig61328202019-06-19 14:48:58 +0000218 }
robertphillipsea461502015-05-26 11:38:03 -0700219
Michael Ludwig75451902019-01-23 11:14:29 -0500220 /**
221 * Creates an op that draws a fill rect with per-edge control over anti-aliasing.
Michael Ludwigce62dec2019-02-19 11:48:46 -0500222 *
223 * This is a specialized version of fillQuadWithEdgeAA, but is kept separate since knowing
224 * the geometry is a rectangle affords more optimizations.
Michael Ludwig75451902019-01-23 11:14:29 -0500225 */
Michael Ludwig7c12e282020-05-29 09:54:07 -0400226 void fillRectWithEdgeAA(const GrClip* clip, GrPaint&& paint, GrAA aa, GrQuadAAFlags edgeAA,
Michael Ludwig136f45a2019-02-19 11:44:41 -0500227 const SkMatrix& viewMatrix, const SkRect& rect,
Michael Ludwig61328202019-06-19 14:48:58 +0000228 const SkRect* optionalLocalRect = nullptr) {
229 const SkRect& localRect = optionalLocalRect ? *optionalLocalRect : rect;
Michael Ludwig6b45c5d2020-02-07 09:56:38 -0500230 DrawQuad quad{GrQuad::MakeFromRect(rect, viewMatrix), GrQuad(localRect), edgeAA};
231 this->drawFilledQuad(clip, std::move(paint), aa, &quad);
Michael Ludwig61328202019-06-19 14:48:58 +0000232 }
Michael Ludwig75451902019-01-23 11:14:29 -0500233
Michael Ludwigce62dec2019-02-19 11:48:46 -0500234 /**
235 * Similar to fillRectWithEdgeAA but draws an arbitrary 2D convex quadrilateral transformed
236 * by 'viewMatrix', with per-edge control over anti-aliasing. The quad should follow the
237 * ordering used by SkRect::toQuad(), which determines how the edge AA is applied:
238 * - "top" = points [0] and [1]
239 * - "right" = points[1] and [2]
240 * - "bottom" = points[2] and [3]
241 * - "left" = points[3] and [0]
242 *
243 * The last argument, 'optionalLocalQuad', can be null if no separate local coordinates are
244 * necessary.
245 */
Michael Ludwig7c12e282020-05-29 09:54:07 -0400246 void fillQuadWithEdgeAA(const GrClip* clip, GrPaint&& paint, GrAA aa, GrQuadAAFlags edgeAA,
Michael Ludwig6b45c5d2020-02-07 09:56:38 -0500247 const SkMatrix& viewMatrix, const SkPoint points[4],
248 const SkPoint optionalLocalPoints[4]) {
249 const SkPoint* localPoints = optionalLocalPoints ? optionalLocalPoints : points;
250 DrawQuad quad{GrQuad::MakeFromSkQuad(points, viewMatrix),
251 GrQuad::MakeFromSkQuad(localPoints, SkMatrix::I()), edgeAA};
252 this->drawFilledQuad(clip, std::move(paint), aa, &quad);
Michael Ludwig61328202019-06-19 14:48:58 +0000253 }
Michael Ludwigce62dec2019-02-19 11:48:46 -0500254
Michael Ludwig69858532018-11-28 15:34:34 -0500255 /** Used with drawQuadSet */
256 struct QuadSetEntry {
257 SkRect fRect;
258 SkPMColor4f fColor; // Overrides any color on the GrPaint
259 SkMatrix fLocalMatrix;
260 GrQuadAAFlags fAAFlags;
261 };
262
Michael Ludwig75451902019-01-23 11:14:29 -0500263 // TODO(michaelludwig) - remove if the bulk API is not useful for SkiaRenderer
Michael Ludwig7c12e282020-05-29 09:54:07 -0400264 void drawQuadSet(const GrClip* clip, GrPaint&& paint, GrAA aa, const SkMatrix& viewMatrix,
Michael Ludwig69858532018-11-28 15:34:34 -0500265 const QuadSetEntry[], int cnt);
266
robertphillipsea461502015-05-26 11:38:03 -0700267 /**
Brian Salomon34169692017-08-28 15:32:01 -0400268 * Creates an op that draws a subrectangle of a texture. The passed color is modulated by the
269 * texture's color. 'srcRect' specifies the rectangle of the texture to draw. 'dstRect'
270 * specifies the rectangle to draw in local coords which will be transformed by 'viewMatrix' to
Brian Salomonbe3c1d22018-05-21 12:54:39 -0400271 * device space.
Brian Salomon34169692017-08-28 15:32:01 -0400272 */
Brian Salomone69b9ef2020-07-22 11:18:06 -0400273 void drawTexture(const GrClip* clip,
274 GrSurfaceProxyView view,
275 SkAlphaType srcAlphaType,
276 GrSamplerState::Filter filter,
277 GrSamplerState::MipmapMode mm,
278 SkBlendMode mode,
279 const SkPMColor4f& color,
280 const SkRect& srcRect,
281 const SkRect& dstRect,
282 GrAA aa,
283 GrQuadAAFlags edgeAA,
284 SkCanvas::SrcRectConstraint constraint,
285 const SkMatrix& viewMatrix,
Greg Daniel40903af2020-01-30 14:55:05 -0500286 sk_sp<GrColorSpaceXform> texXform) {
Brian Salomon2432d062020-04-16 20:48:09 -0400287 const SkRect* subset = constraint == SkCanvas::kStrict_SrcRectConstraint ?
Michael Ludwigaee26ea2019-07-08 16:22:48 +0000288 &srcRect : nullptr;
Michael Ludwig6b45c5d2020-02-07 09:56:38 -0500289 DrawQuad quad{GrQuad::MakeFromRect(dstRect, viewMatrix), GrQuad(srcRect), edgeAA};
290
Brian Salomone69b9ef2020-07-22 11:18:06 -0400291 this->drawTexturedQuad(clip, std::move(view), srcAlphaType, std::move(texXform), filter, mm,
292 color, mode, aa, &quad, subset);
Michael Ludwigaee26ea2019-07-08 16:22:48 +0000293 }
Brian Salomon34169692017-08-28 15:32:01 -0400294
Michael Ludwigce62dec2019-02-19 11:48:46 -0500295 /**
296 * Variant of drawTexture that instead draws the texture applied to 'dstQuad' transformed by
Brian Salomon2432d062020-04-16 20:48:09 -0400297 * 'viewMatrix', using the 'srcQuad' texture coordinates clamped to the optional 'subset'. If
298 * 'subset' is null, it's equivalent to using the fast src rect constraint. If 'subset' is
299 * provided, the strict src rect constraint is applied using 'subset'.
Michael Ludwigce62dec2019-02-19 11:48:46 -0500300 */
Brian Salomone69b9ef2020-07-22 11:18:06 -0400301 void drawTextureQuad(const GrClip* clip,
302 GrSurfaceProxyView view,
303 GrColorType srcColorType,
304 SkAlphaType srcAlphaType,
305 GrSamplerState::Filter filter,
306 GrSamplerState::MipmapMode mm,
307 SkBlendMode mode,
308 const SkPMColor4f& color,
309 const SkPoint srcQuad[4],
310 const SkPoint dstQuad[4],
311 GrAA aa,
312 GrQuadAAFlags edgeAA,
313 const SkRect* subset,
314 const SkMatrix& viewMatrix,
Michael Ludwigaee26ea2019-07-08 16:22:48 +0000315 sk_sp<GrColorSpaceXform> texXform) {
Michael Ludwig6b45c5d2020-02-07 09:56:38 -0500316 DrawQuad quad{GrQuad::MakeFromSkQuad(dstQuad, viewMatrix),
317 GrQuad::MakeFromSkQuad(srcQuad, SkMatrix::I()), edgeAA};
Brian Salomone69b9ef2020-07-22 11:18:06 -0400318 this->drawTexturedQuad(clip, std::move(view), srcAlphaType, std::move(texXform), filter, mm,
319 color, mode, aa, &quad, subset);
Michael Ludwigaee26ea2019-07-08 16:22:48 +0000320 }
Michael Ludwigce62dec2019-02-19 11:48:46 -0500321
Brian Salomond7065e72018-10-12 11:42:02 -0400322 /** Used with drawTextureSet */
323 struct TextureSetEntry {
Greg Daniel549325c2019-10-30 16:19:20 -0400324 GrSurfaceProxyView fProxyView;
Brian Salomonfc118442019-11-22 19:09:27 -0500325 SkAlphaType fSrcAlphaType;
Brian Salomond7065e72018-10-12 11:42:02 -0400326 SkRect fSrcRect;
327 SkRect fDstRect;
Michael Ludwig1433cfd2019-02-27 17:12:30 -0500328 const SkPoint* fDstClipQuad; // Must be null, or point to an array of 4 points
Michael Ludwig7ae2ab52019-03-05 16:00:20 -0500329 const SkMatrix* fPreViewMatrix; // If not null, entry's CTM is 'viewMatrix' * fPreViewMatrix
Michael Ludwig1c66ad92020-07-10 08:59:44 -0400330 SkPMColor4f fColor; // {a,a,a,a} for rgb textures, {r,g,b,a} for alpha-only textures
Brian Salomond7065e72018-10-12 11:42:02 -0400331 GrQuadAAFlags fAAFlags;
332 };
333 /**
334 * Draws a set of textures with a shared filter, color, view matrix, color xform, and
335 * texture color xform. The textures must all have the same GrTextureType and GrConfig.
Michael Ludwigce62dec2019-02-19 11:48:46 -0500336 *
337 * If any entries provide a non-null fDstClip array, it will be read from immediately based on
338 * fDstClipCount, so the pointer can become invalid after this returns.
Michael Ludwig379e4962019-12-06 13:21:26 -0500339 *
Hal Canary425929c2019-12-09 11:55:40 -0500340 * 'proxRunCnt' is the number of proxy changes encountered in the entry array. Technically this
Michael Ludwig379e4962019-12-06 13:21:26 -0500341 * can be inferred from the array within this function, but the information is already known
342 * by SkGpuDevice, so no need to incur another iteration over the array.
Brian Salomond7065e72018-10-12 11:42:02 -0400343 */
Brian Salomone69b9ef2020-07-22 11:18:06 -0400344 void drawTextureSet(const GrClip*,
345 TextureSetEntry[],
346 int cnt,
347 int proxyRunCnt,
348 GrSamplerState::Filter,
349 GrSamplerState::MipmapMode,
350 SkBlendMode mode,
351 GrAA aa,
352 SkCanvas::SrcRectConstraint,
353 const SkMatrix& viewMatrix,
Michael Ludwig379e4962019-12-06 13:21:26 -0500354 sk_sp<GrColorSpaceXform> texXform);
Brian Salomond7065e72018-10-12 11:42:02 -0400355
Brian Salomon34169692017-08-28 15:32:01 -0400356 /**
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500357 * Draw a roundrect using a paint.
robertphillipsea461502015-05-26 11:38:03 -0700358 *
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500359 * @param paint describes how to color pixels.
360 * @param GrAA Controls whether rrect is antialiased.
361 * @param viewMatrix transformation matrix
362 * @param rrect the roundrect to draw
363 * @param style style to apply to the rrect. Currently path effects are not allowed.
robertphillipsea461502015-05-26 11:38:03 -0700364 */
Michael Ludwig7c12e282020-05-29 09:54:07 -0400365 void drawRRect(const GrClip*,
Brian Salomon82f44312017-01-11 13:42:54 -0500366 GrPaint&&,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500367 GrAA,
robertphillipsea461502015-05-26 11:38:03 -0700368 const SkMatrix& viewMatrix,
369 const SkRRect& rrect,
bsalomon6663acf2016-05-10 09:14:17 -0700370 const GrStyle& style);
robertphillipsea461502015-05-26 11:38:03 -0700371
372 /**
Jim Van Verth3af1af92017-05-18 15:06:54 -0400373 * Use a fast method to render the ambient and spot shadows for a path.
374 * Will return false if not possible for the given path.
Jim Van Verthc5903412016-11-17 15:27:09 -0500375 *
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500376 * @param viewMatrix transformation matrix
Jim Van Verth3af1af92017-05-18 15:06:54 -0400377 * @param path the path to shadow
378 * @param rec parameters for shadow rendering
Jim Van Verthc5903412016-11-17 15:27:09 -0500379 */
Michael Ludwig7c12e282020-05-29 09:54:07 -0400380 bool drawFastShadow(const GrClip*,
Jim Van Verth3af1af92017-05-18 15:06:54 -0400381 const SkMatrix& viewMatrix,
382 const SkPath& path,
383 const SkDrawShadowRec& rec);
Jim Van Verthc5903412016-11-17 15:27:09 -0500384
385 /**
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500386 * Shortcut for filling a SkPath consisting of nested rrects using a paint. The result is
387 * undefined if outer does not contain inner.
robertphillips00095892016-02-29 13:50:40 -0800388 *
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500389 * @param paint describes how to color pixels.
390 * @param GrAA Controls whether rrects edges are antialiased
391 * @param viewMatrix transformation matrix
392 * @param outer the outer roundrect
393 * @param inner the inner roundrect
robertphillips00095892016-02-29 13:50:40 -0800394 */
Michael Ludwig7c12e282020-05-29 09:54:07 -0400395 void drawDRRect(const GrClip*,
Brian Salomon82f44312017-01-11 13:42:54 -0500396 GrPaint&&,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500397 GrAA,
robertphillips00095892016-02-29 13:50:40 -0800398 const SkMatrix& viewMatrix,
399 const SkRRect& outer,
400 const SkRRect& inner);
401
402 /**
robertphillipsea461502015-05-26 11:38:03 -0700403 * Draws a path.
404 *
405 * @param paint describes how to color pixels.
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500406 * @param GrAA Controls whether the path is antialiased.
robertphillipsea461502015-05-26 11:38:03 -0700407 * @param viewMatrix transformation matrix
408 * @param path the path to draw
bsalomon6663acf2016-05-10 09:14:17 -0700409 * @param style style to apply to the path.
robertphillipsea461502015-05-26 11:38:03 -0700410 */
Michael Ludwig7c12e282020-05-29 09:54:07 -0400411 void drawPath(const GrClip*,
Brian Salomon82f44312017-01-11 13:42:54 -0500412 GrPaint&&,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500413 GrAA,
robertphillipsea461502015-05-26 11:38:03 -0700414 const SkMatrix& viewMatrix,
415 const SkPath&,
Robert Phillips20390c32018-08-17 11:01:03 -0400416 const GrStyle&);
417
418 /**
419 * Draws a shape.
420 *
421 * @param paint describes how to color pixels.
422 * @param GrAA Controls whether the path is antialiased.
423 * @param viewMatrix transformation matrix
424 * @param shape the shape to draw
425 */
Michael Ludwig7c12e282020-05-29 09:54:07 -0400426 void drawShape(const GrClip*,
Robert Phillips20390c32018-08-17 11:01:03 -0400427 GrPaint&&,
428 GrAA,
429 const SkMatrix& viewMatrix,
Michael Ludwig2686d692020-04-17 20:21:37 +0000430 const GrStyledShape&);
Robert Phillips20390c32018-08-17 11:01:03 -0400431
robertphillipsea461502015-05-26 11:38:03 -0700432
433 /**
434 * Draws vertices with a paint.
435 *
Brian Osmanae0c50c2017-05-25 16:56:34 -0400436 * @param paint describes how to color pixels.
437 * @param viewMatrix transformation matrix
438 * @param vertices specifies the mesh to draw.
439 * @param overridePrimType primitive type to draw. If NULL, derive prim type from vertices.
Brian Osman3c358422020-03-23 10:44:12 -0400440 * @param effect runtime effect that will handle custom vertex attributes.
robertphillipsea461502015-05-26 11:38:03 -0700441 */
Michael Ludwig7c12e282020-05-29 09:54:07 -0400442 void drawVertices(const GrClip*,
Brian Salomon82f44312017-01-11 13:42:54 -0500443 GrPaint&& paint,
Brian Osman449b1152020-04-15 16:43:00 -0400444 const SkMatrixProvider& matrixProvider,
Brian Osmanae0c50c2017-05-25 16:56:34 -0400445 sk_sp<SkVertices> vertices,
Brian Osman3c358422020-03-23 10:44:12 -0400446 GrPrimitiveType* overridePrimType = nullptr,
Brian Osman449b1152020-04-15 16:43:00 -0400447 const SkRuntimeEffect* effect = nullptr);
Brian Salomon199fb872017-02-06 09:41:10 -0500448
449 /**
Brian Osman4d92b892019-03-24 00:53:23 +0000450 * Draws textured sprites from an atlas with a paint. This currently does not support AA for the
451 * sprite rectangle edges.
452 *
453 * @param paint describes how to color pixels.
454 * @param viewMatrix transformation matrix
455 * @param spriteCount number of sprites.
456 * @param xform array of compressed transformation data, required.
457 * @param texRect array of texture rectangles used to access the paint.
458 * @param colors optional array of per-sprite colors, supercedes
459 * the paint's color field.
460 */
Michael Ludwig7c12e282020-05-29 09:54:07 -0400461 void drawAtlas(const GrClip*,
Brian Osman4d92b892019-03-24 00:53:23 +0000462 GrPaint&& paint,
463 const SkMatrix& viewMatrix,
464 int spriteCount,
465 const SkRSXform xform[],
466 const SkRect texRect[],
467 const SkColor colors[]);
468
469 /**
msarettcc319b92016-08-25 18:07:18 -0700470 * Draws a region.
471 *
472 * @param paint describes how to color pixels
473 * @param viewMatrix transformation matrix
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500474 * @param aa should the rects of the region be antialiased.
msarettcc319b92016-08-25 18:07:18 -0700475 * @param region the region to be drawn
476 * @param style style to apply to the region
477 */
Michael Ludwig7c12e282020-05-29 09:54:07 -0400478 void drawRegion(const GrClip*,
Brian Salomon82f44312017-01-11 13:42:54 -0500479 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500480 GrAA aa,
msarettcc319b92016-08-25 18:07:18 -0700481 const SkMatrix& viewMatrix,
482 const SkRegion& region,
Stan Iliev73d8fd92017-08-02 15:36:24 -0400483 const GrStyle& style,
484 const GrUserStencilSettings* ss = nullptr);
msarettcc319b92016-08-25 18:07:18 -0700485
jvanverth31ff7622015-08-07 10:09:28 -0700486 /**
robertphillipsea461502015-05-26 11:38:03 -0700487 * Draws an oval.
488 *
489 * @param paint describes how to color pixels.
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500490 * @param GrAA Controls whether the oval is antialiased.
robertphillipsea461502015-05-26 11:38:03 -0700491 * @param viewMatrix transformation matrix
492 * @param oval the bounding rect of the oval.
bsalomon6663acf2016-05-10 09:14:17 -0700493 * @param style style to apply to the oval. Currently path effects are not allowed.
robertphillipsea461502015-05-26 11:38:03 -0700494 */
Michael Ludwig7c12e282020-05-29 09:54:07 -0400495 void drawOval(const GrClip*,
Brian Salomon82f44312017-01-11 13:42:54 -0500496 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500497 GrAA,
robertphillipsea461502015-05-26 11:38:03 -0700498 const SkMatrix& viewMatrix,
499 const SkRect& oval,
bsalomon6663acf2016-05-10 09:14:17 -0700500 const GrStyle& style);
Herb Derbyc1583cb2020-07-13 10:42:18 -0400501
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500502 /**
503 * Draws a partial arc of an oval.
504 *
505 * @param paint describes how to color pixels.
Brian Salomon99504082016-12-09 15:51:31 -0500506 * @param GrGrAA Controls whether the arc is antialiased.
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500507 * @param viewMatrix transformation matrix.
508 * @param oval the bounding rect of the oval.
509 * @param startAngle starting angle in degrees.
510 * @param sweepAngle angle to sweep in degrees. Must be in (-360, 360)
511 * @param useCenter true means that the implied path begins at the oval center, connects as
512 * a line to the point indicated by the start contains the arc indicated by
513 * the sweep angle. If false the line beginning at the center point is
514 * omitted.
515 * @param style style to apply to the oval.
516 */
Michael Ludwig7c12e282020-05-29 09:54:07 -0400517 void drawArc(const GrClip*,
Brian Salomon82f44312017-01-11 13:42:54 -0500518 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500519 GrAA,
bsalomon4f3a0ca2016-08-22 13:14:26 -0700520 const SkMatrix& viewMatrix,
521 const SkRect& oval,
522 SkScalar startAngle,
523 SkScalar sweepAngle,
524 bool useCenter,
525 const GrStyle& style);
robertphillipsea461502015-05-26 11:38:03 -0700526
joshualitt33a5fce2015-11-18 13:28:51 -0800527 /**
bsalomon4f3a0ca2016-08-22 13:14:26 -0700528 * Draw the image as a set of rects, specified by |iter|.
joshualitt33a5fce2015-11-18 13:28:51 -0800529 */
Michael Ludwig7c12e282020-05-29 09:54:07 -0400530 void drawImageLattice(const GrClip*,
Brian Salomon2a943df2018-05-04 13:43:19 -0400531 GrPaint&&,
msarett10e3d9b2016-08-18 15:46:03 -0700532 const SkMatrix& viewMatrix,
Greg Danieled96bca2019-12-05 15:05:54 -0500533 GrSurfaceProxyView,
Greg Daniel82c6b102020-01-21 10:33:22 -0500534 SkAlphaType alphaType,
Brian Salomon2a943df2018-05-04 13:43:19 -0400535 sk_sp<GrColorSpaceXform>,
536 GrSamplerState::Filter,
537 std::unique_ptr<SkLatticeIter>,
msarett10e3d9b2016-08-18 15:46:03 -0700538 const SkRect& dst);
robertphillipsea461502015-05-26 11:38:03 -0700539
robertphillips8c523e02016-07-26 07:41:00 -0700540 /**
Herb Derby411e7aa2020-07-09 16:02:08 -0400541 * Draw the text specified by the SkGlyphRunList.
542 *
543 * @param viewMatrix transformationMatrix
544 * @param glyphRunList text, text positions, and paint.
545 */
546 void drawGlyphRunList(const GrClip*,
547 const SkMatrixProvider& viewMatrix,
548 const SkGlyphRunList& glyphRunList);
549
550 /**
Greg Daniel46cfbc62019-06-07 11:43:30 -0400551 * Draws the src texture with no matrix. The dstRect is the dstPoint with the width and height
552 * of the srcRect. The srcRect and dstRect are clipped to the bounds of the src and dst surfaces
553 * respectively.
554 */
Greg Daniel573312e2020-02-07 17:22:35 -0500555 bool blitTexture(GrSurfaceProxyView view, const SkIRect& srcRect, const SkIPoint& dstPoint);
Greg Daniel46cfbc62019-06-07 11:43:30 -0400556
557 /**
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400558 * Adds the necessary signal and wait semaphores and adds the passed in SkDrawable to the
559 * command stream.
560 */
561 void drawDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler>, const SkRect& bounds);
562
Greg Daniela5cb7812017-06-16 09:45:32 -0400563 /**
564 * The next time this GrRenderTargetContext is flushed, the gpu will wait on the passed in
565 * semaphores before executing any commands.
566 */
Greg Daniel414418d2020-07-08 11:44:25 -0400567 bool waitOnSemaphores(int numSemaphores, const GrBackendSemaphore waitSemaphores[],
568 bool deleteSemaphoresAfterWait);
robertphillips8c523e02016-07-26 07:41:00 -0700569
Greg Daniel46e366a2019-12-16 14:38:36 -0500570 int numSamples() const { return this->asRenderTargetProxy()->numSamples(); }
robertphillipsca6eafc2016-05-17 09:57:46 -0700571 const SkSurfaceProps& surfaceProps() const { return fSurfaceProps; }
Greg Daniel46e366a2019-12-16 14:38:36 -0500572 bool wrapsVkSecondaryCB() const { return this->asRenderTargetProxy()->wrapsVkSecondaryCB(); }
Brian Salomon8c82a872020-07-21 12:09:58 -0400573 GrMipmapped mipmapped() const;
robertphillips7bceedc2015-12-01 12:51:26 -0800574
Greg Daniel3912a4b2020-01-14 09:56:04 -0500575 // TODO: See if it makes sense for this to return a const& instead and require the callers to
576 // make a copy (which refs the proxy) if needed.
Brian Salomon8afde5f2020-04-01 16:22:00 -0400577 GrSurfaceProxyView writeSurfaceView() { return fWriteView; }
Greg Daniela83de582019-10-22 09:33:25 -0400578
Robert Phillipsbe9aff22019-02-15 11:33:22 -0500579 // This entry point should only be called if the backing GPU object is known to be
580 // instantiated.
Greg Daniel3912a4b2020-01-14 09:56:04 -0500581 GrRenderTarget* accessRenderTarget() { return this->asSurfaceProxy()->peekRenderTarget(); }
Robert Phillipseaa86252016-11-08 13:49:39 +0000582
Robert Phillipsd46697a2017-01-25 12:10:37 -0500583 GrRenderTargetContext* asRenderTargetContext() override { return this; }
584
robertphillips391395d2016-03-02 09:26:36 -0800585 // Provides access to functions that aren't part of the public API.
Brian Osman693a5402016-10-27 15:13:22 -0400586 GrRenderTargetContextPriv priv();
John Stilesec9b4aa2020-08-07 13:05:14 -0400587 const GrRenderTargetContextPriv priv() const; // NOLINT(readability-const-return-type)
joshualittf5883a62016-01-13 07:47:38 -0800588
Brian Salomon3b8486a2020-04-21 12:43:26 -0400589 void wasClosed(const GrOpsTask& task) override;
590
Robert Phillipsb5204762019-06-19 14:12:13 -0400591#if GR_TEST_UTILS
Greg Daniel3912a4b2020-01-14 09:56:04 -0500592 bool testingOnly_IsInstantiated() const { return this->asSurfaceProxy()->isInstantiated(); }
Chris Dalton6b982802019-06-27 13:53:46 -0600593 void testingOnly_SetPreserveOpsOnFullClear() { fPreserveOpsOnFullClear_TestingOnly = true; }
Greg Danielf41b2bd2019-08-22 16:19:24 -0400594 GrOpsTask* testingOnly_PeekLastOpsTask() { return fOpsTask.get(); }
Robert Phillipsb5204762019-06-19 14:12:13 -0400595#endif
Robert Phillipseaa86252016-11-08 13:49:39 +0000596
robertphillipsea461502015-05-26 11:38:03 -0700597private:
Michael Ludwig61328202019-06-19 14:48:58 +0000598 enum class QuadOptimization;
Brian Salomonf18b1d82017-10-27 11:30:49 -0400599
Chris Dalton7d6748e2019-03-13 00:34:52 -0600600 GrAAType chooseAAType(GrAA);
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500601
Greg Danielf41b2bd2019-08-22 16:19:24 -0400602 friend class GrClipStackClip; // for access to getOpsTask
Michael Ludwiga195d102020-09-15 14:51:52 -0400603 friend class GrClipStack; // ""
Chris Daltonc4b47352019-08-23 10:10:36 -0600604 friend class GrOnFlushResourceProvider; // for access to getOpsTask (http://skbug.com/9357)
robertphillips55fdccc2016-06-06 06:16:20 -0700605
Brian Osman11052242016-10-27 14:47:55 -0400606 friend class GrRenderTargetContextPriv;
robertphillips976f5f02016-06-03 10:59:20 -0700607
Herb Derbyba426ba2020-06-09 14:50:32 -0400608 // All the path and text renderers/ops currently make their own ops
Brian Salomon649a3412017-03-09 13:50:43 -0500609 friend class GrSoftwarePathRenderer; // for access to add[Mesh]DrawOp
610 friend class GrAAConvexPathRenderer; // for access to add[Mesh]DrawOp
611 friend class GrDashLinePathRenderer; // for access to add[Mesh]DrawOp
612 friend class GrAAHairLinePathRenderer; // for access to add[Mesh]DrawOp
613 friend class GrAALinearizingConvexPathRenderer; // for access to add[Mesh]DrawOp
Jim Van Verth83010462017-03-16 08:45:39 -0400614 friend class GrSmallPathRenderer; // for access to add[Mesh]DrawOp
Brian Salomon649a3412017-03-09 13:50:43 -0500615 friend class GrDefaultPathRenderer; // for access to add[Mesh]DrawOp
Brian Salomon649a3412017-03-09 13:50:43 -0500616 friend class GrStencilAndCoverPathRenderer; // for access to add[Mesh]DrawOp
Chris Dalton17dc4182020-03-25 16:18:16 -0600617 friend class GrTriangulatingPathRenderer; // for access to add[Mesh]DrawOp
Chris Dalton9414c962018-06-14 10:14:50 -0600618 friend class GrCCPerFlushResources; // for access to addDrawOp
Chris Dalton1a325d22017-07-14 15:17:41 -0600619 friend class GrCoverageCountingPathRenderer; // for access to addDrawOp
Robert Phillips438d9862019-11-14 12:46:05 -0500620 friend class GrFillRectOp; // for access to addDrawOp
Chris Dalton0a22b1e2020-03-26 11:52:15 -0600621 friend class GrTessellationPathRenderer; // for access to addDrawOp
Robert Phillipse837e612019-11-15 11:02:50 -0500622 friend class GrTextureOp; // for access to addDrawOp
Robert Phillips438d9862019-11-14 12:46:05 -0500623
Greg Daniel46e366a2019-12-16 14:38:36 -0500624 SkDEBUGCODE(void onValidate() const override;)
Greg Daniela83de582019-10-22 09:33:25 -0400625
626
Greg Danielf41b2bd2019-08-22 16:19:24 -0400627 GrOpsTask::CanDiscardPreviousOps canDiscardPreviousOpsOnFullClear() const;
Chris Dalton858cf232019-10-14 16:20:00 -0600628 void setNeedsStencil(bool useMixedSamplesIfNotMSAA);
Chris Dalton6b982802019-06-27 13:53:46 -0600629
Michael Ludwig81d41722020-05-26 16:57:38 -0400630 void internalClear(const SkIRect* scissor, const SkPMColor4f&,
631 bool upgradePartialToFull = false);
632 void internalStencilClear(const SkIRect* scissor, bool insideStencilMask);
csmartdalton29df7602016-08-31 11:55:52 -0700633
Brian Salomon82f44312017-01-11 13:42:54 -0500634 // Only consumes the GrPaint if successful.
Michael Ludwig7c12e282020-05-29 09:54:07 -0400635 bool drawFilledDRRect(const GrClip* clip,
Brian Salomon82f44312017-01-11 13:42:54 -0500636 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500637 GrAA,
robertphillips00095892016-02-29 13:50:40 -0800638 const SkMatrix& viewMatrix,
639 const SkRRect& origOuter,
640 const SkRRect& origInner);
641
Michael Ludwig61328202019-06-19 14:48:58 +0000642 // If the drawn quad's paint is a const blended color, provide it as a non-null pointer to
643 // 'constColor', which enables the draw-as-clear optimization. Otherwise it is assumed the paint
644 // requires some form of shading that invalidates using a clear op.
645 //
646 // The non-const pointers should be the original draw request on input, and will be updated as
647 // appropriate depending on the returned optimization level.
648 //
Michael Ludwige08b4432019-06-19 18:00:48 -0400649 // 'stencilSettings' are provided merely for decision making purposes; When non-null,
650 // optimization strategies that submit special ops are avoided.
Michael Ludwig7c12e282020-05-29 09:54:07 -0400651 QuadOptimization attemptQuadOptimization(const GrClip* clip,
Michael Ludwig61328202019-06-19 14:48:58 +0000652 const SkPMColor4f* constColor,
Michael Ludwige08b4432019-06-19 18:00:48 -0400653 const GrUserStencilSettings* stencilSettings,
Michael Ludwig61328202019-06-19 14:48:58 +0000654 GrAA* aa,
Michael Ludwig6b45c5d2020-02-07 09:56:38 -0500655 DrawQuad* quad);
robertphillips44302392016-07-08 14:43:03 -0700656
Michael Ludwig61328202019-06-19 14:48:58 +0000657 // If stencil settings, 'ss', are non-null, AA controls MSAA or no AA. If they are null, then AA
658 // can choose between coverage, MSAA as per chooseAAType(). This will always attempt to apply
659 // quad optimizations, so all quad/rect public APIs should rely on this function for consistent
Michael Ludwig6b45c5d2020-02-07 09:56:38 -0500660 // clipping behavior. 'quad' will be modified in place to reflect final rendered geometry.
Michael Ludwig7c12e282020-05-29 09:54:07 -0400661 void drawFilledQuad(const GrClip* clip,
Michael Ludwig61328202019-06-19 14:48:58 +0000662 GrPaint&& paint,
663 GrAA aa,
Michael Ludwig6b45c5d2020-02-07 09:56:38 -0500664 DrawQuad* quad,
Michael Ludwig61328202019-06-19 14:48:58 +0000665 const GrUserStencilSettings* ss = nullptr);
Brian Salomon7694b902019-06-18 21:00:21 +0000666
Michael Ludwig6b45c5d2020-02-07 09:56:38 -0500667 // Like drawFilledQuad but does not require using a GrPaint or FP for texturing.
668 // 'quad' may be modified in place to reflect final geometry.
Michael Ludwig7c12e282020-05-29 09:54:07 -0400669 void drawTexturedQuad(const GrClip* clip,
Greg Daniel549325c2019-10-30 16:19:20 -0400670 GrSurfaceProxyView proxyView,
Brian Salomonfc118442019-11-22 19:09:27 -0500671 SkAlphaType alphaType,
Michael Ludwigaee26ea2019-07-08 16:22:48 +0000672 sk_sp<GrColorSpaceXform> textureXform,
673 GrSamplerState::Filter filter,
Brian Salomone69b9ef2020-07-22 11:18:06 -0400674 GrSamplerState::MipmapMode,
Michael Ludwigaee26ea2019-07-08 16:22:48 +0000675 const SkPMColor4f& color,
676 SkBlendMode blendMode,
677 GrAA aa,
Michael Ludwig6b45c5d2020-02-07 09:56:38 -0500678 DrawQuad* quad,
Brian Salomon2432d062020-04-16 20:48:09 -0400679 const SkRect* subset = nullptr);
Michael Ludwigaee26ea2019-07-08 16:22:48 +0000680
Michael Ludwig6a6de652020-04-30 20:16:36 -0400681 // If 'attemptShapeFallback' is true, and the original shape had been simplfied, this
682 // will re-route through drawShape() to see if we can avoid path rendering one more time.
Michael Ludwig7c12e282020-05-29 09:54:07 -0400683 void drawShapeUsingPathRenderer(const GrClip*, GrPaint&&, GrAA, const SkMatrix&,
Michael Ludwig6a6de652020-04-30 20:16:36 -0400684 const GrStyledShape&, bool attemptShapeFallback = true);
robertphillipsea461502015-05-26 11:38:03 -0700685
Chris Dalton08755122019-08-05 16:13:47 -0600686 void addOp(std::unique_ptr<GrOp>);
687
Brian Salomon348a0372018-10-31 10:42:18 -0400688 // Allows caller of addDrawOp to know which op list an op will be added to.
Greg Danielf41b2bd2019-08-22 16:19:24 -0400689 using WillAddOpFn = void(GrOp*, uint32_t opsTaskID);
Brian Salomon348a0372018-10-31 10:42:18 -0400690 // These perform processing specific to GrDrawOp-derived ops before recording them into an
691 // op list. Before adding the op to an op list the WillAddOpFn is called. Note that it
692 // will not be called in the event that the op is discarded. Moreover, the op may merge into
693 // another op after the function is called (either before addDrawOp returns or some time later).
Michael Ludwig7c12e282020-05-29 09:54:07 -0400694 //
695 // If the clip pointer is null, no clipping will be performed.
696 void addDrawOp(const GrClip*, std::unique_ptr<GrDrawOp>,
Brian Salomon348a0372018-10-31 10:42:18 -0400697 const std::function<WillAddOpFn>& = std::function<WillAddOpFn>());
robertphillips2334fb62015-06-17 05:43:33 -0700698
Robert Phillipsbf25d432017-04-07 10:08:53 -0400699 // Makes a copy of the proxy if it is necessary for the draw and places the texture that should
700 // be used by GrXferProcessor to access the destination color in 'result'. If the return
701 // value is false then a texture copy could not be made.
Michael Ludwig28e5f112020-06-09 10:57:24 -0400702 //
703 // The op should have already had setClippedBounds called on it.
704 bool SK_WARN_UNUSED_RESULT setupDstProxyView(const GrOp& op,
Greg Daniel524e28b2019-11-01 11:48:53 -0400705 GrXferProcessor::DstProxyView* result);
Brian Salomon467921e2017-03-06 16:17:12 -0500706
Greg Danielf41b2bd2019-08-22 16:19:24 -0400707 GrOpsTask* getOpsTask();
robertphillipsa106c622015-10-16 09:07:06 -0700708
Herb Derbyd29207a2020-06-08 13:50:19 -0400709 SkGlyphRunListPainter* glyphPainter() { return &fGlyphPainter; }
710
Brian Salomon8afde5f2020-04-01 16:22:00 -0400711 GrSurfaceProxyView fWriteView;
robertphillipsa106c622015-10-16 09:07:06 -0700712
Greg Danielf41b2bd2019-08-22 16:19:24 -0400713 // In MDB-mode the GrOpsTask can be closed by some other renderTargetContext that has picked
714 // it up. For this reason, the GrOpsTask should only ever be accessed via 'getOpsTask'.
715 sk_sp<GrOpsTask> fOpsTask;
robertphillips2334fb62015-06-17 05:43:33 -0700716
Brian Salomonf18b1d82017-10-27 11:30:49 -0400717 SkSurfaceProps fSurfaceProps;
Greg Danielf41b2bd2019-08-22 16:19:24 -0400718 bool fManagedOpsTask;
Robert Phillipse305cc1f2016-12-14 12:19:05 -0500719
Chris Daltoneffee202019-07-01 22:28:03 -0600720 int fNumStencilSamples = 0;
Greg Danield358cbe2020-09-11 09:33:54 -0400721
722 GrDstSampleType fDstSampleType = GrDstSampleType::kNone;
723
Chris Dalton6b982802019-06-27 13:53:46 -0600724#if GR_TEST_UTILS
725 bool fPreserveOpsOnFullClear_TestingOnly = false;
726#endif
Herb Derbyd29207a2020-06-08 13:50:19 -0400727 SkGlyphRunListPainter fGlyphPainter;
John Stiles7571f9e2020-09-02 22:42:33 -0400728 using INHERITED = GrSurfaceContext;
robertphillipsea461502015-05-26 11:38:03 -0700729};
730
731#endif