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 Salomon | eebe735 | 2020-12-09 16:37:04 -0500 | [diff] [blame] | 8 | #ifndef GrSurfaceDrawContext_DEFINED |
| 9 | #define GrSurfaceDrawContext_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" |
Herb Derby | d29207a | 2020-06-08 13:50:19 -0400 | [diff] [blame] | 17 | #include "src/core/SkGlyphRunPainter.h" |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 18 | #include "src/gpu/GrOpsTask.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 19 | #include "src/gpu/GrPaint.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 20 | #include "src/gpu/GrRenderTargetProxy.h" |
Brian Salomon | 590f567 | 2020-12-16 11:44:47 -0500 | [diff] [blame] | 21 | #include "src/gpu/GrSurfaceFillContext.h" |
Greg Daniel | a83de58 | 2019-10-22 09:33:25 -0400 | [diff] [blame] | 22 | #include "src/gpu/GrSurfaceProxyView.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 23 | #include "src/gpu/GrXferProcessor.h" |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 24 | #include "src/gpu/geometry/GrQuad.h" |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 25 | |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 26 | class GrBackendSemaphore; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 27 | class GrClip; |
Brian Osman | 2240be9 | 2017-10-18 13:15:13 -0400 | [diff] [blame] | 28 | class GrColorSpaceXform; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 29 | class GrCoverageCountingPathRenderer; |
Brian Salomon | 9afd371 | 2016-12-01 10:59:09 -0500 | [diff] [blame] | 30 | class GrDrawOp; |
Robert Phillips | 0d075de | 2019-03-04 11:08:13 -0500 | [diff] [blame] | 31 | class GrOp; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 32 | class GrRenderTarget; |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 33 | class GrStyledShape; |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 34 | class GrStyle; |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 35 | class GrTextureProxy; |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 36 | struct GrUserStencilSettings; |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 37 | struct SkDrawShadowRec; |
Herb Derby | cddab25 | 2018-07-16 11:19:04 -0400 | [diff] [blame] | 38 | class SkGlyphRunList; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 39 | struct SkIPoint; |
| 40 | struct SkIRect; |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 41 | class SkLatticeIter; |
Brian Osman | 449b115 | 2020-04-15 16:43:00 -0400 | [diff] [blame] | 42 | class SkMatrixProvider; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 43 | class SkMatrix; |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 44 | class SkPaint; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 45 | class SkPath; |
| 46 | struct SkPoint; |
| 47 | struct SkRect; |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 48 | class SkRegion; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 49 | class SkRRect; |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 50 | struct SkRSXform; |
Brian Osman | 3c35842 | 2020-03-23 10:44:12 -0400 | [diff] [blame] | 51 | class SkRuntimeEffect; |
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 Salomon | 590f567 | 2020-12-16 11:44:47 -0500 | [diff] [blame] | 58 | class GrSurfaceDrawContext : public GrSurfaceFillContext { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 59 | public: |
Brian Salomon | eebe735 | 2020-12-09 16:37:04 -0500 | [diff] [blame] | 60 | static std::unique_ptr<GrSurfaceDrawContext> Make(GrRecordingContext*, |
| 61 | GrColorType, |
| 62 | sk_sp<SkColorSpace>, |
| 63 | sk_sp<GrSurfaceProxy>, |
| 64 | GrSurfaceOrigin, |
Chris Dalton | f5b87f9 | 2021-04-19 17:27:09 -0600 | [diff] [blame] | 65 | const SkSurfaceProps&, |
Brian Salomon | eebe735 | 2020-12-09 16:37:04 -0500 | [diff] [blame] | 66 | bool flushTimeOpsTask = false); |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 67 | |
Brian Salomon | 07bc9a2 | 2020-12-02 13:37:16 -0500 | [diff] [blame] | 68 | /* Uses the default texture format for the color type */ |
Brian Salomon | eebe735 | 2020-12-09 16:37:04 -0500 | [diff] [blame] | 69 | static std::unique_ptr<GrSurfaceDrawContext> Make(GrRecordingContext*, |
| 70 | GrColorType, |
| 71 | sk_sp<SkColorSpace>, |
| 72 | SkBackingFit, |
| 73 | SkISize dimensions, |
Chris Dalton | f5b87f9 | 2021-04-19 17:27:09 -0600 | [diff] [blame] | 74 | const SkSurfaceProps&, |
Brian Salomon | eebe735 | 2020-12-09 16:37:04 -0500 | [diff] [blame] | 75 | int sampleCnt = 1, |
| 76 | GrMipmapped = GrMipmapped::kNo, |
| 77 | GrProtected = GrProtected::kNo, |
| 78 | GrSurfaceOrigin = kBottomLeft_GrSurfaceOrigin, |
Chris Dalton | f5b87f9 | 2021-04-19 17:27:09 -0600 | [diff] [blame] | 79 | SkBudgeted = SkBudgeted::kYes); |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 80 | |
Brian Salomon | 07bc9a2 | 2020-12-02 13:37:16 -0500 | [diff] [blame] | 81 | /** |
| 82 | * Takes custom swizzles rather than determining swizzles from color type and format. |
| 83 | * It will have color type kUnknown. |
| 84 | */ |
Brian Salomon | eebe735 | 2020-12-09 16:37:04 -0500 | [diff] [blame] | 85 | static std::unique_ptr<GrSurfaceDrawContext> Make(GrRecordingContext*, |
| 86 | sk_sp<SkColorSpace>, |
| 87 | SkBackingFit, |
| 88 | SkISize dimensions, |
| 89 | const GrBackendFormat&, |
| 90 | int sampleCnt, |
| 91 | GrMipmapped, |
| 92 | GrProtected, |
| 93 | GrSwizzle readSwizzle, |
| 94 | GrSwizzle writeSwizzle, |
| 95 | GrSurfaceOrigin, |
| 96 | SkBudgeted, |
Chris Dalton | f5b87f9 | 2021-04-19 17:27:09 -0600 | [diff] [blame] | 97 | const SkSurfaceProps&); |
Brian Salomon | 07bc9a2 | 2020-12-02 13:37:16 -0500 | [diff] [blame] | 98 | |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 99 | // Same as previous factory but will try to use fallback GrColorTypes if the one passed in |
| 100 | // fails. The fallback GrColorType will have at least the number of channels and precision per |
| 101 | // channel as the passed in GrColorType. It may also swizzle the changes (e.g., BGRA -> RGBA). |
| 102 | // SRGB-ness will be preserved. |
Brian Salomon | eebe735 | 2020-12-09 16:37:04 -0500 | [diff] [blame] | 103 | static std::unique_ptr<GrSurfaceDrawContext> MakeWithFallback( |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 104 | GrRecordingContext*, |
| 105 | GrColorType, |
| 106 | sk_sp<SkColorSpace>, |
| 107 | SkBackingFit, |
| 108 | SkISize dimensions, |
Chris Dalton | f5b87f9 | 2021-04-19 17:27:09 -0600 | [diff] [blame] | 109 | const SkSurfaceProps&, |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 110 | int sampleCnt = 1, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 111 | GrMipmapped = GrMipmapped::kNo, |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 112 | GrProtected = GrProtected::kNo, |
| 113 | GrSurfaceOrigin = kBottomLeft_GrSurfaceOrigin, |
Chris Dalton | f5b87f9 | 2021-04-19 17:27:09 -0600 | [diff] [blame] | 114 | SkBudgeted = SkBudgeted::kYes); |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 115 | |
Greg Daniel | ba0ff78 | 2020-01-07 15:42:57 -0500 | [diff] [blame] | 116 | // These match the definitions in SkSurface & GrSurface.h, for whence they came |
| 117 | typedef void* ReleaseContext; |
| 118 | typedef void (*ReleaseProc)(ReleaseContext); |
| 119 | |
Brian Salomon | eebe735 | 2020-12-09 16:37:04 -0500 | [diff] [blame] | 120 | // Creates a GrSurfaceDrawContext that wraps the passed in GrBackendTexture. |
| 121 | static std::unique_ptr<GrSurfaceDrawContext> MakeFromBackendTexture( |
Greg Daniel | ba0ff78 | 2020-01-07 15:42:57 -0500 | [diff] [blame] | 122 | GrRecordingContext*, GrColorType, sk_sp<SkColorSpace>, const GrBackendTexture&, |
Chris Dalton | f5b87f9 | 2021-04-19 17:27:09 -0600 | [diff] [blame] | 123 | int sampleCnt, GrSurfaceOrigin, const SkSurfaceProps&, |
Robert Phillips | a112133 | 2020-06-29 13:05:29 -0400 | [diff] [blame] | 124 | sk_sp<GrRefCntedCallback> releaseHelper); |
Greg Daniel | ba0ff78 | 2020-01-07 15:42:57 -0500 | [diff] [blame] | 125 | |
Brian Salomon | eebe735 | 2020-12-09 16:37:04 -0500 | [diff] [blame] | 126 | GrSurfaceDrawContext(GrRecordingContext*, |
| 127 | GrSurfaceProxyView readView, |
| 128 | GrSurfaceProxyView writeView, |
| 129 | GrColorType, |
| 130 | sk_sp<SkColorSpace>, |
Chris Dalton | f5b87f9 | 2021-04-19 17:27:09 -0600 | [diff] [blame] | 131 | const SkSurfaceProps&, |
Brian Salomon | eebe735 | 2020-12-09 16:37:04 -0500 | [diff] [blame] | 132 | bool flushTimeOpsTask = false); |
Greg Daniel | bfa19c4 | 2019-12-19 16:41:40 -0500 | [diff] [blame] | 133 | |
Brian Salomon | eebe735 | 2020-12-09 16:37:04 -0500 | [diff] [blame] | 134 | ~GrSurfaceDrawContext() override; |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 135 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 136 | /** |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 137 | * Draw everywhere (respecting the clip) with the paint. |
| 138 | */ |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 139 | void drawPaint(const GrClip*, GrPaint&&, const SkMatrix& viewMatrix); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 140 | |
| 141 | /** |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 142 | * Draw the rect using a paint. |
| 143 | * @param paint describes how to color pixels. |
| 144 | * @param GrAA Controls whether rect is antialiased |
| 145 | * @param viewMatrix transformation matrix |
| 146 | * @param style The style to apply. Null means fill. Currently path effects are not |
| 147 | * allowed. |
| 148 | * The rects coords are used to access the paint (through texture matrix) |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 149 | */ |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 150 | void drawRect(const GrClip*, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 151 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 152 | GrAA, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 153 | const SkMatrix& viewMatrix, |
| 154 | const SkRect&, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 155 | const GrStyle* style = nullptr); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 156 | |
| 157 | /** |
bsalomon | a2e69fc | 2015-11-05 10:41:43 -0800 | [diff] [blame] | 158 | * Maps a rectangle of shader coordinates to a rectangle and fills that rectangle. |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 159 | * |
Chris Dalton | 61d694d | 2021-03-22 00:00:52 -0600 | [diff] [blame] | 160 | * @param GrPaint describes how to color pixels. |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 161 | * @param GrAA Controls whether rect is antialiased |
Chris Dalton | 61d694d | 2021-03-22 00:00:52 -0600 | [diff] [blame] | 162 | * @param SkMatrix transformation matrix which applies to rectToDraw |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 163 | * @param rectToDraw the rectangle to draw |
| 164 | * @param localRect the rectangle of shader coordinates applied to rectToDraw |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 165 | */ |
Chris Dalton | 61d694d | 2021-03-22 00:00:52 -0600 | [diff] [blame] | 166 | void fillRectToRect(const GrClip*, |
| 167 | GrPaint&&, |
| 168 | GrAA, |
| 169 | const SkMatrix&, |
bsalomon | a2e69fc | 2015-11-05 10:41:43 -0800 | [diff] [blame] | 170 | const SkRect& rectToDraw, |
Chris Dalton | 61d694d | 2021-03-22 00:00:52 -0600 | [diff] [blame] | 171 | const SkRect& localRect); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 172 | |
| 173 | /** |
Chris Dalton | 3561955 | 2021-03-10 19:20:43 -0700 | [diff] [blame] | 174 | * Fills a block of pixels with a paint and a localMatrix, respecting the clip. |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 175 | */ |
Chris Dalton | 3561955 | 2021-03-10 19:20:43 -0700 | [diff] [blame] | 176 | void fillPixelsWithLocalMatrix(const GrClip* clip, |
| 177 | GrPaint&& paint, |
| 178 | const SkIRect& bounds, |
| 179 | const SkMatrix& localMatrix) { |
| 180 | SkRect rect = SkRect::Make(bounds); |
| 181 | DrawQuad quad{GrQuad::MakeFromRect(rect, SkMatrix::I()), |
| 182 | GrQuad::MakeFromRect(rect, localMatrix), GrQuadAAFlags::kNone}; |
| 183 | this->drawFilledQuad(clip, std::move(paint), GrAA::kNo, &quad); |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 184 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 185 | |
Michael Ludwig | 7545190 | 2019-01-23 11:14:29 -0500 | [diff] [blame] | 186 | /** |
| 187 | * 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] | 188 | * |
| 189 | * This is a specialized version of fillQuadWithEdgeAA, but is kept separate since knowing |
| 190 | * the geometry is a rectangle affords more optimizations. |
Michael Ludwig | 7545190 | 2019-01-23 11:14:29 -0500 | [diff] [blame] | 191 | */ |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 192 | void fillRectWithEdgeAA(const GrClip* clip, GrPaint&& paint, GrAA aa, GrQuadAAFlags edgeAA, |
Michael Ludwig | 136f45a | 2019-02-19 11:44:41 -0500 | [diff] [blame] | 193 | const SkMatrix& viewMatrix, const SkRect& rect, |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 194 | const SkRect* optionalLocalRect = nullptr) { |
Chris Dalton | 5c5f09b | 2021-04-13 16:17:58 -0600 | [diff] [blame] | 195 | if (edgeAA == GrQuadAAFlags::kAll) { |
| 196 | this->fillRectToRect(clip, std::move(paint), aa, viewMatrix, rect, |
| 197 | (optionalLocalRect) ? *optionalLocalRect : rect); |
| 198 | return; |
| 199 | } |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 200 | const SkRect& localRect = optionalLocalRect ? *optionalLocalRect : rect; |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 201 | DrawQuad quad{GrQuad::MakeFromRect(rect, viewMatrix), GrQuad(localRect), edgeAA}; |
| 202 | this->drawFilledQuad(clip, std::move(paint), aa, &quad); |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 203 | } |
Michael Ludwig | 7545190 | 2019-01-23 11:14:29 -0500 | [diff] [blame] | 204 | |
Michael Ludwig | ce62dec | 2019-02-19 11:48:46 -0500 | [diff] [blame] | 205 | /** |
| 206 | * Similar to fillRectWithEdgeAA but draws an arbitrary 2D convex quadrilateral transformed |
| 207 | * by 'viewMatrix', with per-edge control over anti-aliasing. The quad should follow the |
| 208 | * ordering used by SkRect::toQuad(), which determines how the edge AA is applied: |
| 209 | * - "top" = points [0] and [1] |
| 210 | * - "right" = points[1] and [2] |
| 211 | * - "bottom" = points[2] and [3] |
| 212 | * - "left" = points[3] and [0] |
| 213 | * |
| 214 | * The last argument, 'optionalLocalQuad', can be null if no separate local coordinates are |
| 215 | * necessary. |
| 216 | */ |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 217 | void fillQuadWithEdgeAA(const GrClip* clip, GrPaint&& paint, GrAA aa, GrQuadAAFlags edgeAA, |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 218 | const SkMatrix& viewMatrix, const SkPoint points[4], |
| 219 | const SkPoint optionalLocalPoints[4]) { |
| 220 | const SkPoint* localPoints = optionalLocalPoints ? optionalLocalPoints : points; |
| 221 | DrawQuad quad{GrQuad::MakeFromSkQuad(points, viewMatrix), |
| 222 | GrQuad::MakeFromSkQuad(localPoints, SkMatrix::I()), edgeAA}; |
| 223 | this->drawFilledQuad(clip, std::move(paint), aa, &quad); |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 224 | } |
Michael Ludwig | ce62dec | 2019-02-19 11:48:46 -0500 | [diff] [blame] | 225 | |
Michael Ludwig | 6985853 | 2018-11-28 15:34:34 -0500 | [diff] [blame] | 226 | /** Used with drawQuadSet */ |
| 227 | struct QuadSetEntry { |
| 228 | SkRect fRect; |
| 229 | SkPMColor4f fColor; // Overrides any color on the GrPaint |
| 230 | SkMatrix fLocalMatrix; |
| 231 | GrQuadAAFlags fAAFlags; |
| 232 | }; |
| 233 | |
Michael Ludwig | 7545190 | 2019-01-23 11:14:29 -0500 | [diff] [blame] | 234 | // TODO(michaelludwig) - remove if the bulk API is not useful for SkiaRenderer |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 235 | void drawQuadSet(const GrClip* clip, GrPaint&& paint, GrAA aa, const SkMatrix& viewMatrix, |
Michael Ludwig | 6985853 | 2018-11-28 15:34:34 -0500 | [diff] [blame] | 236 | const QuadSetEntry[], int cnt); |
| 237 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 238 | /** |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 239 | * Creates an op that draws a subrectangle of a texture. The passed color is modulated by the |
| 240 | * texture's color. 'srcRect' specifies the rectangle of the texture to draw. 'dstRect' |
| 241 | * 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] | 242 | * device space. |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 243 | */ |
Chris Dalton | 4718a8b | 2021-03-18 18:38:52 -0600 | [diff] [blame] | 244 | void drawTexture(const GrClip*, |
| 245 | GrSurfaceProxyView, |
| 246 | SkAlphaType, |
| 247 | GrSamplerState::Filter, |
| 248 | GrSamplerState::MipmapMode, |
| 249 | SkBlendMode, |
| 250 | const SkPMColor4f&, |
Brian Salomon | e69b9ef | 2020-07-22 11:18:06 -0400 | [diff] [blame] | 251 | const SkRect& srcRect, |
| 252 | const SkRect& dstRect, |
Chris Dalton | 4718a8b | 2021-03-18 18:38:52 -0600 | [diff] [blame] | 253 | GrAA, |
| 254 | GrQuadAAFlags, |
| 255 | SkCanvas::SrcRectConstraint, |
| 256 | const SkMatrix&, |
| 257 | sk_sp<GrColorSpaceXform>); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 258 | |
Michael Ludwig | ce62dec | 2019-02-19 11:48:46 -0500 | [diff] [blame] | 259 | /** |
| 260 | * Variant of drawTexture that instead draws the texture applied to 'dstQuad' transformed by |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame] | 261 | * 'viewMatrix', using the 'srcQuad' texture coordinates clamped to the optional 'subset'. If |
| 262 | * 'subset' is null, it's equivalent to using the fast src rect constraint. If 'subset' is |
| 263 | * provided, the strict src rect constraint is applied using 'subset'. |
Michael Ludwig | ce62dec | 2019-02-19 11:48:46 -0500 | [diff] [blame] | 264 | */ |
Brian Salomon | e69b9ef | 2020-07-22 11:18:06 -0400 | [diff] [blame] | 265 | void drawTextureQuad(const GrClip* clip, |
| 266 | GrSurfaceProxyView view, |
| 267 | GrColorType srcColorType, |
| 268 | SkAlphaType srcAlphaType, |
| 269 | GrSamplerState::Filter filter, |
| 270 | GrSamplerState::MipmapMode mm, |
| 271 | SkBlendMode mode, |
| 272 | const SkPMColor4f& color, |
| 273 | const SkPoint srcQuad[4], |
| 274 | const SkPoint dstQuad[4], |
| 275 | GrAA aa, |
| 276 | GrQuadAAFlags edgeAA, |
| 277 | const SkRect* subset, |
| 278 | const SkMatrix& viewMatrix, |
Michael Ludwig | aee26ea | 2019-07-08 16:22:48 +0000 | [diff] [blame] | 279 | sk_sp<GrColorSpaceXform> texXform) { |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 280 | DrawQuad quad{GrQuad::MakeFromSkQuad(dstQuad, viewMatrix), |
| 281 | GrQuad::MakeFromSkQuad(srcQuad, SkMatrix::I()), edgeAA}; |
Brian Salomon | e69b9ef | 2020-07-22 11:18:06 -0400 | [diff] [blame] | 282 | this->drawTexturedQuad(clip, std::move(view), srcAlphaType, std::move(texXform), filter, mm, |
| 283 | color, mode, aa, &quad, subset); |
Michael Ludwig | aee26ea | 2019-07-08 16:22:48 +0000 | [diff] [blame] | 284 | } |
Michael Ludwig | ce62dec | 2019-02-19 11:48:46 -0500 | [diff] [blame] | 285 | |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 286 | /** Used with drawTextureSet */ |
| 287 | struct TextureSetEntry { |
Greg Daniel | 549325c | 2019-10-30 16:19:20 -0400 | [diff] [blame] | 288 | GrSurfaceProxyView fProxyView; |
Brian Salomon | fc11844 | 2019-11-22 19:09:27 -0500 | [diff] [blame] | 289 | SkAlphaType fSrcAlphaType; |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 290 | SkRect fSrcRect; |
| 291 | SkRect fDstRect; |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 292 | 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] | 293 | const SkMatrix* fPreViewMatrix; // If not null, entry's CTM is 'viewMatrix' * fPreViewMatrix |
Michael Ludwig | 1c66ad9 | 2020-07-10 08:59:44 -0400 | [diff] [blame] | 294 | SkPMColor4f fColor; // {a,a,a,a} for rgb textures, {r,g,b,a} for alpha-only textures |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 295 | GrQuadAAFlags fAAFlags; |
| 296 | }; |
| 297 | /** |
| 298 | * Draws a set of textures with a shared filter, color, view matrix, color xform, and |
| 299 | * 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] | 300 | * |
| 301 | * If any entries provide a non-null fDstClip array, it will be read from immediately based on |
| 302 | * fDstClipCount, so the pointer can become invalid after this returns. |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 303 | * |
Hal Canary | 425929c | 2019-12-09 11:55:40 -0500 | [diff] [blame] | 304 | * 'proxRunCnt' is the number of proxy changes encountered in the entry array. Technically this |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 305 | * can be inferred from the array within this function, but the information is already known |
| 306 | * by SkGpuDevice, so no need to incur another iteration over the array. |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 307 | */ |
Brian Salomon | e69b9ef | 2020-07-22 11:18:06 -0400 | [diff] [blame] | 308 | void drawTextureSet(const GrClip*, |
| 309 | TextureSetEntry[], |
| 310 | int cnt, |
| 311 | int proxyRunCnt, |
| 312 | GrSamplerState::Filter, |
| 313 | GrSamplerState::MipmapMode, |
| 314 | SkBlendMode mode, |
| 315 | GrAA aa, |
| 316 | SkCanvas::SrcRectConstraint, |
| 317 | const SkMatrix& viewMatrix, |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 318 | sk_sp<GrColorSpaceXform> texXform); |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 319 | |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 320 | /** |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 321 | * Draw a roundrect using a paint. |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 322 | * |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 323 | * @param paint describes how to color pixels. |
| 324 | * @param GrAA Controls whether rrect is antialiased. |
| 325 | * @param viewMatrix transformation matrix |
| 326 | * @param rrect the roundrect to draw |
| 327 | * @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] | 328 | */ |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 329 | void drawRRect(const GrClip*, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 330 | GrPaint&&, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 331 | GrAA, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 332 | const SkMatrix& viewMatrix, |
| 333 | const SkRRect& rrect, |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 334 | const GrStyle& style); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 335 | |
| 336 | /** |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 337 | * Use a fast method to render the ambient and spot shadows for a path. |
| 338 | * Will return false if not possible for the given path. |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 339 | * |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 340 | * @param viewMatrix transformation matrix |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 341 | * @param path the path to shadow |
| 342 | * @param rec parameters for shadow rendering |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 343 | */ |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 344 | bool drawFastShadow(const GrClip*, |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 345 | const SkMatrix& viewMatrix, |
| 346 | const SkPath& path, |
| 347 | const SkDrawShadowRec& rec); |
Jim Van Verth | c590341 | 2016-11-17 15:27:09 -0500 | [diff] [blame] | 348 | |
| 349 | /** |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 350 | * Draws a path. |
| 351 | * |
| 352 | * @param paint describes how to color pixels. |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 353 | * @param GrAA Controls whether the path is antialiased. |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 354 | * @param viewMatrix transformation matrix |
| 355 | * @param path the path to draw |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 356 | * @param style style to apply to the path. |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 357 | */ |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 358 | void drawPath(const GrClip*, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 359 | GrPaint&&, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 360 | GrAA, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 361 | const SkMatrix& viewMatrix, |
| 362 | const SkPath&, |
Robert Phillips | 20390c3 | 2018-08-17 11:01:03 -0400 | [diff] [blame] | 363 | const GrStyle&); |
| 364 | |
| 365 | /** |
| 366 | * Draws a shape. |
| 367 | * |
| 368 | * @param paint describes how to color pixels. |
| 369 | * @param GrAA Controls whether the path is antialiased. |
| 370 | * @param viewMatrix transformation matrix |
| 371 | * @param shape the shape to draw |
| 372 | */ |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 373 | void drawShape(const GrClip*, |
Robert Phillips | 20390c3 | 2018-08-17 11:01:03 -0400 | [diff] [blame] | 374 | GrPaint&&, |
| 375 | GrAA, |
| 376 | const SkMatrix& viewMatrix, |
Chris Dalton | 2185901 | 2021-01-29 23:44:53 -0700 | [diff] [blame] | 377 | GrStyledShape&&); |
Robert Phillips | 20390c3 | 2018-08-17 11:01:03 -0400 | [diff] [blame] | 378 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 379 | |
| 380 | /** |
| 381 | * Draws vertices with a paint. |
| 382 | * |
Brian Osman | ae0c50c | 2017-05-25 16:56:34 -0400 | [diff] [blame] | 383 | * @param paint describes how to color pixels. |
| 384 | * @param viewMatrix transformation matrix |
| 385 | * @param vertices specifies the mesh to draw. |
| 386 | * @param overridePrimType primitive type to draw. If NULL, derive prim type from vertices. |
Brian Osman | 3c35842 | 2020-03-23 10:44:12 -0400 | [diff] [blame] | 387 | * @param effect runtime effect that will handle custom vertex attributes. |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 388 | */ |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 389 | void drawVertices(const GrClip*, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 390 | GrPaint&& paint, |
Brian Osman | 449b115 | 2020-04-15 16:43:00 -0400 | [diff] [blame] | 391 | const SkMatrixProvider& matrixProvider, |
Brian Osman | ae0c50c | 2017-05-25 16:56:34 -0400 | [diff] [blame] | 392 | sk_sp<SkVertices> vertices, |
Brian Osman | 3c35842 | 2020-03-23 10:44:12 -0400 | [diff] [blame] | 393 | GrPrimitiveType* overridePrimType = nullptr, |
Brian Osman | 449b115 | 2020-04-15 16:43:00 -0400 | [diff] [blame] | 394 | const SkRuntimeEffect* effect = nullptr); |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 395 | |
| 396 | /** |
Brian Osman | 4d92b89 | 2019-03-24 00:53:23 +0000 | [diff] [blame] | 397 | * Draws textured sprites from an atlas with a paint. This currently does not support AA for the |
| 398 | * sprite rectangle edges. |
| 399 | * |
| 400 | * @param paint describes how to color pixels. |
| 401 | * @param viewMatrix transformation matrix |
| 402 | * @param spriteCount number of sprites. |
| 403 | * @param xform array of compressed transformation data, required. |
| 404 | * @param texRect array of texture rectangles used to access the paint. |
| 405 | * @param colors optional array of per-sprite colors, supercedes |
| 406 | * the paint's color field. |
| 407 | */ |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 408 | void drawAtlas(const GrClip*, |
Brian Osman | 4d92b89 | 2019-03-24 00:53:23 +0000 | [diff] [blame] | 409 | GrPaint&& paint, |
| 410 | const SkMatrix& viewMatrix, |
| 411 | int spriteCount, |
| 412 | const SkRSXform xform[], |
| 413 | const SkRect texRect[], |
| 414 | const SkColor colors[]); |
| 415 | |
| 416 | /** |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 417 | * Draws a region. |
| 418 | * |
| 419 | * @param paint describes how to color pixels |
| 420 | * @param viewMatrix transformation matrix |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 421 | * @param aa should the rects of the region be antialiased. |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 422 | * @param region the region to be drawn |
| 423 | * @param style style to apply to the region |
| 424 | */ |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 425 | void drawRegion(const GrClip*, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 426 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 427 | GrAA aa, |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 428 | const SkMatrix& viewMatrix, |
| 429 | const SkRegion& region, |
Stan Iliev | 73d8fd9 | 2017-08-02 15:36:24 -0400 | [diff] [blame] | 430 | const GrStyle& style, |
| 431 | const GrUserStencilSettings* ss = nullptr); |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 432 | |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 433 | /** |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 434 | * Draws an oval. |
| 435 | * |
| 436 | * @param paint describes how to color pixels. |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 437 | * @param GrAA Controls whether the oval is antialiased. |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 438 | * @param viewMatrix transformation matrix |
| 439 | * @param oval the bounding rect of the oval. |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 440 | * @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] | 441 | */ |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 442 | void drawOval(const GrClip*, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 443 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 444 | GrAA, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 445 | const SkMatrix& viewMatrix, |
| 446 | const SkRect& oval, |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 447 | const GrStyle& style); |
Herb Derby | c1583cb | 2020-07-13 10:42:18 -0400 | [diff] [blame] | 448 | |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 449 | /** |
| 450 | * Draws a partial arc of an oval. |
| 451 | * |
| 452 | * @param paint describes how to color pixels. |
Brian Salomon | 9950408 | 2016-12-09 15:51:31 -0500 | [diff] [blame] | 453 | * @param GrGrAA Controls whether the arc is antialiased. |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 454 | * @param viewMatrix transformation matrix. |
| 455 | * @param oval the bounding rect of the oval. |
| 456 | * @param startAngle starting angle in degrees. |
| 457 | * @param sweepAngle angle to sweep in degrees. Must be in (-360, 360) |
| 458 | * @param useCenter true means that the implied path begins at the oval center, connects as |
| 459 | * a line to the point indicated by the start contains the arc indicated by |
| 460 | * the sweep angle. If false the line beginning at the center point is |
| 461 | * omitted. |
| 462 | * @param style style to apply to the oval. |
| 463 | */ |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 464 | void drawArc(const GrClip*, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 465 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 466 | GrAA, |
bsalomon | 4f3a0ca | 2016-08-22 13:14:26 -0700 | [diff] [blame] | 467 | const SkMatrix& viewMatrix, |
| 468 | const SkRect& oval, |
| 469 | SkScalar startAngle, |
| 470 | SkScalar sweepAngle, |
| 471 | bool useCenter, |
| 472 | const GrStyle& style); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 473 | |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 474 | /** |
bsalomon | 4f3a0ca | 2016-08-22 13:14:26 -0700 | [diff] [blame] | 475 | * Draw the image as a set of rects, specified by |iter|. |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 476 | */ |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 477 | void drawImageLattice(const GrClip*, |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 478 | GrPaint&&, |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 479 | const SkMatrix& viewMatrix, |
Greg Daniel | ed96bca | 2019-12-05 15:05:54 -0500 | [diff] [blame] | 480 | GrSurfaceProxyView, |
Greg Daniel | 82c6b10 | 2020-01-21 10:33:22 -0500 | [diff] [blame] | 481 | SkAlphaType alphaType, |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 482 | sk_sp<GrColorSpaceXform>, |
| 483 | GrSamplerState::Filter, |
| 484 | std::unique_ptr<SkLatticeIter>, |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 485 | const SkRect& dst); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 486 | |
robertphillips | 8c523e0 | 2016-07-26 07:41:00 -0700 | [diff] [blame] | 487 | /** |
Herb Derby | 411e7aa | 2020-07-09 16:02:08 -0400 | [diff] [blame] | 488 | * Draw the text specified by the SkGlyphRunList. |
| 489 | * |
| 490 | * @param viewMatrix transformationMatrix |
| 491 | * @param glyphRunList text, text positions, and paint. |
| 492 | */ |
| 493 | void drawGlyphRunList(const GrClip*, |
| 494 | const SkMatrixProvider& viewMatrix, |
Herb Derby | 0da2c14 | 2021-03-22 15:28:23 -0400 | [diff] [blame] | 495 | const SkGlyphRunList& glyphRunList, |
| 496 | const SkPaint& paint); |
Herb Derby | 411e7aa | 2020-07-09 16:02:08 -0400 | [diff] [blame] | 497 | |
| 498 | /** |
Herb Derby | 2e0b5bb | 2020-11-19 11:03:50 -0500 | [diff] [blame] | 499 | * Draw the text specified by the SkGlyphRunList. |
| 500 | * |
| 501 | * @param viewMatrix transformationMatrix |
| 502 | * @param glyphRunList text, text positions, and paint. |
| 503 | */ |
| 504 | void drawGlyphRunListWithCache(const GrClip*, |
| 505 | const SkMatrixProvider& viewMatrix, |
Herb Derby | 0da2c14 | 2021-03-22 15:28:23 -0400 | [diff] [blame] | 506 | const SkGlyphRunList& glyphRunList, |
| 507 | const SkPaint& paint); |
Herb Derby | 2e0b5bb | 2020-11-19 11:03:50 -0500 | [diff] [blame] | 508 | |
| 509 | /** |
| 510 | * Draw the text specified by the SkGlyphRunList. |
| 511 | * |
| 512 | * @param viewMatrix transformationMatrix |
| 513 | * @param glyphRunList text, text positions, and paint. |
| 514 | */ |
| 515 | void drawGlyphRunListNoCache(const GrClip*, |
| 516 | const SkMatrixProvider& viewMatrix, |
Herb Derby | 0da2c14 | 2021-03-22 15:28:23 -0400 | [diff] [blame] | 517 | const SkGlyphRunList& glyphRunList, |
| 518 | const SkPaint& paint); |
Herb Derby | 2e0b5bb | 2020-11-19 11:03:50 -0500 | [diff] [blame] | 519 | |
| 520 | /** |
Greg Daniel | 64cc9aa | 2018-10-19 13:54:56 -0400 | [diff] [blame] | 521 | * Adds the necessary signal and wait semaphores and adds the passed in SkDrawable to the |
| 522 | * command stream. |
| 523 | */ |
| 524 | void drawDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler>, const SkRect& bounds); |
| 525 | |
Brian Salomon | 70fe17e | 2020-11-30 14:33:58 -0500 | [diff] [blame] | 526 | // called to note the last clip drawn to the stencil buffer. |
| 527 | // TODO: remove after clipping overhaul. |
| 528 | void setLastClip(uint32_t clipStackGenID, |
| 529 | const SkIRect& devClipBounds, |
| 530 | int numClipAnalyticElements) { |
| 531 | GrOpsTask* opsTask = this->getOpsTask(); |
| 532 | opsTask->fLastClipStackGenID = clipStackGenID; |
| 533 | opsTask->fLastDevClipBounds = devClipBounds; |
| 534 | opsTask->fLastClipNumAnalyticElements = numClipAnalyticElements; |
| 535 | } |
| 536 | |
| 537 | // called to determine if we have to render the clip into SB. |
| 538 | // TODO: remove after clipping overhaul. |
| 539 | bool mustRenderClip(uint32_t clipStackGenID, |
| 540 | const SkIRect& devClipBounds, |
| 541 | int numClipAnalyticElements) { |
| 542 | GrOpsTask* opsTask = this->getOpsTask(); |
| 543 | return opsTask->fLastClipStackGenID != clipStackGenID || |
| 544 | !opsTask->fLastDevClipBounds.contains(devClipBounds) || |
| 545 | opsTask->fLastClipNumAnalyticElements != numClipAnalyticElements; |
| 546 | } |
| 547 | |
Brian Salomon | 70fe17e | 2020-11-30 14:33:58 -0500 | [diff] [blame] | 548 | void clearStencilClip(const SkIRect& scissor, bool insideStencilMask) { |
| 549 | this->internalStencilClear(&scissor, insideStencilMask); |
| 550 | } |
| 551 | |
| 552 | // While this can take a general clip, since GrReducedClip relies on this function, it must take |
| 553 | // care to only provide hard clips or we could get stuck in a loop. The general clip is needed |
| 554 | // so that path renderers can use this function. |
| 555 | void stencilRect(const GrClip* clip, |
| 556 | const GrUserStencilSettings* ss, |
| 557 | GrPaint&& paint, |
| 558 | GrAA doStencilMSAA, |
| 559 | const SkMatrix& viewMatrix, |
| 560 | const SkRect& rect, |
| 561 | const SkMatrix* localMatrix = nullptr) { |
| 562 | // Since this provides stencil settings to drawFilledQuad, it performs a different AA type |
| 563 | // resolution compared to regular rect draws, which is the main reason it remains separate. |
| 564 | DrawQuad quad{GrQuad::MakeFromRect(rect, viewMatrix), |
| 565 | localMatrix ? GrQuad::MakeFromRect(rect, *localMatrix) : GrQuad(rect), |
Michael Ludwig | 79aaa9b | 2021-04-08 15:05:29 -0400 | [diff] [blame] | 566 | doStencilMSAA == GrAA::kYes ? GrQuadAAFlags::kAll : GrQuadAAFlags::kNone}; |
Brian Salomon | 70fe17e | 2020-11-30 14:33:58 -0500 | [diff] [blame] | 567 | this->drawFilledQuad(clip, std::move(paint), doStencilMSAA, &quad, ss); |
| 568 | } |
| 569 | |
Chris Dalton | 7d592cd | 2021-03-11 22:49:33 -0700 | [diff] [blame] | 570 | // Fills the user stencil bits with a non-zero value at every sample inside the path. This will |
| 571 | // likely be implemented with a Redbook algorithm, but it is not guaranteed. The samples being |
| 572 | // rendered to must be zero initially. |
| 573 | bool stencilPath(const GrHardClip*, |
| 574 | GrAA doStencilMSAA, |
| 575 | const SkMatrix& viewMatrix, |
| 576 | const SkPath&); |
| 577 | |
Brian Salomon | 70fe17e | 2020-11-30 14:33:58 -0500 | [diff] [blame] | 578 | /** |
| 579 | * Draws a path, either AA or not, and touches the stencil buffer with the user stencil settings |
| 580 | * for each color sample written. |
| 581 | */ |
| 582 | bool drawAndStencilPath(const GrHardClip*, |
| 583 | const GrUserStencilSettings*, |
| 584 | SkRegion::Op op, |
| 585 | bool invert, |
| 586 | GrAA doStencilMSAA, |
| 587 | const SkMatrix& viewMatrix, |
| 588 | const SkPath&); |
| 589 | |
| 590 | SkBudgeted isBudgeted() const; |
| 591 | |
| 592 | int maxWindowRectangles() const; |
| 593 | |
| 594 | SkGlyphRunListPainter* glyphRunPainter() { return &fGlyphPainter; } |
| 595 | |
| 596 | /* |
| 597 | * This unique ID will not change for a given RenderTargetContext. However, it is _NOT_ |
| 598 | * guaranteed to match the uniqueID of the underlying GrRenderTarget - beware! |
| 599 | */ |
| 600 | GrSurfaceProxy::UniqueID uniqueID() const { return this->asSurfaceProxy()->uniqueID(); } |
| 601 | |
Brian Salomon | 70fe17e | 2020-11-30 14:33:58 -0500 | [diff] [blame] | 602 | // Allows caller of addDrawOp to know which op list an op will be added to. |
| 603 | using WillAddOpFn = void(GrOp*, uint32_t opsTaskID); |
| 604 | // These perform processing specific to GrDrawOp-derived ops before recording them into an |
| 605 | // op list. Before adding the op to an op list the WillAddOpFn is called. Note that it |
| 606 | // will not be called in the event that the op is discarded. Moreover, the op may merge into |
| 607 | // another op after the function is called (either before addDrawOp returns or some time later). |
| 608 | // |
| 609 | // If the clip pointer is null, no clipping will be performed. |
| 610 | void addDrawOp(const GrClip*, |
| 611 | GrOp::Owner, |
| 612 | const std::function<WillAddOpFn>& = std::function<WillAddOpFn>()); |
| 613 | void addDrawOp(GrOp::Owner op) { this->addDrawOp(nullptr, std::move(op)); } |
| 614 | |
| 615 | bool refsWrappedObjects() const { return this->asRenderTargetProxy()->refsWrappedObjects(); } |
| 616 | |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 617 | /** |
Brian Salomon | eebe735 | 2020-12-09 16:37:04 -0500 | [diff] [blame] | 618 | * The next time this GrSurfaceDrawContext is flushed, the gpu will wait on the passed in |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 619 | * semaphores before executing any commands. |
| 620 | */ |
Greg Daniel | 414418d | 2020-07-08 11:44:25 -0400 | [diff] [blame] | 621 | bool waitOnSemaphores(int numSemaphores, const GrBackendSemaphore waitSemaphores[], |
| 622 | bool deleteSemaphoresAfterWait); |
robertphillips | 8c523e0 | 2016-07-26 07:41:00 -0700 | [diff] [blame] | 623 | |
Greg Daniel | 46e366a | 2019-12-16 14:38:36 -0500 | [diff] [blame] | 624 | int numSamples() const { return this->asRenderTargetProxy()->numSamples(); } |
robertphillips | ca6eafc | 2016-05-17 09:57:46 -0700 | [diff] [blame] | 625 | const SkSurfaceProps& surfaceProps() const { return fSurfaceProps; } |
Chris Dalton | a7dffa1 | 2021-05-03 19:00:55 -0600 | [diff] [blame] | 626 | bool canUseDynamicMSAA() const { return fCanUseDynamicMSAA; } |
Greg Daniel | 46e366a | 2019-12-16 14:38:36 -0500 | [diff] [blame] | 627 | bool wrapsVkSecondaryCB() const { return this->asRenderTargetProxy()->wrapsVkSecondaryCB(); } |
Brian Salomon | 8c82a87 | 2020-07-21 12:09:58 -0400 | [diff] [blame] | 628 | GrMipmapped mipmapped() const; |
robertphillips | 7bceedc | 2015-12-01 12:51:26 -0800 | [diff] [blame] | 629 | |
Chris Dalton | 94df572 | 2021-04-19 17:40:40 -0600 | [diff] [blame] | 630 | bool alwaysAntialias() const { |
| 631 | return fSurfaceProps.flags() & kDMSAA_SkSurfacePropsPrivateFlag; |
| 632 | } |
| 633 | |
| 634 | GrAA chooseAA(const SkPaint& paint) { |
| 635 | return GrAA(paint.isAntiAlias() || this->alwaysAntialias()); |
| 636 | } |
| 637 | |
Robert Phillips | be9aff2 | 2019-02-15 11:33:22 -0500 | [diff] [blame] | 638 | // This entry point should only be called if the backing GPU object is known to be |
| 639 | // instantiated. |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 640 | GrRenderTarget* accessRenderTarget() { return this->asSurfaceProxy()->peekRenderTarget(); } |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 641 | |
Brian Salomon | eebe735 | 2020-12-09 16:37:04 -0500 | [diff] [blame] | 642 | GrSurfaceDrawContext* asRenderTargetContext() override { return this; } |
Robert Phillips | d46697a | 2017-01-25 12:10:37 -0500 | [diff] [blame] | 643 | |
Robert Phillips | b520476 | 2019-06-19 14:12:13 -0400 | [diff] [blame] | 644 | #if GR_TEST_UTILS |
Chris Dalton | 6b98280 | 2019-06-27 13:53:46 -0600 | [diff] [blame] | 645 | void testingOnly_SetPreserveOpsOnFullClear() { fPreserveOpsOnFullClear_TestingOnly = true; } |
Robert Phillips | b520476 | 2019-06-19 14:12:13 -0400 | [diff] [blame] | 646 | #endif |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 647 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 648 | private: |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 649 | enum class QuadOptimization; |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 650 | |
Brian Salomon | 9a0da78 | 2021-04-23 13:41:55 -0400 | [diff] [blame] | 651 | void willReplaceOpsTask(GrOpsTask* prevTask, GrOpsTask* nextTask) override; |
| 652 | |
Chris Dalton | 7d6748e | 2019-03-13 00:34:52 -0600 | [diff] [blame] | 653 | GrAAType chooseAAType(GrAA); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 654 | |
Brian Salomon | 590f567 | 2020-12-16 11:44:47 -0500 | [diff] [blame] | 655 | GrOpsTask::CanDiscardPreviousOps canDiscardPreviousOpsOnFullClear() const override; |
Chris Dalton | 57ab06c | 2021-04-22 12:57:28 -0600 | [diff] [blame] | 656 | void setNeedsStencil(); |
Chris Dalton | 6b98280 | 2019-06-27 13:53:46 -0600 | [diff] [blame] | 657 | |
Michael Ludwig | 81d4172 | 2020-05-26 16:57:38 -0400 | [diff] [blame] | 658 | void internalStencilClear(const SkIRect* scissor, bool insideStencilMask); |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 659 | |
Michael Ludwig | e08b443 | 2019-06-19 18:00:48 -0400 | [diff] [blame] | 660 | // 'stencilSettings' are provided merely for decision making purposes; When non-null, |
| 661 | // optimization strategies that submit special ops are avoided. |
Chris Dalton | 61d694d | 2021-03-22 00:00:52 -0600 | [diff] [blame] | 662 | // |
| 663 | // 'aa' and 'quad' should be the original draw request on input, and will be updated as |
| 664 | // appropriate depending on the returned optimization level. |
| 665 | // |
| 666 | // If kSubmitted is returned, the provided paint was consumed. Otherwise it is left unchanged. |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 667 | QuadOptimization attemptQuadOptimization(const GrClip* clip, |
Michael Ludwig | e08b443 | 2019-06-19 18:00:48 -0400 | [diff] [blame] | 668 | const GrUserStencilSettings* stencilSettings, |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 669 | GrAA* aa, |
Chris Dalton | 61d694d | 2021-03-22 00:00:52 -0600 | [diff] [blame] | 670 | DrawQuad* quad, |
| 671 | GrPaint* paint); |
robertphillips | 4430239 | 2016-07-08 14:43:03 -0700 | [diff] [blame] | 672 | |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 673 | // If stencil settings, 'ss', are non-null, AA controls MSAA or no AA. If they are null, then AA |
| 674 | // can choose between coverage, MSAA as per chooseAAType(). This will always attempt to apply |
| 675 | // quad optimizations, so all quad/rect public APIs should rely on this function for consistent |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 676 | // clipping behavior. 'quad' will be modified in place to reflect final rendered geometry. |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 677 | void drawFilledQuad(const GrClip* clip, |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 678 | GrPaint&& paint, |
| 679 | GrAA aa, |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 680 | DrawQuad* quad, |
Michael Ludwig | 6132820 | 2019-06-19 14:48:58 +0000 | [diff] [blame] | 681 | const GrUserStencilSettings* ss = nullptr); |
Brian Salomon | 7694b90 | 2019-06-18 21:00:21 +0000 | [diff] [blame] | 682 | |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 683 | // Like drawFilledQuad but does not require using a GrPaint or FP for texturing. |
| 684 | // 'quad' may be modified in place to reflect final geometry. |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 685 | void drawTexturedQuad(const GrClip* clip, |
Greg Daniel | 549325c | 2019-10-30 16:19:20 -0400 | [diff] [blame] | 686 | GrSurfaceProxyView proxyView, |
Brian Salomon | fc11844 | 2019-11-22 19:09:27 -0500 | [diff] [blame] | 687 | SkAlphaType alphaType, |
Michael Ludwig | aee26ea | 2019-07-08 16:22:48 +0000 | [diff] [blame] | 688 | sk_sp<GrColorSpaceXform> textureXform, |
| 689 | GrSamplerState::Filter filter, |
Brian Salomon | e69b9ef | 2020-07-22 11:18:06 -0400 | [diff] [blame] | 690 | GrSamplerState::MipmapMode, |
Michael Ludwig | aee26ea | 2019-07-08 16:22:48 +0000 | [diff] [blame] | 691 | const SkPMColor4f& color, |
| 692 | SkBlendMode blendMode, |
| 693 | GrAA aa, |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 694 | DrawQuad* quad, |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame] | 695 | const SkRect* subset = nullptr); |
Michael Ludwig | aee26ea | 2019-07-08 16:22:48 +0000 | [diff] [blame] | 696 | |
Chris Dalton | 319d020 | 2021-01-29 23:49:47 -0700 | [diff] [blame] | 697 | void drawStrokedLine(const GrClip*, GrPaint&&, GrAA, const SkMatrix&, const SkPoint[2], |
| 698 | const SkStrokeRec&); |
| 699 | |
Chris Dalton | bfe0d37 | 2021-02-04 12:24:54 -0700 | [diff] [blame] | 700 | // Tries to detect if the given shape is a simple, and draws it without path rendering if |
| 701 | // we know how. |
| 702 | bool drawSimpleShape(const GrClip*, GrPaint*, GrAA, const SkMatrix&, const GrStyledShape&); |
| 703 | |
Chris Dalton | 9f704a8 | 2021-02-04 15:07:56 -0700 | [diff] [blame] | 704 | // If 'attemptDrawSimple' is true, of if the original shape is marked as having been simplfied, |
| 705 | // this will attempt to re-route through drawSimpleShape() to see if we can avoid path rendering |
| 706 | // one more time. |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 707 | void drawShapeUsingPathRenderer(const GrClip*, GrPaint&&, GrAA, const SkMatrix&, |
Chris Dalton | 9f704a8 | 2021-02-04 15:07:56 -0700 | [diff] [blame] | 708 | GrStyledShape&&, bool attemptDrawSimple = false); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 709 | |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 710 | // Makes a copy of the proxy if it is necessary for the draw and places the texture that should |
| 711 | // be used by GrXferProcessor to access the destination color in 'result'. If the return |
| 712 | // value is false then a texture copy could not be made. |
Michael Ludwig | 28e5f11 | 2020-06-09 10:57:24 -0400 | [diff] [blame] | 713 | // |
| 714 | // The op should have already had setClippedBounds called on it. |
| 715 | bool SK_WARN_UNUSED_RESULT setupDstProxyView(const GrOp& op, |
Greg Daniel | 524e28b | 2019-11-01 11:48:53 -0400 | [diff] [blame] | 716 | GrXferProcessor::DstProxyView* result); |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 717 | |
Herb Derby | d29207a | 2020-06-08 13:50:19 -0400 | [diff] [blame] | 718 | SkGlyphRunListPainter* glyphPainter() { return &fGlyphPainter; } |
| 719 | |
Chris Dalton | 710e1c9 | 2021-04-23 13:07:52 -0600 | [diff] [blame] | 720 | const SkSurfaceProps fSurfaceProps; |
| 721 | const bool fCanUseDynamicMSAA; |
Robert Phillips | e305cc1f | 2016-12-14 12:19:05 -0500 | [diff] [blame] | 722 | |
Chris Dalton | 57ab06c | 2021-04-22 12:57:28 -0600 | [diff] [blame] | 723 | bool fNeedsStencil = false; |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 724 | |
| 725 | GrDstSampleType fDstSampleType = GrDstSampleType::kNone; |
| 726 | |
Chris Dalton | 6b98280 | 2019-06-27 13:53:46 -0600 | [diff] [blame] | 727 | #if GR_TEST_UTILS |
| 728 | bool fPreserveOpsOnFullClear_TestingOnly = false; |
| 729 | #endif |
Herb Derby | d29207a | 2020-06-08 13:50:19 -0400 | [diff] [blame] | 730 | SkGlyphRunListPainter fGlyphPainter; |
Brian Salomon | 590f567 | 2020-12-16 11:44:47 -0500 | [diff] [blame] | 731 | using INHERITED = GrSurfaceFillContext; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 732 | }; |
| 733 | |
| 734 | #endif |