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 3// found in the LICENSE file. 4 5#ifndef SKIA_EXT_ANALYSIS_CANVAS_H_ 6#define SKIA_EXT_ANALYSIS_CANVAS_H_ 7 8#include "base/compiler_specific.h" 9#include "third_party/skia/include/core/SkCanvas.h" 10#include "third_party/skia/include/core/SkPicture.h" 11 12namespace skia { 13 14// Does not render anything, but gathers statistics about a region 15// (specified as a clip rectangle) of an SkPicture as the picture is 16// played back through it. 17// To use: play a picture into the canvas, and then check result. 18class SK_API AnalysisCanvas : public SkCanvas, public SkDrawPictureCallback { 19 public: 20 AnalysisCanvas(int width, int height); 21 virtual ~AnalysisCanvas(); 22 23 // Returns true when a SkColor can be used to represent result. 24 bool GetColorIfSolid(SkColor* color) const; 25 bool HasText() const; 26 27 void SetForceNotSolid(bool flag); 28 void SetForceNotTransparent(bool flag); 29 30 // SkDrawPictureCallback override. 31 virtual bool abortDrawing() OVERRIDE; 32 33 // SkCanvas overrides. 34 virtual void clear(SkColor) OVERRIDE; 35 virtual void drawPaint(const SkPaint& paint) OVERRIDE; 36 virtual void drawPoints(PointMode, 37 size_t count, 38 const SkPoint pts[], 39 const SkPaint&) OVERRIDE; 40 virtual void drawOval(const SkRect&, const SkPaint&) OVERRIDE; 41 virtual void drawRect(const SkRect&, const SkPaint&) OVERRIDE; 42 virtual void drawRRect(const SkRRect&, const SkPaint&) OVERRIDE; 43 virtual void drawPath(const SkPath& path, const SkPaint&) OVERRIDE; 44 virtual void drawBitmap(const SkBitmap&, 45 SkScalar left, 46 SkScalar top, 47 const SkPaint* paint = NULL) OVERRIDE; 48 virtual void drawBitmapRectToRect(const SkBitmap&, 49 const SkRect* src, 50 const SkRect& dst, 51 const SkPaint* paint, 52 DrawBitmapRectFlags flags) OVERRIDE; 53 virtual void drawBitmapMatrix(const SkBitmap&, 54 const SkMatrix&, 55 const SkPaint* paint = NULL) OVERRIDE; 56 virtual void drawBitmapNine(const SkBitmap& bitmap, 57 const SkIRect& center, 58 const SkRect& dst, 59 const SkPaint* paint = NULL) OVERRIDE; 60 virtual void drawSprite(const SkBitmap&, int left, int top, 61 const SkPaint* paint = NULL) OVERRIDE; 62 virtual void drawVertices(VertexMode, 63 int vertexCount, 64 const SkPoint vertices[], 65 const SkPoint texs[], 66 const SkColor colors[], 67 SkXfermode*, 68 const uint16_t indices[], 69 int indexCount, 70 const SkPaint&) OVERRIDE; 71 72 protected: 73 virtual void willSave() OVERRIDE; 74 virtual SaveLayerStrategy willSaveLayer(const SkRect*, 75 const SkPaint*, 76 SaveFlags) OVERRIDE; 77 virtual void willRestore() OVERRIDE; 78 79 virtual void onClipRect(const SkRect& rect, 80 SkRegion::Op op, 81 ClipEdgeStyle edge_style) OVERRIDE; 82 virtual void onClipRRect(const SkRRect& rrect, 83 SkRegion::Op op, 84 ClipEdgeStyle edge_style) OVERRIDE; 85 virtual void onClipPath(const SkPath& path, 86 SkRegion::Op op, 87 ClipEdgeStyle edge_style) OVERRIDE; 88 89 virtual void onDrawText(const void* text, 90 size_t byteLength, 91 SkScalar x, 92 SkScalar y, 93 const SkPaint&) OVERRIDE; 94 virtual void onDrawPosText(const void* text, 95 size_t byteLength, 96 const SkPoint pos[], 97 const SkPaint&) OVERRIDE; 98 virtual void onDrawPosTextH(const void* text, 99 size_t byteLength, 100 const SkScalar xpos[], 101 SkScalar constY, 102 const SkPaint&) OVERRIDE; 103 virtual void onDrawTextOnPath(const void* text, 104 size_t byteLength, 105 const SkPath& path, 106 const SkMatrix* matrix, 107 const SkPaint&) OVERRIDE; 108 virtual void onDrawDRRect(const SkRRect& outer, 109 const SkRRect& inner, 110 const SkPaint&) OVERRIDE; 111 112private: 113 typedef SkCanvas INHERITED; 114 115 int saved_stack_size_; 116 int force_not_solid_stack_level_; 117 int force_not_transparent_stack_level_; 118 119 bool is_forced_not_solid_; 120 bool is_forced_not_transparent_; 121 bool is_solid_color_; 122 SkColor color_; 123 bool is_transparent_; 124 bool has_text_; 125}; 126 127} // namespace skia 128 129#endif // SKIA_EXT_ANALYSIS_CANVAS_H_ 130 131