Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(380)

Side by Side Diff: dm/DMSerializeTask.cpp

Issue 32613003: DM: add --serialize (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: no-find-copies Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « dm/DMSerializeTask.h ('k') | dm/DMUtil.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #include "DMSerializeTask.h"
2 #include "DMUtil.h"
3 #include "DMWriteTask.h"
4
5 #include "SkCommandLineFlags.h"
6 #include "SkPicture.h"
7 #include "SkPixelRef.h"
8
9 DEFINE_bool(serialize, false, "If true, run picture serialization tests.");
10
11 namespace DM {
12
13 SerializeTask::SerializeTask(const Task& parent,
14 skiagm::GM* gm,
15 SkBitmap reference)
16 : Task(parent)
17 , fName(UnderJoin(parent.name().c_str(), "serialize"))
18 , fGM(gm)
19 , fReference(reference)
20 {}
21
22 static SkData* trivial_bitmap_encoder(size_t* pixelRefOffset, const SkBitmap& bi tmap) {
23 if (NULL == bitmap.pixelRef()) {
24 return NULL;
25 }
26 SkData* data = bitmap.pixelRef()->refEncodedData();
27 *pixelRefOffset = bitmap.pixelRefOffset();
28 return data;
29 }
30
31 void SerializeTask::draw() {
32 SkPicture recorded;
33 RecordPicture(fGM.get(), &recorded);
34
35 SkDynamicMemoryWStream wStream;
36 recorded.serialize(&wStream, &trivial_bitmap_encoder);
37 SkAutoTUnref<SkStream> rStream(wStream.detachAsStream());
38 SkAutoTUnref<SkPicture> reconstructed(SkPicture::CreateFromStream(rStream));
39
40 SkBitmap bitmap;
41 SetupBitmap(fReference.config(), fGM.get(), &bitmap);
42 DrawPicture(reconstructed, &bitmap);
43 if (!BitmapsEqual(bitmap, fReference)) {
44 this->fail();
45 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
46 }
47 }
48
49 bool SerializeTask::shouldSkip() const {
50 return !FLAGS_serialize || fGM->getFlags() & skiagm::GM::kSkipPicture_Flag;
51 }
52
53 } // namespace DM
OLDNEW
« no previous file with comments | « dm/DMSerializeTask.h ('k') | dm/DMUtil.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698