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;
27 void SetForceNotSolid(bool flag
);
28 void SetForceNotTransparent(bool flag
);
30 // SkDrawPictureCallback override.
31 virtual bool abortDrawing() OVERRIDE
;
33 // SkCanvas overrides.
34 virtual void clear(SkColor
) OVERRIDE
;
35 virtual void drawPaint(const SkPaint
& paint
) OVERRIDE
;
36 virtual void drawPoints(PointMode
,
39 const SkPaint
&) OVERRIDE
;
40 virtual void drawOval(const SkRect
&, const SkPaint
&) OVERRIDE
;
41 virtual void drawRect(const SkRect
&, const SkPaint
&) OVERRIDE
;
42 virtual void drawRRect(const SkRRect
&, const SkPaint
&) OVERRIDE
;
43 virtual void drawPath(const SkPath
& path
, const SkPaint
&) OVERRIDE
;
44 virtual void drawBitmap(const SkBitmap
&,
47 const SkPaint
* paint
= NULL
) OVERRIDE
;
48 virtual void drawBitmapRectToRect(const SkBitmap
&,
52 DrawBitmapRectFlags flags
) OVERRIDE
;
53 virtual void drawBitmapMatrix(const SkBitmap
&,
55 const SkPaint
* paint
= NULL
) OVERRIDE
;
56 virtual void drawBitmapNine(const SkBitmap
& bitmap
,
57 const SkIRect
& center
,
59 const SkPaint
* paint
= NULL
) OVERRIDE
;
60 virtual void drawSprite(const SkBitmap
&, int left
, int top
,
61 const SkPaint
* paint
= NULL
) OVERRIDE
;
62 virtual void drawText(const void* text
,
66 const SkPaint
&) OVERRIDE
;
67 virtual void drawPosText(const void* text
,
70 const SkPaint
&) OVERRIDE
;
71 virtual void drawPosTextH(const void* text
,
73 const SkScalar xpos
[],
75 const SkPaint
&) OVERRIDE
;
76 virtual void drawTextOnPath(const void* text
,
79 const SkMatrix
* matrix
,
80 const SkPaint
&) OVERRIDE
;
81 virtual void drawVertices(VertexMode
,
83 const SkPoint vertices
[],
85 const SkColor colors
[],
87 const uint16_t indices
[],
89 const SkPaint
&) OVERRIDE
;
92 virtual void willSave(SaveFlags
) OVERRIDE
;
93 virtual SaveLayerStrategy
willSaveLayer(const SkRect
*,
96 virtual void willRestore() OVERRIDE
;
98 virtual void onClipRect(const SkRect
& rect
,
100 ClipEdgeStyle edge_style
) OVERRIDE
;
101 virtual void onClipRRect(const SkRRect
& rrect
,
103 ClipEdgeStyle edge_style
) OVERRIDE
;
104 virtual void onClipPath(const SkPath
& path
,
106 ClipEdgeStyle edge_style
) OVERRIDE
;
109 typedef SkCanvas INHERITED
;
111 int saved_stack_size_
;
112 int force_not_solid_stack_level_
;
113 int force_not_transparent_stack_level_
;
115 bool is_forced_not_solid_
;
116 bool is_forced_not_transparent_
;
117 bool is_solid_color_
;
119 bool is_transparent_
;
125 #endif // SKIA_EXT_ANALYSIS_CANVAS_H_