blob: 81684bd4125b17050f7e50f6b0e5d407287a388e [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
11#include "GrColor.h"
bsalomonfaf82032016-09-16 09:53:27 -070012#include "GrContext.h"
csmartdaltonecbc12b2016-06-08 10:08:43 -070013#include "GrPaint.h"
Brian Osman45580d32016-11-23 09:37:01 -050014#include "GrSurfaceContext.h"
Brian Salomon467921e2017-03-06 16:17:12 -050015#include "GrXferProcessor.h"
robertphillipsea461502015-05-26 11:38:03 -070016#include "SkRefCnt.h"
robertphillipsfcf78292015-06-19 11:49:52 -070017#include "SkSurfaceProps.h"
csmartdaltona7f29642016-07-07 08:49:11 -070018#include "../private/GrInstancedPipelineInfo.h"
Robert Phillipsc7635fa2016-10-28 13:25:24 -040019#include "../private/GrRenderTargetProxy.h"
robertphillipsea461502015-05-26 11:38:03 -070020
robertphillipsea461502015-05-26 11:38:03 -070021class GrClip;
robertphillips77a2e522015-10-17 07:43:27 -070022class GrDrawingManager;
Brian Salomon9afd3712016-12-01 10:59:09 -050023class GrDrawOp;
csmartdalton29df7602016-08-31 11:55:52 -070024class GrFixedClip;
robertphillipsea461502015-05-26 11:38:03 -070025class GrPipelineBuilder;
Brian Salomon649a3412017-03-09 13:50:43 -050026class GrMeshDrawOp;
robertphillipsea461502015-05-26 11:38:03 -070027class GrRenderTarget;
Brian Osman45580d32016-11-23 09:37:01 -050028class GrRenderTargetContextPriv;
Robert Phillipsf2361d22016-10-25 14:20:06 -040029class GrRenderTargetOpList;
bsalomon6663acf2016-05-10 09:14:17 -070030class GrStyle;
robertphillipsea461502015-05-26 11:38:03 -070031class GrSurface;
Robert Phillipseaa86252016-11-08 13:49:39 +000032class GrTextureProxy;
robertphillips44302392016-07-08 14:43:03 -070033struct GrUserStencilSettings;
robertphillips2334fb62015-06-17 05:43:33 -070034class SkDrawFilter;
robertphillipsea461502015-05-26 11:38:03 -070035struct SkIPoint;
36struct SkIRect;
msarett10e3d9b2016-08-18 15:46:03 -070037class SkLatticeIter;
robertphillipsea461502015-05-26 11:38:03 -070038class SkMatrix;
robertphillips2334fb62015-06-17 05:43:33 -070039class SkPaint;
robertphillipsea461502015-05-26 11:38:03 -070040class SkPath;
41struct SkPoint;
42struct SkRect;
Brian Osman45580d32016-11-23 09:37:01 -050043class SkRegion;
robertphillipsea461502015-05-26 11:38:03 -070044class SkRRect;
jvanverth31ff7622015-08-07 10:09:28 -070045struct SkRSXform;
robertphillips2334fb62015-06-17 05:43:33 -070046class SkTextBlob;
Brian Salomon199fb872017-02-06 09:41:10 -050047class SkVertices;
robertphillipsea461502015-05-26 11:38:03 -070048
Brian Osman45580d32016-11-23 09:37:01 -050049/**
50 * A helper object to orchestrate commands (draws, etc...) for GrSurfaces that are GrRenderTargets.
robertphillipsea461502015-05-26 11:38:03 -070051 */
Brian Osman45580d32016-11-23 09:37:01 -050052class SK_API GrRenderTargetContext : public GrSurfaceContext {
robertphillipsea461502015-05-26 11:38:03 -070053public:
Brian Osman11052242016-10-27 14:47:55 -040054 ~GrRenderTargetContext() override;
robertphillips2334fb62015-06-17 05:43:33 -070055
Robert Phillips26c90e02017-03-14 14:39:29 -040056 GrResourceProvider* resourceProvider() { return fContext->resourceProvider(); }
57
Brian Salomon6f1d36c2017-01-13 12:02:17 -050058 // We use SkPaint rather than GrPaint here for two reasons:
59 // * The SkPaint carries extra text settings. If these were extracted to a lighter object
60 // we could use GrPaint except that
61 // * SkPaint->GrPaint conversion depends upon whether the glyphs are color or grayscale and
62 // this can vary within a text run.
63 virtual void drawText(const GrClip&, const SkPaint&, const SkMatrix& viewMatrix,
Brian Salomon82f44312017-01-11 13:42:54 -050064 const char text[], size_t byteLength, SkScalar x, SkScalar y,
65 const SkIRect& clipBounds);
Brian Salomon6f1d36c2017-01-13 12:02:17 -050066 virtual void drawPosText(const GrClip&, const SkPaint&, const SkMatrix& viewMatrix,
Brian Salomon82f44312017-01-11 13:42:54 -050067 const char text[], size_t byteLength, const SkScalar pos[],
68 int scalarsPerPosition, const SkPoint& offset,
69 const SkIRect& clipBounds);
joshualitt96880d92016-02-16 10:36:53 -080070 virtual void drawTextBlob(const GrClip&, const SkPaint&,
71 const SkMatrix& viewMatrix, const SkTextBlob*,
72 SkScalar x, SkScalar y,
73 SkDrawFilter*, const SkIRect& clipBounds);
robertphillipsea461502015-05-26 11:38:03 -070074
robertphillipsea461502015-05-26 11:38:03 -070075 /**
76 * Provides a perfomance hint that the render target's contents are allowed
77 * to become undefined.
78 */
robertphillips2e1e51f2015-10-15 08:01:48 -070079 void discard();
robertphillipsea461502015-05-26 11:38:03 -070080
81 /**
82 * Clear the entire or rect of the render target, ignoring any clips.
robertphillipsea461502015-05-26 11:38:03 -070083 * @param rect the rect to clear or the whole thing if rect is NULL.
84 * @param color the color to clear to.
85 * @param canIgnoreRect allows partial clears to be converted to whole
86 * clears on platforms for which that is cheap
87 */
robertphillips2e1e51f2015-10-15 08:01:48 -070088 void clear(const SkIRect* rect, GrColor color, bool canIgnoreRect);
robertphillipsea461502015-05-26 11:38:03 -070089
90 /**
91 * Draw everywhere (respecting the clip) with the paint.
92 */
Brian Salomon82f44312017-01-11 13:42:54 -050093 void drawPaint(const GrClip&, GrPaint&&, const SkMatrix& viewMatrix);
robertphillipsea461502015-05-26 11:38:03 -070094
95 /**
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050096 * Draw the rect using a paint.
97 * @param paint describes how to color pixels.
98 * @param GrAA Controls whether rect is antialiased
99 * @param viewMatrix transformation matrix
100 * @param style The style to apply. Null means fill. Currently path effects are not
101 * allowed.
102 * The rects coords are used to access the paint (through texture matrix)
robertphillipsea461502015-05-26 11:38:03 -0700103 */
robertphillips2e1e51f2015-10-15 08:01:48 -0700104 void drawRect(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500105 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500106 GrAA,
robertphillipsea461502015-05-26 11:38:03 -0700107 const SkMatrix& viewMatrix,
108 const SkRect&,
Brian Salomon82f44312017-01-11 13:42:54 -0500109 const GrStyle* style = nullptr);
robertphillipsea461502015-05-26 11:38:03 -0700110
111 /**
bsalomona2e69fc2015-11-05 10:41:43 -0800112 * Maps a rectangle of shader coordinates to a rectangle and fills that rectangle.
robertphillipsea461502015-05-26 11:38:03 -0700113 *
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500114 * @param paint describes how to color pixels.
115 * @param GrAA Controls whether rect is antialiased
116 * @param viewMatrix transformation matrix which applies to rectToDraw
117 * @param rectToDraw the rectangle to draw
118 * @param localRect the rectangle of shader coordinates applied to rectToDraw
robertphillipsea461502015-05-26 11:38:03 -0700119 */
bsalomona2e69fc2015-11-05 10:41:43 -0800120 void fillRectToRect(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500121 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500122 GrAA,
bsalomona2e69fc2015-11-05 10:41:43 -0800123 const SkMatrix& viewMatrix,
124 const SkRect& rectToDraw,
125 const SkRect& localRect);
robertphillipsea461502015-05-26 11:38:03 -0700126
127 /**
bsalomona2e69fc2015-11-05 10:41:43 -0800128 * Fills a rect with a paint and a localMatrix.
robertphillipsea461502015-05-26 11:38:03 -0700129 */
bsalomona2e69fc2015-11-05 10:41:43 -0800130 void fillRectWithLocalMatrix(const GrClip& clip,
Brian Salomon82f44312017-01-11 13:42:54 -0500131 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500132 GrAA,
bsalomona2e69fc2015-11-05 10:41:43 -0800133 const SkMatrix& viewMatrix,
134 const SkRect& rect,
135 const SkMatrix& localMatrix);
robertphillipsea461502015-05-26 11:38:03 -0700136
137 /**
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500138 * Draw a roundrect using a paint.
robertphillipsea461502015-05-26 11:38:03 -0700139 *
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500140 * @param paint describes how to color pixels.
141 * @param GrAA Controls whether rrect is antialiased.
142 * @param viewMatrix transformation matrix
143 * @param rrect the roundrect to draw
144 * @param style style to apply to the rrect. Currently path effects are not allowed.
robertphillipsea461502015-05-26 11:38:03 -0700145 */
robertphillips2e1e51f2015-10-15 08:01:48 -0700146 void drawRRect(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500147 GrPaint&&,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500148 GrAA,
robertphillipsea461502015-05-26 11:38:03 -0700149 const SkMatrix& viewMatrix,
150 const SkRRect& rrect,
bsalomon6663acf2016-05-10 09:14:17 -0700151 const GrStyle& style);
robertphillipsea461502015-05-26 11:38:03 -0700152
153 /**
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500154 * Draw a roundrect using a paint and a shadow shader. This is separate from drawRRect
155 * because it uses different underlying geometry and GeometryProcessor
Jim Van Verthc5903412016-11-17 15:27:09 -0500156 *
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500157 * @param paint describes how to color pixels.
158 * @param viewMatrix transformation matrix
159 * @param rrect the roundrect to draw
160 * @param blurRadius amount of shadow blur to apply (in device space)
161 * @param style style to apply to the rrect. Currently path effects are not allowed.
Jim Van Verthc5903412016-11-17 15:27:09 -0500162 */
163 void drawShadowRRect(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500164 GrPaint&&,
Jim Van Verthc5903412016-11-17 15:27:09 -0500165 const SkMatrix& viewMatrix,
166 const SkRRect& rrect,
167 SkScalar blurRadius,
168 const GrStyle& style);
169
170 /**
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500171 * Shortcut for filling a SkPath consisting of nested rrects using a paint. The result is
172 * undefined if outer does not contain inner.
robertphillips00095892016-02-29 13:50:40 -0800173 *
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500174 * @param paint describes how to color pixels.
175 * @param GrAA Controls whether rrects edges are antialiased
176 * @param viewMatrix transformation matrix
177 * @param outer the outer roundrect
178 * @param inner the inner roundrect
robertphillips00095892016-02-29 13:50:40 -0800179 */
180 void drawDRRect(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500181 GrPaint&&,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500182 GrAA,
robertphillips00095892016-02-29 13:50:40 -0800183 const SkMatrix& viewMatrix,
184 const SkRRect& outer,
185 const SkRRect& inner);
186
187 /**
robertphillipsea461502015-05-26 11:38:03 -0700188 * Draws a path.
189 *
190 * @param paint describes how to color pixels.
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500191 * @param GrAA Controls whether the path is antialiased.
robertphillipsea461502015-05-26 11:38:03 -0700192 * @param viewMatrix transformation matrix
193 * @param path the path to draw
bsalomon6663acf2016-05-10 09:14:17 -0700194 * @param style style to apply to the path.
robertphillipsea461502015-05-26 11:38:03 -0700195 */
robertphillips2e1e51f2015-10-15 08:01:48 -0700196 void drawPath(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500197 GrPaint&&,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500198 GrAA,
robertphillipsea461502015-05-26 11:38:03 -0700199 const SkMatrix& viewMatrix,
200 const SkPath&,
bsalomon6663acf2016-05-10 09:14:17 -0700201 const GrStyle& style);
robertphillipsea461502015-05-26 11:38:03 -0700202
Brian Salomon3de0aee2017-01-29 09:34:17 -0500203 enum class ColorArrayType {
204 kPremulGrColor,
205 kSkColor,
206 };
robertphillipsea461502015-05-26 11:38:03 -0700207 /**
208 * Draws vertices with a paint.
209 *
210 * @param paint describes how to color pixels.
211 * @param viewMatrix transformation matrix
212 * @param primitiveType primitives type to draw.
213 * @param vertexCount number of vertices.
214 * @param positions array of vertex positions, required.
215 * @param texCoords optional array of texture coordinates used
216 * to access the paint.
217 * @param colors optional array of per-vertex colors, supercedes
218 * the paint's color field.
219 * @param indices optional array of indices. If NULL vertices
220 * are drawn non-indexed.
221 * @param indexCount if indices is non-null then this is the
222 * number of indices.
Brian Salomon3de0aee2017-01-29 09:34:17 -0500223 * @param ColorArrayType Determines how the color array should be interpreted.
robertphillipsea461502015-05-26 11:38:03 -0700224 */
robertphillips2e1e51f2015-10-15 08:01:48 -0700225 void drawVertices(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500226 GrPaint&& paint,
robertphillipsea461502015-05-26 11:38:03 -0700227 const SkMatrix& viewMatrix,
228 GrPrimitiveType primitiveType,
229 int vertexCount,
230 const SkPoint positions[],
231 const SkPoint texs[],
Brian Salomon3de0aee2017-01-29 09:34:17 -0500232 const uint32_t colors[],
robertphillipsea461502015-05-26 11:38:03 -0700233 const uint16_t indices[],
Brian Salomon3de0aee2017-01-29 09:34:17 -0500234 int indexCount,
235 ColorArrayType = ColorArrayType::kPremulGrColor);
robertphillipsea461502015-05-26 11:38:03 -0700236
237 /**
Brian Salomon199fb872017-02-06 09:41:10 -0500238 * Draws vertices with a paint.
239 *
240 * @param paint describes how to color pixels.
241 * @param viewMatrix transformation matrix
242 * @param veritces specifies the mesh to draw.
243 * @param flags A bitfield of options specified by SkCanvas::VerticesFlags.
244 */
245 void drawVertices(const GrClip&,
246 GrPaint&& paint,
247 const SkMatrix& viewMatrix,
248 sk_sp<SkVertices> vertices,
249 uint32_t flags);
250
251 /**
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500252 * Draws textured sprites from an atlas with a paint. This currently does not support AA for the
253 * sprite rectangle edges.
jvanverth31ff7622015-08-07 10:09:28 -0700254 *
255 * @param paint describes how to color pixels.
256 * @param viewMatrix transformation matrix
257 * @param spriteCount number of sprites.
258 * @param xform array of compressed transformation data, required.
259 * @param texRect array of texture rectangles used to access the paint.
260 * @param colors optional array of per-sprite colors, supercedes
261 * the paint's color field.
262 */
robertphillips2e1e51f2015-10-15 08:01:48 -0700263 void drawAtlas(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500264 GrPaint&& paint,
jvanverth31ff7622015-08-07 10:09:28 -0700265 const SkMatrix& viewMatrix,
266 int spriteCount,
267 const SkRSXform xform[],
268 const SkRect texRect[],
269 const SkColor colors[]);
msarettcc319b92016-08-25 18:07:18 -0700270
271 /**
272 * Draws a region.
273 *
274 * @param paint describes how to color pixels
275 * @param viewMatrix transformation matrix
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500276 * @param aa should the rects of the region be antialiased.
msarettcc319b92016-08-25 18:07:18 -0700277 * @param region the region to be drawn
278 * @param style style to apply to the region
279 */
280 void drawRegion(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500281 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500282 GrAA aa,
msarettcc319b92016-08-25 18:07:18 -0700283 const SkMatrix& viewMatrix,
284 const SkRegion& region,
285 const GrStyle& style);
286
jvanverth31ff7622015-08-07 10:09:28 -0700287 /**
robertphillipsea461502015-05-26 11:38:03 -0700288 * Draws an oval.
289 *
290 * @param paint describes how to color pixels.
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500291 * @param GrAA Controls whether the oval is antialiased.
robertphillipsea461502015-05-26 11:38:03 -0700292 * @param viewMatrix transformation matrix
293 * @param oval the bounding rect of the oval.
bsalomon6663acf2016-05-10 09:14:17 -0700294 * @param style style to apply to the oval. Currently path effects are not allowed.
robertphillipsea461502015-05-26 11:38:03 -0700295 */
robertphillips2e1e51f2015-10-15 08:01:48 -0700296 void drawOval(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500297 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500298 GrAA,
robertphillipsea461502015-05-26 11:38:03 -0700299 const SkMatrix& viewMatrix,
300 const SkRect& oval,
bsalomon6663acf2016-05-10 09:14:17 -0700301 const GrStyle& style);
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500302 /**
303 * Draws a partial arc of an oval.
304 *
305 * @param paint describes how to color pixels.
Brian Salomon99504082016-12-09 15:51:31 -0500306 * @param GrGrAA Controls whether the arc is antialiased.
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500307 * @param viewMatrix transformation matrix.
308 * @param oval the bounding rect of the oval.
309 * @param startAngle starting angle in degrees.
310 * @param sweepAngle angle to sweep in degrees. Must be in (-360, 360)
311 * @param useCenter true means that the implied path begins at the oval center, connects as
312 * a line to the point indicated by the start contains the arc indicated by
313 * the sweep angle. If false the line beginning at the center point is
314 * omitted.
315 * @param style style to apply to the oval.
316 */
bsalomon4f3a0ca2016-08-22 13:14:26 -0700317 void drawArc(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500318 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500319 GrAA,
bsalomon4f3a0ca2016-08-22 13:14:26 -0700320 const SkMatrix& viewMatrix,
321 const SkRect& oval,
322 SkScalar startAngle,
323 SkScalar sweepAngle,
324 bool useCenter,
325 const GrStyle& style);
robertphillipsea461502015-05-26 11:38:03 -0700326
joshualitt33a5fce2015-11-18 13:28:51 -0800327 /**
bsalomon4f3a0ca2016-08-22 13:14:26 -0700328 * Draw the image as a set of rects, specified by |iter|.
joshualitt33a5fce2015-11-18 13:28:51 -0800329 */
msarett10e3d9b2016-08-18 15:46:03 -0700330 void drawImageLattice(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500331 GrPaint&& paint,
msarett10e3d9b2016-08-18 15:46:03 -0700332 const SkMatrix& viewMatrix,
333 int imageWidth,
334 int imageHeight,
335 std::unique_ptr<SkLatticeIter> iter,
336 const SkRect& dst);
robertphillipsea461502015-05-26 11:38:03 -0700337
robertphillips8c523e02016-07-26 07:41:00 -0700338 /**
339 * After this returns any pending surface IO will be issued to the backend 3D API and
340 * if the surface has MSAA it will be resolved.
341 */
342 void prepareForExternalIO();
343
robertphillips976f5f02016-06-03 10:59:20 -0700344 bool isStencilBufferMultisampled() const {
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400345 return fRenderTargetProxy->isStencilBufferMultisampled();
robertphillips976f5f02016-06-03 10:59:20 -0700346 }
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400347 bool isUnifiedMultisampled() const { return fRenderTargetProxy->isUnifiedMultisampled(); }
348 bool hasMixedSamples() const { return fRenderTargetProxy->isMixedSampled(); }
robertphillips82ec6e52016-05-19 14:01:05 -0700349
bsalomonfaf82032016-09-16 09:53:27 -0700350 const GrCaps* caps() const { return fContext->caps(); }
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400351 const GrSurfaceDesc& desc() const { return fRenderTargetProxy->desc(); }
352 int width() const { return fRenderTargetProxy->width(); }
353 int height() const { return fRenderTargetProxy->height(); }
354 GrPixelConfig config() const { return fRenderTargetProxy->config(); }
355 int numColorSamples() const { return fRenderTargetProxy->numColorSamples(); }
robertphillipsca6eafc2016-05-17 09:57:46 -0700356 const SkSurfaceProps& surfaceProps() const { return fSurfaceProps; }
msarettc71a9b72016-09-16 11:01:27 -0700357 GrColorSpaceXform* getColorXformFromSRGB() const { return fColorXformFromSRGB.get(); }
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400358 GrSurfaceOrigin origin() const { return fRenderTargetProxy->origin(); }
robertphillips7bceedc2015-12-01 12:51:26 -0800359
robertphillips7761d612016-05-16 09:14:53 -0700360 bool wasAbandoned() const;
361
Robert Phillipseaa86252016-11-08 13:49:39 +0000362 GrRenderTarget* instantiate();
363
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400364 GrRenderTarget* accessRenderTarget() {
365 // TODO: usage of this entry point needs to be reduced and potentially eliminated
366 // since it ends the deferral of the GrRenderTarget's allocation
Brian Osman32342f02017-03-04 08:12:46 -0500367 return fRenderTargetProxy->instantiate(fContext->resourceProvider());
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400368 }
robertphillips6c7e3252016-04-27 10:47:51 -0700369
Robert Phillipsf200a902017-01-30 13:27:37 -0500370 GrSurfaceProxy* asSurfaceProxy() override { return fRenderTargetProxy.get(); }
371 const GrSurfaceProxy* asSurfaceProxy() const override { return fRenderTargetProxy.get(); }
372 sk_sp<GrSurfaceProxy> asSurfaceProxyRef() override { return fRenderTargetProxy; }
373
374 GrTextureProxy* asTextureProxy() override;
375 sk_sp<GrTextureProxy> asTextureProxyRef() override;
376
377 GrRenderTargetProxy* asRenderTargetProxy() override { return fRenderTargetProxy.get(); }
378 sk_sp<GrRenderTargetProxy> asRenderTargetProxyRef() override { return fRenderTargetProxy; }
Robert Phillipseaa86252016-11-08 13:49:39 +0000379
Robert Phillipsd46697a2017-01-25 12:10:37 -0500380 GrRenderTargetContext* asRenderTargetContext() override { return this; }
381
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400382 sk_sp<GrTexture> asTexture() {
Robert Phillipse60ad622016-11-17 10:22:48 -0500383 if (!this->accessRenderTarget()) {
384 return nullptr;
385 }
386
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400387 // TODO: usage of this entry point needs to be reduced and potentially eliminated
388 // since it ends the deferral of the GrRenderTarget's allocation
Robert Phillipsf200a902017-01-30 13:27:37 -0500389 // It's usage should migrate to asTextureProxyRef
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400390 return sk_ref_sp(this->accessRenderTarget()->asTexture());
391 }
robertphillips433625e2015-12-04 06:58:16 -0800392
robertphillips391395d2016-03-02 09:26:36 -0800393 // Provides access to functions that aren't part of the public API.
Brian Osman693a5402016-10-27 15:13:22 -0400394 GrRenderTargetContextPriv priv();
395 const GrRenderTargetContextPriv priv() const;
joshualittf5883a62016-01-13 07:47:38 -0800396
Robert Phillipseaa86252016-11-08 13:49:39 +0000397 bool isWrapped_ForTesting() const;
398
joshualitt96880d92016-02-16 10:36:53 -0800399protected:
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400400 GrRenderTargetContext(GrContext*, GrDrawingManager*, sk_sp<GrRenderTargetProxy>,
Robert Phillips2c862492017-01-18 10:08:39 -0500401 sk_sp<SkColorSpace>, const SkSurfaceProps*, GrAuditTrail*,
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400402 GrSingleOwner*);
joshualitt96880d92016-02-16 10:36:53 -0800403
joshualitt96880d92016-02-16 10:36:53 -0800404 SkDEBUGCODE(void validate() const;)
405
robertphillipsea461502015-05-26 11:38:03 -0700406private:
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500407 inline GrAAType decideAAType(GrAA aa, bool allowMixedSamples = false) {
408 if (GrAA::kNo == aa) {
409 return GrAAType::kNone;
410 }
411 if (this->isUnifiedMultisampled()) {
412 return GrAAType::kMSAA;
413 }
414 if (allowMixedSamples && this->isStencilBufferMultisampled()) {
415 return GrAAType::kMixedSamples;
416 }
417 return GrAAType::kCoverage;
418 }
419
Brian Salomon649a3412017-03-09 13:50:43 -0500420 friend class GrAtlasTextBlob; // for access to add[Mesh]DrawOp
421 friend class GrStencilAndCoverTextContext; // for access to add[Mesh]DrawOp
robertphillips55fdccc2016-06-06 06:16:20 -0700422
robertphillips77a2e522015-10-17 07:43:27 -0700423 friend class GrDrawingManager; // for ctor
Brian Osman11052242016-10-27 14:47:55 -0400424 friend class GrRenderTargetContextPriv;
Brian Salomon649a3412017-03-09 13:50:43 -0500425 friend class GrSWMaskHelper; // for access to add[Mesh]DrawOp
robertphillips976f5f02016-06-03 10:59:20 -0700426
Brian Salomon42521e82016-12-07 16:44:58 -0500427 // All the path renderers currently make their own ops
Brian Salomon649a3412017-03-09 13:50:43 -0500428 friend class GrSoftwarePathRenderer; // for access to add[Mesh]DrawOp
429 friend class GrAAConvexPathRenderer; // for access to add[Mesh]DrawOp
430 friend class GrDashLinePathRenderer; // for access to add[Mesh]DrawOp
431 friend class GrAAHairLinePathRenderer; // for access to add[Mesh]DrawOp
432 friend class GrAALinearizingConvexPathRenderer; // for access to add[Mesh]DrawOp
433 friend class GrAADistanceFieldPathRenderer; // for access to add[Mesh]DrawOp
434 friend class GrDefaultPathRenderer; // for access to add[Mesh]DrawOp
435 friend class GrMSAAPathRenderer; // for access to add[Mesh]DrawOp
436 friend class GrStencilAndCoverPathRenderer; // for access to add[Mesh]DrawOp
437 friend class GrTessellatingPathRenderer; // for access to add[Mesh]DrawOp
Brian Salomon5d4cd9e2017-02-09 11:16:46 -0500438 // for a unit test
Robert Phillips296b1cc2017-03-15 10:42:12 -0400439 friend void test_draw_op(GrRenderTargetContext*,
Robert Phillips30f9bc62017-02-22 15:28:38 -0500440 sk_sp<GrFragmentProcessor>, sk_sp<GrTextureProxy>);
robertphillipsea461502015-05-26 11:38:03 -0700441
csmartdalton29df7602016-08-31 11:55:52 -0700442 void internalClear(const GrFixedClip&, const GrColor, bool canIgnoreClip);
443
Brian Salomon82f44312017-01-11 13:42:54 -0500444 // Only consumes the GrPaint if successful.
robertphillips00095892016-02-29 13:50:40 -0800445 bool drawFilledDRRect(const GrClip& clip,
Brian Salomon82f44312017-01-11 13:42:54 -0500446 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500447 GrAA,
robertphillips00095892016-02-29 13:50:40 -0800448 const SkMatrix& viewMatrix,
449 const SkRRect& origOuter,
450 const SkRRect& origInner);
451
Brian Salomon82f44312017-01-11 13:42:54 -0500452 // Only consumes the GrPaint if successful.
robertphillips44302392016-07-08 14:43:03 -0700453 bool drawFilledRect(const GrClip& clip,
Brian Salomon82f44312017-01-11 13:42:54 -0500454 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500455 GrAA,
robertphillips44302392016-07-08 14:43:03 -0700456 const SkMatrix& viewMatrix,
457 const SkRect& rect,
458 const GrUserStencilSettings* ss);
459
460 void drawNonAAFilledRect(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500461 GrPaint&&,
robertphillips44302392016-07-08 14:43:03 -0700462 const SkMatrix& viewMatrix,
463 const SkRect& rect,
464 const SkRect* localRect,
465 const SkMatrix* localMatrix,
csmartdalton34ee0c92016-07-27 13:22:27 -0700466 const GrUserStencilSettings* ss,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500467 GrAAType hwOrNoneAAType);
robertphillips391395d2016-03-02 09:26:36 -0800468
Brian Salomon82f44312017-01-11 13:42:54 -0500469 void internalDrawPath(
470 const GrClip&, GrPaint&&, GrAA, const SkMatrix&, const SkPath&, const GrStyle&);
robertphillipsea461502015-05-26 11:38:03 -0700471
Robert Phillipse2f7d182016-12-15 09:23:05 -0500472 bool onCopy(GrSurfaceProxy* src, const SkIRect& srcRect, const SkIPoint& dstPoint) override;
Robert Phillips2c862492017-01-18 10:08:39 -0500473 bool onReadPixels(const SkImageInfo& dstInfo, void* dstBuffer,
Robert Phillipsb726d582017-03-09 16:36:32 -0500474 size_t dstRowBytes, int x, int y, uint32_t flags) override;
Robert Phillips2c862492017-01-18 10:08:39 -0500475 bool onWritePixels(const SkImageInfo& srcInfo, const void* srcBuffer,
Robert Phillips30f9bc62017-02-22 15:28:38 -0500476 size_t srcRowBytes, int x, int y, uint32_t flags) override;
Robert Phillipse2f7d182016-12-15 09:23:05 -0500477
Brian Salomon649a3412017-03-09 13:50:43 -0500478 // These perform processing specific to Gr[Mesh]DrawOp-derived ops before recording them into
479 // the op list. They return the id of the opList to which the op was added, or 0, if it was
Robert Phillipsc0138922017-03-08 11:50:55 -0500480 // dropped (e.g., due to clipping).
481 uint32_t addDrawOp(const GrPipelineBuilder&, const GrClip&, std::unique_ptr<GrDrawOp>);
Brian Salomon649a3412017-03-09 13:50:43 -0500482 uint32_t addMeshDrawOp(const GrPipelineBuilder&, const GrClip&,
483 std::unique_ptr<GrMeshDrawOp> op);
robertphillips2334fb62015-06-17 05:43:33 -0700484
Brian Salomon467921e2017-03-06 16:17:12 -0500485 // Makes a copy of the dst if it is necessary for the draw and returns the texture that should
486 // be used by GrXferProcessor to access the destination color. If the texture is nullptr then
487 // a texture copy could not be made.
488 void setupDstTexture(GrRenderTarget*, const GrClip&, const SkRect& opBounds,
489 GrXferProcessor::DstTexture*);
490
491
Robert Phillipsf2361d22016-10-25 14:20:06 -0400492 GrRenderTargetOpList* getOpList();
robertphillipsa106c622015-10-16 09:07:06 -0700493
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400494 sk_sp<GrRenderTargetProxy> fRenderTargetProxy;
robertphillipsa106c622015-10-16 09:07:06 -0700495
Brian Osman11052242016-10-27 14:47:55 -0400496 // In MDB-mode the GrOpList can be closed by some other renderTargetContext that has picked
Robert Phillipsf2361d22016-10-25 14:20:06 -0400497 // it up. For this reason, the GrOpList should only ever be accessed via 'getOpList'.
498 GrRenderTargetOpList* fOpList;
msarettc71a9b72016-09-16 11:01:27 -0700499 GrInstancedPipelineInfo fInstancedPipelineInfo;
robertphillips2334fb62015-06-17 05:43:33 -0700500
msarettc71a9b72016-09-16 11:01:27 -0700501 sk_sp<GrColorSpaceXform> fColorXformFromSRGB;
502 SkSurfaceProps fSurfaceProps;
Robert Phillipse305cc1f2016-12-14 12:19:05 -0500503
504 typedef GrSurfaceContext INHERITED;
robertphillipsea461502015-05-26 11:38:03 -0700505};
506
507#endif