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 "SkCanvasVirtualEnforcer.h" 12 #include "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 onDrawRect(const SkRect&, const SkPaint&) override; 29 void onDrawEdgeAARect(const SkRect&, SkCanvas::QuadAAFlags, SkColor, SkBlendMode) 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 onDrawImageSet(const ImageSetEntry[], int count, SkFilterQuality, SkBlendMode) override; 47 void onDrawBitmap(const SkBitmap&, SkScalar, SkScalar, const SkPaint*) override; 48 void onDrawBitmapRect(const SkBitmap&, const SkRect*, const SkRect&, const SkPaint*, 49 SrcRectConstraint) override; 50 void onDrawBitmapNine(const SkBitmap&, const SkIRect&, const SkRect&, const SkPaint*) override; 51 void onDrawBitmapLattice(const SkBitmap&, const Lattice&, const SkRect&, 52 const SkPaint*) override; 53 void onDrawDrawable(SkDrawable*, const SkMatrix*) override; 54 void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override; 55 56 void onDrawAnnotation(const SkRect&, const char key[], SkData* value) override; 57 void onDrawShadowRec(const SkPath&, const SkDrawShadowRec&) override; 58 59 private: 60 void drawPosTextCommon(const SkGlyphID[], int, const SkScalar[], int, const SkPoint&, 61 const SkFont&, const SkPaint&); 62 63 inline SkPaint overdrawPaint(const SkPaint& paint); 64 65 SkPaint fPaint; 66 67 typedef SkCanvasVirtualEnforcer<SkNWayCanvas> INHERITED; 68 }; 69 70 #endif 71