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 "third_party/skia/include/core/SkCanvas.h" | 8 #include "third_party/skia/include/core/SkCanvas.h" |
9 #include "third_party/skia/include/core/SkDevice.h" | 9 #include "third_party/skia/include/core/SkDevice.h" |
10 | 10 |
11 namespace skia { | 11 namespace skia { |
12 | 12 |
13 class AnalysisDevice; | 13 class AnalysisDevice; |
14 | 14 |
15 // Does not render anything, but gathers statistics about a region | 15 // Does not render anything, but gathers statistics about a region |
16 // (specified as a clip rectangle) of an SkPicture as the picture is | 16 // (specified as a clip rectangle) of an SkPicture as the picture is |
17 // played back through it. | 17 // played back through it. |
18 // To use: create a SkBitmap with kNo_Config, create an AnalysisDevice | 18 // To use: create a SkBitmap with kNo_Config, create an AnalysisDevice |
19 // using that bitmap, and create an AnalysisCanvas using the device. | 19 // using that bitmap, and create an AnalysisCanvas using the device. |
20 // Play a picture into the canvas, and then check isCheap(). | 20 // Play a picture into the canvas, and then check isCheap(). |
21 class SK_API AnalysisCanvas : public SkCanvas { | 21 class SK_API AnalysisCanvas : public SkCanvas { |
22 public: | 22 public: |
23 AnalysisCanvas(AnalysisDevice*); | 23 AnalysisCanvas(AnalysisDevice*); |
24 virtual ~AnalysisCanvas(); | 24 virtual ~AnalysisCanvas(); |
25 | 25 |
26 // Returns true if the estimated cost of drawing is below an | 26 // Returns true if the estimated cost of drawing is below an |
27 // arbitrary threshold. | 27 // arbitrary threshold. |
28 bool isCheap() const; | 28 bool isCheap() const; |
| 29 bool getColorIfSolid(SkColor* color) const; |
| 30 bool isTransparent() const; |
29 | 31 |
30 // Returns the estimated cost of drawing, in arbitrary units. | 32 // Returns the estimated cost of drawing, in arbitrary units. |
31 int getEstimatedCost() const; | 33 int getEstimatedCost() const; |
32 | 34 |
33 virtual bool clipRect(const SkRect& rect, | 35 virtual bool clipRect(const SkRect& rect, |
34 SkRegion::Op op = SkRegion::kIntersect_Op, | 36 SkRegion::Op op = SkRegion::kIntersect_Op, |
35 bool doAntiAlias = false) OVERRIDE; | 37 bool doAntiAlias = false) OVERRIDE; |
36 virtual bool clipPath(const SkPath& path, | 38 virtual bool clipPath(const SkPath& path, |
37 SkRegion::Op op = SkRegion::kIntersect_Op, | 39 SkRegion::Op op = SkRegion::kIntersect_Op, |
38 bool doAntiAlias = false) OVERRIDE; | 40 bool doAntiAlias = false) OVERRIDE; |
39 virtual bool clipRRect(const SkRRect& rrect, | 41 virtual bool clipRRect(const SkRRect& rrect, |
40 SkRegion::Op op = SkRegion::kIntersect_Op, | 42 SkRegion::Op op = SkRegion::kIntersect_Op, |
41 bool doAntiAlias = false) OVERRIDE; | 43 bool doAntiAlias = false) OVERRIDE; |
42 | 44 |
43 virtual int saveLayer(const SkRect* bounds, const SkPaint*, | 45 virtual int saveLayer(const SkRect* bounds, const SkPaint*, |
44 SkCanvas::SaveFlags flags) OVERRIDE; | 46 SkCanvas::SaveFlags flags) OVERRIDE; |
| 47 virtual int save(SaveFlags flags = kMatrixClip_SaveFlag) OVERRIDE; |
| 48 |
| 49 virtual void restore() OVERRIDE; |
| 50 |
45 private: | 51 private: |
46 typedef SkCanvas INHERITED; | 52 typedef SkCanvas INHERITED; |
| 53 static const int kNoLayer; |
| 54 |
| 55 int savedStackSize_; |
| 56 int forceNotSolidStackLevel_; |
| 57 int forceNotTransparentStackLevel_; |
47 }; | 58 }; |
48 | 59 |
49 class SK_API AnalysisDevice : public SkDevice { | 60 class SK_API AnalysisDevice : public SkDevice { |
50 public: | 61 public: |
51 AnalysisDevice(const SkBitmap& bm); | 62 AnalysisDevice(const SkBitmap& bm); |
52 virtual ~AnalysisDevice(); | 63 virtual ~AnalysisDevice(); |
53 | 64 |
54 int getEstimatedCost() const; | 65 int getEstimatedCost() const; |
| 66 bool getColorIfSolid(SkColor* color) const; |
| 67 bool isTransparent() const; |
| 68 |
| 69 void setForceNotSolid(bool flag); |
| 70 void setForceNotTransparent(bool flag); |
55 | 71 |
56 protected: | 72 protected: |
57 virtual void clear(SkColor color) OVERRIDE; | 73 virtual void clear(SkColor color) OVERRIDE; |
58 virtual void drawPaint(const SkDraw&, const SkPaint& paint) OVERRIDE; | 74 virtual void drawPaint(const SkDraw&, const SkPaint& paint) OVERRIDE; |
59 virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, | 75 virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, |
60 size_t count, const SkPoint[], | 76 size_t count, const SkPoint[], |
61 const SkPaint& paint) OVERRIDE; | 77 const SkPaint& paint) OVERRIDE; |
62 virtual void drawRect(const SkDraw&, const SkRect& r, | 78 virtual void drawRect(const SkDraw&, const SkRect& r, |
63 const SkPaint& paint) OVERRIDE; | 79 const SkPaint& paint) OVERRIDE; |
64 virtual void drawOval(const SkDraw&, const SkRect& oval, | 80 virtual void drawOval(const SkDraw&, const SkRect& oval, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 const SkColor colors[], SkXfermode* xmode, | 114 const SkColor colors[], SkXfermode* xmode, |
99 const uint16_t indices[], int indexCount, | 115 const uint16_t indices[], int indexCount, |
100 const SkPaint& paint) OVERRIDE; | 116 const SkPaint& paint) OVERRIDE; |
101 virtual void drawDevice(const SkDraw&, SkDevice*, int x, int y, | 117 virtual void drawDevice(const SkDraw&, SkDevice*, int x, int y, |
102 const SkPaint&) OVERRIDE; | 118 const SkPaint&) OVERRIDE; |
103 | 119 |
104 int estimatedCost_; | 120 int estimatedCost_; |
105 | 121 |
106 private: | 122 private: |
107 typedef SkDevice INHERITED; | 123 typedef SkDevice INHERITED; |
| 124 |
| 125 bool isForcedNotSolid_; |
| 126 bool isForcedNotTransparent_; |
| 127 bool isSolidColor_; |
| 128 SkColor color_; |
| 129 bool isTransparent_; |
108 }; | 130 }; |
109 | 131 |
110 } // namespace skia | 132 } // namespace skia |
111 | 133 |
112 #endif // SKIA_EXT_ANALYSIS_CANVAS_H_ | 134 #endif // SKIA_EXT_ANALYSIS_CANVAS_H_ |
113 | 135 |
OLD | NEW |