Chromium Code Reviews| 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: |
| 23 AnalysisCanvas(AnalysisDevice*); | 28 AnalysisCanvas(AnalysisDevice*); |
| 24 virtual ~AnalysisCanvas(); | 29 virtual ~AnalysisCanvas(); |
| 25 | 30 |
| 26 // Returns true if the estimated cost of drawing is below an | 31 // Returns true if the estimated cost of drawing is below an |
| 27 // arbitrary threshold. | 32 // arbitrary threshold. |
| 28 bool isCheap() const; | 33 bool isCheap() const; |
| 29 bool getColorIfSolid(SkColor* color) const; | 34 bool getColorIfSolid(SkColor* color) const; |
| 30 bool isTransparent() const; | 35 bool isTransparent() const; |
| 36 void consumeLazyPixelRefs(std::list<LazyPixelRef*>& pixelRefs); | |
|
Tom Hudson
2013/03/18 11:52:39
This name is really unclear to me; "consume" doesn
Sami
2013/03/18 12:14:33
Use a pointer instead of reference (all reference
| |
| 31 | 37 |
| 32 // Returns the estimated cost of drawing, in arbitrary units. | 38 // Returns the estimated cost of drawing, in arbitrary units. |
| 33 int getEstimatedCost() const; | 39 int getEstimatedCost() const; |
| 34 | 40 |
| 35 virtual bool clipRect(const SkRect& rect, | 41 virtual bool clipRect(const SkRect& rect, |
| 36 SkRegion::Op op = SkRegion::kIntersect_Op, | 42 SkRegion::Op op = SkRegion::kIntersect_Op, |
| 37 bool doAntiAlias = false) OVERRIDE; | 43 bool doAntiAlias = false) OVERRIDE; |
| 38 virtual bool clipPath(const SkPath& path, | 44 virtual bool clipPath(const SkPath& path, |
| 39 SkRegion::Op op = SkRegion::kIntersect_Op, | 45 SkRegion::Op op = SkRegion::kIntersect_Op, |
| 40 bool doAntiAlias = false) OVERRIDE; | 46 bool doAntiAlias = false) OVERRIDE; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 58 }; | 64 }; |
| 59 | 65 |
| 60 class SK_API AnalysisDevice : public SkDevice { | 66 class SK_API AnalysisDevice : public SkDevice { |
| 61 public: | 67 public: |
| 62 AnalysisDevice(const SkBitmap& bm); | 68 AnalysisDevice(const SkBitmap& bm); |
| 63 virtual ~AnalysisDevice(); | 69 virtual ~AnalysisDevice(); |
| 64 | 70 |
| 65 int getEstimatedCost() const; | 71 int getEstimatedCost() const; |
| 66 bool getColorIfSolid(SkColor* color) const; | 72 bool getColorIfSolid(SkColor* color) const; |
| 67 bool isTransparent() const; | 73 bool isTransparent() const; |
| 74 void consumeLazyPixelRefs(std::list<LazyPixelRef*>& pixelRefs); | |
| 68 | 75 |
| 69 void setForceNotSolid(bool flag); | 76 void setForceNotSolid(bool flag); |
| 70 void setForceNotTransparent(bool flag); | 77 void setForceNotTransparent(bool flag); |
| 71 | 78 |
| 72 protected: | 79 protected: |
| 73 virtual void clear(SkColor color) OVERRIDE; | 80 virtual void clear(SkColor color) OVERRIDE; |
| 74 virtual void drawPaint(const SkDraw&, const SkPaint& paint) OVERRIDE; | 81 virtual void drawPaint(const SkDraw&, const SkPaint& paint) OVERRIDE; |
| 75 virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, | 82 virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, |
| 76 size_t count, const SkPoint[], | 83 size_t count, const SkPoint[], |
| 77 const SkPaint& paint) OVERRIDE; | 84 const SkPaint& paint) OVERRIDE; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 const SkPoint verts[], const SkPoint texs[], | 120 const SkPoint verts[], const SkPoint texs[], |
| 114 const SkColor colors[], SkXfermode* xmode, | 121 const SkColor colors[], SkXfermode* xmode, |
| 115 const uint16_t indices[], int indexCount, | 122 const uint16_t indices[], int indexCount, |
| 116 const SkPaint& paint) OVERRIDE; | 123 const SkPaint& paint) OVERRIDE; |
| 117 virtual void drawDevice(const SkDraw&, SkDevice*, int x, int y, | 124 virtual void drawDevice(const SkDraw&, SkDevice*, int x, int y, |
| 118 const SkPaint&) OVERRIDE; | 125 const SkPaint&) OVERRIDE; |
| 119 | 126 |
| 120 int estimatedCost_; | 127 int estimatedCost_; |
| 121 | 128 |
| 122 private: | 129 private: |
| 130 | |
| 123 typedef SkDevice INHERITED; | 131 typedef SkDevice INHERITED; |
| 124 | 132 |
| 133 void addPixelRefIfLazy(SkPixelRef* pixelRef); | |
| 134 void addBitmap(const SkBitmap& bitmap); | |
| 135 void addBitmapFromPaint(const SkPaint& paint); | |
| 136 | |
| 125 bool isForcedNotSolid_; | 137 bool isForcedNotSolid_; |
| 126 bool isForcedNotTransparent_; | 138 bool isForcedNotTransparent_; |
| 127 bool isSolidColor_; | 139 bool isSolidColor_; |
| 128 SkColor color_; | 140 SkColor color_; |
| 129 bool isTransparent_; | 141 bool isTransparent_; |
| 142 base::hash_set<uint32_t> existingPixelRefIDs_; | |
|
Sami
2013/03/18 12:14:33
This could be a typedef too.
| |
| 143 std::list<skia::LazyPixelRef*> lazyPixelRefs_; | |
| 130 }; | 144 }; |
| 131 | 145 |
| 132 } // namespace skia | 146 } // namespace skia |
| 133 | 147 |
| 134 #endif // SKIA_EXT_ANALYSIS_CANVAS_H_ | 148 #endif // SKIA_EXT_ANALYSIS_CANVAS_H_ |
| 135 | 149 |
| OLD | NEW |