blob: aab105087fb504fc7370c5b53f1ceba98943cfea [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"
robertphillipsea461502015-05-26 11:38:03 -070015#include "SkRefCnt.h"
robertphillipsfcf78292015-06-19 11:49:52 -070016#include "SkSurfaceProps.h"
csmartdaltona7f29642016-07-07 08:49:11 -070017#include "../private/GrInstancedPipelineInfo.h"
Robert Phillipsc7635fa2016-10-28 13:25:24 -040018#include "../private/GrRenderTargetProxy.h"
robertphillipsea461502015-05-26 11:38:03 -070019
robertphillipsea461502015-05-26 11:38:03 -070020class GrClip;
robertphillips77a2e522015-10-17 07:43:27 -070021class GrDrawingManager;
Brian Salomon9afd3712016-12-01 10:59:09 -050022class GrDrawOp;
csmartdalton29df7602016-08-31 11:55:52 -070023class GrFixedClip;
robertphillipsea461502015-05-26 11:38:03 -070024class GrPipelineBuilder;
25class GrRenderTarget;
Brian Osman45580d32016-11-23 09:37:01 -050026class GrRenderTargetContextPriv;
Robert Phillipsf2361d22016-10-25 14:20:06 -040027class GrRenderTargetOpList;
bsalomon6663acf2016-05-10 09:14:17 -070028class GrStyle;
robertphillipsea461502015-05-26 11:38:03 -070029class GrSurface;
Robert Phillipseaa86252016-11-08 13:49:39 +000030class GrTextureProxy;
robertphillips44302392016-07-08 14:43:03 -070031struct GrUserStencilSettings;
robertphillips2334fb62015-06-17 05:43:33 -070032class SkDrawFilter;
robertphillipsea461502015-05-26 11:38:03 -070033struct SkIPoint;
34struct SkIRect;
msarett10e3d9b2016-08-18 15:46:03 -070035class SkLatticeIter;
robertphillipsea461502015-05-26 11:38:03 -070036class SkMatrix;
robertphillips2334fb62015-06-17 05:43:33 -070037class SkPaint;
robertphillipsea461502015-05-26 11:38:03 -070038class SkPath;
39struct SkPoint;
40struct SkRect;
Brian Osman45580d32016-11-23 09:37:01 -050041class SkRegion;
robertphillipsea461502015-05-26 11:38:03 -070042class SkRRect;
jvanverth31ff7622015-08-07 10:09:28 -070043struct SkRSXform;
robertphillips2334fb62015-06-17 05:43:33 -070044class SkTextBlob;
robertphillipsea461502015-05-26 11:38:03 -070045
Brian Osman45580d32016-11-23 09:37:01 -050046/**
47 * A helper object to orchestrate commands (draws, etc...) for GrSurfaces that are GrRenderTargets.
robertphillipsea461502015-05-26 11:38:03 -070048 */
Brian Osman45580d32016-11-23 09:37:01 -050049class SK_API GrRenderTargetContext : public GrSurfaceContext {
robertphillipsea461502015-05-26 11:38:03 -070050public:
Brian Osman11052242016-10-27 14:47:55 -040051 ~GrRenderTargetContext() override;
robertphillips2334fb62015-06-17 05:43:33 -070052
Brian Salomon6f1d36c2017-01-13 12:02:17 -050053 // We use SkPaint rather than GrPaint here for two reasons:
54 // * The SkPaint carries extra text settings. If these were extracted to a lighter object
55 // we could use GrPaint except that
56 // * SkPaint->GrPaint conversion depends upon whether the glyphs are color or grayscale and
57 // this can vary within a text run.
58 virtual void drawText(const GrClip&, const SkPaint&, const SkMatrix& viewMatrix,
Brian Salomon82f44312017-01-11 13:42:54 -050059 const char text[], size_t byteLength, SkScalar x, SkScalar y,
60 const SkIRect& clipBounds);
Brian Salomon6f1d36c2017-01-13 12:02:17 -050061 virtual void drawPosText(const GrClip&, const SkPaint&, const SkMatrix& viewMatrix,
Brian Salomon82f44312017-01-11 13:42:54 -050062 const char text[], size_t byteLength, const SkScalar pos[],
63 int scalarsPerPosition, const SkPoint& offset,
64 const SkIRect& clipBounds);
joshualitt96880d92016-02-16 10:36:53 -080065 virtual void drawTextBlob(const GrClip&, const SkPaint&,
66 const SkMatrix& viewMatrix, const SkTextBlob*,
67 SkScalar x, SkScalar y,
68 SkDrawFilter*, const SkIRect& clipBounds);
robertphillipsea461502015-05-26 11:38:03 -070069
robertphillipsea461502015-05-26 11:38:03 -070070 /**
71 * Provides a perfomance hint that the render target's contents are allowed
72 * to become undefined.
73 */
robertphillips2e1e51f2015-10-15 08:01:48 -070074 void discard();
robertphillipsea461502015-05-26 11:38:03 -070075
76 /**
77 * Clear the entire or rect of the render target, ignoring any clips.
robertphillipsea461502015-05-26 11:38:03 -070078 * @param rect the rect to clear or the whole thing if rect is NULL.
79 * @param color the color to clear to.
80 * @param canIgnoreRect allows partial clears to be converted to whole
81 * clears on platforms for which that is cheap
82 */
robertphillips2e1e51f2015-10-15 08:01:48 -070083 void clear(const SkIRect* rect, GrColor color, bool canIgnoreRect);
robertphillipsea461502015-05-26 11:38:03 -070084
85 /**
86 * Draw everywhere (respecting the clip) with the paint.
87 */
Brian Salomon82f44312017-01-11 13:42:54 -050088 void drawPaint(const GrClip&, GrPaint&&, const SkMatrix& viewMatrix);
robertphillipsea461502015-05-26 11:38:03 -070089
90 /**
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050091 * Draw the rect using a paint.
92 * @param paint describes how to color pixels.
93 * @param GrAA Controls whether rect is antialiased
94 * @param viewMatrix transformation matrix
95 * @param style The style to apply. Null means fill. Currently path effects are not
96 * allowed.
97 * The rects coords are used to access the paint (through texture matrix)
robertphillipsea461502015-05-26 11:38:03 -070098 */
robertphillips2e1e51f2015-10-15 08:01:48 -070099 void drawRect(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500100 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500101 GrAA,
robertphillipsea461502015-05-26 11:38:03 -0700102 const SkMatrix& viewMatrix,
103 const SkRect&,
Brian Salomon82f44312017-01-11 13:42:54 -0500104 const GrStyle* style = nullptr);
robertphillipsea461502015-05-26 11:38:03 -0700105
106 /**
bsalomona2e69fc2015-11-05 10:41:43 -0800107 * Maps a rectangle of shader coordinates to a rectangle and fills that rectangle.
robertphillipsea461502015-05-26 11:38:03 -0700108 *
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500109 * @param paint describes how to color pixels.
110 * @param GrAA Controls whether rect is antialiased
111 * @param viewMatrix transformation matrix which applies to rectToDraw
112 * @param rectToDraw the rectangle to draw
113 * @param localRect the rectangle of shader coordinates applied to rectToDraw
robertphillipsea461502015-05-26 11:38:03 -0700114 */
bsalomona2e69fc2015-11-05 10:41:43 -0800115 void fillRectToRect(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500116 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500117 GrAA,
bsalomona2e69fc2015-11-05 10:41:43 -0800118 const SkMatrix& viewMatrix,
119 const SkRect& rectToDraw,
120 const SkRect& localRect);
robertphillipsea461502015-05-26 11:38:03 -0700121
122 /**
bsalomona2e69fc2015-11-05 10:41:43 -0800123 * Fills a rect with a paint and a localMatrix.
robertphillipsea461502015-05-26 11:38:03 -0700124 */
bsalomona2e69fc2015-11-05 10:41:43 -0800125 void fillRectWithLocalMatrix(const GrClip& clip,
Brian Salomon82f44312017-01-11 13:42:54 -0500126 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500127 GrAA,
bsalomona2e69fc2015-11-05 10:41:43 -0800128 const SkMatrix& viewMatrix,
129 const SkRect& rect,
130 const SkMatrix& localMatrix);
robertphillipsea461502015-05-26 11:38:03 -0700131
132 /**
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500133 * Draw a roundrect using a paint.
robertphillipsea461502015-05-26 11:38:03 -0700134 *
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500135 * @param paint describes how to color pixels.
136 * @param GrAA Controls whether rrect is antialiased.
137 * @param viewMatrix transformation matrix
138 * @param rrect the roundrect to draw
139 * @param style style to apply to the rrect. Currently path effects are not allowed.
robertphillipsea461502015-05-26 11:38:03 -0700140 */
robertphillips2e1e51f2015-10-15 08:01:48 -0700141 void drawRRect(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500142 GrPaint&&,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500143 GrAA,
robertphillipsea461502015-05-26 11:38:03 -0700144 const SkMatrix& viewMatrix,
145 const SkRRect& rrect,
bsalomon6663acf2016-05-10 09:14:17 -0700146 const GrStyle& style);
robertphillipsea461502015-05-26 11:38:03 -0700147
148 /**
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500149 * Draw a roundrect using a paint and a shadow shader. This is separate from drawRRect
150 * because it uses different underlying geometry and GeometryProcessor
Jim Van Verthc5903412016-11-17 15:27:09 -0500151 *
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500152 * @param paint describes how to color pixels.
153 * @param viewMatrix transformation matrix
154 * @param rrect the roundrect to draw
155 * @param blurRadius amount of shadow blur to apply (in device space)
156 * @param style style to apply to the rrect. Currently path effects are not allowed.
Jim Van Verthc5903412016-11-17 15:27:09 -0500157 */
158 void drawShadowRRect(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500159 GrPaint&&,
Jim Van Verthc5903412016-11-17 15:27:09 -0500160 const SkMatrix& viewMatrix,
161 const SkRRect& rrect,
162 SkScalar blurRadius,
163 const GrStyle& style);
164
165 /**
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500166 * Shortcut for filling a SkPath consisting of nested rrects using a paint. The result is
167 * undefined if outer does not contain inner.
robertphillips00095892016-02-29 13:50:40 -0800168 *
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500169 * @param paint describes how to color pixels.
170 * @param GrAA Controls whether rrects edges are antialiased
171 * @param viewMatrix transformation matrix
172 * @param outer the outer roundrect
173 * @param inner the inner roundrect
robertphillips00095892016-02-29 13:50:40 -0800174 */
175 void drawDRRect(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500176 GrPaint&&,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500177 GrAA,
robertphillips00095892016-02-29 13:50:40 -0800178 const SkMatrix& viewMatrix,
179 const SkRRect& outer,
180 const SkRRect& inner);
181
182 /**
robertphillipsea461502015-05-26 11:38:03 -0700183 * Draws a path.
184 *
185 * @param paint describes how to color pixels.
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500186 * @param GrAA Controls whether the path is antialiased.
robertphillipsea461502015-05-26 11:38:03 -0700187 * @param viewMatrix transformation matrix
188 * @param path the path to draw
bsalomon6663acf2016-05-10 09:14:17 -0700189 * @param style style to apply to the path.
robertphillipsea461502015-05-26 11:38:03 -0700190 */
robertphillips2e1e51f2015-10-15 08:01:48 -0700191 void drawPath(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500192 GrPaint&&,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500193 GrAA,
robertphillipsea461502015-05-26 11:38:03 -0700194 const SkMatrix& viewMatrix,
195 const SkPath&,
bsalomon6663acf2016-05-10 09:14:17 -0700196 const GrStyle& style);
robertphillipsea461502015-05-26 11:38:03 -0700197
198 /**
199 * Draws vertices with a paint.
200 *
201 * @param paint describes how to color pixels.
202 * @param viewMatrix transformation matrix
203 * @param primitiveType primitives type to draw.
204 * @param vertexCount number of vertices.
205 * @param positions array of vertex positions, required.
206 * @param texCoords optional array of texture coordinates used
207 * to access the paint.
208 * @param colors optional array of per-vertex colors, supercedes
209 * the paint's color field.
210 * @param indices optional array of indices. If NULL vertices
211 * are drawn non-indexed.
212 * @param indexCount if indices is non-null then this is the
213 * number of indices.
214 */
robertphillips2e1e51f2015-10-15 08:01:48 -0700215 void drawVertices(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500216 GrPaint&& paint,
robertphillipsea461502015-05-26 11:38:03 -0700217 const SkMatrix& viewMatrix,
218 GrPrimitiveType primitiveType,
219 int vertexCount,
220 const SkPoint positions[],
221 const SkPoint texs[],
222 const GrColor colors[],
223 const uint16_t indices[],
224 int indexCount);
225
226 /**
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500227 * Draws textured sprites from an atlas with a paint. This currently does not support AA for the
228 * sprite rectangle edges.
jvanverth31ff7622015-08-07 10:09:28 -0700229 *
230 * @param paint describes how to color pixels.
231 * @param viewMatrix transformation matrix
232 * @param spriteCount number of sprites.
233 * @param xform array of compressed transformation data, required.
234 * @param texRect array of texture rectangles used to access the paint.
235 * @param colors optional array of per-sprite colors, supercedes
236 * the paint's color field.
237 */
robertphillips2e1e51f2015-10-15 08:01:48 -0700238 void drawAtlas(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500239 GrPaint&& paint,
jvanverth31ff7622015-08-07 10:09:28 -0700240 const SkMatrix& viewMatrix,
241 int spriteCount,
242 const SkRSXform xform[],
243 const SkRect texRect[],
244 const SkColor colors[]);
msarettcc319b92016-08-25 18:07:18 -0700245
246 /**
247 * Draws a region.
248 *
249 * @param paint describes how to color pixels
250 * @param viewMatrix transformation matrix
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500251 * @param aa should the rects of the region be antialiased.
msarettcc319b92016-08-25 18:07:18 -0700252 * @param region the region to be drawn
253 * @param style style to apply to the region
254 */
255 void drawRegion(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500256 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500257 GrAA aa,
msarettcc319b92016-08-25 18:07:18 -0700258 const SkMatrix& viewMatrix,
259 const SkRegion& region,
260 const GrStyle& style);
261
jvanverth31ff7622015-08-07 10:09:28 -0700262 /**
robertphillipsea461502015-05-26 11:38:03 -0700263 * Draws an oval.
264 *
265 * @param paint describes how to color pixels.
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500266 * @param GrAA Controls whether the oval is antialiased.
robertphillipsea461502015-05-26 11:38:03 -0700267 * @param viewMatrix transformation matrix
268 * @param oval the bounding rect of the oval.
bsalomon6663acf2016-05-10 09:14:17 -0700269 * @param style style to apply to the oval. Currently path effects are not allowed.
robertphillipsea461502015-05-26 11:38:03 -0700270 */
robertphillips2e1e51f2015-10-15 08:01:48 -0700271 void drawOval(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500272 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500273 GrAA,
robertphillipsea461502015-05-26 11:38:03 -0700274 const SkMatrix& viewMatrix,
275 const SkRect& oval,
bsalomon6663acf2016-05-10 09:14:17 -0700276 const GrStyle& style);
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500277 /**
278 * Draws a partial arc of an oval.
279 *
280 * @param paint describes how to color pixels.
Brian Salomon99504082016-12-09 15:51:31 -0500281 * @param GrGrAA Controls whether the arc is antialiased.
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500282 * @param viewMatrix transformation matrix.
283 * @param oval the bounding rect of the oval.
284 * @param startAngle starting angle in degrees.
285 * @param sweepAngle angle to sweep in degrees. Must be in (-360, 360)
286 * @param useCenter true means that the implied path begins at the oval center, connects as
287 * a line to the point indicated by the start contains the arc indicated by
288 * the sweep angle. If false the line beginning at the center point is
289 * omitted.
290 * @param style style to apply to the oval.
291 */
bsalomon4f3a0ca2016-08-22 13:14:26 -0700292 void drawArc(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500293 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500294 GrAA,
bsalomon4f3a0ca2016-08-22 13:14:26 -0700295 const SkMatrix& viewMatrix,
296 const SkRect& oval,
297 SkScalar startAngle,
298 SkScalar sweepAngle,
299 bool useCenter,
300 const GrStyle& style);
robertphillipsea461502015-05-26 11:38:03 -0700301
joshualitt33a5fce2015-11-18 13:28:51 -0800302 /**
bsalomon4f3a0ca2016-08-22 13:14:26 -0700303 * Draw the image as a set of rects, specified by |iter|.
joshualitt33a5fce2015-11-18 13:28:51 -0800304 */
msarett10e3d9b2016-08-18 15:46:03 -0700305 void drawImageLattice(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500306 GrPaint&& paint,
msarett10e3d9b2016-08-18 15:46:03 -0700307 const SkMatrix& viewMatrix,
308 int imageWidth,
309 int imageHeight,
310 std::unique_ptr<SkLatticeIter> iter,
311 const SkRect& dst);
robertphillipsea461502015-05-26 11:38:03 -0700312
robertphillips8c523e02016-07-26 07:41:00 -0700313 /**
314 * After this returns any pending surface IO will be issued to the backend 3D API and
315 * if the surface has MSAA it will be resolved.
316 */
317 void prepareForExternalIO();
318
robertphillips976f5f02016-06-03 10:59:20 -0700319 bool isStencilBufferMultisampled() const {
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400320 return fRenderTargetProxy->isStencilBufferMultisampled();
robertphillips976f5f02016-06-03 10:59:20 -0700321 }
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400322 bool isUnifiedMultisampled() const { return fRenderTargetProxy->isUnifiedMultisampled(); }
323 bool hasMixedSamples() const { return fRenderTargetProxy->isMixedSampled(); }
robertphillips82ec6e52016-05-19 14:01:05 -0700324
bsalomonfaf82032016-09-16 09:53:27 -0700325 const GrCaps* caps() const { return fContext->caps(); }
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400326 const GrSurfaceDesc& desc() const { return fRenderTargetProxy->desc(); }
327 int width() const { return fRenderTargetProxy->width(); }
328 int height() const { return fRenderTargetProxy->height(); }
329 GrPixelConfig config() const { return fRenderTargetProxy->config(); }
330 int numColorSamples() const { return fRenderTargetProxy->numColorSamples(); }
robertphillipsca6eafc2016-05-17 09:57:46 -0700331 const SkSurfaceProps& surfaceProps() const { return fSurfaceProps; }
msarettc71a9b72016-09-16 11:01:27 -0700332 GrColorSpaceXform* getColorXformFromSRGB() const { return fColorXformFromSRGB.get(); }
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400333 GrSurfaceOrigin origin() const { return fRenderTargetProxy->origin(); }
robertphillips7bceedc2015-12-01 12:51:26 -0800334
robertphillips7761d612016-05-16 09:14:53 -0700335 bool wasAbandoned() const;
336
Robert Phillipseaa86252016-11-08 13:49:39 +0000337 GrRenderTarget* instantiate();
338
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400339 GrRenderTarget* accessRenderTarget() {
340 // TODO: usage of this entry point needs to be reduced and potentially eliminated
341 // since it ends the deferral of the GrRenderTarget's allocation
342 return fRenderTargetProxy->instantiate(fContext->textureProvider());
343 }
robertphillips6c7e3252016-04-27 10:47:51 -0700344
Robert Phillips27341362016-12-14 08:46:47 -0500345 GrSurfaceProxy* asDeferredSurface() override { return fRenderTargetProxy.get(); }
346 GrTextureProxy* asDeferredTexture() override;
347 GrRenderTargetProxy* asDeferredRenderTarget() override { return fRenderTargetProxy.get(); }
Robert Phillipseaa86252016-11-08 13:49:39 +0000348
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400349 sk_sp<GrTexture> asTexture() {
Robert Phillipse60ad622016-11-17 10:22:48 -0500350 if (!this->accessRenderTarget()) {
351 return nullptr;
352 }
353
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400354 // TODO: usage of this entry point needs to be reduced and potentially eliminated
355 // since it ends the deferral of the GrRenderTarget's allocation
Robert Phillipseaa86252016-11-08 13:49:39 +0000356 // It's usage should migrate to asDeferredTexture
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400357 return sk_ref_sp(this->accessRenderTarget()->asTexture());
358 }
robertphillips433625e2015-12-04 06:58:16 -0800359
robertphillips391395d2016-03-02 09:26:36 -0800360 // Provides access to functions that aren't part of the public API.
Brian Osman693a5402016-10-27 15:13:22 -0400361 GrRenderTargetContextPriv priv();
362 const GrRenderTargetContextPriv priv() const;
joshualittf5883a62016-01-13 07:47:38 -0800363
Robert Phillipseaa86252016-11-08 13:49:39 +0000364 bool isWrapped_ForTesting() const;
365
joshualitt96880d92016-02-16 10:36:53 -0800366protected:
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400367 GrRenderTargetContext(GrContext*, GrDrawingManager*, sk_sp<GrRenderTargetProxy>,
Robert Phillips2c862492017-01-18 10:08:39 -0500368 sk_sp<SkColorSpace>, const SkSurfaceProps*, GrAuditTrail*,
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400369 GrSingleOwner*);
joshualitt96880d92016-02-16 10:36:53 -0800370
371 GrDrawingManager* drawingManager() { return fDrawingManager; }
robertphillipsca6eafc2016-05-17 09:57:46 -0700372
joshualitt96880d92016-02-16 10:36:53 -0800373 SkDEBUGCODE(void validate() const;)
374
robertphillipsea461502015-05-26 11:38:03 -0700375private:
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500376 inline GrAAType decideAAType(GrAA aa, bool allowMixedSamples = false) {
377 if (GrAA::kNo == aa) {
378 return GrAAType::kNone;
379 }
380 if (this->isUnifiedMultisampled()) {
381 return GrAAType::kMSAA;
382 }
383 if (allowMixedSamples && this->isStencilBufferMultisampled()) {
384 return GrAAType::kMixedSamples;
385 }
386 return GrAAType::kCoverage;
387 }
388
Brian Salomon42521e82016-12-07 16:44:58 -0500389 friend class GrAtlasTextBlob; // for access to addDrawOp
390 friend class GrStencilAndCoverTextContext; // for access to addDrawOp
robertphillips55fdccc2016-06-06 06:16:20 -0700391
robertphillips77a2e522015-10-17 07:43:27 -0700392 friend class GrDrawingManager; // for ctor
Brian Osman11052242016-10-27 14:47:55 -0400393 friend class GrRenderTargetContextPriv;
Brian Salomon42521e82016-12-07 16:44:58 -0500394 friend class GrSWMaskHelper; // for access to addDrawOp
robertphillips976f5f02016-06-03 10:59:20 -0700395
Brian Salomon42521e82016-12-07 16:44:58 -0500396 // All the path renderers currently make their own ops
397 friend class GrSoftwarePathRenderer; // for access to addDrawOp
398 friend class GrAAConvexPathRenderer; // for access to addDrawOp
399 friend class GrDashLinePathRenderer; // for access to addDrawOp
400 friend class GrAAHairLinePathRenderer; // for access to addDrawOp
401 friend class GrAALinearizingConvexPathRenderer; // for access to addDrawOp
402 friend class GrAADistanceFieldPathRenderer; // for access to addDrawOp
403 friend class GrDefaultPathRenderer; // for access to addDrawOp
404 friend class GrPLSPathRenderer; // for access to addDrawOp
405 friend class GrMSAAPathRenderer; // for access to addDrawOp
406 friend class GrStencilAndCoverPathRenderer; // for access to addDrawOp
407 friend class GrTessellatingPathRenderer; // for access to addDrawOp
robertphillipsea461502015-05-26 11:38:03 -0700408
csmartdalton29df7602016-08-31 11:55:52 -0700409 void internalClear(const GrFixedClip&, const GrColor, bool canIgnoreClip);
410
Brian Salomon82f44312017-01-11 13:42:54 -0500411 // Only consumes the GrPaint if successful.
robertphillips00095892016-02-29 13:50:40 -0800412 bool drawFilledDRRect(const GrClip& clip,
Brian Salomon82f44312017-01-11 13:42:54 -0500413 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500414 GrAA,
robertphillips00095892016-02-29 13:50:40 -0800415 const SkMatrix& viewMatrix,
416 const SkRRect& origOuter,
417 const SkRRect& origInner);
418
Brian Salomon82f44312017-01-11 13:42:54 -0500419 // Only consumes the GrPaint if successful.
robertphillips44302392016-07-08 14:43:03 -0700420 bool drawFilledRect(const GrClip& clip,
Brian Salomon82f44312017-01-11 13:42:54 -0500421 GrPaint&& paint,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500422 GrAA,
robertphillips44302392016-07-08 14:43:03 -0700423 const SkMatrix& viewMatrix,
424 const SkRect& rect,
425 const GrUserStencilSettings* ss);
426
427 void drawNonAAFilledRect(const GrClip&,
Brian Salomon82f44312017-01-11 13:42:54 -0500428 GrPaint&&,
robertphillips44302392016-07-08 14:43:03 -0700429 const SkMatrix& viewMatrix,
430 const SkRect& rect,
431 const SkRect* localRect,
432 const SkMatrix* localMatrix,
csmartdalton34ee0c92016-07-27 13:22:27 -0700433 const GrUserStencilSettings* ss,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500434 GrAAType hwOrNoneAAType);
robertphillips391395d2016-03-02 09:26:36 -0800435
Brian Salomon82f44312017-01-11 13:42:54 -0500436 void internalDrawPath(
437 const GrClip&, GrPaint&&, GrAA, const SkMatrix&, const SkPath&, const GrStyle&);
robertphillipsea461502015-05-26 11:38:03 -0700438
Robert Phillipse2f7d182016-12-15 09:23:05 -0500439 bool onCopy(GrSurfaceProxy* src, const SkIRect& srcRect, const SkIPoint& dstPoint) override;
Robert Phillips2c862492017-01-18 10:08:39 -0500440 bool onReadPixels(const SkImageInfo& dstInfo, void* dstBuffer,
441 size_t dstRowBytes, int x, int y) override;
442 bool onWritePixels(const SkImageInfo& srcInfo, const void* srcBuffer,
443 size_t srcRowBytes, int x, int y) override;
Robert Phillipse2f7d182016-12-15 09:23:05 -0500444
Brian Salomon42521e82016-12-07 16:44:58 -0500445 // This entry point allows the GrTextContext-derived classes to add their ops to the GrOpList.
Brian Salomonf8334782017-01-03 09:42:58 -0500446 void addDrawOp(const GrPipelineBuilder&, const GrClip&, std::unique_ptr<GrDrawOp>);
robertphillips2334fb62015-06-17 05:43:33 -0700447
Robert Phillipsf2361d22016-10-25 14:20:06 -0400448 GrRenderTargetOpList* getOpList();
robertphillipsa106c622015-10-16 09:07:06 -0700449
msarettc71a9b72016-09-16 11:01:27 -0700450 GrDrawingManager* fDrawingManager;
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400451 sk_sp<GrRenderTargetProxy> fRenderTargetProxy;
robertphillipsa106c622015-10-16 09:07:06 -0700452
Brian Osman11052242016-10-27 14:47:55 -0400453 // In MDB-mode the GrOpList can be closed by some other renderTargetContext that has picked
Robert Phillipsf2361d22016-10-25 14:20:06 -0400454 // it up. For this reason, the GrOpList should only ever be accessed via 'getOpList'.
455 GrRenderTargetOpList* fOpList;
msarettc71a9b72016-09-16 11:01:27 -0700456 GrInstancedPipelineInfo fInstancedPipelineInfo;
robertphillips2334fb62015-06-17 05:43:33 -0700457
msarettc71a9b72016-09-16 11:01:27 -0700458 sk_sp<GrColorSpaceXform> fColorXformFromSRGB;
459 SkSurfaceProps fSurfaceProps;
Robert Phillipse305cc1f2016-12-14 12:19:05 -0500460
461 typedef GrSurfaceContext INHERITED;
robertphillipsea461502015-05-26 11:38:03 -0700462};
463
464#endif