robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1 | /* |
| 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 Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 8 | #ifndef GrRenderTargetContext_DEFINED |
| 9 | #define GrRenderTargetContext_DEFINED |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 10 | |
| 11 | #include "GrColor.h" |
bsalomon | faf8203 | 2016-09-16 09:53:27 -0700 | [diff] [blame] | 12 | #include "GrContext.h" |
csmartdalton | ecbc12b | 2016-06-08 10:08:43 -0700 | [diff] [blame] | 13 | #include "GrPaint.h" |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 14 | #include "GrSurfaceContext.h" |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 15 | #include "SkRefCnt.h" |
robertphillips | fcf7829 | 2015-06-19 11:49:52 -0700 | [diff] [blame] | 16 | #include "SkSurfaceProps.h" |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 17 | #include "../private/GrInstancedPipelineInfo.h" |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 18 | #include "../private/GrRenderTargetProxy.h" |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 19 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 20 | class GrClip; |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 21 | class GrDrawingManager; |
Brian Salomon | 9afd371 | 2016-12-01 10:59:09 -0500 | [diff] [blame] | 22 | class GrDrawOp; |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 23 | class GrFixedClip; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 24 | class GrPipelineBuilder; |
| 25 | class GrRenderTarget; |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 26 | class GrRenderTargetContextPriv; |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 27 | class GrRenderTargetOpList; |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 28 | class GrStyle; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 29 | class GrSurface; |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 30 | class GrTextureProxy; |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 31 | struct GrUserStencilSettings; |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 32 | class SkDrawFilter; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 33 | struct SkIPoint; |
| 34 | struct SkIRect; |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 35 | class SkLatticeIter; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 36 | class SkMatrix; |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 37 | class SkPaint; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 38 | class SkPath; |
| 39 | struct SkPoint; |
| 40 | struct SkRect; |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 41 | class SkRegion; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 42 | class SkRRect; |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 43 | struct SkRSXform; |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 44 | class SkTextBlob; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 45 | |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 46 | /** |
| 47 | * A helper object to orchestrate commands (draws, etc...) for GrSurfaces that are GrRenderTargets. |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 48 | */ |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 49 | class SK_API GrRenderTargetContext : public GrSurfaceContext { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 50 | public: |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 51 | ~GrRenderTargetContext() override; |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 52 | |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 53 | // 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 Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 59 | const char text[], size_t byteLength, SkScalar x, SkScalar y, |
| 60 | const SkIRect& clipBounds); |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 61 | virtual void drawPosText(const GrClip&, const SkPaint&, const SkMatrix& viewMatrix, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 62 | const char text[], size_t byteLength, const SkScalar pos[], |
| 63 | int scalarsPerPosition, const SkPoint& offset, |
| 64 | const SkIRect& clipBounds); |
joshualitt | 96880d9 | 2016-02-16 10:36:53 -0800 | [diff] [blame] | 65 | virtual void drawTextBlob(const GrClip&, const SkPaint&, |
| 66 | const SkMatrix& viewMatrix, const SkTextBlob*, |
| 67 | SkScalar x, SkScalar y, |
| 68 | SkDrawFilter*, const SkIRect& clipBounds); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 69 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 70 | /** |
| 71 | * Provides a perfomance hint that the render target's contents are allowed |
| 72 | * to become undefined. |
| 73 | */ |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 74 | void discard(); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 75 | |
| 76 | /** |
| 77 | * Clear the entire or rect of the render target, ignoring any clips. |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 78 | * @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 | */ |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 83 | void clear(const SkIRect* rect, GrColor color, bool canIgnoreRect); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 84 | |
| 85 | /** |
| 86 | * Draw everywhere (respecting the clip) with the paint. |
| 87 | */ |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 88 | void drawPaint(const GrClip&, GrPaint&&, const SkMatrix& viewMatrix); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 89 | |
| 90 | /** |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 91 | * 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) |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 98 | */ |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 99 | void drawRect(const GrClip&, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 100 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 101 | GrAA, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 102 | const SkMatrix& viewMatrix, |
| 103 | const SkRect&, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 104 | const GrStyle* style = nullptr); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 105 | |
| 106 | /** |
bsalomon | a2e69fc | 2015-11-05 10:41:43 -0800 | [diff] [blame] | 107 | * Maps a rectangle of shader coordinates to a rectangle and fills that rectangle. |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 108 | * |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 109 | * @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 |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 114 | */ |
bsalomon | a2e69fc | 2015-11-05 10:41:43 -0800 | [diff] [blame] | 115 | void fillRectToRect(const GrClip&, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 116 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 117 | GrAA, |
bsalomon | a2e69fc | 2015-11-05 10:41:43 -0800 | [diff] [blame] | 118 | const SkMatrix& viewMatrix, |
| 119 | const SkRect& rectToDraw, |
| 120 | const SkRect& localRect); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 121 | |
| 122 | /** |
bsalomon | a2e69fc | 2015-11-05 10:41:43 -0800 | [diff] [blame] | 123 | * Fills a rect with a paint and a localMatrix. |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 124 | */ |
bsalomon | a2e69fc | 2015-11-05 10:41:43 -0800 | [diff] [blame] | 125 | void fillRectWithLocalMatrix(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 126 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 127 | GrAA, |
bsalomon | a2e69fc | 2015-11-05 10:41:43 -0800 | [diff] [blame] | 128 | const SkMatrix& viewMatrix, |
| 129 | const SkRect& rect, |
| 130 | const SkMatrix& localMatrix); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 131 | |
| 132 | /** |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 133 | * Draw a roundrect using a paint. |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 134 | * |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 135 | * @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. |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 140 | */ |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 141 | void drawRRect(const GrClip&, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 142 | GrPaint&&, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 143 | GrAA, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 144 | const SkMatrix& viewMatrix, |
| 145 | const SkRRect& rrect, |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 146 | const GrStyle& style); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 147 | |
| 148 | /** |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 149 | * 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 Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 151 | * |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 152 | * @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 Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 157 | */ |
| 158 | void drawShadowRRect(const GrClip&, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 159 | GrPaint&&, |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 160 | const SkMatrix& viewMatrix, |
| 161 | const SkRRect& rrect, |
| 162 | SkScalar blurRadius, |
| 163 | const GrStyle& style); |
| 164 | |
| 165 | /** |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 166 | * Shortcut for filling a SkPath consisting of nested rrects using a paint. The result is |
| 167 | * undefined if outer does not contain inner. |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 168 | * |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 169 | * @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 |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 174 | */ |
| 175 | void drawDRRect(const GrClip&, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 176 | GrPaint&&, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 177 | GrAA, |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 178 | const SkMatrix& viewMatrix, |
| 179 | const SkRRect& outer, |
| 180 | const SkRRect& inner); |
| 181 | |
| 182 | /** |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 183 | * Draws a path. |
| 184 | * |
| 185 | * @param paint describes how to color pixels. |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 186 | * @param GrAA Controls whether the path is antialiased. |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 187 | * @param viewMatrix transformation matrix |
| 188 | * @param path the path to draw |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 189 | * @param style style to apply to the path. |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 190 | */ |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 191 | void drawPath(const GrClip&, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 192 | GrPaint&&, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 193 | GrAA, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 194 | const SkMatrix& viewMatrix, |
| 195 | const SkPath&, |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 196 | const GrStyle& style); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 197 | |
| 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 | */ |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 215 | void drawVertices(const GrClip&, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 216 | GrPaint&& paint, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 217 | 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 Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 227 | * Draws textured sprites from an atlas with a paint. This currently does not support AA for the |
| 228 | * sprite rectangle edges. |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 229 | * |
| 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 | */ |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 238 | void drawAtlas(const GrClip&, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 239 | GrPaint&& paint, |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 240 | const SkMatrix& viewMatrix, |
| 241 | int spriteCount, |
| 242 | const SkRSXform xform[], |
| 243 | const SkRect texRect[], |
| 244 | const SkColor colors[]); |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 245 | |
| 246 | /** |
| 247 | * Draws a region. |
| 248 | * |
| 249 | * @param paint describes how to color pixels |
| 250 | * @param viewMatrix transformation matrix |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 251 | * @param aa should the rects of the region be antialiased. |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 252 | * @param region the region to be drawn |
| 253 | * @param style style to apply to the region |
| 254 | */ |
| 255 | void drawRegion(const GrClip&, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 256 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 257 | GrAA aa, |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 258 | const SkMatrix& viewMatrix, |
| 259 | const SkRegion& region, |
| 260 | const GrStyle& style); |
| 261 | |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 262 | /** |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 263 | * Draws an oval. |
| 264 | * |
| 265 | * @param paint describes how to color pixels. |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 266 | * @param GrAA Controls whether the oval is antialiased. |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 267 | * @param viewMatrix transformation matrix |
| 268 | * @param oval the bounding rect of the oval. |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 269 | * @param style style to apply to the oval. Currently path effects are not allowed. |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 270 | */ |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 271 | void drawOval(const GrClip&, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 272 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 273 | GrAA, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 274 | const SkMatrix& viewMatrix, |
| 275 | const SkRect& oval, |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 276 | const GrStyle& style); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 277 | /** |
| 278 | * Draws a partial arc of an oval. |
| 279 | * |
| 280 | * @param paint describes how to color pixels. |
Brian Salomon | 9950408 | 2016-12-09 15:51:31 -0500 | [diff] [blame] | 281 | * @param GrGrAA Controls whether the arc is antialiased. |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 282 | * @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 | */ |
bsalomon | 4f3a0ca | 2016-08-22 13:14:26 -0700 | [diff] [blame] | 292 | void drawArc(const GrClip&, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 293 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 294 | GrAA, |
bsalomon | 4f3a0ca | 2016-08-22 13:14:26 -0700 | [diff] [blame] | 295 | const SkMatrix& viewMatrix, |
| 296 | const SkRect& oval, |
| 297 | SkScalar startAngle, |
| 298 | SkScalar sweepAngle, |
| 299 | bool useCenter, |
| 300 | const GrStyle& style); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 301 | |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 302 | /** |
bsalomon | 4f3a0ca | 2016-08-22 13:14:26 -0700 | [diff] [blame] | 303 | * Draw the image as a set of rects, specified by |iter|. |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 304 | */ |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 305 | void drawImageLattice(const GrClip&, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 306 | GrPaint&& paint, |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 307 | const SkMatrix& viewMatrix, |
| 308 | int imageWidth, |
| 309 | int imageHeight, |
| 310 | std::unique_ptr<SkLatticeIter> iter, |
| 311 | const SkRect& dst); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 312 | |
robertphillips | 8c523e0 | 2016-07-26 07:41:00 -0700 | [diff] [blame] | 313 | /** |
| 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 | |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 319 | bool isStencilBufferMultisampled() const { |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 320 | return fRenderTargetProxy->isStencilBufferMultisampled(); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 321 | } |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 322 | bool isUnifiedMultisampled() const { return fRenderTargetProxy->isUnifiedMultisampled(); } |
| 323 | bool hasMixedSamples() const { return fRenderTargetProxy->isMixedSampled(); } |
robertphillips | 82ec6e5 | 2016-05-19 14:01:05 -0700 | [diff] [blame] | 324 | |
bsalomon | faf8203 | 2016-09-16 09:53:27 -0700 | [diff] [blame] | 325 | const GrCaps* caps() const { return fContext->caps(); } |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 326 | 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(); } |
robertphillips | ca6eafc | 2016-05-17 09:57:46 -0700 | [diff] [blame] | 331 | const SkSurfaceProps& surfaceProps() const { return fSurfaceProps; } |
msarett | c71a9b7 | 2016-09-16 11:01:27 -0700 | [diff] [blame] | 332 | GrColorSpaceXform* getColorXformFromSRGB() const { return fColorXformFromSRGB.get(); } |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 333 | GrSurfaceOrigin origin() const { return fRenderTargetProxy->origin(); } |
robertphillips | 7bceedc | 2015-12-01 12:51:26 -0800 | [diff] [blame] | 334 | |
robertphillips | 7761d61 | 2016-05-16 09:14:53 -0700 | [diff] [blame] | 335 | bool wasAbandoned() const; |
| 336 | |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 337 | GrRenderTarget* instantiate(); |
| 338 | |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 339 | 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 | } |
robertphillips | 6c7e325 | 2016-04-27 10:47:51 -0700 | [diff] [blame] | 344 | |
Robert Phillips | 2734136 | 2016-12-14 08:46:47 -0500 | [diff] [blame] | 345 | GrSurfaceProxy* asDeferredSurface() override { return fRenderTargetProxy.get(); } |
| 346 | GrTextureProxy* asDeferredTexture() override; |
| 347 | GrRenderTargetProxy* asDeferredRenderTarget() override { return fRenderTargetProxy.get(); } |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 348 | |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 349 | sk_sp<GrTexture> asTexture() { |
Robert Phillips | e60ad62 | 2016-11-17 10:22:48 -0500 | [diff] [blame] | 350 | if (!this->accessRenderTarget()) { |
| 351 | return nullptr; |
| 352 | } |
| 353 | |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 354 | // 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 Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 356 | // It's usage should migrate to asDeferredTexture |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 357 | return sk_ref_sp(this->accessRenderTarget()->asTexture()); |
| 358 | } |
robertphillips | 433625e | 2015-12-04 06:58:16 -0800 | [diff] [blame] | 359 | |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 360 | // Provides access to functions that aren't part of the public API. |
Brian Osman | 693a540 | 2016-10-27 15:13:22 -0400 | [diff] [blame] | 361 | GrRenderTargetContextPriv priv(); |
| 362 | const GrRenderTargetContextPriv priv() const; |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 363 | |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 364 | bool isWrapped_ForTesting() const; |
| 365 | |
joshualitt | 96880d9 | 2016-02-16 10:36:53 -0800 | [diff] [blame] | 366 | protected: |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 367 | GrRenderTargetContext(GrContext*, GrDrawingManager*, sk_sp<GrRenderTargetProxy>, |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 368 | sk_sp<SkColorSpace>, const SkSurfaceProps*, GrAuditTrail*, |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 369 | GrSingleOwner*); |
joshualitt | 96880d9 | 2016-02-16 10:36:53 -0800 | [diff] [blame] | 370 | |
| 371 | GrDrawingManager* drawingManager() { return fDrawingManager; } |
robertphillips | ca6eafc | 2016-05-17 09:57:46 -0700 | [diff] [blame] | 372 | |
joshualitt | 96880d9 | 2016-02-16 10:36:53 -0800 | [diff] [blame] | 373 | SkDEBUGCODE(void validate() const;) |
| 374 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 375 | private: |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 376 | 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 Salomon | 42521e8 | 2016-12-07 16:44:58 -0500 | [diff] [blame] | 389 | friend class GrAtlasTextBlob; // for access to addDrawOp |
| 390 | friend class GrStencilAndCoverTextContext; // for access to addDrawOp |
robertphillips | 55fdccc | 2016-06-06 06:16:20 -0700 | [diff] [blame] | 391 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 392 | friend class GrDrawingManager; // for ctor |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 393 | friend class GrRenderTargetContextPriv; |
Brian Salomon | 42521e8 | 2016-12-07 16:44:58 -0500 | [diff] [blame] | 394 | friend class GrSWMaskHelper; // for access to addDrawOp |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 395 | |
Brian Salomon | 42521e8 | 2016-12-07 16:44:58 -0500 | [diff] [blame] | 396 | // 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 |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 408 | |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 409 | void internalClear(const GrFixedClip&, const GrColor, bool canIgnoreClip); |
| 410 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 411 | // Only consumes the GrPaint if successful. |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 412 | bool drawFilledDRRect(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 413 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 414 | GrAA, |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 415 | const SkMatrix& viewMatrix, |
| 416 | const SkRRect& origOuter, |
| 417 | const SkRRect& origInner); |
| 418 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 419 | // Only consumes the GrPaint if successful. |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 420 | bool drawFilledRect(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 421 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 422 | GrAA, |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 423 | const SkMatrix& viewMatrix, |
| 424 | const SkRect& rect, |
| 425 | const GrUserStencilSettings* ss); |
| 426 | |
| 427 | void drawNonAAFilledRect(const GrClip&, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 428 | GrPaint&&, |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 429 | const SkMatrix& viewMatrix, |
| 430 | const SkRect& rect, |
| 431 | const SkRect* localRect, |
| 432 | const SkMatrix* localMatrix, |
csmartdalton | 34ee0c9 | 2016-07-27 13:22:27 -0700 | [diff] [blame] | 433 | const GrUserStencilSettings* ss, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 434 | GrAAType hwOrNoneAAType); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 435 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 436 | void internalDrawPath( |
| 437 | const GrClip&, GrPaint&&, GrAA, const SkMatrix&, const SkPath&, const GrStyle&); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 438 | |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 439 | bool onCopy(GrSurfaceProxy* src, const SkIRect& srcRect, const SkIPoint& dstPoint) override; |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 440 | 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 Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 444 | |
Brian Salomon | 42521e8 | 2016-12-07 16:44:58 -0500 | [diff] [blame] | 445 | // This entry point allows the GrTextContext-derived classes to add their ops to the GrOpList. |
Brian Salomon | f833478 | 2017-01-03 09:42:58 -0500 | [diff] [blame] | 446 | void addDrawOp(const GrPipelineBuilder&, const GrClip&, std::unique_ptr<GrDrawOp>); |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 447 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 448 | GrRenderTargetOpList* getOpList(); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 449 | |
msarett | c71a9b7 | 2016-09-16 11:01:27 -0700 | [diff] [blame] | 450 | GrDrawingManager* fDrawingManager; |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 451 | sk_sp<GrRenderTargetProxy> fRenderTargetProxy; |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 452 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 453 | // In MDB-mode the GrOpList can be closed by some other renderTargetContext that has picked |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 454 | // it up. For this reason, the GrOpList should only ever be accessed via 'getOpList'. |
| 455 | GrRenderTargetOpList* fOpList; |
msarett | c71a9b7 | 2016-09-16 11:01:27 -0700 | [diff] [blame] | 456 | GrInstancedPipelineInfo fInstancedPipelineInfo; |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 457 | |
msarett | c71a9b7 | 2016-09-16 11:01:27 -0700 | [diff] [blame] | 458 | sk_sp<GrColorSpaceXform> fColorXformFromSRGB; |
| 459 | SkSurfaceProps fSurfaceProps; |
Robert Phillips | e305cc1f | 2016-12-14 12:19:05 -0500 | [diff] [blame] | 460 | |
| 461 | typedef GrSurfaceContext INHERITED; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 462 | }; |
| 463 | |
| 464 | #endif |