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 <list> |
| 9 #include <set> |
| 10 |
| 11 #include "base/hash_tables.h" |
| 12 #include "skia/ext/lazy_pixel_ref.h" |
8 #include "third_party/skia/include/core/SkCanvas.h" | 13 #include "third_party/skia/include/core/SkCanvas.h" |
9 #include "third_party/skia/include/core/SkDevice.h" | 14 #include "third_party/skia/include/core/SkDevice.h" |
10 | 15 |
11 namespace skia { | 16 namespace skia { |
12 | 17 |
13 class AnalysisDevice; | 18 class AnalysisDevice; |
14 | 19 |
15 // Does not render anything, but gathers statistics about a region | 20 // Does not render anything, but gathers statistics about a region |
16 // (specified as a clip rectangle) of an SkPicture as the picture is | 21 // (specified as a clip rectangle) of an SkPicture as the picture is |
17 // played back through it. | 22 // played back through it. |
18 // To use: create a SkBitmap with kNo_Config, create an AnalysisDevice | 23 // To use: create a SkBitmap with kNo_Config, create an AnalysisDevice |
19 // using that bitmap, and create an AnalysisCanvas using the device. | 24 // using that bitmap, and create an AnalysisCanvas using the device. |
20 // Play a picture into the canvas, and then check isCheap(). | 25 // Play a picture into the canvas, and then check isCheap(). |
21 class SK_API AnalysisCanvas : public SkCanvas { | 26 class SK_API AnalysisCanvas : public SkCanvas { |
22 public: | 27 public: |
| 28 typedef std::list<skia::LazyPixelRef*> LazyPixelRefList; |
| 29 |
23 AnalysisCanvas(AnalysisDevice*); | 30 AnalysisCanvas(AnalysisDevice*); |
24 virtual ~AnalysisCanvas(); | 31 virtual ~AnalysisCanvas(); |
25 | 32 |
26 // Returns true if the estimated cost of drawing is below an | 33 // Returns true if the estimated cost of drawing is below an |
27 // arbitrary threshold. | 34 // arbitrary threshold. |
28 bool isCheap() const; | 35 bool isCheap() const; |
29 bool getColorIfSolid(SkColor* color) const; | 36 bool getColorIfSolid(SkColor* color) const; |
30 bool isTransparent() const; | 37 bool isTransparent() const; |
| 38 void consumeLazyPixelRefs(LazyPixelRefList* pixelRefs); |
31 | 39 |
32 // Returns the estimated cost of drawing, in arbitrary units. | 40 // Returns the estimated cost of drawing, in arbitrary units. |
33 int getEstimatedCost() const; | 41 int getEstimatedCost() const; |
34 | 42 |
35 virtual bool clipRect(const SkRect& rect, | 43 virtual bool clipRect(const SkRect& rect, |
36 SkRegion::Op op = SkRegion::kIntersect_Op, | 44 SkRegion::Op op = SkRegion::kIntersect_Op, |
37 bool doAntiAlias = false) OVERRIDE; | 45 bool doAntiAlias = false) OVERRIDE; |
38 virtual bool clipPath(const SkPath& path, | 46 virtual bool clipPath(const SkPath& path, |
39 SkRegion::Op op = SkRegion::kIntersect_Op, | 47 SkRegion::Op op = SkRegion::kIntersect_Op, |
40 bool doAntiAlias = false) OVERRIDE; | 48 bool doAntiAlias = false) OVERRIDE; |
(...skipping 11 matching lines...) Expand all Loading... |
52 typedef SkCanvas INHERITED; | 60 typedef SkCanvas INHERITED; |
53 static const int kNoLayer; | 61 static const int kNoLayer; |
54 | 62 |
55 int savedStackSize_; | 63 int savedStackSize_; |
56 int forceNotSolidStackLevel_; | 64 int forceNotSolidStackLevel_; |
57 int forceNotTransparentStackLevel_; | 65 int forceNotTransparentStackLevel_; |
58 }; | 66 }; |
59 | 67 |
60 class SK_API AnalysisDevice : public SkDevice { | 68 class SK_API AnalysisDevice : public SkDevice { |
61 public: | 69 public: |
| 70 typedef std::list<skia::LazyPixelRef*> LazyPixelRefList; |
| 71 typedef base::hash_set<uint32_t> IdSet; |
| 72 |
62 AnalysisDevice(const SkBitmap& bm); | 73 AnalysisDevice(const SkBitmap& bm); |
63 virtual ~AnalysisDevice(); | 74 virtual ~AnalysisDevice(); |
64 | 75 |
65 int getEstimatedCost() const; | 76 int getEstimatedCost() const; |
66 bool getColorIfSolid(SkColor* color) const; | 77 bool getColorIfSolid(SkColor* color) const; |
67 bool isTransparent() const; | 78 bool isTransparent() const; |
| 79 void consumeLazyPixelRefs(LazyPixelRefList* pixelRefs); |
68 | 80 |
69 void setForceNotSolid(bool flag); | 81 void setForceNotSolid(bool flag); |
70 void setForceNotTransparent(bool flag); | 82 void setForceNotTransparent(bool flag); |
71 | 83 |
72 protected: | 84 protected: |
73 virtual void clear(SkColor color) OVERRIDE; | 85 virtual void clear(SkColor color) OVERRIDE; |
74 virtual void drawPaint(const SkDraw&, const SkPaint& paint) OVERRIDE; | 86 virtual void drawPaint(const SkDraw&, const SkPaint& paint) OVERRIDE; |
75 virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, | 87 virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, |
76 size_t count, const SkPoint[], | 88 size_t count, const SkPoint[], |
77 const SkPaint& paint) OVERRIDE; | 89 const SkPaint& paint) OVERRIDE; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 const SkPoint verts[], const SkPoint texs[], | 125 const SkPoint verts[], const SkPoint texs[], |
114 const SkColor colors[], SkXfermode* xmode, | 126 const SkColor colors[], SkXfermode* xmode, |
115 const uint16_t indices[], int indexCount, | 127 const uint16_t indices[], int indexCount, |
116 const SkPaint& paint) OVERRIDE; | 128 const SkPaint& paint) OVERRIDE; |
117 virtual void drawDevice(const SkDraw&, SkDevice*, int x, int y, | 129 virtual void drawDevice(const SkDraw&, SkDevice*, int x, int y, |
118 const SkPaint&) OVERRIDE; | 130 const SkPaint&) OVERRIDE; |
119 | 131 |
120 int estimatedCost_; | 132 int estimatedCost_; |
121 | 133 |
122 private: | 134 private: |
| 135 |
123 typedef SkDevice INHERITED; | 136 typedef SkDevice INHERITED; |
124 | 137 |
| 138 void addPixelRefIfLazy(SkPixelRef* pixelRef); |
| 139 void addBitmap(const SkBitmap& bitmap); |
| 140 void addBitmapFromPaint(const SkPaint& paint); |
| 141 |
125 bool isForcedNotSolid_; | 142 bool isForcedNotSolid_; |
126 bool isForcedNotTransparent_; | 143 bool isForcedNotTransparent_; |
127 bool isSolidColor_; | 144 bool isSolidColor_; |
128 SkColor color_; | 145 SkColor color_; |
129 bool isTransparent_; | 146 bool isTransparent_; |
| 147 IdSet existingPixelRefIDs_; |
| 148 LazyPixelRefList lazyPixelRefs_; |
130 }; | 149 }; |
131 | 150 |
132 } // namespace skia | 151 } // namespace skia |
133 | 152 |
134 #endif // SKIA_EXT_ANALYSIS_CANVAS_H_ | 153 #endif // SKIA_EXT_ANALYSIS_CANVAS_H_ |
135 | 154 |
OLD | NEW |