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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/SkCanvas.h" |
| 12 | #include "include/core/SkDrawable.h" |
| 13 | #include "include/core/SkRefCnt.h" |
| 14 | #include "include/core/SkSurface.h" |
| 15 | #include "include/core/SkSurfaceProps.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 16 | #include "include/private/GrTypesPriv.h" |
| 17 | #include "src/gpu/GrPaint.h" |
Chris Dalton | 6b98280 | 2019-06-27 13:53:46 -0600 | [diff] [blame] | 18 | #include "src/gpu/GrRenderTargetOpList.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 19 | #include "src/gpu/GrRenderTargetProxy.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 20 | #include "src/gpu/GrSurfaceContext.h" |
| 21 | #include "src/gpu/GrXferProcessor.h" |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 22 | #include "src/gpu/geometry/GrQuad.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 23 | #include "src/gpu/text/GrTextTarget.h" |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 24 | |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 25 | class GrBackendSemaphore; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 26 | class GrClip; |
Brian Osman | 2240be9 | 2017-10-18 13:15:13 -0400 | [diff] [blame] | 27 | class GrColorSpaceXform; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 28 | class GrCoverageCountingPathRenderer; |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 29 | class GrDrawingManager; |
Brian Salomon | 9afd371 | 2016-12-01 10:59:09 -0500 | [diff] [blame] | 30 | class GrDrawOp; |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 31 | class GrFixedClip; |
Robert Phillips | 0d075de | 2019-03-04 11:08:13 -0500 | [diff] [blame] | 32 | class GrOp; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 33 | class GrRenderTarget; |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 34 | class GrRenderTargetContextPriv; |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 35 | class GrShape; |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 36 | class GrStyle; |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 37 | class GrTextureProxy; |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 38 | struct GrUserStencilSettings; |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 39 | struct SkDrawShadowRec; |
Herb Derby | cddab25 | 2018-07-16 11:19:04 -0400 | [diff] [blame] | 40 | class SkGlyphRunList; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 41 | struct SkIPoint; |
| 42 | struct SkIRect; |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 43 | class SkLatticeIter; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 44 | class SkMatrix; |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 45 | class SkPaint; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 46 | class SkPath; |
| 47 | struct SkPoint; |
| 48 | struct SkRect; |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 49 | class SkRegion; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 50 | class SkRRect; |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 51 | struct SkRSXform; |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 52 | class SkTextBlob; |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 53 | class SkVertices; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 54 | |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 55 | /** |
| 56 | * A helper object to orchestrate commands (draws, etc...) for GrSurfaces that are GrRenderTargets. |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 57 | */ |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 58 | class SK_API GrRenderTargetContext : public GrSurfaceContext { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 59 | public: |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 60 | ~GrRenderTargetContext() override; |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 61 | |
Robert Phillips | e4643cc | 2018-08-14 13:01:29 -0400 | [diff] [blame] | 62 | virtual void drawGlyphRunList(const GrClip&, const SkMatrix& viewMatrix, const SkGlyphRunList&); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 63 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 64 | /** |
| 65 | * Provides a perfomance hint that the render target's contents are allowed |
| 66 | * to become undefined. |
| 67 | */ |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 68 | void discard(); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 69 | |
Chris Dalton | 344e903 | 2017-12-11 15:42:09 -0700 | [diff] [blame] | 70 | enum class CanClearFullscreen : bool { |
| 71 | kNo = false, |
| 72 | kYes = true |
| 73 | }; |
| 74 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 75 | /** |
| 76 | * Clear the entire or rect of the render target, ignoring any clips. |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 77 | * @param rect the rect to clear or the whole thing if rect is NULL. |
| 78 | * @param color the color to clear to. |
Chris Dalton | 344e903 | 2017-12-11 15:42:09 -0700 | [diff] [blame] | 79 | * @param CanClearFullscreen allows partial clears to be converted to fullscreen clears on |
| 80 | * tiling platforms where that is an optimization. |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 81 | */ |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 82 | void clear(const SkIRect* rect, const SkPMColor4f& color, CanClearFullscreen); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 83 | |
| 84 | /** |
| 85 | * Draw everywhere (respecting the clip) with the paint. |
| 86 | */ |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 87 | void drawPaint(const GrClip&, GrPaint&&, const SkMatrix& viewMatrix); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 88 | |
| 89 | /** |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 90 | * Draw the rect using a paint. |
| 91 | * @param paint describes how to color pixels. |
| 92 | * @param GrAA Controls whether rect is antialiased |
| 93 | * @param viewMatrix transformation matrix |
| 94 | * @param style The style to apply. Null means fill. Currently path effects are not |
| 95 | * allowed. |
| 96 | * The rects coords are used to access the paint (through texture matrix) |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 97 | */ |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 98 | void drawRect(const GrClip&, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 99 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 100 | GrAA, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 101 | const SkMatrix& viewMatrix, |
| 102 | const SkRect&, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 103 | const GrStyle* style = nullptr); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 104 | |
| 105 | /** |
bsalomon | a2e69fc | 2015-11-05 10:41:43 -0800 | [diff] [blame] | 106 | * Maps a rectangle of shader coordinates to a rectangle and fills that rectangle. |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 107 | * |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 108 | * @param paint describes how to color pixels. |
| 109 | * @param GrAA Controls whether rect is antialiased |
| 110 | * @param viewMatrix transformation matrix which applies to rectToDraw |
| 111 | * @param rectToDraw the rectangle to draw |
| 112 | * @param localRect the rectangle of shader coordinates applied to rectToDraw |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 113 | */ |
Michael Ludwig | 136f45a | 2019-02-19 11:44:41 -0500 | [diff] [blame] | 114 | void fillRectToRect(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 115 | GrPaint&& paint, |
Michael Ludwig | 136f45a | 2019-02-19 11:44:41 -0500 | [diff] [blame] | 116 | GrAA aa, |
bsalomon | a2e69fc | 2015-11-05 10:41:43 -0800 | [diff] [blame] | 117 | const SkMatrix& viewMatrix, |
| 118 | const SkRect& rectToDraw, |
Michael Ludwig | 136f45a | 2019-02-19 11:44:41 -0500 | [diff] [blame] | 119 | const SkRect& localRect) { |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 120 | this->drawFilledQuad(clip, std::move(paint), aa, |
| 121 | aa == GrAA::kYes ? GrQuadAAFlags::kAll : GrQuadAAFlags::kNone, |
| 122 | GrQuad::MakeFromRect(rectToDraw, viewMatrix), GrQuad(localRect)); |
Michael Ludwig | 136f45a | 2019-02-19 11:44:41 -0500 | [diff] [blame] | 123 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 124 | |
| 125 | /** |
bsalomon | a2e69fc | 2015-11-05 10:41:43 -0800 | [diff] [blame] | 126 | * Fills a rect with a paint and a localMatrix. |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 127 | */ |
bsalomon | a2e69fc | 2015-11-05 10:41:43 -0800 | [diff] [blame] | 128 | void fillRectWithLocalMatrix(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 129 | GrPaint&& paint, |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 130 | GrAA aa, |
bsalomon | a2e69fc | 2015-11-05 10:41:43 -0800 | [diff] [blame] | 131 | const SkMatrix& viewMatrix, |
| 132 | const SkRect& rect, |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 133 | const SkMatrix& localMatrix) { |
| 134 | this->drawFilledQuad(clip, std::move(paint), aa, |
| 135 | aa == GrAA::kYes ? GrQuadAAFlags::kAll : GrQuadAAFlags::kNone, |
| 136 | GrQuad::MakeFromRect(rect, viewMatrix), |
| 137 | GrQuad::MakeFromRect(rect, localMatrix)); |
| 138 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 139 | |
Michael Ludwig | 7545190 | 2019-01-23 11:14:29 -0500 | [diff] [blame] | 140 | /** |
| 141 | * Creates an op that draws a fill rect with per-edge control over anti-aliasing. |
Michael Ludwig | ce62dec | 2019-02-19 11:48:46 -0500 | [diff] [blame] | 142 | * |
| 143 | * This is a specialized version of fillQuadWithEdgeAA, but is kept separate since knowing |
| 144 | * the geometry is a rectangle affords more optimizations. |
Michael Ludwig | 7545190 | 2019-01-23 11:14:29 -0500 | [diff] [blame] | 145 | */ |
Michael Ludwig | 136f45a | 2019-02-19 11:44:41 -0500 | [diff] [blame] | 146 | void fillRectWithEdgeAA(const GrClip& clip, GrPaint&& paint, GrAA aa, GrQuadAAFlags edgeAA, |
| 147 | const SkMatrix& viewMatrix, const SkRect& rect, |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 148 | const SkRect* optionalLocalRect = nullptr) { |
| 149 | const SkRect& localRect = optionalLocalRect ? *optionalLocalRect : rect; |
| 150 | this->drawFilledQuad(clip, std::move(paint), aa, edgeAA, |
| 151 | GrQuad::MakeFromRect(rect, viewMatrix), GrQuad(localRect)); |
| 152 | } |
Michael Ludwig | 7545190 | 2019-01-23 11:14:29 -0500 | [diff] [blame] | 153 | |
Michael Ludwig | ce62dec | 2019-02-19 11:48:46 -0500 | [diff] [blame] | 154 | /** |
| 155 | * Similar to fillRectWithEdgeAA but draws an arbitrary 2D convex quadrilateral transformed |
| 156 | * by 'viewMatrix', with per-edge control over anti-aliasing. The quad should follow the |
| 157 | * ordering used by SkRect::toQuad(), which determines how the edge AA is applied: |
| 158 | * - "top" = points [0] and [1] |
| 159 | * - "right" = points[1] and [2] |
| 160 | * - "bottom" = points[2] and [3] |
| 161 | * - "left" = points[3] and [0] |
| 162 | * |
| 163 | * The last argument, 'optionalLocalQuad', can be null if no separate local coordinates are |
| 164 | * necessary. |
| 165 | */ |
| 166 | void fillQuadWithEdgeAA(const GrClip& clip, GrPaint&& paint, GrAA aa, GrQuadAAFlags edgeAA, |
| 167 | const SkMatrix& viewMatrix, const SkPoint quad[4], |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 168 | const SkPoint optionalLocalQuad[4]) { |
| 169 | const SkPoint* localQuad = optionalLocalQuad ? optionalLocalQuad : quad; |
| 170 | this->drawFilledQuad(clip, std::move(paint), aa, edgeAA, |
| 171 | GrQuad::MakeFromSkQuad(quad, viewMatrix), |
| 172 | GrQuad::MakeFromSkQuad(localQuad, SkMatrix::I())); |
| 173 | } |
Michael Ludwig | ce62dec | 2019-02-19 11:48:46 -0500 | [diff] [blame] | 174 | |
Michael Ludwig | 6985853 | 2018-11-28 15:34:34 -0500 | [diff] [blame] | 175 | /** Used with drawQuadSet */ |
| 176 | struct QuadSetEntry { |
| 177 | SkRect fRect; |
| 178 | SkPMColor4f fColor; // Overrides any color on the GrPaint |
| 179 | SkMatrix fLocalMatrix; |
| 180 | GrQuadAAFlags fAAFlags; |
| 181 | }; |
| 182 | |
Michael Ludwig | 7545190 | 2019-01-23 11:14:29 -0500 | [diff] [blame] | 183 | // TODO(michaelludwig) - remove if the bulk API is not useful for SkiaRenderer |
Michael Ludwig | 6985853 | 2018-11-28 15:34:34 -0500 | [diff] [blame] | 184 | void drawQuadSet(const GrClip& clip, GrPaint&& paint, GrAA aa, const SkMatrix& viewMatrix, |
| 185 | const QuadSetEntry[], int cnt); |
| 186 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 187 | /** |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 188 | * Creates an op that draws a subrectangle of a texture. The passed color is modulated by the |
| 189 | * texture's color. 'srcRect' specifies the rectangle of the texture to draw. 'dstRect' |
| 190 | * specifies the rectangle to draw in local coords which will be transformed by 'viewMatrix' to |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 191 | * device space. |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 192 | */ |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 193 | void drawTexture(const GrClip& clip, sk_sp<GrTextureProxy>, GrSamplerState::Filter, |
Michael Ludwig | d54ca8f | 2019-02-13 13:25:21 -0500 | [diff] [blame] | 194 | SkBlendMode mode, const SkPMColor4f&, const SkRect& srcRect, |
Michael Ludwig | 136f45a | 2019-02-19 11:44:41 -0500 | [diff] [blame] | 195 | const SkRect& dstRect, GrAA, GrQuadAAFlags, SkCanvas::SrcRectConstraint, |
Michael Ludwig | d54ca8f | 2019-02-13 13:25:21 -0500 | [diff] [blame] | 196 | const SkMatrix& viewMatrix, sk_sp<GrColorSpaceXform> texXform); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 197 | |
Michael Ludwig | ce62dec | 2019-02-19 11:48:46 -0500 | [diff] [blame] | 198 | /** |
| 199 | * Variant of drawTexture that instead draws the texture applied to 'dstQuad' transformed by |
| 200 | * 'viewMatrix', using the 'srcQuad' texture coordinates clamped to the optional 'domain'. If |
| 201 | * 'domain' is null, it's equivalent to using the fast src rect constraint. If 'domain' is |
| 202 | * provided, the strict src rect constraint is applied using 'domain'. |
| 203 | */ |
| 204 | void drawTextureQuad(const GrClip& clip, sk_sp<GrTextureProxy>, GrSamplerState::Filter, |
| 205 | SkBlendMode mode, const SkPMColor4f&, const SkPoint srcQuad[4], |
| 206 | const SkPoint dstQuad[4], GrAA, GrQuadAAFlags, const SkRect* domain, |
| 207 | const SkMatrix& viewMatrix, sk_sp<GrColorSpaceXform> texXform); |
| 208 | |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 209 | /** Used with drawTextureSet */ |
| 210 | struct TextureSetEntry { |
| 211 | sk_sp<GrTextureProxy> fProxy; |
| 212 | SkRect fSrcRect; |
| 213 | SkRect fDstRect; |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 214 | const SkPoint* fDstClipQuad; // Must be null, or point to an array of 4 points |
Michael Ludwig | 7ae2ab5 | 2019-03-05 16:00:20 -0500 | [diff] [blame] | 215 | const SkMatrix* fPreViewMatrix; // If not null, entry's CTM is 'viewMatrix' * fPreViewMatrix |
Brian Salomon | 1da5cad | 2018-11-21 09:21:18 -0500 | [diff] [blame] | 216 | float fAlpha; |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 217 | GrQuadAAFlags fAAFlags; |
| 218 | }; |
| 219 | /** |
| 220 | * Draws a set of textures with a shared filter, color, view matrix, color xform, and |
| 221 | * texture color xform. The textures must all have the same GrTextureType and GrConfig. |
Michael Ludwig | ce62dec | 2019-02-19 11:48:46 -0500 | [diff] [blame] | 222 | * |
| 223 | * If any entries provide a non-null fDstClip array, it will be read from immediately based on |
| 224 | * fDstClipCount, so the pointer can become invalid after this returns. |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 225 | */ |
| 226 | void drawTextureSet(const GrClip&, const TextureSetEntry[], int cnt, GrSamplerState::Filter, |
Michael Ludwig | 31ba718 | 2019-04-03 10:38:06 -0400 | [diff] [blame] | 227 | SkBlendMode mode, GrAA aa, SkCanvas::SrcRectConstraint, |
| 228 | const SkMatrix& viewMatrix, sk_sp<GrColorSpaceXform> texXform); |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 229 | |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 230 | /** |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 231 | * Draw a roundrect using a paint. |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 232 | * |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 233 | * @param paint describes how to color pixels. |
| 234 | * @param GrAA Controls whether rrect is antialiased. |
| 235 | * @param viewMatrix transformation matrix |
| 236 | * @param rrect the roundrect to draw |
| 237 | * @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] | 238 | */ |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 239 | void drawRRect(const GrClip&, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 240 | GrPaint&&, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 241 | GrAA, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 242 | const SkMatrix& viewMatrix, |
| 243 | const SkRRect& rrect, |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 244 | const GrStyle& style); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 245 | |
| 246 | /** |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 247 | * Use a fast method to render the ambient and spot shadows for a path. |
| 248 | * Will return false if not possible for the given path. |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 249 | * |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 250 | * @param viewMatrix transformation matrix |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 251 | * @param path the path to shadow |
| 252 | * @param rec parameters for shadow rendering |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 253 | */ |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 254 | bool drawFastShadow(const GrClip&, |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 255 | const SkMatrix& viewMatrix, |
| 256 | const SkPath& path, |
| 257 | const SkDrawShadowRec& rec); |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 258 | |
| 259 | /** |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 260 | * Shortcut for filling a SkPath consisting of nested rrects using a paint. The result is |
| 261 | * undefined if outer does not contain inner. |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 262 | * |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 263 | * @param paint describes how to color pixels. |
| 264 | * @param GrAA Controls whether rrects edges are antialiased |
| 265 | * @param viewMatrix transformation matrix |
| 266 | * @param outer the outer roundrect |
| 267 | * @param inner the inner roundrect |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 268 | */ |
| 269 | void drawDRRect(const GrClip&, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 270 | GrPaint&&, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 271 | GrAA, |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 272 | const SkMatrix& viewMatrix, |
| 273 | const SkRRect& outer, |
| 274 | const SkRRect& inner); |
| 275 | |
| 276 | /** |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 277 | * Draws a path. |
| 278 | * |
| 279 | * @param paint describes how to color pixels. |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 280 | * @param GrAA Controls whether the path is antialiased. |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 281 | * @param viewMatrix transformation matrix |
| 282 | * @param path the path to draw |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 283 | * @param style style to apply to the path. |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 284 | */ |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 285 | void drawPath(const GrClip&, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 286 | GrPaint&&, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 287 | GrAA, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 288 | const SkMatrix& viewMatrix, |
| 289 | const SkPath&, |
Robert Phillips | 20390c3 | 2018-08-17 11:01:03 -0400 | [diff] [blame] | 290 | const GrStyle&); |
| 291 | |
| 292 | /** |
| 293 | * Draws a shape. |
| 294 | * |
| 295 | * @param paint describes how to color pixels. |
| 296 | * @param GrAA Controls whether the path is antialiased. |
| 297 | * @param viewMatrix transformation matrix |
| 298 | * @param shape the shape to draw |
| 299 | */ |
| 300 | void drawShape(const GrClip&, |
| 301 | GrPaint&&, |
| 302 | GrAA, |
| 303 | const SkMatrix& viewMatrix, |
| 304 | const GrShape&); |
| 305 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 306 | |
| 307 | /** |
| 308 | * Draws vertices with a paint. |
| 309 | * |
Brian Osman | ae0c50c | 2017-05-25 16:56:34 -0400 | [diff] [blame] | 310 | * @param paint describes how to color pixels. |
| 311 | * @param viewMatrix transformation matrix |
| 312 | * @param vertices specifies the mesh to draw. |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 313 | * @param bones bone deformation matrices. |
| 314 | * @param boneCount number of bone matrices. |
Brian Osman | ae0c50c | 2017-05-25 16:56:34 -0400 | [diff] [blame] | 315 | * @param overridePrimType primitive type to draw. If NULL, derive prim type from vertices. |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 316 | */ |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 317 | void drawVertices(const GrClip&, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 318 | GrPaint&& paint, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 319 | const SkMatrix& viewMatrix, |
Brian Osman | ae0c50c | 2017-05-25 16:56:34 -0400 | [diff] [blame] | 320 | sk_sp<SkVertices> vertices, |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 321 | const SkVertices::Bone bones[], |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 322 | int boneCount, |
Brian Osman | ae0c50c | 2017-05-25 16:56:34 -0400 | [diff] [blame] | 323 | GrPrimitiveType* overridePrimType = nullptr); |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 324 | |
| 325 | /** |
Brian Osman | 4d92b89 | 2019-03-24 00:53:23 +0000 | [diff] [blame] | 326 | * Draws textured sprites from an atlas with a paint. This currently does not support AA for the |
| 327 | * sprite rectangle edges. |
| 328 | * |
| 329 | * @param paint describes how to color pixels. |
| 330 | * @param viewMatrix transformation matrix |
| 331 | * @param spriteCount number of sprites. |
| 332 | * @param xform array of compressed transformation data, required. |
| 333 | * @param texRect array of texture rectangles used to access the paint. |
| 334 | * @param colors optional array of per-sprite colors, supercedes |
| 335 | * the paint's color field. |
| 336 | */ |
| 337 | void drawAtlas(const GrClip&, |
| 338 | GrPaint&& paint, |
| 339 | const SkMatrix& viewMatrix, |
| 340 | int spriteCount, |
| 341 | const SkRSXform xform[], |
| 342 | const SkRect texRect[], |
| 343 | const SkColor colors[]); |
| 344 | |
| 345 | /** |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 346 | * Draws a region. |
| 347 | * |
| 348 | * @param paint describes how to color pixels |
| 349 | * @param viewMatrix transformation matrix |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 350 | * @param aa should the rects of the region be antialiased. |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 351 | * @param region the region to be drawn |
| 352 | * @param style style to apply to the region |
| 353 | */ |
| 354 | void drawRegion(const GrClip&, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 355 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 356 | GrAA aa, |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 357 | const SkMatrix& viewMatrix, |
| 358 | const SkRegion& region, |
Stan Iliev | 73d8fd9 | 2017-08-02 15:36:24 -0400 | [diff] [blame] | 359 | const GrStyle& style, |
| 360 | const GrUserStencilSettings* ss = nullptr); |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 361 | |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 362 | /** |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 363 | * Draws an oval. |
| 364 | * |
| 365 | * @param paint describes how to color pixels. |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 366 | * @param GrAA Controls whether the oval is antialiased. |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 367 | * @param viewMatrix transformation matrix |
| 368 | * @param oval the bounding rect of the oval. |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 369 | * @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] | 370 | */ |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 371 | void drawOval(const GrClip&, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 372 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 373 | GrAA, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 374 | const SkMatrix& viewMatrix, |
| 375 | const SkRect& oval, |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 376 | const GrStyle& style); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 377 | /** |
| 378 | * Draws a partial arc of an oval. |
| 379 | * |
| 380 | * @param paint describes how to color pixels. |
Brian Salomon | 9950408 | 2016-12-09 15:51:31 -0500 | [diff] [blame] | 381 | * @param GrGrAA Controls whether the arc is antialiased. |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 382 | * @param viewMatrix transformation matrix. |
| 383 | * @param oval the bounding rect of the oval. |
| 384 | * @param startAngle starting angle in degrees. |
| 385 | * @param sweepAngle angle to sweep in degrees. Must be in (-360, 360) |
| 386 | * @param useCenter true means that the implied path begins at the oval center, connects as |
| 387 | * a line to the point indicated by the start contains the arc indicated by |
| 388 | * the sweep angle. If false the line beginning at the center point is |
| 389 | * omitted. |
| 390 | * @param style style to apply to the oval. |
| 391 | */ |
bsalomon | 4f3a0ca | 2016-08-22 13:14:26 -0700 | [diff] [blame] | 392 | void drawArc(const GrClip&, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 393 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 394 | GrAA, |
bsalomon | 4f3a0ca | 2016-08-22 13:14:26 -0700 | [diff] [blame] | 395 | const SkMatrix& viewMatrix, |
| 396 | const SkRect& oval, |
| 397 | SkScalar startAngle, |
| 398 | SkScalar sweepAngle, |
| 399 | bool useCenter, |
| 400 | const GrStyle& style); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 401 | |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 402 | /** |
bsalomon | 4f3a0ca | 2016-08-22 13:14:26 -0700 | [diff] [blame] | 403 | * Draw the image as a set of rects, specified by |iter|. |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 404 | */ |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 405 | void drawImageLattice(const GrClip&, |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 406 | GrPaint&&, |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 407 | const SkMatrix& viewMatrix, |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 408 | sk_sp<GrTextureProxy>, |
| 409 | sk_sp<GrColorSpaceXform>, |
| 410 | GrSamplerState::Filter, |
| 411 | std::unique_ptr<SkLatticeIter>, |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 412 | const SkRect& dst); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 413 | |
robertphillips | 8c523e0 | 2016-07-26 07:41:00 -0700 | [diff] [blame] | 414 | /** |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 415 | * Draws the src texture with no matrix. The dstRect is the dstPoint with the width and height |
| 416 | * of the srcRect. The srcRect and dstRect are clipped to the bounds of the src and dst surfaces |
| 417 | * respectively. |
| 418 | */ |
| 419 | bool blitTexture(GrTextureProxy* src, const SkIRect& srcRect, const SkIPoint& dstPoint); |
| 420 | |
| 421 | /** |
Greg Daniel | 64cc9aa | 2018-10-19 13:54:56 -0400 | [diff] [blame] | 422 | * Adds the necessary signal and wait semaphores and adds the passed in SkDrawable to the |
| 423 | * command stream. |
| 424 | */ |
| 425 | void drawDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler>, const SkRect& bounds); |
| 426 | |
Brian Salomon | ab32f65 | 2019-05-10 14:24:50 -0400 | [diff] [blame] | 427 | using ReadPixelsCallback = SkSurface::ReadPixelsCallback; |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 428 | using ReadPixelsCallbackYUV420 = SkSurface::ReadPixelsCallbackYUV420; |
Brian Salomon | ab32f65 | 2019-05-10 14:24:50 -0400 | [diff] [blame] | 429 | using ReadPixelsContext = SkSurface::ReadPixelsContext; |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 430 | using RescaleGamma = SkSurface::RescaleGamma; |
| 431 | |
| 432 | // GPU implementation for SkSurface::asyncRescaleAndReadPixels. |
Brian Salomon | 031b0ba | 2019-05-23 11:05:26 -0400 | [diff] [blame] | 433 | void asyncRescaleAndReadPixels(const SkImageInfo& info, const SkIRect& srcRect, |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 434 | RescaleGamma rescaleGamma, SkFilterQuality rescaleQuality, |
| 435 | ReadPixelsCallback callback, ReadPixelsContext context); |
| 436 | // GPU implementation for SkSurface::asyncRescaleAndReadPixelsYUV420. |
| 437 | void asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace, |
| 438 | sk_sp<SkColorSpace> dstColorSpace, const SkIRect& srcRect, |
| 439 | int dstW, int dstH, RescaleGamma rescaleGamma, |
| 440 | SkFilterQuality rescaleQuality, |
| 441 | ReadPixelsCallbackYUV420 callback, |
| 442 | ReadPixelsContext context); |
Brian Salomon | ab32f65 | 2019-05-10 14:24:50 -0400 | [diff] [blame] | 443 | |
Greg Daniel | 64cc9aa | 2018-10-19 13:54:56 -0400 | [diff] [blame] | 444 | /** |
robertphillips | 8c523e0 | 2016-07-26 07:41:00 -0700 | [diff] [blame] | 445 | * After this returns any pending surface IO will be issued to the backend 3D API and |
| 446 | * if the surface has MSAA it will be resolved. |
| 447 | */ |
Greg Daniel | e6bfb7d | 2019-04-17 15:26:11 -0400 | [diff] [blame] | 448 | GrSemaphoresSubmitted flush(SkSurface::BackendSurfaceAccess access, const GrFlushInfo&); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 449 | |
| 450 | /** |
| 451 | * The next time this GrRenderTargetContext is flushed, the gpu will wait on the passed in |
| 452 | * semaphores before executing any commands. |
| 453 | */ |
Robert Phillips | bc4994a | 2019-02-14 08:36:56 -0500 | [diff] [blame] | 454 | bool waitOnSemaphores(int numSemaphores, const GrBackendSemaphore waitSemaphores[]); |
robertphillips | 8c523e0 | 2016-07-26 07:41:00 -0700 | [diff] [blame] | 455 | |
Robert Phillips | 65a88fa | 2017-08-08 08:36:22 -0400 | [diff] [blame] | 456 | void insertEventMarker(const SkString&); |
| 457 | |
Robert Phillips | be9aff2 | 2019-02-15 11:33:22 -0500 | [diff] [blame] | 458 | const GrCaps* caps() const; |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 459 | int width() const { return fRenderTargetProxy->width(); } |
| 460 | int height() const { return fRenderTargetProxy->height(); } |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 461 | int numSamples() const { return fRenderTargetProxy->numSamples(); } |
robertphillips | ca6eafc | 2016-05-17 09:57:46 -0700 | [diff] [blame] | 462 | const SkSurfaceProps& surfaceProps() const { return fSurfaceProps; } |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 463 | GrSurfaceOrigin origin() const { return fRenderTargetProxy->origin(); } |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 464 | bool wrapsVkSecondaryCB() const { return fRenderTargetProxy->wrapsVkSecondaryCB(); } |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 465 | GrMipMapped mipMapped() const; |
robertphillips | 7bceedc | 2015-12-01 12:51:26 -0800 | [diff] [blame] | 466 | |
Robert Phillips | be9aff2 | 2019-02-15 11:33:22 -0500 | [diff] [blame] | 467 | // This entry point should only be called if the backing GPU object is known to be |
| 468 | // instantiated. |
| 469 | GrRenderTarget* accessRenderTarget() { return fRenderTargetProxy->peekRenderTarget(); } |
robertphillips | 6c7e325 | 2016-04-27 10:47:51 -0700 | [diff] [blame] | 470 | |
Robert Phillips | f200a90 | 2017-01-30 13:27:37 -0500 | [diff] [blame] | 471 | GrSurfaceProxy* asSurfaceProxy() override { return fRenderTargetProxy.get(); } |
| 472 | const GrSurfaceProxy* asSurfaceProxy() const override { return fRenderTargetProxy.get(); } |
| 473 | sk_sp<GrSurfaceProxy> asSurfaceProxyRef() override { return fRenderTargetProxy; } |
| 474 | |
| 475 | GrTextureProxy* asTextureProxy() override; |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 476 | const GrTextureProxy* asTextureProxy() const override; |
Robert Phillips | f200a90 | 2017-01-30 13:27:37 -0500 | [diff] [blame] | 477 | sk_sp<GrTextureProxy> asTextureProxyRef() override; |
| 478 | |
| 479 | GrRenderTargetProxy* asRenderTargetProxy() override { return fRenderTargetProxy.get(); } |
| 480 | sk_sp<GrRenderTargetProxy> asRenderTargetProxyRef() override { return fRenderTargetProxy; } |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 481 | |
Robert Phillips | d46697a | 2017-01-25 12:10:37 -0500 | [diff] [blame] | 482 | GrRenderTargetContext* asRenderTargetContext() override { return this; } |
| 483 | |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 484 | // Provides access to functions that aren't part of the public API. |
Brian Osman | 693a540 | 2016-10-27 15:13:22 -0400 | [diff] [blame] | 485 | GrRenderTargetContextPriv priv(); |
| 486 | const GrRenderTargetContextPriv priv() const; |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 487 | |
Herb Derby | c1b482c | 2018-08-09 15:02:27 -0400 | [diff] [blame] | 488 | GrTextTarget* textTarget() { return fTextTarget.get(); } |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 489 | |
Robert Phillips | b520476 | 2019-06-19 14:12:13 -0400 | [diff] [blame] | 490 | #if GR_TEST_UTILS |
| 491 | bool testingOnly_IsInstantiated() const { return fRenderTargetProxy->isInstantiated(); } |
Chris Dalton | 6b98280 | 2019-06-27 13:53:46 -0600 | [diff] [blame] | 492 | void testingOnly_SetPreserveOpsOnFullClear() { fPreserveOpsOnFullClear_TestingOnly = true; } |
Robert Phillips | b520476 | 2019-06-19 14:12:13 -0400 | [diff] [blame] | 493 | #endif |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 494 | |
joshualitt | 96880d9 | 2016-02-16 10:36:53 -0800 | [diff] [blame] | 495 | protected: |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 496 | GrRenderTargetContext(GrRecordingContext*, sk_sp<GrRenderTargetProxy>, GrColorType, |
| 497 | sk_sp<SkColorSpace>, const SkSurfaceProps*, bool managedOpList = true); |
joshualitt | 96880d9 | 2016-02-16 10:36:53 -0800 | [diff] [blame] | 498 | |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 499 | SkDEBUGCODE(void validate() const override;) |
joshualitt | 96880d9 | 2016-02-16 10:36:53 -0800 | [diff] [blame] | 500 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 501 | private: |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 502 | class TextTarget; |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 503 | enum class QuadOptimization; |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 504 | |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 505 | GrAAType chooseAAType(GrAA); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 506 | |
Brian Salomon | 649a341 | 2017-03-09 13:50:43 -0500 | [diff] [blame] | 507 | friend class GrAtlasTextBlob; // for access to add[Mesh]DrawOp |
Brian Osman | 5d03474 | 2017-09-11 13:38:55 -0400 | [diff] [blame] | 508 | friend class GrClipStackClip; // for access to getOpList |
robertphillips | 55fdccc | 2016-06-06 06:16:20 -0700 | [diff] [blame] | 509 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 510 | friend class GrDrawingManager; // for ctor |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 511 | friend class GrRenderTargetContextPriv; |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 512 | |
Brian Salomon | 42521e8 | 2016-12-07 16:44:58 -0500 | [diff] [blame] | 513 | // All the path renderers currently make their own ops |
Brian Salomon | 649a341 | 2017-03-09 13:50:43 -0500 | [diff] [blame] | 514 | friend class GrSoftwarePathRenderer; // for access to add[Mesh]DrawOp |
| 515 | friend class GrAAConvexPathRenderer; // for access to add[Mesh]DrawOp |
| 516 | friend class GrDashLinePathRenderer; // for access to add[Mesh]DrawOp |
| 517 | friend class GrAAHairLinePathRenderer; // for access to add[Mesh]DrawOp |
| 518 | friend class GrAALinearizingConvexPathRenderer; // for access to add[Mesh]DrawOp |
Jim Van Verth | 8301046 | 2017-03-16 08:45:39 -0400 | [diff] [blame] | 519 | friend class GrSmallPathRenderer; // for access to add[Mesh]DrawOp |
Brian Salomon | 649a341 | 2017-03-09 13:50:43 -0500 | [diff] [blame] | 520 | friend class GrDefaultPathRenderer; // for access to add[Mesh]DrawOp |
Brian Salomon | 649a341 | 2017-03-09 13:50:43 -0500 | [diff] [blame] | 521 | friend class GrStencilAndCoverPathRenderer; // for access to add[Mesh]DrawOp |
| 522 | friend class GrTessellatingPathRenderer; // for access to add[Mesh]DrawOp |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 523 | friend class GrCCPerFlushResources; // for access to addDrawOp |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 524 | friend class GrCoverageCountingPathRenderer; // for access to addDrawOp |
Brian Salomon | 5d4cd9e | 2017-02-09 11:16:46 -0500 | [diff] [blame] | 525 | // for a unit test |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 526 | friend void test_draw_op(GrContext*, |
| 527 | GrRenderTargetContext*, |
| 528 | std::unique_ptr<GrFragmentProcessor>, |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 529 | sk_sp<GrTextureProxy>); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 530 | |
Chris Dalton | 6b98280 | 2019-06-27 13:53:46 -0600 | [diff] [blame] | 531 | GrRenderTargetOpList::CanDiscardPreviousOps canDiscardPreviousOpsOnFullClear() const; |
| 532 | void setNeedsStencil(); |
| 533 | |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 534 | void internalClear(const GrFixedClip&, const SkPMColor4f&, CanClearFullscreen); |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 535 | void internalStencilClear(const GrFixedClip&, bool insideStencilMask); |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 536 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 537 | // Only consumes the GrPaint if successful. |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 538 | bool drawFilledDRRect(const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 539 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 540 | GrAA, |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 541 | const SkMatrix& viewMatrix, |
| 542 | const SkRRect& origOuter, |
| 543 | const SkRRect& origInner); |
| 544 | |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 545 | // If the drawn quad's paint is a const blended color, provide it as a non-null pointer to |
| 546 | // 'constColor', which enables the draw-as-clear optimization. Otherwise it is assumed the paint |
| 547 | // requires some form of shading that invalidates using a clear op. |
| 548 | // |
| 549 | // The non-const pointers should be the original draw request on input, and will be updated as |
| 550 | // appropriate depending on the returned optimization level. |
| 551 | // |
Michael Ludwig | e08b443 | 2019-06-19 18:00:48 -0400 | [diff] [blame] | 552 | // 'stencilSettings' are provided merely for decision making purposes; When non-null, |
| 553 | // optimization strategies that submit special ops are avoided. |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 554 | QuadOptimization attemptQuadOptimization(const GrClip& clip, |
| 555 | const SkPMColor4f* constColor, |
Michael Ludwig | e08b443 | 2019-06-19 18:00:48 -0400 | [diff] [blame] | 556 | const GrUserStencilSettings* stencilSettings, |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 557 | GrAA* aa, |
| 558 | GrQuadAAFlags* edgeFlags, |
| 559 | GrQuad* deviceQuad, |
| 560 | GrQuad* localQuad); |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 561 | |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 562 | // If stencil settings, 'ss', are non-null, AA controls MSAA or no AA. If they are null, then AA |
| 563 | // can choose between coverage, MSAA as per chooseAAType(). This will always attempt to apply |
| 564 | // quad optimizations, so all quad/rect public APIs should rely on this function for consistent |
| 565 | // clipping behavior. |
| 566 | void drawFilledQuad(const GrClip& clip, |
| 567 | GrPaint&& paint, |
| 568 | GrAA aa, |
| 569 | GrQuadAAFlags edgeFlags, |
| 570 | const GrQuad& deviceQuad, |
| 571 | const GrQuad& localQuad, |
| 572 | const GrUserStencilSettings* ss = nullptr); |
Brian Salomon | 7694b90 | 2019-06-18 21:00:21 +0000 | [diff] [blame] | 573 | |
Brian Salomon | 2fad74a | 2017-12-20 13:28:55 -0500 | [diff] [blame] | 574 | void drawShapeUsingPathRenderer(const GrClip&, GrPaint&&, GrAA, const SkMatrix&, |
| 575 | const GrShape&); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 576 | |
Brian Salomon | 348a037 | 2018-10-31 10:42:18 -0400 | [diff] [blame] | 577 | // Allows caller of addDrawOp to know which op list an op will be added to. |
| 578 | using WillAddOpFn = void(GrOp*, uint32_t opListID); |
| 579 | // These perform processing specific to GrDrawOp-derived ops before recording them into an |
| 580 | // op list. Before adding the op to an op list the WillAddOpFn is called. Note that it |
| 581 | // will not be called in the event that the op is discarded. Moreover, the op may merge into |
| 582 | // another op after the function is called (either before addDrawOp returns or some time later). |
| 583 | void addDrawOp(const GrClip&, std::unique_ptr<GrDrawOp>, |
| 584 | const std::function<WillAddOpFn>& = std::function<WillAddOpFn>()); |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 585 | |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 586 | // Makes a copy of the proxy if it is necessary for the draw and places the texture that should |
| 587 | // be used by GrXferProcessor to access the destination color in 'result'. If the return |
| 588 | // value is false then a texture copy could not be made. |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 589 | bool SK_WARN_UNUSED_RESULT setupDstProxy(GrRenderTargetProxy*, |
| 590 | const GrClip&, |
Brian Salomon | 09181ef | 2018-11-14 13:39:51 -0500 | [diff] [blame] | 591 | const GrOp& op, |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 592 | GrXferProcessor::DstProxy* result); |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 593 | |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 594 | // The rescaling step of asyncRescaleAndReadPixels[YUV420](). |
Brian Salomon | 031b0ba | 2019-05-23 11:05:26 -0400 | [diff] [blame] | 595 | sk_sp<GrRenderTargetContext> rescale(const SkImageInfo& info, const SkIRect& srcRect, |
| 596 | SkSurface::RescaleGamma rescaleGamma, |
| 597 | SkFilterQuality rescaleQuality); |
Brian Salomon | 024bd00 | 2019-06-11 11:38:16 -0400 | [diff] [blame] | 598 | // The async read step of asyncRescaleAndReadPixels() |
| 599 | void asyncReadPixels(const SkIRect& rect, SkColorType colorType, ReadPixelsCallback callback, |
| 600 | ReadPixelsContext context); |
| 601 | |
| 602 | // Inserts a transfer, part of the implementation of asyncReadPixels and |
| 603 | // asyncRescaleAndReadPixelsYUV420(). |
| 604 | struct PixelTransferResult { |
| 605 | using ConversionSignature = void(void* dst, const void* mappedBuffer); |
| 606 | // If null then the transfer could not be performed. Otherwise this buffer will contain |
| 607 | // the pixel data when the transfer is complete. |
| 608 | sk_sp<GrGpuBuffer> fTransferBuffer; |
| 609 | // If this is null then the transfer buffer will contain the data in the requested |
| 610 | // color type. Otherwise, when the transfer is done this must be called to convert |
| 611 | // from the transfer buffer's color type to the requested color type. |
| 612 | std::function<ConversionSignature> fPixelConverter; |
| 613 | }; |
| 614 | // Inserts a transfer of rect to a buffer that this call will create. |
| 615 | PixelTransferResult transferPixels(GrColorType colorType, const SkIRect& rect); |
Brian Salomon | 031b0ba | 2019-05-23 11:05:26 -0400 | [diff] [blame] | 616 | |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 617 | GrRenderTargetOpList* getRTOpList(); |
| 618 | GrOpList* getOpList() override; |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 619 | |
Herb Derby | c1b482c | 2018-08-09 15:02:27 -0400 | [diff] [blame] | 620 | std::unique_ptr<GrTextTarget> fTextTarget; |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 621 | sk_sp<GrRenderTargetProxy> fRenderTargetProxy; |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 622 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 623 | // 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] | 624 | // it up. For this reason, the GrOpList should only ever be accessed via 'getOpList'. |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 625 | sk_sp<GrRenderTargetOpList> fOpList; |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 626 | |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 627 | SkSurfaceProps fSurfaceProps; |
| 628 | bool fManagedOpList; |
Robert Phillips | e305cc1f | 2016-12-14 12:19:05 -0500 | [diff] [blame] | 629 | |
Chris Dalton | 6b98280 | 2019-06-27 13:53:46 -0600 | [diff] [blame] | 630 | bool fNeedsStencil = false; |
| 631 | #if GR_TEST_UTILS |
| 632 | bool fPreserveOpsOnFullClear_TestingOnly = false; |
| 633 | #endif |
| 634 | |
Robert Phillips | e305cc1f | 2016-12-14 12:19:05 -0500 | [diff] [blame] | 635 | typedef GrSurfaceContext INHERITED; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 636 | }; |
| 637 | |
| 638 | #endif |