blob: c230d35f137de6e718c0400eccd71260f2fbd552 [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"
Greg Danielf41b2bd2019-08-22 16:19:24 -040017#include "src/gpu/GrOpsTask.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050018#include "src/gpu/GrPaint.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040019#include "src/gpu/GrRenderTargetProxy.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050020#include "src/gpu/GrSurfaceContext.h"
Greg Daniela83de582019-10-22 09:33:25 -040021#include "src/gpu/GrSurfaceProxyView.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050022#include "src/gpu/GrXferProcessor.h"
Michael Ludwig61328202019-06-19 14:48:58 +000023#include "src/gpu/geometry/GrQuad.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050024#include "src/gpu/text/GrTextTarget.h"
robertphillipsea461502015-05-26 11:38:03 -070025
Greg Daniela5cb7812017-06-16 09:45:32 -040026class GrBackendSemaphore;
robertphillipsea461502015-05-26 11:38:03 -070027class GrClip;
Brian Osman2240be92017-10-18 13:15:13 -040028class GrColorSpaceXform;
Chris Dalton1a325d22017-07-14 15:17:41 -060029class GrCoverageCountingPathRenderer;
Brian Salomon9afd3712016-12-01 10:59:09 -050030class GrDrawOp;
csmartdalton29df7602016-08-31 11:55:52 -070031class GrFixedClip;
Robert Phillips0d075de2019-03-04 11:08:13 -050032class GrOp;
robertphillipsea461502015-05-26 11:38:03 -070033class GrRenderTarget;
Brian Osman45580d32016-11-23 09:37:01 -050034class GrRenderTargetContextPriv;
Brian Salomon2fad74a2017-12-20 13:28:55 -050035class GrShape;
bsalomon6663acf2016-05-10 09:14:17 -070036class GrStyle;
Robert Phillipseaa86252016-11-08 13:49:39 +000037class GrTextureProxy;
robertphillips44302392016-07-08 14:43:03 -070038struct GrUserStencilSettings;
Jim Van Verth3af1af92017-05-18 15:06:54 -040039struct SkDrawShadowRec;
Herb Derbycddab252018-07-16 11:19:04 -040040class SkGlyphRunList;
robertphillipsea461502015-05-26 11:38:03 -070041struct SkIPoint;
42struct SkIRect;
msarett10e3d9b2016-08-18 15:46:03 -070043class SkLatticeIter;
robertphillipsea461502015-05-26 11:38:03 -070044class SkMatrix;
robertphillips2334fb62015-06-17 05:43:33 -070045class SkPaint;
robertphillipsea461502015-05-26 11:38:03 -070046class SkPath;
47struct SkPoint;
48struct SkRect;
Brian Osman45580d32016-11-23 09:37:01 -050049class SkRegion;
robertphillipsea461502015-05-26 11:38:03 -070050class SkRRect;
jvanverth31ff7622015-08-07 10:09:28 -070051struct SkRSXform;
Brian Osman3c358422020-03-23 10:44:12 -040052class SkRuntimeEffect;
robertphillips2334fb62015-06-17 05:43:33 -070053class SkTextBlob;
Brian Salomon199fb872017-02-06 09:41:10 -050054class SkVertices;
robertphillipsea461502015-05-26 11:38:03 -070055
Brian Osman45580d32016-11-23 09:37:01 -050056/**
57 * A helper object to orchestrate commands (draws, etc...) for GrSurfaces that are GrRenderTargets.
robertphillipsea461502015-05-26 11:38:03 -070058 */
Brian Salomon57f211b2019-08-21 15:21:09 -040059class GrRenderTargetContext : public GrSurfaceContext {
robertphillipsea461502015-05-26 11:38:03 -070060public:
Greg Daniele20fcad2020-01-08 11:52:34 -050061 static std::unique_ptr<GrRenderTargetContext> Make(
Greg Danielba0ff782020-01-07 15:42:57 -050062 GrRecordingContext*, GrColorType, sk_sp<SkColorSpace>, sk_sp<GrSurfaceProxy>,
63 GrSurfaceOrigin, const SkSurfaceProps*, bool managedOps = true);
64
Brian Salomona56a7462020-02-07 14:17:25 -050065 static std::unique_ptr<GrRenderTargetContext> Make(GrRecordingContext*,
66 GrColorType,
67 sk_sp<SkColorSpace>,
68 SkBackingFit,
69 SkISize dimensions,
70 const GrBackendFormat&,
71 int sampleCnt,
72 GrMipMapped,
73 GrProtected,
74 GrSurfaceOrigin,
75 SkBudgeted,
76 const SkSurfaceProps*);
Greg Daniele20fcad2020-01-08 11:52:34 -050077
78 // Same as above but will use the default GrBackendFormat for the given GrColorType
79 static std::unique_ptr<GrRenderTargetContext> Make(
Brian Salomona56a7462020-02-07 14:17:25 -050080 GrRecordingContext*,
81 GrColorType,
82 sk_sp<SkColorSpace>,
83 SkBackingFit,
84 SkISize dimensions,
85 int sampleCnt = 1,
86 GrMipMapped = GrMipMapped::kNo,
87 GrProtected = GrProtected::kNo,
88 GrSurfaceOrigin = kBottomLeft_GrSurfaceOrigin,
89 SkBudgeted = SkBudgeted::kYes,
90 const SkSurfaceProps* = nullptr);
Greg Daniele20fcad2020-01-08 11:52:34 -050091
Brian Salomond005b692020-04-01 15:47:05 -040092 static std::tuple<GrColorType, GrBackendFormat> GetFallbackColorTypeAndFormat(GrImageContext*,
93 GrColorType);
94
Greg Daniele20fcad2020-01-08 11:52:34 -050095 // Same as previous factory but will try to use fallback GrColorTypes if the one passed in
96 // fails. The fallback GrColorType will have at least the number of channels and precision per
97 // channel as the passed in GrColorType. It may also swizzle the changes (e.g., BGRA -> RGBA).
98 // SRGB-ness will be preserved.
99 static std::unique_ptr<GrRenderTargetContext> MakeWithFallback(
Brian Salomona56a7462020-02-07 14:17:25 -0500100 GrRecordingContext*,
101 GrColorType,
102 sk_sp<SkColorSpace>,
103 SkBackingFit,
104 SkISize dimensions,
105 int sampleCnt = 1,
106 GrMipMapped = GrMipMapped::kNo,
107 GrProtected = GrProtected::kNo,
108 GrSurfaceOrigin = kBottomLeft_GrSurfaceOrigin,
109 SkBudgeted = SkBudgeted::kYes,
110 const SkSurfaceProps* = nullptr);
Greg Daniele20fcad2020-01-08 11:52:34 -0500111
Greg Danielba0ff782020-01-07 15:42:57 -0500112 // These match the definitions in SkSurface & GrSurface.h, for whence they came
113 typedef void* ReleaseContext;
114 typedef void (*ReleaseProc)(ReleaseContext);
115
116 // Creates a GrRenderTargetContext that wraps the passed in GrBackendTexture.
117 static std::unique_ptr<GrRenderTargetContext> MakeFromBackendTexture(
118 GrRecordingContext*, GrColorType, sk_sp<SkColorSpace>, const GrBackendTexture&,
119 int sampleCnt, GrSurfaceOrigin, const SkSurfaceProps*, ReleaseProc releaseProc,
120 ReleaseContext releaseCtx);
121
122 static std::unique_ptr<GrRenderTargetContext> MakeFromBackendTextureAsRenderTarget(
123 GrRecordingContext*, GrColorType, sk_sp<SkColorSpace>, const GrBackendTexture&,
124 int sampleCnt, GrSurfaceOrigin, const SkSurfaceProps*);
125
126 static std::unique_ptr<GrRenderTargetContext> MakeFromBackendRenderTarget(
127 GrRecordingContext*, GrColorType, sk_sp<SkColorSpace>, const GrBackendRenderTarget&,
128 GrSurfaceOrigin, const SkSurfaceProps*, ReleaseProc releaseProc,
129 ReleaseContext releaseCtx);
130
131 static std::unique_ptr<GrRenderTargetContext> MakeFromVulkanSecondaryCB(
132 GrRecordingContext*, const SkImageInfo&, const GrVkDrawableInfo&,
133 const SkSurfaceProps*);
134
Greg Daniel3912a4b2020-01-14 09:56:04 -0500135 GrRenderTargetContext(GrRecordingContext*, GrSurfaceProxyView readView,
Brian Salomon8afde5f2020-04-01 16:22:00 -0400136 GrSurfaceProxyView writeView, GrColorType, sk_sp<SkColorSpace>,
Greg Daniel3912a4b2020-01-14 09:56:04 -0500137 const SkSurfaceProps*, bool managedOpsTask = true);
Greg Danielbfa19c42019-12-19 16:41:40 -0500138
Brian Osman11052242016-10-27 14:47:55 -0400139 ~GrRenderTargetContext() override;
robertphillips2334fb62015-06-17 05:43:33 -0700140
Robert Phillipse4643cc2018-08-14 13:01:29 -0400141 virtual void drawGlyphRunList(const GrClip&, const SkMatrix& viewMatrix, const SkGlyphRunList&);
robertphillipsea461502015-05-26 11:38:03 -0700142
robertphillipsea461502015-05-26 11:38:03 -0700143 /**
144 * Provides a perfomance hint that the render target's contents are allowed
145 * to become undefined.
146 */
robertphillips2e1e51f2015-10-15 08:01:48 -0700147 void discard();
robertphillipsea461502015-05-26 11:38:03 -0700148
Chris Dalton344e9032017-12-11 15:42:09 -0700149 enum class CanClearFullscreen : bool {
150 kNo = false,
151 kYes = true
152 };
153
robertphillipsea461502015-05-26 11:38:03 -0700154 /**
155 * Clear the entire or rect of the render target, ignoring any clips.
robertphillipsea461502015-05-26 11:38:03 -0700156 * @param rect the rect to clear or the whole thing if rect is NULL.
157 * @param color the color to clear to.
Chris Dalton344e9032017-12-11 15:42:09 -0700158 * @param CanClearFullscreen allows partial clears to be converted to fullscreen clears on
159 * tiling platforms where that is an optimization.
robertphillipsea461502015-05-26 11:38:03 -0700160 */
Brian Osman9a9baae2018-11-05 15:06:26 -0500161 void clear(const SkIRect* rect, const SkPMColor4f& color, CanClearFullscreen);
robertphillipsea461502015-05-26 11:38:03 -0700162
Chris Dalton0493fbd2019-09-18 15:49:46 -0600163 void clear(const SkPMColor4f& color) {
164 return this->clear(nullptr, color, CanClearFullscreen::kYes);
165 }
166
robertphillipsea461502015-05-26 11:38:03 -0700167 /**
168 * Draw everywhere (respecting the clip) with the paint.
169 */
Brian Salomon82f44312017-01-11 13:42:54 -0500170 void drawPaint(const GrClip&, GrPaint&&, const SkMatrix& viewMatrix);
robertphillipsea461502015-05-26 11:38:03 -0700171
172 /**
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500173 * Draw the rect using a paint.
174 * @param paint describes how to color pixels.
175 * @param GrAA Controls whether rect is antialiased
176 * @param viewMatrix transformation matrix
177 * @param style The style to apply. Null means fill. Currently path effects are not
178 * allowed.
179 * The rects coords are used to access the paint (through texture matrix)
robertphillipsea461502015-05-26 11:38:03 -0700180 */
robertphillips2e1e51f2015-10-15 08:01:48 -0700181 void drawRect(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500182 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500183 GrAA,
robertphillipsea461502015-05-26 11:38:03 -0700184 const SkMatrix& viewMatrix,
185 const SkRect&,
Brian Salomon82f44312017-01-11 13:42:54 -0500186 const GrStyle* style = nullptr);
robertphillipsea461502015-05-26 11:38:03 -0700187
188 /**
bsalomona2e69fc2015-11-05 10:41:43 -0800189 * Maps a rectangle of shader coordinates to a rectangle and fills that rectangle.
robertphillipsea461502015-05-26 11:38:03 -0700190 *
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500191 * @param paint describes how to color pixels.
192 * @param GrAA Controls whether rect is antialiased
193 * @param viewMatrix transformation matrix which applies to rectToDraw
194 * @param rectToDraw the rectangle to draw
195 * @param localRect the rectangle of shader coordinates applied to rectToDraw
robertphillipsea461502015-05-26 11:38:03 -0700196 */
Michael Ludwig136f45a2019-02-19 11:44:41 -0500197 void fillRectToRect(const GrClip& clip,
Brian Salomon82f44312017-01-11 13:42:54 -0500198 GrPaint&& paint,
Michael Ludwig136f45a2019-02-19 11:44:41 -0500199 GrAA aa,
bsalomona2e69fc2015-11-05 10:41:43 -0800200 const SkMatrix& viewMatrix,
201 const SkRect& rectToDraw,
Michael Ludwig136f45a2019-02-19 11:44:41 -0500202 const SkRect& localRect) {
Michael Ludwig6b45c5d2020-02-07 09:56:38 -0500203 DrawQuad quad{GrQuad::MakeFromRect(rectToDraw, viewMatrix), GrQuad(localRect),
204 aa == GrAA::kYes ? GrQuadAAFlags::kAll : GrQuadAAFlags::kNone};
205 this->drawFilledQuad(clip, std::move(paint), aa, &quad);
Michael Ludwig136f45a2019-02-19 11:44:41 -0500206 }
robertphillipsea461502015-05-26 11:38:03 -0700207
208 /**
bsalomona2e69fc2015-11-05 10:41:43 -0800209 * Fills a rect with a paint and a localMatrix.
robertphillipsea461502015-05-26 11:38:03 -0700210 */
bsalomona2e69fc2015-11-05 10:41:43 -0800211 void fillRectWithLocalMatrix(const GrClip& clip,
Brian Salomon82f44312017-01-11 13:42:54 -0500212 GrPaint&& paint,
Michael Ludwig61328202019-06-19 14:48:58 +0000213 GrAA aa,
bsalomona2e69fc2015-11-05 10:41:43 -0800214 const SkMatrix& viewMatrix,
215 const SkRect& rect,
Michael Ludwig61328202019-06-19 14:48:58 +0000216 const SkMatrix& localMatrix) {
Michael Ludwig6b45c5d2020-02-07 09:56:38 -0500217 DrawQuad quad{GrQuad::MakeFromRect(rect, viewMatrix),
218 GrQuad::MakeFromRect(rect, localMatrix),
219 aa == GrAA::kYes ? GrQuadAAFlags::kAll : GrQuadAAFlags::kNone};
220 this->drawFilledQuad(clip, std::move(paint), aa, &quad);
Michael Ludwig61328202019-06-19 14:48:58 +0000221 }
robertphillipsea461502015-05-26 11:38:03 -0700222
Michael Ludwig75451902019-01-23 11:14:29 -0500223 /**
224 * Creates an op that draws a fill rect with per-edge control over anti-aliasing.
Michael Ludwigce62dec2019-02-19 11:48:46 -0500225 *
226 * This is a specialized version of fillQuadWithEdgeAA, but is kept separate since knowing
227 * the geometry is a rectangle affords more optimizations.
Michael Ludwig75451902019-01-23 11:14:29 -0500228 */
Michael Ludwig136f45a2019-02-19 11:44:41 -0500229 void fillRectWithEdgeAA(const GrClip& clip, GrPaint&& paint, GrAA aa, GrQuadAAFlags edgeAA,
230 const SkMatrix& viewMatrix, const SkRect& rect,
Michael Ludwig61328202019-06-19 14:48:58 +0000231 const SkRect* optionalLocalRect = nullptr) {
232 const SkRect& localRect = optionalLocalRect ? *optionalLocalRect : rect;
Michael Ludwig6b45c5d2020-02-07 09:56:38 -0500233 DrawQuad quad{GrQuad::MakeFromRect(rect, viewMatrix), GrQuad(localRect), edgeAA};
234 this->drawFilledQuad(clip, std::move(paint), aa, &quad);
Michael Ludwig61328202019-06-19 14:48:58 +0000235 }
Michael Ludwig75451902019-01-23 11:14:29 -0500236
Michael Ludwigce62dec2019-02-19 11:48:46 -0500237 /**
238 * Similar to fillRectWithEdgeAA but draws an arbitrary 2D convex quadrilateral transformed
239 * by 'viewMatrix', with per-edge control over anti-aliasing. The quad should follow the
240 * ordering used by SkRect::toQuad(), which determines how the edge AA is applied:
241 * - "top" = points [0] and [1]
242 * - "right" = points[1] and [2]
243 * - "bottom" = points[2] and [3]
244 * - "left" = points[3] and [0]
245 *
246 * The last argument, 'optionalLocalQuad', can be null if no separate local coordinates are
247 * necessary.
248 */
249 void fillQuadWithEdgeAA(const GrClip& clip, GrPaint&& paint, GrAA aa, GrQuadAAFlags edgeAA,
Michael Ludwig6b45c5d2020-02-07 09:56:38 -0500250 const SkMatrix& viewMatrix, const SkPoint points[4],
251 const SkPoint optionalLocalPoints[4]) {
252 const SkPoint* localPoints = optionalLocalPoints ? optionalLocalPoints : points;
253 DrawQuad quad{GrQuad::MakeFromSkQuad(points, viewMatrix),
254 GrQuad::MakeFromSkQuad(localPoints, SkMatrix::I()), edgeAA};
255 this->drawFilledQuad(clip, std::move(paint), aa, &quad);
Michael Ludwig61328202019-06-19 14:48:58 +0000256 }
Michael Ludwigce62dec2019-02-19 11:48:46 -0500257
Michael Ludwig69858532018-11-28 15:34:34 -0500258 /** Used with drawQuadSet */
259 struct QuadSetEntry {
260 SkRect fRect;
261 SkPMColor4f fColor; // Overrides any color on the GrPaint
262 SkMatrix fLocalMatrix;
263 GrQuadAAFlags fAAFlags;
264 };
265
Michael Ludwig75451902019-01-23 11:14:29 -0500266 // TODO(michaelludwig) - remove if the bulk API is not useful for SkiaRenderer
Michael Ludwig69858532018-11-28 15:34:34 -0500267 void drawQuadSet(const GrClip& clip, GrPaint&& paint, GrAA aa, const SkMatrix& viewMatrix,
268 const QuadSetEntry[], int cnt);
269
robertphillipsea461502015-05-26 11:38:03 -0700270 /**
Brian Salomon34169692017-08-28 15:32:01 -0400271 * Creates an op that draws a subrectangle of a texture. The passed color is modulated by the
272 * texture's color. 'srcRect' specifies the rectangle of the texture to draw. 'dstRect'
273 * specifies the rectangle to draw in local coords which will be transformed by 'viewMatrix' to
Brian Salomonbe3c1d22018-05-21 12:54:39 -0400274 * device space.
Brian Salomon34169692017-08-28 15:32:01 -0400275 */
Greg Daniel40903af2020-01-30 14:55:05 -0500276 void drawTexture(const GrClip& clip, GrSurfaceProxyView view, SkAlphaType srcAlphaType,
277 GrSamplerState::Filter filter, SkBlendMode mode, const SkPMColor4f& color,
278 const SkRect& srcRect, const SkRect& dstRect, GrAA aa, GrQuadAAFlags edgeAA,
279 SkCanvas::SrcRectConstraint constraint, const SkMatrix& viewMatrix,
280 sk_sp<GrColorSpaceXform> texXform) {
Michael Ludwigaee26ea2019-07-08 16:22:48 +0000281 const SkRect* domain = constraint == SkCanvas::kStrict_SrcRectConstraint ?
282 &srcRect : nullptr;
Michael Ludwig6b45c5d2020-02-07 09:56:38 -0500283 DrawQuad quad{GrQuad::MakeFromRect(dstRect, viewMatrix), GrQuad(srcRect), edgeAA};
284
Greg Daniel40903af2020-01-30 14:55:05 -0500285 this->drawTexturedQuad(clip, std::move(view), srcAlphaType, std::move(texXform),
Michael Ludwig6b45c5d2020-02-07 09:56:38 -0500286 filter, color, mode, aa, &quad, domain);
Michael Ludwigaee26ea2019-07-08 16:22:48 +0000287 }
Brian Salomon34169692017-08-28 15:32:01 -0400288
Michael Ludwigce62dec2019-02-19 11:48:46 -0500289 /**
290 * Variant of drawTexture that instead draws the texture applied to 'dstQuad' transformed by
291 * 'viewMatrix', using the 'srcQuad' texture coordinates clamped to the optional 'domain'. If
292 * 'domain' is null, it's equivalent to using the fast src rect constraint. If 'domain' is
293 * provided, the strict src rect constraint is applied using 'domain'.
294 */
Greg Daniel2f3cd4f2020-02-07 11:07:25 -0500295 void drawTextureQuad(const GrClip& clip, GrSurfaceProxyView view, GrColorType srcColorType,
Brian Salomonfc118442019-11-22 19:09:27 -0500296 SkAlphaType srcAlphaType, GrSamplerState::Filter filter, SkBlendMode mode,
297 const SkPMColor4f& color, const SkPoint srcQuad[4],
298 const SkPoint dstQuad[4], GrAA aa, GrQuadAAFlags edgeAA,
299 const SkRect* domain, const SkMatrix& viewMatrix,
Michael Ludwigaee26ea2019-07-08 16:22:48 +0000300 sk_sp<GrColorSpaceXform> texXform) {
Michael Ludwig6b45c5d2020-02-07 09:56:38 -0500301 DrawQuad quad{GrQuad::MakeFromSkQuad(dstQuad, viewMatrix),
302 GrQuad::MakeFromSkQuad(srcQuad, SkMatrix::I()), edgeAA};
Greg Daniel2f3cd4f2020-02-07 11:07:25 -0500303 this->drawTexturedQuad(clip, std::move(view), srcAlphaType, std::move(texXform),
Michael Ludwig6b45c5d2020-02-07 09:56:38 -0500304 filter, color, mode, aa, &quad, domain);
Michael Ludwigaee26ea2019-07-08 16:22:48 +0000305 }
Michael Ludwigce62dec2019-02-19 11:48:46 -0500306
Brian Salomond7065e72018-10-12 11:42:02 -0400307 /** Used with drawTextureSet */
308 struct TextureSetEntry {
Greg Daniel549325c2019-10-30 16:19:20 -0400309 GrSurfaceProxyView fProxyView;
Brian Salomonfc118442019-11-22 19:09:27 -0500310 SkAlphaType fSrcAlphaType;
Brian Salomond7065e72018-10-12 11:42:02 -0400311 SkRect fSrcRect;
312 SkRect fDstRect;
Michael Ludwig1433cfd2019-02-27 17:12:30 -0500313 const SkPoint* fDstClipQuad; // Must be null, or point to an array of 4 points
Michael Ludwig7ae2ab52019-03-05 16:00:20 -0500314 const SkMatrix* fPreViewMatrix; // If not null, entry's CTM is 'viewMatrix' * fPreViewMatrix
Brian Salomon1da5cad2018-11-21 09:21:18 -0500315 float fAlpha;
Brian Salomond7065e72018-10-12 11:42:02 -0400316 GrQuadAAFlags fAAFlags;
317 };
318 /**
319 * Draws a set of textures with a shared filter, color, view matrix, color xform, and
320 * texture color xform. The textures must all have the same GrTextureType and GrConfig.
Michael Ludwigce62dec2019-02-19 11:48:46 -0500321 *
322 * If any entries provide a non-null fDstClip array, it will be read from immediately based on
323 * fDstClipCount, so the pointer can become invalid after this returns.
Michael Ludwig379e4962019-12-06 13:21:26 -0500324 *
Hal Canary425929c2019-12-09 11:55:40 -0500325 * 'proxRunCnt' is the number of proxy changes encountered in the entry array. Technically this
Michael Ludwig379e4962019-12-06 13:21:26 -0500326 * can be inferred from the array within this function, but the information is already known
327 * by SkGpuDevice, so no need to incur another iteration over the array.
Brian Salomond7065e72018-10-12 11:42:02 -0400328 */
Hal Canary425929c2019-12-09 11:55:40 -0500329 void drawTextureSet(const GrClip&, TextureSetEntry[], int cnt, int proxyRunCnt,
Michael Ludwig379e4962019-12-06 13:21:26 -0500330 GrSamplerState::Filter, SkBlendMode mode, GrAA aa,
331 SkCanvas::SrcRectConstraint, const SkMatrix& viewMatrix,
332 sk_sp<GrColorSpaceXform> texXform);
Brian Salomond7065e72018-10-12 11:42:02 -0400333
Brian Salomon34169692017-08-28 15:32:01 -0400334 /**
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500335 * Draw a roundrect using a paint.
robertphillipsea461502015-05-26 11:38:03 -0700336 *
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500337 * @param paint describes how to color pixels.
338 * @param GrAA Controls whether rrect is antialiased.
339 * @param viewMatrix transformation matrix
340 * @param rrect the roundrect to draw
341 * @param style style to apply to the rrect. Currently path effects are not allowed.
robertphillipsea461502015-05-26 11:38:03 -0700342 */
robertphillips2e1e51f2015-10-15 08:01:48 -0700343 void drawRRect(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500344 GrPaint&&,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500345 GrAA,
robertphillipsea461502015-05-26 11:38:03 -0700346 const SkMatrix& viewMatrix,
347 const SkRRect& rrect,
bsalomon6663acf2016-05-10 09:14:17 -0700348 const GrStyle& style);
robertphillipsea461502015-05-26 11:38:03 -0700349
350 /**
Jim Van Verth3af1af92017-05-18 15:06:54 -0400351 * Use a fast method to render the ambient and spot shadows for a path.
352 * Will return false if not possible for the given path.
Jim Van Verthc5903412016-11-17 15:27:09 -0500353 *
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500354 * @param viewMatrix transformation matrix
Jim Van Verth3af1af92017-05-18 15:06:54 -0400355 * @param path the path to shadow
356 * @param rec parameters for shadow rendering
Jim Van Verthc5903412016-11-17 15:27:09 -0500357 */
Jim Van Verth3af1af92017-05-18 15:06:54 -0400358 bool drawFastShadow(const GrClip&,
Jim Van Verth3af1af92017-05-18 15:06:54 -0400359 const SkMatrix& viewMatrix,
360 const SkPath& path,
361 const SkDrawShadowRec& rec);
Jim Van Verthc5903412016-11-17 15:27:09 -0500362
363 /**
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500364 * Shortcut for filling a SkPath consisting of nested rrects using a paint. The result is
365 * undefined if outer does not contain inner.
robertphillips00095892016-02-29 13:50:40 -0800366 *
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500367 * @param paint describes how to color pixels.
368 * @param GrAA Controls whether rrects edges are antialiased
369 * @param viewMatrix transformation matrix
370 * @param outer the outer roundrect
371 * @param inner the inner roundrect
robertphillips00095892016-02-29 13:50:40 -0800372 */
373 void drawDRRect(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500374 GrPaint&&,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500375 GrAA,
robertphillips00095892016-02-29 13:50:40 -0800376 const SkMatrix& viewMatrix,
377 const SkRRect& outer,
378 const SkRRect& inner);
379
380 /**
robertphillipsea461502015-05-26 11:38:03 -0700381 * Draws a path.
382 *
383 * @param paint describes how to color pixels.
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500384 * @param GrAA Controls whether the path is antialiased.
robertphillipsea461502015-05-26 11:38:03 -0700385 * @param viewMatrix transformation matrix
386 * @param path the path to draw
bsalomon6663acf2016-05-10 09:14:17 -0700387 * @param style style to apply to the path.
robertphillipsea461502015-05-26 11:38:03 -0700388 */
robertphillips2e1e51f2015-10-15 08:01:48 -0700389 void drawPath(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500390 GrPaint&&,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500391 GrAA,
robertphillipsea461502015-05-26 11:38:03 -0700392 const SkMatrix& viewMatrix,
393 const SkPath&,
Robert Phillips20390c32018-08-17 11:01:03 -0400394 const GrStyle&);
395
396 /**
397 * Draws a shape.
398 *
399 * @param paint describes how to color pixels.
400 * @param GrAA Controls whether the path is antialiased.
401 * @param viewMatrix transformation matrix
402 * @param shape the shape to draw
403 */
404 void drawShape(const GrClip&,
405 GrPaint&&,
406 GrAA,
407 const SkMatrix& viewMatrix,
408 const GrShape&);
409
robertphillipsea461502015-05-26 11:38:03 -0700410
411 /**
412 * Draws vertices with a paint.
413 *
Brian Osmanae0c50c2017-05-25 16:56:34 -0400414 * @param paint describes how to color pixels.
415 * @param viewMatrix transformation matrix
416 * @param vertices specifies the mesh to draw.
417 * @param overridePrimType primitive type to draw. If NULL, derive prim type from vertices.
Brian Osman3c358422020-03-23 10:44:12 -0400418 * @param effect runtime effect that will handle custom vertex attributes.
robertphillipsea461502015-05-26 11:38:03 -0700419 */
robertphillips2e1e51f2015-10-15 08:01:48 -0700420 void drawVertices(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500421 GrPaint&& paint,
robertphillipsea461502015-05-26 11:38:03 -0700422 const SkMatrix& viewMatrix,
Brian Osmanae0c50c2017-05-25 16:56:34 -0400423 sk_sp<SkVertices> vertices,
Brian Osman3c358422020-03-23 10:44:12 -0400424 GrPrimitiveType* overridePrimType = nullptr,
425 const SkRuntimeEffect* effect = nullptr);
Brian Salomon199fb872017-02-06 09:41:10 -0500426
427 /**
Brian Osman4d92b892019-03-24 00:53:23 +0000428 * Draws textured sprites from an atlas with a paint. This currently does not support AA for the
429 * sprite rectangle edges.
430 *
431 * @param paint describes how to color pixels.
432 * @param viewMatrix transformation matrix
433 * @param spriteCount number of sprites.
434 * @param xform array of compressed transformation data, required.
435 * @param texRect array of texture rectangles used to access the paint.
436 * @param colors optional array of per-sprite colors, supercedes
437 * the paint's color field.
438 */
439 void drawAtlas(const GrClip&,
440 GrPaint&& paint,
441 const SkMatrix& viewMatrix,
442 int spriteCount,
443 const SkRSXform xform[],
444 const SkRect texRect[],
445 const SkColor colors[]);
446
447 /**
msarettcc319b92016-08-25 18:07:18 -0700448 * Draws a region.
449 *
450 * @param paint describes how to color pixels
451 * @param viewMatrix transformation matrix
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500452 * @param aa should the rects of the region be antialiased.
msarettcc319b92016-08-25 18:07:18 -0700453 * @param region the region to be drawn
454 * @param style style to apply to the region
455 */
456 void drawRegion(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500457 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500458 GrAA aa,
msarettcc319b92016-08-25 18:07:18 -0700459 const SkMatrix& viewMatrix,
460 const SkRegion& region,
Stan Iliev73d8fd92017-08-02 15:36:24 -0400461 const GrStyle& style,
462 const GrUserStencilSettings* ss = nullptr);
msarettcc319b92016-08-25 18:07:18 -0700463
jvanverth31ff7622015-08-07 10:09:28 -0700464 /**
robertphillipsea461502015-05-26 11:38:03 -0700465 * Draws an oval.
466 *
467 * @param paint describes how to color pixels.
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500468 * @param GrAA Controls whether the oval is antialiased.
robertphillipsea461502015-05-26 11:38:03 -0700469 * @param viewMatrix transformation matrix
470 * @param oval the bounding rect of the oval.
bsalomon6663acf2016-05-10 09:14:17 -0700471 * @param style style to apply to the oval. Currently path effects are not allowed.
robertphillipsea461502015-05-26 11:38:03 -0700472 */
robertphillips2e1e51f2015-10-15 08:01:48 -0700473 void drawOval(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500474 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500475 GrAA,
robertphillipsea461502015-05-26 11:38:03 -0700476 const SkMatrix& viewMatrix,
477 const SkRect& oval,
bsalomon6663acf2016-05-10 09:14:17 -0700478 const GrStyle& style);
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500479 /**
480 * Draws a partial arc of an oval.
481 *
482 * @param paint describes how to color pixels.
Brian Salomon99504082016-12-09 15:51:31 -0500483 * @param GrGrAA Controls whether the arc is antialiased.
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500484 * @param viewMatrix transformation matrix.
485 * @param oval the bounding rect of the oval.
486 * @param startAngle starting angle in degrees.
487 * @param sweepAngle angle to sweep in degrees. Must be in (-360, 360)
488 * @param useCenter true means that the implied path begins at the oval center, connects as
489 * a line to the point indicated by the start contains the arc indicated by
490 * the sweep angle. If false the line beginning at the center point is
491 * omitted.
492 * @param style style to apply to the oval.
493 */
bsalomon4f3a0ca2016-08-22 13:14:26 -0700494 void drawArc(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500495 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500496 GrAA,
bsalomon4f3a0ca2016-08-22 13:14:26 -0700497 const SkMatrix& viewMatrix,
498 const SkRect& oval,
499 SkScalar startAngle,
500 SkScalar sweepAngle,
501 bool useCenter,
502 const GrStyle& style);
robertphillipsea461502015-05-26 11:38:03 -0700503
joshualitt33a5fce2015-11-18 13:28:51 -0800504 /**
bsalomon4f3a0ca2016-08-22 13:14:26 -0700505 * Draw the image as a set of rects, specified by |iter|.
joshualitt33a5fce2015-11-18 13:28:51 -0800506 */
msarett10e3d9b2016-08-18 15:46:03 -0700507 void drawImageLattice(const GrClip&,
Brian Salomon2a943df2018-05-04 13:43:19 -0400508 GrPaint&&,
msarett10e3d9b2016-08-18 15:46:03 -0700509 const SkMatrix& viewMatrix,
Greg Danieled96bca2019-12-05 15:05:54 -0500510 GrSurfaceProxyView,
Greg Daniel82c6b102020-01-21 10:33:22 -0500511 SkAlphaType alphaType,
Brian Salomon2a943df2018-05-04 13:43:19 -0400512 sk_sp<GrColorSpaceXform>,
513 GrSamplerState::Filter,
514 std::unique_ptr<SkLatticeIter>,
msarett10e3d9b2016-08-18 15:46:03 -0700515 const SkRect& dst);
robertphillipsea461502015-05-26 11:38:03 -0700516
robertphillips8c523e02016-07-26 07:41:00 -0700517 /**
Greg Daniel46cfbc62019-06-07 11:43:30 -0400518 * Draws the src texture with no matrix. The dstRect is the dstPoint with the width and height
519 * of the srcRect. The srcRect and dstRect are clipped to the bounds of the src and dst surfaces
520 * respectively.
521 */
Greg Daniel573312e2020-02-07 17:22:35 -0500522 bool blitTexture(GrSurfaceProxyView view, const SkIRect& srcRect, const SkIPoint& dstPoint);
Greg Daniel46cfbc62019-06-07 11:43:30 -0400523
524 /**
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400525 * Adds the necessary signal and wait semaphores and adds the passed in SkDrawable to the
526 * command stream.
527 */
528 void drawDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler>, const SkRect& bounds);
529
Brian Salomonab32f652019-05-10 14:24:50 -0400530 using ReadPixelsCallback = SkSurface::ReadPixelsCallback;
531 using ReadPixelsContext = SkSurface::ReadPixelsContext;
Brian Salomon024bd002019-06-11 11:38:16 -0400532 using RescaleGamma = SkSurface::RescaleGamma;
533
534 // GPU implementation for SkSurface::asyncRescaleAndReadPixels.
Brian Salomon031b0ba2019-05-23 11:05:26 -0400535 void asyncRescaleAndReadPixels(const SkImageInfo& info, const SkIRect& srcRect,
Brian Salomon024bd002019-06-11 11:38:16 -0400536 RescaleGamma rescaleGamma, SkFilterQuality rescaleQuality,
537 ReadPixelsCallback callback, ReadPixelsContext context);
538 // GPU implementation for SkSurface::asyncRescaleAndReadPixelsYUV420.
539 void asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace,
Brian Salomon9241a6d2019-10-03 13:26:54 -0400540 sk_sp<SkColorSpace> dstColorSpace,
541 const SkIRect& srcRect,
Brian Salomona56a7462020-02-07 14:17:25 -0500542 SkISize dstSize,
Brian Salomon9241a6d2019-10-03 13:26:54 -0400543 RescaleGamma rescaleGamma,
Brian Salomon024bd002019-06-11 11:38:16 -0400544 SkFilterQuality rescaleQuality,
Brian Salomon9241a6d2019-10-03 13:26:54 -0400545 ReadPixelsCallback callback,
Brian Salomon024bd002019-06-11 11:38:16 -0400546 ReadPixelsContext context);
Brian Salomonab32f652019-05-10 14:24:50 -0400547
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400548 /**
robertphillips8c523e02016-07-26 07:41:00 -0700549 * After this returns any pending surface IO will be issued to the backend 3D API and
550 * if the surface has MSAA it will be resolved.
551 */
Greg Daniele6bfb7d2019-04-17 15:26:11 -0400552 GrSemaphoresSubmitted flush(SkSurface::BackendSurfaceAccess access, const GrFlushInfo&);
Greg Daniela5cb7812017-06-16 09:45:32 -0400553
554 /**
555 * The next time this GrRenderTargetContext is flushed, the gpu will wait on the passed in
556 * semaphores before executing any commands.
557 */
Robert Phillipsbc4994a2019-02-14 08:36:56 -0500558 bool waitOnSemaphores(int numSemaphores, const GrBackendSemaphore waitSemaphores[]);
robertphillips8c523e02016-07-26 07:41:00 -0700559
Greg Daniel46e366a2019-12-16 14:38:36 -0500560 int numSamples() const { return this->asRenderTargetProxy()->numSamples(); }
robertphillipsca6eafc2016-05-17 09:57:46 -0700561 const SkSurfaceProps& surfaceProps() const { return fSurfaceProps; }
Greg Daniel46e366a2019-12-16 14:38:36 -0500562 bool wrapsVkSecondaryCB() const { return this->asRenderTargetProxy()->wrapsVkSecondaryCB(); }
Greg Daniele252f082017-10-23 16:05:23 -0400563 GrMipMapped mipMapped() const;
robertphillips7bceedc2015-12-01 12:51:26 -0800564
Greg Daniel3912a4b2020-01-14 09:56:04 -0500565 // TODO: See if it makes sense for this to return a const& instead and require the callers to
566 // make a copy (which refs the proxy) if needed.
Brian Salomon8afde5f2020-04-01 16:22:00 -0400567 GrSurfaceProxyView writeSurfaceView() { return fWriteView; }
Greg Daniela83de582019-10-22 09:33:25 -0400568
Robert Phillipsbe9aff22019-02-15 11:33:22 -0500569 // This entry point should only be called if the backing GPU object is known to be
570 // instantiated.
Greg Daniel3912a4b2020-01-14 09:56:04 -0500571 GrRenderTarget* accessRenderTarget() { return this->asSurfaceProxy()->peekRenderTarget(); }
Robert Phillipseaa86252016-11-08 13:49:39 +0000572
Robert Phillipsd46697a2017-01-25 12:10:37 -0500573 GrRenderTargetContext* asRenderTargetContext() override { return this; }
574
robertphillips391395d2016-03-02 09:26:36 -0800575 // Provides access to functions that aren't part of the public API.
Brian Osman693a5402016-10-27 15:13:22 -0400576 GrRenderTargetContextPriv priv();
577 const GrRenderTargetContextPriv priv() const;
joshualittf5883a62016-01-13 07:47:38 -0800578
Herb Derbyc1b482c2018-08-09 15:02:27 -0400579 GrTextTarget* textTarget() { return fTextTarget.get(); }
Brian Salomonf18b1d82017-10-27 11:30:49 -0400580
Robert Phillipsb5204762019-06-19 14:12:13 -0400581#if GR_TEST_UTILS
Greg Daniel3912a4b2020-01-14 09:56:04 -0500582 bool testingOnly_IsInstantiated() const { return this->asSurfaceProxy()->isInstantiated(); }
Chris Dalton6b982802019-06-27 13:53:46 -0600583 void testingOnly_SetPreserveOpsOnFullClear() { fPreserveOpsOnFullClear_TestingOnly = true; }
Greg Danielf41b2bd2019-08-22 16:19:24 -0400584 GrOpsTask* testingOnly_PeekLastOpsTask() { return fOpsTask.get(); }
Robert Phillipsb5204762019-06-19 14:12:13 -0400585#endif
Robert Phillipseaa86252016-11-08 13:49:39 +0000586
robertphillipsea461502015-05-26 11:38:03 -0700587private:
Brian Salomonf18b1d82017-10-27 11:30:49 -0400588 class TextTarget;
Michael Ludwig61328202019-06-19 14:48:58 +0000589 enum class QuadOptimization;
Brian Salomonf18b1d82017-10-27 11:30:49 -0400590
Chris Dalton7d6748e2019-03-13 00:34:52 -0600591 GrAAType chooseAAType(GrAA);
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500592
Brian Salomon649a3412017-03-09 13:50:43 -0500593 friend class GrAtlasTextBlob; // for access to add[Mesh]DrawOp
Greg Danielf41b2bd2019-08-22 16:19:24 -0400594 friend class GrClipStackClip; // for access to getOpsTask
Chris Daltonc4b47352019-08-23 10:10:36 -0600595 friend class GrOnFlushResourceProvider; // for access to getOpsTask (http://skbug.com/9357)
robertphillips55fdccc2016-06-06 06:16:20 -0700596
Brian Osman11052242016-10-27 14:47:55 -0400597 friend class GrRenderTargetContextPriv;
robertphillips976f5f02016-06-03 10:59:20 -0700598
Brian Salomon42521e82016-12-07 16:44:58 -0500599 // All the path renderers currently make their own ops
Brian Salomon649a3412017-03-09 13:50:43 -0500600 friend class GrSoftwarePathRenderer; // for access to add[Mesh]DrawOp
601 friend class GrAAConvexPathRenderer; // for access to add[Mesh]DrawOp
602 friend class GrDashLinePathRenderer; // for access to add[Mesh]DrawOp
603 friend class GrAAHairLinePathRenderer; // for access to add[Mesh]DrawOp
604 friend class GrAALinearizingConvexPathRenderer; // for access to add[Mesh]DrawOp
Jim Van Verth83010462017-03-16 08:45:39 -0400605 friend class GrSmallPathRenderer; // for access to add[Mesh]DrawOp
Brian Salomon649a3412017-03-09 13:50:43 -0500606 friend class GrDefaultPathRenderer; // for access to add[Mesh]DrawOp
Brian Salomon649a3412017-03-09 13:50:43 -0500607 friend class GrStencilAndCoverPathRenderer; // for access to add[Mesh]DrawOp
Chris Dalton17dc4182020-03-25 16:18:16 -0600608 friend class GrTriangulatingPathRenderer; // for access to add[Mesh]DrawOp
Chris Dalton9414c962018-06-14 10:14:50 -0600609 friend class GrCCPerFlushResources; // for access to addDrawOp
Chris Dalton1a325d22017-07-14 15:17:41 -0600610 friend class GrCoverageCountingPathRenderer; // for access to addDrawOp
Robert Phillips438d9862019-11-14 12:46:05 -0500611 friend class GrFillRectOp; // for access to addDrawOp
Chris Dalton0a22b1e2020-03-26 11:52:15 -0600612 friend class GrTessellationPathRenderer; // for access to addDrawOp
Robert Phillipse837e612019-11-15 11:02:50 -0500613 friend class GrTextureOp; // for access to addDrawOp
Robert Phillips438d9862019-11-14 12:46:05 -0500614
Greg Daniel46e366a2019-12-16 14:38:36 -0500615 SkDEBUGCODE(void onValidate() const override;)
Greg Daniela83de582019-10-22 09:33:25 -0400616
617
Greg Danielf41b2bd2019-08-22 16:19:24 -0400618 GrOpsTask::CanDiscardPreviousOps canDiscardPreviousOpsOnFullClear() const;
Chris Dalton858cf232019-10-14 16:20:00 -0600619 void setNeedsStencil(bool useMixedSamplesIfNotMSAA);
Chris Dalton6b982802019-06-27 13:53:46 -0600620
Brian Osman9a9baae2018-11-05 15:06:26 -0500621 void internalClear(const GrFixedClip&, const SkPMColor4f&, CanClearFullscreen);
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500622 void internalStencilClear(const GrFixedClip&, bool insideStencilMask);
csmartdalton29df7602016-08-31 11:55:52 -0700623
Brian Salomon82f44312017-01-11 13:42:54 -0500624 // Only consumes the GrPaint if successful.
robertphillips00095892016-02-29 13:50:40 -0800625 bool drawFilledDRRect(const GrClip& clip,
Brian Salomon82f44312017-01-11 13:42:54 -0500626 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500627 GrAA,
robertphillips00095892016-02-29 13:50:40 -0800628 const SkMatrix& viewMatrix,
629 const SkRRect& origOuter,
630 const SkRRect& origInner);
631
Michael Ludwig61328202019-06-19 14:48:58 +0000632 // If the drawn quad's paint is a const blended color, provide it as a non-null pointer to
633 // 'constColor', which enables the draw-as-clear optimization. Otherwise it is assumed the paint
634 // requires some form of shading that invalidates using a clear op.
635 //
636 // The non-const pointers should be the original draw request on input, and will be updated as
637 // appropriate depending on the returned optimization level.
638 //
Michael Ludwige08b4432019-06-19 18:00:48 -0400639 // 'stencilSettings' are provided merely for decision making purposes; When non-null,
640 // optimization strategies that submit special ops are avoided.
Michael Ludwig61328202019-06-19 14:48:58 +0000641 QuadOptimization attemptQuadOptimization(const GrClip& clip,
642 const SkPMColor4f* constColor,
Michael Ludwige08b4432019-06-19 18:00:48 -0400643 const GrUserStencilSettings* stencilSettings,
Michael Ludwig61328202019-06-19 14:48:58 +0000644 GrAA* aa,
Michael Ludwig6b45c5d2020-02-07 09:56:38 -0500645 DrawQuad* quad);
robertphillips44302392016-07-08 14:43:03 -0700646
Michael Ludwig61328202019-06-19 14:48:58 +0000647 // If stencil settings, 'ss', are non-null, AA controls MSAA or no AA. If they are null, then AA
648 // can choose between coverage, MSAA as per chooseAAType(). This will always attempt to apply
649 // quad optimizations, so all quad/rect public APIs should rely on this function for consistent
Michael Ludwig6b45c5d2020-02-07 09:56:38 -0500650 // clipping behavior. 'quad' will be modified in place to reflect final rendered geometry.
Michael Ludwig61328202019-06-19 14:48:58 +0000651 void drawFilledQuad(const GrClip& clip,
652 GrPaint&& paint,
653 GrAA aa,
Michael Ludwig6b45c5d2020-02-07 09:56:38 -0500654 DrawQuad* quad,
Michael Ludwig61328202019-06-19 14:48:58 +0000655 const GrUserStencilSettings* ss = nullptr);
Brian Salomon7694b902019-06-18 21:00:21 +0000656
Michael Ludwig6b45c5d2020-02-07 09:56:38 -0500657 // Like drawFilledQuad but does not require using a GrPaint or FP for texturing.
658 // 'quad' may be modified in place to reflect final geometry.
Michael Ludwigaee26ea2019-07-08 16:22:48 +0000659 void drawTexturedQuad(const GrClip& clip,
Greg Daniel549325c2019-10-30 16:19:20 -0400660 GrSurfaceProxyView proxyView,
Brian Salomonfc118442019-11-22 19:09:27 -0500661 SkAlphaType alphaType,
Michael Ludwigaee26ea2019-07-08 16:22:48 +0000662 sk_sp<GrColorSpaceXform> textureXform,
663 GrSamplerState::Filter filter,
664 const SkPMColor4f& color,
665 SkBlendMode blendMode,
666 GrAA aa,
Michael Ludwig6b45c5d2020-02-07 09:56:38 -0500667 DrawQuad* quad,
Michael Ludwigaee26ea2019-07-08 16:22:48 +0000668 const SkRect* domain = nullptr);
669
Brian Salomon2fad74a2017-12-20 13:28:55 -0500670 void drawShapeUsingPathRenderer(const GrClip&, GrPaint&&, GrAA, const SkMatrix&,
671 const GrShape&);
robertphillipsea461502015-05-26 11:38:03 -0700672
Chris Dalton08755122019-08-05 16:13:47 -0600673 void addOp(std::unique_ptr<GrOp>);
674
Brian Salomon348a0372018-10-31 10:42:18 -0400675 // Allows caller of addDrawOp to know which op list an op will be added to.
Greg Danielf41b2bd2019-08-22 16:19:24 -0400676 using WillAddOpFn = void(GrOp*, uint32_t opsTaskID);
Brian Salomon348a0372018-10-31 10:42:18 -0400677 // These perform processing specific to GrDrawOp-derived ops before recording them into an
678 // op list. Before adding the op to an op list the WillAddOpFn is called. Note that it
679 // will not be called in the event that the op is discarded. Moreover, the op may merge into
680 // another op after the function is called (either before addDrawOp returns or some time later).
681 void addDrawOp(const GrClip&, std::unique_ptr<GrDrawOp>,
682 const std::function<WillAddOpFn>& = std::function<WillAddOpFn>());
robertphillips2334fb62015-06-17 05:43:33 -0700683
Robert Phillipsbf25d432017-04-07 10:08:53 -0400684 // Makes a copy of the proxy if it is necessary for the draw and places the texture that should
685 // be used by GrXferProcessor to access the destination color in 'result'. If the return
686 // value is false then a texture copy could not be made.
Greg Daniel524e28b2019-11-01 11:48:53 -0400687 bool SK_WARN_UNUSED_RESULT setupDstProxyView(const GrClip&, const GrOp& op,
688 GrXferProcessor::DstProxyView* result);
Brian Salomon467921e2017-03-06 16:17:12 -0500689
Brian Salomon9241a6d2019-10-03 13:26:54 -0400690 class AsyncReadResult;
691
Brian Salomon024bd002019-06-11 11:38:16 -0400692 // The async read step of asyncRescaleAndReadPixels()
693 void asyncReadPixels(const SkIRect& rect, SkColorType colorType, ReadPixelsCallback callback,
694 ReadPixelsContext context);
695
Greg Danielf41b2bd2019-08-22 16:19:24 -0400696 GrOpsTask* getOpsTask();
robertphillipsa106c622015-10-16 09:07:06 -0700697
Herb Derbyc1b482c2018-08-09 15:02:27 -0400698 std::unique_ptr<GrTextTarget> fTextTarget;
Greg Daniela83de582019-10-22 09:33:25 -0400699
Brian Salomon8afde5f2020-04-01 16:22:00 -0400700 GrSurfaceProxyView fWriteView;
robertphillipsa106c622015-10-16 09:07:06 -0700701
Greg Danielf41b2bd2019-08-22 16:19:24 -0400702 // In MDB-mode the GrOpsTask can be closed by some other renderTargetContext that has picked
703 // it up. For this reason, the GrOpsTask should only ever be accessed via 'getOpsTask'.
704 sk_sp<GrOpsTask> fOpsTask;
robertphillips2334fb62015-06-17 05:43:33 -0700705
Brian Salomonf18b1d82017-10-27 11:30:49 -0400706 SkSurfaceProps fSurfaceProps;
Greg Danielf41b2bd2019-08-22 16:19:24 -0400707 bool fManagedOpsTask;
Robert Phillipse305cc1f2016-12-14 12:19:05 -0500708
Chris Daltoneffee202019-07-01 22:28:03 -0600709 int fNumStencilSamples = 0;
Chris Dalton6b982802019-06-27 13:53:46 -0600710#if GR_TEST_UTILS
711 bool fPreserveOpsOnFullClear_TestingOnly = false;
712#endif
713
Robert Phillipse305cc1f2016-12-14 12:19:05 -0500714 typedef GrSurfaceContext INHERITED;
robertphillipsea461502015-05-26 11:38:03 -0700715};
716
717#endif