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"
|
2015-01-31 15:51:14 +00:00
|
|
|
#include "SkShader.h"
|
2011-10-31 14:18:20 +00:00
|
|
|
using namespace skiagm;
|
|
|
|
|
|
|
|
GM::GM() {
|
2014-02-07 21:13:11 +00:00
|
|
|
fMode = kGM_Mode;
|
2011-10-31 14:18:20 +00:00
|
|
|
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
|
|
|
}
|
2014-06-09 19:05:34 +00:00
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2014-02-26 23:01:57 +00:00
|
|
|
const char* GM::getName() {
|
2011-10-31 14:18:20 +00:00
|
|
|
if (fShortName.size() == 0) {
|
|
|
|
fShortName = this->onShortName();
|
|
|
|
}
|
|
|
|
return fShortName.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GM::setBGColor(SkColor color) {
|
|
|
|
fBGColor = color;
|
|
|
|
}
|
|
|
|
|
2015-02-02 20:55:02 +00:00
|
|
|
bool GM::animate(const SkAnimTimer& timer) {
|
|
|
|
return this->onAnimate(timer);
|
2015-02-02 03:01:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-10-31 14:18:20 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2015-01-31 15:51:14 +00:00
|
|
|
void GM::drawGpuOnlyMessage(SkCanvas* canvas) {
|
|
|
|
SkBitmap bmp;
|
|
|
|
bmp.allocN32Pixels(128, 64);
|
|
|
|
SkCanvas bmpCanvas(bmp);
|
|
|
|
bmpCanvas.drawColor(SK_ColorWHITE);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setTextSize(20);
|
|
|
|
paint.setColor(SK_ColorRED);
|
2015-07-28 17:37:53 +00:00
|
|
|
sk_tool_utils::set_portable_typeface(&paint);
|
2015-01-31 15:51:14 +00:00
|
|
|
static const char kTxt[] = "GPU Only";
|
|
|
|
bmpCanvas.drawText(kTxt, strlen(kTxt), 20, 40, paint);
|
|
|
|
SkMatrix localM;
|
|
|
|
localM.setRotate(35.f);
|
|
|
|
localM.postTranslate(10.f, 0.f);
|
|
|
|
SkAutoTUnref<SkShader> shader(SkShader::CreateBitmapShader(bmp, SkShader::kMirror_TileMode,
|
|
|
|
SkShader::kMirror_TileMode,
|
|
|
|
&localM));
|
|
|
|
paint.setShader(shader);
|
|
|
|
paint.setFilterQuality(kMedium_SkFilterQuality);
|
|
|
|
canvas->drawPaint(paint);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-31 14:18:20 +00:00
|
|
|
// need to explicitly declare this, or we get some weird infinite loop llist
|
2014-06-18 21:32:48 +00:00
|
|
|
template GMRegistry* GMRegistry::gHead;
|
2015-01-12 23:27:46 +00:00
|
|
|
|
|
|
|
void skiagm::SimpleGM::onDraw(SkCanvas* canvas) {
|
|
|
|
fDrawProc(canvas);
|
|
|
|
}
|
|
|
|
|
|
|
|
SkISize skiagm::SimpleGM::onISize() {
|
|
|
|
return fSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkString skiagm::SimpleGM::onShortName() {
|
|
|
|
return fName;
|
|
|
|
}
|
2015-02-02 03:01:04 +00:00
|
|
|
|