1/* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#ifndef DumpLayer_h 18#define DumpLayer_h 19 20#include "FixedPositioning.h" 21#include "IntPoint.h" 22#include "LayerAndroid.h" 23#include "SkPoint.h" 24#include "SkRect.h" 25#include "SkSize.h" 26#include "TransformationMatrix.h" 27 28// Debug tools : dump the layers tree in a file. 29// The format is simple: 30// properties have the form: key = value; 31// all statements are finished with a semi-colon. 32// value can be: 33// - int 34// - float 35// - array of elements 36// - composed type 37// a composed type enclose properties in { and } 38// an array enclose composed types in { }, separated with a comma. 39// exemple: 40// { 41// x = 3; 42// y = 4; 43// value = { 44// x = 3; 45// y = 4; 46// }; 47// anarray = [ 48// { x = 3; }, 49// { y = 4; } 50// ]; 51// } 52 53namespace WebCore { 54 55class LayerDumper { 56public: 57 LayerDumper(int initialIndentLevel = 0) 58 : m_indentLevel(initialIndentLevel) 59 {} 60 virtual ~LayerDumper() {} 61 62 virtual void beginLayer(const char* className, const LayerAndroid* layerPtr) {} 63 64 virtual void endLayer() {} 65 66 virtual void beginChildren(int childCount) { 67 m_indentLevel++; 68 } 69 virtual void endChildren() { 70 m_indentLevel--; 71 } 72 73 void writeIntVal(const char* label, int value); 74 void writeHexVal(const char* label, int value); 75 void writeFloatVal(const char* label, float value); 76 void writePoint(const char* label, SkPoint value); 77 void writeIntPoint(const char* label, IntPoint value); 78 void writeSize(const char* label, SkSize value); 79 void writeRect(const char* label, SkRect value); 80 void writeMatrix(const char* label, const TransformationMatrix& value); 81 void writeLength(const char* label, SkLength value); 82 83protected: 84 virtual void writeEntry(const char* label, const char* value) = 0; 85 86 int m_indentLevel; 87 88private: 89 static const int BUF_SIZE = 4096; 90 char m_valueBuffer[BUF_SIZE]; 91}; 92 93class FileLayerDumper : public LayerDumper { 94public: 95 FileLayerDumper(FILE* file) 96 : m_file(file) 97 {} 98 99 virtual void beginLayer(const char* className, const LayerAndroid* layerPtr); 100 virtual void endLayer(); 101protected: 102 virtual void writeEntry(const char* label, const char* value); 103 104private: 105 void writeLine(const char* str); 106 FILE* m_file; 107}; 108 109} 110 111#endif // DumpLayer_h 112