blob: 453f104bdb0a103587491999152d96b0b46e263c [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.comdd0ac282009-06-20 02:38:16 +000015#include "SkSize.h"
reed@android.com00dae862009-06-10 15:38:48 +000016#include "SkString.h"
17#include "SkTRegistry.h"
18
19namespace skiagm {
rmistry@google.comd6176b02012-08-23 18:14:13 +000020
robertphillips@google.com8570b5c2012-03-20 17:40:58 +000021 static inline SkISize make_isize(int w, int h) {
22 SkISize sz;
23 sz.set(w, h);
24 return sz;
25 }
reed@android.com00dae862009-06-10 15:38:48 +000026
27 class GM {
28 public:
29 GM();
30 virtual ~GM();
rmistry@google.comd6176b02012-08-23 18:14:13 +000031
reed@google.comfbc21172011-09-19 19:08:33 +000032 enum Flags {
33 kSkipPDF_Flag = 1 << 0,
scroggo@google.com5af9b202012-06-04 17:17:36 +000034 kSkipPicture_Flag = 1 << 1,
scroggo@google.com63258862012-08-15 16:32:19 +000035 kSkipPipe_Flag = 1 << 2,
36 kSkipTiled_Flag = 1 << 3,
reed@google.com1b6c73d2012-10-10 15:17:24 +000037 kSkip565_Flag = 1 << 4,
reed@google.comfbc21172011-09-19 19:08:33 +000038 };
39
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000040 void draw(SkCanvas*);
41 void drawBackground(SkCanvas*);
42 void drawContent(SkCanvas*);
rmistry@google.comd6176b02012-08-23 18:14:13 +000043
robertphillips@google.com8570b5c2012-03-20 17:40:58 +000044 SkISize getISize() { return this->onISize(); }
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000045 const char* shortName();
reed@android.com00dae862009-06-10 15:38:48 +000046
reed@google.comfbc21172011-09-19 19:08:33 +000047 uint32_t getFlags() const {
48 return this->onGetFlags();
49 }
vandebo@chromium.org79d3cb42012-03-21 17:34:30 +000050
51 // TODO(vandebo) Instead of exposing this, we should run all the GMs
52 // with and without an initial transform.
53 // Most GMs will return the identity matrix, but some PDFs tests
54 // require setting the initial transform.
55 SkMatrix getInitialTransform() const {
56 return this->onGetInitialTransform();
57 }
58
reed@google.comb4b49cc2011-12-06 16:15:42 +000059 SkColor getBGColor() const { return fBGColor; }
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000060 void setBGColor(SkColor);
reed@google.com30db5992011-08-29 17:41:02 +000061
reed@google.com2d6ef522012-01-03 17:20:38 +000062 // helper: fill a rect in the specified color based on the
63 // GM's getISize bounds.
64 void drawSizeBounds(SkCanvas*, SkColor);
65
rmistry@google.comd6176b02012-08-23 18:14:13 +000066 static void SetResourcePath(const char* resourcePath) {
67 gResourcePath = resourcePath;
robertphillips@google.com8570b5c2012-03-20 17:40:58 +000068 }
69
70 protected:
71 static SkString gResourcePath;
72
73 virtual void onDraw(SkCanvas*) = 0;
74 virtual void onDrawBackground(SkCanvas*);
75 virtual SkISize onISize() = 0;
reed@android.com8015dd82009-06-21 00:49:18 +000076 virtual SkString onShortName() = 0;
reed@google.comfbc21172011-09-19 19:08:33 +000077 virtual uint32_t onGetFlags() const { return 0; }
vandebo@chromium.org79d3cb42012-03-21 17:34:30 +000078 virtual SkMatrix onGetInitialTransform() const { return SkMatrix::I(); }
79
reed@android.com8015dd82009-06-21 00:49:18 +000080 private:
81 SkString fShortName;
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000082 SkColor fBGColor;
reed@android.com00dae862009-06-10 15:38:48 +000083 };
84
85 typedef SkTRegistry<GM*, void*> GMRegistry;
86}
87
88#endif