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