Debian Codegraph @

src/gpu/ganesh/SurfaceDrawContext.h

raw ◀ ▶
1 Debian patch touch 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 #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 bool setMayHavePersp);
328
329 /**
330 * Draw a roundrect using a paint.
331 *
332 * @param paint describes how to color pixels.
333 * @param GrAA Controls whether rrect is antialiased.
334 * @param viewMatrix transformation matrix
335 * @param rrect the roundrect to draw
336 * @param style style to apply to the rrect. Currently path effects are not allowed.
337 */
338 void drawRRect(const GrClip*,
339 GrPaint&&,
340 GrAA,
341 const SkMatrix& viewMatrix,
342 const SkRRect& rrect,
343 const GrStyle& style);
344
345 /**
346 * Use a fast method to render the ambient and spot shadows for a path.
347 * Will return false if not possible for the given path.
348 *
349 * @param viewMatrix transformation matrix
350 * @param path the path to shadow
351 * @param rec parameters for shadow rendering
352 */
353 bool drawFastShadow(const GrClip*,
354 const SkMatrix& viewMatrix,
355 const SkPath& path,
356 const SkDrawShadowRec& rec);
357
358 /**
359 * Draws a path.
360 *
361 * @param paint describes how to color pixels.
362 * @param GrAA Controls whether the path is antialiased.
363 * @param viewMatrix transformation matrix
364 * @param path the path to draw
365 * @param style style to apply to the path.
366 */
367 void drawPath(const GrClip*,
368 GrPaint&&,
369 GrAA,
370 const SkMatrix& viewMatrix,
371 const SkPath&,
372 const GrStyle&);
373
374 /**
375 * Draws a shape.
376 *
377 * @param paint describes how to color pixels.
378 * @param GrAA Controls whether the path is antialiased.
379 * @param viewMatrix transformation matrix
380 * @param shape the shape to draw
381 */
382 void drawShape(const GrClip*,
383 GrPaint&&,
384 GrAA,
385 const SkMatrix& viewMatrix,
386 GrStyledShape&&);
387
388 /**
389 * Draws vertices with a paint.
390 *
391 * @param paint describes how to color pixels.
392 * @param viewMatrix transformation matrix
393 * @param vertices specifies the mesh to draw.
394 * @param overridePrimType primitive type to draw. If NULL, derive prim type from vertices.
395 * @param skipColorXform if true, do not apply a color space transfer function
396 */
397 void drawVertices(const GrClip*,
398 GrPaint&& paint,
399 const SkMatrix& viewMatrix,
400 sk_sp<SkVertices> vertices,
401 GrPrimitiveType* overridePrimType = nullptr,
402 bool skipColorXform = false);
403
404 /**
405 * Draws a custom mesh with a paint.
406 *
407 * @param paint describes how to color pixels.
408 * @param viewMatrix transformation matrix
409 * @param mesh the mesh to draw.
410 * @param children child effects referenced by SkMesh shaders
411 */
412 void drawMesh(const GrClip*,
413 GrPaint&& paint,
414 const SkMatrix& viewMatrix,
415 const SkMesh& mesh,
416 skia_private::TArray<std::unique_ptr<GrFragmentProcessor>> children);
417
418 /**
419 * Draws textured sprites from an atlas with a paint. This currently does not support AA for the
420 * sprite rectangle edges.
421 *
422 * @param paint describes how to color pixels.
423 * @param viewMatrix transformation matrix
424 * @param spriteCount number of sprites.
425 * @param xform array of compressed transformation data, required.
426 * @param texRect array of texture rectangles used to access the paint.
427 * @param colors optional array of per-sprite colors, supercedes
428 * the paint's color field.
429 */
430 void drawAtlas(const GrClip*,
431 GrPaint&& paint,
432 const SkMatrix& viewMatrix,
433 SkSpan<const SkRSXform> xform,
434 SkSpan<const SkRect> texRect,
435 SkSpan<const SkColor> colors);
436
437 /**
438 * Draws a region.
439 *
440 * @param paint describes how to color pixels
441 * @param viewMatrix transformation matrix
442 * @param aa should the rects of the region be antialiased.
443 * @param region the region to be drawn
444 * @param style style to apply to the region
445 */
446 void drawRegion(const GrClip*,
447 GrPaint&& paint,
448 GrAA aa,
449 const SkMatrix& viewMatrix,
450 const SkRegion& region,
451 const GrStyle& style,
452 const GrUserStencilSettings* ss = nullptr);
453
454 /**
455 * Draws an oval.
456 *
457 * @param paint describes how to color pixels.
458 * @param GrAA Controls whether the oval is antialiased.
459 * @param viewMatrix transformation matrix
460 * @param oval the bounding rect of the oval.
461 * @param style style to apply to the oval. Currently path effects are not allowed.
462 */
463 void drawOval(const GrClip*,
464 GrPaint&& paint,
465 GrAA,
466 const SkMatrix& viewMatrix,
467 const SkRect& oval,
468 const GrStyle& style);
469
470 /**
471 * Draws a partial arc of an oval.
472 *
473 * @param paint describes how to color pixels.
474 * @param GrGrAA Controls whether the arc is antialiased.
475 * @param viewMatrix transformation matrix.
476 * @param oval the bounding rect of the oval.
477 * @param startAngle starting angle in degrees.
478 * @param sweepAngle angle to sweep in degrees. Must be in (-360, 360)
479 * @param useCenter true means that the implied path begins at the oval center, connects as
480 * a line to the point indicated by the start contains the arc indicated by
481 * the sweep angle. If false the line beginning at the center point is
482 * omitted.
483 * @param style style to apply to the oval.
484 */
485 void drawArc(const GrClip*,
486 GrPaint&& paint,
487 GrAA,
488 const SkMatrix& viewMatrix,
489 const SkArc& arc,
490 const GrStyle& style);
491
492 /**
493 * Draw the image as a set of rects, specified by |iter|.
494 */
495 void drawImageLattice(const GrClip*,
496 GrPaint&&,
497 const SkMatrix& viewMatrix,
498 GrSurfaceProxyView,
499 SkAlphaType alphaType,
500 sk_sp<GrColorSpaceXform>,
501 GrSamplerState::Filter,
502 std::unique_ptr<SkLatticeIter>,
503 const SkRect& dst);
504
505 /**
506 * Draw the text specified by the GlyphRunList.
507 *
508 * @param viewMatrix transformation matrix
509 * @param glyphRunList text, text positions, and paint.
510 */
511 void drawGlyphRunList(SkCanvas*,
512 const GrClip*,
513 const SkMatrix& viewMatrix,
514 const sktext::GlyphRunList& glyphRunList,
515 SkStrikeDeviceInfo strikeDeviceInfo,
516 const SkPaint& paint);
517
518 /**
519 * Adds the necessary signal and wait semaphores and adds the passed in SkDrawable to the
520 * command stream.
521 */
522 void drawDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler>, const SkRect& bounds);
523
524 // called to note the last clip drawn to the stencil buffer.
525 // TODO: remove after clipping overhaul.
526 void setLastClip(uint32_t clipStackGenID,
527 const SkIRect& devClipBounds,
528 int numClipAnalyticElements);
529
530 // called to determine if we have to render the clip into SB.
531 // TODO: remove after clipping overhaul.
532 bool mustRenderClip(uint32_t clipStackGenID,
533 const SkIRect& devClipBounds,
534 int numClipAnalyticElements);
535
536 void clearStencilClip(const SkIRect& scissor, bool insideStencilMask) {
537 this->internalStencilClear(&scissor, insideStencilMask);
538 }
539
540 // While this can take a general clip, since ClipStack relies on this function, it must take
541 // care to only provide hard clips or we could get stuck in a loop. The general clip is needed
542 // so that path renderers can use this function.
543 void stencilRect(const GrClip* clip,
544 const GrUserStencilSettings* ss,
545 GrPaint&& paint,
546 GrAA doStencilMSAA,
547 const SkMatrix& viewMatrix,
548 const SkRect& rect,
549 const SkMatrix* localMatrix = nullptr) {
550 // Since this provides stencil settings to drawFilledQuad, it performs a different AA type
551 // resolution compared to regular rect draws, which is the main reason it remains separate.
552 DrawQuad quad{GrQuad::MakeFromRect(rect, viewMatrix),
553 localMatrix ? GrQuad::MakeFromRect(rect, *localMatrix) : GrQuad(rect),
554 doStencilMSAA == GrAA::kYes ? GrQuadAAFlags::kAll : GrQuadAAFlags::kNone};
555 this->drawFilledQuad(clip, std::move(paint), &quad, ss);
556 }
557
558 // Fills the user stencil bits with a non-zero value at every sample inside the path. This will
559 // likely be implemented with a Redbook algorithm, but it is not guaranteed. The samples being
560 // rendered to must be zero initially.
561 bool stencilPath(const GrHardClip*,
562 GrAA doStencilMSAA,
563 const SkMatrix& viewMatrix,
564 const SkPath&);
565
566 /**
567 * Draws a path, either AA or not, and touches the stencil buffer with the user stencil settings
568 * for each color sample written.
569 */
570 bool drawAndStencilPath(const GrHardClip*,
571 const GrUserStencilSettings*,
572 SkRegion::Op op,
573 bool invert,
574 GrAA doStencilMSAA,
575 const SkMatrix& viewMatrix,
576 const SkPath&);
577
578 skgpu::Budgeted isBudgeted() const;
579
580 int maxWindowRectangles() const;
581
582 /*
583 * This unique ID will not change for a given SurfaceDrawContext. However, it is _NOT_
584 * guaranteed to match the uniqueID of the underlying GrRenderTarget - beware!
585 */
586 GrSurfaceProxy::UniqueID uniqueID() const { return this->asSurfaceProxy()->uniqueID(); }
587
588 // Allows caller of addDrawOp to know which op list an op will be added to.
589 using WillAddOpFn = void(GrOp*, uint32_t opsTaskID);
590 // These perform processing specific to GrDrawOp-derived ops before recording them into an
591 // op list. Before adding the op to an op list the WillAddOpFn is called. Note that it
592 // will not be called in the event that the op is discarded. Moreover, the op may merge into
593 // another op after the function is called (either before addDrawOp returns or some time later).
594 //
595 // If the clip pointer is null, no clipping will be performed.
596 void addDrawOp(const GrClip*,
597 GrOp::Owner,
598 const std::function<WillAddOpFn>& = std::function<WillAddOpFn>());
599 void addDrawOp(GrOp::Owner op) { this->addDrawOp(nullptr, std::move(op)); }
600
601 bool refsWrappedObjects() const { return this->asRenderTargetProxy()->refsWrappedObjects(); }
602
603 /**
604 * The next time this SurfaceDrawContext is flushed, the gpu will wait on the passed in
605 * semaphores before executing any commands.
606 */
607 bool waitOnSemaphores(int numSemaphores, const GrBackendSemaphore waitSemaphores[],
608 bool deleteSemaphoresAfterWait);
609
610 int numSamples() const { return this->asRenderTargetProxy()->numSamples(); }
611 const SkSurfaceProps& surfaceProps() const { return fSurfaceProps; }
612 bool canUseDynamicMSAA() const { return fCanUseDynamicMSAA; }
613 bool wrapsVkSecondaryCB() const { return this->asRenderTargetProxy()->wrapsVkSecondaryCB(); }
614
615 bool alwaysAntialias() const {
616 return fSurfaceProps.flags() & SkSurfaceProps::kDynamicMSAA_Flag;
617 }
618
619 GrAA chooseAA(const SkPaint& paint) {
620 return GrAA(paint.isAntiAlias() || this->alwaysAntialias());
621 }
622
623 GrAAType chooseAAType(GrAA aa) {
624 if (this->numSamples() > 1 || fCanUseDynamicMSAA) {
625 // Always trigger DMSAA when it's available. The coverage ops that know how to handle
626 // both single and multisample targets without popping will do so without calling
627 // chooseAAType.
628 return GrAAType::kMSAA;
629 }
630 return (aa == GrAA::kYes) ? GrAAType::kCoverage : GrAAType::kNone;
631 }
632
633 // This entry point should only be called if the backing GPU object is known to be
634 // instantiated.
635 GrRenderTarget* accessRenderTarget() { return this->asSurfaceProxy()->peekRenderTarget(); }
636
637 #if defined(GPU_TEST_UTILS)
638 void testingOnly_SetPreserveOpsOnFullClear() { fPreserveOpsOnFullClear_TestingOnly = true; }
639 #endif
640
641 void drawStrokedLine(const GrClip*, GrPaint&&, GrAA, const SkMatrix&, const SkPoint[2],
642 const SkStrokeRec&);
643
644 private:
645 enum class QuadOptimization;
646
647 void willReplaceOpsTask(OpsTask* prevTask, OpsTask* nextTask) override;
648
649 OpsTask::CanDiscardPreviousOps canDiscardPreviousOpsOnFullClear() const override;
650 void setNeedsStencil();
651
652 void internalStencilClear(const SkIRect* scissor, bool insideStencilMask);
653
654 // 'stencilSettings' are provided merely for decision making purposes; When non-null,
655 // optimization strategies that submit special ops are avoided.
656 //
657 // 'quad' should be the original draw request on input, and will be updated as
658 // appropriate depending on the returned optimization level.
659 //
660 // If kSubmitted is returned, the provided paint was consumed. Otherwise it is left unchanged.
661 QuadOptimization attemptQuadOptimization(const GrClip* clip,
662 const GrUserStencilSettings* stencilSettings,
663 DrawQuad* quad,
664 GrPaint* paint);
665
666 // The overall AA policy is determined by the quad's edge flags: kNone is no AA, and anything
667 // else uses some form of anti-aliasing. If 'ss' is non-null, that will be MSAA; otherwise it's
668 // MSAA or analytic coverage per chooseAAType(). This will always attempt to apply
669 // quad optimizations, so all quad/rect public APIs should rely on this function for consistent
670 // clipping behavior. 'quad' will be modified in place to reflect final rendered geometry.
671 void drawFilledQuad(const GrClip* clip,
672 GrPaint&& paint,
673 DrawQuad* quad,
674 const GrUserStencilSettings* ss = nullptr);
675
676 // Like drawFilledQuad but does not require using a GrPaint or FP for texturing.
677 // 'quad' may be modified in place to reflect final geometry.
678 void drawTexturedQuad(const GrClip* clip,
679 GrSurfaceProxyView proxyView,
680 SkAlphaType alphaType,
681 sk_sp<GrColorSpaceXform> textureXform,
682 GrSamplerState::Filter filter,
683 GrSamplerState::MipmapMode,
684 const SkPMColor4f& color,
685 SkBlendMode blendMode,
686 DrawQuad* quad,
687 const SkRect* subset = nullptr);
688
689 // Tries to detect if the given shape is a simple, and draws it without path rendering if
690 // we know how.
691 bool drawSimpleShape(const GrClip*, GrPaint*, GrAA, const SkMatrix&, const GrStyledShape&);
692
693 // If 'attemptDrawSimple' is true, of if the original shape is marked as having been simplfied,
694 // this will attempt to re-route through drawSimpleShape() to see if we can avoid path rendering
695 // one more time.
696 void drawShapeUsingPathRenderer(const GrClip*, GrPaint&&, GrAA, const SkMatrix&,
697 GrStyledShape&&, bool attemptDrawSimple = false);
698
699 // Makes a copy of the proxy if it is necessary for the draw and places the texture that should
700 // be used by GrXferProcessor to access the destination color in 'result'. If the return
701 // value is false then a texture copy could not be made.
702 //
703 // The op should have already had setClippedBounds called on it.
704 [[nodiscard]] bool setupDstProxyView(const SkRect& opBounds,
705 bool opRequiresMSAA,
706 GrDstProxyView* result);
707
708 OpsTask* replaceOpsTaskIfModifiesColor();
709
710 const SkSurfaceProps fSurfaceProps;
711 const bool fCanUseDynamicMSAA;
712
713 bool fNeedsStencil = false;
714
715 #if defined(GPU_TEST_UTILS)
716 bool fPreserveOpsOnFullClear_TestingOnly = false;
717 #endif
718 };
719
720 } // namespace skgpu::ganesh
721
722 #endif // SurfaceDrawContext_v1_DEFINED