2014-08-01 14:46:52 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SKPBench.h"
|
2014-10-21 19:29:25 +00:00
|
|
|
#include "SkCommandLineFlags.h"
|
2014-11-21 14:19:36 +00:00
|
|
|
#include "SkMultiPictureDraw.h"
|
|
|
|
#include "SkSurface.h"
|
2014-10-21 19:29:25 +00:00
|
|
|
|
2015-06-16 17:41:27 +00:00
|
|
|
// These CPU tile sizes are not good per se, but they are similar to what Chrome uses.
|
|
|
|
DEFINE_int32(CPUbenchTileW, 256, "Tile width used for CPU SKP playback.");
|
|
|
|
DEFINE_int32(CPUbenchTileH, 256, "Tile height used for CPU SKP playback.");
|
|
|
|
|
|
|
|
DEFINE_int32(GPUbenchTileW, 1600, "Tile width used for GPU SKP playback.");
|
|
|
|
DEFINE_int32(GPUbenchTileH, 512, "Tile height used for GPU SKP playback.");
|
2014-08-01 14:46:52 +00:00
|
|
|
|
2014-11-21 14:19:36 +00:00
|
|
|
SKPBench::SKPBench(const char* name, const SkPicture* pic, const SkIRect& clip, SkScalar scale,
|
2015-06-25 17:51:56 +00:00
|
|
|
bool useMultiPictureDraw, bool doLooping)
|
2014-08-01 14:46:52 +00:00
|
|
|
: fPic(SkRef(pic))
|
|
|
|
, fClip(clip)
|
2014-09-10 19:05:59 +00:00
|
|
|
, fScale(scale)
|
2014-11-21 14:19:36 +00:00
|
|
|
, fName(name)
|
2015-06-25 17:51:56 +00:00
|
|
|
, fUseMultiPictureDraw(useMultiPictureDraw)
|
|
|
|
, fDoLooping(doLooping) {
|
2015-01-26 14:47:55 +00:00
|
|
|
fUniqueName.printf("%s_%.2g", name, scale); // Scale makes this unqiue for perf.skia.org traces.
|
2014-11-21 14:19:36 +00:00
|
|
|
if (useMultiPictureDraw) {
|
|
|
|
fUniqueName.append("_mpd");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SKPBench::~SKPBench() {
|
|
|
|
for (int i = 0; i < fSurfaces.count(); ++i) {
|
|
|
|
fSurfaces[i]->unref();
|
|
|
|
}
|
2014-08-01 14:46:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* SKPBench::onGetName() {
|
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2014-09-10 19:05:59 +00:00
|
|
|
const char* SKPBench::onGetUniqueName() {
|
|
|
|
return fUniqueName.c_str();
|
|
|
|
}
|
|
|
|
|
2014-11-21 14:19:36 +00:00
|
|
|
void SKPBench::onPerCanvasPreDraw(SkCanvas* canvas) {
|
|
|
|
SkIRect bounds;
|
|
|
|
SkAssertResult(canvas->getClipDeviceBounds(&bounds));
|
|
|
|
|
2015-06-16 17:41:27 +00:00
|
|
|
const bool gpu = canvas->getGrContext() != nullptr;
|
|
|
|
int tileW = gpu ? FLAGS_GPUbenchTileW : FLAGS_CPUbenchTileW,
|
|
|
|
tileH = gpu ? FLAGS_GPUbenchTileH : FLAGS_CPUbenchTileH;
|
|
|
|
|
|
|
|
tileW = SkTMin(tileW, bounds.width());
|
|
|
|
tileH = SkTMin(tileH, bounds.height());
|
2015-03-05 21:42:27 +00:00
|
|
|
|
|
|
|
int xTiles = SkScalarCeilToInt(bounds.width() / SkIntToScalar(tileW));
|
|
|
|
int yTiles = SkScalarCeilToInt(bounds.height() / SkIntToScalar(tileH));
|
2014-11-21 14:19:36 +00:00
|
|
|
|
|
|
|
fSurfaces.setReserve(xTiles * yTiles);
|
|
|
|
fTileRects.setReserve(xTiles * yTiles);
|
|
|
|
|
2015-03-05 21:42:27 +00:00
|
|
|
SkImageInfo ii = canvas->imageInfo().makeWH(tileW, tileH);
|
2014-11-21 14:19:36 +00:00
|
|
|
|
2015-03-05 21:42:27 +00:00
|
|
|
for (int y = bounds.fTop; y < bounds.fBottom; y += tileH) {
|
|
|
|
for (int x = bounds.fLeft; x < bounds.fRight; x += tileW) {
|
|
|
|
const SkIRect tileRect = SkIRect::MakeXYWH(x, y, tileW, tileH);
|
2014-12-04 16:31:02 +00:00
|
|
|
*fTileRects.append() = tileRect;
|
2014-11-21 14:19:36 +00:00
|
|
|
*fSurfaces.push() = canvas->newSurface(ii);
|
2014-12-04 16:31:02 +00:00
|
|
|
|
|
|
|
// Never want the contents of a tile to include stuff the parent
|
|
|
|
// canvas clips out
|
|
|
|
SkRect clip = SkRect::Make(bounds);
|
|
|
|
clip.offset(-SkIntToScalar(tileRect.fLeft), -SkIntToScalar(tileRect.fTop));
|
|
|
|
fSurfaces.top()->getCanvas()->clipRect(clip);
|
|
|
|
|
2014-11-21 14:19:36 +00:00
|
|
|
fSurfaces.top()->getCanvas()->setMatrix(canvas->getTotalMatrix());
|
|
|
|
fSurfaces.top()->getCanvas()->scale(fScale, fScale);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SKPBench::onPerCanvasPostDraw(SkCanvas* canvas) {
|
|
|
|
// Draw the last set of tiles into the master canvas in case we're
|
|
|
|
// saving the images
|
|
|
|
for (int i = 0; i < fTileRects.count(); ++i) {
|
2014-11-21 14:53:00 +00:00
|
|
|
SkAutoTUnref<SkImage> image(fSurfaces[i]->newImageSnapshot());
|
|
|
|
canvas->drawImage(image,
|
2014-11-21 14:19:36 +00:00
|
|
|
SkIntToScalar(fTileRects[i].fLeft), SkIntToScalar(fTileRects[i].fTop));
|
|
|
|
SkSafeSetNull(fSurfaces[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
fSurfaces.rewind();
|
|
|
|
fTileRects.rewind();
|
|
|
|
}
|
|
|
|
|
2014-08-01 14:46:52 +00:00
|
|
|
bool SKPBench::isSuitableFor(Backend backend) {
|
|
|
|
return backend != kNonRendering_Backend;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkIPoint SKPBench::onGetSize() {
|
|
|
|
return SkIPoint::Make(fClip.width(), fClip.height());
|
|
|
|
}
|
|
|
|
|
|
|
|
void SKPBench::onDraw(const int loops, SkCanvas* canvas) {
|
2015-06-25 17:51:56 +00:00
|
|
|
SkASSERT(fDoLooping || 1 == loops);
|
2014-11-21 14:19:36 +00:00
|
|
|
if (fUseMultiPictureDraw) {
|
|
|
|
for (int i = 0; i < loops; i++) {
|
2015-04-27 16:16:57 +00:00
|
|
|
this->drawMPDPicture();
|
2014-11-21 13:35:54 +00:00
|
|
|
}
|
2014-11-21 14:19:36 +00:00
|
|
|
} else {
|
|
|
|
for (int i = 0; i < loops; i++) {
|
2015-04-27 16:16:57 +00:00
|
|
|
this->drawPicture();
|
2014-11-21 14:19:36 +00:00
|
|
|
}
|
2014-10-21 19:29:25 +00:00
|
|
|
}
|
2014-08-01 14:46:52 +00:00
|
|
|
}
|
2015-04-27 16:16:57 +00:00
|
|
|
|
|
|
|
void SKPBench::drawMPDPicture() {
|
|
|
|
SkMultiPictureDraw mpd;
|
|
|
|
|
|
|
|
for (int j = 0; j < fTileRects.count(); ++j) {
|
|
|
|
SkMatrix trans;
|
|
|
|
trans.setTranslate(-fTileRects[j].fLeft/fScale,
|
|
|
|
-fTileRects[j].fTop/fScale);
|
|
|
|
mpd.add(fSurfaces[j]->getCanvas(), fPic, &trans);
|
|
|
|
}
|
|
|
|
|
|
|
|
mpd.draw();
|
|
|
|
|
|
|
|
for (int j = 0; j < fTileRects.count(); ++j) {
|
|
|
|
fSurfaces[j]->getCanvas()->flush();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SKPBench::drawPicture() {
|
|
|
|
for (int j = 0; j < fTileRects.count(); ++j) {
|
|
|
|
const SkMatrix trans = SkMatrix::MakeTrans(-fTileRects[j].fLeft / fScale,
|
|
|
|
-fTileRects[j].fTop / fScale);
|
|
|
|
fSurfaces[j]->getCanvas()->drawPicture(fPic, &trans, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int j = 0; j < fTileRects.count(); ++j) {
|
|
|
|
fSurfaces[j]->getCanvas()->flush();
|
|
|
|
}
|
|
|
|
}
|