| 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 | |
| 8 | #ifndef GrRenderTargetContext_DEFINED |
| 9 | #define GrRenderTargetContext_DEFINED |
| 10 | |
| 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" |
| 16 | #include "include/private/GrTypesPriv.h" |
| 17 | #include "src/core/SkGlyphRunPainter.h" |
| 18 | #include "src/gpu/GrOpsTask.h" |
| 19 | #include "src/gpu/GrPaint.h" |
| 20 | #include "src/gpu/GrRenderTargetProxy.h" |
| 21 | #include "src/gpu/GrSurfaceContext.h" |
| 22 | #include "src/gpu/GrSurfaceProxyView.h" |
| 23 | #include "src/gpu/GrXferProcessor.h" |
| 24 | #include "src/gpu/geometry/GrQuad.h" |
| 25 | #include "src/gpu/text/GrTextBlob.h" |
| 26 | |
| 27 | #include <tuple> |
| 28 | |
| 29 | class GrBackendSemaphore; |
| 30 | class GrClip; |
| 31 | class GrColorSpaceXform; |
| 32 | class GrCoverageCountingPathRenderer; |
| 33 | class GrDrawOp; |
| 34 | class GrOp; |
| 35 | class GrRenderTarget; |
| 36 | class GrRenderTargetContextPriv; |
| 37 | class GrStyledShape; |
| 38 | class GrStyle; |
| 39 | class GrTextureProxy; |
| 40 | struct GrUserStencilSettings; |
| 41 | struct SkDrawShadowRec; |
| 42 | class SkGlyphRunList; |
| 43 | struct SkIPoint; |
| 44 | struct SkIRect; |
| 45 | class SkLatticeIter; |
| 46 | class SkMatrixProvider; |
| 47 | class SkMatrix; |
| 48 | class SkPaint; |
| 49 | class SkPath; |
| 50 | struct SkPoint; |
| 51 | struct SkRect; |
| 52 | class SkRegion; |
| 53 | class SkRRect; |
| 54 | struct SkRSXform; |
| 55 | class SkRuntimeEffect; |
| 56 | class SkTextBlob; |
| 57 | class SkVertices; |
| 58 | |
| 59 | /** |
| 60 | * A helper object to orchestrate commands (draws, etc...) for GrSurfaces that are GrRenderTargets. |
| 61 | */ |
| 62 | class GrRenderTargetContext : public GrSurfaceContext, public GrOpsTaskClosedObserver { |
| 63 | public: |
| 64 | static std::unique_ptr<GrRenderTargetContext> Make( |
| 65 | GrRecordingContext*, GrColorType, sk_sp<SkColorSpace>, sk_sp<GrSurfaceProxy>, |
| 66 | GrSurfaceOrigin, const SkSurfaceProps*, bool managedOps = true); |
| 67 | |
| 68 | static std::unique_ptr<GrRenderTargetContext> Make(GrRecordingContext*, |
| 69 | GrColorType, |
| 70 | sk_sp<SkColorSpace>, |
| 71 | SkBackingFit, |
| 72 | SkISize dimensions, |
| 73 | const GrBackendFormat&, |
| 74 | int sampleCnt, |
| 75 | GrMipmapped, |
| 76 | GrProtected, |
| 77 | GrSurfaceOrigin, |
| 78 | SkBudgeted, |
| 79 | const SkSurfaceProps*); |
| 80 | |
| 81 | // Same as above but will use the default GrBackendFormat for the given GrColorType |
| 82 | static std::unique_ptr<GrRenderTargetContext> Make( |
| 83 | GrRecordingContext*, |
| 84 | GrColorType, |
| 85 | sk_sp<SkColorSpace>, |
| 86 | SkBackingFit, |
| 87 | SkISize dimensions, |
| 88 | int sampleCnt = 1, |
| 89 | GrMipmapped = GrMipmapped::kNo, |
| 90 | GrProtected = GrProtected::kNo, |
| 91 | GrSurfaceOrigin = kBottomLeft_GrSurfaceOrigin, |
| 92 | SkBudgeted = SkBudgeted::kYes, |
| 93 | const SkSurfaceProps* = nullptr); |
| 94 | |
| 95 | static std::tuple<GrColorType, GrBackendFormat> GetFallbackColorTypeAndFormat(GrImageContext*, |
| 96 | GrColorType, |
| 97 | int sampleCnt); |
| 98 | |
| 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. |
| 103 | static std::unique_ptr<GrRenderTargetContext> MakeWithFallback( |
| 104 | GrRecordingContext*, |
| 105 | GrColorType, |
| 106 | sk_sp<SkColorSpace>, |
| 107 | SkBackingFit, |
| 108 | SkISize dimensions, |
| 109 | int sampleCnt = 1, |
| 110 | GrMipmapped = GrMipmapped::kNo, |
| 111 | GrProtected = GrProtected::kNo, |
| 112 | GrSurfaceOrigin = kBottomLeft_GrSurfaceOrigin, |
| 113 | SkBudgeted = SkBudgeted::kYes, |
| 114 | const SkSurfaceProps* = nullptr); |
| 115 | |
| 116 | // These match the definitions in SkSurface & GrSurface.h, for whence they came |
| 117 | typedef void* ReleaseContext; |
| 118 | typedef void (*ReleaseProc)(ReleaseContext); |
| 119 | |
| 120 | // Creates a GrRenderTargetContext that wraps the passed in GrBackendTexture. |
| 121 | static std::unique_ptr<GrRenderTargetContext> MakeFromBackendTexture( |
| 122 | GrRecordingContext*, GrColorType, sk_sp<SkColorSpace>, const GrBackendTexture&, |
| 123 | int sampleCnt, GrSurfaceOrigin, const SkSurfaceProps*, |
| 124 | sk_sp<GrRefCntedCallback> releaseHelper); |
| 125 | |
| 126 | static std::unique_ptr<GrRenderTargetContext> MakeFromBackendTextureAsRenderTarget( |
| 127 | GrRecordingContext*, GrColorType, sk_sp<SkColorSpace>, const GrBackendTexture&, |
| 128 | int sampleCnt, GrSurfaceOrigin, const SkSurfaceProps*); |
| 129 | |
| 130 | static std::unique_ptr<GrRenderTargetContext> MakeFromBackendRenderTarget( |
| 131 | GrRecordingContext*, GrColorType, sk_sp<SkColorSpace>, const GrBackendRenderTarget&, |
| 132 | GrSurfaceOrigin, const SkSurfaceProps*, ReleaseProc releaseProc, |
| 133 | ReleaseContext releaseCtx); |
| 134 | |
| 135 | static std::unique_ptr<GrRenderTargetContext> MakeFromVulkanSecondaryCB( |
| 136 | GrRecordingContext*, const SkImageInfo&, const GrVkDrawableInfo&, |
| 137 | const SkSurfaceProps*); |
| 138 | |
| 139 | GrRenderTargetContext(GrRecordingContext*, GrSurfaceProxyView readView, |
| 140 | GrSurfaceProxyView writeView, GrColorType, sk_sp<SkColorSpace>, |
| 141 | const SkSurfaceProps*, bool managedOpsTask = true); |
| 142 | |
| 143 | ~GrRenderTargetContext() override; |
| 144 | |
| 145 | /** |
| 146 | * Provides a perfomance hint that the render target's contents are allowed |
| 147 | * to become undefined. |
| 148 | */ |
| 149 | void discard(); |
| 150 | |
| 151 | /** |
| 152 | * Clear the rect of the render target to the given color. |
| 153 | * @param rect the rect to clear to |
| 154 | * @param color the color to clear to. |
| 155 | */ |
| 156 | void clear(const SkIRect& rect, const SkPMColor4f& color) { |
| 157 | this->internalClear(&rect, color); |
| 158 | } |
| 159 | // Clears the entire render target to the color. |
| 160 | void clear(const SkPMColor4f& color) { |
| 161 | this->internalClear(nullptr, color); |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * Draw everywhere (respecting the clip) with the paint. |
| 166 | */ |
| 167 | void drawPaint(const GrClip*, GrPaint&&, const SkMatrix& viewMatrix); |
| 168 | |
| 169 | /** |
| 170 | * Draw the rect using a paint. |
| 171 | * @param paint describes how to color pixels. |
| 172 | * @param GrAA Controls whether rect is antialiased |
| 173 | * @param viewMatrix transformation matrix |
| 174 | * @param style The style to apply. Null means fill. Currently path effects are not |
| 175 | * allowed. |
| 176 | * The rects coords are used to access the paint (through texture matrix) |
| 177 | */ |
| 178 | void drawRect(const GrClip*, |
| 179 | GrPaint&& paint, |
| 180 | GrAA, |
| 181 | const SkMatrix& viewMatrix, |
| 182 | const SkRect&, |
| 183 | const GrStyle* style = nullptr); |
| 184 | |
| 185 | /** |
| 186 | * Maps a rectangle of shader coordinates to a rectangle and fills that rectangle. |
| 187 | * |
| 188 | * @param paint describes how to color pixels. |
| 189 | * @param GrAA Controls whether rect is antialiased |
| 190 | * @param viewMatrix transformation matrix which applies to rectToDraw |
| 191 | * @param rectToDraw the rectangle to draw |
| 192 | * @param localRect the rectangle of shader coordinates applied to rectToDraw |
| 193 | */ |
| 194 | void fillRectToRect(const GrClip* clip, |
| 195 | GrPaint&& paint, |
| 196 | GrAA aa, |
| 197 | const SkMatrix& viewMatrix, |
| 198 | const SkRect& rectToDraw, |
| 199 | const SkRect& localRect) { |
| 200 | DrawQuad quad{GrQuad::MakeFromRect(rectToDraw, viewMatrix), GrQuad(localRect), |
| 201 | aa == GrAA::kYes ? GrQuadAAFlags::kAll : GrQuadAAFlags::kNone}; |
| 202 | this->drawFilledQuad(clip, std::move(paint), aa, &quad); |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Fills a rect with a paint and a localMatrix. |
| 207 | */ |
| 208 | void fillRectWithLocalMatrix(const GrClip* clip, |
| 209 | GrPaint&& paint, |
| 210 | GrAA aa, |
| 211 | const SkMatrix& viewMatrix, |
| 212 | const SkRect& rect, |
| 213 | const SkMatrix& localMatrix) { |
| 214 | DrawQuad quad{GrQuad::MakeFromRect(rect, viewMatrix), |
| 215 | GrQuad::MakeFromRect(rect, localMatrix), |
| 216 | aa == GrAA::kYes ? GrQuadAAFlags::kAll : GrQuadAAFlags::kNone}; |
| 217 | this->drawFilledQuad(clip, std::move(paint), aa, &quad); |
| 218 | } |
| 219 | |
| 220 | /** |
| 221 | * Creates an op that draws a fill rect with per-edge control over anti-aliasing. |
| 222 | * |
| 223 | * This is a specialized version of fillQuadWithEdgeAA, but is kept separate since knowing |
| 224 | * the geometry is a rectangle affords more optimizations. |
| 225 | */ |
| 226 | void fillRectWithEdgeAA(const GrClip* clip, GrPaint&& paint, GrAA aa, GrQuadAAFlags edgeAA, |
| 227 | const SkMatrix& viewMatrix, const SkRect& rect, |
| 228 | const SkRect* optionalLocalRect = nullptr) { |
| 229 | const SkRect& localRect = optionalLocalRect ? *optionalLocalRect : rect; |
| 230 | DrawQuad quad{GrQuad::MakeFromRect(rect, viewMatrix), GrQuad(localRect), edgeAA}; |
| 231 | this->drawFilledQuad(clip, std::move(paint), aa, &quad); |
| 232 | } |
| 233 | |
| 234 | /** |
| 235 | * Similar to fillRectWithEdgeAA but draws an arbitrary 2D convex quadrilateral transformed |
| 236 | * by 'viewMatrix', with per-edge control over anti-aliasing. The quad should follow the |
| 237 | * ordering used by SkRect::toQuad(), which determines how the edge AA is applied: |
| 238 | * - "top" = points [0] and [1] |
| 239 | * - "right" = points[1] and [2] |
| 240 | * - "bottom" = points[2] and [3] |
| 241 | * - "left" = points[3] and [0] |
| 242 | * |
| 243 | * The last argument, 'optionalLocalQuad', can be null if no separate local coordinates are |
| 244 | * necessary. |
| 245 | */ |
| 246 | void fillQuadWithEdgeAA(const GrClip* clip, GrPaint&& paint, GrAA aa, GrQuadAAFlags edgeAA, |
| 247 | const SkMatrix& viewMatrix, const SkPoint points[4], |
| 248 | const SkPoint optionalLocalPoints[4]) { |
| 249 | const SkPoint* localPoints = optionalLocalPoints ? optionalLocalPoints : points; |
| 250 | DrawQuad quad{GrQuad::MakeFromSkQuad(points, viewMatrix), |
| 251 | GrQuad::MakeFromSkQuad(localPoints, SkMatrix::I()), edgeAA}; |
| 252 | this->drawFilledQuad(clip, std::move(paint), aa, &quad); |
| 253 | } |
| 254 | |
| 255 | /** Used with drawQuadSet */ |
| 256 | struct QuadSetEntry { |
| 257 | SkRect fRect; |
| 258 | SkPMColor4f fColor; // Overrides any color on the GrPaint |
| 259 | SkMatrix fLocalMatrix; |
| 260 | GrQuadAAFlags fAAFlags; |
| 261 | }; |
| 262 | |
| 263 | // TODO(michaelludwig) - remove if the bulk API is not useful for SkiaRenderer |
| 264 | void drawQuadSet(const GrClip* clip, GrPaint&& paint, GrAA aa, const SkMatrix& viewMatrix, |
| 265 | const QuadSetEntry[], int cnt); |
| 266 | |
| 267 | /** |
| 268 | * Creates an op that draws a subrectangle of a texture. The passed color is modulated by the |
| 269 | * texture's color. 'srcRect' specifies the rectangle of the texture to draw. 'dstRect' |
| 270 | * specifies the rectangle to draw in local coords which will be transformed by 'viewMatrix' to |
| 271 | * device space. |
| 272 | */ |
| 273 | void drawTexture(const GrClip* clip, |
| 274 | GrSurfaceProxyView view, |
| 275 | SkAlphaType srcAlphaType, |
| 276 | GrSamplerState::Filter filter, |
| 277 | GrSamplerState::MipmapMode mm, |
| 278 | SkBlendMode mode, |
| 279 | const SkPMColor4f& color, |
| 280 | const SkRect& srcRect, |
| 281 | const SkRect& dstRect, |
| 282 | GrAA aa, |
| 283 | GrQuadAAFlags edgeAA, |
| 284 | SkCanvas::SrcRectConstraint constraint, |
| 285 | const SkMatrix& viewMatrix, |
| 286 | sk_sp<GrColorSpaceXform> texXform) { |
| 287 | const SkRect* subset = constraint == SkCanvas::kStrict_SrcRectConstraint ? |
| 288 | &srcRect : nullptr; |
| 289 | DrawQuad quad{GrQuad::MakeFromRect(dstRect, viewMatrix), GrQuad(srcRect), edgeAA}; |
| 290 | |
| 291 | this->drawTexturedQuad(clip, std::move(view), srcAlphaType, std::move(texXform), filter, mm, |
| 292 | color, mode, aa, &quad, subset); |
| 293 | } |
| 294 | |
| 295 | /** |
| 296 | * Variant of drawTexture that instead draws the texture applied to 'dstQuad' transformed by |
| 297 | * 'viewMatrix', using the 'srcQuad' texture coordinates clamped to the optional 'subset'. If |
| 298 | * 'subset' is null, it's equivalent to using the fast src rect constraint. If 'subset' is |
| 299 | * provided, the strict src rect constraint is applied using 'subset'. |
| 300 | */ |
| 301 | void drawTextureQuad(const GrClip* clip, |
| 302 | GrSurfaceProxyView view, |
| 303 | GrColorType srcColorType, |
| 304 | SkAlphaType srcAlphaType, |
| 305 | GrSamplerState::Filter filter, |
| 306 | GrSamplerState::MipmapMode mm, |
| 307 | SkBlendMode mode, |
| 308 | const SkPMColor4f& color, |
| 309 | const SkPoint srcQuad[4], |
| 310 | const SkPoint dstQuad[4], |
| 311 | GrAA aa, |
| 312 | GrQuadAAFlags edgeAA, |
| 313 | const SkRect* subset, |
| 314 | const SkMatrix& viewMatrix, |
| 315 | sk_sp<GrColorSpaceXform> texXform) { |
| 316 | DrawQuad quad{GrQuad::MakeFromSkQuad(dstQuad, viewMatrix), |
| 317 | GrQuad::MakeFromSkQuad(srcQuad, SkMatrix::I()), edgeAA}; |
| 318 | this->drawTexturedQuad(clip, std::move(view), srcAlphaType, std::move(texXform), filter, mm, |
| 319 | color, mode, aa, &quad, subset); |
| 320 | } |
| 321 | |
| 322 | /** Used with drawTextureSet */ |
| 323 | struct TextureSetEntry { |
| 324 | GrSurfaceProxyView fProxyView; |
| 325 | SkAlphaType fSrcAlphaType; |
| 326 | SkRect fSrcRect; |
| 327 | SkRect fDstRect; |
| 328 | const SkPoint* fDstClipQuad; // Must be null, or point to an array of 4 points |
| 329 | const SkMatrix* fPreViewMatrix; // If not null, entry's CTM is 'viewMatrix' * fPreViewMatrix |
| 330 | SkPMColor4f fColor; // {a,a,a,a} for rgb textures, {r,g,b,a} for alpha-only textures |
| 331 | GrQuadAAFlags fAAFlags; |
| 332 | }; |
| 333 | /** |
| 334 | * Draws a set of textures with a shared filter, color, view matrix, color xform, and |
| 335 | * texture color xform. The textures must all have the same GrTextureType and GrConfig. |
| 336 | * |
| 337 | * If any entries provide a non-null fDstClip array, it will be read from immediately based on |
| 338 | * fDstClipCount, so the pointer can become invalid after this returns. |
| 339 | * |
| 340 | * 'proxRunCnt' is the number of proxy changes encountered in the entry array. Technically this |
| 341 | * can be inferred from the array within this function, but the information is already known |
| 342 | * by SkGpuDevice, so no need to incur another iteration over the array. |
| 343 | */ |
| 344 | void drawTextureSet(const GrClip*, |
| 345 | TextureSetEntry[], |
| 346 | int cnt, |
| 347 | int proxyRunCnt, |
| 348 | GrSamplerState::Filter, |
| 349 | GrSamplerState::MipmapMode, |
| 350 | SkBlendMode mode, |
| 351 | GrAA aa, |
| 352 | SkCanvas::SrcRectConstraint, |
| 353 | const SkMatrix& viewMatrix, |
| 354 | sk_sp<GrColorSpaceXform> texXform); |
| 355 | |
| 356 | /** |
| 357 | * Draw a roundrect using a paint. |
| 358 | * |
| 359 | * @param paint describes how to color pixels. |
| 360 | * @param GrAA Controls whether rrect is antialiased. |
| 361 | * @param viewMatrix transformation matrix |
| 362 | * @param rrect the roundrect to draw |
| 363 | * @param style style to apply to the rrect. Currently path effects are not allowed. |
| 364 | */ |
| 365 | void drawRRect(const GrClip*, |
| 366 | GrPaint&&, |
| 367 | GrAA, |
| 368 | const SkMatrix& viewMatrix, |
| 369 | const SkRRect& rrect, |
| 370 | const GrStyle& style); |
| 371 | |
| 372 | /** |
| 373 | * Use a fast method to render the ambient and spot shadows for a path. |
| 374 | * Will return false if not possible for the given path. |
| 375 | * |
| 376 | * @param viewMatrix transformation matrix |
| 377 | * @param path the path to shadow |
| 378 | * @param rec parameters for shadow rendering |
| 379 | */ |
| 380 | bool drawFastShadow(const GrClip*, |
| 381 | const SkMatrix& viewMatrix, |
| 382 | const SkPath& path, |
| 383 | const SkDrawShadowRec& rec); |
| 384 | |
| 385 | /** |
| 386 | * Shortcut for filling a SkPath consisting of nested rrects using a paint. The result is |
| 387 | * undefined if outer does not contain inner. |
| 388 | * |
| 389 | * @param paint describes how to color pixels. |
| 390 | * @param GrAA Controls whether rrects edges are antialiased |
| 391 | * @param viewMatrix transformation matrix |
| 392 | * @param outer the outer roundrect |
| 393 | * @param inner the inner roundrect |
| 394 | */ |
| 395 | void drawDRRect(const GrClip*, |
| 396 | GrPaint&&, |
| 397 | GrAA, |
| 398 | const SkMatrix& viewMatrix, |
| 399 | const SkRRect& outer, |
| 400 | const SkRRect& inner); |
| 401 | |
| 402 | /** |
| 403 | * Draws a path. |
| 404 | * |
| 405 | * @param paint describes how to color pixels. |
| 406 | * @param GrAA Controls whether the path is antialiased. |
| 407 | * @param viewMatrix transformation matrix |
| 408 | * @param path the path to draw |
| 409 | * @param style style to apply to the path. |
| 410 | */ |
| 411 | void drawPath(const GrClip*, |
| 412 | GrPaint&&, |
| 413 | GrAA, |
| 414 | const SkMatrix& viewMatrix, |
| 415 | const SkPath&, |
| 416 | const GrStyle&); |
| 417 | |
| 418 | /** |
| 419 | * Draws a shape. |
| 420 | * |
| 421 | * @param paint describes how to color pixels. |
| 422 | * @param GrAA Controls whether the path is antialiased. |
| 423 | * @param viewMatrix transformation matrix |
| 424 | * @param shape the shape to draw |
| 425 | */ |
| 426 | void drawShape(const GrClip*, |
| 427 | GrPaint&&, |
| 428 | GrAA, |
| 429 | const SkMatrix& viewMatrix, |
| 430 | const GrStyledShape&); |
| 431 | |
| 432 | |
| 433 | /** |
| 434 | * Draws vertices with a paint. |
| 435 | * |
| 436 | * @param paint describes how to color pixels. |
| 437 | * @param viewMatrix transformation matrix |
| 438 | * @param vertices specifies the mesh to draw. |
| 439 | * @param overridePrimType primitive type to draw. If NULL, derive prim type from vertices. |
| 440 | * @param effect runtime effect that will handle custom vertex attributes. |
| 441 | */ |
| 442 | void drawVertices(const GrClip*, |
| 443 | GrPaint&& paint, |
| 444 | const SkMatrixProvider& matrixProvider, |
| 445 | sk_sp<SkVertices> vertices, |
| 446 | GrPrimitiveType* overridePrimType = nullptr, |
| 447 | const SkRuntimeEffect* effect = nullptr); |
| 448 | |
| 449 | /** |
| 450 | * Draws textured sprites from an atlas with a paint. This currently does not support AA for the |
| 451 | * sprite rectangle edges. |
| 452 | * |
| 453 | * @param paint describes how to color pixels. |
| 454 | * @param viewMatrix transformation matrix |
| 455 | * @param spriteCount number of sprites. |
| 456 | * @param xform array of compressed transformation data, required. |
| 457 | * @param texRect array of texture rectangles used to access the paint. |
| 458 | * @param colors optional array of per-sprite colors, supercedes |
| 459 | * the paint's color field. |
| 460 | */ |
| 461 | void drawAtlas(const GrClip*, |
| 462 | GrPaint&& paint, |
| 463 | const SkMatrix& viewMatrix, |
| 464 | int spriteCount, |
| 465 | const SkRSXform xform[], |
| 466 | const SkRect texRect[], |
| 467 | const SkColor colors[]); |
| 468 | |
| 469 | /** |
| 470 | * Draws a region. |
| 471 | * |
| 472 | * @param paint describes how to color pixels |
| 473 | * @param viewMatrix transformation matrix |
| 474 | * @param aa should the rects of the region be antialiased. |
| 475 | * @param region the region to be drawn |
| 476 | * @param style style to apply to the region |
| 477 | */ |
| 478 | void drawRegion(const GrClip*, |
| 479 | GrPaint&& paint, |
| 480 | GrAA aa, |
| 481 | const SkMatrix& viewMatrix, |
| 482 | const SkRegion& region, |
| 483 | const GrStyle& style, |
| 484 | const GrUserStencilSettings* ss = nullptr); |
| 485 | |
| 486 | /** |
| 487 | * Draws an oval. |
| 488 | * |
| 489 | * @param paint describes how to color pixels. |
| 490 | * @param GrAA Controls whether the oval is antialiased. |
| 491 | * @param viewMatrix transformation matrix |
| 492 | * @param oval the bounding rect of the oval. |
| 493 | * @param style style to apply to the oval. Currently path effects are not allowed. |
| 494 | */ |
| 495 | void drawOval(const GrClip*, |
| 496 | GrPaint&& paint, |
| 497 | GrAA, |
| 498 | const SkMatrix& viewMatrix, |
| 499 | const SkRect& oval, |
| 500 | const GrStyle& style); |
| 501 | |
| 502 | /** |
| 503 | * Draws a partial arc of an oval. |
| 504 | * |
| 505 | * @param paint describes how to color pixels. |
| 506 | * @param GrGrAA Controls whether the arc is antialiased. |
| 507 | * @param viewMatrix transformation matrix. |
| 508 | * @param oval the bounding rect of the oval. |
| 509 | * @param startAngle starting angle in degrees. |
| 510 | * @param sweepAngle angle to sweep in degrees. Must be in (-360, 360) |
| 511 | * @param useCenter true means that the implied path begins at the oval center, connects as |
| 512 | * a line to the point indicated by the start contains the arc indicated by |
| 513 | * the sweep angle. If false the line beginning at the center point is |
| 514 | * omitted. |
| 515 | * @param style style to apply to the oval. |
| 516 | */ |
| 517 | void drawArc(const GrClip*, |
| 518 | GrPaint&& paint, |
| 519 | GrAA, |
| 520 | const SkMatrix& viewMatrix, |
| 521 | const SkRect& oval, |
| 522 | SkScalar startAngle, |
| 523 | SkScalar sweepAngle, |
| 524 | bool useCenter, |
| 525 | const GrStyle& style); |
| 526 | |
| 527 | /** |
| 528 | * Draw the image as a set of rects, specified by |iter|. |
| 529 | */ |
| 530 | void drawImageLattice(const GrClip*, |
| 531 | GrPaint&&, |
| 532 | const SkMatrix& viewMatrix, |
| 533 | GrSurfaceProxyView, |
| 534 | SkAlphaType alphaType, |
| 535 | sk_sp<GrColorSpaceXform>, |
| 536 | GrSamplerState::Filter, |
| 537 | std::unique_ptr<SkLatticeIter>, |
| 538 | const SkRect& dst); |
| 539 | |
| 540 | /** |
| 541 | * Draw the text specified by the SkGlyphRunList. |
| 542 | * |
| 543 | * @param viewMatrix transformationMatrix |
| 544 | * @param glyphRunList text, text positions, and paint. |
| 545 | */ |
| 546 | void drawGlyphRunList(const GrClip*, |
| 547 | const SkMatrixProvider& viewMatrix, |
| 548 | const SkGlyphRunList& glyphRunList); |
| 549 | |
| 550 | /** |
| 551 | * Draws the src texture with no matrix. The dstRect is the dstPoint with the width and height |
| 552 | * of the srcRect. The srcRect and dstRect are clipped to the bounds of the src and dst surfaces |
| 553 | * respectively. |
| 554 | */ |
| 555 | bool blitTexture(GrSurfaceProxyView view, const SkIRect& srcRect, const SkIPoint& dstPoint); |
| 556 | |
| 557 | /** |
| 558 | * Adds the necessary signal and wait semaphores and adds the passed in SkDrawable to the |
| 559 | * command stream. |
| 560 | */ |
| 561 | void drawDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler>, const SkRect& bounds); |
| 562 | |
| 563 | /** |
| 564 | * The next time this GrRenderTargetContext is flushed, the gpu will wait on the passed in |
| 565 | * semaphores before executing any commands. |
| 566 | */ |
| 567 | bool waitOnSemaphores(int numSemaphores, const GrBackendSemaphore waitSemaphores[], |
| 568 | bool deleteSemaphoresAfterWait); |
| 569 | |
| 570 | int numSamples() const { return this->asRenderTargetProxy()->numSamples(); } |
| 571 | const SkSurfaceProps& surfaceProps() const { return fSurfaceProps; } |
| 572 | bool wrapsVkSecondaryCB() const { return this->asRenderTargetProxy()->wrapsVkSecondaryCB(); } |
| 573 | GrMipmapped mipmapped() const; |
| 574 | |
| 575 | // TODO: See if it makes sense for this to return a const& instead and require the callers to |
| 576 | // make a copy (which refs the proxy) if needed. |
| 577 | GrSurfaceProxyView writeSurfaceView() { return fWriteView; } |
| 578 | |
| 579 | // This entry point should only be called if the backing GPU object is known to be |
| 580 | // instantiated. |
| 581 | GrRenderTarget* accessRenderTarget() { return this->asSurfaceProxy()->peekRenderTarget(); } |
| 582 | |
| 583 | GrRenderTargetContext* asRenderTargetContext() override { return this; } |
| 584 | |
| 585 | // Provides access to functions that aren't part of the public API. |
| 586 | GrRenderTargetContextPriv priv(); |
| 587 | const GrRenderTargetContextPriv priv() const; // NOLINT(readability-const-return-type) |
| 588 | |
| 589 | void wasClosed(const GrOpsTask& task) override; |
| 590 | |
| 591 | #if GR_TEST_UTILS |
| 592 | bool testingOnly_IsInstantiated() const { return this->asSurfaceProxy()->isInstantiated(); } |
| 593 | void testingOnly_SetPreserveOpsOnFullClear() { fPreserveOpsOnFullClear_TestingOnly = true; } |
| 594 | GrOpsTask* testingOnly_PeekLastOpsTask() { return fOpsTask.get(); } |
| 595 | #endif |
| 596 | |
| 597 | private: |
| 598 | enum class QuadOptimization; |
| 599 | |
| 600 | GrAAType chooseAAType(GrAA); |
| 601 | |
| 602 | friend class GrClipStackClip; // for access to getOpsTask |
| 603 | friend class GrOnFlushResourceProvider; // for access to getOpsTask (http://skbug.com/9357) |
| 604 | |
| 605 | friend class GrRenderTargetContextPriv; |
| 606 | |
| 607 | // All the path and text renderers/ops currently make their own ops |
| 608 | friend class GrSoftwarePathRenderer; // for access to add[Mesh]DrawOp |
| 609 | friend class GrAAConvexPathRenderer; // for access to add[Mesh]DrawOp |
| 610 | friend class GrDashLinePathRenderer; // for access to add[Mesh]DrawOp |
| 611 | friend class GrAAHairLinePathRenderer; // for access to add[Mesh]DrawOp |
| 612 | friend class GrAALinearizingConvexPathRenderer; // for access to add[Mesh]DrawOp |
| 613 | friend class GrSmallPathRenderer; // for access to add[Mesh]DrawOp |
| 614 | friend class GrDefaultPathRenderer; // for access to add[Mesh]DrawOp |
| 615 | friend class GrStencilAndCoverPathRenderer; // for access to add[Mesh]DrawOp |
| 616 | friend class GrTriangulatingPathRenderer; // for access to add[Mesh]DrawOp |
| 617 | friend class GrCCPerFlushResources; // for access to addDrawOp |
| 618 | friend class GrCoverageCountingPathRenderer; // for access to addDrawOp |
| 619 | friend class GrFillRectOp; // for access to addDrawOp |
| 620 | friend class GrTessellationPathRenderer; // for access to addDrawOp |
| 621 | friend class GrTextureOp; // for access to addDrawOp |
| 622 | |
| 623 | SkDEBUGCODE(void onValidate() const override;) |
| 624 | |
| 625 | |
| 626 | GrOpsTask::CanDiscardPreviousOps canDiscardPreviousOpsOnFullClear() const; |
| 627 | void setNeedsStencil(bool useMixedSamplesIfNotMSAA); |
| 628 | |
| 629 | void internalClear(const SkIRect* scissor, const SkPMColor4f&, |
| 630 | bool upgradePartialToFull = false); |
| 631 | void internalStencilClear(const SkIRect* scissor, bool insideStencilMask); |
| 632 | |
| 633 | // Only consumes the GrPaint if successful. |
| 634 | bool drawFilledDRRect(const GrClip* clip, |
| 635 | GrPaint&& paint, |
| 636 | GrAA, |
| 637 | const SkMatrix& viewMatrix, |
| 638 | const SkRRect& origOuter, |
| 639 | const SkRRect& origInner); |
| 640 | |
| 641 | // If the drawn quad's paint is a const blended color, provide it as a non-null pointer to |
| 642 | // 'constColor', which enables the draw-as-clear optimization. Otherwise it is assumed the paint |
| 643 | // requires some form of shading that invalidates using a clear op. |
| 644 | // |
| 645 | // The non-const pointers should be the original draw request on input, and will be updated as |
| 646 | // appropriate depending on the returned optimization level. |
| 647 | // |
| 648 | // 'stencilSettings' are provided merely for decision making purposes; When non-null, |
| 649 | // optimization strategies that submit special ops are avoided. |
| 650 | QuadOptimization attemptQuadOptimization(const GrClip* clip, |
| 651 | const SkPMColor4f* constColor, |
| 652 | const GrUserStencilSettings* stencilSettings, |
| 653 | GrAA* aa, |
| 654 | DrawQuad* quad); |
| 655 | |
| 656 | // If stencil settings, 'ss', are non-null, AA controls MSAA or no AA. If they are null, then AA |
| 657 | // can choose between coverage, MSAA as per chooseAAType(). This will always attempt to apply |
| 658 | // quad optimizations, so all quad/rect public APIs should rely on this function for consistent |
| 659 | // clipping behavior. 'quad' will be modified in place to reflect final rendered geometry. |
| 660 | void drawFilledQuad(const GrClip* clip, |
| 661 | GrPaint&& paint, |
| 662 | GrAA aa, |
| 663 | DrawQuad* quad, |
| 664 | const GrUserStencilSettings* ss = nullptr); |
| 665 | |
| 666 | // Like drawFilledQuad but does not require using a GrPaint or FP for texturing. |
| 667 | // 'quad' may be modified in place to reflect final geometry. |
| 668 | void drawTexturedQuad(const GrClip* clip, |
| 669 | GrSurfaceProxyView proxyView, |
| 670 | SkAlphaType alphaType, |
| 671 | sk_sp<GrColorSpaceXform> textureXform, |
| 672 | GrSamplerState::Filter filter, |
| 673 | GrSamplerState::MipmapMode, |
| 674 | const SkPMColor4f& color, |
| 675 | SkBlendMode blendMode, |
| 676 | GrAA aa, |
| 677 | DrawQuad* quad, |
| 678 | const SkRect* subset = nullptr); |
| 679 | |
| 680 | // If 'attemptShapeFallback' is true, and the original shape had been simplfied, this |
| 681 | // will re-route through drawShape() to see if we can avoid path rendering one more time. |
| 682 | void drawShapeUsingPathRenderer(const GrClip*, GrPaint&&, GrAA, const SkMatrix&, |
| 683 | const GrStyledShape&, bool attemptShapeFallback = true); |
| 684 | |
| 685 | void addOp(std::unique_ptr<GrOp>); |
| 686 | |
| 687 | // Allows caller of addDrawOp to know which op list an op will be added to. |
| 688 | using WillAddOpFn = void(GrOp*, uint32_t opsTaskID); |
| 689 | // These perform processing specific to GrDrawOp-derived ops before recording them into an |
| 690 | // op list. Before adding the op to an op list the WillAddOpFn is called. Note that it |
| 691 | // will not be called in the event that the op is discarded. Moreover, the op may merge into |
| 692 | // another op after the function is called (either before addDrawOp returns or some time later). |
| 693 | // |
| 694 | // If the clip pointer is null, no clipping will be performed. |
| 695 | void addDrawOp(const GrClip*, std::unique_ptr<GrDrawOp>, |
| 696 | const std::function<WillAddOpFn>& = std::function<WillAddOpFn>()); |
| 697 | |
| 698 | // Makes a copy of the proxy if it is necessary for the draw and places the texture that should |
| 699 | // be used by GrXferProcessor to access the destination color in 'result'. If the return |
| 700 | // value is false then a texture copy could not be made. |
| 701 | // |
| 702 | // The op should have already had setClippedBounds called on it. |
| 703 | bool SK_WARN_UNUSED_RESULT setupDstProxyView(const GrOp& op, |
| 704 | GrXferProcessor::DstProxyView* result); |
| 705 | |
| 706 | GrOpsTask* getOpsTask(); |
| 707 | |
| 708 | SkGlyphRunListPainter* glyphPainter() { return &fGlyphPainter; } |
| 709 | |
| 710 | GrSurfaceProxyView fWriteView; |
| 711 | |
| 712 | // In MDB-mode the GrOpsTask can be closed by some other renderTargetContext that has picked |
| 713 | // it up. For this reason, the GrOpsTask should only ever be accessed via 'getOpsTask'. |
| 714 | sk_sp<GrOpsTask> fOpsTask; |
| 715 | |
| 716 | SkSurfaceProps fSurfaceProps; |
| 717 | bool fManagedOpsTask; |
| 718 | |
| 719 | int fNumStencilSamples = 0; |
| 720 | #if GR_TEST_UTILS |
| 721 | bool fPreserveOpsOnFullClear_TestingOnly = false; |
| 722 | #endif |
| 723 | SkGlyphRunListPainter fGlyphPainter; |
| 724 | typedef GrSurfaceContext INHERITED; |
| 725 | }; |
| 726 | |
| 727 | #endif |
| 728 | |