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