Debian Codegraph @

src/gpu/ganesh/SurfaceDrawContext.h

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