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*, SkBlendMode, const SkPaint&) override; |
37 | void onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[], |
38 | int, SkBlendMode, const SkRect*, const SkPaint*) override; |
39 | void onDrawPath(const SkPath&, const SkPaint&) override; |
40 | void onDrawImage(const SkImage*, SkScalar, SkScalar, const SkPaint*) override; |
41 | void onDrawImageRect(const SkImage*, const SkRect*, const SkRect&, const SkPaint*, |
42 | SrcRectConstraint) override; |
43 | void onDrawImageNine(const SkImage*, const SkIRect&, const SkRect&, const SkPaint*) override; |
44 | void onDrawImageLattice(const SkImage*, const Lattice&, const SkRect&, const SkPaint*) override; |
45 | void onDrawDrawable(SkDrawable*, const SkMatrix*) override; |
46 | void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override; |
47 | |
48 | void onDrawAnnotation(const SkRect&, const char key[], SkData* value) override; |
49 | void onDrawShadowRec(const SkPath&, const SkDrawShadowRec&) override; |
50 | |
51 | void onDrawEdgeAAQuad(const SkRect&, const SkPoint[4], SkCanvas::QuadAAFlags, const SkColor4f&, |
52 | SkBlendMode) override; |
53 | void onDrawEdgeAAImageSet(const ImageSetEntry[], int count, const SkPoint[], const SkMatrix[], |
54 | const SkPaint*, SrcRectConstraint) override; |
55 | |
56 | private: |
57 | void drawPosTextCommon(const SkGlyphID[], int, const SkScalar[], int, const SkPoint&, |
58 | const SkFont&, const SkPaint&); |
59 | |
60 | inline SkPaint overdrawPaint(const SkPaint& paint); |
61 | |
62 | SkPaint fPaint; |
63 | |
64 | typedef SkCanvasVirtualEnforcer<SkNWayCanvas> INHERITED; |
65 | }; |
66 | |
67 | #endif |
68 | |