• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016 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 SkOverdrawCanvas_DEFINED
9 #define SkOverdrawCanvas_DEFINED
10 
11 #include "include/core/SkCanvasVirtualEnforcer.h"
12 #include "include/utils/SkNWayCanvas.h"
13 
14 /**
15  *  Captures all drawing commands.  Rather than draw the actual content, this device
16  *  increments the alpha channel of each pixel every time it would have been touched
17  *  by a draw call.  This is useful for detecting overdraw.
18  */
19 class SK_API SkOverdrawCanvas : public SkCanvasVirtualEnforcer<SkNWayCanvas> {
20 public:
21     /* Does not take ownership of canvas */
22     SkOverdrawCanvas(SkCanvas*);
23 
24     void onDrawTextBlob(const SkTextBlob*, SkScalar, SkScalar, const SkPaint&) override;
25     void onDrawGlyphRunList(
26             const sktext::GlyphRunList& glyphRunList, const SkPaint& paint) override;
27     void onDrawPatch(const SkPoint[12], const SkColor[4], const SkPoint[4], SkBlendMode,
28                      const SkPaint&) override;
29     void onDrawPaint(const SkPaint&) override;
30     void onDrawBehind(const SkPaint& paint) override;
31     void onDrawRect(const SkRect&, const SkPaint&) override;
32     void onDrawRegion(const SkRegion&, const SkPaint&) override;
33     void onDrawOval(const SkRect&, const SkPaint&) override;
34     void onDrawArc(const SkRect&, SkScalar, SkScalar, bool, const SkPaint&) override;
35     void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override;
36     void onDrawRRect(const SkRRect&, const SkPaint&) override;
37     void onDrawPoints(PointMode, size_t, const SkPoint[], const SkPaint&) override;
38     void onDrawVerticesObject(const SkVertices*, SkBlendMode, const SkPaint&) override;
39     void onDrawPath(const SkPath&, const SkPaint&) override;
40 
41     void onDrawImage2(const SkImage*, SkScalar, SkScalar, const SkSamplingOptions&,
42                       const SkPaint*) override;
43     void onDrawImageRect2(const SkImage*, const SkRect&, const SkRect&, const SkSamplingOptions&,
44                           const SkPaint*, SrcRectConstraint) override;
45     void onDrawImageLattice2(const SkImage*, const Lattice&, const SkRect&, SkFilterMode,
46                              const SkPaint*) override;
47     void onDrawAtlas2(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[], int,
48                      SkBlendMode, const SkSamplingOptions&, const SkRect*, const SkPaint*) override;
49 
50     void onDrawDrawable(SkDrawable*, const SkMatrix*) override;
51     void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override;
52 
53     void onDrawAnnotation(const SkRect&, const char key[], SkData* value) override;
54     void onDrawShadowRec(const SkPath&, const SkDrawShadowRec&) override;
55 
56     void onDrawEdgeAAQuad(const SkRect&, const SkPoint[4], SkCanvas::QuadAAFlags, const SkColor4f&,
57                           SkBlendMode) override;
58     void onDrawEdgeAAImageSet2(const ImageSetEntry[], int count, const SkPoint[], const SkMatrix[],
59                                const SkSamplingOptions&,const SkPaint*, SrcRectConstraint) override;
60 
61 private:
62     inline SkPaint overdrawPaint(const SkPaint& paint);
63 
64     SkPaint   fPaint;
65 
66     using INHERITED = SkCanvasVirtualEnforcer<SkNWayCanvas>;
67 };
68 
69 #endif
70