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/SkDrawPictureCallback.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 ~AnalysisCanvas() override
;
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 bool abortDrawing() override
;
32 // SkCanvas overrides.
33 void onDrawPaint(const SkPaint
& paint
) override
;
34 void onDrawPoints(PointMode
,
37 const SkPaint
&) override
;
38 void onDrawOval(const SkRect
&, const SkPaint
&) override
;
39 void onDrawRect(const SkRect
&, const SkPaint
&) override
;
40 void onDrawRRect(const SkRRect
&, const SkPaint
&) override
;
41 void onDrawPath(const SkPath
& path
, const SkPaint
&) override
;
42 void onDrawBitmap(const SkBitmap
&,
45 const SkPaint
* paint
= NULL
) override
;
46 void onDrawBitmapRect(const SkBitmap
&,
50 DrawBitmapRectFlags flags
) override
;
51 void onDrawBitmapNine(const SkBitmap
& bitmap
,
52 const SkIRect
& center
,
54 const SkPaint
* paint
= NULL
) override
;
55 void onDrawSprite(const SkBitmap
&,
58 const SkPaint
* paint
= NULL
) override
;
59 void onDrawVertices(VertexMode
,
61 const SkPoint vertices
[],
63 const SkColor colors
[],
65 const uint16_t indices
[],
67 const SkPaint
&) override
;
70 void willSave() override
;
71 SaveLayerStrategy
willSaveLayer(const SkRect
*,
74 void willRestore() override
;
76 void onClipRect(const SkRect
& rect
,
78 ClipEdgeStyle edge_style
) override
;
79 void onClipRRect(const SkRRect
& rrect
,
81 ClipEdgeStyle edge_style
) override
;
82 void onClipPath(const SkPath
& path
,
84 ClipEdgeStyle edge_style
) override
;
85 void onClipRegion(const SkRegion
& deviceRgn
, SkRegion::Op op
) override
;
87 void onDrawText(const void* text
,
91 const SkPaint
&) override
;
92 void onDrawPosText(const void* text
,
95 const SkPaint
&) override
;
96 void onDrawPosTextH(const void* text
,
98 const SkScalar xpos
[],
100 const SkPaint
&) override
;
101 void onDrawTextOnPath(const void* text
,
104 const SkMatrix
* matrix
,
105 const SkPaint
&) override
;
106 void onDrawTextBlob(const SkTextBlob
* blob
,
109 const SkPaint
& paint
) override
;
110 void onDrawDRRect(const SkRRect
& outer
,
111 const SkRRect
& inner
,
112 const SkPaint
&) override
;
114 void OnComplexClip();
117 typedef SkCanvas INHERITED
;
119 int saved_stack_size_
;
120 int force_not_solid_stack_level_
;
121 int force_not_transparent_stack_level_
;
123 bool is_forced_not_solid_
;
124 bool is_forced_not_transparent_
;
125 bool is_solid_color_
;
127 bool is_transparent_
;
133 #endif // SKIA_EXT_ANALYSIS_CANVAS_H_