2011-10-31 14:18:20 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gm.h"
|
|
|
|
using namespace skiagm;
|
|
|
|
|
2012-03-20 17:40:58 +00:00
|
|
|
SkString GM::gResourcePath;
|
|
|
|
|
2011-10-31 14:18:20 +00:00
|
|
|
GM::GM() {
|
|
|
|
fBGColor = SK_ColorWHITE;
|
2012-11-16 13:41:45 +00:00
|
|
|
fCanvasIsDeferred = false;
|
2012-11-27 15:15:58 +00:00
|
|
|
fHaveCalledOnceBeforeDraw = false;
|
2013-09-26 20:44:24 +00:00
|
|
|
fStarterMatrix.reset();
|
2011-10-31 14:18:20 +00:00
|
|
|
}
|
|
|
|
GM::~GM() {}
|
|
|
|
|
|
|
|
void GM::draw(SkCanvas* canvas) {
|
|
|
|
this->drawBackground(canvas);
|
|
|
|
this->drawContent(canvas);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GM::drawContent(SkCanvas* canvas) {
|
2012-11-27 15:15:58 +00:00
|
|
|
if (!fHaveCalledOnceBeforeDraw) {
|
|
|
|
fHaveCalledOnceBeforeDraw = true;
|
|
|
|
this->onOnceBeforeDraw();
|
|
|
|
}
|
2011-10-31 14:18:20 +00:00
|
|
|
this->onDraw(canvas);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GM::drawBackground(SkCanvas* canvas) {
|
2012-11-27 15:15:58 +00:00
|
|
|
if (!fHaveCalledOnceBeforeDraw) {
|
|
|
|
fHaveCalledOnceBeforeDraw = true;
|
|
|
|
this->onOnceBeforeDraw();
|
|
|
|
}
|
2011-10-31 14:18:20 +00:00
|
|
|
this->onDrawBackground(canvas);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* GM::shortName() {
|
|
|
|
if (fShortName.size() == 0) {
|
|
|
|
fShortName = this->onShortName();
|
|
|
|
}
|
|
|
|
return fShortName.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GM::setBGColor(SkColor color) {
|
|
|
|
fBGColor = color;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GM::onDrawBackground(SkCanvas* canvas) {
|
2012-11-02 17:38:28 +00:00
|
|
|
canvas->drawColor(fBGColor, SkXfermode::kSrc_Mode);
|
2011-10-31 14:18:20 +00:00
|
|
|
}
|
|
|
|
|
2012-01-03 17:20:38 +00:00
|
|
|
void GM::drawSizeBounds(SkCanvas* canvas, SkColor color) {
|
|
|
|
SkISize size = this->getISize();
|
|
|
|
SkRect r = SkRect::MakeWH(SkIntToScalar(size.width()),
|
|
|
|
SkIntToScalar(size.height()));
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(color);
|
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
}
|
|
|
|
|
2013-09-16 20:42:15 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
// canvas could almost be a const&, but accessRenderTarget isn't const.
|
|
|
|
/*static*/ GrContext* GM::GetGr(SkCanvas* canvas) {
|
|
|
|
SkASSERT(NULL != canvas);
|
|
|
|
SkBaseDevice* device = canvas->getTopDevice();
|
|
|
|
GrRenderTarget* renderTarget = device->accessRenderTarget();
|
|
|
|
if (NULL != renderTarget) {
|
|
|
|
return renderTarget->getContext();
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-10-31 14:18:20 +00:00
|
|
|
// need to explicitly declare this, or we get some weird infinite loop llist
|
2013-09-04 17:20:18 +00:00
|
|
|
template GMRegistry* SkTRegistry<GM*(*)(void*)>::gHead;
|