blob: d75a1c17c8f27fcd07932a8ac4b25cf47bc51b92 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
reed@android.com00dae862009-06-10 15:38:48 +00008#ifndef skiagm_DEFINED
9#define skiagm_DEFINED
10
epoger@google.comd4af56c2011-07-25 16:27:59 +000011#include "SkBitmap.h"
reed@android.comdd0ac282009-06-20 02:38:16 +000012#include "SkCanvas.h"
epoger@google.comd4af56c2011-07-25 16:27:59 +000013#include "SkDevice.h"
reed@android.comdd0ac282009-06-20 02:38:16 +000014#include "SkPaint.h"
reed@android.com00dae862009-06-10 15:38:48 +000015#include "SkRefCnt.h"
reed@android.comdd0ac282009-06-20 02:38:16 +000016#include "SkSize.h"
reed@android.com00dae862009-06-10 15:38:48 +000017#include "SkString.h"
18#include "SkTRegistry.h"
19
20namespace skiagm {
robertphillips@google.com8570b5c2012-03-20 17:40:58 +000021
22 static inline SkISize make_isize(int w, int h) {
23 SkISize sz;
24 sz.set(w, h);
25 return sz;
26 }
reed@android.com00dae862009-06-10 15:38:48 +000027
28 class GM {
29 public:
30 GM();
31 virtual ~GM();
robertphillips@google.com8570b5c2012-03-20 17:40:58 +000032
reed@google.comfbc21172011-09-19 19:08:33 +000033 enum Flags {
34 kSkipPDF_Flag = 1 << 0,
35 kSkipPicture_Flag = 1 << 1
36 };
37
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000038 void draw(SkCanvas*);
39 void drawBackground(SkCanvas*);
40 void drawContent(SkCanvas*);
41
robertphillips@google.com8570b5c2012-03-20 17:40:58 +000042 SkISize getISize() { return this->onISize(); }
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000043 const char* shortName();
reed@android.com00dae862009-06-10 15:38:48 +000044
reed@google.comfbc21172011-09-19 19:08:33 +000045 uint32_t getFlags() const {
46 return this->onGetFlags();
47 }
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000048
reed@google.comb4b49cc2011-12-06 16:15:42 +000049 SkColor getBGColor() const { return fBGColor; }
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000050 void setBGColor(SkColor);
reed@google.com30db5992011-08-29 17:41:02 +000051
reed@google.com2d6ef522012-01-03 17:20:38 +000052 // helper: fill a rect in the specified color based on the
53 // GM's getISize bounds.
54 void drawSizeBounds(SkCanvas*, SkColor);
55
robertphillips@google.com8570b5c2012-03-20 17:40:58 +000056 static void SetResourcePath(const char* resourcePath) {
57 gResourcePath = resourcePath;
58 }
59
60 protected:
61 static SkString gResourcePath;
62
63 virtual void onDraw(SkCanvas*) = 0;
64 virtual void onDrawBackground(SkCanvas*);
65 virtual SkISize onISize() = 0;
reed@android.com8015dd82009-06-21 00:49:18 +000066 virtual SkString onShortName() = 0;
reed@google.comfbc21172011-09-19 19:08:33 +000067 virtual uint32_t onGetFlags() const { return 0; }
reed@android.com8015dd82009-06-21 00:49:18 +000068
69 private:
70 SkString fShortName;
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000071 SkColor fBGColor;
reed@android.com00dae862009-06-10 15:38:48 +000072 };
73
74 typedef SkTRegistry<GM*, void*> GMRegistry;
75}
76
77#endif