blob: 6e34d3dedeccc86d30bd844e62ce47ef4d1bf29f [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
reed@google.com4117a242012-10-30 20:26:58 +000019#define DEF_GM(code) \
sugoi@google.com0f0d9b72013-02-27 15:41:12 +000020 static skiagm::GM* SK_MACRO_APPEND_LINE(F_)(void*) { code; } \
reed@google.com4117a242012-10-30 20:26:58 +000021 static skiagm::GMRegistry SK_MACRO_APPEND_LINE(R_)(SK_MACRO_APPEND_LINE(F_));
22
reed@android.com00dae862009-06-10 15:38:48 +000023namespace skiagm {
rmistry@google.comd6176b02012-08-23 18:14:13 +000024
epoger@google.com5efdd0c2013-03-13 14:18:40 +000025 static inline SkISize make_isize(int w, int h) {
26 SkISize sz;
27 sz.set(w, h);
28 return sz;
29 }
reed@android.com00dae862009-06-10 15:38:48 +000030
31 class GM {
32 public:
33 GM();
34 virtual ~GM();
rmistry@google.comd6176b02012-08-23 18:14:13 +000035
reed@google.comfbc21172011-09-19 19:08:33 +000036 enum Flags {
junov@chromium.orgff06af22013-01-14 16:27:50 +000037 kSkipPDF_Flag = 1 << 0,
38 kSkipPicture_Flag = 1 << 1,
39 kSkipPipe_Flag = 1 << 2,
40 kSkipTiled_Flag = 1 << 3,
41 kSkip565_Flag = 1 << 4,
42 kSkipScaledReplay_Flag = 1 << 5,
reed@google.com1f19b7f2013-03-08 13:31:02 +000043 kSkipGPU_Flag = 1 << 6,
reed@google.comfbc21172011-09-19 19:08:33 +000044 };
45
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000046 void draw(SkCanvas*);
47 void drawBackground(SkCanvas*);
48 void drawContent(SkCanvas*);
rmistry@google.comd6176b02012-08-23 18:14:13 +000049
robertphillips@google.com8570b5c2012-03-20 17:40:58 +000050 SkISize getISize() { return this->onISize(); }
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000051 const char* shortName();
reed@android.com00dae862009-06-10 15:38:48 +000052
reed@google.comfbc21172011-09-19 19:08:33 +000053 uint32_t getFlags() const {
54 return this->onGetFlags();
55 }
vandebo@chromium.org79d3cb42012-03-21 17:34:30 +000056
reed@google.com487b5602013-02-01 15:01:24 +000057 SkScalar width() {
58 return SkIntToScalar(this->getISize().width());
59 }
60 SkScalar height() {
scroggo@google.comab026272013-04-12 22:14:03 +000061 return SkIntToScalar(this->getISize().height());
reed@google.com487b5602013-02-01 15:01:24 +000062 }
63
vandebo@chromium.org79d3cb42012-03-21 17:34:30 +000064 // TODO(vandebo) Instead of exposing this, we should run all the GMs
65 // with and without an initial transform.
66 // Most GMs will return the identity matrix, but some PDFs tests
67 // require setting the initial transform.
68 SkMatrix getInitialTransform() const {
69 return this->onGetInitialTransform();
70 }
71
reed@google.comb4b49cc2011-12-06 16:15:42 +000072 SkColor getBGColor() const { return fBGColor; }
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000073 void setBGColor(SkColor);
reed@google.com30db5992011-08-29 17:41:02 +000074
reed@google.com2d6ef522012-01-03 17:20:38 +000075 // helper: fill a rect in the specified color based on the
76 // GM's getISize bounds.
77 void drawSizeBounds(SkCanvas*, SkColor);
78
rmistry@google.comd6176b02012-08-23 18:14:13 +000079 static void SetResourcePath(const char* resourcePath) {
80 gResourcePath = resourcePath;
robertphillips@google.com8570b5c2012-03-20 17:40:58 +000081 }
82
reed@google.comaef73612012-11-16 13:41:45 +000083 bool isCanvasDeferred() const { return fCanvasIsDeferred; }
84 void setCanvasIsDeferred(bool isDeferred) {
85 fCanvasIsDeferred = isDeferred;
86 }
87
robertphillips@google.com8570b5c2012-03-20 17:40:58 +000088 protected:
89 static SkString gResourcePath;
90
reed@google.com7775d662012-11-27 15:15:58 +000091 virtual void onOnceBeforeDraw() {}
robertphillips@google.com8570b5c2012-03-20 17:40:58 +000092 virtual void onDraw(SkCanvas*) = 0;
93 virtual void onDrawBackground(SkCanvas*);
94 virtual SkISize onISize() = 0;
reed@android.com8015dd82009-06-21 00:49:18 +000095 virtual SkString onShortName() = 0;
reed@google.comfbc21172011-09-19 19:08:33 +000096 virtual uint32_t onGetFlags() const { return 0; }
vandebo@chromium.org79d3cb42012-03-21 17:34:30 +000097 virtual SkMatrix onGetInitialTransform() const { return SkMatrix::I(); }
98
reed@android.com8015dd82009-06-21 00:49:18 +000099 private:
100 SkString fShortName;
bsalomon@google.com48dd1a22011-10-31 14:18:20 +0000101 SkColor fBGColor;
reed@google.comaef73612012-11-16 13:41:45 +0000102 bool fCanvasIsDeferred; // work-around problem in srcmode.cpp
reed@google.com7775d662012-11-27 15:15:58 +0000103 bool fHaveCalledOnceBeforeDraw;
reed@android.com00dae862009-06-10 15:38:48 +0000104 };
105
106 typedef SkTRegistry<GM*, void*> GMRegistry;
107}
108
109#endif