blob: f21b8d02cf7933ec921027ffa0ba14662f2bb6dd [file] [log] [blame]
James Robinson646469d2014-10-03 15:33:28 -07001// Copyright (c) 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef SKIA_EXT_ANALYSIS_CANVAS_H_
6#define SKIA_EXT_ANALYSIS_CANVAS_H_
7
8#include "base/compiler_specific.h"
9#include "third_party/skia/include/core/SkCanvas.h"
Adam Barth823f6402015-07-13 12:54:08 -070010#include "third_party/skia/include/core/SkPicture.h"
James Robinson646469d2014-10-03 15:33:28 -070011
12namespace skia {
13
14// Does not render anything, but gathers statistics about a region
15// (specified as a clip rectangle) of an SkPicture as the picture is
16// played back through it.
17// To use: play a picture into the canvas, and then check result.
Adam Barth823f6402015-07-13 12:54:08 -070018class SK_API AnalysisCanvas : public SkCanvas,
19 public SkPicture::AbortCallback {
James Robinson646469d2014-10-03 15:33:28 -070020 public:
21 AnalysisCanvas(int width, int height);
James Robinson675df572014-10-22 17:20:33 -070022 ~AnalysisCanvas() override;
James Robinson646469d2014-10-03 15:33:28 -070023
24 // Returns true when a SkColor can be used to represent result.
25 bool GetColorIfSolid(SkColor* color) const;
26
27 void SetForceNotSolid(bool flag);
28 void SetForceNotTransparent(bool flag);
29
Adam Barth823f6402015-07-13 12:54:08 -070030 // SkPicture::AbortCallback override.
31 bool abort() override;
James Robinson646469d2014-10-03 15:33:28 -070032
33 // SkCanvas overrides.
James Robinsond753aca2015-01-12 13:07:20 -080034 void onDrawPaint(const SkPaint& paint) override;
35 void onDrawPoints(PointMode,
James Robinson675df572014-10-22 17:20:33 -070036 size_t count,
37 const SkPoint pts[],
38 const SkPaint&) override;
James Robinsond753aca2015-01-12 13:07:20 -080039 void onDrawOval(const SkRect&, const SkPaint&) override;
40 void onDrawRect(const SkRect&, const SkPaint&) override;
41 void onDrawRRect(const SkRRect&, const SkPaint&) override;
42 void onDrawPath(const SkPath& path, const SkPaint&) override;
43 void onDrawBitmap(const SkBitmap&,
44 SkScalar left,
45 SkScalar top,
46 const SkPaint* paint = NULL) override;
47 void onDrawBitmapRect(const SkBitmap&,
48 const SkRect* src,
49 const SkRect& dst,
50 const SkPaint* paint,
51 DrawBitmapRectFlags flags) override;
52 void onDrawBitmapNine(const SkBitmap& bitmap,
53 const SkIRect& center,
54 const SkRect& dst,
55 const SkPaint* paint = NULL) override;
56 void onDrawSprite(const SkBitmap&,
57 int left,
58 int top,
59 const SkPaint* paint = NULL) override;
60 void onDrawVertices(VertexMode,
61 int vertexCount,
62 const SkPoint vertices[],
63 const SkPoint texs[],
64 const SkColor colors[],
65 SkXfermode*,
66 const uint16_t indices[],
67 int indexCount,
68 const SkPaint&) override;
James Robinson646469d2014-10-03 15:33:28 -070069
70 protected:
James Robinson675df572014-10-22 17:20:33 -070071 void willSave() override;
72 SaveLayerStrategy willSaveLayer(const SkRect*,
73 const SkPaint*,
74 SaveFlags) override;
75 void willRestore() override;
James Robinson646469d2014-10-03 15:33:28 -070076
James Robinson675df572014-10-22 17:20:33 -070077 void onClipRect(const SkRect& rect,
78 SkRegion::Op op,
79 ClipEdgeStyle edge_style) override;
80 void onClipRRect(const SkRRect& rrect,
81 SkRegion::Op op,
82 ClipEdgeStyle edge_style) override;
83 void onClipPath(const SkPath& path,
84 SkRegion::Op op,
85 ClipEdgeStyle edge_style) override;
86 void onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) override;
James Robinson646469d2014-10-03 15:33:28 -070087
James Robinson675df572014-10-22 17:20:33 -070088 void onDrawText(const void* text,
89 size_t byteLength,
90 SkScalar x,
91 SkScalar y,
92 const SkPaint&) override;
93 void onDrawPosText(const void* text,
94 size_t byteLength,
95 const SkPoint pos[],
96 const SkPaint&) override;
97 void onDrawPosTextH(const void* text,
98 size_t byteLength,
99 const SkScalar xpos[],
100 SkScalar constY,
101 const SkPaint&) override;
102 void onDrawTextOnPath(const void* text,
103 size_t byteLength,
104 const SkPath& path,
105 const SkMatrix* matrix,
106 const SkPaint&) override;
107 void onDrawTextBlob(const SkTextBlob* blob,
108 SkScalar x,
109 SkScalar y,
110 const SkPaint& paint) override;
111 void onDrawDRRect(const SkRRect& outer,
112 const SkRRect& inner,
113 const SkPaint&) override;
James Robinson646469d2014-10-03 15:33:28 -0700114
115 void OnComplexClip();
116
117 private:
118 typedef SkCanvas INHERITED;
119
120 int saved_stack_size_;
121 int force_not_solid_stack_level_;
122 int force_not_transparent_stack_level_;
123
124 bool is_forced_not_solid_;
125 bool is_forced_not_transparent_;
126 bool is_solid_color_;
127 SkColor color_;
128 bool is_transparent_;
129 int draw_op_count_;
130};
131
132} // namespace skia
133
134#endif // SKIA_EXT_ANALYSIS_CANVAS_H_
135