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" |
robertphillips | 7bceedc | 2015-12-01 12:51:26 -0800 | [diff] [blame] | 14 | #include "GrRenderTarget.h" |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 15 | #include "SkRefCnt.h" |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 16 | #include "SkRegion.h" |
robertphillips | fcf7829 | 2015-06-19 11:49:52 -0700 | [diff] [blame] | 17 | #include "SkSurfaceProps.h" |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 18 | #include "../private/GrInstancedPipelineInfo.h" |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 19 | #include "../private/GrSingleOwner.h" |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 20 | |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 21 | class GrAuditTrail; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 22 | class GrClip; |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 23 | class GrDrawBatch; |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 24 | class GrRenderTargetContextPriv; |
cdalton | 8ff8d24 | 2015-12-08 10:20:32 -0800 | [diff] [blame] | 25 | class GrDrawPathBatchBase; |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 26 | class GrDrawingManager; |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 27 | class GrFixedClip; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 28 | class GrPaint; |
| 29 | class GrPathProcessor; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 30 | class GrPipelineBuilder; |
| 31 | class GrRenderTarget; |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 32 | class GrRenderTargetOpList; |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 33 | class GrStyle; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 34 | class GrSurface; |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 35 | struct GrUserStencilSettings; |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 36 | class SkDrawFilter; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 37 | struct SkIPoint; |
| 38 | struct SkIRect; |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 39 | class SkLatticeIter; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 40 | class SkMatrix; |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 41 | class SkPaint; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 42 | class SkPath; |
| 43 | struct SkPoint; |
| 44 | struct SkRect; |
| 45 | class SkRRect; |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 46 | struct SkRSXform; |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 47 | class SkTextBlob; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 48 | |
| 49 | /* |
| 50 | * A helper object to orchestrate draws |
| 51 | */ |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 52 | class SK_API GrRenderTargetContext : public SkRefCnt { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 53 | public: |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 54 | ~GrRenderTargetContext() override; |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 55 | |
bsalomon | b8fea97 | 2016-02-16 07:34:17 -0800 | [diff] [blame] | 56 | bool copySurface(GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 57 | |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 58 | // TODO: it is odd that we need both the SkPaint in the following 3 methods. |
| 59 | // We should extract the text parameters from SkPaint and pass them separately |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 60 | // akin to GrStyle (GrTextInfo?) |
joshualitt | 96880d9 | 2016-02-16 10:36:53 -0800 | [diff] [blame] | 61 | virtual void drawText(const GrClip&, const GrPaint&, const SkPaint&, |
| 62 | const SkMatrix& viewMatrix, const char text[], size_t byteLength, |
| 63 | SkScalar x, SkScalar y, const SkIRect& clipBounds); |
| 64 | virtual void drawPosText(const GrClip&, const GrPaint&, const SkPaint&, |
| 65 | const SkMatrix& viewMatrix, const char text[], size_t byteLength, |
| 66 | const SkScalar pos[], int scalarsPerPosition, |
| 67 | const SkPoint& offset, const SkIRect& clipBounds); |
| 68 | virtual void drawTextBlob(const GrClip&, const SkPaint&, |
| 69 | const SkMatrix& viewMatrix, const SkTextBlob*, |
| 70 | SkScalar x, SkScalar y, |
| 71 | SkDrawFilter*, const SkIRect& clipBounds); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 72 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 73 | /** |
| 74 | * Provides a perfomance hint that the render target's contents are allowed |
| 75 | * to become undefined. |
| 76 | */ |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 77 | void discard(); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 78 | |
| 79 | /** |
| 80 | * Clear the entire or rect of the render target, ignoring any clips. |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 81 | * @param rect the rect to clear or the whole thing if rect is NULL. |
| 82 | * @param color the color to clear to. |
| 83 | * @param canIgnoreRect allows partial clears to be converted to whole |
| 84 | * clears on platforms for which that is cheap |
| 85 | */ |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 86 | void clear(const SkIRect* rect, GrColor color, bool canIgnoreRect); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 87 | |
| 88 | /** |
| 89 | * Draw everywhere (respecting the clip) with the paint. |
| 90 | */ |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 91 | void drawPaint(const GrClip&, const GrPaint&, const SkMatrix& viewMatrix); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 92 | |
| 93 | /** |
| 94 | * Draw the rect using a paint. |
| 95 | * @param paint describes how to color pixels. |
| 96 | * @param viewMatrix transformation matrix |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 97 | * @param style The style to apply. Null means fill. Currently path effects are not |
| 98 | * allowed. |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 99 | * The rects coords are used to access the paint (through texture matrix) |
| 100 | */ |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 101 | void drawRect(const GrClip&, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 102 | const GrPaint& paint, |
| 103 | const SkMatrix& viewMatrix, |
| 104 | const SkRect&, |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 105 | const GrStyle* style = nullptr); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 106 | |
| 107 | /** |
bsalomon | a2e69fc | 2015-11-05 10:41:43 -0800 | [diff] [blame] | 108 | * Maps a rectangle of shader coordinates to a rectangle and fills that rectangle. |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 109 | * |
| 110 | * @param paint describes how to color pixels. |
| 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&, |
| 116 | const GrPaint& paint, |
| 117 | const SkMatrix& viewMatrix, |
| 118 | const SkRect& rectToDraw, |
| 119 | const SkRect& localRect); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 120 | |
| 121 | /** |
bsalomon | a2e69fc | 2015-11-05 10:41:43 -0800 | [diff] [blame] | 122 | * Fills a rect with a paint and a localMatrix. |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 123 | */ |
bsalomon | a2e69fc | 2015-11-05 10:41:43 -0800 | [diff] [blame] | 124 | void fillRectWithLocalMatrix(const GrClip& clip, |
| 125 | const GrPaint& paint, |
| 126 | const SkMatrix& viewMatrix, |
| 127 | const SkRect& rect, |
| 128 | const SkMatrix& localMatrix); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 129 | |
| 130 | /** |
| 131 | * Draw a roundrect using a paint. |
| 132 | * |
| 133 | * @param paint describes how to color pixels. |
| 134 | * @param viewMatrix transformation matrix |
| 135 | * @param rrect the roundrect to draw |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 136 | * @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] | 137 | */ |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 138 | void drawRRect(const GrClip&, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 139 | const GrPaint&, |
| 140 | const SkMatrix& viewMatrix, |
| 141 | const SkRRect& rrect, |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 142 | const GrStyle& style); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 143 | |
| 144 | /** |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 145 | * Shortcut for drawing an SkPath consisting of nested rrects using a paint. |
| 146 | * Does not support stroking. The result is undefined if outer does not contain |
| 147 | * inner. |
| 148 | * |
| 149 | * @param paint describes how to color pixels. |
| 150 | * @param viewMatrix transformation matrix |
| 151 | * @param outer the outer roundrect |
| 152 | * @param inner the inner roundrect |
| 153 | */ |
| 154 | void drawDRRect(const GrClip&, |
| 155 | const GrPaint&, |
| 156 | const SkMatrix& viewMatrix, |
| 157 | const SkRRect& outer, |
| 158 | const SkRRect& inner); |
| 159 | |
| 160 | /** |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 161 | * Draws a path. |
| 162 | * |
| 163 | * @param paint describes how to color pixels. |
| 164 | * @param viewMatrix transformation matrix |
| 165 | * @param path the path to draw |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 166 | * @param style style to apply to the path. |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 167 | */ |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 168 | void drawPath(const GrClip&, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 169 | const GrPaint&, |
| 170 | const SkMatrix& viewMatrix, |
| 171 | const SkPath&, |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 172 | const GrStyle& style); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 173 | |
| 174 | /** |
| 175 | * Draws vertices with a paint. |
| 176 | * |
| 177 | * @param paint describes how to color pixels. |
| 178 | * @param viewMatrix transformation matrix |
| 179 | * @param primitiveType primitives type to draw. |
| 180 | * @param vertexCount number of vertices. |
| 181 | * @param positions array of vertex positions, required. |
| 182 | * @param texCoords optional array of texture coordinates used |
| 183 | * to access the paint. |
| 184 | * @param colors optional array of per-vertex colors, supercedes |
| 185 | * the paint's color field. |
| 186 | * @param indices optional array of indices. If NULL vertices |
| 187 | * are drawn non-indexed. |
| 188 | * @param indexCount if indices is non-null then this is the |
| 189 | * number of indices. |
| 190 | */ |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 191 | void drawVertices(const GrClip&, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 192 | const GrPaint& paint, |
| 193 | const SkMatrix& viewMatrix, |
| 194 | GrPrimitiveType primitiveType, |
| 195 | int vertexCount, |
| 196 | const SkPoint positions[], |
| 197 | const SkPoint texs[], |
| 198 | const GrColor colors[], |
| 199 | const uint16_t indices[], |
| 200 | int indexCount); |
| 201 | |
| 202 | /** |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 203 | * Draws textured sprites from an atlas with a paint. |
| 204 | * |
| 205 | * @param paint describes how to color pixels. |
| 206 | * @param viewMatrix transformation matrix |
| 207 | * @param spriteCount number of sprites. |
| 208 | * @param xform array of compressed transformation data, required. |
| 209 | * @param texRect array of texture rectangles used to access the paint. |
| 210 | * @param colors optional array of per-sprite colors, supercedes |
| 211 | * the paint's color field. |
| 212 | */ |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 213 | void drawAtlas(const GrClip&, |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 214 | const GrPaint& paint, |
| 215 | const SkMatrix& viewMatrix, |
| 216 | int spriteCount, |
| 217 | const SkRSXform xform[], |
| 218 | const SkRect texRect[], |
| 219 | const SkColor colors[]); |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 220 | |
| 221 | /** |
| 222 | * Draws a region. |
| 223 | * |
| 224 | * @param paint describes how to color pixels |
| 225 | * @param viewMatrix transformation matrix |
| 226 | * @param region the region to be drawn |
| 227 | * @param style style to apply to the region |
| 228 | */ |
| 229 | void drawRegion(const GrClip&, |
| 230 | const GrPaint& paint, |
| 231 | const SkMatrix& viewMatrix, |
| 232 | const SkRegion& region, |
| 233 | const GrStyle& style); |
| 234 | |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 235 | /** |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 236 | * Draws an oval. |
| 237 | * |
| 238 | * @param paint describes how to color pixels. |
| 239 | * @param viewMatrix transformation matrix |
| 240 | * @param oval the bounding rect of the oval. |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 241 | * @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] | 242 | */ |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 243 | void drawOval(const GrClip&, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 244 | const GrPaint& paint, |
| 245 | const SkMatrix& viewMatrix, |
| 246 | const SkRect& oval, |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 247 | const GrStyle& style); |
bsalomon | 4f3a0ca | 2016-08-22 13:14:26 -0700 | [diff] [blame] | 248 | /** |
| 249 | * Draws a partial arc of an oval. |
| 250 | * |
| 251 | * @param paint describes how to color pixels. |
| 252 | * @param viewMatrix transformation matrix. |
| 253 | * @param oval the bounding rect of the oval. |
| 254 | * @param startAngle starting angle in degrees. |
| 255 | * @param sweepAngle angle to sweep in degrees. Must be in (-360, 360) |
| 256 | * @param useCenter true means that the implied path begins at the oval center, connects as a |
| 257 | * line to the point indicated by the start contains the arc indicated by |
| 258 | * the sweep angle. If false the line beginning at the center point is |
| 259 | * omitted. |
| 260 | * @param style style to apply to the oval. |
| 261 | */ |
| 262 | void drawArc(const GrClip&, |
| 263 | const GrPaint& paint, |
| 264 | const SkMatrix& viewMatrix, |
| 265 | const SkRect& oval, |
| 266 | SkScalar startAngle, |
| 267 | SkScalar sweepAngle, |
| 268 | bool useCenter, |
| 269 | const GrStyle& style); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 270 | |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 271 | /** |
bsalomon | 4f3a0ca | 2016-08-22 13:14:26 -0700 | [diff] [blame] | 272 | * Draw the image as a set of rects, specified by |iter|. |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 273 | */ |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 274 | void drawImageLattice(const GrClip&, |
| 275 | const GrPaint& paint, |
| 276 | const SkMatrix& viewMatrix, |
| 277 | int imageWidth, |
| 278 | int imageHeight, |
| 279 | std::unique_ptr<SkLatticeIter> iter, |
| 280 | const SkRect& dst); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 281 | |
robertphillips | 8c523e0 | 2016-07-26 07:41:00 -0700 | [diff] [blame] | 282 | /** |
| 283 | * After this returns any pending surface IO will be issued to the backend 3D API and |
| 284 | * if the surface has MSAA it will be resolved. |
| 285 | */ |
| 286 | void prepareForExternalIO(); |
| 287 | |
robertphillips | 1da3ecd | 2016-08-31 14:54:15 -0700 | [diff] [blame] | 288 | /** |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 289 | * Reads a rectangle of pixels from the render target context. |
robertphillips | 1da3ecd | 2016-08-31 14:54:15 -0700 | [diff] [blame] | 290 | * @param dstInfo image info for the destination |
| 291 | * @param dstBuffer destination pixels for the read |
| 292 | * @param dstRowBytes bytes in a row of 'dstBuffer' |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 293 | * @param x x offset w/in the render target context from which to read |
| 294 | * @param y y offset w/in the render target context from which to read |
robertphillips | 1da3ecd | 2016-08-31 14:54:15 -0700 | [diff] [blame] | 295 | * |
| 296 | * @return true if the read succeeded, false if not. The read can fail because of an |
| 297 | * unsupported pixel config. |
| 298 | */ |
| 299 | bool readPixels(const SkImageInfo& dstInfo, void* dstBuffer, size_t dstRowBytes, int x, int y); |
| 300 | |
| 301 | /** |
| 302 | * Writes a rectangle of pixels [srcInfo, srcBuffer, srcRowbytes] into the |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 303 | * renderTargetContext at the specified position. |
robertphillips | 1da3ecd | 2016-08-31 14:54:15 -0700 | [diff] [blame] | 304 | * @param srcInfo image info for the source pixels |
| 305 | * @param srcBuffer source for the write |
| 306 | * @param srcRowBytes bytes in a row of 'srcBuffer' |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 307 | * @param x x offset w/in the render target context at which to write |
| 308 | * @param y y offset w/in the render target context at which to write |
robertphillips | 1da3ecd | 2016-08-31 14:54:15 -0700 | [diff] [blame] | 309 | * |
| 310 | * @return true if the write succeeded, false if not. The write can fail because of an |
| 311 | * unsupported pixel config. |
| 312 | */ |
| 313 | bool writePixels(const SkImageInfo& srcInfo, const void* srcBuffer, size_t srcRowBytes, |
| 314 | int x, int y); |
| 315 | |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 316 | bool isStencilBufferMultisampled() const { |
| 317 | return fRenderTarget->isStencilBufferMultisampled(); |
| 318 | } |
robertphillips | 55fdccc | 2016-06-06 06:16:20 -0700 | [diff] [blame] | 319 | bool isUnifiedMultisampled() const { return fRenderTarget->isUnifiedMultisampled(); } |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 320 | bool hasMixedSamples() const { return fRenderTarget->isMixedSampled(); } |
robertphillips | 82ec6e5 | 2016-05-19 14:01:05 -0700 | [diff] [blame] | 321 | |
csmartdalton | ecbc12b | 2016-06-08 10:08:43 -0700 | [diff] [blame] | 322 | bool mustUseHWAA(const GrPaint& paint) const { |
bsalomon | bb24383 | 2016-07-22 07:10:19 -0700 | [diff] [blame] | 323 | return paint.isAntiAlias() && fRenderTarget->isUnifiedMultisampled(); |
csmartdalton | ecbc12b | 2016-06-08 10:08:43 -0700 | [diff] [blame] | 324 | } |
| 325 | |
bsalomon | faf8203 | 2016-09-16 09:53:27 -0700 | [diff] [blame] | 326 | const GrCaps* caps() const { return fContext->caps(); } |
robertphillips | e576874 | 2016-05-13 11:20:46 -0700 | [diff] [blame] | 327 | const GrSurfaceDesc& desc() const { return fRenderTarget->desc(); } |
robertphillips | 7bceedc | 2015-12-01 12:51:26 -0800 | [diff] [blame] | 328 | int width() const { return fRenderTarget->width(); } |
| 329 | int height() const { return fRenderTarget->height(); } |
robertphillips | ca6eafc | 2016-05-17 09:57:46 -0700 | [diff] [blame] | 330 | GrPixelConfig config() const { return fRenderTarget->config(); } |
robertphillips | 7bceedc | 2015-12-01 12:51:26 -0800 | [diff] [blame] | 331 | int numColorSamples() const { return fRenderTarget->numColorSamples(); } |
brianosman | 9dc935f | 2016-07-26 10:21:54 -0700 | [diff] [blame] | 332 | bool isGammaCorrect() const { return SkToBool(fColorSpace.get()); } |
brianosman | 8fe485b | 2016-07-25 12:31:51 -0700 | [diff] [blame] | 333 | SkSourceGammaTreatment sourceGammaTreatment() const { |
| 334 | return this->isGammaCorrect() ? SkSourceGammaTreatment::kRespect |
| 335 | : SkSourceGammaTreatment::kIgnore; |
| 336 | } |
robertphillips | ca6eafc | 2016-05-17 09:57:46 -0700 | [diff] [blame] | 337 | const SkSurfaceProps& surfaceProps() const { return fSurfaceProps; } |
brianosman | dfe4f2e | 2016-07-21 13:28:36 -0700 | [diff] [blame] | 338 | SkColorSpace* getColorSpace() const { return fColorSpace.get(); } |
msarett | c71a9b7 | 2016-09-16 11:01:27 -0700 | [diff] [blame] | 339 | GrColorSpaceXform* getColorXformFromSRGB() const { return fColorXformFromSRGB.get(); } |
robertphillips | 7e92276 | 2016-07-26 11:38:17 -0700 | [diff] [blame] | 340 | GrSurfaceOrigin origin() const { return fRenderTarget->origin(); } |
robertphillips | 7bceedc | 2015-12-01 12:51:26 -0800 | [diff] [blame] | 341 | |
robertphillips | 7761d61 | 2016-05-16 09:14:53 -0700 | [diff] [blame] | 342 | bool wasAbandoned() const; |
| 343 | |
robertphillips | 6c7e325 | 2016-04-27 10:47:51 -0700 | [diff] [blame] | 344 | GrRenderTarget* accessRenderTarget() { return fRenderTarget.get(); } |
| 345 | |
robertphillips | 6c7e325 | 2016-04-27 10:47:51 -0700 | [diff] [blame] | 346 | sk_sp<GrTexture> asTexture() { return sk_ref_sp(fRenderTarget->asTexture()); } |
robertphillips | 433625e | 2015-12-04 06:58:16 -0800 | [diff] [blame] | 347 | |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 348 | // Provides access to functions that aren't part of the public API. |
Brian Osman | 693a540 | 2016-10-27 15:13:22 -0400 | [diff] [blame^] | 349 | GrRenderTargetContextPriv priv(); |
| 350 | const GrRenderTargetContextPriv priv() const; |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 351 | |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 352 | GrAuditTrail* auditTrail() { return fAuditTrail; } |
| 353 | |
joshualitt | 96880d9 | 2016-02-16 10:36:53 -0800 | [diff] [blame] | 354 | protected: |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 355 | GrRenderTargetContext(GrContext*, GrDrawingManager*, sk_sp<GrRenderTarget>, sk_sp<SkColorSpace>, |
| 356 | const SkSurfaceProps* surfaceProps, GrAuditTrail*, GrSingleOwner*); |
joshualitt | 96880d9 | 2016-02-16 10:36:53 -0800 | [diff] [blame] | 357 | |
| 358 | GrDrawingManager* drawingManager() { return fDrawingManager; } |
robertphillips | ca6eafc | 2016-05-17 09:57:46 -0700 | [diff] [blame] | 359 | |
joshualitt | 96880d9 | 2016-02-16 10:36:53 -0800 | [diff] [blame] | 360 | SkDEBUGCODE(GrSingleOwner* singleOwner() { return fSingleOwner; }) |
| 361 | SkDEBUGCODE(void validate() const;) |
| 362 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 363 | private: |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 364 | friend class GrAtlasTextBlob; // for access to drawBatch |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 365 | friend class GrStencilAndCoverTextContext; // for access to drawBatch |
robertphillips | 55fdccc | 2016-06-06 06:16:20 -0700 | [diff] [blame] | 366 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 367 | friend class GrDrawingManager; // for ctor |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 368 | friend class GrRenderTargetContextPriv; |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 369 | friend class GrTestTarget; // for access to getOpList |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 370 | friend class GrSWMaskHelper; // for access to drawBatch |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 371 | |
| 372 | // All the path renderers currently make their own batches |
| 373 | friend class GrSoftwarePathRenderer; // for access to drawBatch |
| 374 | friend class GrAAConvexPathRenderer; // for access to drawBatch |
| 375 | friend class GrDashLinePathRenderer; // for access to drawBatch |
| 376 | friend class GrAAHairLinePathRenderer; // for access to drawBatch |
| 377 | friend class GrAALinearizingConvexPathRenderer; // for access to drawBatch |
| 378 | friend class GrAADistanceFieldPathRenderer; // for access to drawBatch |
| 379 | friend class GrDefaultPathRenderer; // for access to drawBatch |
| 380 | friend class GrPLSPathRenderer; // for access to drawBatch |
| 381 | friend class GrMSAAPathRenderer; // for access to drawBatch |
| 382 | friend class GrStencilAndCoverPathRenderer; // for access to drawBatch |
| 383 | friend class GrTessellatingPathRenderer; // for access to drawBatch |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 384 | |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 385 | void internalClear(const GrFixedClip&, const GrColor, bool canIgnoreClip); |
| 386 | |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 387 | bool drawFilledDRRect(const GrClip& clip, |
| 388 | const GrPaint& paint, |
| 389 | const SkMatrix& viewMatrix, |
| 390 | const SkRRect& origOuter, |
| 391 | const SkRRect& origInner); |
| 392 | |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 393 | bool drawFilledRect(const GrClip& clip, |
| 394 | const GrPaint& paint, |
| 395 | const SkMatrix& viewMatrix, |
| 396 | const SkRect& rect, |
| 397 | const GrUserStencilSettings* ss); |
| 398 | |
| 399 | void drawNonAAFilledRect(const GrClip&, |
| 400 | const GrPaint&, |
| 401 | const SkMatrix& viewMatrix, |
| 402 | const SkRect& rect, |
| 403 | const SkRect* localRect, |
| 404 | const SkMatrix* localMatrix, |
csmartdalton | 34ee0c9 | 2016-07-27 13:22:27 -0700 | [diff] [blame] | 405 | const GrUserStencilSettings* ss, |
| 406 | bool useHWAA); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 407 | |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 408 | void internalDrawPath(const GrClip& clip, |
| 409 | const GrPaint& paint, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 410 | const SkMatrix& viewMatrix, |
robertphillips | 4bc3181 | 2016-03-01 12:22:49 -0800 | [diff] [blame] | 411 | const SkPath& path, |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 412 | const GrStyle& style); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 413 | |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 414 | // This entry point allows the GrTextContext-derived classes to add their batches to |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 415 | // the GrOpList. |
bsalomon | bb24383 | 2016-07-22 07:10:19 -0700 | [diff] [blame] | 416 | void drawBatch(const GrPipelineBuilder& pipelineBuilder, const GrClip&, GrDrawBatch* batch); |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 417 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 418 | GrRenderTargetOpList* getOpList(); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 419 | |
msarett | c71a9b7 | 2016-09-16 11:01:27 -0700 | [diff] [blame] | 420 | GrDrawingManager* fDrawingManager; |
| 421 | sk_sp<GrRenderTarget> fRenderTarget; |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 422 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 423 | // 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] | 424 | // it up. For this reason, the GrOpList should only ever be accessed via 'getOpList'. |
| 425 | GrRenderTargetOpList* fOpList; |
msarett | c71a9b7 | 2016-09-16 11:01:27 -0700 | [diff] [blame] | 426 | GrContext* fContext; |
| 427 | GrInstancedPipelineInfo fInstancedPipelineInfo; |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 428 | |
msarett | c71a9b7 | 2016-09-16 11:01:27 -0700 | [diff] [blame] | 429 | sk_sp<SkColorSpace> fColorSpace; |
| 430 | sk_sp<GrColorSpaceXform> fColorXformFromSRGB; |
| 431 | SkSurfaceProps fSurfaceProps; |
| 432 | GrAuditTrail* fAuditTrail; |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 433 | |
| 434 | // In debug builds we guard against improper thread handling |
msarett | c71a9b7 | 2016-09-16 11:01:27 -0700 | [diff] [blame] | 435 | SkDEBUGCODE(mutable GrSingleOwner* fSingleOwner;) |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 436 | }; |
| 437 | |
| 438 | #endif |