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 "SkNWayCanvas.h" 12 13 /** 14 * Captures all drawing commands. Rather than draw the actual content, this device 15 * increments the alpha channel of each pixel every time it would have been touched 16 * by a draw call. This is useful for detecting overdraw. 17 */ 18 class SkOverdrawCanvas : public SkNWayCanvas { 19 public: 20 /* Does not take ownership of canvas */ 21 SkOverdrawCanvas(SkCanvas*); 22 23 void onDrawText(const void*, size_t, SkScalar, SkScalar, const SkPaint&) override; 24 void onDrawPosText(const void*, size_t, const SkPoint[], const SkPaint&) override; 25 void onDrawPosTextH(const void*, size_t, const SkScalar[], SkScalar, const SkPaint&) override; 26 void onDrawTextOnPath(const void*, size_t, const SkPath&, const SkMatrix*, 27 const SkPaint&) override; 28 void onDrawTextRSXform(const void*, size_t, const SkRSXform[], const SkRect*, 29 const SkPaint&) override; 30 void onDrawTextBlob(const SkTextBlob*, SkScalar, SkScalar, const SkPaint&) override; 31 void onDrawPatch(const SkPoint[12], const SkColor[4], const SkPoint[4], SkBlendMode, 32 const SkPaint&) override; 33 void onDrawPaint(const SkPaint&) override; 34 void onDrawRect(const SkRect&, const SkPaint&) override; 35 void onDrawRegion(const SkRegion&, const SkPaint&) override; 36 void onDrawOval(const SkRect&, const SkPaint&) override; 37 void onDrawArc(const SkRect&, SkScalar, SkScalar, bool, const SkPaint&) override; 38 void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override; 39 void onDrawRRect(const SkRRect&, const SkPaint&) override; 40 void onDrawPoints(PointMode, size_t, const SkPoint[], const SkPaint&) override; 41 void onDrawVerticesObject(const SkVertices*, SkBlendMode, const SkPaint&) override; 42 void onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[], 43 int, SkBlendMode, const SkRect*, const SkPaint*) override; 44 void onDrawPath(const SkPath&, const SkPaint&) override; 45 void onDrawImage(const SkImage*, SkScalar, SkScalar, const SkPaint*) override; 46 void onDrawImageRect(const SkImage*, const SkRect*, const SkRect&, const SkPaint*, 47 SrcRectConstraint) override; 48 void onDrawImageNine(const SkImage*, const SkIRect&, const SkRect&, const SkPaint*) override; 49 void onDrawImageLattice(const SkImage*, const Lattice&, const SkRect&, const SkPaint*) override; 50 void onDrawBitmap(const SkBitmap&, SkScalar, SkScalar, const SkPaint*) override; 51 void onDrawBitmapRect(const SkBitmap&, const SkRect*, const SkRect&, const SkPaint*, 52 SrcRectConstraint) override; 53 void onDrawBitmapNine(const SkBitmap&, const SkIRect&, const SkRect&, const SkPaint*) override; 54 void onDrawBitmapLattice(const SkBitmap&, const Lattice&, const SkRect&, 55 const SkPaint*) override; 56 void onDrawDrawable(SkDrawable*, const SkMatrix*) override; 57 void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override; 58 59 private: 60 void drawPosTextCommon(const void*, size_t, const SkScalar[], int, const SkPoint&, 61 const SkPaint&); 62 63 inline SkPaint overdrawPaint(const SkPaint& paint); 64 65 SkPaint fPaint; 66 67 typedef SkNWayCanvas INHERITED; 68 }; 69 70 #endif 71