Skia
2DGraphicsLibrary
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GrDrawContext.h
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 GrDrawContext_DEFINED
9 #define GrDrawContext_DEFINED
10 
11 #include "GrColor.h"
12 #include "GrPaint.h"
13 #include "GrRenderTarget.h"
14 #include "SkRefCnt.h"
15 #include "SkRegion.h"
16 #include "SkSurfaceProps.h"
17 #include "../private/GrInstancedPipelineInfo.h"
18 #include "../private/GrSingleOwner.h"
19 
20 class GrAuditTrail;
21 class GrClip;
22 class GrContext;
23 class GrDrawBatch;
24 class GrDrawContextPriv;
25 class GrDrawPathBatchBase;
26 class GrDrawingManager;
27 class GrDrawTarget;
28 class GrPaint;
29 class GrPathProcessor;
30 class GrPipelineBuilder;
31 class GrRenderTarget;
32 class GrStyle;
33 class GrSurface;
34 struct GrUserStencilSettings;
35 class SkDrawFilter;
36 struct SkIPoint;
37 struct SkIRect;
38 class SkLatticeIter;
39 class SkMatrix;
40 class SkPaint;
41 class SkPath;
42 struct SkPoint;
43 struct SkRect;
44 class SkRRect;
45 struct SkRSXform;
46 class SkTextBlob;
47 
48 /*
49  * A helper object to orchestrate draws
50  */
51 class SK_API GrDrawContext : public SkRefCnt {
52 public:
53  ~GrDrawContext() override;
54 
55  bool copySurface(GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint);
56 
57  // TODO: it is odd that we need both the SkPaint in the following 3 methods.
58  // We should extract the text parameters from SkPaint and pass them separately
59  // akin to GrStyle (GrTextInfo?)
60  virtual void drawText(const GrClip&, const GrPaint&, const SkPaint&,
61  const SkMatrix& viewMatrix, const char text[], size_t byteLength,
62  SkScalar x, SkScalar y, const SkIRect& clipBounds);
63  virtual void drawPosText(const GrClip&, const GrPaint&, const SkPaint&,
64  const SkMatrix& viewMatrix, const char text[], size_t byteLength,
65  const SkScalar pos[], int scalarsPerPosition,
66  const SkPoint& offset, const SkIRect& clipBounds);
67  virtual void drawTextBlob(const GrClip&, const SkPaint&,
68  const SkMatrix& viewMatrix, const SkTextBlob*,
69  SkScalar x, SkScalar y,
70  SkDrawFilter*, const SkIRect& clipBounds);
71 
76  void discard();
77 
85  void clear(const SkIRect* rect, GrColor color, bool canIgnoreRect);
86 
90  void drawPaint(const GrClip&, const GrPaint&, const SkMatrix& viewMatrix);
91 
100  void drawRect(const GrClip&,
101  const GrPaint& paint,
102  const SkMatrix& viewMatrix,
103  const SkRect&,
104  const GrStyle* style = nullptr);
105 
114  void fillRectToRect(const GrClip&,
115  const GrPaint& paint,
116  const SkMatrix& viewMatrix,
117  const SkRect& rectToDraw,
118  const SkRect& localRect);
119 
123  void fillRectWithLocalMatrix(const GrClip& clip,
124  const GrPaint& paint,
125  const SkMatrix& viewMatrix,
126  const SkRect& rect,
127  const SkMatrix& localMatrix);
128 
137  void drawRRect(const GrClip&,
138  const GrPaint&,
139  const SkMatrix& viewMatrix,
140  const SkRRect& rrect,
141  const GrStyle& style);
142 
153  void drawDRRect(const GrClip&,
154  const GrPaint&,
155  const SkMatrix& viewMatrix,
156  const SkRRect& outer,
157  const SkRRect& inner);
158 
167  void drawPath(const GrClip&,
168  const GrPaint&,
169  const SkMatrix& viewMatrix,
170  const SkPath&,
171  const GrStyle& style);
172 
190  void drawVertices(const GrClip&,
191  const GrPaint& paint,
192  const SkMatrix& viewMatrix,
193  GrPrimitiveType primitiveType,
194  int vertexCount,
195  const SkPoint positions[],
196  const SkPoint texs[],
197  const GrColor colors[],
198  const uint16_t indices[],
199  int indexCount);
200 
212  void drawAtlas(const GrClip&,
213  const GrPaint& paint,
214  const SkMatrix& viewMatrix,
215  int spriteCount,
216  const SkRSXform xform[],
217  const SkRect texRect[],
218  const SkColor colors[]);
219 
228  void drawOval(const GrClip&,
229  const GrPaint& paint,
230  const SkMatrix& viewMatrix,
231  const SkRect& oval,
232  const GrStyle& style);
247  void drawArc(const GrClip&,
248  const GrPaint& paint,
249  const SkMatrix& viewMatrix,
250  const SkRect& oval,
251  SkScalar startAngle,
252  SkScalar sweepAngle,
253  bool useCenter,
254  const GrStyle& style);
255 
259  void drawImageLattice(const GrClip&,
260  const GrPaint& paint,
261  const SkMatrix& viewMatrix,
262  int imageWidth,
263  int imageHeight,
264  std::unique_ptr<SkLatticeIter> iter,
265  const SkRect& dst);
266 
271  void prepareForExternalIO();
272 
273  bool isStencilBufferMultisampled() const {
274  return fRenderTarget->isStencilBufferMultisampled();
275  }
276  bool isUnifiedMultisampled() const { return fRenderTarget->isUnifiedMultisampled(); }
277  bool hasMixedSamples() const { return fRenderTarget->isMixedSampled(); }
278 
279  bool mustUseHWAA(const GrPaint& paint) const {
280  return paint.isAntiAlias() && fRenderTarget->isUnifiedMultisampled();
281  }
282 
283  const GrSurfaceDesc& desc() const { return fRenderTarget->desc(); }
284  int width() const { return fRenderTarget->width(); }
285  int height() const { return fRenderTarget->height(); }
286  GrPixelConfig config() const { return fRenderTarget->config(); }
287  int numColorSamples() const { return fRenderTarget->numColorSamples(); }
288  bool isGammaCorrect() const { return SkToBool(fColorSpace.get()); }
289  SkSourceGammaTreatment sourceGammaTreatment() const {
290  return this->isGammaCorrect() ? SkSourceGammaTreatment::kRespect
291  : SkSourceGammaTreatment::kIgnore;
292  }
293  const SkSurfaceProps& surfaceProps() const { return fSurfaceProps; }
294  SkColorSpace* getColorSpace() const { return fColorSpace.get(); }
295  GrSurfaceOrigin origin() const { return fRenderTarget->origin(); }
296 
297  bool wasAbandoned() const;
298 
299  GrRenderTarget* accessRenderTarget() { return fRenderTarget.get(); }
300 
301  sk_sp<GrRenderTarget> renderTarget() { return fRenderTarget; }
302 
303  sk_sp<GrTexture> asTexture() { return sk_ref_sp(fRenderTarget->asTexture()); }
304 
305  // Provides access to functions that aren't part of the public API.
306  GrDrawContextPriv drawContextPriv();
307  const GrDrawContextPriv drawContextPriv() const;
308 
309  GrAuditTrail* auditTrail() { return fAuditTrail; }
310 
311 protected:
313  const SkSurfaceProps* surfaceProps, GrAuditTrail*, GrSingleOwner*);
314 
315  GrDrawingManager* drawingManager() { return fDrawingManager; }
316 
317  SkDEBUGCODE(GrSingleOwner* singleOwner() { return fSingleOwner; })
318  SkDEBUGCODE(void validate() const;)
319 
320 private:
321  friend class GrAtlasTextBlob; // for access to drawBatch
322  friend class GrStencilAndCoverTextContext; // for access to drawBatch
323 
324  friend class GrDrawingManager; // for ctor
325  friend class GrDrawContextPriv;
326  friend class GrTestTarget; // for access to getDrawTarget
327  friend class GrSWMaskHelper; // for access to drawBatch
328 
329  // All the path renderers currently make their own batches
330  friend class GrSoftwarePathRenderer; // for access to drawBatch
331  friend class GrAAConvexPathRenderer; // for access to drawBatch
332  friend class GrDashLinePathRenderer; // for access to drawBatch
333  friend class GrAAHairLinePathRenderer; // for access to drawBatch
334  friend class GrAALinearizingConvexPathRenderer; // for access to drawBatch
335  friend class GrAADistanceFieldPathRenderer; // for access to drawBatch
336  friend class GrDefaultPathRenderer; // for access to drawBatch
337  friend class GrPLSPathRenderer; // for access to drawBatch
338  friend class GrMSAAPathRenderer; // for access to drawBatch
339  friend class GrStencilAndCoverPathRenderer; // for access to drawBatch
340  friend class GrTessellatingPathRenderer; // for access to drawBatch
341 
342  bool drawFilledDRRect(const GrClip& clip,
343  const GrPaint& paint,
344  const SkMatrix& viewMatrix,
345  const SkRRect& origOuter,
346  const SkRRect& origInner);
347 
348  bool drawFilledRect(const GrClip& clip,
349  const GrPaint& paint,
350  const SkMatrix& viewMatrix,
351  const SkRect& rect,
352  const GrUserStencilSettings* ss);
353 
354  void drawNonAAFilledRect(const GrClip&,
355  const GrPaint&,
356  const SkMatrix& viewMatrix,
357  const SkRect& rect,
358  const SkRect* localRect,
359  const SkMatrix* localMatrix,
360  const GrUserStencilSettings* ss,
361  bool useHWAA);
362 
363  void internalDrawPath(const GrClip& clip,
364  const GrPaint& paint,
365  const SkMatrix& viewMatrix,
366  const SkPath& path,
367  const GrStyle& style);
368 
369  // This entry point allows the GrTextContext-derived classes to add their batches to
370  // the drawTarget.
371  void drawBatch(const GrPipelineBuilder& pipelineBuilder, const GrClip&, GrDrawBatch* batch);
372 
373  GrDrawTarget* getDrawTarget();
374 
375  GrDrawingManager* fDrawingManager;
376  sk_sp<GrRenderTarget> fRenderTarget;
377 
378  // In MDB-mode the drawTarget can be closed by some other drawContext that has picked
379  // it up. For this reason, the drawTarget should only ever be accessed via 'getDrawTarget'.
380  GrDrawTarget* fDrawTarget;
381  GrContext* fContext;
382  GrInstancedPipelineInfo fInstancedPipelineInfo;
383 
384  sk_sp<SkColorSpace> fColorSpace;
385  SkSurfaceProps fSurfaceProps;
386  GrAuditTrail* fAuditTrail;
387 
388  // In debug builds we guard against improper thread handling
389  SkDEBUGCODE(mutable GrSingleOwner* fSingleOwner;)
390 };
391 
392 #endif
The SkRRect class represents a rounded rect with a potentially different radii for each corner...
Definition: SkRRect.h:48
Definition: SkColorSpace.h:16
The SkPath class encapsulates compound (multiple contour) geometric paths consisting of straight line...
Definition: SkPath.h:27
SkTextBlob combines multiple text runs into an immutable, ref-counted structure.
Definition: SkTextBlob.h:22
Describes a surface to be created.
Definition: GrTypes.h:467
Describes properties and constraints of a given SkSurface.
Definition: SkSurfaceProps.h:51
Definition: SkPoint.h:156
The SkMatrix class holds a 3x3 matrix for transforming coordinates.
Definition: SkMatrix.h:26
Definition: SkRefCnt.h:135
The SkPaint class holds the style and color information about how to draw geometries, text and bitmaps.
Definition: SkPaint.h:46
GrClip is an abstract base class for applying a clip.
Definition: GrClip.h:22
#define SkToBool(cond)
Returns 0 or 1 based on the condition.
Definition: SkTypes.h:287
A compressed form of a rotation+scale matrix.
Definition: SkRSXform.h:20
Definition: GrSurface.h:21
Definition: GrDrawContext.h:51
DEPRECATED - use SkPaintFilterCanvas instead.
Definition: SkDrawFilter.h:26
Definition: GrContext.h:48
uint32_t SkColor
32 bit ARGB color value, not premultiplied.
Definition: SkColor.h:28
The paint describes how color and coverage are computed at each pixel by GrContext draw functions and...
Definition: GrPaint.h:41
Definition: SkRect.h:390
GrRenderTarget represents a 2D buffer of pixels that can be rendered to.
Definition: GrRenderTarget.h:26
SkIRect holds four 32 bit integer coordinates for a rectangle.
Definition: SkRect.h:20
SkIPoint holds two 32 bit integer coordinates.
Definition: SkPoint.h:40