| 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 SK_API AnalysisDevice : public SkDevice { | 13 class AnalysisDevice; |
| 14 |
| 15 class AnalysisDevice : public SkDevice { |
| 14 public: | 16 public: |
| 15 AnalysisDevice(const SkBitmap& bm); | 17 AnalysisDevice(const SkBitmap& bm); |
| 18 virtual ~AnalysisDevice(); |
| 19 |
| 20 int getEstimatedCost() const; |
| 21 |
| 22 protected: |
| 23 virtual void clear(SkColor color) OVERRIDE; |
| 24 virtual void drawPaint(const SkDraw&, const SkPaint& paint) OVERRIDE; |
| 25 virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, |
| 26 size_t count, const SkPoint[], |
| 27 const SkPaint& paint) OVERRIDE; |
| 28 virtual void drawRect(const SkDraw&, const SkRect& r, |
| 29 const SkPaint& paint) OVERRIDE; |
| 30 virtual void drawOval(const SkDraw&, const SkRect& oval, |
| 31 const SkPaint& paint) OVERRIDE; |
| 32 virtual void drawPath(const SkDraw&, const SkPath& path, |
| 33 const SkPaint& paint, |
| 34 const SkMatrix* prePathMatrix = NULL, |
| 35 bool pathIsMutable = false) OVERRIDE; |
| 36 virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap, |
| 37 const SkIRect* srcRectOrNull, |
| 38 const SkMatrix& matrix, const SkPaint& paint) |
| 39 OVERRIDE; |
| 40 virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap, |
| 41 int x, int y, const SkPaint& paint) OVERRIDE; |
| 42 virtual void drawBitmapRect(const SkDraw&, const SkBitmap&, |
| 43 const SkRect* srcOrNull, const SkRect& dst, |
| 44 const SkPaint& paint) OVERRIDE; |
| 45 virtual void drawText(const SkDraw&, const void* text, size_t len, |
| 46 SkScalar x, SkScalar y, const SkPaint& paint) |
| 47 OVERRIDE; |
| 48 virtual void drawPosText(const SkDraw& draw, const void* text, size_t len, |
| 49 const SkScalar pos[], SkScalar constY, |
| 50 int scalarsPerPos, const SkPaint& paint) OVERRIDE; |
| 51 virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len, |
| 52 const SkPath& path, const SkMatrix* matrix, |
| 53 const SkPaint& paint) OVERRIDE; |
| 54 #ifdef SK_BUILD_FOR_ANDROID |
| 55 virtual void drawPosTextOnPath(const SkDraw& draw, const void* text, |
| 56 size_t len, |
| 57 const SkPoint pos[], const SkPaint& paint, |
| 58 const SkPath& path, const SkMatrix* matrix) |
| 59 OVERRIDE; |
| 60 #endif |
| 61 virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, |
| 62 int vertexCount, |
| 63 const SkPoint verts[], const SkPoint texs[], |
| 64 const SkColor colors[], SkXfermode* xmode, |
| 65 const uint16_t indices[], int indexCount, |
| 66 const SkPaint& paint) OVERRIDE; |
| 67 virtual void drawDevice(const SkDraw&, SkDevice*, int x, int y, |
| 68 const SkPaint&) OVERRIDE; |
| 69 |
| 70 int estimatedCost_; |
| 16 }; | 71 }; |
| 17 | 72 |
| 18 // Does not render anything, but gathers statistics about a region | 73 // Does not render anything, but gathers statistics about a region |
| 19 // (specified as a clip rectangle) of an SkPicture as the picture is | 74 // (specified as a clip rectangle) of an SkPicture as the picture is |
| 20 // played back through it. | 75 // played back through it. |
| 21 class SK_API AnalysisCanvas : public SkCanvas { | 76 class SK_API AnalysisCanvas : public SkCanvas { |
| 22 public: | 77 public: |
| 23 AnalysisCanvas(SkDevice*, SkRect clip); | 78 AnalysisCanvas(AnalysisDevice*); |
| 24 virtual ~AnalysisCanvas(); | 79 virtual ~AnalysisCanvas(); |
| 25 | 80 |
| 26 virtual int save(SkCanvas::SaveFlags = kMatrixClip_SaveFlag) SK_OVERRIDE; | 81 // Creates a canvas and its supporting data structures. |
| 27 virtual int saveLayer(const SkRect*, const SkPaint*, | 82 //static AnalysisCanvas* Create(int width, int height); |
| 28 SkCanvas::SaveFlags = kARGB_ClipLayer_SaveFlag) | |
| 29 SK_OVERRIDE; | |
| 30 virtual void restore() SK_OVERRIDE; | |
| 31 virtual bool clipRect(const SkRect&, SkRegion::Op, bool) SK_OVERRIDE; | |
| 32 virtual bool clipRRect(const SkRRect&, SkRegion::Op, bool) SK_OVERRIDE; | |
| 33 virtual bool clipPath(const SkPath&, SkRegion::Op, bool) SK_OVERRIDE; | |
| 34 virtual bool clipRegion(const SkRegion&, SkRegion::Op) SK_OVERRIDE; | |
| 35 virtual void clear(SkColor) SK_OVERRIDE; | |
| 36 virtual void drawPaint(const SkPaint&) SK_OVERRIDE; | |
| 37 virtual void drawPoints(PointMode, size_t, const SkPoint [], | |
| 38 const SkPaint&) SK_OVERRIDE; | |
| 39 virtual void drawRect(const SkRect&, const SkPaint&) SK_OVERRIDE; | |
| 40 virtual void drawOval(const SkRect&, const SkPaint&) SK_OVERRIDE; | |
| 41 virtual void drawRRect(const SkRRect&, const SkPaint&) SK_OVERRIDE; | |
| 42 virtual void drawPath(const SkPath&, const SkPaint&) SK_OVERRIDE; | |
| 43 virtual void drawBitmap(const SkBitmap&, SkScalar, SkScalar, | |
| 44 const SkPaint&) SK_OVERRIDE; | |
| 45 virtual void drawBitmapRectToRect(const SkBitmap&, const SkRect*, | |
| 46 const SkRect&, const SkPaint* = NULL) | |
| 47 SK_OVERRIDE; | |
| 48 virtual void drawBitmapMatrix(const SkBitmap&, const SkMatrix&, | |
| 49 const SkPaint* = NULL) SK_OVERRIDE; | |
| 50 virtual void drawBitmapNine(const SkBitmap&, const SkIRect&, const SkRect&, | |
| 51 const SkPaint* = NULL) SK_OVERRIDE; | |
| 52 virtual void drawSprite(const SkBitmap&, int left, int top, | |
| 53 const SkPaint* = NULL) SK_OVERRIDE; | |
| 54 virtual void drawText(const void*, size_t, SkScalar, SkScalar, | |
| 55 const SkPaint&) SK_OVERRIDE; | |
| 56 virtual void drawPosText(const void*, size_t, const SkPoint [], | |
| 57 const SkPaint&) SK_OVERRIDE; | |
| 58 virtual void drawPosTextH(const void*, size_t, const SkScalar [], SkScalar, | |
| 59 const SkPaint&) SK_OVERRIDE; | |
| 60 virtual void drawTextOnPath(const void*, size_t, const SkPath&, | |
| 61 const SkMatrix*, const SkPaint&) SK_OVERRIDE; | |
| 62 virtual void drawVertices(VertexMode, int, const SkPoint [], | |
| 63 const SkPoint [], const SkColor [], SkXfermode*, | |
| 64 const uint16_t [], int, const SkPaint&) SK_OVERRIDE; | |
| 65 virtual void drawData(const void*, size_t) SK_OVERRIDE; | |
| 66 | 83 |
| 67 // Returns true if the estimated cost of drawing is below an | 84 // Returns true if the estimated cost of drawing is below an |
| 68 // arbitrary threshold. | 85 // arbitrary threshold. |
| 69 bool isCheap() const; | 86 bool isCheap() const; |
| 70 | 87 |
| 71 // Returns the estimated cost of drawing, in arbitrary units. | 88 // Returns the estimated cost of drawing, in arbitrary units. |
| 72 int getEstimatedCost() const; | 89 int getEstimatedCost() const; |
| 73 | 90 |
| 74 // Resets the clip and the cost estimate. | 91 virtual bool clipRect(const SkRect& rect, |
| 75 void reset(SkRect clip); | 92 SkRegion::Op op = SkRegion::kIntersect_Op, |
| 93 bool doAntiAlias = false) OVERRIDE; |
| 94 virtual bool clipPath(const SkPath& path, |
| 95 SkRegion::Op op = SkRegion::kIntersect_Op, |
| 96 bool doAntiAlias = false) OVERRIDE; |
| 97 virtual bool clipRRect(const SkRRect& rrect, |
| 98 SkRegion::Op op = SkRegion::kIntersect_Op, |
| 99 bool doAntiAlias = false) OVERRIDE; |
| 76 | 100 |
| 77 protected: | 101 virtual int saveLayer(const SkRect* bounds, const SkPaint*, |
| 78 | 102 SkCanvas::SaveFlags flags) OVERRIDE; |
| 79 int estimatedCost_; | |
| 80 SkRect clip_; | |
| 81 | |
| 82 }; | 103 }; |
| 83 | 104 |
| 84 } // namespace skia | 105 } // namespace skia |
| 85 | 106 |
| 86 #endif // SKIA_EXT_ANALYSIS_CANVAS_H_ | 107 #endif // SKIA_EXT_ANALYSIS_CANVAS_H_ |
| 87 | 108 |
| OLD | NEW |