blob: c1e75e9d43fbacef8522bc8d849716c3636d6ec4 [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"
9using namespace skiagm;
10
robertphillips@google.com8570b5c2012-03-20 17:40:58 +000011SkString GM::gResourcePath;
12
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000013GM::GM() {
14 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;
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000017}
18GM::~GM() {}
19
20void GM::draw(SkCanvas* canvas) {
21 this->drawBackground(canvas);
22 this->drawContent(canvas);
23}
24
25void GM::drawContent(SkCanvas* canvas) {
reed@google.com7775d662012-11-27 15:15:58 +000026 if (!fHaveCalledOnceBeforeDraw) {
27 fHaveCalledOnceBeforeDraw = true;
28 this->onOnceBeforeDraw();
29 }
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000030 this->onDraw(canvas);
31}
32
33void GM::drawBackground(SkCanvas* canvas) {
reed@google.com7775d662012-11-27 15:15:58 +000034 if (!fHaveCalledOnceBeforeDraw) {
35 fHaveCalledOnceBeforeDraw = true;
36 this->onOnceBeforeDraw();
37 }
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000038 this->onDrawBackground(canvas);
39}
40
41const char* GM::shortName() {
42 if (fShortName.size() == 0) {
43 fShortName = this->onShortName();
44 }
45 return fShortName.c_str();
46}
47
48void GM::setBGColor(SkColor color) {
49 fBGColor = color;
50}
51
52void GM::onDrawBackground(SkCanvas* canvas) {
robertphillips@google.comea5d8af2012-11-02 17:38:28 +000053 canvas->drawColor(fBGColor, SkXfermode::kSrc_Mode);
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000054}
55
reed@google.com2d6ef522012-01-03 17:20:38 +000056void 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.com48dd1a22011-10-31 14:18:20 +000065// need to explicitly declare this, or we get some weird infinite loop llist
66template GMRegistry* SkTRegistry<GM*, void*>::gHead;