1 /* 2 * Copyright 2011 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #include "gm.h" 9 10 using namespace skiagm; 11 GM()12GM::GM() { 13 fMode = kGM_Mode; 14 fBGColor = SK_ColorWHITE; 15 fCanvasIsDeferred = false; 16 fHaveCalledOnceBeforeDraw = false; 17 fStarterMatrix.reset(); 18 } 19 ~GM()20GM::~GM() {} 21 draw(SkCanvas * canvas)22void GM::draw(SkCanvas* canvas) { 23 this->drawBackground(canvas); 24 this->drawContent(canvas); 25 } 26 drawContent(SkCanvas * canvas)27void GM::drawContent(SkCanvas* canvas) { 28 if (!fHaveCalledOnceBeforeDraw) { 29 fHaveCalledOnceBeforeDraw = true; 30 this->onOnceBeforeDraw(); 31 } 32 this->onDraw(canvas); 33 } 34 drawBackground(SkCanvas * canvas)35void GM::drawBackground(SkCanvas* canvas) { 36 if (!fHaveCalledOnceBeforeDraw) { 37 fHaveCalledOnceBeforeDraw = true; 38 this->onOnceBeforeDraw(); 39 } 40 this->onDrawBackground(canvas); 41 } 42 getName()43const char* GM::getName() { 44 if (fShortName.size() == 0) { 45 fShortName = this->onShortName(); 46 } 47 return fShortName.c_str(); 48 } 49 setBGColor(SkColor color)50void GM::setBGColor(SkColor color) { 51 fBGColor = color; 52 } 53 onDrawBackground(SkCanvas * canvas)54void GM::onDrawBackground(SkCanvas* canvas) { 55 canvas->drawColor(fBGColor, SkXfermode::kSrc_Mode); 56 } 57 drawSizeBounds(SkCanvas * canvas,SkColor color)58void GM::drawSizeBounds(SkCanvas* canvas, SkColor color) { 59 SkISize size = this->getISize(); 60 SkRect r = SkRect::MakeWH(SkIntToScalar(size.width()), 61 SkIntToScalar(size.height())); 62 SkPaint paint; 63 paint.setColor(color); 64 canvas->drawRect(r, paint); 65 } 66 67 // need to explicitly declare this, or we get some weird infinite loop llist 68 template GMRegistry* GMRegistry::gHead; 69