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.
|
|
|
|
*/
|
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"
|
2013-08-29 11:54:56 +00:00
|
|
|
#include "SkBitmapDevice.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"
|
|
|
|
|
2013-09-16 20:42:15 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
#include "GrContext.h"
|
|
|
|
#endif
|
|
|
|
|
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_));
|
|
|
|
|
2009-06-10 15:38:48 +00:00
|
|
|
namespace skiagm {
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2013-03-13 14:18:40 +00:00
|
|
|
static inline SkISize make_isize(int w, int h) {
|
|
|
|
SkISize sz;
|
|
|
|
sz.set(w, h);
|
|
|
|
return sz;
|
|
|
|
}
|
2009-06-10 15:38:48 +00:00
|
|
|
|
|
|
|
class GM {
|
|
|
|
public:
|
|
|
|
GM();
|
|
|
|
virtual ~GM();
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-09-19 19:08:33 +00:00
|
|
|
enum Flags {
|
2013-08-16 19:18:12 +00:00
|
|
|
kSkipPDF_Flag = 1 << 0,
|
|
|
|
kSkipPicture_Flag = 1 << 1,
|
|
|
|
kSkipPipe_Flag = 1 << 2,
|
|
|
|
kSkipPipeCrossProcess_Flag = 1 << 3,
|
|
|
|
kSkipTiled_Flag = 1 << 4,
|
|
|
|
kSkip565_Flag = 1 << 5,
|
|
|
|
kSkipScaledReplay_Flag = 1 << 6,
|
|
|
|
kSkipGPU_Flag = 1 << 7,
|
2013-08-20 23:08:40 +00:00
|
|
|
kSkipPDFRasterization_Flag = 1 << 8,
|
2013-08-21 19:27:48 +00:00
|
|
|
|
|
|
|
kGPUOnly_Flag = 1 << 9,
|
2011-09-19 19:08:33 +00:00
|
|
|
};
|
|
|
|
|
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
|
|
|
|
2012-03-20 17:40:58 +00:00
|
|
|
SkISize getISize() { return this->onISize(); }
|
2011-10-31 14:18:20 +00:00
|
|
|
const char* shortName();
|
2009-06-10 15:38:48 +00:00
|
|
|
|
2011-09-19 19:08:33 +00:00
|
|
|
uint32_t getFlags() const {
|
|
|
|
return this->onGetFlags();
|
|
|
|
}
|
2012-03-21 17:34:30 +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
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
return this->onGetInitialTransform();
|
|
|
|
}
|
|
|
|
|
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-08-23 18:14:13 +00:00
|
|
|
static void SetResourcePath(const char* resourcePath) {
|
|
|
|
gResourcePath = resourcePath;
|
2012-03-20 17:40:58 +00:00
|
|
|
}
|
|
|
|
|
2013-06-14 15:33:20 +00:00
|
|
|
static SkString& GetResourcePath() {
|
|
|
|
return gResourcePath;
|
|
|
|
}
|
|
|
|
|
2012-11-16 13:41:45 +00:00
|
|
|
bool isCanvasDeferred() const { return fCanvasIsDeferred; }
|
|
|
|
void setCanvasIsDeferred(bool isDeferred) {
|
|
|
|
fCanvasIsDeferred = isDeferred;
|
|
|
|
}
|
|
|
|
|
2013-09-16 20:42:15 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
static GrContext* GetGr(/*very nearly const*/ SkCanvas*);
|
|
|
|
#endif
|
|
|
|
|
2012-03-20 17:40:58 +00:00
|
|
|
protected:
|
|
|
|
static SkString gResourcePath;
|
|
|
|
|
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;
|
2011-09-19 19:08:33 +00:00
|
|
|
virtual uint32_t onGetFlags() const { return 0; }
|
2012-03-21 17:34:30 +00:00
|
|
|
virtual SkMatrix onGetInitialTransform() const { return SkMatrix::I(); }
|
|
|
|
|
2009-06-21 00:49:18 +00:00
|
|
|
private:
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2013-09-04 17:20:18 +00:00
|
|
|
typedef SkTRegistry<GM*(*)(void*)> GMRegistry;
|
2009-06-10 15:38:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|