2015-06-30 14:43:14 +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 "VisualSKPBench.h"
|
|
|
|
|
2015-10-26 20:45:29 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
#include "GrContext.h"
|
|
|
|
#endif
|
|
|
|
|
2015-06-30 14:43:14 +00:00
|
|
|
VisualSKPBench::VisualSKPBench(const char* name, const SkPicture* pic)
|
|
|
|
: fPic(SkRef(pic))
|
2015-11-24 16:54:29 +00:00
|
|
|
, fCullRect(fPic->cullRect().roundOut())
|
2015-06-30 14:43:14 +00:00
|
|
|
, fName(name) {
|
|
|
|
fUniqueName.printf("%s", name);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* VisualSKPBench::onGetName() {
|
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* VisualSKPBench::onGetUniqueName() {
|
|
|
|
return fUniqueName.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VisualSKPBench::isSuitableFor(Backend backend) {
|
|
|
|
return backend != kNonRendering_Backend;
|
|
|
|
}
|
|
|
|
|
2015-11-24 16:54:29 +00:00
|
|
|
SkIPoint VisualSKPBench::onGetSize() {
|
|
|
|
return SkIPoint::Make(fCullRect.width(), fCullRect.height());
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void VisualSKPBench::onDraw(int loops, SkCanvas* canvas) {
|
2015-11-24 16:54:29 +00:00
|
|
|
bool isOffset = SkToBool(fCullRect.left() | fCullRect.top());
|
|
|
|
if (isOffset) {
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(SkIntToScalar(-fCullRect.left()), SkIntToScalar(-fCullRect.top()));
|
|
|
|
}
|
|
|
|
|
2015-06-30 14:43:14 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
|
|
|
canvas->drawPicture(fPic);
|
2015-10-26 20:45:29 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
// Ensure the GrContext doesn't batch across draw loops.
|
|
|
|
if (GrContext* context = canvas->getGrContext()) {
|
|
|
|
context->flush();
|
|
|
|
}
|
|
|
|
#endif
|
2015-06-30 14:43:14 +00:00
|
|
|
}
|
2015-11-24 16:54:29 +00:00
|
|
|
|
|
|
|
if (isOffset) {
|
|
|
|
canvas->restore();
|
|
|
|
}
|
2015-06-30 14:43:14 +00:00
|
|
|
}
|