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/SkBitmapDevice.h"
10 #include "third_party/skia/include/core/SkCanvas.h"
11 #include "third_party/skia/include/core/SkPicture.h"
17 // Does not render anything, but gathers statistics about a region
18 // (specified as a clip rectangle) of an SkPicture as the picture is
19 // played back through it.
20 // To use: create a SkBitmap with kNo_Config, create an AnalysisDevice
21 // using that bitmap, and create an AnalysisCanvas using the device.
22 // Play a picture into the canvas, and then check result.
23 class SK_API AnalysisCanvas : public SkCanvas, public SkDrawPictureCallback {
25 AnalysisCanvas(AnalysisDevice*);
26 virtual ~AnalysisCanvas();
28 // Returns true when a SkColor can be used to represent result.
29 bool GetColorIfSolid(SkColor* color) const;
32 // SkDrawPictureCallback override.
33 virtual bool abortDrawing() OVERRIDE;
35 // SkCanvas overrides.
36 virtual bool clipRect(const SkRect& rect,
37 SkRegion::Op op = SkRegion::kIntersect_Op,
38 bool do_anti_alias = false) OVERRIDE;
39 virtual bool clipPath(const SkPath& path,
40 SkRegion::Op op = SkRegion::kIntersect_Op,
41 bool do_anti_alias = false) OVERRIDE;
42 virtual bool clipRRect(const SkRRect& rrect,
43 SkRegion::Op op = SkRegion::kIntersect_Op,
44 bool do_anti_alias = false) OVERRIDE;
46 virtual int saveLayer(const SkRect* bounds,
48 SkCanvas::SaveFlags flags) OVERRIDE;
49 virtual int save(SaveFlags flags = kMatrixClip_SaveFlag) OVERRIDE;
51 virtual void restore() OVERRIDE;
54 typedef SkCanvas INHERITED;
56 int saved_stack_size_;
57 int force_not_solid_stack_level_;
58 int force_not_transparent_stack_level_;
61 // TODO(robertphillips): Once Skia's SkBaseDevice API is refactored to
62 // remove the bitmap-specific entry points, it might make sense for this
63 // to be derived from SkBaseDevice (rather than SkBitmapDevice)
64 class SK_API AnalysisDevice : public SkBitmapDevice {
66 AnalysisDevice(const SkBitmap& bitmap);
67 virtual ~AnalysisDevice();
69 bool GetColorIfSolid(SkColor* color) const;
72 void SetForceNotSolid(bool flag);
73 void SetForceNotTransparent(bool flag);
76 // SkBaseDevice overrides.
77 virtual void clear(SkColor color) OVERRIDE;
78 virtual void drawPaint(const SkDraw& draw, const SkPaint& paint) OVERRIDE;
79 virtual void drawPoints(const SkDraw& draw,
80 SkCanvas::PointMode mode,
82 const SkPoint points[],
83 const SkPaint& paint) OVERRIDE;
84 virtual void drawRect(const SkDraw& draw,
86 const SkPaint& paint) OVERRIDE;
87 virtual void drawOval(const SkDraw& draw,
89 const SkPaint& paint) OVERRIDE;
90 virtual void drawPath(const SkDraw& draw,
93 const SkMatrix* pre_path_matrix = NULL,
94 bool path_is_mutable = false) OVERRIDE;
95 virtual void drawBitmap(const SkDraw& draw,
96 const SkBitmap& bitmap,
97 const SkMatrix& matrix,
98 const SkPaint& paint) OVERRIDE;
99 virtual void drawSprite(const SkDraw& draw,
100 const SkBitmap& bitmap,
103 const SkPaint& paint) OVERRIDE;
104 virtual void drawBitmapRect(const SkDraw& draw,
105 const SkBitmap& bitmap,
106 const SkRect* src_or_null,
108 const SkPaint& paint,
109 SkCanvas::DrawBitmapRectFlags flags) OVERRIDE;
110 virtual void drawText(const SkDraw& draw,
115 const SkPaint& paint) OVERRIDE;
116 virtual void drawPosText(const SkDraw& draw,
119 const SkScalar pos[],
122 const SkPaint& paint) OVERRIDE;
123 virtual void drawTextOnPath(const SkDraw& draw,
127 const SkMatrix* matrix,
128 const SkPaint& paint) OVERRIDE;
129 #ifdef SK_BUILD_FOR_ANDROID
130 virtual void drawPosTextOnPath(const SkDraw& draw,
134 const SkPaint& paint,
136 const SkMatrix* matrix) OVERRIDE;
138 virtual void drawVertices(const SkDraw& draw,
139 SkCanvas::VertexMode vertex_mode,
141 const SkPoint verts[],
142 const SkPoint texs[],
143 const SkColor colors[],
145 const uint16_t indices[],
147 const SkPaint& paint) OVERRIDE;
148 virtual void drawDevice(const SkDraw& draw,
149 SkBaseDevice* device,
152 const SkPaint& paint) OVERRIDE;
155 typedef SkBitmapDevice INHERITED;
157 bool is_forced_not_solid_;
158 bool is_forced_not_transparent_;
159 bool is_solid_color_;
161 bool is_transparent_;
167 #endif // SKIA_EXT_ANALYSIS_CANVAS_H_