blob: 29d02d150a73e4ff88fb914b03f433de735f3331 [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;
commit-bot@chromium.orgf4f9df42013-09-26 20:44:24 +000017 fStarterMatrix.reset();
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000018}
19GM::~GM() {}
20
21void GM::draw(SkCanvas* canvas) {
22 this->drawBackground(canvas);
23 this->drawContent(canvas);
24}
25
26void GM::drawContent(SkCanvas* canvas) {
reed@google.com7775d662012-11-27 15:15:58 +000027 if (!fHaveCalledOnceBeforeDraw) {
28 fHaveCalledOnceBeforeDraw = true;
29 this->onOnceBeforeDraw();
30 }
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000031 this->onDraw(canvas);
32}
33
34void GM::drawBackground(SkCanvas* canvas) {
reed@google.com7775d662012-11-27 15:15:58 +000035 if (!fHaveCalledOnceBeforeDraw) {
36 fHaveCalledOnceBeforeDraw = true;
37 this->onOnceBeforeDraw();
38 }
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000039 this->onDrawBackground(canvas);
40}
41
42const char* GM::shortName() {
43 if (fShortName.size() == 0) {
44 fShortName = this->onShortName();
45 }
46 return fShortName.c_str();
47}
48
49void GM::setBGColor(SkColor color) {
50 fBGColor = color;
51}
52
53void GM::onDrawBackground(SkCanvas* canvas) {
robertphillips@google.comea5d8af2012-11-02 17:38:28 +000054 canvas->drawColor(fBGColor, SkXfermode::kSrc_Mode);
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000055}
56
reed@google.com2d6ef522012-01-03 17:20:38 +000057void GM::drawSizeBounds(SkCanvas* canvas, SkColor color) {
58 SkISize size = this->getISize();
59 SkRect r = SkRect::MakeWH(SkIntToScalar(size.width()),
60 SkIntToScalar(size.height()));
61 SkPaint paint;
62 paint.setColor(color);
63 canvas->drawRect(r, paint);
64}
65
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000066// need to explicitly declare this, or we get some weird infinite loop llist
mtklein@google.combd6343b2013-09-04 17:20:18 +000067template GMRegistry* SkTRegistry<GM*(*)(void*)>::gHead;