1 // 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.
5 #ifndef SKIA_EXT_ANALYSIS_CANVAS_H_
6 #define SKIA_EXT_ANALYSIS_CANVAS_H_
8 #include "base/compiler_specific.h"
9 #include "third_party/skia/include/core/SkCanvas.h"
10 #include "third_party/skia/include/core/SkPicture.h"
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.
18 class SK_API AnalysisCanvas
: public SkCanvas
, public SkDrawPictureCallback
{
20 AnalysisCanvas(int width
, int height
);
21 virtual ~AnalysisCanvas();
23 // Returns true when a SkColor can be used to represent result.
24 bool GetColorIfSolid(SkColor
* color
) const;
26 void SetForceNotSolid(bool flag
);
27 void SetForceNotTransparent(bool flag
);
29 // SkDrawPictureCallback override.
30 virtual bool abortDrawing() override
;
32 // SkCanvas overrides.
33 virtual void clear(SkColor
) override
;
34 virtual void drawPaint(const SkPaint
& paint
) override
;
35 virtual void drawPoints(PointMode
,
38 const SkPaint
&) override
;
39 virtual void drawOval(const SkRect
&, const SkPaint
&) override
;
40 virtual void drawRect(const SkRect
&, const SkPaint
&) override
;
41 virtual void drawRRect(const SkRRect
&, const SkPaint
&) override
;
42 virtual void drawPath(const SkPath
& path
, const SkPaint
&) override
;
43 virtual void drawBitmap(const SkBitmap
&,
46 const SkPaint
* paint
= NULL
) override
;
47 virtual void drawBitmapRectToRect(const SkBitmap
&,
51 DrawBitmapRectFlags flags
) override
;
52 virtual void drawBitmapMatrix(const SkBitmap
&,
54 const SkPaint
* paint
= NULL
) override
;
55 virtual void drawBitmapNine(const SkBitmap
& bitmap
,
56 const SkIRect
& center
,
58 const SkPaint
* paint
= NULL
) override
;
59 virtual void drawSprite(const SkBitmap
&, int left
, int top
,
60 const SkPaint
* paint
= NULL
) override
;
61 virtual void drawVertices(VertexMode
,
63 const SkPoint vertices
[],
65 const SkColor colors
[],
67 const uint16_t indices
[],
69 const SkPaint
&) override
;
72 virtual void willSave() override
;
73 virtual SaveLayerStrategy
willSaveLayer(const SkRect
*,
76 virtual void willRestore() override
;
78 virtual void onClipRect(const SkRect
& rect
,
80 ClipEdgeStyle edge_style
) override
;
81 virtual void onClipRRect(const SkRRect
& rrect
,
83 ClipEdgeStyle edge_style
) override
;
84 virtual void onClipPath(const SkPath
& path
,
86 ClipEdgeStyle edge_style
) override
;
87 virtual void onClipRegion(const SkRegion
& deviceRgn
,
88 SkRegion::Op op
) override
;
90 virtual void onDrawText(const void* text
,
94 const SkPaint
&) override
;
95 virtual void onDrawPosText(const void* text
,
98 const SkPaint
&) override
;
99 virtual void onDrawPosTextH(const void* text
,
101 const SkScalar xpos
[],
103 const SkPaint
&) override
;
104 virtual void onDrawTextOnPath(const void* text
,
107 const SkMatrix
* matrix
,
108 const SkPaint
&) override
;
109 virtual void onDrawTextBlob(const SkTextBlob
* blob
,
112 const SkPaint
& paint
) override
;
113 virtual void onDrawDRRect(const SkRRect
& outer
,
114 const SkRRect
& inner
,
115 const SkPaint
&) override
;
117 void OnComplexClip();
120 typedef SkCanvas INHERITED
;
122 int saved_stack_size_
;
123 int force_not_solid_stack_level_
;
124 int force_not_transparent_stack_level_
;
126 bool is_forced_not_solid_
;
127 bool is_forced_not_transparent_
;
128 bool is_solid_color_
;
130 bool is_transparent_
;
136 #endif // SKIA_EXT_ANALYSIS_CANVAS_H_