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.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "bench/SKPBench.h"
|
|
|
|
#include "include/core/SkSurface.h"
|
|
|
|
#include "tools/flags/CommandLineFlags.h"
|
2014-10-21 19:29:25 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/GrContext.h"
|
|
|
|
#include "src/gpu/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.
|
2019-03-21 16:42:21 +00:00
|
|
|
static DEFINE_int(CPUbenchTileW, 256, "Tile width used for CPU SKP playback.");
|
|
|
|
static DEFINE_int(CPUbenchTileH, 256, "Tile height used for CPU SKP playback.");
|
2015-06-16 17:41:27 +00:00
|
|
|
|
2019-03-21 16:42:21 +00:00
|
|
|
static DEFINE_int(GPUbenchTileW, 1600, "Tile width used for GPU SKP playback.");
|
|
|
|
static DEFINE_int(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() {
|
2019-11-15 15:39:50 +00:00
|
|
|
// TODO: remove me
|
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
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrGpu.h"
|
2015-12-02 17:05:37 +00:00
|
|
|
static void draw_pic_for_stats(SkCanvas* canvas, GrContext* context, const SkPicture* picture,
|
2019-03-25 17:32:28 +00:00
|
|
|
SkTArray<SkString>* keys, SkTArray<double>* values) {
|
2019-02-04 18:26:26 +00:00
|
|
|
context->priv().resetGpuStats();
|
2015-12-02 17:05:37 +00:00
|
|
|
canvas->drawPicture(picture);
|
|
|
|
canvas->flush();
|
|
|
|
|
2019-02-04 18:26:26 +00:00
|
|
|
context->priv().dumpGpuStatsKeyValuePairs(keys, values);
|
|
|
|
context->priv().dumpCacheStatsKeyValuePairs(keys, values);
|
2015-12-02 17:05:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2019-02-04 18:26:26 +00:00
|
|
|
context->priv().getGpu()->resetShaderCacheForTesting();
|
2019-03-25 17:32:28 +00:00
|
|
|
draw_pic_for_stats(canvas, context, fPic.get(), keys, values);
|
2015-12-02 17:05:37 +00:00
|
|
|
}
|