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-10-26 20:45:29 +00:00
|
|
|
#include "GrContext.h"
|
2018-01-22 15:48:15 +00:00
|
|
|
#include "GrContextPriv.h"
|
2015-10-26 20:45:29 +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) {
|
2017-01-23 16:39:45 +00:00
|
|
|
SkIRect bounds = canvas->getDeviceClipBounds();
|
|
|
|
SkAssertResult(!bounds.isEmpty());
|
2014-11-21 14:19:36 +00:00
|
|
|
|
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
|
|
|
|
2018-07-12 17:30:47 +00:00
|
|
|
fSurfaces.reserve(xTiles * yTiles);
|
2014-11-21 14:19:36 +00:00
|
|
|
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;
|
2018-07-12 17:30:47 +00:00
|
|
|
fSurfaces.emplace_back(canvas->makeSurface(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));
|
2018-07-12 17:30:47 +00:00
|
|
|
fSurfaces.back()->getCanvas()->clipRect(clip);
|
2014-12-04 16:31:02 +00:00
|
|
|
|
2018-07-12 17:30:47 +00:00
|
|
|
fSurfaces.back()->getCanvas()->setMatrix(canvas->getTotalMatrix());
|
|
|
|
fSurfaces.back()->getCanvas()->scale(fScale, fScale);
|
2014-11-21 14:19:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> image(fSurfaces[i]->makeImageSnapshot());
|
2014-11-21 14:53:00 +00:00
|
|
|
canvas->drawImage(image,
|
2014-11-21 14:19:36 +00:00
|
|
|
SkIntToScalar(fTileRects[i].fLeft), SkIntToScalar(fTileRects[i].fTop));
|
|
|
|
}
|
|
|
|
|
2018-07-12 17:30:47 +00:00
|
|
|
fSurfaces.reset();
|
2014-11-21 14:19:36 +00:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void SKPBench::onDraw(int loops, SkCanvas* canvas) {
|
2015-06-25 17:51:56 +00:00
|
|
|
SkASSERT(fDoLooping || 1 == loops);
|
2016-02-22 16:08:25 +00:00
|
|
|
while (1) {
|
|
|
|
if (fUseMultiPictureDraw) {
|
2015-04-27 16:16:57 +00:00
|
|
|
this->drawMPDPicture();
|
2016-02-22 16:08:25 +00:00
|
|
|
} else {
|
2015-04-27 16:16:57 +00:00
|
|
|
this->drawPicture();
|
2014-11-21 14:19:36 +00:00
|
|
|
}
|
2016-02-22 16:08:25 +00:00
|
|
|
if (0 == --loops) {
|
|
|
|
break;
|
|
|
|
}
|
2016-12-21 16:14:46 +00:00
|
|
|
// Ensure the GrContext doesn't combine ops across draw loops.
|
2016-02-22 16:08:25 +00:00
|
|
|
if (GrContext* context = canvas->getGrContext()) {
|
|
|
|
context->flush();
|
|
|
|
}
|
|
|
|
}
|
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);
|
2016-11-04 17:02:54 +00:00
|
|
|
mpd.add(fSurfaces[j]->getCanvas(), fPic.get(), &trans);
|
2015-04-27 16:16:57 +00:00
|
|
|
}
|
|
|
|
|
2018-10-31 16:45:12 +00:00
|
|
|
// We flush after each picture to more closely model how Chrome rasterizes tiles.
|
|
|
|
mpd.draw(/*flush = */ true);
|
2015-04-27 16:16:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SKPBench::drawPicture() {
|
|
|
|
for (int j = 0; j < fTileRects.count(); ++j) {
|
|
|
|
const SkMatrix trans = SkMatrix::MakeTrans(-fTileRects[j].fLeft / fScale,
|
|
|
|
-fTileRects[j].fTop / fScale);
|
2016-11-04 17:02:54 +00:00
|
|
|
fSurfaces[j]->getCanvas()->drawPicture(fPic.get(), &trans, nullptr);
|
2015-04-27 16:16:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int j = 0; j < fTileRects.count(); ++j) {
|
|
|
|
fSurfaces[j]->getCanvas()->flush();
|
|
|
|
}
|
|
|
|
}
|
2015-12-02 17:05:37 +00:00
|
|
|
|
2015-12-02 21:36:47 +00:00
|
|
|
#include "GrGpu.h"
|
2015-12-02 17:05:37 +00:00
|
|
|
static void draw_pic_for_stats(SkCanvas* canvas, GrContext* context, const SkPicture* picture,
|
|
|
|
SkTArray<SkString>* keys, SkTArray<double>* values,
|
|
|
|
const char* tag) {
|
2018-03-06 13:20:37 +00:00
|
|
|
context->contextPriv().resetGpuStats();
|
2015-12-02 17:05:37 +00:00
|
|
|
canvas->drawPicture(picture);
|
|
|
|
canvas->flush();
|
|
|
|
|
|
|
|
int offset = keys->count();
|
2018-03-06 13:20:37 +00:00
|
|
|
context->contextPriv().dumpGpuStatsKeyValuePairs(keys, values);
|
|
|
|
context->contextPriv().dumpCacheStatsKeyValuePairs(keys, values);
|
2015-12-02 17:05:37 +00:00
|
|
|
|
|
|
|
// append tag, but only to new tags
|
|
|
|
for (int i = offset; i < keys->count(); i++, offset++) {
|
|
|
|
(*keys)[i].appendf("_%s", tag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SKPBench::getGpuStats(SkCanvas* canvas, SkTArray<SkString>* keys, SkTArray<double>* values) {
|
|
|
|
// we do a special single draw and then dump the key / value pairs
|
|
|
|
GrContext* context = canvas->getGrContext();
|
|
|
|
if (!context) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO refactor this out if we want to test other subclasses of skpbench
|
|
|
|
context->flush();
|
|
|
|
context->freeGpuResources();
|
|
|
|
context->resetContext();
|
2018-01-22 15:48:15 +00:00
|
|
|
context->contextPriv().getGpu()->resetShaderCacheForTesting();
|
2016-11-04 17:02:54 +00:00
|
|
|
draw_pic_for_stats(canvas, context, fPic.get(), keys, values, "first_frame");
|
2015-12-02 17:05:37 +00:00
|
|
|
|
|
|
|
// draw second frame
|
2016-11-04 17:02:54 +00:00
|
|
|
draw_pic_for_stats(canvas, context, fPic.get(), keys, values, "second_frame");
|
2015-12-02 17:05:37 +00:00
|
|
|
}
|