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