skia2/dm/DMRecordTask.cpp
commit-bot@chromium.org a095041f51 Remove SkRecorder's kWriteOnly mode.
I'm soon going to have SkRecorder start calling getTotalMatrix(), which
would be broken in write-only mode.  That change is big and nebulous,
but it's clear kWriteOnly needs to go, so we might as well kill it now.

My notes in bench_playback about kWriteOnly mode being important were
probably overly cautious.  I now think this is a fair enough comparison
even re-recording into a read-write canvas.

BUG=skia:2378
R=fmalita@chromium.org, mtklein@google.com

Author: mtklein@chromium.org

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

git-svn-id: http://skia.googlecode.com/svn/trunk@14963 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-05-29 16:52:40 +00:00

64 lines
1.6 KiB
C++

#include "DMRecordTask.h"
#include "DMUtil.h"
#include "DMWriteTask.h"
#include "SkCommandLineFlags.h"
#include "SkRecord.h"
#include "SkRecordDraw.h"
#include "SkRecordOpts.h"
#include "SkRecorder.h"
DEFINE_bool(skr, true, "If true, run SKR tests.");
namespace DM {
RecordTask::RecordTask(const Task& parent, skiagm::GM* gm, SkBitmap reference, Mode mode)
: CpuTask(parent)
, fOptimize(mode == kOptimize_Mode)
, fName(UnderJoin(parent.name().c_str(), fOptimize ? "skr" : "skr-noopt"))
, fGM(gm)
, fReference(reference)
{}
RecordTask::RecordTask(const Task& parent, SkPicture* pic, SkBitmap reference, Mode mode)
: CpuTask(parent)
, fOptimize(mode == kOptimize_Mode)
, fName(UnderJoin(parent.name().c_str(), fOptimize ? "skr" : "skr-noopt"))
, fPicture(SkRef(pic))
, fReference(reference)
{}
void RecordTask::draw() {
// Record into an SkRecord.
SkRecord record;
SkRecorder recorder(&record, fReference.width(), fReference.height());
if (fGM.get()) {
recorder.concat(fGM->getInitialTransform());
fGM->draw(&recorder);
} else {
fPicture->draw(&recorder);
}
if (fOptimize) {
SkRecordOptimize(&record);
}
// Draw the SkRecord back into a bitmap.
SkBitmap bitmap;
AllocatePixels(fReference, &bitmap);
SkCanvas target(bitmap);
SkRecordDraw(record, &target);
if (!BitmapsEqual(bitmap, fReference)) {
this->fail();
this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
}
}
bool RecordTask::shouldSkip() const {
return !FLAGS_skr;
}
} // namespace DM