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 using namespace skiagm; 10 11 SkString GM::gResourcePath; 12 13 GM::GM() { 14 fBGColor = SK_ColorWHITE; 15 fCanvasIsDeferred = false; 16 fHaveCalledOnceBeforeDraw = false; 17 fStarterMatrix.reset(); 18 } 19 GM::~GM() {} 20 21 void GM::draw(SkCanvas* canvas) { 22 this->drawBackground(canvas); 23 this->drawContent(canvas); 24 } 25 26 void GM::drawContent(SkCanvas* canvas) { 27 if (!fHaveCalledOnceBeforeDraw) { 28 fHaveCalledOnceBeforeDraw = true; 29 this->onOnceBeforeDraw(); 30 } 31 this->onDraw(canvas); 32 } 33 34 void GM::drawBackground(SkCanvas* canvas) { 35 if (!fHaveCalledOnceBeforeDraw) { 36 fHaveCalledOnceBeforeDraw = true; 37 this->onOnceBeforeDraw(); 38 } 39 this->onDrawBackground(canvas); 40 } 41 42 const char* GM::shortName() { 43 if (fShortName.size() == 0) { 44 fShortName = this->onShortName(); 45 } 46 return fShortName.c_str(); 47 } 48 49 void GM::setBGColor(SkColor color) { 50 fBGColor = color; 51 } 52 53 void GM::onDrawBackground(SkCanvas* canvas) { 54 canvas->drawColor(fBGColor, SkXfermode::kSrc_Mode); 55 } 56 57 void GM::drawSizeBounds(SkCanvas* canvas, SkColor color) { 58 SkISize size = this->getISize(); 59 SkRect r = SkRect::MakeWH(SkIntToScalar(size.width()), 60 SkIntToScalar(size.height())); 61 SkPaint paint; 62 paint.setColor(color); 63 canvas->drawRect(r, paint); 64 } 65 66 // need to explicitly declare this, or we get some weird infinite loop llist 67 template GMRegistry* SkTRegistry<GM*(*)(void*)>::gHead; 68