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