blob: 9ba9f452a798bfb6d365511b1e7a6be3c5b4e4bf [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +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 */
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +00007
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"
13#include "SkPaint.h"
reed@android.comdd0ac282009-06-20 02:38:16 +000014#include "SkSize.h"
reed@android.com00dae862009-06-10 15:38:48 +000015#include "SkString.h"
16#include "SkTRegistry.h"
caryclark5fb6bd42014-06-23 11:25:00 -070017#include "sk_tool_utils.h"
reed@android.com00dae862009-06-10 15:38:48 +000018
mtklein@google.com62b50b72013-09-16 20:42:15 +000019#if SK_SUPPORT_GPU
20#include "GrContext.h"
21#endif
22
reed@google.com4117a242012-10-30 20:26:58 +000023#define DEF_GM(code) \
sugoi@google.com0f0d9b72013-02-27 15:41:12 +000024 static skiagm::GM* SK_MACRO_APPEND_LINE(F_)(void*) { code; } \
reed@google.com4117a242012-10-30 20:26:58 +000025 static skiagm::GMRegistry SK_MACRO_APPEND_LINE(R_)(SK_MACRO_APPEND_LINE(F_));
26
halcanary30b83d42014-10-26 05:23:53 -070027// See colorwheel.cpp for example usage.
28#define DEF_SIMPLE_GM(NAME, CANVAS, W, H) \
29 class SK_MACRO_CONCAT(NAME, _GM) : public skiagm::GM { \
30 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE; \
31 virtual SkISize onISize() SK_OVERRIDE { \
32 return SkISize::Make((W), (H)); \
33 } \
34 virtual SkString onShortName() SK_OVERRIDE { \
35 return SkString(#NAME); \
36 } \
37 }; \
38 DEF_GM( return SkNEW(SK_MACRO_CONCAT(NAME, _GM)); ) \
39 void SK_MACRO_CONCAT(NAME, _GM)::onDraw(SkCanvas* CANVAS)
40
reed@android.com00dae862009-06-10 15:38:48 +000041namespace skiagm {
rmistry@google.comd6176b02012-08-23 18:14:13 +000042
reed@android.com00dae862009-06-10 15:38:48 +000043 class GM {
44 public:
45 GM();
46 virtual ~GM();
rmistry@google.comd6176b02012-08-23 18:14:13 +000047
reed@google.comfbc21172011-09-19 19:08:33 +000048 enum Flags {
commit-bot@chromium.org805df1a2013-08-16 19:18:12 +000049 kSkipPDF_Flag = 1 << 0,
50 kSkipPicture_Flag = 1 << 1,
51 kSkipPipe_Flag = 1 << 2,
52 kSkipPipeCrossProcess_Flag = 1 << 3,
53 kSkipTiled_Flag = 1 << 4,
54 kSkip565_Flag = 1 << 5,
55 kSkipScaledReplay_Flag = 1 << 6,
56 kSkipGPU_Flag = 1 << 7,
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +000057 kSkipPDFRasterization_Flag = 1 << 8,
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000058
59 kGPUOnly_Flag = 1 << 9,
commit-bot@chromium.org6adce672014-02-03 14:48:17 +000060
61 kAsBench_Flag = 1 << 10, // Run the GM as a benchmark in the bench tool
mtkleine4636aa2014-07-09 13:10:58 -070062
63 kNoBBH_Flag = 1 << 11, // May draw wrong using a bounding-box hierarchy
reed@google.comfbc21172011-09-19 19:08:33 +000064 };
65
commit-bot@chromium.orgb21fac12014-02-07 21:13:11 +000066 enum Mode {
67 kGM_Mode,
68 kSample_Mode,
69 kBench_Mode,
70 };
71
72 void setMode(Mode mode) { fMode = mode; }
73 Mode getMode() const { return fMode; }
74
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000075 void draw(SkCanvas*);
76 void drawBackground(SkCanvas*);
77 void drawContent(SkCanvas*);
rmistry@google.comd6176b02012-08-23 18:14:13 +000078
robertphillips@google.com8570b5c2012-03-20 17:40:58 +000079 SkISize getISize() { return this->onISize(); }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000080 const char* getName();
reed@android.com00dae862009-06-10 15:38:48 +000081
reed@google.comfbc21172011-09-19 19:08:33 +000082 uint32_t getFlags() const {
83 return this->onGetFlags();
84 }
vandebo@chromium.org79d3cb42012-03-21 17:34:30 +000085
reed@google.com487b5602013-02-01 15:01:24 +000086 SkScalar width() {
87 return SkIntToScalar(this->getISize().width());
88 }
89 SkScalar height() {
scroggo@google.comab026272013-04-12 22:14:03 +000090 return SkIntToScalar(this->getISize().height());
reed@google.com487b5602013-02-01 15:01:24 +000091 }
92
vandebo@chromium.org79d3cb42012-03-21 17:34:30 +000093 // TODO(vandebo) Instead of exposing this, we should run all the GMs
94 // with and without an initial transform.
95 // Most GMs will return the identity matrix, but some PDFs tests
96 // require setting the initial transform.
97 SkMatrix getInitialTransform() const {
commit-bot@chromium.orgf4f9df42013-09-26 20:44:24 +000098 SkMatrix matrix = fStarterMatrix;
99 matrix.preConcat(this->onGetInitialTransform());
100 return matrix;
vandebo@chromium.org79d3cb42012-03-21 17:34:30 +0000101 }
102
reed@google.comb4b49cc2011-12-06 16:15:42 +0000103 SkColor getBGColor() const { return fBGColor; }
bsalomon@google.com48dd1a22011-10-31 14:18:20 +0000104 void setBGColor(SkColor);
reed@google.com30db5992011-08-29 17:41:02 +0000105
reed@google.com2d6ef522012-01-03 17:20:38 +0000106 // helper: fill a rect in the specified color based on the
107 // GM's getISize bounds.
108 void drawSizeBounds(SkCanvas*, SkColor);
109
reed@google.comaef73612012-11-16 13:41:45 +0000110 bool isCanvasDeferred() const { return fCanvasIsDeferred; }
111 void setCanvasIsDeferred(bool isDeferred) {
112 fCanvasIsDeferred = isDeferred;
113 }
114
commit-bot@chromium.orgb21fac12014-02-07 21:13:11 +0000115 const SkMatrix& getStarterMatrix() { return fStarterMatrix; }
116 void setStarterMatrix(const SkMatrix& matrix) {
117 fStarterMatrix = matrix;
118 }
commit-bot@chromium.orgf4f9df42013-09-26 20:44:24 +0000119
robertphillips@google.com8570b5c2012-03-20 17:40:58 +0000120 protected:
reed@google.com7775d662012-11-27 15:15:58 +0000121 virtual void onOnceBeforeDraw() {}
robertphillips@google.com8570b5c2012-03-20 17:40:58 +0000122 virtual void onDraw(SkCanvas*) = 0;
123 virtual void onDrawBackground(SkCanvas*);
124 virtual SkISize onISize() = 0;
reed@android.com8015dd82009-06-21 00:49:18 +0000125 virtual SkString onShortName() = 0;
reed@google.comfbc21172011-09-19 19:08:33 +0000126 virtual uint32_t onGetFlags() const { return 0; }
vandebo@chromium.org79d3cb42012-03-21 17:34:30 +0000127 virtual SkMatrix onGetInitialTransform() const { return SkMatrix::I(); }
128
reed@android.com8015dd82009-06-21 00:49:18 +0000129 private:
commit-bot@chromium.orgb21fac12014-02-07 21:13:11 +0000130 Mode fMode;
reed@android.com8015dd82009-06-21 00:49:18 +0000131 SkString fShortName;
bsalomon@google.com48dd1a22011-10-31 14:18:20 +0000132 SkColor fBGColor;
reed@google.comaef73612012-11-16 13:41:45 +0000133 bool fCanvasIsDeferred; // work-around problem in srcmode.cpp
reed@google.com7775d662012-11-27 15:15:58 +0000134 bool fHaveCalledOnceBeforeDraw;
commit-bot@chromium.orgf4f9df42013-09-26 20:44:24 +0000135 SkMatrix fStarterMatrix;
reed@android.com00dae862009-06-10 15:38:48 +0000136 };
137
mtklein@google.combd6343b2013-09-04 17:20:18 +0000138 typedef SkTRegistry<GM*(*)(void*)> GMRegistry;
reed@android.com00dae862009-06-10 15:38:48 +0000139}
140
141#endif