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
|
|
|
|
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkTypes.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/private/SkMacros.h"
|
|
|
|
#include "tools/Registry.h"
|
2009-06-10 15:38:48 +00:00
|
|
|
|
2019-03-20 16:55:08 +00:00
|
|
|
class AnimTimer;
|
2019-05-01 21:28:53 +00:00
|
|
|
class GrContext;
|
|
|
|
class GrRenderTargetContext;
|
|
|
|
class SkCanvas;
|
2019-02-04 21:50:10 +00:00
|
|
|
class SkMetaData;
|
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_));
|
|
|
|
|
2019-02-07 22:23:36 +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:
|
2015-09-09 15:16:41 +00:00
|
|
|
// * A name.
|
|
|
|
// * Prefered width and height.
|
|
|
|
// * Optionally, a background color (default is white).
|
2019-02-07 22:23:36 +00:00
|
|
|
// * A standalone function pointer that implements its onDraw method.
|
2015-09-09 15:16:41 +00:00
|
|
|
#define DEF_SIMPLE_GM(NAME, CANVAS, W, H) \
|
|
|
|
DEF_SIMPLE_GM_BG_NAME(NAME, CANVAS, W, H, SK_ColorWHITE, SkString(#NAME))
|
2019-02-07 22:23:36 +00:00
|
|
|
#define DEF_SIMPLE_GM_BG(NAME, CANVAS, W, H, BGCOLOR) \
|
2015-09-09 15:16:41 +00:00
|
|
|
DEF_SIMPLE_GM_BG_NAME(NAME, CANVAS, W, H, BGCOLOR, SkString(#NAME))
|
2019-02-07 22:23:36 +00:00
|
|
|
#define DEF_SIMPLE_GM_BG_NAME(NAME, CANVAS, W, H, BGCOLOR, NAME_STR) \
|
2019-02-07 23:20:09 +00:00
|
|
|
static void SK_MACRO_CONCAT(NAME,_GM_inner)(SkCanvas*); \
|
|
|
|
DEF_SIMPLE_GM_BG_NAME_CAN_FAIL(NAME, CANVAS,, W, H, BGCOLOR, NAME_STR) { \
|
|
|
|
SK_MACRO_CONCAT(NAME,_GM_inner)(CANVAS); \
|
|
|
|
return skiagm::DrawResult::kOk; \
|
|
|
|
} \
|
|
|
|
void SK_MACRO_CONCAT(NAME,_GM_inner)(SkCanvas* CANVAS)
|
|
|
|
|
|
|
|
#define DEF_SIMPLE_GM_CAN_FAIL(NAME, CANVAS, ERR_MSG, W, H) \
|
|
|
|
DEF_SIMPLE_GM_BG_NAME_CAN_FAIL(NAME, CANVAS, ERR_MSG, W, H, SK_ColorWHITE, SkString(#NAME))
|
|
|
|
#define DEF_SIMPLE_GM_BG_CAN_FAIL(NAME, CANVAS, ERR_MSG, W, H, BGCOLOR) \
|
|
|
|
DEF_SIMPLE_GM_BG_NAME_CAN_FAIL(NAME, CANVAS, ERR_MSG, W, H, BGCOLOR, SkString(#NAME))
|
|
|
|
#define DEF_SIMPLE_GM_BG_NAME_CAN_FAIL(NAME, CANVAS, ERR_MSG, W, H, BGCOLOR, NAME_STR) \
|
|
|
|
static skiagm::DrawResult SK_MACRO_CONCAT(NAME,_GM)(SkCanvas*, SkString*); \
|
|
|
|
DEF_GM(return new skiagm::SimpleGM(BGCOLOR, NAME_STR, {W,H}, SK_MACRO_CONCAT(NAME,_GM));) \
|
|
|
|
skiagm::DrawResult SK_MACRO_CONCAT(NAME,_GM)(SkCanvas* CANVAS, SkString* ERR_MSG)
|
|
|
|
|
2014-10-26 12:23:53 +00:00
|
|
|
|
2019-02-07 22:23:36 +00:00
|
|
|
// A Simple GpuGM makes direct GPU calls. Its onDraw hook that includes GPU objects as params, and
|
|
|
|
// is only invoked on GPU configs. Non-GPU configs automatically draw a GPU-only message and abort.
|
|
|
|
#define DEF_SIMPLE_GPU_GM(NAME, GR_CONTEXT, RENDER_TARGET_CONTEXT, CANVAS, W, H) \
|
|
|
|
DEF_SIMPLE_GPU_GM_BG(NAME, GR_CONTEXT, RENDER_TARGET_CONTEXT, CANVAS, W, H, SK_ColorWHITE)
|
2019-02-07 23:20:09 +00:00
|
|
|
#define DEF_SIMPLE_GPU_GM_BG(NAME, GR_CONTEXT, RENDER_TARGET_CONTEXT, CANVAS, W, H, BGCOLOR) \
|
|
|
|
static void SK_MACRO_CONCAT(NAME,_GM_inner)(GrContext*, GrRenderTargetContext*, SkCanvas*); \
|
|
|
|
DEF_SIMPLE_GPU_GM_BG_CAN_FAIL(NAME, GR_CONTEXT, RENDER_TARGET_CONTEXT, CANVAS,, W, H, \
|
|
|
|
BGCOLOR) { \
|
|
|
|
SK_MACRO_CONCAT(NAME,_GM_inner)(GR_CONTEXT, RENDER_TARGET_CONTEXT, CANVAS); \
|
|
|
|
return skiagm::DrawResult::kOk; \
|
|
|
|
} \
|
|
|
|
void SK_MACRO_CONCAT(NAME,_GM_inner)( \
|
2019-02-07 22:23:36 +00:00
|
|
|
GrContext* GR_CONTEXT, GrRenderTargetContext* RENDER_TARGET_CONTEXT, SkCanvas* CANVAS)
|
|
|
|
|
2019-02-07 23:20:09 +00:00
|
|
|
#define DEF_SIMPLE_GPU_GM_CAN_FAIL(NAME, GR_CONTEXT, RENDER_TARGET_CONTEXT, CANVAS, ERR_MSG, W, H) \
|
|
|
|
DEF_SIMPLE_GPU_GM_BG_CAN_FAIL(NAME, GR_CONTEXT, RENDER_TARGET_CONTEXT, CANVAS, \
|
|
|
|
ERR_MSG, W, H, SK_ColorWHITE)
|
|
|
|
#define DEF_SIMPLE_GPU_GM_BG_CAN_FAIL(NAME, GR_CONTEXT, RENDER_TARGET_CONTEXT, CANVAS, ERR_MSG, W, \
|
|
|
|
H, BGCOLOR) \
|
|
|
|
static skiagm::DrawResult SK_MACRO_CONCAT(NAME,_GM)( \
|
|
|
|
GrContext*, GrRenderTargetContext*, SkCanvas*, SkString*); \
|
|
|
|
DEF_GM(return new skiagm::SimpleGpuGM(BGCOLOR, SkString(#NAME), {W,H}, \
|
|
|
|
SK_MACRO_CONCAT(NAME,_GM));) \
|
|
|
|
skiagm::DrawResult SK_MACRO_CONCAT(NAME,_GM)( \
|
|
|
|
GrContext* GR_CONTEXT, GrRenderTargetContext* RENDER_TARGET_CONTEXT, SkCanvas* CANVAS, \
|
|
|
|
SkString* ERR_MSG)
|
|
|
|
|
2009-06-10 15:38:48 +00:00
|
|
|
namespace skiagm {
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2019-02-07 23:20:09 +00:00
|
|
|
enum class DrawResult {
|
|
|
|
kOk, // Test drew successfully.
|
|
|
|
kFail, // Test failed to draw.
|
|
|
|
kSkip // Test is not applicable in this context and should be skipped.
|
|
|
|
};
|
|
|
|
|
2009-06-10 15:38:48 +00:00
|
|
|
class GM {
|
|
|
|
public:
|
2019-02-07 23:20:09 +00:00
|
|
|
using DrawResult = skiagm::DrawResult;
|
|
|
|
|
2019-02-07 22:23:36 +00:00
|
|
|
GM(SkColor backgroundColor = SK_ColorWHITE);
|
2009-06-10 15:38:48 +00:00
|
|
|
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; }
|
|
|
|
|
2019-02-07 23:20:09 +00:00
|
|
|
static constexpr char kErrorMsg_DrawSkippedGpuOnly[] = "This test is for GPU configs only.";
|
|
|
|
|
|
|
|
DrawResult draw(SkCanvas* canvas) {
|
|
|
|
SkString errorMsg;
|
|
|
|
return this->draw(canvas, &errorMsg);
|
|
|
|
}
|
|
|
|
DrawResult draw(SkCanvas*, SkString* errorMsg);
|
|
|
|
|
2011-10-31 14:18:20 +00:00
|
|
|
void drawBackground(SkCanvas*);
|
2019-02-07 23:20:09 +00:00
|
|
|
DrawResult drawContent(SkCanvas* canvas) {
|
|
|
|
SkString errorMsg;
|
|
|
|
return this->drawContent(canvas, &errorMsg);
|
|
|
|
}
|
|
|
|
DrawResult drawContent(SkCanvas*, SkString* errorMsg);
|
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
|
|
|
|
2019-02-07 21:18:22 +00:00
|
|
|
virtual bool runAsBench() const;
|
2015-01-23 18:31:45 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2019-02-07 22:23:36 +00:00
|
|
|
// helper: fill a rect in the specified color based on the GM's getISize bounds.
|
2012-01-03 17:20:38 +00:00
|
|
|
void drawSizeBounds(SkCanvas*, SkColor);
|
|
|
|
|
2012-11-16 13:41:45 +00:00
|
|
|
bool isCanvasDeferred() const { return fCanvasIsDeferred; }
|
|
|
|
void setCanvasIsDeferred(bool isDeferred) {
|
|
|
|
fCanvasIsDeferred = isDeferred;
|
|
|
|
}
|
|
|
|
|
2019-03-20 16:55:08 +00:00
|
|
|
bool animate(const AnimTimer&);
|
2016-09-08 16:02:43 +00:00
|
|
|
bool handleKey(SkUnichar uni) {
|
|
|
|
return this->onHandleKey(uni);
|
|
|
|
}
|
2015-02-02 03:01:04 +00:00
|
|
|
|
2018-05-15 14:09:52 +00:00
|
|
|
bool getControls(SkMetaData* controls) { return this->onGetControls(controls); }
|
|
|
|
void setControls(const SkMetaData& controls) { this->onSetControls(controls); }
|
|
|
|
|
2019-06-05 17:54:39 +00:00
|
|
|
virtual void modifyGrContextOptions(GrContextOptions*);
|
2015-05-27 20:23:23 +00:00
|
|
|
|
2015-09-09 15:16:41 +00:00
|
|
|
protected:
|
2019-02-07 21:18:22 +00:00
|
|
|
virtual void onOnceBeforeDraw();
|
|
|
|
virtual DrawResult onDraw(SkCanvas* canvas, SkString* errorMsg);
|
|
|
|
virtual void onDraw(SkCanvas*);
|
|
|
|
|
2012-03-20 17:40:58 +00:00
|
|
|
virtual SkISize onISize() = 0;
|
2009-06-21 00:49:18 +00:00
|
|
|
virtual SkString onShortName() = 0;
|
2015-01-23 19:07:07 +00:00
|
|
|
|
2019-03-20 16:55:08 +00:00
|
|
|
virtual bool onAnimate(const AnimTimer&);
|
2019-02-07 21:18:22 +00:00
|
|
|
virtual bool onHandleKey(SkUnichar uni);
|
|
|
|
virtual bool onGetControls(SkMetaData*);
|
|
|
|
virtual void onSetControls(const SkMetaData&);
|
2012-03-21 17:34:30 +00:00
|
|
|
|
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;
|
2009-06-10 15:38:48 +00:00
|
|
|
};
|
|
|
|
|
2018-07-30 21:07:07 +00:00
|
|
|
typedef GM*(*GMFactory)(void*) ;
|
|
|
|
typedef sk_tools::Registry<GMFactory> GMRegistry;
|
2015-01-12 23:27:46 +00:00
|
|
|
|
2019-02-07 22:23:36 +00:00
|
|
|
// A GpuGM replaces the onDraw method with one that also accepts GPU objects alongside the
|
|
|
|
// SkCanvas. Its onDraw is only invoked on GPU configs; on non-GPU configs it will automatically
|
|
|
|
// draw a GPU-only message and abort.
|
|
|
|
class GpuGM : public GM {
|
2019-02-06 00:42:14 +00:00
|
|
|
public:
|
2019-02-07 22:23:36 +00:00
|
|
|
GpuGM(SkColor backgroundColor = SK_ColorWHITE) : GM(backgroundColor) {}
|
2019-02-07 10:05:55 +00:00
|
|
|
private:
|
2019-02-07 23:20:09 +00:00
|
|
|
using GM::onDraw;
|
|
|
|
DrawResult onDraw(SkCanvas*, SkString* errorMsg) final;
|
2019-02-07 21:18:22 +00:00
|
|
|
|
2019-02-07 23:20:09 +00:00
|
|
|
virtual DrawResult onDraw(GrContext* ctx, GrRenderTargetContext* rtc, SkCanvas* canvas,
|
2019-02-07 21:18:22 +00:00
|
|
|
SkString* errorMsg);
|
|
|
|
virtual void onDraw(GrContext*, GrRenderTargetContext*, SkCanvas*);
|
2019-02-07 22:23:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// SimpleGM is intended for basic GMs that can define their entire implementation inside a
|
|
|
|
// single "draw" function pointer.
|
|
|
|
class SimpleGM : public GM {
|
|
|
|
public:
|
2019-02-07 23:20:09 +00:00
|
|
|
using DrawProc = DrawResult(*)(SkCanvas*, SkString*);
|
2019-02-07 22:23:36 +00:00
|
|
|
SimpleGM(SkColor bgColor, const SkString& name, const SkISize& size, DrawProc drawProc)
|
|
|
|
: GM(bgColor), fName(name), fSize(size), fDrawProc(drawProc) {}
|
|
|
|
|
|
|
|
private:
|
2019-02-07 21:18:22 +00:00
|
|
|
SkISize onISize() override;
|
|
|
|
SkString onShortName() override;
|
|
|
|
DrawResult onDraw(SkCanvas* canvas, SkString* errorMsg) override;
|
2019-02-07 22:23:36 +00:00
|
|
|
|
|
|
|
const SkString fName;
|
|
|
|
const SkISize fSize;
|
|
|
|
const DrawProc fDrawProc;
|
2019-02-06 00:42:14 +00:00
|
|
|
};
|
2019-02-07 22:23:36 +00:00
|
|
|
|
|
|
|
class SimpleGpuGM : public GpuGM {
|
|
|
|
public:
|
2019-02-07 23:20:09 +00:00
|
|
|
using DrawProc = DrawResult(*)(GrContext*, GrRenderTargetContext*, SkCanvas*, SkString*);
|
2019-02-07 22:23:36 +00:00
|
|
|
SimpleGpuGM(SkColor bgColor, const SkString& name, const SkISize& size, DrawProc drawProc)
|
|
|
|
: GpuGM(bgColor), fName(name), fSize(size), fDrawProc(drawProc) {}
|
|
|
|
|
|
|
|
private:
|
2019-02-07 21:18:22 +00:00
|
|
|
SkISize onISize() override;
|
|
|
|
SkString onShortName() override;
|
2019-02-07 23:20:09 +00:00
|
|
|
DrawResult onDraw(GrContext* ctx, GrRenderTargetContext* rtc, SkCanvas* canvas,
|
2019-02-07 21:18:22 +00:00
|
|
|
SkString* errorMsg) override;
|
2019-02-07 22:23:36 +00:00
|
|
|
|
|
|
|
const SkString fName;
|
|
|
|
const SkISize fSize;
|
|
|
|
const DrawProc fDrawProc;
|
|
|
|
};
|
|
|
|
|
2009-06-10 15:38:48 +00:00
|
|
|
}
|
|
|
|
|
2018-10-31 14:49:38 +00:00
|
|
|
void MarkGMGood(SkCanvas*, SkScalar x, SkScalar y);
|
|
|
|
void MarkGMBad (SkCanvas*, SkScalar x, SkScalar y);
|
|
|
|
|
2009-06-10 15:38:48 +00:00
|
|
|
#endif
|