blob: b613a276a477814870290fa2ace506649f0fc0df [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"
robertphillipsea461502015-05-26 11:38:03 -070012#include "GrColor.h"
bsalomonfaf82032016-09-16 09:53:27 -070013#include "GrContext.h"
Robert Phillips6be756b2018-01-16 15:07:54 -050014#include "GrContextPriv.h"
csmartdaltonecbc12b2016-06-08 10:08:43 -070015#include "GrPaint.h"
Brian Osman45580d32016-11-23 09:37:01 -050016#include "GrSurfaceContext.h"
Brian Salomon7c8460e2017-05-12 11:36:10 -040017#include "GrTypesPriv.h"
Brian Salomon467921e2017-03-06 16:17:12 -050018#include "GrXferProcessor.h"
Brian Salomon238069b2018-07-11 15:58:57 -040019#include "SkCanvas.h"
robertphillipsea461502015-05-26 11:38:03 -070020#include "SkRefCnt.h"
robertphillipsfcf78292015-06-19 11:49:52 -070021#include "SkSurfaceProps.h"
Herb Derbyc1b482c2018-08-09 15:02:27 -040022#include "text/GrTextTarget.h"
robertphillipsea461502015-05-26 11:38:03 -070023
Greg Daniela5cb7812017-06-16 09:45:32 -040024class GrBackendSemaphore;
Chris Dalton1a325d22017-07-14 15:17:41 -060025class GrCCPRAtlas;
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;
robertphillipsea461502015-05-26 11:38:03 -070032class GrRenderTarget;
Brian Osman45580d32016-11-23 09:37:01 -050033class GrRenderTargetContextPriv;
Robert Phillipsf2361d22016-10-25 14:20:06 -040034class GrRenderTargetOpList;
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 */
Chris Dalton344e9032017-12-11 15:42:09 -070082 void clear(const SkIRect* rect, GrColor 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 */
bsalomona2e69fc2015-11-05 10:41:43 -0800114 void fillRectToRect(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500115 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500116 GrAA,
bsalomona2e69fc2015-11-05 10:41:43 -0800117 const SkMatrix& viewMatrix,
118 const SkRect& rectToDraw,
119 const SkRect& localRect);
robertphillipsea461502015-05-26 11:38:03 -0700120
121 /**
bsalomona2e69fc2015-11-05 10:41:43 -0800122 * Fills a rect with a paint and a localMatrix.
robertphillipsea461502015-05-26 11:38:03 -0700123 */
bsalomona2e69fc2015-11-05 10:41:43 -0800124 void fillRectWithLocalMatrix(const GrClip& clip,
Brian Salomon82f44312017-01-11 13:42:54 -0500125 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500126 GrAA,
bsalomona2e69fc2015-11-05 10:41:43 -0800127 const SkMatrix& viewMatrix,
128 const SkRect& rect,
129 const SkMatrix& localMatrix);
robertphillipsea461502015-05-26 11:38:03 -0700130
131 /**
Brian Salomon34169692017-08-28 15:32:01 -0400132 * Creates an op that draws a subrectangle of a texture. The passed color is modulated by the
133 * texture's color. 'srcRect' specifies the rectangle of the texture to draw. 'dstRect'
134 * specifies the rectangle to draw in local coords which will be transformed by 'viewMatrix' to
Brian Salomonbe3c1d22018-05-21 12:54:39 -0400135 * device space.
Brian Salomon34169692017-08-28 15:32:01 -0400136 */
Brian Salomonbe3c1d22018-05-21 12:54:39 -0400137 void drawTexture(const GrClip& clip, sk_sp<GrTextureProxy>, GrSamplerState::Filter, GrColor,
138 const SkRect& srcRect, const SkRect& dstRect, GrAA aa,
Brian Salomonb80ffee2018-05-23 16:39:39 -0400139 SkCanvas::SrcRectConstraint, const SkMatrix& viewMatrix,
Brian Osman3ebd3542018-07-30 14:36:53 -0400140 sk_sp<GrColorSpaceXform> texXform, sk_sp<GrColorSpaceXform> colorXform);
Brian Salomon34169692017-08-28 15:32:01 -0400141
142 /**
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500143 * Draw a roundrect using a paint.
robertphillipsea461502015-05-26 11:38:03 -0700144 *
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500145 * @param paint describes how to color pixels.
146 * @param GrAA Controls whether rrect is antialiased.
147 * @param viewMatrix transformation matrix
148 * @param rrect the roundrect to draw
149 * @param style style to apply to the rrect. Currently path effects are not allowed.
robertphillipsea461502015-05-26 11:38:03 -0700150 */
robertphillips2e1e51f2015-10-15 08:01:48 -0700151 void drawRRect(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500152 GrPaint&&,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500153 GrAA,
robertphillipsea461502015-05-26 11:38:03 -0700154 const SkMatrix& viewMatrix,
155 const SkRRect& rrect,
bsalomon6663acf2016-05-10 09:14:17 -0700156 const GrStyle& style);
robertphillipsea461502015-05-26 11:38:03 -0700157
158 /**
Jim Van Verth3af1af92017-05-18 15:06:54 -0400159 * Use a fast method to render the ambient and spot shadows for a path.
160 * Will return false if not possible for the given path.
Jim Van Verthc5903412016-11-17 15:27:09 -0500161 *
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500162 * @param viewMatrix transformation matrix
Jim Van Verth3af1af92017-05-18 15:06:54 -0400163 * @param path the path to shadow
164 * @param rec parameters for shadow rendering
Jim Van Verthc5903412016-11-17 15:27:09 -0500165 */
Jim Van Verth3af1af92017-05-18 15:06:54 -0400166 bool drawFastShadow(const GrClip&,
Jim Van Verth3af1af92017-05-18 15:06:54 -0400167 const SkMatrix& viewMatrix,
168 const SkPath& path,
169 const SkDrawShadowRec& rec);
Jim Van Verthc5903412016-11-17 15:27:09 -0500170
171 /**
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500172 * Shortcut for filling a SkPath consisting of nested rrects using a paint. The result is
173 * undefined if outer does not contain inner.
robertphillips00095892016-02-29 13:50:40 -0800174 *
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500175 * @param paint describes how to color pixels.
176 * @param GrAA Controls whether rrects edges are antialiased
177 * @param viewMatrix transformation matrix
178 * @param outer the outer roundrect
179 * @param inner the inner roundrect
robertphillips00095892016-02-29 13:50:40 -0800180 */
181 void drawDRRect(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500182 GrPaint&&,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500183 GrAA,
robertphillips00095892016-02-29 13:50:40 -0800184 const SkMatrix& viewMatrix,
185 const SkRRect& outer,
186 const SkRRect& inner);
187
188 /**
robertphillipsea461502015-05-26 11:38:03 -0700189 * Draws a path.
190 *
191 * @param paint describes how to color pixels.
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500192 * @param GrAA Controls whether the path is antialiased.
robertphillipsea461502015-05-26 11:38:03 -0700193 * @param viewMatrix transformation matrix
194 * @param path the path to draw
bsalomon6663acf2016-05-10 09:14:17 -0700195 * @param style style to apply to the path.
robertphillipsea461502015-05-26 11:38:03 -0700196 */
robertphillips2e1e51f2015-10-15 08:01:48 -0700197 void drawPath(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500198 GrPaint&&,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500199 GrAA,
robertphillipsea461502015-05-26 11:38:03 -0700200 const SkMatrix& viewMatrix,
201 const SkPath&,
Robert Phillips20390c32018-08-17 11:01:03 -0400202 const GrStyle&);
203
204 /**
205 * Draws a shape.
206 *
207 * @param paint describes how to color pixels.
208 * @param GrAA Controls whether the path is antialiased.
209 * @param viewMatrix transformation matrix
210 * @param shape the shape to draw
211 */
212 void drawShape(const GrClip&,
213 GrPaint&&,
214 GrAA,
215 const SkMatrix& viewMatrix,
216 const GrShape&);
217
robertphillipsea461502015-05-26 11:38:03 -0700218
219 /**
220 * Draws vertices with a paint.
221 *
Brian Osmanae0c50c2017-05-25 16:56:34 -0400222 * @param paint describes how to color pixels.
223 * @param viewMatrix transformation matrix
224 * @param vertices specifies the mesh to draw.
Ruiqi Mao4ec72f72018-07-10 17:21:07 -0400225 * @param bones bone deformation matrices.
226 * @param boneCount number of bone matrices.
Brian Osmanae0c50c2017-05-25 16:56:34 -0400227 * @param overridePrimType primitive type to draw. If NULL, derive prim type from vertices.
robertphillipsea461502015-05-26 11:38:03 -0700228 */
robertphillips2e1e51f2015-10-15 08:01:48 -0700229 void drawVertices(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500230 GrPaint&& paint,
robertphillipsea461502015-05-26 11:38:03 -0700231 const SkMatrix& viewMatrix,
Brian Osmanae0c50c2017-05-25 16:56:34 -0400232 sk_sp<SkVertices> vertices,
Ruiqi Maoc97a3392018-08-15 10:44:19 -0400233 const SkVertices::Bone bones[],
Ruiqi Mao4ec72f72018-07-10 17:21:07 -0400234 int boneCount,
Brian Osmanae0c50c2017-05-25 16:56:34 -0400235 GrPrimitiveType* overridePrimType = nullptr);
Brian Salomon199fb872017-02-06 09:41:10 -0500236
237 /**
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500238 * Draws textured sprites from an atlas with a paint. This currently does not support AA for the
239 * sprite rectangle edges.
jvanverth31ff7622015-08-07 10:09:28 -0700240 *
241 * @param paint describes how to color pixels.
242 * @param viewMatrix transformation matrix
243 * @param spriteCount number of sprites.
244 * @param xform array of compressed transformation data, required.
245 * @param texRect array of texture rectangles used to access the paint.
246 * @param colors optional array of per-sprite colors, supercedes
247 * the paint's color field.
248 */
robertphillips2e1e51f2015-10-15 08:01:48 -0700249 void drawAtlas(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500250 GrPaint&& paint,
jvanverth31ff7622015-08-07 10:09:28 -0700251 const SkMatrix& viewMatrix,
252 int spriteCount,
253 const SkRSXform xform[],
254 const SkRect texRect[],
255 const SkColor colors[]);
msarettcc319b92016-08-25 18:07:18 -0700256
257 /**
258 * Draws a region.
259 *
260 * @param paint describes how to color pixels
261 * @param viewMatrix transformation matrix
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500262 * @param aa should the rects of the region be antialiased.
msarettcc319b92016-08-25 18:07:18 -0700263 * @param region the region to be drawn
264 * @param style style to apply to the region
265 */
266 void drawRegion(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500267 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500268 GrAA aa,
msarettcc319b92016-08-25 18:07:18 -0700269 const SkMatrix& viewMatrix,
270 const SkRegion& region,
Stan Iliev73d8fd92017-08-02 15:36:24 -0400271 const GrStyle& style,
272 const GrUserStencilSettings* ss = nullptr);
msarettcc319b92016-08-25 18:07:18 -0700273
jvanverth31ff7622015-08-07 10:09:28 -0700274 /**
robertphillipsea461502015-05-26 11:38:03 -0700275 * Draws an oval.
276 *
277 * @param paint describes how to color pixels.
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500278 * @param GrAA Controls whether the oval is antialiased.
robertphillipsea461502015-05-26 11:38:03 -0700279 * @param viewMatrix transformation matrix
280 * @param oval the bounding rect of the oval.
bsalomon6663acf2016-05-10 09:14:17 -0700281 * @param style style to apply to the oval. Currently path effects are not allowed.
robertphillipsea461502015-05-26 11:38:03 -0700282 */
robertphillips2e1e51f2015-10-15 08:01:48 -0700283 void drawOval(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500284 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500285 GrAA,
robertphillipsea461502015-05-26 11:38:03 -0700286 const SkMatrix& viewMatrix,
287 const SkRect& oval,
bsalomon6663acf2016-05-10 09:14:17 -0700288 const GrStyle& style);
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500289 /**
290 * Draws a partial arc of an oval.
291 *
292 * @param paint describes how to color pixels.
Brian Salomon99504082016-12-09 15:51:31 -0500293 * @param GrGrAA Controls whether the arc is antialiased.
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500294 * @param viewMatrix transformation matrix.
295 * @param oval the bounding rect of the oval.
296 * @param startAngle starting angle in degrees.
297 * @param sweepAngle angle to sweep in degrees. Must be in (-360, 360)
298 * @param useCenter true means that the implied path begins at the oval center, connects as
299 * a line to the point indicated by the start contains the arc indicated by
300 * the sweep angle. If false the line beginning at the center point is
301 * omitted.
302 * @param style style to apply to the oval.
303 */
bsalomon4f3a0ca2016-08-22 13:14:26 -0700304 void drawArc(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500305 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500306 GrAA,
bsalomon4f3a0ca2016-08-22 13:14:26 -0700307 const SkMatrix& viewMatrix,
308 const SkRect& oval,
309 SkScalar startAngle,
310 SkScalar sweepAngle,
311 bool useCenter,
312 const GrStyle& style);
robertphillipsea461502015-05-26 11:38:03 -0700313
joshualitt33a5fce2015-11-18 13:28:51 -0800314 /**
bsalomon4f3a0ca2016-08-22 13:14:26 -0700315 * Draw the image as a set of rects, specified by |iter|.
joshualitt33a5fce2015-11-18 13:28:51 -0800316 */
msarett10e3d9b2016-08-18 15:46:03 -0700317 void drawImageLattice(const GrClip&,
Brian Salomon2a943df2018-05-04 13:43:19 -0400318 GrPaint&&,
msarett10e3d9b2016-08-18 15:46:03 -0700319 const SkMatrix& viewMatrix,
Brian Salomon2a943df2018-05-04 13:43:19 -0400320 sk_sp<GrTextureProxy>,
321 sk_sp<GrColorSpaceXform>,
322 GrSamplerState::Filter,
323 std::unique_ptr<SkLatticeIter>,
msarett10e3d9b2016-08-18 15:46:03 -0700324 const SkRect& dst);
robertphillipsea461502015-05-26 11:38:03 -0700325
robertphillips8c523e02016-07-26 07:41:00 -0700326 /**
327 * After this returns any pending surface IO will be issued to the backend 3D API and
328 * if the surface has MSAA it will be resolved.
329 */
Greg Daniel51316782017-08-02 15:10:09 +0000330 GrSemaphoresSubmitted prepareForExternalIO(int numSemaphores,
331 GrBackendSemaphore backendSemaphores[]);
Greg Daniela5cb7812017-06-16 09:45:32 -0400332
333 /**
334 * The next time this GrRenderTargetContext is flushed, the gpu will wait on the passed in
335 * semaphores before executing any commands.
336 */
Greg Danielc64ee462017-06-15 16:59:49 -0400337 bool waitOnSemaphores(int numSemaphores, const GrBackendSemaphore* waitSemaphores);
robertphillips8c523e02016-07-26 07:41:00 -0700338
Robert Phillips65a88fa2017-08-08 08:36:22 -0400339 void insertEventMarker(const SkString&);
340
Brian Salomon7c8460e2017-05-12 11:36:10 -0400341 GrFSAAType fsaaType() const { return fRenderTargetProxy->fsaaType(); }
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400342 const GrCaps* caps() const { return fContext->contextPriv().caps(); }
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400343 int width() const { return fRenderTargetProxy->width(); }
344 int height() const { return fRenderTargetProxy->height(); }
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400345 int numColorSamples() const { return fRenderTargetProxy->numColorSamples(); }
Brian Salomon50e66d42017-05-15 16:28:07 -0400346 int numStencilSamples() const { return fRenderTargetProxy->numStencilSamples(); }
robertphillipsca6eafc2016-05-17 09:57:46 -0700347 const SkSurfaceProps& surfaceProps() const { return fSurfaceProps; }
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400348 GrSurfaceOrigin origin() const { return fRenderTargetProxy->origin(); }
Greg Daniele252f082017-10-23 16:05:23 -0400349 GrMipMapped mipMapped() const;
robertphillips7bceedc2015-12-01 12:51:26 -0800350
robertphillips7761d612016-05-16 09:14:53 -0700351 bool wasAbandoned() const;
352
Robert Phillips65048132017-08-10 08:44:49 -0400353 void setNeedsStencil() { fRenderTargetProxy->setNeedsStencil(); }
354
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400355 GrRenderTarget* accessRenderTarget() {
356 // TODO: usage of this entry point needs to be reduced and potentially eliminated
357 // since it ends the deferral of the GrRenderTarget's allocation
Robert Phillips6be756b2018-01-16 15:07:54 -0500358 if (!fRenderTargetProxy->instantiate(fContext->contextPriv().resourceProvider())) {
Robert Phillipseee4d6e2017-06-05 09:26:07 -0400359 return nullptr;
360 }
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400361 return fRenderTargetProxy->peekRenderTarget();
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400362 }
robertphillips6c7e3252016-04-27 10:47:51 -0700363
Robert Phillipsf200a902017-01-30 13:27:37 -0500364 GrSurfaceProxy* asSurfaceProxy() override { return fRenderTargetProxy.get(); }
365 const GrSurfaceProxy* asSurfaceProxy() const override { return fRenderTargetProxy.get(); }
366 sk_sp<GrSurfaceProxy> asSurfaceProxyRef() override { return fRenderTargetProxy; }
367
368 GrTextureProxy* asTextureProxy() override;
Greg Daniele252f082017-10-23 16:05:23 -0400369 const GrTextureProxy* asTextureProxy() const override;
Robert Phillipsf200a902017-01-30 13:27:37 -0500370 sk_sp<GrTextureProxy> asTextureProxyRef() override;
371
372 GrRenderTargetProxy* asRenderTargetProxy() override { return fRenderTargetProxy.get(); }
373 sk_sp<GrRenderTargetProxy> asRenderTargetProxyRef() override { return fRenderTargetProxy; }
Robert Phillipseaa86252016-11-08 13:49:39 +0000374
Robert Phillipsd46697a2017-01-25 12:10:37 -0500375 GrRenderTargetContext* asRenderTargetContext() override { return this; }
376
robertphillips391395d2016-03-02 09:26:36 -0800377 // Provides access to functions that aren't part of the public API.
Brian Osman693a5402016-10-27 15:13:22 -0400378 GrRenderTargetContextPriv priv();
379 const GrRenderTargetContextPriv priv() const;
joshualittf5883a62016-01-13 07:47:38 -0800380
Herb Derbyc1b482c2018-08-09 15:02:27 -0400381 GrTextTarget* textTarget() { return fTextTarget.get(); }
Brian Salomonf18b1d82017-10-27 11:30:49 -0400382
Robert Phillipseaa86252016-11-08 13:49:39 +0000383 bool isWrapped_ForTesting() const;
384
joshualitt96880d92016-02-16 10:36:53 -0800385protected:
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400386 GrRenderTargetContext(GrContext*, GrDrawingManager*, sk_sp<GrRenderTargetProxy>,
Robert Phillips2c862492017-01-18 10:08:39 -0500387 sk_sp<SkColorSpace>, const SkSurfaceProps*, GrAuditTrail*,
Robert Phillips941d1442017-06-14 16:37:02 -0400388 GrSingleOwner*, bool managedOpList = true);
joshualitt96880d92016-02-16 10:36:53 -0800389
Robert Phillips2de8cfa2017-06-28 10:33:41 -0400390 SkDEBUGCODE(void validate() const override;)
joshualitt96880d92016-02-16 10:36:53 -0800391
robertphillipsea461502015-05-26 11:38:03 -0700392private:
Brian Salomonf18b1d82017-10-27 11:30:49 -0400393 class TextTarget;
394
Brian Salomonea26d6b2018-01-23 20:33:21 +0000395 inline GrAAType chooseAAType(GrAA aa, GrAllowMixedSamples allowMixedSamples) {
396 return GrChooseAAType(aa, this->fsaaType(), allowMixedSamples, *this->caps());
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500397 }
398
Brian Salomon649a3412017-03-09 13:50:43 -0500399 friend class GrAtlasTextBlob; // for access to add[Mesh]DrawOp
Brian Osman5d034742017-09-11 13:38:55 -0400400 friend class GrClipStackClip; // for access to getOpList
robertphillips55fdccc2016-06-06 06:16:20 -0700401
robertphillips77a2e522015-10-17 07:43:27 -0700402 friend class GrDrawingManager; // for ctor
Brian Osman11052242016-10-27 14:47:55 -0400403 friend class GrRenderTargetContextPriv;
robertphillips976f5f02016-06-03 10:59:20 -0700404
Brian Salomon42521e82016-12-07 16:44:58 -0500405 // All the path renderers currently make their own ops
Brian Salomon649a3412017-03-09 13:50:43 -0500406 friend class GrSoftwarePathRenderer; // for access to add[Mesh]DrawOp
407 friend class GrAAConvexPathRenderer; // for access to add[Mesh]DrawOp
408 friend class GrDashLinePathRenderer; // for access to add[Mesh]DrawOp
409 friend class GrAAHairLinePathRenderer; // for access to add[Mesh]DrawOp
410 friend class GrAALinearizingConvexPathRenderer; // for access to add[Mesh]DrawOp
Jim Van Verth83010462017-03-16 08:45:39 -0400411 friend class GrSmallPathRenderer; // for access to add[Mesh]DrawOp
Brian Salomon649a3412017-03-09 13:50:43 -0500412 friend class GrDefaultPathRenderer; // for access to add[Mesh]DrawOp
Brian Salomon649a3412017-03-09 13:50:43 -0500413 friend class GrStencilAndCoverPathRenderer; // for access to add[Mesh]DrawOp
414 friend class GrTessellatingPathRenderer; // for access to add[Mesh]DrawOp
Chris Dalton9414c962018-06-14 10:14:50 -0600415 friend class GrCCPerFlushResources; // for access to addDrawOp
Chris Dalton1a325d22017-07-14 15:17:41 -0600416 friend class GrCoverageCountingPathRenderer; // for access to addDrawOp
Brian Salomon5d4cd9e2017-02-09 11:16:46 -0500417 // for a unit test
Robert Phillips7c525e62018-06-12 10:11:12 -0400418 friend void test_draw_op(GrContext*,
419 GrRenderTargetContext*,
420 std::unique_ptr<GrFragmentProcessor>,
Brian Salomonaff329b2017-08-11 09:40:37 -0400421 sk_sp<GrTextureProxy>);
robertphillipsea461502015-05-26 11:38:03 -0700422
Chris Dalton344e9032017-12-11 15:42:09 -0700423 void internalClear(const GrFixedClip&, const GrColor, CanClearFullscreen);
csmartdalton29df7602016-08-31 11:55:52 -0700424
Brian Salomon82f44312017-01-11 13:42:54 -0500425 // Only consumes the GrPaint if successful.
robertphillips00095892016-02-29 13:50:40 -0800426 bool drawFilledDRRect(const GrClip& clip,
Brian Salomon82f44312017-01-11 13:42:54 -0500427 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500428 GrAA,
robertphillips00095892016-02-29 13:50:40 -0800429 const SkMatrix& viewMatrix,
430 const SkRRect& origOuter,
431 const SkRRect& origInner);
432
Brian Salomon82f44312017-01-11 13:42:54 -0500433 // Only consumes the GrPaint if successful.
robertphillips44302392016-07-08 14:43:03 -0700434 bool drawFilledRect(const GrClip& clip,
Brian Salomon82f44312017-01-11 13:42:54 -0500435 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500436 GrAA,
robertphillips44302392016-07-08 14:43:03 -0700437 const SkMatrix& viewMatrix,
438 const SkRect& rect,
439 const GrUserStencilSettings* ss);
440
Brian Salomon2fad74a2017-12-20 13:28:55 -0500441 void drawShapeUsingPathRenderer(const GrClip&, GrPaint&&, GrAA, const SkMatrix&,
442 const GrShape&);
robertphillipsea461502015-05-26 11:38:03 -0700443
Brian Salomon649a3412017-03-09 13:50:43 -0500444 // These perform processing specific to Gr[Mesh]DrawOp-derived ops before recording them into
445 // the op list. They return the id of the opList to which the op was added, or 0, if it was
Chris Daltonf104fec2018-05-22 16:17:48 -0600446 // dropped (e.g., due to clipping or being combined).
Brian Salomon54d212e2017-03-21 14:22:38 -0400447 uint32_t addDrawOp(const GrClip&, std::unique_ptr<GrDrawOp>);
robertphillips2334fb62015-06-17 05:43:33 -0700448
Robert Phillipsbf25d432017-04-07 10:08:53 -0400449 // Makes a copy of the proxy if it is necessary for the draw and places the texture that should
450 // be used by GrXferProcessor to access the destination color in 'result'. If the return
451 // value is false then a texture copy could not be made.
Robert Phillipsbb581ce2017-05-29 15:05:15 -0400452 bool SK_WARN_UNUSED_RESULT setupDstProxy(GrRenderTargetProxy*,
453 const GrClip&,
454 const SkRect& opBounds,
455 GrXferProcessor::DstProxy* result);
Brian Salomon467921e2017-03-06 16:17:12 -0500456
Robert Phillips2de8cfa2017-06-28 10:33:41 -0400457 GrRenderTargetOpList* getRTOpList();
458 GrOpList* getOpList() override;
robertphillipsa106c622015-10-16 09:07:06 -0700459
Herb Derbyc1b482c2018-08-09 15:02:27 -0400460 std::unique_ptr<GrTextTarget> fTextTarget;
Brian Salomonf18b1d82017-10-27 11:30:49 -0400461 sk_sp<GrRenderTargetProxy> fRenderTargetProxy;
robertphillipsa106c622015-10-16 09:07:06 -0700462
Brian Osman11052242016-10-27 14:47:55 -0400463 // In MDB-mode the GrOpList can be closed by some other renderTargetContext that has picked
Robert Phillipsf2361d22016-10-25 14:20:06 -0400464 // it up. For this reason, the GrOpList should only ever be accessed via 'getOpList'.
Brian Salomonf18b1d82017-10-27 11:30:49 -0400465 sk_sp<GrRenderTargetOpList> fOpList;
robertphillips2334fb62015-06-17 05:43:33 -0700466
Brian Salomonf18b1d82017-10-27 11:30:49 -0400467 SkSurfaceProps fSurfaceProps;
468 bool fManagedOpList;
Robert Phillipse305cc1f2016-12-14 12:19:05 -0500469
470 typedef GrSurfaceContext INHERITED;
robertphillipsea461502015-05-26 11:38:03 -0700471};
472
473#endif