1 #include "SkCanvas.h" 2 #include "SkShape.h" 3 #include "SkMatrix.h" 4 5 #if 0 6 static int gShapeCounter; 7 static void inc_shape(const SkShape* s) { 8 SkDebugf("inc %d\n", gShapeCounter); 9 gShapeCounter += 1; 10 } 11 static void dec_shape(const SkShape* s) { 12 --gShapeCounter; 13 SkDebugf("dec %d\n", gShapeCounter); 14 } 15 #else 16 #define inc_shape(s) 17 #define dec_shape(s) 18 #endif 19 20 /////////////////////////////////////////////////////////////////////////////// 21 22 void SkShape::draw(SkCanvas* canvas) { 23 int saveCount = canvas->getSaveCount(); 24 this->onDraw(canvas); 25 canvas->restoreToCount(saveCount); 26 } 27 28 void SkShape::drawXY(SkCanvas* canvas, SkScalar dx, SkScalar dy) { 29 int saveCount = canvas->save(SkCanvas::kMatrix_SaveFlag); 30 canvas->translate(dx, dy); 31 this->onDraw(canvas); 32 canvas->restoreToCount(saveCount); 33 } 34 35 void SkShape::drawMatrix(SkCanvas* canvas, const SkMatrix& matrix) { 36 int saveCount = canvas->save(SkCanvas::kMatrix_SaveFlag); 37 canvas->concat(matrix); 38 this->onDraw(canvas); 39 canvas->restoreToCount(saveCount); 40 } 41 42 /////////////////////////////////////////////////////////////////////////////// 43 44 SkShape::SkShape() { 45 inc_shape(this); 46 } 47 48 SkShape::~SkShape() { 49 dec_shape(this); 50 } 51 52 SkShape::SkShape(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) { 53 inc_shape(this); 54 } 55 56 SkFlattenable* SkShape::CreateProc(SkFlattenableReadBuffer& buffer) { 57 return SkNEW_ARGS(SkShape, (buffer)); 58 } 59 60 SkFlattenable::Factory SkShape::getFactory() { 61 return CreateProc; 62 } 63 64 void SkShape::flatten(SkFlattenableWriteBuffer& buffer) { 65 this->INHERITED::flatten(buffer); 66 } 67 68 void SkShape::onDraw(SkCanvas*) {} 69 70 static SkFlattenable::Registrar gReg("SkShape", SkShape::CreateProc); 71