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" |
tfarina | 880914c | 2014-06-09 12:05:34 -0700 | [diff] [blame] | 9 | |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 10 | using namespace skiagm; |
| 11 | |
| 12 | GM::GM() { |
commit-bot@chromium.org | b21fac1 | 2014-02-07 21:13:11 +0000 | [diff] [blame] | 13 | fMode = kGM_Mode; |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 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; |
commit-bot@chromium.org | f4f9df4 | 2013-09-26 20:44:24 +0000 | [diff] [blame] | 17 | fStarterMatrix.reset(); |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 18 | } |
tfarina | 880914c | 2014-06-09 12:05:34 -0700 | [diff] [blame] | 19 | |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 20 | GM::~GM() {} |
| 21 | |
| 22 | void GM::draw(SkCanvas* canvas) { |
| 23 | this->drawBackground(canvas); |
| 24 | this->drawContent(canvas); |
| 25 | } |
| 26 | |
| 27 | void GM::drawContent(SkCanvas* canvas) { |
reed@google.com | 7775d66 | 2012-11-27 15:15:58 +0000 | [diff] [blame] | 28 | if (!fHaveCalledOnceBeforeDraw) { |
| 29 | fHaveCalledOnceBeforeDraw = true; |
| 30 | this->onOnceBeforeDraw(); |
| 31 | } |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 32 | this->onDraw(canvas); |
| 33 | } |
| 34 | |
| 35 | void GM::drawBackground(SkCanvas* canvas) { |
reed@google.com | 7775d66 | 2012-11-27 15:15:58 +0000 | [diff] [blame] | 36 | if (!fHaveCalledOnceBeforeDraw) { |
| 37 | fHaveCalledOnceBeforeDraw = true; |
| 38 | this->onOnceBeforeDraw(); |
| 39 | } |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 40 | this->onDrawBackground(canvas); |
| 41 | } |
| 42 | |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 43 | const char* GM::getName() { |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 44 | if (fShortName.size() == 0) { |
| 45 | fShortName = this->onShortName(); |
| 46 | } |
| 47 | return fShortName.c_str(); |
| 48 | } |
| 49 | |
| 50 | void GM::setBGColor(SkColor color) { |
| 51 | fBGColor = color; |
| 52 | } |
| 53 | |
| 54 | void GM::onDrawBackground(SkCanvas* canvas) { |
robertphillips@google.com | ea5d8af | 2012-11-02 17:38:28 +0000 | [diff] [blame] | 55 | canvas->drawColor(fBGColor, SkXfermode::kSrc_Mode); |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 56 | } |
| 57 | |
reed@google.com | 2d6ef52 | 2012-01-03 17:20:38 +0000 | [diff] [blame] | 58 | void 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 | |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 67 | // need to explicitly declare this, or we get some weird infinite loop llist |
tfarina | bcbc178 | 2014-06-18 14:32:48 -0700 | [diff] [blame] | 68 | template GMRegistry* GMRegistry::gHead; |