blob: 4da688c7ffe86343aabe67f97a24c97c7729ee52 [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"
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000012#include "SkBitmapDevice.h"
reed@android.comdd0ac282009-06-20 02:38:16 +000013#include "SkCanvas.h"
14#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
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
reed@android.com00dae862009-06-10 15:38:48 +000027namespace skiagm {
rmistry@google.comd6176b02012-08-23 18:14:13 +000028
epoger@google.com5efdd0c2013-03-13 14:18:40 +000029 static inline SkISize make_isize(int w, int h) {
30 SkISize sz;
31 sz.set(w, h);
32 return sz;
33 }
reed@android.com00dae862009-06-10 15:38:48 +000034
35 class GM {
36 public:
37 GM();
38 virtual ~GM();
rmistry@google.comd6176b02012-08-23 18:14:13 +000039
reed@google.comfbc21172011-09-19 19:08:33 +000040 enum Flags {
commit-bot@chromium.org805df1a2013-08-16 19:18:12 +000041 kSkipPDF_Flag = 1 << 0,
42 kSkipPicture_Flag = 1 << 1,
43 kSkipPipe_Flag = 1 << 2,
44 kSkipPipeCrossProcess_Flag = 1 << 3,
45 kSkipTiled_Flag = 1 << 4,
46 kSkip565_Flag = 1 << 5,
47 kSkipScaledReplay_Flag = 1 << 6,
48 kSkipGPU_Flag = 1 << 7,
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +000049 kSkipPDFRasterization_Flag = 1 << 8,
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000050
51 kGPUOnly_Flag = 1 << 9,
commit-bot@chromium.org6adce672014-02-03 14:48:17 +000052
53 kAsBench_Flag = 1 << 10, // Run the GM as a benchmark in the bench tool
reed@google.comfbc21172011-09-19 19:08:33 +000054 };
55
commit-bot@chromium.orgb21fac12014-02-07 21:13:11 +000056 enum Mode {
57 kGM_Mode,
58 kSample_Mode,
59 kBench_Mode,
60 };
61
62 void setMode(Mode mode) { fMode = mode; }
63 Mode getMode() const { return fMode; }
64
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000065 void draw(SkCanvas*);
66 void drawBackground(SkCanvas*);
67 void drawContent(SkCanvas*);
rmistry@google.comd6176b02012-08-23 18:14:13 +000068
robertphillips@google.com8570b5c2012-03-20 17:40:58 +000069 SkISize getISize() { return this->onISize(); }
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000070 const char* shortName();
reed@android.com00dae862009-06-10 15:38:48 +000071
reed@google.comfbc21172011-09-19 19:08:33 +000072 uint32_t getFlags() const {
73 return this->onGetFlags();
74 }
vandebo@chromium.org79d3cb42012-03-21 17:34:30 +000075
reed@google.com487b5602013-02-01 15:01:24 +000076 SkScalar width() {
77 return SkIntToScalar(this->getISize().width());
78 }
79 SkScalar height() {
scroggo@google.comab026272013-04-12 22:14:03 +000080 return SkIntToScalar(this->getISize().height());
reed@google.com487b5602013-02-01 15:01:24 +000081 }
82
vandebo@chromium.org79d3cb42012-03-21 17:34:30 +000083 // TODO(vandebo) Instead of exposing this, we should run all the GMs
84 // with and without an initial transform.
85 // Most GMs will return the identity matrix, but some PDFs tests
86 // require setting the initial transform.
87 SkMatrix getInitialTransform() const {
commit-bot@chromium.orgf4f9df42013-09-26 20:44:24 +000088 SkMatrix matrix = fStarterMatrix;
89 matrix.preConcat(this->onGetInitialTransform());
90 return matrix;
vandebo@chromium.org79d3cb42012-03-21 17:34:30 +000091 }
92
reed@google.comb4b49cc2011-12-06 16:15:42 +000093 SkColor getBGColor() const { return fBGColor; }
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000094 void setBGColor(SkColor);
reed@google.com30db5992011-08-29 17:41:02 +000095
reed@google.com2d6ef522012-01-03 17:20:38 +000096 // helper: fill a rect in the specified color based on the
97 // GM's getISize bounds.
98 void drawSizeBounds(SkCanvas*, SkColor);
99
rmistry@google.comd6176b02012-08-23 18:14:13 +0000100 static void SetResourcePath(const char* resourcePath) {
101 gResourcePath = resourcePath;
robertphillips@google.com8570b5c2012-03-20 17:40:58 +0000102 }
103
scroggo@google.com2bbc2c92013-06-14 15:33:20 +0000104 static SkString& GetResourcePath() {
105 return gResourcePath;
106 }
107
reed@google.comaef73612012-11-16 13:41:45 +0000108 bool isCanvasDeferred() const { return fCanvasIsDeferred; }
109 void setCanvasIsDeferred(bool isDeferred) {
110 fCanvasIsDeferred = isDeferred;
111 }
112
commit-bot@chromium.orgb21fac12014-02-07 21:13:11 +0000113 const SkMatrix& getStarterMatrix() { return fStarterMatrix; }
114 void setStarterMatrix(const SkMatrix& matrix) {
115 fStarterMatrix = matrix;
116 }
commit-bot@chromium.orgf4f9df42013-09-26 20:44:24 +0000117
robertphillips@google.com8570b5c2012-03-20 17:40:58 +0000118 protected:
119 static SkString gResourcePath;
120
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