skia2/dm/DMTileGridTask.cpp
commit-bot@chromium.org ef57b7e653 DM: make GPU tasks multithreaded again. Big refactor.
The main meat of things is in SkThreadPool.  We can now give SkThreadPool a
type for each thread to create and destroy on its local stack.  It's TLS
without going through SkTLS.

I've split the DM tasks into CpuTasks that run on threads with no TLS, and
GpuTasks that run on threads with a thread local GrContextFactory.

The old CpuTask and GpuTask have been renamed to CpuGMTask and GpuGMTask.

Upshot: default run of out/Debug/dm goes from ~45 seconds to ~20 seconds.

BUG=skia:
R=bsalomon@google.com, mtklein@google.com, reed@google.com

Author: mtklein@chromium.org

Review URL: https://codereview.chromium.org/179233005

git-svn-id: http://skia.googlecode.com/svn/trunk@13632 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-02-28 20:31:31 +00:00

81 lines
2.6 KiB
C++

#include "DMTileGridTask.h"
#include "DMWriteTask.h"
#include "DMUtil.h"
#include "SkCommandLineFlags.h"
#include "SkPicture.h"
#include "SkTileGridPicture.h"
// TODO(mtklein): Tile grid tests are currently failing. (Skia issue 1198). When fixed, -> true.
DEFINE_bool(tileGrid, false, "If true, run picture replay tests with a tile grid.");
namespace DM {
TileGridTask::TileGridTask(const Task& parent, skiagm::GM* gm, SkBitmap reference, SkISize tileSize)
: CpuTask(parent)
, fName(UnderJoin(parent.name().c_str(), "tilegrid"))
, fGM(gm)
, fReference(reference)
, fTileSize(tileSize)
{}
static int tiles_needed(int fullDimension, int tileDimension) {
return (fullDimension + tileDimension - 1) / tileDimension;
}
void TileGridTask::draw() {
const SkTileGridPicture::TileGridInfo info = {
fTileSize,
SkISize::Make(0,0), // Overlap between adjacent tiles.
SkIPoint::Make(0,0), // Offset.
};
const SkISize size = fGM->getISize();
SkTileGridPicture recorded(size.width(), size.height(), info);
RecordPicture(fGM.get(), &recorded, SkPicture::kUsePathBoundsForClip_RecordingFlag);
SkBitmap full;
SetupBitmap(fReference.colorType(), fGM.get(), &full);
SkCanvas fullCanvas(full);
SkBitmap tile;
tile.allocPixels(SkImageInfo::Make(fTileSize.width(), fTileSize.height(),
fReference.colorType(), kPremul_SkAlphaType));
SkCanvas tileCanvas(tile);
SkPaint paint;
paint.setXfermodeMode(SkXfermode::kSrc_Mode);
for (int y = 0; y < tiles_needed(full.height(), tile.height()); y++) {
for (int x = 0; x < tiles_needed(full.width(), tile.width()); x++) {
SkAutoCanvasRestore ar(&tileCanvas, true/*also save now*/);
const SkScalar xOffset = SkIntToScalar(x * tile.width()),
yOffset = SkIntToScalar(y * tile.height());
SkMatrix matrix = tileCanvas.getTotalMatrix();
matrix.postTranslate(-xOffset, -yOffset);
tileCanvas.setMatrix(matrix);
recorded.draw(&tileCanvas);
tileCanvas.flush();
fullCanvas.drawBitmap(tile, xOffset, yOffset, &paint);
}
}
if (!BitmapsEqual(full, fReference)) {
this->fail();
this->spawnChild(SkNEW_ARGS(WriteTask, (*this, full)));
}
}
bool TileGridTask::shouldSkip() const {
if (fGM->getFlags() & skiagm::GM::kSkipPicture_Flag) {
return true;
}
if (fGM->getFlags() & skiagm::GM::kSkipTiled_Flag) {
return true;
}
return !FLAGS_tileGrid;
}
} // namespace DM