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