blob: e5f392cee4a13dbed0f802c6dfedd836d31be165 [file] [log] [blame]
mtklein@google.comd36522d2013-10-16 13:02:15 +00001#include "DMReplayTask.h"
2#include "DMUtil.h"
3
4#include "SkPicture.h"
5
6namespace DM {
7
8ReplayTask::ReplayTask(const char* suffix,
9 const Task& parent,
10 skiagm::GM* gm,
commit-bot@chromium.org66bb3d12013-10-16 19:13:38 +000011 SkBitmap reference)
mtklein@google.comd36522d2013-10-16 13:02:15 +000012 : Task(parent)
13 , fName(underJoin(parent.name().c_str(), suffix))
14 , fGM(gm)
15 , fReference(reference)
mtklein@google.comd36522d2013-10-16 13:02:15 +000016 {}
17
18void ReplayTask::draw() {
19 SkPicture picture;
commit-bot@chromium.org846872f2013-10-16 18:21:03 +000020 SkCanvas* canvas = picture.beginRecording(SkScalarCeilToInt(fGM->width()),
21 SkScalarCeilToInt(fGM->height()),
22 0 /*flags*/);
mtklein@google.comd36522d2013-10-16 13:02:15 +000023
24 canvas->concat(fGM->getInitialTransform());
25 fGM->draw(canvas);
26 canvas->flush();
27
28 picture.endRecording();
29
30 SkBitmap bitmap;
commit-bot@chromium.org66bb3d12013-10-16 19:13:38 +000031 bitmap.setConfig(fReference.config(),
32 SkScalarCeilToInt(fGM->width()),
33 SkScalarCeilToInt(fGM->height()));
mtklein@google.comd36522d2013-10-16 13:02:15 +000034 bitmap.allocPixels();
35 bitmap.eraseColor(0x00000000);
36
37 SkCanvas replay(bitmap);
38 replay.drawPicture(picture);
39 replay.flush();
40
commit-bot@chromium.org66bb3d12013-10-16 19:13:38 +000041 const SkAutoLockPixels mine(bitmap), theirs(fReference);
42 if (bitmap.getSize() != fReference.getSize() ||
43 0 != memcmp(bitmap.getPixels(), fReference.getPixels(), bitmap.getSize()))
44 {
mtklein@google.comd36522d2013-10-16 13:02:15 +000045 this->fail();
46 }
47}
48
49bool ReplayTask::shouldSkip() const {
50 return fGM->getFlags() & skiagm::GM::kGPUOnly_Flag ||
51 fGM->getFlags() & skiagm::GM::kSkipPicture_Flag;
52}
53
54} // namespace