blob: 57c5c5ded64bfeae76a10bbb56d1d55d83a5c3cc [file] [log] [blame]
bsalomon@google.com48dd1a22011-10-31 14:18:20 +00001/*
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"
tfarina880914c2014-06-09 12:05:34 -07009
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000010using namespace skiagm;
11
12GM::GM() {
commit-bot@chromium.orgb21fac12014-02-07 21:13:11 +000013 fMode = kGM_Mode;
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000014 fBGColor = SK_ColorWHITE;
reed@google.comaef73612012-11-16 13:41:45 +000015 fCanvasIsDeferred = false;
reed@google.com7775d662012-11-27 15:15:58 +000016 fHaveCalledOnceBeforeDraw = false;
commit-bot@chromium.orgf4f9df42013-09-26 20:44:24 +000017 fStarterMatrix.reset();
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000018}
tfarina880914c2014-06-09 12:05:34 -070019
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000020GM::~GM() {}
21
22void GM::draw(SkCanvas* canvas) {
23 this->drawBackground(canvas);
24 this->drawContent(canvas);
25}
26
27void GM::drawContent(SkCanvas* canvas) {
reed@google.com7775d662012-11-27 15:15:58 +000028 if (!fHaveCalledOnceBeforeDraw) {
29 fHaveCalledOnceBeforeDraw = true;
30 this->onOnceBeforeDraw();
31 }
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000032 this->onDraw(canvas);
33}
34
35void GM::drawBackground(SkCanvas* canvas) {
reed@google.com7775d662012-11-27 15:15:58 +000036 if (!fHaveCalledOnceBeforeDraw) {
37 fHaveCalledOnceBeforeDraw = true;
38 this->onOnceBeforeDraw();
39 }
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000040 this->onDrawBackground(canvas);
41}
42
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000043const char* GM::getName() {
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000044 if (fShortName.size() == 0) {
45 fShortName = this->onShortName();
46 }
47 return fShortName.c_str();
48}
49
50void GM::setBGColor(SkColor color) {
51 fBGColor = color;
52}
53
54void GM::onDrawBackground(SkCanvas* canvas) {
robertphillips@google.comea5d8af2012-11-02 17:38:28 +000055 canvas->drawColor(fBGColor, SkXfermode::kSrc_Mode);
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000056}
57
reed@google.com2d6ef522012-01-03 17:20:38 +000058void 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.com48dd1a22011-10-31 14:18:20 +000067// need to explicitly declare this, or we get some weird infinite loop llist
tfarinabcbc1782014-06-18 14:32:48 -070068template GMRegistry* GMRegistry::gHead;