• 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 onDrawPatch(const SkPoint[12], const SkColor[4], const SkPoint[4], SkBlendMode,
26                       const SkPaint&) override;
27      void onDrawPaint(const SkPaint&) override;
28      void onDrawBehind(const SkPaint& paint) override;
29      void onDrawRect(const SkRect&, const SkPaint&) override;
30      void onDrawRegion(const SkRegion&, const SkPaint&) override;
31      void onDrawOval(const SkRect&, const SkPaint&) override;
32      void onDrawArc(const SkRect&, SkScalar, SkScalar, bool, const SkPaint&) override;
33      void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override;
34      void onDrawRRect(const SkRRect&, const SkPaint&) override;
35      void onDrawPoints(PointMode, size_t, const SkPoint[], const SkPaint&) override;
36      void onDrawVerticesObject(const SkVertices*, const SkVertices::Bone bones[], int boneCount,
37                                SkBlendMode, const SkPaint&) override;
38      void onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[],
39                       int, SkBlendMode, const SkRect*, const SkPaint*) override;
40      void onDrawPath(const SkPath&, const SkPaint&) override;
41      void onDrawImage(const SkImage*, SkScalar, SkScalar, const SkPaint*) override;
42      void onDrawImageRect(const SkImage*, const SkRect*, const SkRect&, const SkPaint*,
43                           SrcRectConstraint) override;
44      void onDrawImageNine(const SkImage*, const SkIRect&, const SkRect&, const SkPaint*) override;
45      void onDrawImageLattice(const SkImage*, const Lattice&, const SkRect&, const SkPaint*) override;
46      void onDrawBitmap(const SkBitmap&, SkScalar, SkScalar, const SkPaint*) override;
47      void onDrawBitmapRect(const SkBitmap&, const SkRect*, const SkRect&, const SkPaint*,
48                            SrcRectConstraint) override;
49      void onDrawBitmapNine(const SkBitmap&, const SkIRect&, const SkRect&, const SkPaint*) override;
50      void onDrawBitmapLattice(const SkBitmap&, const Lattice&, const SkRect&,
51                               const SkPaint*) override;
52      void onDrawDrawable(SkDrawable*, const SkMatrix*) override;
53      void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override;
54  
55      void onDrawAnnotation(const SkRect&, const char key[], SkData* value) override;
56      void onDrawShadowRec(const SkPath&, const SkDrawShadowRec&) override;
57  
58      void onDrawEdgeAAQuad(const SkRect&, const SkPoint[4], SkCanvas::QuadAAFlags, SkColor,
59                            SkBlendMode) override;
60      void onDrawEdgeAAImageSet(const ImageSetEntry[], int count, const SkPoint[], const SkMatrix[],
61                                const SkPaint*, SrcRectConstraint) override;
62  
63  private:
64      void drawPosTextCommon(const SkGlyphID[], int, const SkScalar[], int, const SkPoint&,
65                             const SkFont&, const SkPaint&);
66  
67      inline SkPaint overdrawPaint(const SkPaint& paint);
68  
69      SkPaint   fPaint;
70  
71      typedef SkCanvasVirtualEnforcer<SkNWayCanvas> INHERITED;
72  };
73  
74  #endif
75