SkOverdrawCanvas.h 3.7 KB

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