OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef SKIA_EXT_ANALYSIS_CANVAS_H_ | 5 #ifndef SKIA_EXT_ANALYSIS_CANVAS_H_ |
6 #define SKIA_EXT_ANALYSIS_CANVAS_H_ | 6 #define SKIA_EXT_ANALYSIS_CANVAS_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "third_party/skia/include/core/SkBitmapDevice.h" | 9 #include "third_party/skia/include/core/SkBitmapDevice.h" |
10 #include "third_party/skia/include/core/SkCanvas.h" | 10 #include "third_party/skia/include/core/SkCanvas.h" |
11 #include "third_party/skia/include/core/SkPicture.h" | 11 #include "third_party/skia/include/core/SkPicture.h" |
12 | 12 |
13 namespace skia { | 13 namespace skia { |
14 | 14 |
15 class AnalysisDevice; | 15 class AnalysisDevice; |
16 | 16 |
17 // Does not render anything, but gathers statistics about a region | 17 // Does not render anything, but gathers statistics about a region |
18 // (specified as a clip rectangle) of an SkPicture as the picture is | 18 // (specified as a clip rectangle) of an SkPicture as the picture is |
19 // played back through it. | 19 // played back through it. |
20 // To use: create a SkBitmap with kNo_Config, create an AnalysisDevice | 20 // To use: create a SkBitmap with kNo_Config, create an AnalysisDevice |
21 // using that bitmap, and create an AnalysisCanvas using the device. | 21 // using that bitmap, and create an AnalysisCanvas using the device. |
22 // Play a picture into the canvas, and then check result. | 22 // Play a picture into the canvas, and then check result. |
23 class SK_API AnalysisCanvas : public SkCanvas { | 23 class SK_API AnalysisCanvas : public SkCanvas, public SkDrawPictureCallback { |
24 public: | 24 public: |
25 explicit AnalysisCanvas(AnalysisDevice* device); | 25 AnalysisCanvas(AnalysisDevice*); |
26 virtual ~AnalysisCanvas(); | 26 virtual ~AnalysisCanvas(); |
27 | 27 |
28 // Returns true when a SkColor can be used to represent result. | 28 // Returns true when a SkColor can be used to represent result. |
29 bool GetColorIfSolid(SkColor* color) const; | 29 bool GetColorIfSolid(SkColor* color) const; |
30 bool HasText() const; | 30 bool HasText() const; |
31 | 31 |
| 32 // SkDrawPictureCallback override. |
| 33 virtual bool abortDrawing() OVERRIDE; |
| 34 |
32 // SkCanvas overrides. | 35 // SkCanvas overrides. |
33 virtual bool clipRect(const SkRect& rect, | 36 virtual bool clipRect(const SkRect& rect, |
34 SkRegion::Op op = SkRegion::kIntersect_Op, | 37 SkRegion::Op op = SkRegion::kIntersect_Op, |
35 bool do_anti_alias = false) OVERRIDE; | 38 bool do_anti_alias = false) OVERRIDE; |
36 virtual bool clipPath(const SkPath& path, | 39 virtual bool clipPath(const SkPath& path, |
37 SkRegion::Op op = SkRegion::kIntersect_Op, | 40 SkRegion::Op op = SkRegion::kIntersect_Op, |
38 bool do_anti_alias = false) OVERRIDE; | 41 bool do_anti_alias = false) OVERRIDE; |
39 virtual bool clipRRect(const SkRRect& rrect, | 42 virtual bool clipRRect(const SkRRect& rrect, |
40 SkRegion::Op op = SkRegion::kIntersect_Op, | 43 SkRegion::Op op = SkRegion::kIntersect_Op, |
41 bool do_anti_alias = false) OVERRIDE; | 44 bool do_anti_alias = false) OVERRIDE; |
(...skipping 11 matching lines...) Expand all Loading... |
53 int saved_stack_size_; | 56 int saved_stack_size_; |
54 int force_not_solid_stack_level_; | 57 int force_not_solid_stack_level_; |
55 int force_not_transparent_stack_level_; | 58 int force_not_transparent_stack_level_; |
56 }; | 59 }; |
57 | 60 |
58 // TODO(robertphillips): Once Skia's SkBaseDevice API is refactored to | 61 // TODO(robertphillips): Once Skia's SkBaseDevice API is refactored to |
59 // remove the bitmap-specific entry points, it might make sense for this | 62 // remove the bitmap-specific entry points, it might make sense for this |
60 // to be derived from SkBaseDevice (rather than SkBitmapDevice) | 63 // to be derived from SkBaseDevice (rather than SkBitmapDevice) |
61 class SK_API AnalysisDevice : public SkBitmapDevice { | 64 class SK_API AnalysisDevice : public SkBitmapDevice { |
62 public: | 65 public: |
63 // |analysis_rect| is in device space. | |
64 AnalysisDevice(const SkBitmap& bitmap, SkRect analysis_rect); | |
65 // Analyze the entire bitmap. | |
66 AnalysisDevice(const SkBitmap& bitmap); | 66 AnalysisDevice(const SkBitmap& bitmap); |
67 virtual ~AnalysisDevice(); | 67 virtual ~AnalysisDevice(); |
68 | 68 |
69 bool GetColorIfSolid(SkColor* color) const; | 69 bool GetColorIfSolid(SkColor* color) const; |
70 bool HasText() const; | 70 bool HasText() const; |
71 | 71 |
72 void SetForceNotSolid(bool flag); | 72 void SetForceNotSolid(bool flag); |
73 void SetForceNotTransparent(bool flag); | 73 void SetForceNotTransparent(bool flag); |
74 | 74 |
75 SkRect AnalysisRect() const { return analysis_rect_; } | |
76 | |
77 protected: | 75 protected: |
78 // SkBaseDevice overrides. | 76 // SkBaseDevice overrides. |
79 virtual void clear(SkColor color) OVERRIDE; | 77 virtual void clear(SkColor color) OVERRIDE; |
80 virtual void drawPaint(const SkDraw& draw, const SkPaint& paint) OVERRIDE; | 78 virtual void drawPaint(const SkDraw& draw, const SkPaint& paint) OVERRIDE; |
81 virtual void drawPoints(const SkDraw& draw, | 79 virtual void drawPoints(const SkDraw& draw, |
82 SkCanvas::PointMode mode, | 80 SkCanvas::PointMode mode, |
83 size_t count, | 81 size_t count, |
84 const SkPoint points[], | 82 const SkPoint points[], |
85 const SkPaint& paint) OVERRIDE; | 83 const SkPaint& paint) OVERRIDE; |
86 virtual void drawRect(const SkDraw& draw, | 84 virtual void drawRect(const SkDraw& draw, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 const SkPaint& paint) OVERRIDE; | 150 const SkPaint& paint) OVERRIDE; |
153 virtual void drawDevice(const SkDraw& draw, | 151 virtual void drawDevice(const SkDraw& draw, |
154 SkBaseDevice* device, | 152 SkBaseDevice* device, |
155 int x, | 153 int x, |
156 int y, | 154 int y, |
157 const SkPaint& paint) OVERRIDE; | 155 const SkPaint& paint) OVERRIDE; |
158 | 156 |
159 private: | 157 private: |
160 typedef SkBitmapDevice INHERITED; | 158 typedef SkBitmapDevice INHERITED; |
161 | 159 |
162 SkRect analysis_rect_; | |
163 bool is_forced_not_solid_; | 160 bool is_forced_not_solid_; |
164 bool is_forced_not_transparent_; | 161 bool is_forced_not_transparent_; |
165 bool is_solid_color_; | 162 bool is_solid_color_; |
166 SkColor color_; | 163 SkColor color_; |
167 bool is_transparent_; | 164 bool is_transparent_; |
168 bool has_text_; | 165 bool has_text_; |
169 }; | 166 }; |
170 | 167 |
171 } // namespace skia | 168 } // namespace skia |
172 | 169 |
173 #endif // SKIA_EXT_ANALYSIS_CANVAS_H_ | 170 #endif // SKIA_EXT_ANALYSIS_CANVAS_H_ |
174 | 171 |
OLD | NEW |