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