| 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 | |
| tfarina | 880914c | 2014-06-09 12:05:34 -0700 | [diff] [blame^] | 12 | const char* GM::gResourcePath; |
| robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 13 | |
| bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 14 | GM::GM() { |
| commit-bot@chromium.org | b21fac1 | 2014-02-07 21:13:11 +0000 | [diff] [blame] | 15 | fMode = kGM_Mode; |
| bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 16 | fBGColor = SK_ColorWHITE; |
| reed@google.com | aef7361 | 2012-11-16 13:41:45 +0000 | [diff] [blame] | 17 | fCanvasIsDeferred = false; |
| reed@google.com | 7775d66 | 2012-11-27 15:15:58 +0000 | [diff] [blame] | 18 | fHaveCalledOnceBeforeDraw = false; |
| commit-bot@chromium.org | f4f9df4 | 2013-09-26 20:44:24 +0000 | [diff] [blame] | 19 | fStarterMatrix.reset(); |
| bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 20 | } |
| tfarina | 880914c | 2014-06-09 12:05:34 -0700 | [diff] [blame^] | 21 | |
| bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 22 | GM::~GM() {} |
| 23 | |
| 24 | void GM::draw(SkCanvas* canvas) { |
| 25 | this->drawBackground(canvas); |
| 26 | this->drawContent(canvas); |
| 27 | } |
| 28 | |
| 29 | void GM::drawContent(SkCanvas* canvas) { |
| reed@google.com | 7775d66 | 2012-11-27 15:15:58 +0000 | [diff] [blame] | 30 | if (!fHaveCalledOnceBeforeDraw) { |
| 31 | fHaveCalledOnceBeforeDraw = true; |
| 32 | this->onOnceBeforeDraw(); |
| 33 | } |
| bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 34 | this->onDraw(canvas); |
| 35 | } |
| 36 | |
| 37 | void GM::drawBackground(SkCanvas* canvas) { |
| reed@google.com | 7775d66 | 2012-11-27 15:15:58 +0000 | [diff] [blame] | 38 | if (!fHaveCalledOnceBeforeDraw) { |
| 39 | fHaveCalledOnceBeforeDraw = true; |
| 40 | this->onOnceBeforeDraw(); |
| 41 | } |
| bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 42 | this->onDrawBackground(canvas); |
| 43 | } |
| 44 | |
| commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 45 | const char* GM::getName() { |
| bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 46 | if (fShortName.size() == 0) { |
| 47 | fShortName = this->onShortName(); |
| 48 | } |
| 49 | return fShortName.c_str(); |
| 50 | } |
| 51 | |
| 52 | void GM::setBGColor(SkColor color) { |
| 53 | fBGColor = color; |
| 54 | } |
| 55 | |
| 56 | void GM::onDrawBackground(SkCanvas* canvas) { |
| robertphillips@google.com | ea5d8af | 2012-11-02 17:38:28 +0000 | [diff] [blame] | 57 | canvas->drawColor(fBGColor, SkXfermode::kSrc_Mode); |
| bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| reed@google.com | 2d6ef52 | 2012-01-03 17:20:38 +0000 | [diff] [blame] | 60 | void GM::drawSizeBounds(SkCanvas* canvas, SkColor color) { |
| 61 | SkISize size = this->getISize(); |
| 62 | SkRect r = SkRect::MakeWH(SkIntToScalar(size.width()), |
| 63 | SkIntToScalar(size.height())); |
| 64 | SkPaint paint; |
| 65 | paint.setColor(color); |
| 66 | canvas->drawRect(r, paint); |
| 67 | } |
| 68 | |
| tfarina | 880914c | 2014-06-09 12:05:34 -0700 | [diff] [blame^] | 69 | void GM::SetResourcePath(const char* resourcePath) { |
| 70 | gResourcePath = resourcePath; |
| 71 | } |
| 72 | |
| 73 | SkString GM::GetResourcePath() { |
| 74 | return SkString(gResourcePath); |
| 75 | } |
| 76 | |
| bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 77 | // need to explicitly declare this, or we get some weird infinite loop llist |
| mtklein@google.com | bd6343b | 2013-09-04 17:20:18 +0000 | [diff] [blame] | 78 | template GMRegistry* SkTRegistry<GM*(*)(void*)>::gHead; |