blob: 2746fc5876ecfa5f34c8aca9cde3812b8b1a8d6a [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"
17#include "src/gpu/GrPaint.h"
Chris Dalton6b982802019-06-27 13:53:46 -060018#include "src/gpu/GrRenderTargetOpList.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"
21#include "src/gpu/GrXferProcessor.h"
Michael Ludwig61328202019-06-19 14:48:58 +000022#include "src/gpu/geometry/GrQuad.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050023#include "src/gpu/text/GrTextTarget.h"
robertphillipsea461502015-05-26 11:38:03 -070024
Greg Daniela5cb7812017-06-16 09:45:32 -040025class GrBackendSemaphore;
robertphillipsea461502015-05-26 11:38:03 -070026class GrClip;
Brian Osman2240be92017-10-18 13:15:13 -040027class GrColorSpaceXform;
Chris Dalton1a325d22017-07-14 15:17:41 -060028class GrCoverageCountingPathRenderer;
robertphillips77a2e522015-10-17 07:43:27 -070029class GrDrawingManager;
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;
robertphillips2334fb62015-06-17 05:43:33 -070052class SkTextBlob;
Brian Salomon199fb872017-02-06 09:41:10 -050053class SkVertices;
robertphillipsea461502015-05-26 11:38:03 -070054
Brian Osman45580d32016-11-23 09:37:01 -050055/**
56 * A helper object to orchestrate commands (draws, etc...) for GrSurfaces that are GrRenderTargets.
robertphillipsea461502015-05-26 11:38:03 -070057 */
Brian Osman45580d32016-11-23 09:37:01 -050058class SK_API GrRenderTargetContext : public GrSurfaceContext {
robertphillipsea461502015-05-26 11:38:03 -070059public:
Brian Osman11052242016-10-27 14:47:55 -040060 ~GrRenderTargetContext() override;
robertphillips2334fb62015-06-17 05:43:33 -070061
Robert Phillipse4643cc2018-08-14 13:01:29 -040062 virtual void drawGlyphRunList(const GrClip&, const SkMatrix& viewMatrix, const SkGlyphRunList&);
robertphillipsea461502015-05-26 11:38:03 -070063
robertphillipsea461502015-05-26 11:38:03 -070064 /**
65 * Provides a perfomance hint that the render target's contents are allowed
66 * to become undefined.
67 */
robertphillips2e1e51f2015-10-15 08:01:48 -070068 void discard();
robertphillipsea461502015-05-26 11:38:03 -070069
Chris Dalton344e9032017-12-11 15:42:09 -070070 enum class CanClearFullscreen : bool {
71 kNo = false,
72 kYes = true
73 };
74
robertphillipsea461502015-05-26 11:38:03 -070075 /**
76 * Clear the entire or rect of the render target, ignoring any clips.
robertphillipsea461502015-05-26 11:38:03 -070077 * @param rect the rect to clear or the whole thing if rect is NULL.
78 * @param color the color to clear to.
Chris Dalton344e9032017-12-11 15:42:09 -070079 * @param CanClearFullscreen allows partial clears to be converted to fullscreen clears on
80 * tiling platforms where that is an optimization.
robertphillipsea461502015-05-26 11:38:03 -070081 */
Brian Osman9a9baae2018-11-05 15:06:26 -050082 void clear(const SkIRect* rect, const SkPMColor4f& color, CanClearFullscreen);
robertphillipsea461502015-05-26 11:38:03 -070083
84 /**
85 * Draw everywhere (respecting the clip) with the paint.
86 */
Brian Salomon82f44312017-01-11 13:42:54 -050087 void drawPaint(const GrClip&, GrPaint&&, const SkMatrix& viewMatrix);
robertphillipsea461502015-05-26 11:38:03 -070088
89 /**
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050090 * Draw the rect using a paint.
91 * @param paint describes how to color pixels.
92 * @param GrAA Controls whether rect is antialiased
93 * @param viewMatrix transformation matrix
94 * @param style The style to apply. Null means fill. Currently path effects are not
95 * allowed.
96 * The rects coords are used to access the paint (through texture matrix)
robertphillipsea461502015-05-26 11:38:03 -070097 */
robertphillips2e1e51f2015-10-15 08:01:48 -070098 void drawRect(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -050099 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500100 GrAA,
robertphillipsea461502015-05-26 11:38:03 -0700101 const SkMatrix& viewMatrix,
102 const SkRect&,
Brian Salomon82f44312017-01-11 13:42:54 -0500103 const GrStyle* style = nullptr);
robertphillipsea461502015-05-26 11:38:03 -0700104
105 /**
bsalomona2e69fc2015-11-05 10:41:43 -0800106 * Maps a rectangle of shader coordinates to a rectangle and fills that rectangle.
robertphillipsea461502015-05-26 11:38:03 -0700107 *
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500108 * @param paint describes how to color pixels.
109 * @param GrAA Controls whether rect is antialiased
110 * @param viewMatrix transformation matrix which applies to rectToDraw
111 * @param rectToDraw the rectangle to draw
112 * @param localRect the rectangle of shader coordinates applied to rectToDraw
robertphillipsea461502015-05-26 11:38:03 -0700113 */
Michael Ludwig136f45a2019-02-19 11:44:41 -0500114 void fillRectToRect(const GrClip& clip,
Brian Salomon82f44312017-01-11 13:42:54 -0500115 GrPaint&& paint,
Michael Ludwig136f45a2019-02-19 11:44:41 -0500116 GrAA aa,
bsalomona2e69fc2015-11-05 10:41:43 -0800117 const SkMatrix& viewMatrix,
118 const SkRect& rectToDraw,
Michael Ludwig136f45a2019-02-19 11:44:41 -0500119 const SkRect& localRect) {
Michael Ludwig61328202019-06-19 14:48:58 +0000120 this->drawFilledQuad(clip, std::move(paint), aa,
121 aa == GrAA::kYes ? GrQuadAAFlags::kAll : GrQuadAAFlags::kNone,
122 GrQuad::MakeFromRect(rectToDraw, viewMatrix), GrQuad(localRect));
Michael Ludwig136f45a2019-02-19 11:44:41 -0500123 }
robertphillipsea461502015-05-26 11:38:03 -0700124
125 /**
bsalomona2e69fc2015-11-05 10:41:43 -0800126 * Fills a rect with a paint and a localMatrix.
robertphillipsea461502015-05-26 11:38:03 -0700127 */
bsalomona2e69fc2015-11-05 10:41:43 -0800128 void fillRectWithLocalMatrix(const GrClip& clip,
Brian Salomon82f44312017-01-11 13:42:54 -0500129 GrPaint&& paint,
Michael Ludwig61328202019-06-19 14:48:58 +0000130 GrAA aa,
bsalomona2e69fc2015-11-05 10:41:43 -0800131 const SkMatrix& viewMatrix,
132 const SkRect& rect,
Michael Ludwig61328202019-06-19 14:48:58 +0000133 const SkMatrix& localMatrix) {
134 this->drawFilledQuad(clip, std::move(paint), aa,
135 aa == GrAA::kYes ? GrQuadAAFlags::kAll : GrQuadAAFlags::kNone,
136 GrQuad::MakeFromRect(rect, viewMatrix),
137 GrQuad::MakeFromRect(rect, localMatrix));
138 }
robertphillipsea461502015-05-26 11:38:03 -0700139
Michael Ludwig75451902019-01-23 11:14:29 -0500140 /**
141 * Creates an op that draws a fill rect with per-edge control over anti-aliasing.
Michael Ludwigce62dec2019-02-19 11:48:46 -0500142 *
143 * This is a specialized version of fillQuadWithEdgeAA, but is kept separate since knowing
144 * the geometry is a rectangle affords more optimizations.
Michael Ludwig75451902019-01-23 11:14:29 -0500145 */
Michael Ludwig136f45a2019-02-19 11:44:41 -0500146 void fillRectWithEdgeAA(const GrClip& clip, GrPaint&& paint, GrAA aa, GrQuadAAFlags edgeAA,
147 const SkMatrix& viewMatrix, const SkRect& rect,
Michael Ludwig61328202019-06-19 14:48:58 +0000148 const SkRect* optionalLocalRect = nullptr) {
149 const SkRect& localRect = optionalLocalRect ? *optionalLocalRect : rect;
150 this->drawFilledQuad(clip, std::move(paint), aa, edgeAA,
151 GrQuad::MakeFromRect(rect, viewMatrix), GrQuad(localRect));
152 }
Michael Ludwig75451902019-01-23 11:14:29 -0500153
Michael Ludwigce62dec2019-02-19 11:48:46 -0500154 /**
155 * Similar to fillRectWithEdgeAA but draws an arbitrary 2D convex quadrilateral transformed
156 * by 'viewMatrix', with per-edge control over anti-aliasing. The quad should follow the
157 * ordering used by SkRect::toQuad(), which determines how the edge AA is applied:
158 * - "top" = points [0] and [1]
159 * - "right" = points[1] and [2]
160 * - "bottom" = points[2] and [3]
161 * - "left" = points[3] and [0]
162 *
163 * The last argument, 'optionalLocalQuad', can be null if no separate local coordinates are
164 * necessary.
165 */
166 void fillQuadWithEdgeAA(const GrClip& clip, GrPaint&& paint, GrAA aa, GrQuadAAFlags edgeAA,
167 const SkMatrix& viewMatrix, const SkPoint quad[4],
Michael Ludwig61328202019-06-19 14:48:58 +0000168 const SkPoint optionalLocalQuad[4]) {
169 const SkPoint* localQuad = optionalLocalQuad ? optionalLocalQuad : quad;
170 this->drawFilledQuad(clip, std::move(paint), aa, edgeAA,
171 GrQuad::MakeFromSkQuad(quad, viewMatrix),
172 GrQuad::MakeFromSkQuad(localQuad, SkMatrix::I()));
173 }
Michael Ludwigce62dec2019-02-19 11:48:46 -0500174
Michael Ludwig69858532018-11-28 15:34:34 -0500175 /** Used with drawQuadSet */
176 struct QuadSetEntry {
177 SkRect fRect;
178 SkPMColor4f fColor; // Overrides any color on the GrPaint
179 SkMatrix fLocalMatrix;
180 GrQuadAAFlags fAAFlags;
181 };
182
Michael Ludwig75451902019-01-23 11:14:29 -0500183 // TODO(michaelludwig) - remove if the bulk API is not useful for SkiaRenderer
Michael Ludwig69858532018-11-28 15:34:34 -0500184 void drawQuadSet(const GrClip& clip, GrPaint&& paint, GrAA aa, const SkMatrix& viewMatrix,
185 const QuadSetEntry[], int cnt);
186
robertphillipsea461502015-05-26 11:38:03 -0700187 /**
Brian Salomon34169692017-08-28 15:32:01 -0400188 * Creates an op that draws a subrectangle of a texture. The passed color is modulated by the
189 * texture's color. 'srcRect' specifies the rectangle of the texture to draw. 'dstRect'
190 * specifies the rectangle to draw in local coords which will be transformed by 'viewMatrix' to
Brian Salomonbe3c1d22018-05-21 12:54:39 -0400191 * device space.
Brian Salomon34169692017-08-28 15:32:01 -0400192 */
Brian Osman3d139a42018-11-19 10:42:10 -0500193 void drawTexture(const GrClip& clip, sk_sp<GrTextureProxy>, GrSamplerState::Filter,
Michael Ludwigd54ca8f2019-02-13 13:25:21 -0500194 SkBlendMode mode, const SkPMColor4f&, const SkRect& srcRect,
Michael Ludwig136f45a2019-02-19 11:44:41 -0500195 const SkRect& dstRect, GrAA, GrQuadAAFlags, SkCanvas::SrcRectConstraint,
Michael Ludwigd54ca8f2019-02-13 13:25:21 -0500196 const SkMatrix& viewMatrix, sk_sp<GrColorSpaceXform> texXform);
Brian Salomon34169692017-08-28 15:32:01 -0400197
Michael Ludwigce62dec2019-02-19 11:48:46 -0500198 /**
199 * Variant of drawTexture that instead draws the texture applied to 'dstQuad' transformed by
200 * 'viewMatrix', using the 'srcQuad' texture coordinates clamped to the optional 'domain'. If
201 * 'domain' is null, it's equivalent to using the fast src rect constraint. If 'domain' is
202 * provided, the strict src rect constraint is applied using 'domain'.
203 */
204 void drawTextureQuad(const GrClip& clip, sk_sp<GrTextureProxy>, GrSamplerState::Filter,
205 SkBlendMode mode, const SkPMColor4f&, const SkPoint srcQuad[4],
206 const SkPoint dstQuad[4], GrAA, GrQuadAAFlags, const SkRect* domain,
207 const SkMatrix& viewMatrix, sk_sp<GrColorSpaceXform> texXform);
208
Brian Salomond7065e72018-10-12 11:42:02 -0400209 /** Used with drawTextureSet */
210 struct TextureSetEntry {
211 sk_sp<GrTextureProxy> fProxy;
212 SkRect fSrcRect;
213 SkRect fDstRect;
Michael Ludwig1433cfd2019-02-27 17:12:30 -0500214 const SkPoint* fDstClipQuad; // Must be null, or point to an array of 4 points
Michael Ludwig7ae2ab52019-03-05 16:00:20 -0500215 const SkMatrix* fPreViewMatrix; // If not null, entry's CTM is 'viewMatrix' * fPreViewMatrix
Brian Salomon1da5cad2018-11-21 09:21:18 -0500216 float fAlpha;
Brian Salomond7065e72018-10-12 11:42:02 -0400217 GrQuadAAFlags fAAFlags;
218 };
219 /**
220 * Draws a set of textures with a shared filter, color, view matrix, color xform, and
221 * texture color xform. The textures must all have the same GrTextureType and GrConfig.
Michael Ludwigce62dec2019-02-19 11:48:46 -0500222 *
223 * If any entries provide a non-null fDstClip array, it will be read from immediately based on
224 * fDstClipCount, so the pointer can become invalid after this returns.
Brian Salomond7065e72018-10-12 11:42:02 -0400225 */
226 void drawTextureSet(const GrClip&, const TextureSetEntry[], int cnt, GrSamplerState::Filter,
Michael Ludwig31ba7182019-04-03 10:38:06 -0400227 SkBlendMode mode, GrAA aa, SkCanvas::SrcRectConstraint,
228 const SkMatrix& viewMatrix, sk_sp<GrColorSpaceXform> texXform);
Brian Salomond7065e72018-10-12 11:42:02 -0400229
Brian Salomon34169692017-08-28 15:32:01 -0400230 /**
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500231 * Draw a roundrect using a paint.
robertphillipsea461502015-05-26 11:38:03 -0700232 *
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500233 * @param paint describes how to color pixels.
234 * @param GrAA Controls whether rrect is antialiased.
235 * @param viewMatrix transformation matrix
236 * @param rrect the roundrect to draw
237 * @param style style to apply to the rrect. Currently path effects are not allowed.
robertphillipsea461502015-05-26 11:38:03 -0700238 */
robertphillips2e1e51f2015-10-15 08:01:48 -0700239 void drawRRect(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500240 GrPaint&&,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500241 GrAA,
robertphillipsea461502015-05-26 11:38:03 -0700242 const SkMatrix& viewMatrix,
243 const SkRRect& rrect,
bsalomon6663acf2016-05-10 09:14:17 -0700244 const GrStyle& style);
robertphillipsea461502015-05-26 11:38:03 -0700245
246 /**
Jim Van Verth3af1af92017-05-18 15:06:54 -0400247 * Use a fast method to render the ambient and spot shadows for a path.
248 * Will return false if not possible for the given path.
Jim Van Verthc5903412016-11-17 15:27:09 -0500249 *
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500250 * @param viewMatrix transformation matrix
Jim Van Verth3af1af92017-05-18 15:06:54 -0400251 * @param path the path to shadow
252 * @param rec parameters for shadow rendering
Jim Van Verthc5903412016-11-17 15:27:09 -0500253 */
Jim Van Verth3af1af92017-05-18 15:06:54 -0400254 bool drawFastShadow(const GrClip&,
Jim Van Verth3af1af92017-05-18 15:06:54 -0400255 const SkMatrix& viewMatrix,
256 const SkPath& path,
257 const SkDrawShadowRec& rec);
Jim Van Verthc5903412016-11-17 15:27:09 -0500258
259 /**
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500260 * Shortcut for filling a SkPath consisting of nested rrects using a paint. The result is
261 * undefined if outer does not contain inner.
robertphillips00095892016-02-29 13:50:40 -0800262 *
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500263 * @param paint describes how to color pixels.
264 * @param GrAA Controls whether rrects edges are antialiased
265 * @param viewMatrix transformation matrix
266 * @param outer the outer roundrect
267 * @param inner the inner roundrect
robertphillips00095892016-02-29 13:50:40 -0800268 */
269 void drawDRRect(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500270 GrPaint&&,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500271 GrAA,
robertphillips00095892016-02-29 13:50:40 -0800272 const SkMatrix& viewMatrix,
273 const SkRRect& outer,
274 const SkRRect& inner);
275
276 /**
robertphillipsea461502015-05-26 11:38:03 -0700277 * Draws a path.
278 *
279 * @param paint describes how to color pixels.
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500280 * @param GrAA Controls whether the path is antialiased.
robertphillipsea461502015-05-26 11:38:03 -0700281 * @param viewMatrix transformation matrix
282 * @param path the path to draw
bsalomon6663acf2016-05-10 09:14:17 -0700283 * @param style style to apply to the path.
robertphillipsea461502015-05-26 11:38:03 -0700284 */
robertphillips2e1e51f2015-10-15 08:01:48 -0700285 void drawPath(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500286 GrPaint&&,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500287 GrAA,
robertphillipsea461502015-05-26 11:38:03 -0700288 const SkMatrix& viewMatrix,
289 const SkPath&,
Robert Phillips20390c32018-08-17 11:01:03 -0400290 const GrStyle&);
291
292 /**
293 * Draws a shape.
294 *
295 * @param paint describes how to color pixels.
296 * @param GrAA Controls whether the path is antialiased.
297 * @param viewMatrix transformation matrix
298 * @param shape the shape to draw
299 */
300 void drawShape(const GrClip&,
301 GrPaint&&,
302 GrAA,
303 const SkMatrix& viewMatrix,
304 const GrShape&);
305
robertphillipsea461502015-05-26 11:38:03 -0700306
307 /**
308 * Draws vertices with a paint.
309 *
Brian Osmanae0c50c2017-05-25 16:56:34 -0400310 * @param paint describes how to color pixels.
311 * @param viewMatrix transformation matrix
312 * @param vertices specifies the mesh to draw.
Ruiqi Mao4ec72f72018-07-10 17:21:07 -0400313 * @param bones bone deformation matrices.
314 * @param boneCount number of bone matrices.
Brian Osmanae0c50c2017-05-25 16:56:34 -0400315 * @param overridePrimType primitive type to draw. If NULL, derive prim type from vertices.
robertphillipsea461502015-05-26 11:38:03 -0700316 */
robertphillips2e1e51f2015-10-15 08:01:48 -0700317 void drawVertices(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500318 GrPaint&& paint,
robertphillipsea461502015-05-26 11:38:03 -0700319 const SkMatrix& viewMatrix,
Brian Osmanae0c50c2017-05-25 16:56:34 -0400320 sk_sp<SkVertices> vertices,
Ruiqi Maoc97a3392018-08-15 10:44:19 -0400321 const SkVertices::Bone bones[],
Ruiqi Mao4ec72f72018-07-10 17:21:07 -0400322 int boneCount,
Brian Osmanae0c50c2017-05-25 16:56:34 -0400323 GrPrimitiveType* overridePrimType = nullptr);
Brian Salomon199fb872017-02-06 09:41:10 -0500324
325 /**
Brian Osman4d92b892019-03-24 00:53:23 +0000326 * Draws textured sprites from an atlas with a paint. This currently does not support AA for the
327 * sprite rectangle edges.
328 *
329 * @param paint describes how to color pixels.
330 * @param viewMatrix transformation matrix
331 * @param spriteCount number of sprites.
332 * @param xform array of compressed transformation data, required.
333 * @param texRect array of texture rectangles used to access the paint.
334 * @param colors optional array of per-sprite colors, supercedes
335 * the paint's color field.
336 */
337 void drawAtlas(const GrClip&,
338 GrPaint&& paint,
339 const SkMatrix& viewMatrix,
340 int spriteCount,
341 const SkRSXform xform[],
342 const SkRect texRect[],
343 const SkColor colors[]);
344
345 /**
msarettcc319b92016-08-25 18:07:18 -0700346 * Draws a region.
347 *
348 * @param paint describes how to color pixels
349 * @param viewMatrix transformation matrix
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500350 * @param aa should the rects of the region be antialiased.
msarettcc319b92016-08-25 18:07:18 -0700351 * @param region the region to be drawn
352 * @param style style to apply to the region
353 */
354 void drawRegion(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500355 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500356 GrAA aa,
msarettcc319b92016-08-25 18:07:18 -0700357 const SkMatrix& viewMatrix,
358 const SkRegion& region,
Stan Iliev73d8fd92017-08-02 15:36:24 -0400359 const GrStyle& style,
360 const GrUserStencilSettings* ss = nullptr);
msarettcc319b92016-08-25 18:07:18 -0700361
jvanverth31ff7622015-08-07 10:09:28 -0700362 /**
robertphillipsea461502015-05-26 11:38:03 -0700363 * Draws an oval.
364 *
365 * @param paint describes how to color pixels.
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500366 * @param GrAA Controls whether the oval is antialiased.
robertphillipsea461502015-05-26 11:38:03 -0700367 * @param viewMatrix transformation matrix
368 * @param oval the bounding rect of the oval.
bsalomon6663acf2016-05-10 09:14:17 -0700369 * @param style style to apply to the oval. Currently path effects are not allowed.
robertphillipsea461502015-05-26 11:38:03 -0700370 */
robertphillips2e1e51f2015-10-15 08:01:48 -0700371 void drawOval(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500372 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500373 GrAA,
robertphillipsea461502015-05-26 11:38:03 -0700374 const SkMatrix& viewMatrix,
375 const SkRect& oval,
bsalomon6663acf2016-05-10 09:14:17 -0700376 const GrStyle& style);
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500377 /**
378 * Draws a partial arc of an oval.
379 *
380 * @param paint describes how to color pixels.
Brian Salomon99504082016-12-09 15:51:31 -0500381 * @param GrGrAA Controls whether the arc is antialiased.
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500382 * @param viewMatrix transformation matrix.
383 * @param oval the bounding rect of the oval.
384 * @param startAngle starting angle in degrees.
385 * @param sweepAngle angle to sweep in degrees. Must be in (-360, 360)
386 * @param useCenter true means that the implied path begins at the oval center, connects as
387 * a line to the point indicated by the start contains the arc indicated by
388 * the sweep angle. If false the line beginning at the center point is
389 * omitted.
390 * @param style style to apply to the oval.
391 */
bsalomon4f3a0ca2016-08-22 13:14:26 -0700392 void drawArc(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500393 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500394 GrAA,
bsalomon4f3a0ca2016-08-22 13:14:26 -0700395 const SkMatrix& viewMatrix,
396 const SkRect& oval,
397 SkScalar startAngle,
398 SkScalar sweepAngle,
399 bool useCenter,
400 const GrStyle& style);
robertphillipsea461502015-05-26 11:38:03 -0700401
joshualitt33a5fce2015-11-18 13:28:51 -0800402 /**
bsalomon4f3a0ca2016-08-22 13:14:26 -0700403 * Draw the image as a set of rects, specified by |iter|.
joshualitt33a5fce2015-11-18 13:28:51 -0800404 */
msarett10e3d9b2016-08-18 15:46:03 -0700405 void drawImageLattice(const GrClip&,
Brian Salomon2a943df2018-05-04 13:43:19 -0400406 GrPaint&&,
msarett10e3d9b2016-08-18 15:46:03 -0700407 const SkMatrix& viewMatrix,
Brian Salomon2a943df2018-05-04 13:43:19 -0400408 sk_sp<GrTextureProxy>,
409 sk_sp<GrColorSpaceXform>,
410 GrSamplerState::Filter,
411 std::unique_ptr<SkLatticeIter>,
msarett10e3d9b2016-08-18 15:46:03 -0700412 const SkRect& dst);
robertphillipsea461502015-05-26 11:38:03 -0700413
robertphillips8c523e02016-07-26 07:41:00 -0700414 /**
Greg Daniel46cfbc62019-06-07 11:43:30 -0400415 * Draws the src texture with no matrix. The dstRect is the dstPoint with the width and height
416 * of the srcRect. The srcRect and dstRect are clipped to the bounds of the src and dst surfaces
417 * respectively.
418 */
419 bool blitTexture(GrTextureProxy* src, const SkIRect& srcRect, const SkIPoint& dstPoint);
420
421 /**
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400422 * Adds the necessary signal and wait semaphores and adds the passed in SkDrawable to the
423 * command stream.
424 */
425 void drawDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler>, const SkRect& bounds);
426
Brian Salomonab32f652019-05-10 14:24:50 -0400427 using ReadPixelsCallback = SkSurface::ReadPixelsCallback;
Brian Salomon024bd002019-06-11 11:38:16 -0400428 using ReadPixelsCallbackYUV420 = SkSurface::ReadPixelsCallbackYUV420;
Brian Salomonab32f652019-05-10 14:24:50 -0400429 using ReadPixelsContext = SkSurface::ReadPixelsContext;
Brian Salomon024bd002019-06-11 11:38:16 -0400430 using RescaleGamma = SkSurface::RescaleGamma;
431
432 // GPU implementation for SkSurface::asyncRescaleAndReadPixels.
Brian Salomon031b0ba2019-05-23 11:05:26 -0400433 void asyncRescaleAndReadPixels(const SkImageInfo& info, const SkIRect& srcRect,
Brian Salomon024bd002019-06-11 11:38:16 -0400434 RescaleGamma rescaleGamma, SkFilterQuality rescaleQuality,
435 ReadPixelsCallback callback, ReadPixelsContext context);
436 // GPU implementation for SkSurface::asyncRescaleAndReadPixelsYUV420.
437 void asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace,
438 sk_sp<SkColorSpace> dstColorSpace, const SkIRect& srcRect,
439 int dstW, int dstH, RescaleGamma rescaleGamma,
440 SkFilterQuality rescaleQuality,
441 ReadPixelsCallbackYUV420 callback,
442 ReadPixelsContext context);
Brian Salomonab32f652019-05-10 14:24:50 -0400443
Greg Daniel64cc9aa2018-10-19 13:54:56 -0400444 /**
robertphillips8c523e02016-07-26 07:41:00 -0700445 * After this returns any pending surface IO will be issued to the backend 3D API and
446 * if the surface has MSAA it will be resolved.
447 */
Greg Daniele6bfb7d2019-04-17 15:26:11 -0400448 GrSemaphoresSubmitted flush(SkSurface::BackendSurfaceAccess access, const GrFlushInfo&);
Greg Daniela5cb7812017-06-16 09:45:32 -0400449
450 /**
451 * The next time this GrRenderTargetContext is flushed, the gpu will wait on the passed in
452 * semaphores before executing any commands.
453 */
Robert Phillipsbc4994a2019-02-14 08:36:56 -0500454 bool waitOnSemaphores(int numSemaphores, const GrBackendSemaphore waitSemaphores[]);
robertphillips8c523e02016-07-26 07:41:00 -0700455
Robert Phillips65a88fa2017-08-08 08:36:22 -0400456 void insertEventMarker(const SkString&);
457
Robert Phillipsbe9aff22019-02-15 11:33:22 -0500458 const GrCaps* caps() const;
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400459 int width() const { return fRenderTargetProxy->width(); }
460 int height() const { return fRenderTargetProxy->height(); }
Chris Dalton6ce447a2019-06-23 18:07:38 -0600461 int numSamples() const { return fRenderTargetProxy->numSamples(); }
robertphillipsca6eafc2016-05-17 09:57:46 -0700462 const SkSurfaceProps& surfaceProps() const { return fSurfaceProps; }
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400463 GrSurfaceOrigin origin() const { return fRenderTargetProxy->origin(); }
Greg Danielb46add82019-01-02 14:51:29 -0500464 bool wrapsVkSecondaryCB() const { return fRenderTargetProxy->wrapsVkSecondaryCB(); }
Greg Daniele252f082017-10-23 16:05:23 -0400465 GrMipMapped mipMapped() const;
robertphillips7bceedc2015-12-01 12:51:26 -0800466
Robert Phillipsbe9aff22019-02-15 11:33:22 -0500467 // This entry point should only be called if the backing GPU object is known to be
468 // instantiated.
469 GrRenderTarget* accessRenderTarget() { return fRenderTargetProxy->peekRenderTarget(); }
robertphillips6c7e3252016-04-27 10:47:51 -0700470
Robert Phillipsf200a902017-01-30 13:27:37 -0500471 GrSurfaceProxy* asSurfaceProxy() override { return fRenderTargetProxy.get(); }
472 const GrSurfaceProxy* asSurfaceProxy() const override { return fRenderTargetProxy.get(); }
473 sk_sp<GrSurfaceProxy> asSurfaceProxyRef() override { return fRenderTargetProxy; }
474
475 GrTextureProxy* asTextureProxy() override;
Greg Daniele252f082017-10-23 16:05:23 -0400476 const GrTextureProxy* asTextureProxy() const override;
Robert Phillipsf200a902017-01-30 13:27:37 -0500477 sk_sp<GrTextureProxy> asTextureProxyRef() override;
478
479 GrRenderTargetProxy* asRenderTargetProxy() override { return fRenderTargetProxy.get(); }
480 sk_sp<GrRenderTargetProxy> asRenderTargetProxyRef() override { return fRenderTargetProxy; }
Robert Phillipseaa86252016-11-08 13:49:39 +0000481
Robert Phillipsd46697a2017-01-25 12:10:37 -0500482 GrRenderTargetContext* asRenderTargetContext() override { return this; }
483
robertphillips391395d2016-03-02 09:26:36 -0800484 // Provides access to functions that aren't part of the public API.
Brian Osman693a5402016-10-27 15:13:22 -0400485 GrRenderTargetContextPriv priv();
486 const GrRenderTargetContextPriv priv() const;
joshualittf5883a62016-01-13 07:47:38 -0800487
Herb Derbyc1b482c2018-08-09 15:02:27 -0400488 GrTextTarget* textTarget() { return fTextTarget.get(); }
Brian Salomonf18b1d82017-10-27 11:30:49 -0400489
Robert Phillipsb5204762019-06-19 14:12:13 -0400490#if GR_TEST_UTILS
491 bool testingOnly_IsInstantiated() const { return fRenderTargetProxy->isInstantiated(); }
Chris Dalton6b982802019-06-27 13:53:46 -0600492 void testingOnly_SetPreserveOpsOnFullClear() { fPreserveOpsOnFullClear_TestingOnly = true; }
Robert Phillipsb5204762019-06-19 14:12:13 -0400493#endif
Robert Phillipseaa86252016-11-08 13:49:39 +0000494
joshualitt96880d92016-02-16 10:36:53 -0800495protected:
Brian Salomond6287472019-06-24 15:50:07 -0400496 GrRenderTargetContext(GrRecordingContext*, sk_sp<GrRenderTargetProxy>, GrColorType,
497 sk_sp<SkColorSpace>, const SkSurfaceProps*, bool managedOpList = true);
joshualitt96880d92016-02-16 10:36:53 -0800498
Robert Phillips2de8cfa2017-06-28 10:33:41 -0400499 SkDEBUGCODE(void validate() const override;)
joshualitt96880d92016-02-16 10:36:53 -0800500
robertphillipsea461502015-05-26 11:38:03 -0700501private:
Brian Salomonf18b1d82017-10-27 11:30:49 -0400502 class TextTarget;
Michael Ludwig61328202019-06-19 14:48:58 +0000503 enum class QuadOptimization;
Brian Salomonf18b1d82017-10-27 11:30:49 -0400504
Chris Dalton7d6748e2019-03-13 00:34:52 -0600505 GrAAType chooseAAType(GrAA);
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500506
Brian Salomon649a3412017-03-09 13:50:43 -0500507 friend class GrAtlasTextBlob; // for access to add[Mesh]DrawOp
Brian Osman5d034742017-09-11 13:38:55 -0400508 friend class GrClipStackClip; // for access to getOpList
robertphillips55fdccc2016-06-06 06:16:20 -0700509
robertphillips77a2e522015-10-17 07:43:27 -0700510 friend class GrDrawingManager; // for ctor
Brian Osman11052242016-10-27 14:47:55 -0400511 friend class GrRenderTargetContextPriv;
robertphillips976f5f02016-06-03 10:59:20 -0700512
Brian Salomon42521e82016-12-07 16:44:58 -0500513 // All the path renderers currently make their own ops
Brian Salomon649a3412017-03-09 13:50:43 -0500514 friend class GrSoftwarePathRenderer; // for access to add[Mesh]DrawOp
515 friend class GrAAConvexPathRenderer; // for access to add[Mesh]DrawOp
516 friend class GrDashLinePathRenderer; // for access to add[Mesh]DrawOp
517 friend class GrAAHairLinePathRenderer; // for access to add[Mesh]DrawOp
518 friend class GrAALinearizingConvexPathRenderer; // for access to add[Mesh]DrawOp
Jim Van Verth83010462017-03-16 08:45:39 -0400519 friend class GrSmallPathRenderer; // for access to add[Mesh]DrawOp
Brian Salomon649a3412017-03-09 13:50:43 -0500520 friend class GrDefaultPathRenderer; // for access to add[Mesh]DrawOp
Brian Salomon649a3412017-03-09 13:50:43 -0500521 friend class GrStencilAndCoverPathRenderer; // for access to add[Mesh]DrawOp
522 friend class GrTessellatingPathRenderer; // for access to add[Mesh]DrawOp
Chris Dalton9414c962018-06-14 10:14:50 -0600523 friend class GrCCPerFlushResources; // for access to addDrawOp
Chris Dalton1a325d22017-07-14 15:17:41 -0600524 friend class GrCoverageCountingPathRenderer; // for access to addDrawOp
Brian Salomon5d4cd9e2017-02-09 11:16:46 -0500525 // for a unit test
Robert Phillips7c525e62018-06-12 10:11:12 -0400526 friend void test_draw_op(GrContext*,
527 GrRenderTargetContext*,
528 std::unique_ptr<GrFragmentProcessor>,
Brian Salomonaff329b2017-08-11 09:40:37 -0400529 sk_sp<GrTextureProxy>);
robertphillipsea461502015-05-26 11:38:03 -0700530
Chris Dalton6b982802019-06-27 13:53:46 -0600531 GrRenderTargetOpList::CanDiscardPreviousOps canDiscardPreviousOpsOnFullClear() const;
532 void setNeedsStencil();
533
Brian Osman9a9baae2018-11-05 15:06:26 -0500534 void internalClear(const GrFixedClip&, const SkPMColor4f&, CanClearFullscreen);
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500535 void internalStencilClear(const GrFixedClip&, bool insideStencilMask);
csmartdalton29df7602016-08-31 11:55:52 -0700536
Brian Salomon82f44312017-01-11 13:42:54 -0500537 // Only consumes the GrPaint if successful.
robertphillips00095892016-02-29 13:50:40 -0800538 bool drawFilledDRRect(const GrClip& clip,
Brian Salomon82f44312017-01-11 13:42:54 -0500539 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500540 GrAA,
robertphillips00095892016-02-29 13:50:40 -0800541 const SkMatrix& viewMatrix,
542 const SkRRect& origOuter,
543 const SkRRect& origInner);
544
Michael Ludwig61328202019-06-19 14:48:58 +0000545 // If the drawn quad's paint is a const blended color, provide it as a non-null pointer to
546 // 'constColor', which enables the draw-as-clear optimization. Otherwise it is assumed the paint
547 // requires some form of shading that invalidates using a clear op.
548 //
549 // The non-const pointers should be the original draw request on input, and will be updated as
550 // appropriate depending on the returned optimization level.
551 //
Michael Ludwige08b4432019-06-19 18:00:48 -0400552 // 'stencilSettings' are provided merely for decision making purposes; When non-null,
553 // optimization strategies that submit special ops are avoided.
Michael Ludwig61328202019-06-19 14:48:58 +0000554 QuadOptimization attemptQuadOptimization(const GrClip& clip,
555 const SkPMColor4f* constColor,
Michael Ludwige08b4432019-06-19 18:00:48 -0400556 const GrUserStencilSettings* stencilSettings,
Michael Ludwig61328202019-06-19 14:48:58 +0000557 GrAA* aa,
558 GrQuadAAFlags* edgeFlags,
559 GrQuad* deviceQuad,
560 GrQuad* localQuad);
robertphillips44302392016-07-08 14:43:03 -0700561
Michael Ludwig61328202019-06-19 14:48:58 +0000562 // If stencil settings, 'ss', are non-null, AA controls MSAA or no AA. If they are null, then AA
563 // can choose between coverage, MSAA as per chooseAAType(). This will always attempt to apply
564 // quad optimizations, so all quad/rect public APIs should rely on this function for consistent
565 // clipping behavior.
566 void drawFilledQuad(const GrClip& clip,
567 GrPaint&& paint,
568 GrAA aa,
569 GrQuadAAFlags edgeFlags,
570 const GrQuad& deviceQuad,
571 const GrQuad& localQuad,
572 const GrUserStencilSettings* ss = nullptr);
Brian Salomon7694b902019-06-18 21:00:21 +0000573
Brian Salomon2fad74a2017-12-20 13:28:55 -0500574 void drawShapeUsingPathRenderer(const GrClip&, GrPaint&&, GrAA, const SkMatrix&,
575 const GrShape&);
robertphillipsea461502015-05-26 11:38:03 -0700576
Brian Salomon348a0372018-10-31 10:42:18 -0400577 // Allows caller of addDrawOp to know which op list an op will be added to.
578 using WillAddOpFn = void(GrOp*, uint32_t opListID);
579 // These perform processing specific to GrDrawOp-derived ops before recording them into an
580 // op list. Before adding the op to an op list the WillAddOpFn is called. Note that it
581 // will not be called in the event that the op is discarded. Moreover, the op may merge into
582 // another op after the function is called (either before addDrawOp returns or some time later).
583 void addDrawOp(const GrClip&, std::unique_ptr<GrDrawOp>,
584 const std::function<WillAddOpFn>& = std::function<WillAddOpFn>());
robertphillips2334fb62015-06-17 05:43:33 -0700585
Robert Phillipsbf25d432017-04-07 10:08:53 -0400586 // Makes a copy of the proxy if it is necessary for the draw and places the texture that should
587 // be used by GrXferProcessor to access the destination color in 'result'. If the return
588 // value is false then a texture copy could not be made.
Robert Phillipsbb581ce2017-05-29 15:05:15 -0400589 bool SK_WARN_UNUSED_RESULT setupDstProxy(GrRenderTargetProxy*,
590 const GrClip&,
Brian Salomon09181ef2018-11-14 13:39:51 -0500591 const GrOp& op,
Robert Phillipsbb581ce2017-05-29 15:05:15 -0400592 GrXferProcessor::DstProxy* result);
Brian Salomon467921e2017-03-06 16:17:12 -0500593
Brian Salomon024bd002019-06-11 11:38:16 -0400594 // The rescaling step of asyncRescaleAndReadPixels[YUV420]().
Brian Salomon031b0ba2019-05-23 11:05:26 -0400595 sk_sp<GrRenderTargetContext> rescale(const SkImageInfo& info, const SkIRect& srcRect,
596 SkSurface::RescaleGamma rescaleGamma,
597 SkFilterQuality rescaleQuality);
Brian Salomon024bd002019-06-11 11:38:16 -0400598 // The async read step of asyncRescaleAndReadPixels()
599 void asyncReadPixels(const SkIRect& rect, SkColorType colorType, ReadPixelsCallback callback,
600 ReadPixelsContext context);
601
602 // Inserts a transfer, part of the implementation of asyncReadPixels and
603 // asyncRescaleAndReadPixelsYUV420().
604 struct PixelTransferResult {
605 using ConversionSignature = void(void* dst, const void* mappedBuffer);
606 // If null then the transfer could not be performed. Otherwise this buffer will contain
607 // the pixel data when the transfer is complete.
608 sk_sp<GrGpuBuffer> fTransferBuffer;
609 // If this is null then the transfer buffer will contain the data in the requested
610 // color type. Otherwise, when the transfer is done this must be called to convert
611 // from the transfer buffer's color type to the requested color type.
612 std::function<ConversionSignature> fPixelConverter;
613 };
614 // Inserts a transfer of rect to a buffer that this call will create.
615 PixelTransferResult transferPixels(GrColorType colorType, const SkIRect& rect);
Brian Salomon031b0ba2019-05-23 11:05:26 -0400616
Robert Phillips2de8cfa2017-06-28 10:33:41 -0400617 GrRenderTargetOpList* getRTOpList();
618 GrOpList* getOpList() override;
robertphillipsa106c622015-10-16 09:07:06 -0700619
Herb Derbyc1b482c2018-08-09 15:02:27 -0400620 std::unique_ptr<GrTextTarget> fTextTarget;
Brian Salomonf18b1d82017-10-27 11:30:49 -0400621 sk_sp<GrRenderTargetProxy> fRenderTargetProxy;
robertphillipsa106c622015-10-16 09:07:06 -0700622
Brian Osman11052242016-10-27 14:47:55 -0400623 // In MDB-mode the GrOpList can be closed by some other renderTargetContext that has picked
Robert Phillipsf2361d22016-10-25 14:20:06 -0400624 // it up. For this reason, the GrOpList should only ever be accessed via 'getOpList'.
Brian Salomonf18b1d82017-10-27 11:30:49 -0400625 sk_sp<GrRenderTargetOpList> fOpList;
robertphillips2334fb62015-06-17 05:43:33 -0700626
Brian Salomonf18b1d82017-10-27 11:30:49 -0400627 SkSurfaceProps fSurfaceProps;
628 bool fManagedOpList;
Robert Phillipse305cc1f2016-12-14 12:19:05 -0500629
Chris Dalton6b982802019-06-27 13:53:46 -0600630 bool fNeedsStencil = false;
631#if GR_TEST_UTILS
632 bool fPreserveOpsOnFullClear_TestingOnly = false;
633#endif
634
Robert Phillipse305cc1f2016-12-14 12:19:05 -0500635 typedef GrSurfaceContext INHERITED;
robertphillipsea461502015-05-26 11:38:03 -0700636};
637
638#endif