2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2014-02-13 17:14:46 +00:00
|
|
|
|
2009-06-10 15:38:48 +00:00
|
|
|
#ifndef skiagm_DEFINED
|
|
|
|
#define skiagm_DEFINED
|
|
|
|
|
2011-07-25 16:27:59 +00:00
|
|
|
#include "SkBitmap.h"
|
2009-06-20 02:38:16 +00:00
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkSize.h"
|
2009-06-10 15:38:48 +00:00
|
|
|
#include "SkString.h"
|
|
|
|
#include "SkTRegistry.h"
|
2014-06-23 18:25:00 +00:00
|
|
|
#include "sk_tool_utils.h"
|
2016-12-12 15:02:12 +00:00
|
|
|
#include "SkClipOpPriv.h"
|
2009-06-10 15:38:48 +00:00
|
|
|
|
2015-02-02 20:55:02 +00:00
|
|
|
class SkAnimTimer;
|
2015-05-27 20:23:23 +00:00
|
|
|
struct GrContextOptions;
|
2013-09-16 20:42:15 +00:00
|
|
|
|
2012-10-30 20:26:58 +00:00
|
|
|
#define DEF_GM(code) \
|
2013-02-27 15:41:12 +00:00
|
|
|
static skiagm::GM* SK_MACRO_APPEND_LINE(F_)(void*) { code; } \
|
2012-10-30 20:26:58 +00:00
|
|
|
static skiagm::GMRegistry SK_MACRO_APPEND_LINE(R_)(SK_MACRO_APPEND_LINE(F_));
|
|
|
|
|
2015-09-09 15:16:41 +00:00
|
|
|
// a Simple GM is a rendering test that does not store state between
|
|
|
|
// rendering calls or make use of the onOnceBeforeDraw() virtual; it
|
|
|
|
// consists of:
|
|
|
|
// * A single void(*)(SkCanvas*) function.
|
|
|
|
// * A name.
|
|
|
|
// * Prefered width and height.
|
|
|
|
// * Optionally, a background color (default is white).
|
|
|
|
#define DEF_SIMPLE_GM(NAME, CANVAS, W, H) \
|
|
|
|
DEF_SIMPLE_GM_BG_NAME(NAME, CANVAS, W, H, SK_ColorWHITE, SkString(#NAME))
|
|
|
|
#define DEF_SIMPLE_GM_BG(NAME, CANVAS, W, H, BGCOLOR)\
|
|
|
|
DEF_SIMPLE_GM_BG_NAME(NAME, CANVAS, W, H, BGCOLOR, SkString(#NAME))
|
2016-06-09 19:20:25 +00:00
|
|
|
#define DEF_SIMPLE_GM_BG_NAME(NAME, CANVAS, W, H, BGCOLOR, NAME_STR) \
|
|
|
|
static void SK_MACRO_CONCAT(NAME, _GM)(SkCanvas * CANVAS); \
|
|
|
|
DEF_GM(return new skiagm::SimpleGM(NAME_STR, SK_MACRO_CONCAT(NAME, _GM), \
|
|
|
|
SkISize::Make(W, H), BGCOLOR);) \
|
2015-08-26 20:07:48 +00:00
|
|
|
void SK_MACRO_CONCAT(NAME, _GM)(SkCanvas * CANVAS)
|
2014-10-26 12:23:53 +00:00
|
|
|
|
2009-06-10 15:38:48 +00:00
|
|
|
namespace skiagm {
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2009-06-10 15:38:48 +00:00
|
|
|
class GM {
|
|
|
|
public:
|
|
|
|
GM();
|
|
|
|
virtual ~GM();
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2014-02-07 21:13:11 +00:00
|
|
|
enum Mode {
|
|
|
|
kGM_Mode,
|
|
|
|
kSample_Mode,
|
|
|
|
kBench_Mode,
|
|
|
|
};
|
|
|
|
|
|
|
|
void setMode(Mode mode) { fMode = mode; }
|
|
|
|
Mode getMode() const { return fMode; }
|
|
|
|
|
2011-10-31 14:18:20 +00:00
|
|
|
void draw(SkCanvas*);
|
|
|
|
void drawBackground(SkCanvas*);
|
|
|
|
void drawContent(SkCanvas*);
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2015-01-28 23:32:24 +00:00
|
|
|
SkISize getISize() { return this->onISize(); }
|
2014-02-26 23:01:57 +00:00
|
|
|
const char* getName();
|
2009-06-10 15:38:48 +00:00
|
|
|
|
2015-01-23 18:31:45 +00:00
|
|
|
virtual bool runAsBench() const { return false; }
|
|
|
|
|
2013-02-01 15:01:24 +00:00
|
|
|
SkScalar width() {
|
|
|
|
return SkIntToScalar(this->getISize().width());
|
|
|
|
}
|
|
|
|
SkScalar height() {
|
2013-04-12 22:14:03 +00:00
|
|
|
return SkIntToScalar(this->getISize().height());
|
2013-02-01 15:01:24 +00:00
|
|
|
}
|
|
|
|
|
2012-03-21 17:34:30 +00:00
|
|
|
// TODO(vandebo) Instead of exposing this, we should run all the GMs
|
|
|
|
// with and without an initial transform.
|
|
|
|
// Most GMs will return the identity matrix, but some PDFs tests
|
|
|
|
// require setting the initial transform.
|
|
|
|
SkMatrix getInitialTransform() const {
|
2013-09-26 20:44:24 +00:00
|
|
|
SkMatrix matrix = fStarterMatrix;
|
|
|
|
matrix.preConcat(this->onGetInitialTransform());
|
|
|
|
return matrix;
|
2012-03-21 17:34:30 +00:00
|
|
|
}
|
|
|
|
|
2011-12-06 16:15:42 +00:00
|
|
|
SkColor getBGColor() const { return fBGColor; }
|
2011-10-31 14:18:20 +00:00
|
|
|
void setBGColor(SkColor);
|
2011-08-29 17:41:02 +00:00
|
|
|
|
2012-01-03 17:20:38 +00:00
|
|
|
// helper: fill a rect in the specified color based on the
|
|
|
|
// GM's getISize bounds.
|
|
|
|
void drawSizeBounds(SkCanvas*, SkColor);
|
|
|
|
|
2012-11-16 13:41:45 +00:00
|
|
|
bool isCanvasDeferred() const { return fCanvasIsDeferred; }
|
|
|
|
void setCanvasIsDeferred(bool isDeferred) {
|
|
|
|
fCanvasIsDeferred = isDeferred;
|
|
|
|
}
|
|
|
|
|
2014-02-07 21:13:11 +00:00
|
|
|
const SkMatrix& getStarterMatrix() { return fStarterMatrix; }
|
|
|
|
void setStarterMatrix(const SkMatrix& matrix) {
|
|
|
|
fStarterMatrix = matrix;
|
|
|
|
}
|
2013-09-26 20:44:24 +00:00
|
|
|
|
2015-02-02 20:55:02 +00:00
|
|
|
bool animate(const SkAnimTimer&);
|
2016-09-08 16:02:43 +00:00
|
|
|
bool handleKey(SkUnichar uni) {
|
|
|
|
return this->onHandleKey(uni);
|
|
|
|
}
|
2015-02-02 03:01:04 +00:00
|
|
|
|
2015-05-27 20:23:23 +00:00
|
|
|
virtual void modifyGrContextOptions(GrContextOptions* options) {}
|
|
|
|
|
2015-01-31 15:51:14 +00:00
|
|
|
/** draws a standard message that the GM is only intended to be used with the GPU.*/
|
2015-09-09 15:16:41 +00:00
|
|
|
static void DrawGpuOnlyMessage(SkCanvas*);
|
|
|
|
|
|
|
|
protected:
|
2012-11-27 15:15:58 +00:00
|
|
|
virtual void onOnceBeforeDraw() {}
|
2012-03-20 17:40:58 +00:00
|
|
|
virtual void onDraw(SkCanvas*) = 0;
|
|
|
|
virtual void onDrawBackground(SkCanvas*);
|
|
|
|
virtual SkISize onISize() = 0;
|
2009-06-21 00:49:18 +00:00
|
|
|
virtual SkString onShortName() = 0;
|
2015-01-23 19:07:07 +00:00
|
|
|
|
2015-02-02 20:55:02 +00:00
|
|
|
virtual bool onAnimate(const SkAnimTimer&) { return false; }
|
2016-09-08 16:02:43 +00:00
|
|
|
virtual bool onHandleKey(SkUnichar uni) { return false; }
|
2012-03-21 17:34:30 +00:00
|
|
|
virtual SkMatrix onGetInitialTransform() const { return SkMatrix::I(); }
|
|
|
|
|
2009-06-21 00:49:18 +00:00
|
|
|
private:
|
2014-02-07 21:13:11 +00:00
|
|
|
Mode fMode;
|
2009-06-21 00:49:18 +00:00
|
|
|
SkString fShortName;
|
2011-10-31 14:18:20 +00:00
|
|
|
SkColor fBGColor;
|
2012-11-16 13:41:45 +00:00
|
|
|
bool fCanvasIsDeferred; // work-around problem in srcmode.cpp
|
2012-11-27 15:15:58 +00:00
|
|
|
bool fHaveCalledOnceBeforeDraw;
|
2013-09-26 20:44:24 +00:00
|
|
|
SkMatrix fStarterMatrix;
|
2009-06-10 15:38:48 +00:00
|
|
|
};
|
|
|
|
|
2013-09-04 17:20:18 +00:00
|
|
|
typedef SkTRegistry<GM*(*)(void*)> GMRegistry;
|
2015-01-12 23:27:46 +00:00
|
|
|
|
|
|
|
class SimpleGM : public skiagm::GM {
|
|
|
|
public:
|
|
|
|
SimpleGM(const SkString& name,
|
|
|
|
void (*drawProc)(SkCanvas*),
|
2015-09-09 15:16:41 +00:00
|
|
|
const SkISize& size,
|
|
|
|
SkColor backgroundColor)
|
|
|
|
: fName(name), fDrawProc(drawProc), fSize(size) {
|
|
|
|
if (backgroundColor != SK_ColorWHITE) {
|
|
|
|
this->setBGColor(backgroundColor);
|
|
|
|
}
|
|
|
|
}
|
2015-01-12 23:27:46 +00:00
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override;
|
|
|
|
SkISize onISize() override;
|
|
|
|
SkString onShortName() override;
|
2015-01-12 23:27:46 +00:00
|
|
|
private:
|
|
|
|
SkString fName;
|
|
|
|
void (*fDrawProc)(SkCanvas*);
|
|
|
|
SkISize fSize;
|
|
|
|
};
|
2009-06-10 15:38:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|