blob: acbf963c06fc2e3c328f7da6cef39235fe2e4421 [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"
robertphillipsea461502015-05-26 11:38:03 -070019#include "SkRefCnt.h"
robertphillipsfcf78292015-06-19 11:49:52 -070020#include "SkSurfaceProps.h"
Brian Salomonf18b1d82017-10-27 11:30:49 -040021#include "text/GrTextUtils.h"
robertphillipsea461502015-05-26 11:38:03 -070022
Greg Daniela5cb7812017-06-16 09:45:32 -040023class GrBackendSemaphore;
Chris Dalton1a325d22017-07-14 15:17:41 -060024class GrCCPRAtlas;
robertphillipsea461502015-05-26 11:38:03 -070025class GrClip;
Brian Osman2240be92017-10-18 13:15:13 -040026class GrColorSpaceXform;
Chris Dalton1a325d22017-07-14 15:17:41 -060027class GrCoverageCountingPathRenderer;
robertphillips77a2e522015-10-17 07:43:27 -070028class GrDrawingManager;
Brian Salomon9afd3712016-12-01 10:59:09 -050029class GrDrawOp;
csmartdalton29df7602016-08-31 11:55:52 -070030class GrFixedClip;
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;
robertphillips2334fb62015-06-17 05:43:33 -070038class SkDrawFilter;
Jim Van Verth3af1af92017-05-18 15:06:54 -040039struct SkDrawShadowRec;
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
Brian Salomon6f1d36c2017-01-13 12:02:17 -050061 // We use SkPaint rather than GrPaint here for two reasons:
62 // * The SkPaint carries extra text settings. If these were extracted to a lighter object
63 // we could use GrPaint except that
64 // * SkPaint->GrPaint conversion depends upon whether the glyphs are color or grayscale and
65 // this can vary within a text run.
66 virtual void drawText(const GrClip&, const SkPaint&, const SkMatrix& viewMatrix,
Brian Salomon82f44312017-01-11 13:42:54 -050067 const char text[], size_t byteLength, SkScalar x, SkScalar y,
68 const SkIRect& clipBounds);
Brian Salomon6f1d36c2017-01-13 12:02:17 -050069 virtual void drawPosText(const GrClip&, const SkPaint&, const SkMatrix& viewMatrix,
Brian Salomon82f44312017-01-11 13:42:54 -050070 const char text[], size_t byteLength, const SkScalar pos[],
71 int scalarsPerPosition, const SkPoint& offset,
72 const SkIRect& clipBounds);
joshualitt96880d92016-02-16 10:36:53 -080073 virtual void drawTextBlob(const GrClip&, const SkPaint&,
74 const SkMatrix& viewMatrix, const SkTextBlob*,
75 SkScalar x, SkScalar y,
76 SkDrawFilter*, const SkIRect& clipBounds);
robertphillipsea461502015-05-26 11:38:03 -070077
robertphillipsea461502015-05-26 11:38:03 -070078 /**
79 * Provides a perfomance hint that the render target's contents are allowed
80 * to become undefined.
81 */
robertphillips2e1e51f2015-10-15 08:01:48 -070082 void discard();
robertphillipsea461502015-05-26 11:38:03 -070083
Chris Dalton344e9032017-12-11 15:42:09 -070084 enum class CanClearFullscreen : bool {
85 kNo = false,
86 kYes = true
87 };
88
robertphillipsea461502015-05-26 11:38:03 -070089 /**
90 * Clear the entire or rect of the render target, ignoring any clips.
robertphillipsea461502015-05-26 11:38:03 -070091 * @param rect the rect to clear or the whole thing if rect is NULL.
92 * @param color the color to clear to.
Chris Dalton344e9032017-12-11 15:42:09 -070093 * @param CanClearFullscreen allows partial clears to be converted to fullscreen clears on
94 * tiling platforms where that is an optimization.
robertphillipsea461502015-05-26 11:38:03 -070095 */
Chris Dalton344e9032017-12-11 15:42:09 -070096 void clear(const SkIRect* rect, GrColor color, CanClearFullscreen);
robertphillipsea461502015-05-26 11:38:03 -070097
98 /**
99 * Draw everywhere (respecting the clip) with the paint.
100 */
Brian Salomon82f44312017-01-11 13:42:54 -0500101 void drawPaint(const GrClip&, GrPaint&&, const SkMatrix& viewMatrix);
robertphillipsea461502015-05-26 11:38:03 -0700102
103 /**
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500104 * Draw the rect using a paint.
105 * @param paint describes how to color pixels.
106 * @param GrAA Controls whether rect is antialiased
107 * @param viewMatrix transformation matrix
108 * @param style The style to apply. Null means fill. Currently path effects are not
109 * allowed.
110 * The rects coords are used to access the paint (through texture matrix)
robertphillipsea461502015-05-26 11:38:03 -0700111 */
robertphillips2e1e51f2015-10-15 08:01:48 -0700112 void drawRect(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500113 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500114 GrAA,
robertphillipsea461502015-05-26 11:38:03 -0700115 const SkMatrix& viewMatrix,
116 const SkRect&,
Brian Salomon82f44312017-01-11 13:42:54 -0500117 const GrStyle* style = nullptr);
robertphillipsea461502015-05-26 11:38:03 -0700118
119 /**
bsalomona2e69fc2015-11-05 10:41:43 -0800120 * Maps a rectangle of shader coordinates to a rectangle and fills that rectangle.
robertphillipsea461502015-05-26 11:38:03 -0700121 *
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500122 * @param paint describes how to color pixels.
123 * @param GrAA Controls whether rect is antialiased
124 * @param viewMatrix transformation matrix which applies to rectToDraw
125 * @param rectToDraw the rectangle to draw
126 * @param localRect the rectangle of shader coordinates applied to rectToDraw
robertphillipsea461502015-05-26 11:38:03 -0700127 */
bsalomona2e69fc2015-11-05 10:41:43 -0800128 void fillRectToRect(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500129 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500130 GrAA,
bsalomona2e69fc2015-11-05 10:41:43 -0800131 const SkMatrix& viewMatrix,
132 const SkRect& rectToDraw,
133 const SkRect& localRect);
robertphillipsea461502015-05-26 11:38:03 -0700134
135 /**
bsalomona2e69fc2015-11-05 10:41:43 -0800136 * Fills a rect with a paint and a localMatrix.
robertphillipsea461502015-05-26 11:38:03 -0700137 */
bsalomona2e69fc2015-11-05 10:41:43 -0800138 void fillRectWithLocalMatrix(const GrClip& clip,
Brian Salomon82f44312017-01-11 13:42:54 -0500139 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500140 GrAA,
bsalomona2e69fc2015-11-05 10:41:43 -0800141 const SkMatrix& viewMatrix,
142 const SkRect& rect,
143 const SkMatrix& localMatrix);
robertphillipsea461502015-05-26 11:38:03 -0700144
145 /**
Brian Salomon34169692017-08-28 15:32:01 -0400146 * Creates an op that draws a subrectangle of a texture. The passed color is modulated by the
147 * texture's color. 'srcRect' specifies the rectangle of the texture to draw. 'dstRect'
148 * specifies the rectangle to draw in local coords which will be transformed by 'viewMatrix' to
Brian Salomonbe3c1d22018-05-21 12:54:39 -0400149 * device space.
Brian Salomon34169692017-08-28 15:32:01 -0400150 */
Brian Salomonbe3c1d22018-05-21 12:54:39 -0400151 void drawTexture(const GrClip& clip, sk_sp<GrTextureProxy>, GrSamplerState::Filter, GrColor,
152 const SkRect& srcRect, const SkRect& dstRect, GrAA aa,
Brian Salomona0047bc2018-05-23 16:39:39 -0400153 SkCanvas::SrcRectConstraint, const SkMatrix& viewMatrix,
154 sk_sp<GrColorSpaceXform>);
Brian Salomon34169692017-08-28 15:32:01 -0400155
156 /**
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500157 * Draw a roundrect using a paint.
robertphillipsea461502015-05-26 11:38:03 -0700158 *
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500159 * @param paint describes how to color pixels.
160 * @param GrAA Controls whether rrect is antialiased.
161 * @param viewMatrix transformation matrix
162 * @param rrect the roundrect to draw
163 * @param style style to apply to the rrect. Currently path effects are not allowed.
robertphillipsea461502015-05-26 11:38:03 -0700164 */
robertphillips2e1e51f2015-10-15 08:01:48 -0700165 void drawRRect(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500166 GrPaint&&,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500167 GrAA,
robertphillipsea461502015-05-26 11:38:03 -0700168 const SkMatrix& viewMatrix,
169 const SkRRect& rrect,
bsalomon6663acf2016-05-10 09:14:17 -0700170 const GrStyle& style);
robertphillipsea461502015-05-26 11:38:03 -0700171
172 /**
Jim Van Verth3af1af92017-05-18 15:06:54 -0400173 * Use a fast method to render the ambient and spot shadows for a path.
174 * Will return false if not possible for the given path.
Jim Van Verthc5903412016-11-17 15:27:09 -0500175 *
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500176 * @param viewMatrix transformation matrix
Jim Van Verth3af1af92017-05-18 15:06:54 -0400177 * @param path the path to shadow
178 * @param rec parameters for shadow rendering
Jim Van Verthc5903412016-11-17 15:27:09 -0500179 */
Jim Van Verth3af1af92017-05-18 15:06:54 -0400180 bool drawFastShadow(const GrClip&,
Jim Van Verth3af1af92017-05-18 15:06:54 -0400181 const SkMatrix& viewMatrix,
182 const SkPath& path,
183 const SkDrawShadowRec& rec);
Jim Van Verthc5903412016-11-17 15:27:09 -0500184
185 /**
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500186 * Shortcut for filling a SkPath consisting of nested rrects using a paint. The result is
187 * undefined if outer does not contain inner.
robertphillips00095892016-02-29 13:50:40 -0800188 *
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500189 * @param paint describes how to color pixels.
190 * @param GrAA Controls whether rrects edges are antialiased
191 * @param viewMatrix transformation matrix
192 * @param outer the outer roundrect
193 * @param inner the inner roundrect
robertphillips00095892016-02-29 13:50:40 -0800194 */
195 void drawDRRect(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500196 GrPaint&&,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500197 GrAA,
robertphillips00095892016-02-29 13:50:40 -0800198 const SkMatrix& viewMatrix,
199 const SkRRect& outer,
200 const SkRRect& inner);
201
202 /**
robertphillipsea461502015-05-26 11:38:03 -0700203 * Draws a path.
204 *
205 * @param paint describes how to color pixels.
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500206 * @param GrAA Controls whether the path is antialiased.
robertphillipsea461502015-05-26 11:38:03 -0700207 * @param viewMatrix transformation matrix
208 * @param path the path to draw
bsalomon6663acf2016-05-10 09:14:17 -0700209 * @param style style to apply to the path.
robertphillipsea461502015-05-26 11:38:03 -0700210 */
robertphillips2e1e51f2015-10-15 08:01:48 -0700211 void drawPath(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500212 GrPaint&&,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500213 GrAA,
robertphillipsea461502015-05-26 11:38:03 -0700214 const SkMatrix& viewMatrix,
215 const SkPath&,
bsalomon6663acf2016-05-10 09:14:17 -0700216 const GrStyle& style);
robertphillipsea461502015-05-26 11:38:03 -0700217
218 /**
219 * Draws vertices with a paint.
220 *
Brian Osmanae0c50c2017-05-25 16:56:34 -0400221 * @param paint describes how to color pixels.
222 * @param viewMatrix transformation matrix
223 * @param vertices specifies the mesh to draw.
224 * @param overridePrimType primitive type to draw. If NULL, derive prim type from vertices.
robertphillipsea461502015-05-26 11:38:03 -0700225 */
robertphillips2e1e51f2015-10-15 08:01:48 -0700226 void drawVertices(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500227 GrPaint&& paint,
robertphillipsea461502015-05-26 11:38:03 -0700228 const SkMatrix& viewMatrix,
Brian Osmanae0c50c2017-05-25 16:56:34 -0400229 sk_sp<SkVertices> vertices,
230 GrPrimitiveType* overridePrimType = nullptr);
Brian Salomon199fb872017-02-06 09:41:10 -0500231
232 /**
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500233 * Draws textured sprites from an atlas with a paint. This currently does not support AA for the
234 * sprite rectangle edges.
jvanverth31ff7622015-08-07 10:09:28 -0700235 *
236 * @param paint describes how to color pixels.
237 * @param viewMatrix transformation matrix
238 * @param spriteCount number of sprites.
239 * @param xform array of compressed transformation data, required.
240 * @param texRect array of texture rectangles used to access the paint.
241 * @param colors optional array of per-sprite colors, supercedes
242 * the paint's color field.
243 */
robertphillips2e1e51f2015-10-15 08:01:48 -0700244 void drawAtlas(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500245 GrPaint&& paint,
jvanverth31ff7622015-08-07 10:09:28 -0700246 const SkMatrix& viewMatrix,
247 int spriteCount,
248 const SkRSXform xform[],
249 const SkRect texRect[],
250 const SkColor colors[]);
msarettcc319b92016-08-25 18:07:18 -0700251
252 /**
253 * Draws a region.
254 *
255 * @param paint describes how to color pixels
256 * @param viewMatrix transformation matrix
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500257 * @param aa should the rects of the region be antialiased.
msarettcc319b92016-08-25 18:07:18 -0700258 * @param region the region to be drawn
259 * @param style style to apply to the region
260 */
261 void drawRegion(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500262 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500263 GrAA aa,
msarettcc319b92016-08-25 18:07:18 -0700264 const SkMatrix& viewMatrix,
265 const SkRegion& region,
Stan Iliev73d8fd92017-08-02 15:36:24 -0400266 const GrStyle& style,
267 const GrUserStencilSettings* ss = nullptr);
msarettcc319b92016-08-25 18:07:18 -0700268
jvanverth31ff7622015-08-07 10:09:28 -0700269 /**
robertphillipsea461502015-05-26 11:38:03 -0700270 * Draws an oval.
271 *
272 * @param paint describes how to color pixels.
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500273 * @param GrAA Controls whether the oval is antialiased.
robertphillipsea461502015-05-26 11:38:03 -0700274 * @param viewMatrix transformation matrix
275 * @param oval the bounding rect of the oval.
bsalomon6663acf2016-05-10 09:14:17 -0700276 * @param style style to apply to the oval. Currently path effects are not allowed.
robertphillipsea461502015-05-26 11:38:03 -0700277 */
robertphillips2e1e51f2015-10-15 08:01:48 -0700278 void drawOval(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500279 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500280 GrAA,
robertphillipsea461502015-05-26 11:38:03 -0700281 const SkMatrix& viewMatrix,
282 const SkRect& oval,
bsalomon6663acf2016-05-10 09:14:17 -0700283 const GrStyle& style);
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500284 /**
285 * Draws a partial arc of an oval.
286 *
287 * @param paint describes how to color pixels.
Brian Salomon99504082016-12-09 15:51:31 -0500288 * @param GrGrAA Controls whether the arc is antialiased.
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500289 * @param viewMatrix transformation matrix.
290 * @param oval the bounding rect of the oval.
291 * @param startAngle starting angle in degrees.
292 * @param sweepAngle angle to sweep in degrees. Must be in (-360, 360)
293 * @param useCenter true means that the implied path begins at the oval center, connects as
294 * a line to the point indicated by the start contains the arc indicated by
295 * the sweep angle. If false the line beginning at the center point is
296 * omitted.
297 * @param style style to apply to the oval.
298 */
bsalomon4f3a0ca2016-08-22 13:14:26 -0700299 void drawArc(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500300 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500301 GrAA,
bsalomon4f3a0ca2016-08-22 13:14:26 -0700302 const SkMatrix& viewMatrix,
303 const SkRect& oval,
304 SkScalar startAngle,
305 SkScalar sweepAngle,
306 bool useCenter,
307 const GrStyle& style);
robertphillipsea461502015-05-26 11:38:03 -0700308
joshualitt33a5fce2015-11-18 13:28:51 -0800309 /**
bsalomon4f3a0ca2016-08-22 13:14:26 -0700310 * Draw the image as a set of rects, specified by |iter|.
joshualitt33a5fce2015-11-18 13:28:51 -0800311 */
msarett10e3d9b2016-08-18 15:46:03 -0700312 void drawImageLattice(const GrClip&,
Brian Salomon2a943df2018-05-04 13:43:19 -0400313 GrPaint&&,
msarett10e3d9b2016-08-18 15:46:03 -0700314 const SkMatrix& viewMatrix,
Brian Salomon2a943df2018-05-04 13:43:19 -0400315 sk_sp<GrTextureProxy>,
316 sk_sp<GrColorSpaceXform>,
317 GrSamplerState::Filter,
318 std::unique_ptr<SkLatticeIter>,
msarett10e3d9b2016-08-18 15:46:03 -0700319 const SkRect& dst);
robertphillipsea461502015-05-26 11:38:03 -0700320
robertphillips8c523e02016-07-26 07:41:00 -0700321 /**
322 * After this returns any pending surface IO will be issued to the backend 3D API and
323 * if the surface has MSAA it will be resolved.
324 */
Greg Daniel51316782017-08-02 15:10:09 +0000325 GrSemaphoresSubmitted prepareForExternalIO(int numSemaphores,
326 GrBackendSemaphore backendSemaphores[]);
Greg Daniela5cb7812017-06-16 09:45:32 -0400327
328 /**
329 * The next time this GrRenderTargetContext is flushed, the gpu will wait on the passed in
330 * semaphores before executing any commands.
331 */
Greg Danielc64ee462017-06-15 16:59:49 -0400332 bool waitOnSemaphores(int numSemaphores, const GrBackendSemaphore* waitSemaphores);
robertphillips8c523e02016-07-26 07:41:00 -0700333
Robert Phillips65a88fa2017-08-08 08:36:22 -0400334 void insertEventMarker(const SkString&);
335
Brian Salomon7c8460e2017-05-12 11:36:10 -0400336 GrFSAAType fsaaType() const { return fRenderTargetProxy->fsaaType(); }
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400337 const GrCaps* caps() const { return fContext->contextPriv().caps(); }
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400338 int width() const { return fRenderTargetProxy->width(); }
339 int height() const { return fRenderTargetProxy->height(); }
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400340 int numColorSamples() const { return fRenderTargetProxy->numColorSamples(); }
Brian Salomon50e66d42017-05-15 16:28:07 -0400341 int numStencilSamples() const { return fRenderTargetProxy->numStencilSamples(); }
robertphillipsca6eafc2016-05-17 09:57:46 -0700342 const SkSurfaceProps& surfaceProps() const { return fSurfaceProps; }
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400343 GrSurfaceOrigin origin() const { return fRenderTargetProxy->origin(); }
Greg Daniele252f082017-10-23 16:05:23 -0400344 GrMipMapped mipMapped() const;
robertphillips7bceedc2015-12-01 12:51:26 -0800345
robertphillips7761d612016-05-16 09:14:53 -0700346 bool wasAbandoned() const;
347
Robert Phillips65048132017-08-10 08:44:49 -0400348 void setNeedsStencil() { fRenderTargetProxy->setNeedsStencil(); }
349
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400350 GrRenderTarget* accessRenderTarget() {
351 // TODO: usage of this entry point needs to be reduced and potentially eliminated
352 // since it ends the deferral of the GrRenderTarget's allocation
Robert Phillips6be756b2018-01-16 15:07:54 -0500353 if (!fRenderTargetProxy->instantiate(fContext->contextPriv().resourceProvider())) {
Robert Phillipseee4d6e2017-06-05 09:26:07 -0400354 return nullptr;
355 }
356 return fRenderTargetProxy->priv().peekRenderTarget();
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400357 }
robertphillips6c7e3252016-04-27 10:47:51 -0700358
Robert Phillipsf200a902017-01-30 13:27:37 -0500359 GrSurfaceProxy* asSurfaceProxy() override { return fRenderTargetProxy.get(); }
360 const GrSurfaceProxy* asSurfaceProxy() const override { return fRenderTargetProxy.get(); }
361 sk_sp<GrSurfaceProxy> asSurfaceProxyRef() override { return fRenderTargetProxy; }
362
363 GrTextureProxy* asTextureProxy() override;
Greg Daniele252f082017-10-23 16:05:23 -0400364 const GrTextureProxy* asTextureProxy() const override;
Robert Phillipsf200a902017-01-30 13:27:37 -0500365 sk_sp<GrTextureProxy> asTextureProxyRef() override;
366
367 GrRenderTargetProxy* asRenderTargetProxy() override { return fRenderTargetProxy.get(); }
368 sk_sp<GrRenderTargetProxy> asRenderTargetProxyRef() override { return fRenderTargetProxy; }
Robert Phillipseaa86252016-11-08 13:49:39 +0000369
Robert Phillipsd46697a2017-01-25 12:10:37 -0500370 GrRenderTargetContext* asRenderTargetContext() override { return this; }
371
robertphillips391395d2016-03-02 09:26:36 -0800372 // Provides access to functions that aren't part of the public API.
Brian Osman693a5402016-10-27 15:13:22 -0400373 GrRenderTargetContextPriv priv();
374 const GrRenderTargetContextPriv priv() const;
joshualittf5883a62016-01-13 07:47:38 -0800375
Brian Salomonf18b1d82017-10-27 11:30:49 -0400376 GrTextUtils::Target* textTarget() { return fTextTarget.get(); }
377
Robert Phillipseaa86252016-11-08 13:49:39 +0000378 bool isWrapped_ForTesting() const;
379
joshualitt96880d92016-02-16 10:36:53 -0800380protected:
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400381 GrRenderTargetContext(GrContext*, GrDrawingManager*, sk_sp<GrRenderTargetProxy>,
Robert Phillips2c862492017-01-18 10:08:39 -0500382 sk_sp<SkColorSpace>, const SkSurfaceProps*, GrAuditTrail*,
Robert Phillips941d1442017-06-14 16:37:02 -0400383 GrSingleOwner*, bool managedOpList = true);
joshualitt96880d92016-02-16 10:36:53 -0800384
Robert Phillips2de8cfa2017-06-28 10:33:41 -0400385 SkDEBUGCODE(void validate() const override;)
joshualitt96880d92016-02-16 10:36:53 -0800386
robertphillipsea461502015-05-26 11:38:03 -0700387private:
Brian Salomonf18b1d82017-10-27 11:30:49 -0400388 class TextTarget;
389
Brian Salomonea26d6b2018-01-23 20:33:21 +0000390 inline GrAAType chooseAAType(GrAA aa, GrAllowMixedSamples allowMixedSamples) {
391 return GrChooseAAType(aa, this->fsaaType(), allowMixedSamples, *this->caps());
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500392 }
393
Brian Salomon649a3412017-03-09 13:50:43 -0500394 friend class GrAtlasTextBlob; // for access to add[Mesh]DrawOp
Brian Osman5d034742017-09-11 13:38:55 -0400395 friend class GrClipStackClip; // for access to getOpList
robertphillips55fdccc2016-06-06 06:16:20 -0700396
robertphillips77a2e522015-10-17 07:43:27 -0700397 friend class GrDrawingManager; // for ctor
Brian Osman11052242016-10-27 14:47:55 -0400398 friend class GrRenderTargetContextPriv;
robertphillips976f5f02016-06-03 10:59:20 -0700399
Brian Salomon42521e82016-12-07 16:44:58 -0500400 // All the path renderers currently make their own ops
Brian Salomon649a3412017-03-09 13:50:43 -0500401 friend class GrSoftwarePathRenderer; // for access to add[Mesh]DrawOp
402 friend class GrAAConvexPathRenderer; // for access to add[Mesh]DrawOp
403 friend class GrDashLinePathRenderer; // for access to add[Mesh]DrawOp
404 friend class GrAAHairLinePathRenderer; // for access to add[Mesh]DrawOp
405 friend class GrAALinearizingConvexPathRenderer; // for access to add[Mesh]DrawOp
Jim Van Verth83010462017-03-16 08:45:39 -0400406 friend class GrSmallPathRenderer; // for access to add[Mesh]DrawOp
Brian Salomon649a3412017-03-09 13:50:43 -0500407 friend class GrDefaultPathRenderer; // for access to add[Mesh]DrawOp
Brian Salomon649a3412017-03-09 13:50:43 -0500408 friend class GrStencilAndCoverPathRenderer; // for access to add[Mesh]DrawOp
409 friend class GrTessellatingPathRenderer; // for access to add[Mesh]DrawOp
Chris Dalton383a2ef2018-01-08 17:21:41 -0500410 friend class GrCCAtlas; // for access to addDrawOp
Chris Dalton1a325d22017-07-14 15:17:41 -0600411 friend class GrCoverageCountingPathRenderer; // for access to addDrawOp
Brian Salomon5d4cd9e2017-02-09 11:16:46 -0500412 // for a unit test
Brian Salomonaff329b2017-08-11 09:40:37 -0400413 friend void test_draw_op(GrRenderTargetContext*, std::unique_ptr<GrFragmentProcessor>,
414 sk_sp<GrTextureProxy>);
robertphillipsea461502015-05-26 11:38:03 -0700415
Chris Dalton344e9032017-12-11 15:42:09 -0700416 void internalClear(const GrFixedClip&, const GrColor, CanClearFullscreen);
csmartdalton29df7602016-08-31 11:55:52 -0700417
Brian Salomon82f44312017-01-11 13:42:54 -0500418 // Only consumes the GrPaint if successful.
robertphillips00095892016-02-29 13:50:40 -0800419 bool drawFilledDRRect(const GrClip& clip,
Brian Salomon82f44312017-01-11 13:42:54 -0500420 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500421 GrAA,
robertphillips00095892016-02-29 13:50:40 -0800422 const SkMatrix& viewMatrix,
423 const SkRRect& origOuter,
424 const SkRRect& origInner);
425
Brian Salomon82f44312017-01-11 13:42:54 -0500426 // Only consumes the GrPaint if successful.
robertphillips44302392016-07-08 14:43:03 -0700427 bool drawFilledRect(const GrClip& clip,
Brian Salomon82f44312017-01-11 13:42:54 -0500428 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500429 GrAA,
robertphillips44302392016-07-08 14:43:03 -0700430 const SkMatrix& viewMatrix,
431 const SkRect& rect,
432 const GrUserStencilSettings* ss);
433
Brian Salomon2fad74a2017-12-20 13:28:55 -0500434 void drawShapeUsingPathRenderer(const GrClip&, GrPaint&&, GrAA, const SkMatrix&,
435 const GrShape&);
robertphillipsea461502015-05-26 11:38:03 -0700436
Brian Salomon649a3412017-03-09 13:50:43 -0500437 // These perform processing specific to Gr[Mesh]DrawOp-derived ops before recording them into
438 // 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 -0600439 // dropped (e.g., due to clipping or being combined).
Brian Salomon54d212e2017-03-21 14:22:38 -0400440 uint32_t addDrawOp(const GrClip&, std::unique_ptr<GrDrawOp>);
robertphillips2334fb62015-06-17 05:43:33 -0700441
Robert Phillipsbf25d432017-04-07 10:08:53 -0400442 // Makes a copy of the proxy if it is necessary for the draw and places the texture that should
443 // be used by GrXferProcessor to access the destination color in 'result'. If the return
444 // value is false then a texture copy could not be made.
Robert Phillipsbb581ce2017-05-29 15:05:15 -0400445 bool SK_WARN_UNUSED_RESULT setupDstProxy(GrRenderTargetProxy*,
446 const GrClip&,
447 const SkRect& opBounds,
448 GrXferProcessor::DstProxy* result);
Brian Salomon467921e2017-03-06 16:17:12 -0500449
Robert Phillips2de8cfa2017-06-28 10:33:41 -0400450 GrRenderTargetOpList* getRTOpList();
451 GrOpList* getOpList() override;
robertphillipsa106c622015-10-16 09:07:06 -0700452
Brian Salomonf18b1d82017-10-27 11:30:49 -0400453 std::unique_ptr<GrTextUtils::Target> fTextTarget;
454 sk_sp<GrRenderTargetProxy> fRenderTargetProxy;
robertphillipsa106c622015-10-16 09:07:06 -0700455
Brian Osman11052242016-10-27 14:47:55 -0400456 // In MDB-mode the GrOpList can be closed by some other renderTargetContext that has picked
Robert Phillipsf2361d22016-10-25 14:20:06 -0400457 // it up. For this reason, the GrOpList should only ever be accessed via 'getOpList'.
Brian Salomonf18b1d82017-10-27 11:30:49 -0400458 sk_sp<GrRenderTargetOpList> fOpList;
robertphillips2334fb62015-06-17 05:43:33 -0700459
Brian Salomonf18b1d82017-10-27 11:30:49 -0400460 SkSurfaceProps fSurfaceProps;
461 bool fManagedOpList;
Robert Phillipse305cc1f2016-12-14 12:19:05 -0500462
463 typedef GrSurfaceContext INHERITED;
robertphillipsea461502015-05-26 11:38:03 -0700464};
465
466#endif