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

Side by Side Diff: dm/DMWriteTask.cpp

Issue 553583004: Remove expectations / -r from DM entirely. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 6 years, 3 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
« no previous file with comments | « dm/DMWriteTask.h ('k') | gyp/dm.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include "DMWriteTask.h" 1 #include "DMWriteTask.h"
2 2
3 #include "DMUtil.h" 3 #include "DMUtil.h"
4 #include "SkColorPriv.h" 4 #include "SkColorPriv.h"
5 #include "SkCommonFlags.h" 5 #include "SkCommonFlags.h"
6 #include "SkData.h"
6 #include "SkImageEncoder.h" 7 #include "SkImageEncoder.h"
7 #include "SkMD5.h" 8 #include "SkMD5.h"
8 #include "SkMallocPixelRef.h" 9 #include "SkMallocPixelRef.h"
9 #include "SkOSFile.h" 10 #include "SkOSFile.h"
10 #include "SkStream.h" 11 #include "SkStream.h"
11 #include "SkString.h" 12 #include "SkString.h"
12 13
13 DEFINE_bool(nameByHash, false, "If true, write .../hash.png instead of .../mode/ config/name.png"); 14 DEFINE_bool(nameByHash, false, "If true, write .../hash.png instead of .../mode/ config/name.png");
14 15
15 namespace DM { 16 namespace DM {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 name.appendf("%s/", fSuffixes[i].c_str()); 152 name.appendf("%s/", fSuffixes[i].c_str());
152 } 153 }
153 name.append(fBaseName.c_str()); 154 name.append(fBaseName.c_str());
154 return name; 155 return name;
155 } 156 }
156 157
157 bool WriteTask::shouldSkip() const { 158 bool WriteTask::shouldSkip() const {
158 return FLAGS_writePath.isEmpty(); 159 return FLAGS_writePath.isEmpty();
159 } 160 }
160 161
161 WriteTask::Expectations* WriteTask::Expectations::Create(const char* path) {
162 if (!FLAGS_writePath.isEmpty() && 0 == strcmp(FLAGS_writePath[0], path)) {
163 SkDebugf("We seem to be reading and writing %s concurrently. This won't work.\n", path);
164 return NULL;
165 }
166
167 SkString jsonPath;
168 if (sk_isdir(path)) {
169 jsonPath = SkOSPath::Join(path, "dm.json");
170 } else {
171 jsonPath.set(path);
172 }
173
174 SkAutoDataUnref json(SkData::NewFromFileName(jsonPath.c_str()));
175 if (NULL == json.get()) {
176 SkDebugf("Can't read %s!\n", jsonPath.c_str());
177 return NULL;
178 }
179
180 SkAutoTDelete<Expectations> expectations(SkNEW(Expectations));
181 Json::Reader reader;
182 const char* begin = (const char*)json->bytes();
183 const char* end = begin + json->size();
184 if (!reader.parse(begin, end, expectations->fJson)) {
185 SkDebugf("Can't read %s as JSON!\n", jsonPath.c_str());
186 return NULL;
187 }
188 return expectations.detach();
189 }
190
191 bool WriteTask::Expectations::check(const Task& task, SkBitmap bitmap) const {
192 const SkString name = task.name();
193 if (fJson[name.c_str()].isNull()) {
194 return true; // No expectations.
195 }
196
197 const char* expected = fJson[name.c_str()].asCString();
198 SkAutoTDelete<SkStreamAsset> png(encode_to_png(bitmap));
199 SkString actual = get_md5(png);
200 return actual.equals(expected);
201 }
202
203 void WriteTask::DumpJson() { 162 void WriteTask::DumpJson() {
204 if (FLAGS_writePath.isEmpty()) { 163 if (FLAGS_writePath.isEmpty()) {
205 return; 164 return;
206 } 165 }
207 166
208 // FIXME: This JSON format is a complete MVP strawman. 167 // FIXME: This JSON format is a complete MVP strawman.
209 Json::Value root; 168 Json::Value root;
210 { 169 {
211 SkAutoMutexAcquire lock(&gJsonDataLock); 170 SkAutoMutexAcquire lock(&gJsonDataLock);
212 for (int i = 0; i < gJsonData.count(); i++) { 171 for (int i = 0; i < gJsonData.count(); i++) {
213 root[gJsonData[i].name.c_str()] = gJsonData[i].md5.c_str(); 172 root[gJsonData[i].name.c_str()] = gJsonData[i].md5.c_str();
214 } 173 }
215 } 174 }
216 175
217 SkString path = SkOSPath::Join(FLAGS_writePath[0], "dm.json"); 176 SkString path = SkOSPath::Join(FLAGS_writePath[0], "dm.json");
218 SkFILEWStream stream(path.c_str()); 177 SkFILEWStream stream(path.c_str());
219 stream.writeText(Json::StyledWriter().write(root).c_str()); 178 stream.writeText(Json::StyledWriter().write(root).c_str());
220 stream.flush(); 179 stream.flush();
221 } 180 }
222 181
223 } // namespace DM 182 } // namespace DM
OLDNEW
« no previous file with comments | « dm/DMWriteTask.h ('k') | gyp/dm.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698