blob: c036be93111d4a7fccbc4f04cb2af548d817cd36 [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
Brian Salomon7c8460e2017-05-12 11:36:10 -040011#include "../private/GrRenderTargetProxy.h"
csmartdaltonecbc12b2016-06-08 10:08:43 -070012#include "GrPaint.h"
Brian Osman45580d32016-11-23 09:37:01 -050013#include "GrSurfaceContext.h"
Brian Salomon7c8460e2017-05-12 11:36:10 -040014#include "GrTypesPriv.h"
Brian Salomon467921e2017-03-06 16:17:12 -050015#include "GrXferProcessor.h"
Brian Salomon238069b2018-07-11 15:58:57 -040016#include "SkCanvas.h"
Greg Daniel64cc9aa2018-10-19 13:54:56 -040017#include "SkDrawable.h"
robertphillipsea461502015-05-26 11:38:03 -070018#include "SkRefCnt.h"
Greg Danielbae71212019-03-01 15:24:35 -050019#include "SkSurface.h"
robertphillipsfcf78292015-06-19 11:49:52 -070020#include "SkSurfaceProps.h"
Herb Derbyc1b482c2018-08-09 15:02:27 -040021#include "text/GrTextTarget.h"
robertphillipsea461502015-05-26 11:38:03 -070022
Greg Daniela5cb7812017-06-16 09:45:32 -040023class GrBackendSemaphore;
robertphillipsea461502015-05-26 11:38:03 -070024class GrClip;
Brian Osman2240be92017-10-18 13:15:13 -040025class GrColorSpaceXform;
Chris Dalton1a325d22017-07-14 15:17:41 -060026class GrCoverageCountingPathRenderer;
robertphillips77a2e522015-10-17 07:43:27 -070027class GrDrawingManager;
Brian Salomon9afd3712016-12-01 10:59:09 -050028class GrDrawOp;
csmartdalton29df7602016-08-31 11:55:52 -070029class GrFixedClip;
Robert Phillips0d075de2019-03-04 11:08:13 -050030class GrOp;
robertphillipsea461502015-05-26 11:38:03 -070031class GrRenderTarget;
Brian Osman45580d32016-11-23 09:37:01 -050032class GrRenderTargetContextPriv;
Robert Phillipsf2361d22016-10-25 14:20:06 -040033class GrRenderTargetOpList;
Brian Salomon2fad74a2017-12-20 13:28:55 -050034class GrShape;
bsalomon6663acf2016-05-10 09:14:17 -070035class GrStyle;
Robert Phillipseaa86252016-11-08 13:49:39 +000036class GrTextureProxy;
robertphillips44302392016-07-08 14:43:03 -070037struct GrUserStencilSettings;
Jim Van Verth3af1af92017-05-18 15:06:54 -040038struct SkDrawShadowRec;
Herb Derbycddab252018-07-16 11:19:04 -040039class SkGlyphRunList;
robertphillipsea461502015-05-26 11:38:03 -070040struct SkIPoint;
41struct SkIRect;
msarett10e3d9b2016-08-18 15:46:03 -070042class SkLatticeIter;
robertphillipsea461502015-05-26 11:38:03 -070043class SkMatrix;
robertphillips2334fb62015-06-17 05:43:33 -070044class SkPaint;
robertphillipsea461502015-05-26 11:38:03 -070045class SkPath;
46struct SkPoint;
47struct SkRect;
Brian Osman45580d32016-11-23 09:37:01 -050048class SkRegion;
robertphillipsea461502015-05-26 11:38:03 -070049class SkRRect;
jvanverth31ff7622015-08-07 10:09:28 -070050struct SkRSXform;
robertphillips2334fb62015-06-17 05:43:33 -070051class SkTextBlob;
Brian Salomon199fb872017-02-06 09:41:10 -050052class SkVertices;
robertphillipsea461502015-05-26 11:38:03 -070053
Brian Osman45580d32016-11-23 09:37:01 -050054/**
55 * A helper object to orchestrate commands (draws, etc...) for GrSurfaces that are GrRenderTargets.
robertphillipsea461502015-05-26 11:38:03 -070056 */
Brian Osman45580d32016-11-23 09:37:01 -050057class SK_API GrRenderTargetContext : public GrSurfaceContext {
robertphillipsea461502015-05-26 11:38:03 -070058public:
Brian Osman11052242016-10-27 14:47:55 -040059 ~GrRenderTargetContext() override;
robertphillips2334fb62015-06-17 05:43:33 -070060
Robert Phillipse4643cc2018-08-14 13:01:29 -040061 virtual void drawGlyphRunList(const GrClip&, const SkMatrix& viewMatrix, const SkGlyphRunList&);
robertphillipsea461502015-05-26 11:38:03 -070062
robertphillipsea461502015-05-26 11:38:03 -070063 /**
64 * Provides a perfomance hint that the render target's contents are allowed
65 * to become undefined.
66 */
robertphillips2e1e51f2015-10-15 08:01:48 -070067 void discard();
robertphillipsea461502015-05-26 11:38:03 -070068
Chris Dalton344e9032017-12-11 15:42:09 -070069 enum class CanClearFullscreen : bool {
70 kNo = false,
71 kYes = true
72 };
73
robertphillipsea461502015-05-26 11:38:03 -070074 /**
75 * Clear the entire or rect of the render target, ignoring any clips.
robertphillipsea461502015-05-26 11:38:03 -070076 * @param rect the rect to clear or the whole thing if rect is NULL.
77 * @param color the color to clear to.
Chris Dalton344e9032017-12-11 15:42:09 -070078 * @param CanClearFullscreen allows partial clears to be converted to fullscreen clears on
79 * tiling platforms where that is an optimization.
robertphillipsea461502015-05-26 11:38:03 -070080 */
Brian Osman9a9baae2018-11-05 15:06:26 -050081 void clear(const SkIRect* rect, const SkPMColor4f& color, CanClearFullscreen);
robertphillipsea461502015-05-26 11:38:03 -070082
83 /**
84 * Draw everywhere (respecting the clip) with the paint.
85 */
Brian Salomon82f44312017-01-11 13:42:54 -050086 void drawPaint(const GrClip&, GrPaint&&, const SkMatrix& viewMatrix);
robertphillipsea461502015-05-26 11:38:03 -070087
88 /**
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050089 * Draw the rect using a paint.
90 * @param paint describes how to color pixels.
91 * @param GrAA Controls whether rect is antialiased
92 * @param viewMatrix transformation matrix
93 * @param style The style to apply. Null means fill. Currently path effects are not
94 * allowed.
95 * The rects coords are used to access the paint (through texture matrix)
robertphillipsea461502015-05-26 11:38:03 -070096 */
robertphillips2e1e51f2015-10-15 08:01:48 -070097 void drawRect(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -050098 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050099 GrAA,
robertphillipsea461502015-05-26 11:38:03 -0700100 const SkMatrix& viewMatrix,
101 const SkRect&,
Brian Salomon82f44312017-01-11 13:42:54 -0500102 const GrStyle* style = nullptr);
robertphillipsea461502015-05-26 11:38:03 -0700103
104 /**
bsalomona2e69fc2015-11-05 10:41:43 -0800105 * Maps a rectangle of shader coordinates to a rectangle and fills that rectangle.
robertphillipsea461502015-05-26 11:38:03 -0700106 *
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500107 * @param paint describes how to color pixels.
108 * @param GrAA Controls whether rect is antialiased
109 * @param viewMatrix transformation matrix which applies to rectToDraw
110 * @param rectToDraw the rectangle to draw
111 * @param localRect the rectangle of shader coordinates applied to rectToDraw
robertphillipsea461502015-05-26 11:38:03 -0700112 */
Michael Ludwig136f45a2019-02-19 11:44:41 -0500113 void fillRectToRect(const GrClip& clip,
Brian Salomon82f44312017-01-11 13:42:54 -0500114 GrPaint&& paint,
Michael Ludwig136f45a2019-02-19 11:44:41 -0500115 GrAA aa,
bsalomona2e69fc2015-11-05 10:41:43 -0800116 const SkMatrix& viewMatrix,
117 const SkRect& rectToDraw,
Michael Ludwig136f45a2019-02-19 11:44:41 -0500118 const SkRect& localRect) {
119 this->fillRectWithEdgeAA(clip, std::move(paint), aa,
120 aa == GrAA::kYes ? GrQuadAAFlags::kAll : GrQuadAAFlags::kNone,
121 viewMatrix, rectToDraw, &localRect);
122 }
robertphillipsea461502015-05-26 11:38:03 -0700123
124 /**
bsalomona2e69fc2015-11-05 10:41:43 -0800125 * Fills a rect with a paint and a localMatrix.
robertphillipsea461502015-05-26 11:38:03 -0700126 */
bsalomona2e69fc2015-11-05 10:41:43 -0800127 void fillRectWithLocalMatrix(const GrClip& clip,
Brian Salomon82f44312017-01-11 13:42:54 -0500128 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500129 GrAA,
bsalomona2e69fc2015-11-05 10:41:43 -0800130 const SkMatrix& viewMatrix,
131 const SkRect& rect,
132 const SkMatrix& localMatrix);
robertphillipsea461502015-05-26 11:38:03 -0700133
Michael Ludwig75451902019-01-23 11:14:29 -0500134 /**
135 * Creates an op that draws a fill rect with per-edge control over anti-aliasing.
Michael Ludwigce62dec2019-02-19 11:48:46 -0500136 *
137 * This is a specialized version of fillQuadWithEdgeAA, but is kept separate since knowing
138 * the geometry is a rectangle affords more optimizations.
Michael Ludwig75451902019-01-23 11:14:29 -0500139 */
Michael Ludwig136f45a2019-02-19 11:44:41 -0500140 void fillRectWithEdgeAA(const GrClip& clip, GrPaint&& paint, GrAA aa, GrQuadAAFlags edgeAA,
141 const SkMatrix& viewMatrix, const SkRect& rect,
142 const SkRect* optionalLocalRect = nullptr);
Michael Ludwig75451902019-01-23 11:14:29 -0500143
Michael Ludwigce62dec2019-02-19 11:48:46 -0500144 /**
145 * Similar to fillRectWithEdgeAA but draws an arbitrary 2D convex quadrilateral transformed
146 * by 'viewMatrix', with per-edge control over anti-aliasing. The quad should follow the
147 * ordering used by SkRect::toQuad(), which determines how the edge AA is applied:
148 * - "top" = points [0] and [1]
149 * - "right" = points[1] and [2]
150 * - "bottom" = points[2] and [3]
151 * - "left" = points[3] and [0]
152 *
153 * The last argument, 'optionalLocalQuad', can be null if no separate local coordinates are
154 * necessary.
155 */
156 void fillQuadWithEdgeAA(const GrClip& clip, GrPaint&& paint, GrAA aa, GrQuadAAFlags edgeAA,
157 const SkMatrix& viewMatrix, const SkPoint quad[4],
158 const SkPoint optionalLocalQuad[4]);
159
Michael Ludwig69858532018-11-28 15:34:34 -0500160 /** Used with drawQuadSet */
161 struct QuadSetEntry {
162 SkRect fRect;
163 SkPMColor4f fColor; // Overrides any color on the GrPaint
164 SkMatrix fLocalMatrix;
165 GrQuadAAFlags fAAFlags;
166 };
167
Michael Ludwig75451902019-01-23 11:14:29 -0500168 // TODO(michaelludwig) - remove if the bulk API is not useful for SkiaRenderer
Michael Ludwig69858532018-11-28 15:34:34 -0500169 void drawQuadSet(const GrClip& clip, GrPaint&& paint, GrAA aa, const SkMatrix& viewMatrix,
170 const QuadSetEntry[], int cnt);
171
robertphillipsea461502015-05-26 11:38:03 -0700172 /**
Brian Salomon34169692017-08-28 15:32:01 -0400173 * Creates an op that draws a subrectangle of a texture. The passed color is modulated by the
174 * texture's color. 'srcRect' specifies the rectangle of the texture to draw. 'dstRect'
175 * specifies the rectangle to draw in local coords which will be transformed by 'viewMatrix' to
Brian Salomonbe3c1d22018-05-21 12:54:39 -0400176 * device space.
Brian Salomon34169692017-08-28 15:32:01 -0400177 */
Brian Osman3d139a42018-11-19 10:42:10 -0500178 void drawTexture(const GrClip& clip, sk_sp<GrTextureProxy>, GrSamplerState::Filter,
Michael Ludwigd54ca8f2019-02-13 13:25:21 -0500179 SkBlendMode mode, const SkPMColor4f&, const SkRect& srcRect,
Michael Ludwig136f45a2019-02-19 11:44:41 -0500180 const SkRect& dstRect, GrAA, GrQuadAAFlags, SkCanvas::SrcRectConstraint,
Michael Ludwigd54ca8f2019-02-13 13:25:21 -0500181 const SkMatrix& viewMatrix, sk_sp<GrColorSpaceXform> texXform);
Brian Salomon34169692017-08-28 15:32:01 -0400182
Michael Ludwigce62dec2019-02-19 11:48:46 -0500183 /**
184 * Variant of drawTexture that instead draws the texture applied to 'dstQuad' transformed by
185 * 'viewMatrix', using the 'srcQuad' texture coordinates clamped to the optional 'domain'. If
186 * 'domain' is null, it's equivalent to using the fast src rect constraint. If 'domain' is
187 * provided, the strict src rect constraint is applied using 'domain'.
188 */
189 void drawTextureQuad(const GrClip& clip, sk_sp<GrTextureProxy>, GrSamplerState::Filter,
190 SkBlendMode mode, const SkPMColor4f&, const SkPoint srcQuad[4],
191 const SkPoint dstQuad[4], GrAA, GrQuadAAFlags, const SkRect* domain,
192 const SkMatrix& viewMatrix, sk_sp<GrColorSpaceXform> texXform);
193
Brian Salomond7065e72018-10-12 11:42:02 -0400194 /** Used with drawTextureSet */
195 struct TextureSetEntry {
196 sk_sp<GrTextureProxy> fProxy;
197 SkRect fSrcRect;
198 SkRect fDstRect;
Michael Ludwig1433cfd2019-02-27 17:12:30 -0500199 const SkPoint* fDstClipQuad; // Must be null, or point to an array of 4 points
Michael Ludwig7ae2ab52019-03-05 16:00:20 -0500200 const SkMatrix* fPreViewMatrix; // If not null, entry's CTM is 'viewMatrix' * fPreViewMatrix
Brian Salomon1da5cad2018-11-21 09:21:18 -0500201 float fAlpha;
Brian Salomond7065e72018-10-12 11:42:02 -0400202 GrQuadAAFlags fAAFlags;
203 };
204 /**
205 * Draws a set of textures with a shared filter, color, view matrix, color xform, and
206 * texture color xform. The textures must all have the same GrTextureType and GrConfig.
Michael Ludwigce62dec2019-02-19 11:48:46 -0500207 *
208 * If any entries provide a non-null fDstClip array, it will be read from immediately based on
209 * fDstClipCount, so the pointer can become invalid after this returns.
Brian Salomond7065e72018-10-12 11:42:02 -0400210 */
211 void drawTextureSet(const GrClip&, const TextureSetEntry[], int cnt, GrSamplerState::Filter,
Michael Ludwig136f45a2019-02-19 11:44:41 -0500212 SkBlendMode mode, GrAA aa, const SkMatrix& viewMatrix,
Michael Ludwiga3c45c72019-01-17 17:26:48 -0500213 sk_sp<GrColorSpaceXform> texXform);
Brian Salomond7065e72018-10-12 11:42:02 -0400214
Brian Salomon34169692017-08-28 15:32:01 -0400215 /**
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500216 * Draw a roundrect using a paint.
robertphillipsea461502015-05-26 11:38:03 -0700217 *
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500218 * @param paint describes how to color pixels.
219 * @param GrAA Controls whether rrect is antialiased.
220 * @param viewMatrix transformation matrix
221 * @param rrect the roundrect to draw
222 * @param style style to apply to the rrect. Currently path effects are not allowed.
robertphillipsea461502015-05-26 11:38:03 -0700223 */
robertphillips2e1e51f2015-10-15 08:01:48 -0700224 void drawRRect(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500225 GrPaint&&,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500226 GrAA,
robertphillipsea461502015-05-26 11:38:03 -0700227 const SkMatrix& viewMatrix,
228 const SkRRect& rrect,
bsalomon6663acf2016-05-10 09:14:17 -0700229 const GrStyle& style);
robertphillipsea461502015-05-26 11:38:03 -0700230
231 /**
Jim Van Verth3af1af92017-05-18 15:06:54 -0400232 * Use a fast method to render the ambient and spot shadows for a path.
233 * Will return false if not possible for the given path.
Jim Van Verthc5903412016-11-17 15:27:09 -0500234 *
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500235 * @param viewMatrix transformation matrix
Jim Van Verth3af1af92017-05-18 15:06:54 -0400236 * @param path the path to shadow
237 * @param rec parameters for shadow rendering
Jim Van Verthc5903412016-11-17 15:27:09 -0500238 */
Jim Van Verth3af1af92017-05-18 15:06:54 -0400239 bool drawFastShadow(const GrClip&,
Jim Van Verth3af1af92017-05-18 15:06:54 -0400240 const SkMatrix& viewMatrix,
241 const SkPath& path,
242 const SkDrawShadowRec& rec);
Jim Van Verthc5903412016-11-17 15:27:09 -0500243
244 /**
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500245 * Shortcut for filling a SkPath consisting of nested rrects using a paint. The result is
246 * undefined if outer does not contain inner.
robertphillips00095892016-02-29 13:50:40 -0800247 *
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500248 * @param paint describes how to color pixels.
249 * @param GrAA Controls whether rrects edges are antialiased
250 * @param viewMatrix transformation matrix
251 * @param outer the outer roundrect
252 * @param inner the inner roundrect
robertphillips00095892016-02-29 13:50:40 -0800253 */
254 void drawDRRect(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500255 GrPaint&&,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500256 GrAA,
robertphillips00095892016-02-29 13:50:40 -0800257 const SkMatrix& viewMatrix,
258 const SkRRect& outer,
259 const SkRRect& inner);
260
261 /**
robertphillipsea461502015-05-26 11:38:03 -0700262 * Draws a path.
263 *
264 * @param paint describes how to color pixels.
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500265 * @param GrAA Controls whether the path is antialiased.
robertphillipsea461502015-05-26 11:38:03 -0700266 * @param viewMatrix transformation matrix
267 * @param path the path to draw
bsalomon6663acf2016-05-10 09:14:17 -0700268 * @param style style to apply to the path.
robertphillipsea461502015-05-26 11:38:03 -0700269 */
robertphillips2e1e51f2015-10-15 08:01:48 -0700270 void drawPath(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500271 GrPaint&&,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500272 GrAA,
robertphillipsea461502015-05-26 11:38:03 -0700273 const SkMatrix& viewMatrix,
274 const SkPath&,
Robert Phillips20390c32018-08-17 11:01:03 -0400275 const GrStyle&);
276
277 /**
278 * Draws a shape.
279 *
280 * @param paint describes how to color pixels.
281 * @param GrAA Controls whether the path is antialiased.
282 * @param viewMatrix transformation matrix
283 * @param shape the shape to draw
284 */
285 void drawShape(const GrClip&,
286 GrPaint&&,
287 GrAA,
288 const SkMatrix& viewMatrix,
289 const GrShape&);
290
robertphillipsea461502015-05-26 11:38:03 -0700291
292 /**
293 * Draws vertices with a paint.
294 *
Brian Osmanae0c50c2017-05-25 16:56:34 -0400295 * @param paint describes how to color pixels.
296 * @param viewMatrix transformation matrix
297 * @param vertices specifies the mesh to draw.
Ruiqi Mao4ec72f72018-07-10 17:21:07 -0400298 * @param bones bone deformation matrices.
299 * @param boneCount number of bone matrices.
Brian Osmanae0c50c2017-05-25 16:56:34 -0400300 * @param overridePrimType primitive type to draw. If NULL, derive prim type from vertices.
robertphillipsea461502015-05-26 11:38:03 -0700301 */
robertphillips2e1e51f2015-10-15 08:01:48 -0700302 void drawVertices(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500303 GrPaint&& paint,
robertphillipsea461502015-05-26 11:38:03 -0700304 const SkMatrix& viewMatrix,
Brian Osmanae0c50c2017-05-25 16:56:34 -0400305 sk_sp<SkVertices> vertices,
Ruiqi Maoc97a3392018-08-15 10:44:19 -0400306 const SkVertices::Bone bones[],
Ruiqi Mao4ec72f72018-07-10 17:21:07 -0400307 int boneCount,
Brian Osmanae0c50c2017-05-25 16:56:34 -0400308 GrPrimitiveType* overridePrimType = nullptr);
Brian Salomon199fb872017-02-06 09:41:10 -0500309
310 /**
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500311 * Draws textured sprites from an atlas with a paint. This currently does not support AA for the
312 * sprite rectangle edges.
jvanverth31ff7622015-08-07 10:09:28 -0700313 *
314 * @param paint describes how to color pixels.
315 * @param viewMatrix transformation matrix
316 * @param spriteCount number of sprites.
317 * @param xform array of compressed transformation data, required.
318 * @param texRect array of texture rectangles used to access the paint.
319 * @param colors optional array of per-sprite colors, supercedes
320 * the paint's color field.
321 */
robertphillips2e1e51f2015-10-15 08:01:48 -0700322 void drawAtlas(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500323 GrPaint&& paint,
jvanverth31ff7622015-08-07 10:09:28 -0700324 const SkMatrix& viewMatrix,
325 int spriteCount,
326 const SkRSXform xform[],
327 const SkRect texRect[],
328 const SkColor colors[]);
msarettcc319b92016-08-25 18:07:18 -0700329
330 /**
331 * Draws a region.
332 *
333 * @param paint describes how to color pixels
334 * @param viewMatrix transformation matrix
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500335 * @param aa should the rects of the region be antialiased.
msarettcc319b92016-08-25 18:07:18 -0700336 * @param region the region to be drawn
337 * @param style style to apply to the region
338 */
339 void drawRegion(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500340 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500341 GrAA aa,
msarettcc319b92016-08-25 18:07:18 -0700342 const SkMatrix& viewMatrix,
343 const SkRegion& region,
Stan Iliev73d8fd92017-08-02 15:36:24 -0400344 const GrStyle& style,
345 const GrUserStencilSettings* ss = nullptr);
msarettcc319b92016-08-25 18:07:18 -0700346
jvanverth31ff7622015-08-07 10:09:28 -0700347 /**
robertphillipsea461502015-05-26 11:38:03 -0700348 * Draws an oval.
349 *
350 * @param paint describes how to color pixels.
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500351 * @param GrAA Controls whether the oval is antialiased.
robertphillipsea461502015-05-26 11:38:03 -0700352 * @param viewMatrix transformation matrix
353 * @param oval the bounding rect of the oval.
bsalomon6663acf2016-05-10 09:14:17 -0700354 * @param style style to apply to the oval. Currently path effects are not allowed.
robertphillipsea461502015-05-26 11:38:03 -0700355 */
robertphillips2e1e51f2015-10-15 08:01:48 -0700356 void drawOval(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500357 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500358 GrAA,
robertphillipsea461502015-05-26 11:38:03 -0700359 const SkMatrix& viewMatrix,
360 const SkRect& oval,
bsalomon6663acf2016-05-10 09:14:17 -0700361 const GrStyle& style);
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500362 /**
363 * Draws a partial arc of an oval.
364 *
365 * @param paint describes how to color pixels.
Brian Salomon99504082016-12-09 15:51:31 -0500366 * @param GrGrAA Controls whether the arc is antialiased.
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500367 * @param viewMatrix transformation matrix.
368 * @param oval the bounding rect of the oval.
369 * @param startAngle starting angle in degrees.
370 * @param sweepAngle angle to sweep in degrees. Must be in (-360, 360)
371 * @param useCenter true means that the implied path begins at the oval center, connects as
372 * a line to the point indicated by the start contains the arc indicated by
373 * the sweep angle. If false the line beginning at the center point is
374 * omitted.
375 * @param style style to apply to the oval.
376 */
bsalomon4f3a0ca2016-08-22 13:14:26 -0700377 void drawArc(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500378 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500379 GrAA,
bsalomon4f3a0ca2016-08-22 13:14:26 -0700380 const SkMatrix& viewMatrix,
381 const SkRect& oval,
382 SkScalar startAngle,
383 SkScalar sweepAngle,
384 bool useCenter,
385 const GrStyle& style);
robertphillipsea461502015-05-26 11:38:03 -0700386
joshualitt33a5fce2015-11-18 13:28:51 -0800387 /**
bsalomon4f3a0ca2016-08-22 13:14:26 -0700388 * Draw the image as a set of rects, specified by |iter|.
joshualitt33a5fce2015-11-18 13:28:51 -0800389 */
msarett10e3d9b2016-08-18 15:46:03 -0700390 void drawImageLattice(const GrClip&,
Brian Salomon2a943df2018-05-04 13:43:19 -0400391 GrPaint&&,
msarett10e3d9b2016-08-18 15:46:03 -0700392 const SkMatrix& viewMatrix,
Brian Salomon2a943df2018-05-04 13:43:19 -0400393 sk_sp<GrTextureProxy>,
394 sk_sp<GrColorSpaceXform>,
395 GrSamplerState::Filter,
396 std::unique_ptr<SkLatticeIter>,
msarett10e3d9b2016-08-18 15:46:03 -0700397 const SkRect& dst);
robertphillipsea461502015-05-26 11:38:03 -0700398
robertphillips8c523e02016-07-26 07:41:00 -0700399 /**
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400400 * Adds the necessary signal and wait semaphores and adds the passed in SkDrawable to the
401 * command stream.
402 */
403 void drawDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler>, const SkRect& bounds);
404
405 /**
robertphillips8c523e02016-07-26 07:41:00 -0700406 * After this returns any pending surface IO will be issued to the backend 3D API and
407 * if the surface has MSAA it will be resolved.
408 */
Greg Danielbae71212019-03-01 15:24:35 -0500409 GrSemaphoresSubmitted prepareForExternalIO(SkSurface::BackendSurfaceAccess access,
410 SkSurface::FlushFlags flags, int numSemaphores,
Greg Daniel51316782017-08-02 15:10:09 +0000411 GrBackendSemaphore backendSemaphores[]);
Greg Daniela5cb7812017-06-16 09:45:32 -0400412
413 /**
414 * The next time this GrRenderTargetContext is flushed, the gpu will wait on the passed in
415 * semaphores before executing any commands.
416 */
Robert Phillipsbc4994a2019-02-14 08:36:56 -0500417 bool waitOnSemaphores(int numSemaphores, const GrBackendSemaphore waitSemaphores[]);
robertphillips8c523e02016-07-26 07:41:00 -0700418
Robert Phillips65a88fa2017-08-08 08:36:22 -0400419 void insertEventMarker(const SkString&);
420
Brian Salomon7c8460e2017-05-12 11:36:10 -0400421 GrFSAAType fsaaType() const { return fRenderTargetProxy->fsaaType(); }
Robert Phillipsbe9aff22019-02-15 11:33:22 -0500422 const GrCaps* caps() const;
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400423 int width() const { return fRenderTargetProxy->width(); }
424 int height() const { return fRenderTargetProxy->height(); }
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400425 int numColorSamples() const { return fRenderTargetProxy->numColorSamples(); }
Brian Salomon50e66d42017-05-15 16:28:07 -0400426 int numStencilSamples() const { return fRenderTargetProxy->numStencilSamples(); }
robertphillipsca6eafc2016-05-17 09:57:46 -0700427 const SkSurfaceProps& surfaceProps() const { return fSurfaceProps; }
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400428 GrSurfaceOrigin origin() const { return fRenderTargetProxy->origin(); }
Greg Danielb46add82019-01-02 14:51:29 -0500429 bool wrapsVkSecondaryCB() const { return fRenderTargetProxy->wrapsVkSecondaryCB(); }
Greg Daniele252f082017-10-23 16:05:23 -0400430 GrMipMapped mipMapped() const;
robertphillips7bceedc2015-12-01 12:51:26 -0800431
Robert Phillips65048132017-08-10 08:44:49 -0400432 void setNeedsStencil() { fRenderTargetProxy->setNeedsStencil(); }
433
Robert Phillipsbe9aff22019-02-15 11:33:22 -0500434 // This entry point should only be called if the backing GPU object is known to be
435 // instantiated.
436 GrRenderTarget* accessRenderTarget() { return fRenderTargetProxy->peekRenderTarget(); }
robertphillips6c7e3252016-04-27 10:47:51 -0700437
Robert Phillipsf200a902017-01-30 13:27:37 -0500438 GrSurfaceProxy* asSurfaceProxy() override { return fRenderTargetProxy.get(); }
439 const GrSurfaceProxy* asSurfaceProxy() const override { return fRenderTargetProxy.get(); }
440 sk_sp<GrSurfaceProxy> asSurfaceProxyRef() override { return fRenderTargetProxy; }
441
442 GrTextureProxy* asTextureProxy() override;
Greg Daniele252f082017-10-23 16:05:23 -0400443 const GrTextureProxy* asTextureProxy() const override;
Robert Phillipsf200a902017-01-30 13:27:37 -0500444 sk_sp<GrTextureProxy> asTextureProxyRef() override;
445
446 GrRenderTargetProxy* asRenderTargetProxy() override { return fRenderTargetProxy.get(); }
447 sk_sp<GrRenderTargetProxy> asRenderTargetProxyRef() override { return fRenderTargetProxy; }
Robert Phillipseaa86252016-11-08 13:49:39 +0000448
Robert Phillipsd46697a2017-01-25 12:10:37 -0500449 GrRenderTargetContext* asRenderTargetContext() override { return this; }
450
robertphillips391395d2016-03-02 09:26:36 -0800451 // Provides access to functions that aren't part of the public API.
Brian Osman693a5402016-10-27 15:13:22 -0400452 GrRenderTargetContextPriv priv();
453 const GrRenderTargetContextPriv priv() const;
joshualittf5883a62016-01-13 07:47:38 -0800454
Herb Derbyc1b482c2018-08-09 15:02:27 -0400455 GrTextTarget* textTarget() { return fTextTarget.get(); }
Brian Salomonf18b1d82017-10-27 11:30:49 -0400456
Robert Phillipseaa86252016-11-08 13:49:39 +0000457 bool isWrapped_ForTesting() const;
458
joshualitt96880d92016-02-16 10:36:53 -0800459protected:
Robert Phillips0d075de2019-03-04 11:08:13 -0500460 GrRenderTargetContext(GrRecordingContext*, sk_sp<GrRenderTargetProxy>,
461 sk_sp<SkColorSpace>, const SkSurfaceProps*,
462 bool managedOpList = true);
joshualitt96880d92016-02-16 10:36:53 -0800463
Robert Phillips2de8cfa2017-06-28 10:33:41 -0400464 SkDEBUGCODE(void validate() const override;)
joshualitt96880d92016-02-16 10:36:53 -0800465
robertphillipsea461502015-05-26 11:38:03 -0700466private:
Brian Salomonf18b1d82017-10-27 11:30:49 -0400467 class TextTarget;
468
Chris Dalton7d6748e2019-03-13 00:34:52 -0600469 GrAAType chooseAAType(GrAA);
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500470
Brian Salomon649a3412017-03-09 13:50:43 -0500471 friend class GrAtlasTextBlob; // for access to add[Mesh]DrawOp
Brian Osman5d034742017-09-11 13:38:55 -0400472 friend class GrClipStackClip; // for access to getOpList
robertphillips55fdccc2016-06-06 06:16:20 -0700473
robertphillips77a2e522015-10-17 07:43:27 -0700474 friend class GrDrawingManager; // for ctor
Brian Osman11052242016-10-27 14:47:55 -0400475 friend class GrRenderTargetContextPriv;
robertphillips976f5f02016-06-03 10:59:20 -0700476
Brian Salomon42521e82016-12-07 16:44:58 -0500477 // All the path renderers currently make their own ops
Brian Salomon649a3412017-03-09 13:50:43 -0500478 friend class GrSoftwarePathRenderer; // for access to add[Mesh]DrawOp
479 friend class GrAAConvexPathRenderer; // for access to add[Mesh]DrawOp
480 friend class GrDashLinePathRenderer; // for access to add[Mesh]DrawOp
481 friend class GrAAHairLinePathRenderer; // for access to add[Mesh]DrawOp
482 friend class GrAALinearizingConvexPathRenderer; // for access to add[Mesh]DrawOp
Jim Van Verth83010462017-03-16 08:45:39 -0400483 friend class GrSmallPathRenderer; // for access to add[Mesh]DrawOp
Brian Salomon649a3412017-03-09 13:50:43 -0500484 friend class GrDefaultPathRenderer; // for access to add[Mesh]DrawOp
Brian Salomon649a3412017-03-09 13:50:43 -0500485 friend class GrStencilAndCoverPathRenderer; // for access to add[Mesh]DrawOp
486 friend class GrTessellatingPathRenderer; // for access to add[Mesh]DrawOp
Chris Dalton9414c962018-06-14 10:14:50 -0600487 friend class GrCCPerFlushResources; // for access to addDrawOp
Chris Dalton1a325d22017-07-14 15:17:41 -0600488 friend class GrCoverageCountingPathRenderer; // for access to addDrawOp
Brian Salomon5d4cd9e2017-02-09 11:16:46 -0500489 // for a unit test
Robert Phillips7c525e62018-06-12 10:11:12 -0400490 friend void test_draw_op(GrContext*,
491 GrRenderTargetContext*,
492 std::unique_ptr<GrFragmentProcessor>,
Brian Salomonaff329b2017-08-11 09:40:37 -0400493 sk_sp<GrTextureProxy>);
robertphillipsea461502015-05-26 11:38:03 -0700494
Brian Osman9a9baae2018-11-05 15:06:26 -0500495 void internalClear(const GrFixedClip&, const SkPMColor4f&, CanClearFullscreen);
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500496 void internalStencilClear(const GrFixedClip&, bool insideStencilMask);
csmartdalton29df7602016-08-31 11:55:52 -0700497
Brian Salomon82f44312017-01-11 13:42:54 -0500498 // Only consumes the GrPaint if successful.
robertphillips00095892016-02-29 13:50:40 -0800499 bool drawFilledDRRect(const GrClip& clip,
Brian Salomon82f44312017-01-11 13:42:54 -0500500 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500501 GrAA,
robertphillips00095892016-02-29 13:50:40 -0800502 const SkMatrix& viewMatrix,
503 const SkRRect& origOuter,
504 const SkRRect& origInner);
505
Michael Ludwig61a16512019-01-15 11:15:13 -0500506 void drawFilledRect(const GrClip& clip,
Brian Salomon82f44312017-01-11 13:42:54 -0500507 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500508 GrAA,
robertphillips44302392016-07-08 14:43:03 -0700509 const SkMatrix& viewMatrix,
510 const SkRect& rect,
Michael Ludwig61a16512019-01-15 11:15:13 -0500511 const GrUserStencilSettings* ss = nullptr);
512
513 // Only consumes the GrPaint if successful.
514 bool drawFilledRectAsClear(const GrClip& clip,
515 GrPaint&& paint,
516 GrAA aa,
517 const SkMatrix& viewMatrix,
518 const SkRect& rect);
robertphillips44302392016-07-08 14:43:03 -0700519
Brian Salomon2fad74a2017-12-20 13:28:55 -0500520 void drawShapeUsingPathRenderer(const GrClip&, GrPaint&&, GrAA, const SkMatrix&,
521 const GrShape&);
robertphillipsea461502015-05-26 11:38:03 -0700522
Brian Salomon348a0372018-10-31 10:42:18 -0400523 // Allows caller of addDrawOp to know which op list an op will be added to.
524 using WillAddOpFn = void(GrOp*, uint32_t opListID);
525 // These perform processing specific to GrDrawOp-derived ops before recording them into an
526 // op list. Before adding the op to an op list the WillAddOpFn is called. Note that it
527 // will not be called in the event that the op is discarded. Moreover, the op may merge into
528 // another op after the function is called (either before addDrawOp returns or some time later).
529 void addDrawOp(const GrClip&, std::unique_ptr<GrDrawOp>,
530 const std::function<WillAddOpFn>& = std::function<WillAddOpFn>());
robertphillips2334fb62015-06-17 05:43:33 -0700531
Robert Phillipsbf25d432017-04-07 10:08:53 -0400532 // Makes a copy of the proxy if it is necessary for the draw and places the texture that should
533 // be used by GrXferProcessor to access the destination color in 'result'. If the return
534 // value is false then a texture copy could not be made.
Robert Phillipsbb581ce2017-05-29 15:05:15 -0400535 bool SK_WARN_UNUSED_RESULT setupDstProxy(GrRenderTargetProxy*,
536 const GrClip&,
Brian Salomon09181ef2018-11-14 13:39:51 -0500537 const GrOp& op,
Robert Phillipsbb581ce2017-05-29 15:05:15 -0400538 GrXferProcessor::DstProxy* result);
Brian Salomon467921e2017-03-06 16:17:12 -0500539
Robert Phillips2de8cfa2017-06-28 10:33:41 -0400540 GrRenderTargetOpList* getRTOpList();
541 GrOpList* getOpList() override;
robertphillipsa106c622015-10-16 09:07:06 -0700542
Herb Derbyc1b482c2018-08-09 15:02:27 -0400543 std::unique_ptr<GrTextTarget> fTextTarget;
Brian Salomonf18b1d82017-10-27 11:30:49 -0400544 sk_sp<GrRenderTargetProxy> fRenderTargetProxy;
robertphillipsa106c622015-10-16 09:07:06 -0700545
Brian Osman11052242016-10-27 14:47:55 -0400546 // In MDB-mode the GrOpList can be closed by some other renderTargetContext that has picked
Robert Phillipsf2361d22016-10-25 14:20:06 -0400547 // it up. For this reason, the GrOpList should only ever be accessed via 'getOpList'.
Brian Salomonf18b1d82017-10-27 11:30:49 -0400548 sk_sp<GrRenderTargetOpList> fOpList;
robertphillips2334fb62015-06-17 05:43:33 -0700549
Brian Salomonf18b1d82017-10-27 11:30:49 -0400550 SkSurfaceProps fSurfaceProps;
551 bool fManagedOpList;
Robert Phillipse305cc1f2016-12-14 12:19:05 -0500552
553 typedef GrSurfaceContext INHERITED;
robertphillipsea461502015-05-26 11:38:03 -0700554};
555
556#endif