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