1/* 2 * Copyright (C) 2013 Google Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above 11 * copyright notice, this list of conditions and the following disclaimer 12 * in the documentation and/or other materials provided with the 13 * distribution. 14 * * Neither the name of Google Inc. nor the names of its 15 * contributors may be used to endorse or promote products derived from 16 * this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31#ifndef LoggingCanvas_h 32#define LoggingCanvas_h 33 34#include "platform/JSONValues.h" 35#include "platform/graphics/InterceptingCanvas.h" 36 37namespace blink { 38 39class LoggingCanvas : public InterceptingCanvas { 40public: 41 LoggingCanvas(int width, int height); 42 PassRefPtr<JSONArray> log(); 43 44 virtual void clear(SkColor) OVERRIDE; 45 virtual void drawPaint(const SkPaint&) OVERRIDE; 46 virtual void drawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&) OVERRIDE; 47 virtual void drawRect(const SkRect&, const SkPaint&) OVERRIDE; 48 virtual void drawOval(const SkRect&, const SkPaint&) OVERRIDE; 49 virtual void drawRRect(const SkRRect&, const SkPaint&) OVERRIDE; 50 virtual void drawPath(const SkPath&, const SkPaint&) OVERRIDE; 51 virtual void drawBitmap(const SkBitmap&, SkScalar left, SkScalar top, const SkPaint* = 0) OVERRIDE; 52 virtual void drawBitmapRectToRect(const SkBitmap&, const SkRect* src, const SkRect& dst, const SkPaint*, DrawBitmapRectFlags) OVERRIDE; 53 virtual void drawBitmapMatrix(const SkBitmap&, const SkMatrix&, const SkPaint* = 0) OVERRIDE; 54 virtual void drawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst, const SkPaint*) OVERRIDE; 55 virtual void drawSprite(const SkBitmap&, int left, int top, const SkPaint* = 0) OVERRIDE; 56 virtual void drawVertices(VertexMode vmode, int vertexCount, const SkPoint vertices[], const SkPoint texs[], 57 const SkColor colors[], SkXfermode* xmode, const uint16_t indices[], int indexCount, const SkPaint&) OVERRIDE; 58 virtual void drawData(const void* data, size_t length) OVERRIDE; 59 virtual void beginCommentGroup(const char* description) OVERRIDE; 60 virtual void addComment(const char* keyword, const char* value) OVERRIDE; 61 virtual void endCommentGroup() OVERRIDE; 62 63 virtual void onDrawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint&) OVERRIDE; 64 virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, const SkPaint&) OVERRIDE; 65 virtual void onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[], const SkPaint&) OVERRIDE; 66 virtual void onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], SkScalar constY, const SkPaint&) OVERRIDE; 67 virtual void onDrawTextOnPath(const void* text, size_t byteLength, const SkPath&, const SkMatrix*, const SkPaint&) OVERRIDE; 68 virtual void onPushCull(const SkRect& cullRect) OVERRIDE; 69 virtual void onPopCull() OVERRIDE; 70 virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) OVERRIDE; 71 virtual void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) OVERRIDE; 72 virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) OVERRIDE; 73 virtual void onClipRegion(const SkRegion&, SkRegion::Op) OVERRIDE; 74 virtual void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*); 75 virtual void didSetMatrix(const SkMatrix&) OVERRIDE; 76 virtual void didConcat(const SkMatrix&) OVERRIDE; 77 virtual void willSave() OVERRIDE; 78 SaveLayerStrategy willSaveLayer(const SkRect* bounds, const SkPaint*, SaveFlags) OVERRIDE; 79 virtual void willRestore() OVERRIDE; 80 81private: 82 RefPtr<JSONArray> m_log; 83 friend class AutoLogger; 84 85 struct VerbParams { 86 String name; 87 unsigned pointCount; 88 unsigned pointOffset; 89 90 VerbParams(const String& name, unsigned pointCount, unsigned pointOffset) 91 : name(name) 92 , pointCount(pointCount) 93 , pointOffset(pointOffset) { } 94 }; 95 96 PassRefPtr<JSONObject> addItem(const String& name); 97 PassRefPtr<JSONObject> addItemWithParams(const String& name); 98 PassRefPtr<JSONObject> objectForSkRect(const SkRect&); 99 PassRefPtr<JSONObject> objectForSkIRect(const SkIRect&); 100 String pointModeName(PointMode); 101 PassRefPtr<JSONObject> objectForSkPoint(const SkPoint&); 102 PassRefPtr<JSONArray> arrayForSkPoints(size_t count, const SkPoint points[]); 103 PassRefPtr<JSONObject> objectForSkPicture(const SkPicture&); 104 PassRefPtr<JSONObject> objectForRadius(const SkRRect& rrect, SkRRect::Corner); 105 String rrectTypeName(SkRRect::Type); 106 String radiusName(SkRRect::Corner); 107 PassRefPtr<JSONObject> objectForSkRRect(const SkRRect&); 108 String fillTypeName(SkPath::FillType); 109 String convexityName(SkPath::Convexity); 110 String verbName(SkPath::Verb); 111 VerbParams segmentParams(SkPath::Verb); 112 PassRefPtr<JSONObject> objectForSkPath(const SkPath&); 113 String colorTypeName(SkColorType); 114 PassRefPtr<JSONObject> objectForBitmapData(const SkBitmap&); 115 PassRefPtr<JSONObject> objectForSkBitmap(const SkBitmap&); 116 PassRefPtr<JSONObject> objectForSkShader(const SkShader&); 117 String stringForSkColor(const SkColor&); 118 void appendFlagToString(String* flagsString, bool isSet, const String& name); 119 String stringForSkPaintFlags(const SkPaint&); 120 String filterLevelName(SkPaint::FilterLevel); 121 String textAlignName(SkPaint::Align); 122 String strokeCapName(SkPaint::Cap); 123 String strokeJoinName(SkPaint::Join); 124 String styleName(SkPaint::Style); 125 String textEncodingName(SkPaint::TextEncoding); 126 String hintingName(SkPaint::Hinting); 127 PassRefPtr<JSONObject> objectForSkPaint(const SkPaint&); 128 PassRefPtr<JSONArray> arrayForSkMatrix(const SkMatrix&); 129 PassRefPtr<JSONArray> arrayForSkScalars(size_t n, const SkScalar scalars[]); 130 String regionOpName(SkRegion::Op); 131 String saveFlagsToString(SkCanvas::SaveFlags); 132 String textEncodingCanonicalName(SkPaint::TextEncoding); 133 String stringForUTFText(const void* text, size_t length, SkPaint::TextEncoding); 134 String stringForText(const void* text, size_t byteLength, const SkPaint&); 135}; 136 137} // namespace blink 138 139#endif // LoggingCanvas_h 140