Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SurfaceDrawContext.cpp
Go to the documentation of this file.
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
9
19#include "src/base/SkVx.h"
27#include "src/core/SkMeshPriv.h"
53#include "src/gpu/ganesh/SkGr.h"
76
77#define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this->drawingManager()->getContext())
78#define ASSERT_SINGLE_OWNER SKGPU_ASSERT_SINGLE_OWNER(this->singleOwner())
79#define RETURN_IF_ABANDONED if (fContext->abandoned()) { return; }
80#define RETURN_FALSE_IF_ABANDONED if (fContext->abandoned()) { return false; }
81
82using namespace skia_private;
83
84//////////////////////////////////////////////////////////////////////////////
85
86namespace {
87
88void op_bounds(SkRect* bounds, const GrOp* op) {
89 *bounds = op->bounds();
90 if (op->hasZeroArea()) {
91 if (op->hasAABloat()) {
92 bounds->outset(0.5f, 0.5f);
93 } else {
94 // We don't know which way the particular GPU will snap lines or points at integer
95 // coords. So we ensure that the bounds is large enough for either snap.
96 SkRect before = *bounds;
97 bounds->roundOut(bounds);
98 if (bounds->fLeft == before.fLeft) {
99 bounds->fLeft -= 1;
100 }
101 if (bounds->fTop == before.fTop) {
102 bounds->fTop -= 1;
103 }
104 if (bounds->fRight == before.fRight) {
105 bounds->fRight += 1;
106 }
107 if (bounds->fBottom == before.fBottom) {
108 bounds->fBottom += 1;
109 }
110 }
111 }
112}
113
114} // anonymous namespace
115
116namespace skgpu::ganesh {
117
119
121public:
122 AutoCheckFlush(GrDrawingManager* drawingManager) : fDrawingManager(drawingManager) {
123 SkASSERT(fDrawingManager);
124 }
125 ~AutoCheckFlush() { fDrawingManager->flushIfNecessary(); }
126
127private:
128 GrDrawingManager* fDrawingManager;
129};
130
131std::unique_ptr<SurfaceDrawContext> SurfaceDrawContext::Make(GrRecordingContext* rContext,
134 sk_sp<SkColorSpace> colorSpace,
135 GrSurfaceOrigin origin,
136 const SkSurfaceProps& surfaceProps) {
137 if (!rContext || !proxy || colorType == GrColorType::kUnknown) {
138 return nullptr;
139 }
140
141 const GrBackendFormat& format = proxy->backendFormat();
143 skgpu::Swizzle writeSwizzle = rContext->priv().caps()->getWriteSwizzle(format, colorType);
144
145 GrSurfaceProxyView readView ( proxy, origin, readSwizzle);
146 GrSurfaceProxyView writeView(std::move(proxy), origin, writeSwizzle);
147
148 return std::make_unique<SurfaceDrawContext>(rContext,
149 std::move(readView),
150 std::move(writeView),
151 colorType,
152 std::move(colorSpace),
154}
155
156std::unique_ptr<SurfaceDrawContext> SurfaceDrawContext::Make(GrRecordingContext* rContext,
157 sk_sp<SkColorSpace> colorSpace,
158 SkBackingFit fit,
159 SkISize dimensions,
160 const GrBackendFormat& format,
161 int sampleCnt,
162 skgpu::Mipmapped mipmapped,
163 GrProtected isProtected,
164 skgpu::Swizzle readSwizzle,
165 skgpu::Swizzle writeSwizzle,
166 GrSurfaceOrigin origin,
167 skgpu::Budgeted budgeted,
168 const SkSurfaceProps& surfaceProps,
169 std::string_view label) {
170 // It is probably not necessary to check if the context is abandoned here since uses of the
171 // SurfaceDrawContext which need the context will mostly likely fail later on without an
172 // issue. However having this hear adds some reassurance in case there is a path doesn't handle
173 // an abandoned context correctly. It also lets us early out of some extra work.
174 if (rContext->abandoned()) {
175 return nullptr;
176 }
177
179 format,
181 GrRenderable::kYes,
182 sampleCnt,
183 mipmapped,
184 fit,
185 budgeted,
186 isProtected,
187 label);
188 if (!proxy) {
189 return nullptr;
190 }
191
192 GrSurfaceProxyView readView ( proxy, origin, readSwizzle);
193 GrSurfaceProxyView writeView(std::move(proxy), origin, writeSwizzle);
194
195 auto sdc = std::make_unique<SurfaceDrawContext>(rContext,
196 std::move(readView),
197 std::move(writeView),
199 std::move(colorSpace),
201 sdc->discard();
202 return sdc;
203}
204
205std::unique_ptr<SurfaceDrawContext> SurfaceDrawContext::Make(GrRecordingContext* rContext,
207 sk_sp<SkColorSpace> colorSpace,
208 SkBackingFit fit,
209 SkISize dimensions,
210 const SkSurfaceProps& surfaceProps,
211 std::string_view label,
212 int sampleCnt,
213 skgpu::Mipmapped mipmapped,
214 GrProtected isProtected,
215 GrSurfaceOrigin origin,
216 skgpu::Budgeted budgeted) {
217 if (!rContext) {
218 return nullptr;
219 }
220
221 auto format = rContext->priv().caps()->getDefaultBackendFormat(colorType, GrRenderable::kYes);
222 if (!format.isValid()) {
223 return nullptr;
224 }
226 format,
228 GrRenderable::kYes,
229 sampleCnt,
230 mipmapped,
231 fit,
232 budgeted,
233 isProtected,
234 label);
235 if (!proxy) {
236 return nullptr;
237 }
238
239 return SurfaceDrawContext::Make(rContext,
240 colorType,
241 std::move(proxy),
242 std::move(colorSpace),
243 origin,
245}
246
247std::unique_ptr<SurfaceDrawContext> SurfaceDrawContext::MakeWithFallback(
248 GrRecordingContext* rContext,
250 sk_sp<SkColorSpace> colorSpace,
251 SkBackingFit fit,
252 SkISize dimensions,
253 const SkSurfaceProps& surfaceProps,
254 int sampleCnt,
255 skgpu::Mipmapped mipmapped,
256 GrProtected isProtected,
257 GrSurfaceOrigin origin,
258 skgpu::Budgeted budgeted) {
259 const GrCaps* caps = rContext->priv().caps();
260 auto [ct, _] = caps->getFallbackColorTypeAndFormat(colorType, sampleCnt);
261 if (ct == GrColorType::kUnknown) {
262 return nullptr;
263 }
264 return SurfaceDrawContext::Make(rContext, ct, colorSpace, fit, dimensions, surfaceProps,
265 /*label=*/"MakeSurfaceDrawContextWithFallback", sampleCnt,
266 mipmapped, isProtected, origin, budgeted);
267}
268
269std::unique_ptr<SurfaceDrawContext> SurfaceDrawContext::MakeFromBackendTexture(
270 GrRecordingContext* rContext,
272 sk_sp<SkColorSpace> colorSpace,
273 const GrBackendTexture& tex,
274 int sampleCnt,
275 GrSurfaceOrigin origin,
276 const SkSurfaceProps& surfaceProps,
277 sk_sp<skgpu::RefCntedCallback> releaseHelper) {
278 SkASSERT(sampleCnt > 0);
281 std::move(releaseHelper)));
282 if (!proxy) {
283 return nullptr;
284 }
285
286 return SurfaceDrawContext::Make(rContext, colorType, std::move(proxy), std::move(colorSpace),
288}
289
290// In MDB mode the reffing of the 'getLastOpsTask' call's result allows in-progress
291// OpsTask to be picked up and added to by SurfaceDrawContexts lower in the call
292// stack. When this occurs with a closed OpsTask, a new one will be allocated
293// when the surfaceDrawContext attempts to use it (via getOpsTask).
295 GrSurfaceProxyView readView,
296 GrSurfaceProxyView writeView,
298 sk_sp<SkColorSpace> colorSpace,
299 const SkSurfaceProps& surfaceProps)
300 : SurfaceFillContext(rContext,
301 std::move(readView),
302 std::move(writeView),
303 {colorType, kPremul_SkAlphaType, std::move(colorSpace)})
304 , fSurfaceProps(surfaceProps)
305 , fCanUseDynamicMSAA(
306 (fSurfaceProps.flags() & SkSurfaceProps::kDynamicMSAA_Flag) &&
307 rContext->priv().caps()->supportsDynamicMSAA(this->asRenderTargetProxy())) {
308 SkDEBUGCODE(this->validate();)
309}
310
314
316 if (prevTask && fNeedsStencil) {
317 // Store the stencil values in memory upon completion of fOpsTask.
318 prevTask->setMustPreserveStencil();
319 // Reload the stencil buffer content at the beginning of newOpsTask.
320 // FIXME: Could the topo sort insert a task between these two that modifies the stencil
321 // values?
323 }
324#if GR_GPU_STATS && defined(GR_TEST_UTILS)
325 if (fCanUseDynamicMSAA) {
326 fContext->priv().dmsaaStats().fNumRenderPasses++;
327 }
328#endif
329}
330
332 const GrClip* clip,
333 const SkMatrix& viewMatrix,
334 const sktext::GlyphRunList& glyphRunList,
335 SkStrikeDeviceInfo strikeDeviceInfo,
336 const SkPaint& paint) {
339 SkDEBUGCODE(this->validate();)
340 GR_CREATE_TRACE_MARKER_CONTEXT("SurfaceDrawContext", "drawGlyphRunList", fContext);
341
342 // Drawing text can cause us to do inline uploads. This is not supported for wrapped vulkan
343 // secondary command buffers because it would require stopping and starting a render pass which
344 // we don't have access to.
345 if (this->wrapsVkSecondaryCB()) {
346 return;
347 }
348
350
351 auto atlasDelegate = [&](const sktext::gpu::AtlasSubRun* subRun,
352 SkPoint drawOrigin,
353 const SkPaint& paint,
354 sk_sp<SkRefCnt> subRunStorage,
356 auto [drawingClip, op] = subRun->makeAtlasTextOp(
357 clip, viewMatrix, drawOrigin, paint, std::move(subRunStorage), this);
358 if (op != nullptr) {
359 this->addDrawOp(drawingClip, std::move(op));
360 }
361 };
362
363 textBlobCache->drawGlyphRunList(
364 canvas, viewMatrix, glyphRunList, paint, strikeDeviceInfo, atlasDelegate);
365}
366
368 GrPaint&& paint,
369 const SkMatrix& viewMatrix) {
370 // Start with the render target, since that is the maximum content we could possibly fill.
371 // drawFilledQuad() will automatically restrict it to clip bounds for us if possible.
372 if (!paint.numTotalFragmentProcessors()) {
373 // The paint is trivial so we won't need to use local coordinates, so skip calculating the
374 // inverse view matrix.
375 SkRect r = this->asSurfaceProxy()->getBoundsRect();
376 this->fillRectToRect(clip, std::move(paint), GrAA::kNo, SkMatrix::I(), r, r);
377 } else {
378 // Use the inverse view matrix to arrive at appropriate local coordinates for the paint.
379 SkMatrix localMatrix;
380 if (!viewMatrix.invert(&localMatrix)) {
381 return;
382 }
384 this->fillPixelsWithLocalMatrix(clip, std::move(paint), bounds, localMatrix);
385 }
386}
387
389 // The rect to draw doesn't intersect clip or render target, so no draw op should be added
390 kDiscarded,
391 // The rect to draw was converted to some other op and appended to the oplist, so no additional
392 // op is necessary. Currently this can convert it to a clear op or a rrect op. Only valid if
393 // a constColor is provided.
394 kSubmitted,
395 // The clip was folded into the device quad, with updated edge flags and local coords, and
396 // caller is responsible for adding an appropriate op.
397 kClipApplied,
398 // No change to clip, but quad updated to better fit clip/render target, and caller is
399 // responsible for adding an appropriate op.
400 kCropped
401};
402
403SurfaceDrawContext::QuadOptimization SurfaceDrawContext::attemptQuadOptimization(
404 const GrClip* clip,
405 const GrUserStencilSettings* stencilSettings,
406 DrawQuad* quad,
407 GrPaint* paint) {
408 // Optimization requirements:
409 // 1. kDiscard applies when clip bounds and quad bounds do not intersect
410 // 2a. kSubmitted applies when constColor and final geom is pixel aligned rect;
411 // pixel aligned rect requires rect clip and (rect quad or quad covers clip) OR
412 // 2b. kSubmitted applies when constColor and rrect clip and quad covers clip
413 // 4. kClipApplied applies when rect clip and (rect quad or quad covers clip)
414 // 5. kCropped in all other scenarios (although a crop may be a no-op)
415 const SkPMColor4f* constColor = nullptr;
416 SkPMColor4f paintColor;
417 if (!stencilSettings && paint && !paint->hasCoverageFragmentProcessor() &&
418 paint->isConstantBlendedColor(&paintColor)) {
419 // Only consider clears/rrects when it's easy to guarantee 100% fill with single color
420 constColor = &paintColor;
421 }
422
423 // Save the old AA flags since CropToRect will modify 'quad' and if kCropped is returned, it's
424 // better to just keep the old flags instead of introducing mixed edge flags.
425 GrQuadAAFlags oldFlags = quad->fEdgeFlags;
426
427 // Use the logical size of the render target, which allows for "fullscreen" clears even if
428 // the render target has an approximate backing fit
429 SkRect rtRect = this->asSurfaceProxy()->getBoundsRect();
430
431 // For historical reasons, we assume AA for exact bounds checking in IsOutsideClip.
432 // TODO(michaelludwig) - Hopefully that can be revisited when the clipping optimizations are
433 // refactored to work better with round rects and dmsaa.
434 SkRect drawBounds = quad->fDevice.bounds();
435 if (!quad->fDevice.isFinite() || drawBounds.isEmpty() ||
436 GrClip::IsOutsideClip(SkIRect::MakeSize(this->dimensions()), drawBounds, GrAA::kYes)) {
439 // Don't try to apply the clip early if we know rendering will use hairline methods, as this
440 // has an effect on the op bounds not otherwise taken into account in this function.
442 }
443
444 GrAA drawUsesAA{quad->fEdgeFlags != GrQuadAAFlags::kNone};
445 auto conservativeCrop = [&]() {
446 static constexpr int kLargeDrawLimit = 15000;
447 // Crop the quad to the render target. This doesn't change the visual results of drawing but
448 // is meant to help numerical stability for excessively large draws.
449 if (drawBounds.width() > kLargeDrawLimit || drawBounds.height() > kLargeDrawLimit) {
450 GrQuadUtils::CropToRect(rtRect, drawUsesAA, quad, /* compute local */ !constColor);
451 }
452 };
453
454 bool simpleColor = !stencilSettings && constColor;
455 GrClip::PreClipResult result = clip ? clip->preApply(drawBounds, drawUsesAA)
457 switch(result.fEffect) {
461 if (!simpleColor) {
462 conservativeCrop();
464 } else {
465 // Update result to store the render target bounds in order and then fall
466 // through to attempt the draw->native clear optimization. Pick an AA value such
467 // that any geometric clipping doesn't need to change aa or edge flags (since we
468 // know this is on pixel boundaries, it will draw the same regardless).
469 // See skbug.com/13114 for more details.
470 result = GrClip::PreClipResult(SkRRect::MakeRect(rtRect), drawUsesAA);
471 }
472 break;
474 if (!result.fIsRRect || (stencilSettings && result.fAA != drawUsesAA) ||
475 (!result.fRRect.isRect() && !simpleColor)) {
476 // The clip and draw state are too complicated to try and reduce
477 conservativeCrop();
479 } // Else fall through to attempt to combine the draw and clip geometry together
480 break;
481 default:
483 }
484
485 // If we reached here, we know we're an axis-aligned clip that is either a rect or a round rect,
486 // so we can potentially combine it with the draw geometry so that no clipping is needed.
487 SkASSERT(result.fEffect == GrClip::Effect::kClipped && result.fIsRRect);
488 SkRect clippedBounds = result.fRRect.getBounds();
489 clippedBounds.intersect(rtRect);
490 if (!drawBounds.intersect(clippedBounds)) {
491 // Our fractional bounds aren't actually inside the clip. GrClip::preApply() can sometimes
492 // think in terms of rounded-out bounds. Discard the draw.
494 }
495 // Guard against the clipped draw turning into a hairline draw after intersection
496 if (drawBounds.width() < 1.f || drawBounds.height() < 1.f) {
498 }
499
500 if (result.fRRect.isRect()) {
501 // No rounded corners, so we might be able to become a native clear or we might be able to
502 // modify geometry and edge flags to represent intersected shape of clip and draw.
503 if (GrQuadUtils::CropToRect(clippedBounds, result.fAA, quad,
504 /*compute local*/ !constColor)) {
505 if (simpleColor && quad->fDevice.quadType() == GrQuad::Type::kAxisAligned) {
506 // Clear optimization is possible
507 drawBounds = quad->fDevice.bounds();
508 if (drawBounds.contains(rtRect)) {
509 // Fullscreen clear
510 this->clear(*constColor);
512 } else if (GrClip::IsPixelAligned(drawBounds) &&
513 drawBounds.width() > 256 && drawBounds.height() > 256) {
514 // Scissor + clear (round shouldn't do anything since we are pixel aligned)
515 SkIRect scissorRect;
516 drawBounds.round(&scissorRect);
517 this->clear(scissorRect, *constColor);
519 }
520 }
521
523 }
524 } else {
525 // Rounded corners and constant filled color (limit ourselves to solid colors because
526 // there is no way to use custom local coordinates with drawRRect).
527 SkASSERT(simpleColor);
528 if (GrQuadUtils::CropToRect(clippedBounds, result.fAA, quad,
529 /* compute local */ false) &&
531 quad->fDevice.bounds().contains(clippedBounds)) {
532 // Since the cropped quad became a rectangle which covered the bounds of the rrect,
533 // we can draw the rrect directly and ignore the edge flags
534 this->drawRRect(nullptr, std::move(*paint), result.fAA, SkMatrix::I(), result.fRRect,
537 }
538 }
539
540 // The quads have been updated to better fit the clip bounds, but can't get rid of
541 // the clip entirely
542 quad->fEdgeFlags = oldFlags;
544}
545
546void SurfaceDrawContext::drawFilledQuad(const GrClip* clip,
547 GrPaint&& paint,
548 DrawQuad* quad,
549 const GrUserStencilSettings* ss) {
552 SkDEBUGCODE(this->validate();)
553 GR_CREATE_TRACE_MARKER_CONTEXT("SurfaceDrawContext", "drawFilledQuad", fContext);
554
555 AutoCheckFlush acf(this->drawingManager());
556
557 QuadOptimization opt = this->attemptQuadOptimization(clip, ss, quad, &paint);
559 // These optimizations require caller to add an op themselves
560 const GrClip* finalClip = opt == QuadOptimization::kClipApplied ? nullptr : clip;
561 // The quad being drawn requires AA if any of its edges requires AA
563 GrAAType aaType;
564 if (ss) {
565 aaType = (aa == GrAA::kYes) ? GrAAType::kMSAA : GrAAType::kNone;
566 } else if (fCanUseDynamicMSAA && aa == GrAA::kNo) {
567 // The SkGpuDevice ensures GrAA is always kYes when using dmsaa. If the caller calls
568 // into here with GrAA::kNo, trust that they know what they're doing and that the
569 // rendering will be equal with or without msaa.
570 aaType = GrAAType::kNone;
571 } else {
572 aaType = this->chooseAAType(aa);
573 }
574 this->addDrawOp(finalClip, FillRectOp::Make(fContext, std::move(paint), aaType,
575 quad, ss));
576 }
577 // All other optimization levels were completely handled inside attempt(), so no extra op needed
578}
579
582 SkAlphaType srcAlphaType,
585 SkBlendMode blendMode,
586 const SkPMColor4f& color,
587 const SkRect& srcRect,
588 const SkRect& dstRect,
589 GrQuadAAFlags edgeAA,
591 const SkMatrix& viewMatrix,
592 sk_sp<GrColorSpaceXform> colorSpaceXform) {
593 // If we are using dmsaa then go through FillRRectOp (via fillRectToRect).
594 if ((this->alwaysAntialias() || this->caps()->reducedShaderMode()) &&
595 edgeAA != GrQuadAAFlags::kNone) {
596 auto [mustFilter, mustMM] = FilterAndMipmapHaveNoEffect(
597 GrQuad::MakeFromRect(dstRect, viewMatrix), GrQuad(srcRect));
598 if (!mustFilter) {
599 // Chromeos-jacuzzi devices (ARM Mali-G72 MP3) have issues with blitting with linear
600 // filtering. Likely some optimization or quantization causes fragments to be produced
601 // with small offset/error. This will result in a slight blending of pixels when
602 // sampling. Normally in most application this would be completely unnoticeable but when
603 // trying to use the gpu as a per pixel blit we will end up with slightly blurry
604 // results.
605 // See https://crbug.com/326980863
606 filter = GrSamplerState::Filter::kNearest;
607 }
608
610 paint.setColor4f(color);
611 std::unique_ptr<GrFragmentProcessor> fp;
612 if (constraint == SkCanvas::kStrict_SrcRectConstraint) {
613 fp = GrTextureEffect::MakeSubset(view, srcAlphaType, SkMatrix::I(),
614 GrSamplerState(filter, mm), srcRect,
615 *this->caps());
616 } else {
617 fp = GrTextureEffect::Make(view, srcAlphaType, SkMatrix::I(), filter, mm);
618 }
619 if (colorSpaceXform) {
620 fp = GrColorSpaceXformEffect::Make(std::move(fp), std::move(colorSpaceXform));
621 }
622 fp = GrBlendFragmentProcessor::Make<SkBlendMode::kModulate>(std::move(fp), nullptr);
623 paint.setColorFragmentProcessor(std::move(fp));
624 if (blendMode != SkBlendMode::kSrcOver) {
625 paint.setXPFactory(GrXPFactory::FromBlendMode(blendMode));
626 }
627 this->fillRectToRect(clip, std::move(paint), GrAA::kYes, viewMatrix, dstRect, srcRect);
628 return;
629 }
630
631 const SkRect* subset = constraint == SkCanvas::kStrict_SrcRectConstraint ?
632 &srcRect : nullptr;
633 DrawQuad quad{GrQuad::MakeFromRect(dstRect, viewMatrix), GrQuad(srcRect), edgeAA};
634
635 this->drawTexturedQuad(clip, std::move(view), srcAlphaType, std::move(colorSpaceXform), filter,
636 mm, color, blendMode, &quad, subset);
637}
638
639void SurfaceDrawContext::drawTexturedQuad(const GrClip* clip,
640 GrSurfaceProxyView proxyView,
641 SkAlphaType srcAlphaType,
642 sk_sp<GrColorSpaceXform> textureXform,
645 const SkPMColor4f& color,
646 SkBlendMode blendMode,
647 DrawQuad* quad,
648 const SkRect* subset) {
651 SkDEBUGCODE(this->validate();)
652 SkASSERT(proxyView.asTextureProxy());
653 GR_CREATE_TRACE_MARKER_CONTEXT("SurfaceDrawContext", "drawTexturedQuad", fContext);
654
655 AutoCheckFlush acf(this->drawingManager());
656
657 // Functionally this is very similar to drawFilledQuad except that there's no constColor to
658 // enable the kSubmitted optimizations, no stencil settings support, and its a TextureOp.
659 QuadOptimization opt = this->attemptQuadOptimization(clip, nullptr/*stencil*/, quad,
660 nullptr/*paint*/);
661
663 if (opt != QuadOptimization::kDiscarded) {
664 // Add the texture op if not discarded
665 const GrClip* finalClip = opt == QuadOptimization::kClipApplied ? nullptr : clip;
666 GrAAType aaType = this->chooseAAType(GrAA{quad->fEdgeFlags != GrQuadAAFlags::kNone});
667 auto clampType = GrColorTypeClampType(this->colorInfo().colorType());
668 auto saturate = clampType == GrClampType::kManual ? ganesh::TextureOp::Saturate::kYes
670 // Use the provided subset, although hypothetically we could detect that the cropped local
671 // quad is sufficiently inside the subset and the constraint could be dropped.
672 this->addDrawOp(finalClip,
673 ganesh::TextureOp::Make(fContext, std::move(proxyView), srcAlphaType,
674 std::move(textureXform), filter, mm, color,
675 saturate, blendMode, aaType, quad, subset));
676 }
677}
678
680 GrPaint&& paint,
681 GrAA aa,
682 const SkMatrix& viewMatrix,
683 const SkRect& rect,
684 const GrStyle* style) {
685 if (!style) {
686 style = &GrStyle::SimpleFill();
687 }
690 SkDEBUGCODE(this->validate();)
691 GR_CREATE_TRACE_MARKER_CONTEXT("SurfaceDrawContext", "drawRect", fContext);
692
693 // Path effects should've been devolved to a path in SkGpuDevice
694 SkASSERT(!style->pathEffect());
695
696 AutoCheckFlush acf(this->drawingManager());
697
698 const SkStrokeRec& stroke = style->strokeRec();
699 if (stroke.getStyle() == SkStrokeRec::kFill_Style) {
700 // Fills the rect, using rect as its own local coordinates
701 this->fillRectToRect(clip, std::move(paint), aa, viewMatrix, rect, rect);
702 return;
703 } else if ((stroke.getStyle() == SkStrokeRec::kStroke_Style ||
705 rect.width() &&
706 rect.height() &&
707 !this->caps()->reducedShaderMode()) {
708 // Only use the StrokeRectOp for non-empty rectangles. Empty rectangles will be processed by
709 // GrStyledShape to handle stroke caps and dashing properly.
710 //
711 // http://skbug.com/12206 -- there is a double-blend issue with the bevel version of
712 // AAStrokeRectOp, and if we increase the AA bloat for MSAA it becomes more pronounced.
713 // Don't use the bevel version with DMSAA.
714 GrAAType aaType = (fCanUseDynamicMSAA &&
715 stroke.getJoin() == SkPaint::kMiter_Join &&
717 : this->chooseAAType(aa);
718 GrOp::Owner op = ganesh::StrokeRectOp::Make(fContext, std::move(paint), aaType, viewMatrix,
719 rect, stroke);
720 // op may be null if the stroke is not supported or if using coverage aa and the view matrix
721 // does not preserve rectangles.
722 if (op) {
723 this->addDrawOp(clip, std::move(op));
724 return;
725 }
726 }
727 assert_alive(paint);
728 this->drawShapeUsingPathRenderer(clip, std::move(paint), aa, viewMatrix,
729 GrStyledShape(rect, *style, DoSimplify::kNo));
730}
731
733 GrPaint&& paint,
734 GrAA aa,
735 const SkMatrix& viewMatrix,
736 const SkRect& rectToDraw,
737 const SkRect& localRect) {
738 DrawQuad quad{GrQuad::MakeFromRect(rectToDraw, viewMatrix), GrQuad(localRect),
740
741 // If we are using dmsaa then attempt to draw the rect with FillRRectOp.
742 if ((fContext->priv().caps()->reducedShaderMode() || this->alwaysAntialias()) &&
743 this->caps()->drawInstancedSupport() &&
744 aa == GrAA::kYes) { // If aa is kNo when using dmsaa, the rect is axis aligned. Don't use
745 // FillRRectOp because it might require dual source blending.
746 // http://skbug.com/11756
747 QuadOptimization opt = this->attemptQuadOptimization(clip, nullptr/*stencil*/, &quad,
748 &paint);
750 // The optimization was completely handled inside attempt().
751 return;
752 }
753
754 SkRect croppedRect, croppedLocal{};
755 const GrClip* optimizedClip = clip;
756 if (clip && viewMatrix.isScaleTranslate() && quad.fDevice.asRect(&croppedRect) &&
757 (!paint.usesLocalCoords() || quad.fLocal.asRect(&croppedLocal))) {
758 // The cropped quad is still a rect, and our view matrix preserves rects. Map it back
759 // to pre-matrix space.
760 SkMatrix inverse;
761 if (!viewMatrix.invert(&inverse)) {
762 return;
763 }
764 SkASSERT(inverse.rectStaysRect());
765 inverse.mapRect(&croppedRect);
767 optimizedClip = nullptr;
768 }
769 } else {
770 // Even if attemptQuadOptimization gave us an optimized quad, FillRRectOp needs a rect
771 // in pre-matrix space, so use the original rect. Also preserve the original clip.
772 croppedRect = rectToDraw;
773 croppedLocal = localRect;
774 }
775
776 if (auto op = FillRRectOp::Make(fContext, this->arenaAlloc(), std::move(paint),
777 viewMatrix, SkRRect::MakeRect(croppedRect), croppedLocal,
778 GrAA::kYes)) {
779 this->addDrawOp(optimizedClip, std::move(op));
780 return;
781 }
782 }
783
784 assert_alive(paint);
785 this->drawFilledQuad(clip, std::move(paint), &quad);
786}
787
789 GrPaint&& paint,
790 const SkMatrix& viewMatrix,
791 const GrQuadSetEntry quads[],
792 int cnt) {
793 GrAAType aaType = this->chooseAAType(GrAA::kYes);
794
795 FillRectOp::AddFillRectOps(this, clip, fContext, std::move(paint), aaType, viewMatrix,
796 quads, cnt);
797}
798
802
804#if defined(GR_TEST_UTILS)
805 if (fPreserveOpsOnFullClear_TestingOnly) {
807 }
808#endif
809 // Regardless of how the clear is implemented (native clear or a fullscreen quad), all prior ops
810 // would normally be overwritten. The one exception is if the render target context is marked as
811 // needing a stencil buffer then there may be a prior op that writes to the stencil buffer.
812 // Although the clear will ignore the stencil buffer, following draw ops may not so we can't get
813 // rid of all the preceding ops. Beware! If we ever add any ops that have a side effect beyond
814 // modifying the stencil buffer we will need a more elaborate tracking system (skbug.com/7002).
815 return OpsTask::CanDiscardPreviousOps(!fNeedsStencil);
816}
817
818void SurfaceDrawContext::setNeedsStencil() {
819 // Don't clear stencil until after we've set fNeedsStencil. This ensures we don't loop forever
820 // in the event that there are driver bugs and we need to clear as a draw.
821 bool hasInitializedStencil = fNeedsStencil;
822 fNeedsStencil = true;
823 if (!hasInitializedStencil) {
825 if (this->caps()->performStencilClearsAsDraws()) {
826 // There is a driver bug with clearing stencil. We must use an op to manually clear the
827 // stencil buffer before the op that required 'setNeedsStencil'.
828 this->internalStencilClear(nullptr, /* inside mask */ false);
829 } else {
832 }
833 }
834}
835
836void SurfaceDrawContext::internalStencilClear(const SkIRect* scissor, bool insideStencilMask) {
837 this->setNeedsStencil();
838
839 GrScissorState scissorState(this->asSurfaceProxy()->backingStoreDimensions());
840 if (scissor && !scissorState.set(*scissor)) {
841 // The requested clear region is off screen, so nothing to do.
842 return;
843 }
844
845 bool clearWithDraw = this->caps()->performStencilClearsAsDraws() ||
846 (scissorState.enabled() && this->caps()->performPartialClearsAsDraws());
847 if (clearWithDraw) {
849
850 // Configure the paint to have no impact on the color buffer
852 paint.setXPFactory(GrDisableColorXPFactory::Get());
853 this->addDrawOp(nullptr,
855 SkRect::Make(scissorState.rect()), ss));
856 } else {
857 this->addOp(ClearOp::MakeStencilClip(fContext, scissorState, insideStencilMask));
858 }
859}
860
862 GrAA doStencilMSAA,
863 const SkMatrix& viewMatrix,
864 const SkPath& path) {
865 SkIRect clipBounds = clip ? clip->getConservativeBounds()
866 : SkIRect::MakeSize(this->dimensions());
868
870 canDrawArgs.fCaps = fContext->priv().caps();
871 canDrawArgs.fProxy = this->asRenderTargetProxy();
872 canDrawArgs.fClipConservativeBounds = &clipBounds;
873 canDrawArgs.fViewMatrix = &viewMatrix;
874 canDrawArgs.fShape = &shape;
875 canDrawArgs.fPaint = nullptr;
876 canDrawArgs.fSurfaceProps = &fSurfaceProps;
877 canDrawArgs.fAAType = (doStencilMSAA == GrAA::kYes) ? GrAAType::kMSAA : GrAAType::kNone;
878 canDrawArgs.fHasUserStencilSettings = false;
879 auto pr = this->drawingManager()->getPathRenderer(canDrawArgs,
880 false,
882 if (!pr) {
883 SkDebugf("WARNING: No path renderer to stencil path.\n");
884 return false;
885 }
886
888 args.fContext = fContext;
889 args.fSurfaceDrawContext = this;
890 args.fClip = clip;
891 args.fClipConservativeBounds = &clipBounds;
892 args.fViewMatrix = &viewMatrix;
893 args.fShape = &shape;
894 args.fDoStencilMSAA = doStencilMSAA;
895 pr->stencilPath(args);
896 return true;
897}
898
900 GrTextureSetEntry set[],
901 int cnt,
902 int proxyRunCnt,
905 SkBlendMode mode,
907 const SkMatrix& viewMatrix,
908 sk_sp<GrColorSpaceXform> texXform) {
911 SkDEBUGCODE(this->validate();)
912 GR_CREATE_TRACE_MARKER_CONTEXT("SurfaceDrawContext", "drawTextureSet", fContext);
913
914 // Create the minimum number of GrTextureOps needed to draw this set. Individual
915 // GrTextureOps can rebind the texture between draws thus avoiding GrPaint (re)creation.
916 AutoCheckFlush acf(this->drawingManager());
917 GrAAType aaType = this->chooseAAType(GrAA::kYes);
918 auto clampType = GrColorTypeClampType(this->colorInfo().colorType());
919 auto saturate = clampType == GrClampType::kManual ? ganesh::TextureOp::Saturate::kYes
921 ganesh::TextureOp::AddTextureSetOps(this, clip, fContext, set, cnt, proxyRunCnt, filter, mm,
922 saturate, mode, aaType, constraint, viewMatrix,
923 std::move(texXform));
924}
925
927 GrPaint&& paint,
928 const SkMatrix& viewMatrix,
929 sk_sp<SkVertices> vertices,
930 GrPrimitiveType* overridePrimType,
931 bool skipColorXform) {
934 SkDEBUGCODE(this->validate();)
935 GR_CREATE_TRACE_MARKER_CONTEXT("SurfaceDrawContext", "drawVertices", fContext);
936
937 AutoCheckFlush acf(this->drawingManager());
938
939 SkASSERT(vertices);
940 auto xform = skipColorXform ? nullptr : this->colorInfo().refColorSpaceXformFromSRGB();
941 GrAAType aaType = fCanUseDynamicMSAA ? GrAAType::kMSAA : this->chooseAAType(GrAA::kNo);
943 std::move(paint),
944 std::move(vertices),
945 overridePrimType,
946 viewMatrix,
947 aaType,
948 std::move(xform));
949 this->addDrawOp(clip, std::move(op));
950}
951
953 GrPaint&& paint,
954 const SkMatrix& viewMatrix,
955 const SkMesh& mesh,
956 TArray<std::unique_ptr<GrFragmentProcessor>> children) {
959 SkDEBUGCODE(this->validate();)
960 GR_CREATE_TRACE_MARKER_CONTEXT("SurfaceDrawContext", "drawMesh", fContext);
961
962 AutoCheckFlush acf(this->drawingManager());
963
964 SkASSERT(mesh.isValid());
965
968 this->colorInfo().colorSpace(),
969 this->colorInfo().alphaType());
970 GrAAType aaType = fCanUseDynamicMSAA ? GrAAType::kMSAA : this->chooseAAType(GrAA::kNo);
972 std::move(paint),
973 mesh,
974 std::move(children),
975 viewMatrix,
976 aaType,
977 std::move(xform));
978 this->addDrawOp(clip, std::move(op));
979}
980
981///////////////////////////////////////////////////////////////////////////////
982
984 GrPaint&& paint,
985 const SkMatrix& viewMatrix,
986 int spriteCount,
987 const SkRSXform xform[],
988 const SkRect texRect[],
989 const SkColor colors[]) {
992 SkDEBUGCODE(this->validate();)
993 GR_CREATE_TRACE_MARKER_CONTEXT("SurfaceDrawContext", "drawAtlas", fContext);
994
995 AutoCheckFlush acf(this->drawingManager());
996
997 GrAAType aaType = this->chooseAAType(GrAA::kNo);
998 GrOp::Owner op = DrawAtlasOp::Make(fContext, std::move(paint), viewMatrix,
999 aaType, spriteCount, xform, texRect, colors);
1000 this->addDrawOp(clip, std::move(op));
1001}
1002
1003///////////////////////////////////////////////////////////////////////////////
1004
1006 GrPaint&& paint,
1007 GrAA aa,
1008 const SkMatrix& viewMatrix,
1009 const SkRRect& rrect,
1010 const GrStyle& style) {
1013 SkDEBUGCODE(this->validate();)
1014 GR_CREATE_TRACE_MARKER_CONTEXT("SurfaceDrawContext", "drawRRect", fContext);
1015
1016 SkASSERT(!style.pathEffect()); // this should've been devolved to a path in SkGpuDevice
1017
1018 const SkStrokeRec& stroke = style.strokeRec();
1019 if (stroke.getStyle() == SkStrokeRec::kFill_Style && rrect.isEmpty()) {
1020 return;
1021 }
1022
1023 const GrClip* clip = origClip;
1024 // It is not uncommon to clip to a round rect and then draw that same round rect. Since our
1025 // lower level clip code works from op bounds, which are SkRects, it doesn't detect that the
1026 // clip can be ignored. The following test attempts to mitigate the stencil clip cost but only
1027 // works for axis-aligned round rects. This also only works for filled rrects since the stroke
1028 // width outsets beyond the rrect itself.
1029 // TODO: skbug.com/10462 - There was mixed performance wins and regressions when this
1030 // optimization was turned on outside of Android Framework. I (michaelludwig) believe this is
1031 // do to the overhead in determining if an SkClipStack is just a rrect. Once that is improved,
1032 // re-enable this and see if we avoid the regressions.
1033#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
1034 SkRRect devRRect;
1035 if (clip && stroke.getStyle() == SkStrokeRec::kFill_Style &&
1036 rrect.transform(viewMatrix, &devRRect)) {
1037 GrClip::PreClipResult result = clip->preApply(devRRect.getBounds(), aa);
1038 switch(result.fEffect) {
1040 return;
1042 clip = nullptr;
1043 break;
1045 // Currently there's no general-purpose rrect-to-rrect contains function, and if we
1046 // got here, we know the devRRect's bounds aren't fully contained by the clip.
1047 // Testing for equality between the two is a reasonable stop-gap for now.
1048 if (result.fIsRRect && result.fRRect == devRRect) {
1049 // NOTE: On the android framework, we allow this optimization even when the clip
1050 // is non-AA and the draw is AA.
1051 if (result.fAA == aa || (result.fAA == GrAA::kNo && aa == GrAA::kYes)) {
1052 clip = nullptr;
1053 }
1054 }
1055 break;
1056 default:
1058 }
1059 }
1060#endif
1061
1062 AutoCheckFlush acf(this->drawingManager());
1063
1064 GrAAType aaType = this->chooseAAType(aa);
1065
1066 GrOp::Owner op;
1067#ifndef SK_ENABLE_OPTIMIZE_SIZE
1068 if (aaType == GrAAType::kCoverage &&
1069 !fCanUseDynamicMSAA &&
1070 !this->caps()->reducedShaderMode() &&
1071 rrect.isSimple() &&
1072 rrect.getSimpleRadii().fX == rrect.getSimpleRadii().fY &&
1073 viewMatrix.rectStaysRect() && viewMatrix.isSimilarity()) {
1074 // In specific cases we use a dedicated circular round rect op to try and get better perf.
1075 assert_alive(paint);
1076 op = GrOvalOpFactory::MakeCircularRRectOp(fContext, std::move(paint), viewMatrix, rrect,
1077 stroke, this->caps()->shaderCaps());
1078 }
1079#endif
1080 if (!op && style.isSimpleFill()) {
1081 assert_alive(paint);
1082 op = FillRRectOp::Make(fContext, this->arenaAlloc(), std::move(paint), viewMatrix, rrect,
1083 rrect.rect(), GrAA(aaType != GrAAType::kNone));
1084 }
1085#ifndef SK_ENABLE_OPTIMIZE_SIZE
1086 if (!op && (aaType == GrAAType::kCoverage || fCanUseDynamicMSAA)) {
1087 assert_alive(paint);
1089 fContext, std::move(paint), viewMatrix, rrect, stroke, this->caps()->shaderCaps());
1090 }
1091#endif
1092 if (op) {
1093 this->addDrawOp(clip, std::move(op));
1094 return;
1095 }
1096
1097 assert_alive(paint);
1098 this->drawShapeUsingPathRenderer(clip, std::move(paint), aa, viewMatrix,
1099 GrStyledShape(rrect, style, DoSimplify::kNo));
1100}
1101
1102///////////////////////////////////////////////////////////////////////////////
1103
1105 const SkMatrix& viewMatrix,
1106 const SkPath& path,
1107 const SkDrawShadowRec& rec) {
1109 if (fContext->abandoned()) {
1110 return true;
1111 }
1112 SkDEBUGCODE(this->validate();)
1113 GR_CREATE_TRACE_MARKER_CONTEXT("SurfaceDrawContext", "drawFastShadow", fContext);
1114
1115 // check z plane
1116 bool tiltZPlane = SkToBool(!SkScalarNearlyZero(rec.fZPlaneParams.fX) ||
1118 bool skipAnalytic = SkToBool(rec.fFlags & SkShadowFlags::kGeometricOnly_ShadowFlag);
1119 if (tiltZPlane || skipAnalytic || !viewMatrix.rectStaysRect() || !viewMatrix.isSimilarity()) {
1120 return false;
1121 }
1122
1123 SkRRect rrect;
1124 SkRect rect;
1125 // we can only handle rects, circles, and simple rrects with circular corners
1126 bool isRRect = path.isRRect(&rrect) && SkRRectPriv::IsNearlySimpleCircular(rrect) &&
1128 if (!isRRect &&
1129 path.isOval(&rect) && SkScalarNearlyEqual(rect.width(), rect.height()) &&
1130 rect.width() > SK_ScalarNearlyZero) {
1131 rrect.setOval(rect);
1132 isRRect = true;
1133 }
1134 if (!isRRect && path.isRect(&rect)) {
1135 rrect.setRect(rect);
1136 isRRect = true;
1137 }
1138
1139 if (!isRRect) {
1140 return false;
1141 }
1142
1143 if (rrect.isEmpty()) {
1144 return true;
1145 }
1146
1147 AutoCheckFlush acf(this->drawingManager());
1148
1149 SkPoint3 devLightPos = rec.fLightPos;
1150 bool directional = SkToBool(rec.fFlags & kDirectionalLight_ShadowFlag);
1151 if (!directional) {
1152 // transform light
1153 viewMatrix.mapPoints((SkPoint*)&devLightPos.fX, 1);
1154 }
1155
1156 // 1/scale
1157 SkScalar devToSrcScale = viewMatrix.isScaleTranslate() ?
1159 sk_float_rsqrt(viewMatrix[SkMatrix::kMScaleX] * viewMatrix[SkMatrix::kMScaleX] +
1160 viewMatrix[SkMatrix::kMSkewX] * viewMatrix[SkMatrix::kMSkewX]);
1161
1162 SkScalar occluderHeight = rec.fZPlaneParams.fZ;
1164
1165 if (SkColorGetA(rec.fAmbientColor) > 0) {
1166 SkScalar devSpaceInsetWidth = SkDrawShadowMetrics::AmbientBlurRadius(occluderHeight);
1167 const SkScalar umbraRecipAlpha = SkDrawShadowMetrics::AmbientRecipAlpha(occluderHeight);
1168 const SkScalar devSpaceAmbientBlur = devSpaceInsetWidth * umbraRecipAlpha;
1169
1170 // Outset the shadow rrect to the border of the penumbra
1171 SkScalar ambientPathOutset = devSpaceInsetWidth * devToSrcScale;
1172 SkRRect ambientRRect;
1173 SkRect outsetRect = rrect.rect().makeOutset(ambientPathOutset, ambientPathOutset);
1174 // If the rrect was an oval then its outset will also be one.
1175 // We set it explicitly to avoid errors.
1176 if (rrect.isOval()) {
1177 ambientRRect = SkRRect::MakeOval(outsetRect);
1178 } else {
1179 SkScalar outsetRad = SkRRectPriv::GetSimpleRadii(rrect).fX + ambientPathOutset;
1180 ambientRRect = SkRRect::MakeRectXY(outsetRect, outsetRad, outsetRad);
1181 }
1182
1183 // The ShadowRRectOp still uses 8888 colors, so it might get clamped if the shadow color
1184 // does not fit in bytes after being transformed to the destination color space. This can
1185 // happen if the destination color space is smaller than sRGB, which is highly unlikely.
1187 if (transparent) {
1188 // set a large inset to force a fill
1189 devSpaceInsetWidth = ambientRRect.width();
1190 }
1191
1193 ambientColor,
1194 viewMatrix,
1195 ambientRRect,
1196 devSpaceAmbientBlur,
1197 devSpaceInsetWidth);
1198 if (op) {
1199 this->addDrawOp(clip, std::move(op));
1200 }
1201 }
1202
1203 if (SkColorGetA(rec.fSpotColor) > 0) {
1204 SkScalar devSpaceSpotBlur;
1205 SkScalar spotScale;
1206 SkVector spotOffset;
1207 if (directional) {
1208 SkDrawShadowMetrics::GetDirectionalParams(occluderHeight, devLightPos.fX,
1209 devLightPos.fY, devLightPos.fZ,
1210 rec.fLightRadius, &devSpaceSpotBlur,
1211 &spotScale, &spotOffset);
1212 } else {
1213 SkDrawShadowMetrics::GetSpotParams(occluderHeight, devLightPos.fX, devLightPos.fY,
1214 devLightPos.fZ, rec.fLightRadius,
1215 &devSpaceSpotBlur, &spotScale, &spotOffset);
1216 }
1217 // handle scale of radius due to CTM
1218 const SkScalar srcSpaceSpotBlur = devSpaceSpotBlur * devToSrcScale;
1219
1220 // Adjust translate for the effect of the scale.
1221 spotOffset.fX += spotScale*viewMatrix[SkMatrix::kMTransX];
1222 spotOffset.fY += spotScale*viewMatrix[SkMatrix::kMTransY];
1223 // This offset is in dev space, need to transform it into source space.
1224 SkMatrix ctmInverse;
1225 if (viewMatrix.invert(&ctmInverse)) {
1226 ctmInverse.mapPoints(&spotOffset, 1);
1227 } else {
1228 // Since the matrix is a similarity, this should never happen, but just in case...
1229 SkDebugf("Matrix is degenerate. Will not render spot shadow correctly!\n");
1230 SkASSERT(false);
1231 }
1232
1233 // Compute the transformed shadow rrect
1234 SkRRect spotShadowRRect;
1235 SkMatrix shadowTransform;
1236 shadowTransform.setScaleTranslate(spotScale, spotScale, spotOffset.fX, spotOffset.fY);
1237 rrect.transform(shadowTransform, &spotShadowRRect);
1238 SkScalar spotRadius = spotShadowRRect.getSimpleRadii().fX;
1239
1240 // Compute the insetWidth
1241 SkScalar blurOutset = srcSpaceSpotBlur;
1242 SkScalar insetWidth = blurOutset;
1243 if (transparent) {
1244 // If transparent, just do a fill
1245 insetWidth += spotShadowRRect.width();
1246 } else {
1247 // For shadows, instead of using a stroke we specify an inset from the penumbra
1248 // border. We want to extend this inset area so that it meets up with the caster
1249 // geometry. The inset geometry will by default already be inset by the blur width.
1250 //
1251 // We compare the min and max corners inset by the radius between the original
1252 // rrect and the shadow rrect. The distance between the two plus the difference
1253 // between the scaled radius and the original radius gives the distance from the
1254 // transformed shadow shape to the original shape in that corner. The max
1255 // of these gives the maximum distance we need to cover.
1256 //
1257 // Since we are outsetting by 1/2 the blur distance, we just add the maxOffset to
1258 // that to get the full insetWidth.
1259 SkScalar maxOffset;
1260 if (rrect.isRect()) {
1261 // Manhattan distance works better for rects
1262 maxOffset = std::max(std::max(SkTAbs(spotShadowRRect.rect().fLeft -
1263 rrect.rect().fLeft),
1264 SkTAbs(spotShadowRRect.rect().fTop -
1265 rrect.rect().fTop)),
1266 std::max(SkTAbs(spotShadowRRect.rect().fRight -
1267 rrect.rect().fRight),
1268 SkTAbs(spotShadowRRect.rect().fBottom -
1269 rrect.rect().fBottom)));
1270 } else {
1271 SkScalar dr = spotRadius - SkRRectPriv::GetSimpleRadii(rrect).fX;
1272 SkPoint upperLeftOffset = SkPoint::Make(spotShadowRRect.rect().fLeft -
1273 rrect.rect().fLeft + dr,
1274 spotShadowRRect.rect().fTop -
1275 rrect.rect().fTop + dr);
1276 SkPoint lowerRightOffset = SkPoint::Make(spotShadowRRect.rect().fRight -
1277 rrect.rect().fRight - dr,
1278 spotShadowRRect.rect().fBottom -
1279 rrect.rect().fBottom - dr);
1280 maxOffset = SkScalarSqrt(std::max(SkPointPriv::LengthSqd(upperLeftOffset),
1281 SkPointPriv::LengthSqd(lowerRightOffset))) + dr;
1282 }
1283 insetWidth += std::max(blurOutset, maxOffset);
1284 }
1285
1286 // Outset the shadow rrect to the border of the penumbra
1287 SkRect outsetRect = spotShadowRRect.rect().makeOutset(blurOutset, blurOutset);
1288 if (spotShadowRRect.isOval()) {
1289 spotShadowRRect = SkRRect::MakeOval(outsetRect);
1290 } else {
1291 SkScalar outsetRad = spotRadius + blurOutset;
1292 spotShadowRRect = SkRRect::MakeRectXY(outsetRect, outsetRad, outsetRad);
1293 }
1294
1295 // The ShadowRRectOp still uses 8888 colors, so it might get clamped if the shadow color
1296 // does not fit in bytes after being transformed to the destination color space. This can
1297 // happen if the destination color space is smaller than sRGB, which is highly unlikely.
1300 spotColor,
1301 viewMatrix,
1302 spotShadowRRect,
1303 2.0f * devSpaceSpotBlur,
1304 insetWidth);
1305 if (op) {
1306 this->addDrawOp(clip, std::move(op));
1307 }
1308 }
1309
1310 return true;
1311}
1312
1313///////////////////////////////////////////////////////////////////////////////
1314
1316 GrPaint&& paint,
1317 GrAA aa,
1318 const SkMatrix& viewMatrix,
1319 const SkRegion& region,
1320 const GrStyle& style,
1321 const GrUserStencilSettings* ss) {
1324 SkDEBUGCODE(this->validate();)
1325 GR_CREATE_TRACE_MARKER_CONTEXT("SurfaceDrawContext", "drawRegion", fContext);
1326
1327 if (GrAA::kYes == aa) {
1328 // GrRegionOp performs no antialiasing but is much faster, so here we check the matrix
1329 // to see whether aa is really required.
1330 if (!SkToBool(viewMatrix.getType() & ~(SkMatrix::kTranslate_Mask)) &&
1331 SkScalarIsInt(viewMatrix.getTranslateX()) &&
1332 SkScalarIsInt(viewMatrix.getTranslateY())) {
1333 aa = GrAA::kNo;
1334 }
1335 }
1336 bool complexStyle = !style.isSimpleFill();
1337 if (complexStyle || GrAA::kYes == aa) {
1338 SkPath path;
1339 region.getBoundaryPath(&path);
1340 path.setIsVolatile(true);
1341
1342 return this->drawPath(clip, std::move(paint), aa, viewMatrix, path, style);
1343 }
1344
1345 GrAAType aaType = (this->numSamples() > 1) ? GrAAType::kMSAA : GrAAType::kNone;
1346 GrOp::Owner op = RegionOp::Make(fContext, std::move(paint), viewMatrix, region, aaType, ss);
1347 this->addDrawOp(clip, std::move(op));
1348}
1349
1351 GrPaint&& paint,
1352 GrAA aa,
1353 const SkMatrix& viewMatrix,
1354 const SkRect& oval,
1355 const GrStyle& style) {
1358 SkDEBUGCODE(this->validate();)
1359 GR_CREATE_TRACE_MARKER_CONTEXT("SurfaceDrawContext", "drawOval", fContext);
1360
1361 const SkStrokeRec& stroke = style.strokeRec();
1362
1363 if (oval.isEmpty() && !style.pathEffect()) {
1364 if (stroke.getStyle() == SkStrokeRec::kFill_Style) {
1365 return;
1366 }
1367
1368 this->drawRect(clip, std::move(paint), aa, viewMatrix, oval, &style);
1369 return;
1370 }
1371
1372 AutoCheckFlush acf(this->drawingManager());
1373
1374 GrAAType aaType = this->chooseAAType(aa);
1375
1376 GrOp::Owner op;
1377#ifndef SK_ENABLE_OPTIMIZE_SIZE
1378 if (aaType == GrAAType::kCoverage &&
1379 !fCanUseDynamicMSAA &&
1380 !this->caps()->reducedShaderMode() &&
1381 oval.width() > SK_ScalarNearlyZero &&
1382 oval.width() == oval.height() &&
1383 viewMatrix.isSimilarity()) {
1384 // In specific cases we use a dedicated circle op to try and get better perf.
1385 assert_alive(paint);
1386 op = GrOvalOpFactory::MakeCircleOp(fContext, std::move(paint), viewMatrix, oval, style,
1387 this->caps()->shaderCaps());
1388 }
1389#endif
1390 if (!op && style.isSimpleFill()) {
1391 // FillRRectOp has special geometry and a fragment-shader branch to conditionally evaluate
1392 // the arc equation. This same special geometry and fragment branch also turn out to be a
1393 // substantial optimization for drawing ovals (namely, by not evaluating the arc equation
1394 // inside the oval's inner diamond). Given these optimizations, it's a clear win to draw
1395 // ovals the exact same way we do round rects.
1396 assert_alive(paint);
1397 op = FillRRectOp::Make(fContext, this->arenaAlloc(), std::move(paint), viewMatrix,
1398 SkRRect::MakeOval(oval), oval, GrAA(aaType != GrAAType::kNone));
1399 }
1400#ifndef SK_ENABLE_OPTIMIZE_SIZE
1401 if (!op && (aaType == GrAAType::kCoverage || fCanUseDynamicMSAA)) {
1402 assert_alive(paint);
1403 op = GrOvalOpFactory::MakeOvalOp(fContext, std::move(paint), viewMatrix, oval, style,
1404 this->caps()->shaderCaps());
1405 }
1406#endif
1407 if (op) {
1408 this->addDrawOp(clip, std::move(op));
1409 return;
1410 }
1411
1412 assert_alive(paint);
1413 this->drawShapeUsingPathRenderer(clip, std::move(paint), aa, viewMatrix,
1415 false, style, DoSimplify::kNo));
1416}
1417
1419 GrPaint&& paint,
1420 GrAA aa,
1421 const SkMatrix& viewMatrix,
1422 const SkRect& oval,
1423 SkScalar startAngle,
1424 SkScalar sweepAngle,
1425 bool useCenter,
1426 const GrStyle& style) {
1429 SkDEBUGCODE(this->validate();)
1430 GR_CREATE_TRACE_MARKER_CONTEXT("SurfaceDrawContext", "drawArc", fContext);
1431
1432 AutoCheckFlush acf(this->drawingManager());
1433
1434#ifndef SK_ENABLE_OPTIMIZE_SIZE
1435 GrAAType aaType = this->chooseAAType(aa);
1436 if (aaType == GrAAType::kCoverage) {
1437 const GrShaderCaps* shaderCaps = this->caps()->shaderCaps();
1439 std::move(paint),
1440 viewMatrix,
1441 oval,
1442 startAngle,
1443 sweepAngle,
1444 useCenter,
1445 style,
1446 shaderCaps);
1447 if (op) {
1448 this->addDrawOp(clip, std::move(op));
1449 return;
1450 }
1451 assert_alive(paint);
1452 }
1453#endif
1454 this->drawShapeUsingPathRenderer(clip, std::move(paint), aa, viewMatrix,
1455 GrStyledShape::MakeArc(oval, startAngle, sweepAngle, useCenter,
1456 style, DoSimplify::kNo));
1457}
1458
1460 GrPaint&& paint,
1461 const SkMatrix& viewMatrix,
1462 GrSurfaceProxyView view,
1463 SkAlphaType alphaType,
1466 std::unique_ptr<SkLatticeIter> iter,
1467 const SkRect& dst) {
1470 SkDEBUGCODE(this->validate();)
1471 GR_CREATE_TRACE_MARKER_CONTEXT("SurfaceDrawContext", "drawImageLattice", fContext);
1472
1473 AutoCheckFlush acf(this->drawingManager());
1474
1475 GrOp::Owner op =
1476 LatticeOp::MakeNonAA(fContext, std::move(paint), viewMatrix, std::move(view),
1477 alphaType, std::move(csxf), filter, std::move(iter), dst);
1478 this->addDrawOp(clip, std::move(op));
1479}
1480
1481void SurfaceDrawContext::drawDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler> drawable,
1482 const SkRect& bounds) {
1485 SkDEBUGCODE(this->validate();)
1486 GR_CREATE_TRACE_MARKER_CONTEXT("SurfaceDrawContext", "drawDrawable", fContext);
1487 GrOp::Owner op(DrawableOp::Make(fContext, std::move(drawable), bounds));
1488 SkASSERT(op);
1489 this->addOp(std::move(op));
1490}
1491
1492void SurfaceDrawContext::setLastClip(uint32_t clipStackGenID,
1493 const SkIRect& devClipBounds,
1494 int numClipAnalyticElements) {
1495 auto opsTask = this->getOpsTask();
1496 opsTask->fLastClipStackGenID = clipStackGenID;
1497 opsTask->fLastDevClipBounds = devClipBounds;
1498 opsTask->fLastClipNumAnalyticElements = numClipAnalyticElements;
1499}
1500
1501bool SurfaceDrawContext::mustRenderClip(uint32_t clipStackGenID,
1502 const SkIRect& devClipBounds,
1503 int numClipAnalyticElements) {
1504 auto opsTask = this->getOpsTask();
1505 return opsTask->fLastClipStackGenID != clipStackGenID ||
1506 !opsTask->fLastDevClipBounds.contains(devClipBounds) ||
1507 opsTask->fLastClipNumAnalyticElements != numClipAnalyticElements;
1508}
1509
1511 const GrBackendSemaphore waitSemaphores[],
1512 bool deleteSemaphoresAfterWait) {
1515 SkDEBUGCODE(this->validate();)
1516 GR_CREATE_TRACE_MARKER_CONTEXT("SurfaceDrawContext", "waitOnSemaphores", fContext);
1517
1518 AutoCheckFlush acf(this->drawingManager());
1519
1520 if (numSemaphores && !this->caps()->backendSemaphoreSupport()) {
1521 return false;
1522 }
1523
1524 auto direct = fContext->asDirectContext();
1525 if (!direct) {
1526 return false;
1527 }
1528
1529 auto resourceProvider = direct->priv().resourceProvider();
1530
1531 GrWrapOwnership ownership =
1532 deleteSemaphoresAfterWait ? kAdopt_GrWrapOwnership : kBorrow_GrWrapOwnership;
1533
1534 std::unique_ptr<std::unique_ptr<GrSemaphore>[]> grSemaphores(
1535 new std::unique_ptr<GrSemaphore>[numSemaphores]);
1536 for (int i = 0; i < numSemaphores; ++i) {
1537 grSemaphores[i] = resourceProvider->wrapBackendSemaphore(waitSemaphores[i],
1539 ownership);
1540 }
1541 this->drawingManager()->newWaitRenderTask(this->asSurfaceProxyRef(), std::move(grSemaphores),
1542 numSemaphores);
1543 return true;
1544}
1545
1547 GrPaint&& paint,
1548 GrAA aa,
1549 const SkMatrix& viewMatrix,
1550 const SkPath& path,
1551 const GrStyle& style) {
1554 SkDEBUGCODE(this->validate();)
1555 GR_CREATE_TRACE_MARKER_CONTEXT("SurfaceDrawContext", "drawPath", fContext);
1556
1557 GrStyledShape shape(path, style, DoSimplify::kNo);
1558 this->drawShape(clip, std::move(paint), aa, viewMatrix, std::move(shape));
1559}
1560
1562 GrPaint&& paint,
1563 GrAA aa,
1564 const SkMatrix& viewMatrix,
1565 GrStyledShape&& shape) {
1568 SkDEBUGCODE(this->validate();)
1569 GR_CREATE_TRACE_MARKER_CONTEXT("SurfaceDrawContext", "drawShape", fContext);
1570
1571 if (shape.isEmpty()) {
1572 if (shape.inverseFilled()) {
1573 this->drawPaint(clip, std::move(paint), viewMatrix);
1574 }
1575 return;
1576 }
1577
1578 AutoCheckFlush acf(this->drawingManager());
1579
1580 // If we get here in drawShape(), we definitely need to use path rendering
1581 this->drawShapeUsingPathRenderer(clip, std::move(paint), aa, viewMatrix, std::move(shape),
1582 /* attemptDrawSimple */ true);
1583}
1584
1586 return clip ? clip->getConservativeBounds() : SkIRect::MakeWH(sdc->width(), sdc->height());
1587}
1588
1590 const GrUserStencilSettings* ss,
1591 SkRegion::Op op,
1592 bool invert,
1593 GrAA aa,
1594 const SkMatrix& viewMatrix,
1595 const SkPath& path) {
1598 SkDEBUGCODE(this->validate();)
1599 GR_CREATE_TRACE_MARKER_CONTEXT("SurfaceDrawContext", "drawAndStencilPath", fContext);
1600
1601 if (path.isEmpty() && path.isInverseFillType()) {
1602 GrPaint paint;
1603 paint.setCoverageSetOpXPFactory(op, invert);
1604 this->stencilRect(clip, ss, std::move(paint), GrAA::kNo, SkMatrix::I(),
1605 SkRect::Make(this->dimensions()));
1606 return true;
1607 }
1608
1609 AutoCheckFlush acf(this->drawingManager());
1610
1611 // An Assumption here is that path renderer would use some form of tweaking
1612 // the src color (either the input alpha or in the frag shader) to implement
1613 // aa. If we have some future driver-mojo path AA that can do the right
1614 // thing WRT to the blend then we'll need some query on the PR.
1615 GrAAType aaType = this->chooseAAType(aa);
1616 bool hasUserStencilSettings = !ss->isUnused();
1617
1618 SkIRect clipConservativeBounds = get_clip_bounds(this, clip);
1619
1620 GrPaint paint;
1621 paint.setCoverageSetOpXPFactory(op, invert);
1622
1623 GrStyledShape shape(path, GrStyle::SimpleFill());
1625 canDrawArgs.fCaps = this->caps();
1626 canDrawArgs.fProxy = this->asRenderTargetProxy();
1627 canDrawArgs.fViewMatrix = &viewMatrix;
1628 canDrawArgs.fShape = &shape;
1629 canDrawArgs.fPaint = &paint;
1630 canDrawArgs.fSurfaceProps = &fSurfaceProps;
1631 canDrawArgs.fClipConservativeBounds = &clipConservativeBounds;
1632 canDrawArgs.fAAType = aaType;
1633 canDrawArgs.fHasUserStencilSettings = hasUserStencilSettings;
1634
1636
1637 // Don't allow the SW renderer
1638 auto pr = this->drawingManager()->getPathRenderer(canDrawArgs,
1639 false,
1640 DrawType::kStencilAndColor);
1641 if (!pr) {
1642 return false;
1643 }
1644
1646 std::move(paint),
1647 ss,
1648 this,
1649 clip,
1650 &clipConservativeBounds,
1651 &viewMatrix,
1652 &shape,
1653 aaType,
1654 this->colorInfo().isLinearlyBlended()};
1655 pr->drawPath(args);
1656 return true;
1657}
1658
1661
1662 if (fContext->abandoned()) {
1663 return skgpu::Budgeted::kNo;
1664 }
1665
1666 SkDEBUGCODE(this->validate();)
1667
1668 return this->asSurfaceProxy()->isBudgeted();
1669}
1670
1672 GrPaint&& paint,
1673 GrAA aa,
1674 const SkMatrix& viewMatrix,
1675 const SkPoint points[2],
1676 const SkStrokeRec& stroke) {
1678
1680 SkASSERT(stroke.getWidth() > 0);
1681 // Adding support for round capping would require a
1682 // SurfaceDrawContext::fillRRectWithLocalMatrix entry point
1683 SkASSERT(SkPaint::kRound_Cap != stroke.getCap());
1684
1685 const SkScalar halfWidth = 0.5f * stroke.getWidth();
1686 if (halfWidth <= 0.f) {
1687 // Prevents underflow when stroke width is epsilon > 0 (so technically not a hairline).
1688 // The CTM would need to have a scale near 1/epsilon in order for this to have meaningful
1689 // coverage (although that would likely overflow elsewhere and cause the draw to drop due
1690 // to non-finite bounds). At any other scale, this line is so thin, it's coverage is
1691 // negligible, so discarding the draw is visually equivalent.
1692 return;
1693 }
1694
1695 SkVector parallel = points[1] - points[0];
1696
1697 if (!SkPoint::Normalize(&parallel)) {
1698 parallel.fX = 1.0f;
1699 parallel.fY = 0.0f;
1700 }
1701 parallel *= halfWidth;
1702
1703 SkVector ortho = { parallel.fY, -parallel.fX };
1704 SkPoint p0 = points[0], p1 = points[1];
1705 if (stroke.getCap() == SkPaint::kSquare_Cap) {
1706 // Extra extension for square caps
1707 p0 -= parallel;
1708 p1 += parallel;
1709 }
1710
1711 // If we are using dmsaa or reduced shader mode then attempt to draw with FillRRectOp.
1712 if (this->caps()->drawInstancedSupport() &&
1713 (this->alwaysAntialias() ||
1714 (fContext->priv().caps()->reducedShaderMode() && aa == GrAA::kYes))) {
1715 SkMatrix localMatrix = SkMatrix::MakeAll(p1.fX - p0.fX, ortho.fX, p0.fX,
1716 p1.fY - p0.fY, ortho.fY, p0.fY,
1717 0, 0, 1);
1718 if (auto op = FillRRectOp::Make(fContext,
1719 this->arenaAlloc(),
1720 std::move(paint),
1721 SkMatrix::Concat(viewMatrix, localMatrix),
1722 SkRRect::MakeRect({0,-1,1,1}),
1723 localMatrix,
1724 GrAA::kYes)) {
1725 this->addDrawOp(clip, std::move(op));
1726 return;
1727 }
1728 }
1729
1730 // Order is TL, TR, BR, BL where arbitrarily "down" is p0 to p1 and "right" is positive
1731 SkPoint corners[4] = { p0 - ortho,
1732 p0 + ortho,
1733 p1 + ortho,
1734 p1 - ortho };
1735
1737
1738 assert_alive(paint);
1739 this->fillQuadWithEdgeAA(clip, std::move(paint), edgeAA, viewMatrix, corners, nullptr);
1740}
1741
1742bool SurfaceDrawContext::drawSimpleShape(const GrClip* clip,
1743 GrPaint* paint,
1744 GrAA aa,
1745 const SkMatrix& viewMatrix,
1746 const GrStyledShape& shape) {
1747 if (!shape.style().hasPathEffect()) {
1748 GrAAType aaType = this->chooseAAType(aa);
1749 SkPoint linePts[2];
1750 SkRRect rrect;
1751 // We can ignore the starting point and direction since there is no path effect.
1752 bool inverted;
1753 if (shape.asLine(linePts, &inverted) && !inverted &&
1755 shape.style().strokeRec().getCap() != SkPaint::kRound_Cap) {
1756 // The stroked line is an oriented rectangle, which looks the same or better (if
1757 // perspective) compared to path rendering. The exception is subpixel/hairline lines
1758 // that are non-AA or MSAA, in which case the default path renderer achieves higher
1759 // quality.
1760 // FIXME(michaelludwig): If the fill rect op could take an external coverage, or checks
1761 // for and outsets thin non-aa rects to 1px, the path renderer could be skipped.
1762 SkScalar coverage;
1763 if (aaType == GrAAType::kCoverage ||
1764 !SkDrawTreatAAStrokeAsHairline(shape.style().strokeRec().getWidth(), viewMatrix,
1765 &coverage)) {
1766 this->drawStrokedLine(clip, std::move(*paint), aa, viewMatrix, linePts,
1767 shape.style().strokeRec());
1768 return true;
1769 }
1770 } else if (shape.asRRect(&rrect, nullptr, nullptr, &inverted) && !inverted) {
1771 if (rrect.isRect()) {
1772 this->drawRect(clip, std::move(*paint), aa, viewMatrix, rrect.rect(),
1773 &shape.style());
1774 return true;
1775 } else if (rrect.isOval()) {
1776 this->drawOval(clip, std::move(*paint), aa, viewMatrix, rrect.rect(),
1777 shape.style());
1778 return true;
1779 }
1780 this->drawRRect(clip, std::move(*paint), aa, viewMatrix, rrect, shape.style());
1781 return true;
1782 } else if (GrAAType::kCoverage == aaType &&
1783 shape.style().isSimpleFill() &&
1784 viewMatrix.rectStaysRect() &&
1785 !this->caps()->reducedShaderMode()) {
1786 // TODO: the rectStaysRect restriction could be lifted if we were willing to apply the
1787 // matrix to all the points individually rather than just to the rect
1788 SkRect rects[2];
1789 if (shape.asNestedRects(rects)) {
1790 // Concave AA paths are expensive - try to avoid them for special cases
1792 viewMatrix, rects);
1793 if (op) {
1794 this->addDrawOp(clip, std::move(op));
1795 return true;
1796 }
1797 // Fall through to let path renderer handle subpixel nested rects with unequal
1798 // stroke widths along X/Y.
1799 }
1800 }
1801 }
1802 return false;
1803}
1804
1805void SurfaceDrawContext::drawShapeUsingPathRenderer(const GrClip* clip,
1806 GrPaint&& paint,
1807 GrAA aa,
1808 const SkMatrix& viewMatrix,
1809 GrStyledShape&& shape,
1810 bool attemptDrawSimple) {
1813 GR_CREATE_TRACE_MARKER_CONTEXT("SurfaceDrawContext", "internalDrawPath", fContext);
1814
1815 if (!viewMatrix.isFinite() || !shape.bounds().isFinite()) {
1816 return;
1817 }
1818
1819 SkIRect clipConservativeBounds = get_clip_bounds(this, clip);
1820
1821 // Always allow paths to trigger DMSAA.
1822 GrAAType aaType = fCanUseDynamicMSAA ? GrAAType::kMSAA : this->chooseAAType(aa);
1823
1824 PathRenderer::CanDrawPathArgs canDrawArgs;
1825 canDrawArgs.fCaps = this->caps();
1826 canDrawArgs.fProxy = this->asRenderTargetProxy();
1827 canDrawArgs.fViewMatrix = &viewMatrix;
1828 canDrawArgs.fShape = &shape;
1829 canDrawArgs.fPaint = &paint;
1830 canDrawArgs.fSurfaceProps = &fSurfaceProps;
1831 canDrawArgs.fClipConservativeBounds = &clipConservativeBounds;
1832 canDrawArgs.fHasUserStencilSettings = false;
1833 canDrawArgs.fAAType = aaType;
1834
1835 constexpr static bool kDisallowSWPathRenderer = false;
1837
1838 PathRenderer* pr = nullptr;
1839
1840 if (!shape.style().strokeRec().isFillStyle() && !shape.isEmpty()) {
1841 // Give the tessellation path renderer a chance to claim this stroke before we simplify it.
1842 PathRenderer* tess = this->drawingManager()->getTessellationPathRenderer();
1843 if (tess && tess->canDrawPath(canDrawArgs) == PathRenderer::CanDrawPath::kYes) {
1844 pr = tess;
1845 }
1846 }
1847
1848 if (!pr) {
1849 // The shape isn't a stroke that can be drawn directly. Simplify if possible.
1850 shape.simplify();
1851
1852 if (shape.isEmpty() && !shape.inverseFilled()) {
1853 return;
1854 }
1855
1856 if (attemptDrawSimple || shape.simplified()) {
1857 // Usually we enter drawShapeUsingPathRenderer() because the shape+style was too complex
1858 // for dedicated draw ops. However, if GrStyledShape was able to reduce something we
1859 // ought to try again instead of going right to path rendering.
1860 if (this->drawSimpleShape(clip, &paint, aa, viewMatrix, shape)) {
1861 return;
1862 }
1863 }
1864
1865 // Try a 1st time without applying any of the style to the geometry (and barring sw)
1866 pr = this->drawingManager()->getPathRenderer(canDrawArgs, kDisallowSWPathRenderer,
1867 DrawType::kColor);
1868 }
1869
1870 SkScalar styleScale = GrStyle::MatrixToScaleFactor(viewMatrix);
1871 if (styleScale == 0.0f) {
1872 return;
1873 }
1874
1875 if (!pr && shape.style().pathEffect()) {
1876 // It didn't work above, so try again with the path effect applied.
1877 shape = shape.applyStyle(GrStyle::Apply::kPathEffectOnly, styleScale);
1878 if (shape.isEmpty()) {
1879 return;
1880 }
1881 pr = this->drawingManager()->getPathRenderer(canDrawArgs, kDisallowSWPathRenderer,
1882 DrawType::kColor);
1883 }
1884 if (!pr && shape.style().applies()) {
1885 shape = shape.applyStyle(GrStyle::Apply::kPathEffectAndStrokeRec, styleScale);
1886 if (shape.isEmpty()) {
1887 return;
1888 }
1889 pr = this->drawingManager()->getPathRenderer(canDrawArgs, kDisallowSWPathRenderer,
1890 DrawType::kColor);
1891 }
1892
1893 if (!pr) {
1894 // Fall back on SW renderer as a last resort.
1895 if (GrAATypeIsHW(aaType)) {
1896 // No point in trying SW renderer with MSAA.
1897 aaType = GrAAType::kCoverage;
1898 canDrawArgs.fAAType = aaType;
1899 }
1900 // This can only fail if a) AA type is MSAA or the style is not applied (already checked),
1901 // or b) the SW renderer's proxy provider is null, which should never happen.
1903 SkASSERT(pr->canDrawPath(canDrawArgs) != PathRenderer::CanDrawPath::kNo);
1904#if GR_PATH_RENDERER_SPEW
1905 SkDebugf("falling back to: %s\n", pr->name());
1906#endif
1907 }
1908
1909 PathRenderer::DrawPathArgs args{this->drawingManager()->getContext(),
1910 std::move(paint),
1912 this,
1913 clip,
1914 &clipConservativeBounds,
1915 &viewMatrix,
1916 canDrawArgs.fShape,
1917 aaType,
1918 this->colorInfo().isLinearlyBlended()};
1919 pr->drawPath(args);
1920}
1921
1923 GrOp::Owner op,
1924 const std::function<WillAddOpFn>& willAddFn) {
1926 if (fContext->abandoned()) {
1927 return;
1928 }
1929 GrDrawOp* drawOp = (GrDrawOp*)op.get();
1930 SkDEBUGCODE(this->validate();)
1931 SkDEBUGCODE(drawOp->fAddDrawOpCalled = true;)
1932 GR_CREATE_TRACE_MARKER_CONTEXT("SurfaceDrawContext", "addDrawOp", fContext);
1933
1934 // Setup clip
1935 SkRect bounds;
1936 op_bounds(&bounds, op.get());
1937 GrAppliedClip appliedClip(this->dimensions(), this->asSurfaceProxy()->backingStoreDimensions());
1938 const bool opUsesMSAA = drawOp->usesMSAA();
1939 bool skipDraw = false;
1940 if (clip) {
1941 // Have a complex clip, so defer to its early clip culling
1942 GrAAType aaType;
1943 if (opUsesMSAA) {
1944 aaType = GrAAType::kMSAA;
1945 } else {
1946 aaType = op->hasAABloat() ? GrAAType::kCoverage : GrAAType::kNone;
1947 }
1948 skipDraw = clip->apply(fContext, this, drawOp, aaType,
1949 &appliedClip, &bounds) == GrClip::Effect::kClippedOut;
1950 } else {
1951 // No clipping, so just clip the bounds against the logical render target dimensions
1952 skipDraw = !bounds.intersect(this->asSurfaceProxy()->getBoundsRect());
1953 }
1954
1955 if (skipDraw) {
1956 return;
1957 }
1958
1959 GrClampType clampType = GrColorTypeClampType(this->colorInfo().colorType());
1960 GrProcessorSet::Analysis analysis = drawOp->finalize(*this->caps(), &appliedClip, clampType);
1961
1962 const bool opUsesStencil = drawOp->usesStencil();
1963
1964 // Always trigger DMSAA when there is stencil. This ensures stencil contents get properly
1965 // preserved between render passes, if needed.
1966 const bool drawNeedsMSAA = opUsesMSAA || (fCanUseDynamicMSAA && opUsesStencil);
1967
1968 // Must be called before setDstProxyView so that it sees the final bounds of the op.
1969 op->setClippedBounds(bounds);
1970
1971 // Determine if the Op will trigger the use of a separate DMSAA attachment that requires manual
1972 // resolves.
1973 // TODO: Currently usesAttachmentIfDMSAA checks if this is a textureProxy or not. This check is
1974 // really only for GL which uses a normal texture sampling when using barriers. For Vulkan it
1975 // is possible to use the msaa buffer as an input attachment even if this is not a texture.
1976 // However, support for that is not fully implemented yet in Vulkan. Once it is, this check
1977 // should change to a virtual caps check that returns whether we need to break up an OpsTask
1978 // if it has barriers and we are about to promote to MSAA.
1979 bool usesAttachmentIfDMSAA =
1980 fCanUseDynamicMSAA &&
1981 (!this->caps()->msaaResolvesAutomatically() || !this->asTextureProxy());
1982 bool opRequiresDMSAAAttachment = usesAttachmentIfDMSAA && drawNeedsMSAA;
1983 bool opTriggersDMSAAAttachment =
1984 opRequiresDMSAAAttachment && !this->getOpsTask()->usesMSAASurface();
1985 if (opTriggersDMSAAAttachment) {
1986 // This will be the op that actually triggers use of a DMSAA attachment. Texture barriers
1987 // can't be moved to a DMSAA attachment, so if there already are any on the current opsTask
1988 // then we need to split.
1989 if (this->getOpsTask()->renderPassXferBarriers() & GrXferBarrierFlags::kTexture) {
1990 SkASSERT(!this->getOpsTask()->isColorNoOp());
1991 this->replaceOpsTask()->setCannotMergeBackward();
1992 }
1993 }
1994
1995 GrDstProxyView dstProxyView;
1996 if (analysis.requiresDstTexture()) {
1997 if (!this->setupDstProxyView(drawOp->bounds(), drawNeedsMSAA, &dstProxyView)) {
1998 return;
1999 }
2000#ifdef SK_DEBUG
2001 if (fCanUseDynamicMSAA && drawNeedsMSAA && !this->caps()->msaaResolvesAutomatically()) {
2002 // Since we aren't literally writing to the render target texture while using a DMSAA
2003 // attachment, we need to resolve that texture before sampling it. Ensure the current
2004 // opsTask got closed off in order to initiate an implicit resolve.
2005 SkASSERT(this->getOpsTask()->isEmpty());
2006 }
2007#endif
2008 }
2009
2010 auto opsTask = this->getOpsTask();
2011 if (willAddFn) {
2012 willAddFn(op.get(), opsTask->uniqueID());
2013 }
2014
2015 // Note if the op needs stencil. Stencil clipping already called setNeedsStencil for itself, if
2016 // needed.
2017 if (opUsesStencil) {
2018 this->setNeedsStencil();
2019 }
2020
2021#if GR_GPU_STATS && defined(GR_TEST_UTILS)
2022 if (fCanUseDynamicMSAA && drawNeedsMSAA) {
2023 if (!opsTask->usesMSAASurface()) {
2024 fContext->priv().dmsaaStats().fNumMultisampleRenderPasses++;
2025 }
2026 fContext->priv().dmsaaStats().fTriggerCounts[op->name()]++;
2027 }
2028#endif
2029
2030 opsTask->addDrawOp(this->drawingManager(), std::move(op), drawNeedsMSAA, analysis,
2031 std::move(appliedClip), dstProxyView,
2032 GrTextureResolveManager(this->drawingManager()), *this->caps());
2033
2034#ifdef SK_DEBUG
2035 if (fCanUseDynamicMSAA && drawNeedsMSAA) {
2036 SkASSERT(opsTask->usesMSAASurface());
2037 }
2038#endif
2039}
2040
2041bool SurfaceDrawContext::setupDstProxyView(const SkRect& opBounds,
2042 bool opRequiresMSAA,
2043 GrDstProxyView* dstProxyView) {
2044 // If we are wrapping a vulkan secondary command buffer, we can't make a dst copy because we
2045 // don't actually have a VkImage to make a copy of. Additionally we don't have the power to
2046 // start and stop the render pass in order to make the copy.
2047 if (this->asRenderTargetProxy()->wrapsVkSecondaryCB()) {
2048 return false;
2049 }
2050
2051 // First get the dstSampleFlags as if we will put the draw into the current OpsTask
2052 auto dstSampleFlags = this->caps()->getDstSampleFlagsForProxy(
2053 this->asRenderTargetProxy(), this->getOpsTask()->usesMSAASurface() || opRequiresMSAA);
2054
2055 // If we don't have barriers for this draw then we will definitely be breaking up the OpsTask.
2056 // However, if using dynamic MSAA, the new OpsTask will not have MSAA already enabled on it
2057 // and that may allow us to use texture barriers. So we check if we can use barriers on the new
2058 // ops task and then break it up if so.
2059 if (!(dstSampleFlags & GrDstSampleFlags::kRequiresTextureBarrier) &&
2060 fCanUseDynamicMSAA && this->getOpsTask()->usesMSAASurface() && !opRequiresMSAA) {
2061 auto newFlags =
2063 false/*=opRequiresMSAA*/);
2065 // We can't have an empty ops task if we are in DMSAA and the ops task already returns
2066 // true for usesMSAASurface.
2067 SkASSERT(!this->getOpsTask()->isColorNoOp());
2068 this->replaceOpsTask()->setCannotMergeBackward();
2069 dstSampleFlags = newFlags;
2070 }
2071 }
2072
2073 if (dstSampleFlags & GrDstSampleFlags::kRequiresTextureBarrier) {
2074 // If we require a barrier to sample the dst it means we are sampling the RT itself
2075 // either as a texture or input attachment. In this case we don't need to break up the
2076 // OpsTask.
2077 dstProxyView->setProxyView(this->readSurfaceView());
2078 dstProxyView->setOffset(0, 0);
2079 dstProxyView->setDstSampleFlags(dstSampleFlags);
2080 return true;
2081 }
2082 SkASSERT(dstSampleFlags == GrDstSampleFlags::kNone);
2083
2084 // We are using a different surface from the main color attachment to sample the dst from. If we
2085 // are in DMSAA we can just use the single sampled RT texture itself. Otherwise, we must do a
2086 // copy.
2087 // We do have to check if we ended up here becasue we don't have texture barriers but do have
2088 // msaaResolvesAutomatically (i.e. render-to-msaa-texture). In that case there will be no op or
2089 // barrier between draws to flush the render target before being used as a texture in the next
2090 // draw. So in that case we just fall through to doing a copy.
2091 if (fCanUseDynamicMSAA && opRequiresMSAA && this->asTextureProxy() &&
2092 !this->caps()->msaaResolvesAutomatically() &&
2093 this->caps()->dmsaaResolveCanBeUsedAsTextureInSameRenderPass()) {
2094 this->replaceOpsTaskIfModifiesColor()->setCannotMergeBackward();
2095 dstProxyView->setProxyView(this->readSurfaceView());
2096 dstProxyView->setOffset(0, 0);
2097 dstProxyView->setDstSampleFlags(dstSampleFlags);
2098 return true;
2099 }
2100
2101 // Now we fallback to doing a copy.
2102
2104 // MSAA consideration: When there is support for reading MSAA samples in the shader we could
2105 // have per-sample dst values by making the copy multisampled.
2107 this->asRenderTargetProxy(), colorType);
2108
2109 SkIRect copyRect = SkIRect::MakeSize(this->asSurfaceProxy()->backingStoreDimensions());
2110 if (!restrictions.fMustCopyWholeSrc) {
2111 // If we don't need the whole source, restrict to the op's bounds. We add an extra pixel
2112 // of padding to account for AA bloat and the unpredictable rounding of coords near pixel
2113 // centers during rasterization.
2114 SkIRect conservativeDrawBounds = opBounds.roundOut();
2115 conservativeDrawBounds.outset(1, 1);
2116 SkAssertResult(copyRect.intersect(conservativeDrawBounds));
2117 }
2118
2119 SkIPoint dstOffset;
2120 SkBackingFit fit;
2122 dstOffset = {0, 0};
2124 } else {
2125 dstOffset = {copyRect.fLeft, copyRect.fTop};
2127 }
2129 this->asSurfaceProxyRef(),
2130 this->origin(),
2131 skgpu::Mipmapped::kNo,
2132 copyRect,
2133 fit,
2135 /*label=*/{},
2136 restrictions.fRectsMustMatch);
2137 SkASSERT(copy);
2138
2139 dstProxyView->setProxyView({std::move(copy), this->origin(), this->readSwizzle()});
2140 dstProxyView->setOffset(dstOffset);
2141 dstProxyView->setDstSampleFlags(dstSampleFlags);
2142 return true;
2143}
2144
2145OpsTask* SurfaceDrawContext::replaceOpsTaskIfModifiesColor() {
2146 if (!this->getOpsTask()->isColorNoOp()) {
2147 this->replaceOpsTask();
2148 }
2149 return this->getOpsTask();
2150}
2151
2152} // namespace skgpu::ganesh
uint32_t GrColor
Definition GrColor.h:25
#define GR_CREATE_TRACE_MARKER_CONTEXT(classname, op, context)
Definition GrTracing.h:18
GrClampType
GrQuadAAFlags
GrWrapOwnership
Definition GrTypesPriv.h:76
@ kAdopt_GrWrapOwnership
Definition GrTypesPriv.h:81
@ kBorrow_GrWrapOwnership
Definition GrTypesPriv.h:78
GrPrimitiveType
Definition GrTypesPriv.h:42
static constexpr bool GrAATypeIsHW(GrAAType type)
GrAAType
GrAA
GrColorType
static constexpr GrClampType GrColorTypeClampType(GrColorType colorType)
GrSurfaceOrigin
Definition GrTypes.h:147
static const int points[]
SkColor4f color
SkAlphaType
Definition SkAlphaType.h:26
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
#define SkAssertResult(cond)
Definition SkAssert.h:123
#define SkUNREACHABLE
Definition SkAssert.h:135
#define SkASSERT(cond)
Definition SkAssert.h:116
SkBackingFit
SkBlendMode
Definition SkBlendMode.h:38
@ kSrcOver
r = s + (1-sa)*d
uint32_t SkColor
Definition SkColor.h:37
#define SkColorGetA(color)
Definition SkColor.h:61
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
#define SkDEBUGCODE(...)
Definition SkDebug.h:23
bool SkDrawTreatAAStrokeAsHairline(SkScalar strokeWidth, const SkMatrix &matrix, SkScalar *coverage)
static float sk_float_rsqrt(float x)
SkPMColor4f SkColorToPMColor4f(SkColor c, const GrColorInfo &colorInfo)
Definition SkGr.cpp:275
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition SkPath.cpp:3824
SkFilterMode
SkMipmapMode
#define SkScalarInvert(x)
Definition SkScalar.h:73
static bool SkScalarNearlyZero(SkScalar x, SkScalar tolerance=SK_ScalarNearlyZero)
Definition SkScalar.h:101
static bool SkScalarNearlyEqual(SkScalar x, SkScalar y, SkScalar tolerance=SK_ScalarNearlyZero)
Definition SkScalar.h:107
#define SK_ScalarNearlyZero
Definition SkScalar.h:99
#define SK_ScalarSqrt2
Definition SkScalar.h:20
static bool SkScalarIsInt(SkScalar x)
Definition SkScalar.h:80
#define SkScalarSqrt(x)
Definition SkScalar.h:42
#define SkScalarAbs(x)
Definition SkScalar.h:39
@ kDirectionalLight_ShadowFlag
@ kGeometricOnly_ShadowFlag
@ kTransparentOccluder_ShadowFlag
static T SkTAbs(T value)
Definition SkTemplates.h:43
static constexpr bool SkToBool(const T &x)
Definition SkTo.h:35
#define RETURN_FALSE_IF_ABANDONED
#define RETURN_IF_ABANDONED
const GrCaps * caps() const
bool reducedShaderMode() const
Definition GrCaps.h:190
std::tuple< GrColorType, GrBackendFormat > getFallbackColorTypeAndFormat(GrColorType, int sampleCount) const
Definition GrCaps.cpp:499
bool performPartialClearsAsDraws() const
Definition GrCaps.h:426
GrDstSampleFlags getDstSampleFlagsForProxy(const GrRenderTargetProxy *, bool drawUsesMSAA) const
Definition GrCaps.cpp:461
const GrShaderCaps * shaderCaps() const
Definition GrCaps.h:63
virtual skgpu::Swizzle getWriteSwizzle(const GrBackendFormat &, GrColorType) const =0
virtual DstCopyRestrictions getDstCopyRestrictions(const GrRenderTargetProxy *src, GrColorType ct) const
Definition GrCaps.h:461
GrBackendFormat getDefaultBackendFormat(GrColorType, GrRenderable) const
Definition GrCaps.cpp:400
bool msaaResolvesAutomatically() const
Definition GrCaps.h:100
bool performStencilClearsAsDraws() const
Definition GrCaps.h:438
skgpu::Swizzle getReadSwizzle(const GrBackendFormat &format, GrColorType colorType) const
Definition GrCaps.cpp:443
static bool IsPixelAligned(const SkRect &rect)
Definition GrClip.h:202
static bool IsOutsideClip(const SkIRect &outerClipBounds, const SkRect &drawBounds, GrAA aa)
Definition GrClip.h:139
bool isLinearlyBlended() const
sk_sp< GrColorSpaceXform > refColorSpaceXformFromSRGB() const
Definition GrColorInfo.h:41
GrColorType colorType() const
Definition GrColorInfo.h:43
static std::unique_ptr< GrFragmentProcessor > Make(std::unique_ptr< GrFragmentProcessor > child, SkColorSpace *src, SkAlphaType srcAT, SkColorSpace *dst, SkAlphaType dstAT)
static sk_sp< GrColorSpaceXform > Make(SkColorSpace *src, SkAlphaType srcAT, SkColorSpace *dst, SkAlphaType dstAT)
virtual GrDirectContext * asDirectContext()
GrResourceProvider * resourceProvider()
GrDirectContextPriv priv()
static const GrDisableColorXPFactory * Get()
virtual bool usesMSAA() const
Definition GrDrawOp.h:37
virtual GrProcessorSet::Analysis finalize(const GrCaps &, const GrAppliedClip *, GrClampType)=0
virtual bool usesStencil() const
Definition GrDrawOp.h:82
GrRecordingContext * getContext()
void newWaitRenderTask(const sk_sp< GrSurfaceProxy > &proxy, std::unique_ptr< std::unique_ptr< GrSemaphore >[]>, int numSemaphores)
PathRenderer * getTessellationPathRenderer()
PathRenderer * getSoftwarePathRenderer()
PathRenderer * getPathRenderer(const PathRenderer::CanDrawPathArgs &, bool allowSW, PathRendererChain::DrawType, PathRenderer::StencilSupport *=nullptr)
void setOffset(const SkIPoint &offset)
void setDstSampleFlags(GrDstSampleFlags dstSampleFlags)
void setProxyView(GrSurfaceProxyView view)
Definition GrOp.h:70
std::unique_ptr< GrOp > Owner
Definition GrOp.h:72
const SkRect & bounds() const
Definition GrOp.h:122
bool hasAABloat() const
Definition GrOp.h:133
bool hasZeroArea() const
Definition GrOp.h:138
static GrOp::Owner MakeArcOp(GrRecordingContext *, GrPaint &&, const SkMatrix &, const SkRect &oval, SkScalar startAngle, SkScalar sweepAngle, bool useCenter, const GrStyle &, const GrShaderCaps *)
static GrOp::Owner MakeOvalOp(GrRecordingContext *, GrPaint &&, const SkMatrix &, const SkRect &oval, const GrStyle &style, const GrShaderCaps *)
static GrOp::Owner MakeCircularRRectOp(GrRecordingContext *, GrPaint &&, const SkMatrix &, const SkRRect &, const SkStrokeRec &, const GrShaderCaps *)
static GrOp::Owner MakeCircleOp(GrRecordingContext *, GrPaint &&, const SkMatrix &, const SkRect &oval, const GrStyle &style, const GrShaderCaps *)
static GrOp::Owner MakeRRectOp(GrRecordingContext *, GrPaint &&, const SkMatrix &, const SkRRect &, const SkStrokeRec &, const GrShaderCaps *)
bool requiresDstTexture() const
sk_sp< GrTextureProxy > createProxy(const GrBackendFormat &, SkISize dimensions, GrRenderable, int renderTargetSampleCnt, skgpu::Mipmapped, SkBackingFit, skgpu::Budgeted, GrProtected, std::string_view label, GrInternalSurfaceFlags=GrInternalSurfaceFlags::kNone, UseAllocator useAllocator=UseAllocator::kYes)
sk_sp< GrTextureProxy > wrapRenderableBackendTexture(const GrBackendTexture &, int sampleCnt, GrWrapOwnership, GrWrapCacheable, sk_sp< skgpu::RefCntedCallback > releaseHelper)
Type quadType() const
Definition GrQuad.h:118
static GrQuad MakeFromRect(const SkRect &, const SkMatrix &)
Definition GrQuad.cpp:107
bool asRect(SkRect *rect) const
Definition GrQuad.cpp:141
bool isFinite() const
Definition GrQuad.h:95
SkRect bounds() const
Definition GrQuad.h:81
GrProxyProvider * proxyProvider()
sktext::gpu::TextBlobRedrawCoordinator * getTextBlobCache()
GrRecordingContextPriv priv()
bool abandoned() override
int maxWindowRectangles(const GrCaps &caps) const
static const GrUserStencilSettings * SetClipBitSettings(bool setToInside)
SkPathEffect * pathEffect() const
Definition GrStyle.h:119
bool hasPathEffect() const
Definition GrStyle.h:122
static const GrStyle & SimpleFill()
Definition GrStyle.h:30
bool applies() const
Definition GrStyle.h:143
static SkScalar MatrixToScaleFactor(const SkMatrix &matrix)
Definition GrStyle.h:147
bool isSimpleFill() const
Definition GrStyle.h:114
const SkStrokeRec & strokeRec() const
Definition GrStyle.h:140
bool isEmpty() const
bool asLine(SkPoint pts[2], bool *inverted) const
bool simplified() const
bool inverseFilled() const
const GrStyle & style() const
static GrStyledShape MakeArc(const SkRect &oval, SkScalar startAngleDegrees, SkScalar sweepAngleDegrees, bool useCenter, const GrStyle &style, DoSimplify=DoSimplify::kYes)
SkRect bounds() const
bool asNestedRects(SkRect rects[2]) const
GrStyledShape applyStyle(GrStyle::Apply apply, SkScalar scale) const
bool asRRect(SkRRect *rrect, SkPathDirection *dir, unsigned *start, bool *inverted) const
GrTextureProxy * asTextureProxy() const
SkRect getBoundsRect() const
skgpu::Budgeted isBudgeted() const
static sk_sp< GrSurfaceProxy > Copy(GrRecordingContext *, sk_sp< GrSurfaceProxy > src, GrSurfaceOrigin, skgpu::Mipmapped, SkIRect srcRect, SkBackingFit, skgpu::Budgeted, std::string_view label, RectsMustMatch=RectsMustMatch::kNo, sk_sp< GrRenderTask > *outTask=nullptr)
static std::unique_ptr< GrFragmentProcessor > MakeSubset(GrSurfaceProxyView, SkAlphaType, const SkMatrix &, GrSamplerState, const SkRect &subset, const GrCaps &caps, const float border[4]=kDefaultBorder, bool alwaysUseShaderTileMode=false)
static std::unique_ptr< GrFragmentProcessor > Make(GrSurfaceProxyView, SkAlphaType, const SkMatrix &=SkMatrix::I(), GrSamplerState::Filter=GrSamplerState::Filter::kNearest, GrSamplerState::MipmapMode mipmapMode=GrSamplerState::MipmapMode::kNone)
static const GrXPFactory * FromBlendMode(SkBlendMode)
SrcRectConstraint
Definition SkCanvas.h:1541
@ kStrict_SrcRectConstraint
sample only inside bounds; slower
Definition SkCanvas.h:1542
static constexpr int kMScaleX
horizontal scale factor
Definition SkMatrix.h:353
static constexpr int kMTransY
vertical translation
Definition SkMatrix.h:358
SkScalar getTranslateY() const
Definition SkMatrix.h:452
void setScaleTranslate(SkScalar sx, SkScalar sy, SkScalar tx, SkScalar ty)
Definition SkMatrix.h:1803
void mapPoints(SkPoint dst[], const SkPoint src[], int count) const
Definition SkMatrix.cpp:770
static SkMatrix MakeAll(SkScalar scaleX, SkScalar skewX, SkScalar transX, SkScalar skewY, SkScalar scaleY, SkScalar transY, SkScalar pers0, SkScalar pers1, SkScalar pers2)
Definition SkMatrix.h:179
static SkMatrix Concat(const SkMatrix &a, const SkMatrix &b)
Definition SkMatrix.h:1775
bool invert(SkMatrix *inverse) const
Definition SkMatrix.h:1206
bool rectStaysRect() const
Definition SkMatrix.h:271
static const SkMatrix & I()
bool isScaleTranslate() const
Definition SkMatrix.h:236
static constexpr int kMTransX
horizontal translation
Definition SkMatrix.h:355
bool isFinite() const
Definition SkMatrix.h:1834
bool isSimilarity(SkScalar tol=SK_ScalarNearlyZero) const
Definition SkMatrix.cpp:180
static constexpr int kMSkewX
horizontal skew factor
Definition SkMatrix.h:354
bool mapRect(SkRect *dst, const SkRect &src, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
SkScalar getTranslateX() const
Definition SkMatrix.h:445
@ kTranslate_Mask
translation SkMatrix
Definition SkMatrix.h:193
TypeMask getType() const
Definition SkMatrix.h:207
bool isValid() const
Definition SkMesh.cpp:753
SkMeshSpecification * spec() const
Definition SkMesh.h:348
@ kRound_Cap
adds circle
Definition SkPaint.h:335
@ kSquare_Cap
adds square
Definition SkPaint.h:336
@ kMiter_Join
extends to miter limit
Definition SkPaint.h:359
static SkScalar LengthSqd(const SkPoint &pt)
Definition SkPointPriv.h:63
static SkVector GetSimpleRadii(const SkRRect &rr)
Definition SkRRectPriv.h:22
static bool IsNearlySimpleCircular(const SkRRect &rr, SkScalar tolerance=SK_ScalarNearlyZero)
Definition SkRRect.cpp:342
SkVector getSimpleRadii() const
Definition SkRRect.h:111
bool isOval() const
Definition SkRRect.h:85
const SkRect & rect() const
Definition SkRRect.h:264
static SkRRect MakeOval(const SkRect &oval)
Definition SkRRect.h:162
bool transform(const SkMatrix &matrix, SkRRect *dst) const
Definition SkRRect.cpp:436
static SkRRect MakeRect(const SkRect &r)
Definition SkRRect.h:149
void setOval(const SkRect &oval)
Definition SkRRect.cpp:30
SkScalar width() const
Definition SkRRect.h:95
static SkRRect MakeRectXY(const SkRect &rect, SkScalar xRad, SkScalar yRad)
Definition SkRRect.h:180
bool isRect() const
Definition SkRRect.h:84
bool isEmpty() const
Definition SkRRect.h:83
const SkRect & getBounds() const
Definition SkRRect.h:279
bool isSimple() const
Definition SkRRect.h:86
void setRect(const SkRect &rect)
Definition SkRRect.h:126
bool getBoundaryPath(SkPath *path) const
Style getStyle() const
SkScalar getWidth() const
Definition SkStrokeRec.h:42
SkPaint::Join getJoin() const
Definition SkStrokeRec.h:45
SkPaint::Cap getCap() const
Definition SkStrokeRec.h:44
bool isFillStyle() const
Definition SkStrokeRec.h:51
SkScalar getMiter() const
Definition SkStrokeRec.h:43
AutoCheckFlush(GrDrawingManager *drawingManager)
static GrOp::Owner MakeStencilClip(GrRecordingContext *context, const GrScissorState &scissor, bool insideMask)
Definition ClearOp.cpp:33
static DEFINE_OP_CLASS_ID GrOp::Owner Make(GrRecordingContext *, std::unique_ptr< SkDrawable::GpuDrawHandler > drawable, const SkRect &bounds)
static GrOp::Owner Make(GrRecordingContext *, GrPaint &&, GrAAType, DrawQuad *, const GrUserStencilSettings *=nullptr, InputFlags=InputFlags::kNone)
static void AddFillRectOps(SurfaceDrawContext *, const GrClip *, GrRecordingContext *, GrPaint &&, GrAAType, const SkMatrix &viewMatrix, const GrQuadSetEntry quads[], int quadCount, const GrUserStencilSettings *=nullptr)
static GrOp::Owner MakeNonAARect(GrRecordingContext *, GrPaint &&, const SkMatrix &view, const SkRect &, const GrUserStencilSettings *=nullptr)
void setInitialStencilContent(StencilContent initialContent)
Definition OpsTask.h:136
bool usesMSAASurface() const
Definition OpsTask.h:51
GrSurfaceProxy * asSurfaceProxy()
GrDrawingManager * drawingManager()
SkDEBUGCODE(void validate() const ;) SkDEBUGCODE(skgpu GrRecordingContext * fContext
GrRenderTargetProxy * asRenderTargetProxy()
const GrCaps * caps() const
const GrColorInfo & colorInfo() const
GrTextureProxy * asTextureProxy()
skgpu::Mipmapped mipmapped() const
GrSurfaceProxyView readSurfaceView()
skgpu::Swizzle readSwizzle() const
sk_sp< GrSurfaceProxy > asSurfaceProxyRef()
GrSurfaceOrigin origin() const
void willReplaceOpsTask(OpsTask *prevTask, OpsTask *nextTask) override
bool stencilPath(const GrHardClip *, GrAA doStencilMSAA, const SkMatrix &viewMatrix, const SkPath &)
bool drawFastShadow(const GrClip *, const SkMatrix &viewMatrix, const SkPath &path, const SkDrawShadowRec &rec)
void drawOval(const GrClip *, GrPaint &&paint, GrAA, const SkMatrix &viewMatrix, const SkRect &oval, const GrStyle &style)
void fillQuadWithEdgeAA(const GrClip *clip, GrPaint &&paint, GrQuadAAFlags edgeAA, const SkMatrix &viewMatrix, const SkPoint points[4], const SkPoint optionalLocalPoints[4])
SurfaceDrawContext(GrRecordingContext *, GrSurfaceProxyView readView, GrSurfaceProxyView writeView, GrColorType, sk_sp< SkColorSpace >, const SkSurfaceProps &)
void fillPixelsWithLocalMatrix(const GrClip *clip, GrPaint &&paint, const SkIRect &bounds, const SkMatrix &localMatrix)
void drawShape(const GrClip *, GrPaint &&, GrAA, const SkMatrix &viewMatrix, GrStyledShape &&)
void drawDrawable(std::unique_ptr< SkDrawable::GpuDrawHandler >, const SkRect &bounds)
void drawAtlas(const GrClip *, GrPaint &&paint, const SkMatrix &viewMatrix, int spriteCount, const SkRSXform xform[], const SkRect texRect[], const SkColor colors[])
void drawTextureSet(const GrClip *, GrTextureSetEntry[], int cnt, int proxyRunCnt, GrSamplerState::Filter, GrSamplerState::MipmapMode, SkBlendMode mode, SkCanvas::SrcRectConstraint, const SkMatrix &viewMatrix, sk_sp< GrColorSpaceXform > texXform)
void setLastClip(uint32_t clipStackGenID, const SkIRect &devClipBounds, int numClipAnalyticElements)
void drawMesh(const GrClip *, GrPaint &&paint, const SkMatrix &viewMatrix, const SkMesh &mesh, skia_private::TArray< std::unique_ptr< GrFragmentProcessor > > children)
void drawArc(const GrClip *, GrPaint &&paint, GrAA, const SkMatrix &viewMatrix, const SkRect &oval, SkScalar startAngle, SkScalar sweepAngle, bool useCenter, const GrStyle &style)
void addDrawOp(const GrClip *, GrOp::Owner, const std::function< WillAddOpFn > &=std::function< WillAddOpFn >())
bool waitOnSemaphores(int numSemaphores, const GrBackendSemaphore waitSemaphores[], bool deleteSemaphoresAfterWait)
void drawQuadSet(const GrClip *clip, GrPaint &&paint, const SkMatrix &viewMatrix, const GrQuadSetEntry[], int cnt)
void drawImageLattice(const GrClip *, GrPaint &&, const SkMatrix &viewMatrix, GrSurfaceProxyView, SkAlphaType alphaType, sk_sp< GrColorSpaceXform >, GrSamplerState::Filter, std::unique_ptr< SkLatticeIter >, const SkRect &dst)
void drawPath(const GrClip *, GrPaint &&, GrAA, const SkMatrix &viewMatrix, const SkPath &, const GrStyle &)
bool drawAndStencilPath(const GrHardClip *, const GrUserStencilSettings *, SkRegion::Op op, bool invert, GrAA doStencilMSAA, const SkMatrix &viewMatrix, const SkPath &)
bool mustRenderClip(uint32_t clipStackGenID, const SkIRect &devClipBounds, int numClipAnalyticElements)
void drawRRect(const GrClip *, GrPaint &&, GrAA, const SkMatrix &viewMatrix, const SkRRect &rrect, const GrStyle &style)
void drawPaint(const GrClip *, GrPaint &&, const SkMatrix &viewMatrix)
void drawRegion(const GrClip *, GrPaint &&paint, GrAA aa, const SkMatrix &viewMatrix, const SkRegion &region, const GrStyle &style, const GrUserStencilSettings *ss=nullptr)
static std::unique_ptr< SurfaceDrawContext > MakeFromBackendTexture(GrRecordingContext *, GrColorType, sk_sp< SkColorSpace >, const GrBackendTexture &, int sampleCnt, GrSurfaceOrigin, const SkSurfaceProps &, sk_sp< skgpu::RefCntedCallback > releaseHelper)
void stencilRect(const GrClip *clip, const GrUserStencilSettings *ss, GrPaint &&paint, GrAA doStencilMSAA, const SkMatrix &viewMatrix, const SkRect &rect, const SkMatrix *localMatrix=nullptr)
const SkSurfaceProps & surfaceProps() const
OpsTask::CanDiscardPreviousOps canDiscardPreviousOpsOnFullClear() const override
static std::unique_ptr< SurfaceDrawContext > Make(GrRecordingContext *, GrColorType, sk_sp< GrSurfaceProxy >, sk_sp< SkColorSpace >, GrSurfaceOrigin, const SkSurfaceProps &)
void drawRect(const GrClip *, GrPaint &&paint, GrAA, const SkMatrix &viewMatrix, const SkRect &, const GrStyle *style=nullptr)
static std::unique_ptr< SurfaceDrawContext > MakeWithFallback(GrRecordingContext *, GrColorType, sk_sp< SkColorSpace >, SkBackingFit, SkISize dimensions, const SkSurfaceProps &, int sampleCnt, skgpu::Mipmapped, skgpu::Protected, GrSurfaceOrigin=kBottomLeft_GrSurfaceOrigin, skgpu::Budgeted=skgpu::Budgeted::kYes)
void drawGlyphRunList(SkCanvas *, const GrClip *, const SkMatrix &viewMatrix, const sktext::GlyphRunList &glyphRunList, SkStrikeDeviceInfo strikeDeviceInfo, const SkPaint &paint)
void fillRectToRect(const GrClip *, GrPaint &&, GrAA, const SkMatrix &, const SkRect &rectToDraw, const SkRect &localRect)
void drawVertices(const GrClip *, GrPaint &&paint, const SkMatrix &viewMatrix, sk_sp< SkVertices > vertices, GrPrimitiveType *overridePrimType=nullptr, bool skipColorXform=false)
void drawTexture(const GrClip *, GrSurfaceProxyView, SkAlphaType, GrSamplerState::Filter, GrSamplerState::MipmapMode, SkBlendMode, const SkPMColor4f &, const SkRect &srcRect, const SkRect &dstRect, GrQuadAAFlags, SkCanvas::SrcRectConstraint, const SkMatrix &, sk_sp< GrColorSpaceXform >)
void drawStrokedLine(const GrClip *, GrPaint &&, GrAA, const SkMatrix &, const SkPoint[2], const SkStrokeRec &)
void clear(const SkIRect &rect, const SkRGBA4f< AlphaType > &color)
static void AddTextureSetOps(skgpu::ganesh::SurfaceDrawContext *, const GrClip *, GrRecordingContext *, GrTextureSetEntry[], int cnt, int proxyRunCnt, GrSamplerState::Filter, GrSamplerState::MipmapMode, Saturate, SkBlendMode, GrAAType, SkCanvas::SrcRectConstraint, const SkMatrix &viewMatrix, sk_sp< GrColorSpaceXform > textureXform)
static GrOp::Owner Make(GrRecordingContext *, GrSurfaceProxyView, SkAlphaType srcAlphaType, sk_sp< GrColorSpaceXform >, GrSamplerState::Filter, GrSamplerState::MipmapMode, const SkPMColor4f &, Saturate, SkBlendMode, GrAAType, DrawQuad *, const SkRect *subset=nullptr)
void drawGlyphRunList(SkCanvas *canvas, const SkMatrix &viewMatrix, const GlyphRunList &glyphRunList, const SkPaint &paint, SkStrikeDeviceInfo strikeDeviceInfo, const AtlasDrawDelegate &)
const Paint & paint
float SkScalar
Definition extension.cpp:12
gboolean invert
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
GAsyncResult * result
uint32_t uint32_t * format
#define ASSERT_SINGLE_OWNER
Definition Device.cpp:120
bool WillUseHairline(const GrQuad &quad, GrAAType aaType, GrQuadAAFlags edgeFlags)
bool CropToRect(const SkRect &cropRect, GrAA cropAA, DrawQuad *quad, bool computeLocal)
SkScalar AmbientRecipAlpha(SkScalar height)
void GetDirectionalParams(SkScalar occluderZ, SkScalar lightX, SkScalar lightY, SkScalar lightZ, SkScalar lightRadius, SkScalar *blurRadius, SkScalar *scale, SkVector *translate)
SkScalar AmbientBlurRadius(SkScalar height)
void GetSpotParams(SkScalar occluderZ, SkScalar lightX, SkScalar lightY, SkScalar lightZ, SkScalar lightRadius, SkScalar *blurRadius, SkScalar *scale, SkVector *translate)
SkRRect rrect
Definition SkRecords.h:232
Definition copy.py:1
GrOp::Owner Make(GrRecordingContext *context, GrPaint &&paint, const SkMatrix &viewMatrix, GrAAType aaType, int spriteCount, const SkRSXform *xforms, const SkRect *rects, const SkColor *colors)
GrOp::Owner Make(GrRecordingContext *context, GrPaint &&paint, const SkMesh &mesh, TArray< std::unique_ptr< GrFragmentProcessor > > children, const SkMatrix &viewMatrix, GrAAType aaType, sk_sp< GrColorSpaceXform > colorSpaceXform)
GrOp::Owner Make(GrRecordingContext *ctx, SkArenaAlloc *arena, GrPaint &&paint, const SkMatrix &viewMatrix, const SkRRect &rrect, const SkRect &localRect, GrAA aa)
GrOp::Owner MakeNonAA(GrRecordingContext *context, GrPaint &&paint, const SkMatrix &viewMatrix, GrSurfaceProxyView view, SkAlphaType alphaType, sk_sp< GrColorSpaceXform > colorSpaceXform, GrSamplerState::Filter filter, std::unique_ptr< SkLatticeIter > iter, const SkRect &dst)
GrOp::Owner Make(GrRecordingContext *context, GrPaint &&paint, const SkMatrix &viewMatrix, const SkRegion &region, GrAAType aaType, const GrUserStencilSettings *stencilSettings)
Definition RegionOp.cpp:204
GrOp::Owner Make(GrRecordingContext *context, GrColor color, const SkMatrix &viewMatrix, const SkRRect &rrect, SkScalar blurWidth, SkScalar insetWidth)
GrOp::Owner Make(GrRecordingContext *context, GrPaint &&paint, GrAAType aaType, const SkMatrix &viewMatrix, const SkRect &rect, const SkStrokeRec &stroke)
GrOp::Owner MakeNested(GrRecordingContext *context, GrPaint &&paint, const SkMatrix &viewMatrix, const SkRect rects[2])
static SkIRect get_clip_bounds(const SurfaceDrawContext *sdc, const GrClip *clip)
std::tuple< bool, bool > FilterAndMipmapHaveNoEffect(const GrQuad &srcQuad, const GrQuad &dstQuad)
Budgeted
Definition GpuTypes.h:35
Mipmapped
Definition GpuTypes.h:53
Protected
Definition GpuTypes.h:61
Definition ref_ptr.h:256
GrQuad fLocal
Definition GrQuad.h:186
GrQuad fDevice
Definition GrQuad.h:185
GrQuadAAFlags fEdgeFlags
Definition GrQuad.h:187
GrSurfaceProxy::RectsMustMatch fRectsMustMatch
Definition GrCaps.h:458
static const GrUserStencilSettings & kUnused
bool intersect(const SkIRect &r)
Definition SkRect.h:513
int32_t fTop
smaller y-axis bounds
Definition SkRect.h:34
static constexpr SkIRect MakeSize(const SkISize &size)
Definition SkRect.h:66
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition SkRect.h:56
int32_t fLeft
smaller x-axis bounds
Definition SkRect.h:33
void outset(int32_t dx, int32_t dy)
Definition SkRect.h:428
static SkAlphaType AlphaType(const SkMeshSpecification &spec)
Definition SkMeshPriv.h:38
static SkColorSpace * ColorSpace(const SkMeshSpecification &spec)
Definition SkMeshPriv.h:34
SkScalar fX
Definition SkPoint3.h:16
SkScalar fZ
Definition SkPoint3.h:16
SkScalar fY
Definition SkPoint3.h:16
float fX
x-axis value
static float Normalize(SkVector *vec)
Definition SkPoint.cpp:71
static constexpr SkPoint Make(float x, float y)
float fY
y-axis value
uint32_t toBytes_RGBA() const
static SkRect Make(const SkISize &size)
Definition SkRect.h:669
SkScalar fBottom
larger y-axis bounds
Definition extension.cpp:17
bool isFinite() const
Definition SkRect.h:711
bool intersect(const SkRect &r)
Definition SkRect.cpp:114
SkScalar fLeft
smaller x-axis bounds
Definition extension.cpp:14
SkRect makeOutset(float dx, float dy) const
Definition SkRect.h:1002
SkScalar fRight
larger x-axis bounds
Definition extension.cpp:16
bool contains(SkScalar x, SkScalar y) const
Definition extension.cpp:19
void roundOut(SkIRect *dst) const
Definition SkRect.h:1241
void round(SkIRect *dst) const
Definition SkRect.h:1228
constexpr float height() const
Definition SkRect.h:769
constexpr float width() const
Definition SkRect.h:762
bool isEmpty() const
Definition SkRect.h:693
SkScalar fTop
smaller y-axis bounds
Definition extension.cpp:15