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"
|
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_));
|
|
|
|
|
2014-10-26 12:23:53 +00:00
|
|
|
// See colorwheel.cpp for example usage.
|
2015-01-12 23:27:46 +00:00
|
|
|
#define DEF_SIMPLE_GM(NAME, CANVAS, W, H) \
|
|
|
|
static void SK_MACRO_CONCAT(NAME, _GM)(SkCanvas* CANVAS); \
|
|
|
|
DEF_GM( return SkNEW_ARGS(skiagm::SimpleGM, \
|
|
|
|
(SkString(#NAME), \
|
|
|
|
SK_MACRO_CONCAT(NAME, _GM), \
|
|
|
|
SkISize::Make(W, H))); ) \
|
|
|
|
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&);
|
2015-02-02 03:01:04 +00:00
|
|
|
|
2015-05-27 20:23:23 +00:00
|
|
|
virtual void modifyGrContextOptions(GrContextOptions* options) {}
|
|
|
|
|
2012-03-20 17:40:58 +00:00
|
|
|
protected:
|
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-01-31 19:29:16 +00:00
|
|
|
void drawGpuOnlyMessage(SkCanvas*);
|
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; }
|
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*),
|
|
|
|
const SkISize& size)
|
|
|
|
: fName(name), fDrawProc(drawProc), fSize(size) {}
|
|
|
|
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
|