2015-02-21 17:36:50 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "GMSampleView.h"
|
2017-05-16 14:39:06 +00:00
|
|
|
#include "SkData.h"
|
2015-02-21 17:36:50 +00:00
|
|
|
|
|
|
|
GMSampleView::GMSampleView(GM* gm) : fShowSize(false), fGM(gm) {}
|
|
|
|
|
|
|
|
GMSampleView::~GMSampleView() {
|
|
|
|
delete fGM;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkEvent* GMSampleView::NewShowSizeEvt(bool doShowSize) {
|
2015-08-26 20:07:48 +00:00
|
|
|
SkEvent* evt = new SkEvent("GMSampleView::showSize");
|
2015-02-21 17:36:50 +00:00
|
|
|
evt->setFast32(doShowSize);
|
|
|
|
return evt;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GMSampleView::onQuery(SkEvent* evt) {
|
|
|
|
if (SampleCode::TitleQ(*evt)) {
|
|
|
|
SkString name("GM:");
|
|
|
|
name.append(fGM->getName());
|
|
|
|
SampleCode::TitleR(evt, name.c_str());
|
|
|
|
return true;
|
|
|
|
}
|
2016-09-08 16:02:43 +00:00
|
|
|
|
|
|
|
SkUnichar uni;
|
|
|
|
if (SampleCode::CharQ(*evt, &uni)) {
|
|
|
|
if (fGM->handleKey(uni)) {
|
|
|
|
this->inval(nullptr);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-21 17:36:50 +00:00
|
|
|
return this->INHERITED::onQuery(evt);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GMSampleView::onEvent(const SkEvent& evt) {
|
|
|
|
if (evt.isType("GMSampleView::showSize")) {
|
|
|
|
fShowSize = SkToBool(evt.getFast32());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this->INHERITED::onEvent(evt);
|
|
|
|
}
|
|
|
|
|
2016-05-04 20:09:39 +00:00
|
|
|
#include "SkPicture.h"
|
|
|
|
static sk_sp<SkPicture> round_trip_serialize(SkPicture* src) {
|
2016-09-15 14:19:35 +00:00
|
|
|
return SkPicture::MakeFromData(src->serialize().get());
|
2016-05-04 20:09:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "SkPictureRecorder.h"
|
2015-02-21 17:36:50 +00:00
|
|
|
void GMSampleView::onDrawContent(SkCanvas* canvas) {
|
2016-05-04 20:09:39 +00:00
|
|
|
SkPictureRecorder recorder;
|
|
|
|
SkCanvas* origCanvas = canvas;
|
|
|
|
|
|
|
|
if (false) {
|
|
|
|
SkISize size = fGM->getISize();
|
|
|
|
canvas = recorder.beginRecording(SkRect::MakeIWH(size.width(), size.height()));
|
|
|
|
}
|
|
|
|
|
2015-02-21 17:36:50 +00:00
|
|
|
{
|
|
|
|
SkAutoCanvasRestore acr(canvas, fShowSize);
|
|
|
|
fGM->drawContent(canvas);
|
|
|
|
}
|
2016-05-04 20:09:39 +00:00
|
|
|
|
|
|
|
if (origCanvas != canvas) {
|
|
|
|
sk_sp<SkPicture> pic = recorder.finishRecordingAsPicture();
|
|
|
|
if (false) {
|
|
|
|
pic = round_trip_serialize(pic.get());
|
|
|
|
}
|
|
|
|
origCanvas->drawPicture(pic);
|
|
|
|
canvas = origCanvas;
|
|
|
|
}
|
|
|
|
|
2015-02-21 17:36:50 +00:00
|
|
|
if (fShowSize) {
|
|
|
|
SkISize size = fGM->getISize();
|
|
|
|
SkRect r = SkRect::MakeWH(SkIntToScalar(size.width()),
|
|
|
|
SkIntToScalar(size.height()));
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(0x40FF8833);
|
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GMSampleView::onDrawBackground(SkCanvas* canvas) {
|
|
|
|
fGM->drawBackground(canvas);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GMSampleView::onAnimate(const SkAnimTimer& timer) {
|
|
|
|
return fGM->animate(timer);
|
|
|
|
}
|