OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "PictureRenderer.h" | 8 #include "PictureRenderer.h" |
9 #include "picture_utils.h" | 9 #include "picture_utils.h" |
10 #include "SamplePipeControllers.h" | 10 #include "SamplePipeControllers.h" |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 static bool write(SkCanvas* canvas, const SkString& outputDir, const SkString& i nputFilename, | 277 static bool write(SkCanvas* canvas, const SkString& outputDir, const SkString& i nputFilename, |
278 ImageResultsSummary *jsonSummaryPtr, bool useChecksumBasedFile names, | 278 ImageResultsSummary *jsonSummaryPtr, bool useChecksumBasedFile names, |
279 const int* tileNumberPtr=NULL) { | 279 const int* tileNumberPtr=NULL) { |
280 SkASSERT(canvas != NULL); | 280 SkASSERT(canvas != NULL); |
281 if (NULL == canvas) { | 281 if (NULL == canvas) { |
282 return false; | 282 return false; |
283 } | 283 } |
284 | 284 |
285 SkBitmap bitmap; | 285 SkBitmap bitmap; |
286 SkISize size = canvas->getDeviceSize(); | 286 SkISize size = canvas->getDeviceSize(); |
287 sk_tools::setup_bitmap(&bitmap, size.width(), size.height()); | 287 setup_bitmap(&bitmap, size.width(), size.height()); |
288 | |
289 // Make sure we only compute the bitmap hash once (at most). | |
borenet
2014/05/09 15:54:01
Do we no longer care about this?
epoger
2014/05/09 16:06:25
We do, but BitmapAndDigest takes care of it for us
| |
290 uint64_t hash; | |
291 bool generatedHash = false; | |
292 | 288 |
293 canvas->readPixels(&bitmap, 0, 0); | 289 canvas->readPixels(&bitmap, 0, 0); |
294 sk_tools::force_all_opaque(bitmap); | 290 force_all_opaque(bitmap); |
291 BitmapAndDigest bitmapAndDigest(bitmap); | |
295 | 292 |
296 SkString escapedInputFilename(inputFilename); | 293 SkString escapedInputFilename(inputFilename); |
297 replace_char(&escapedInputFilename, '.', '_'); | 294 replace_char(&escapedInputFilename, '.', '_'); |
298 | 295 |
299 // TODO(epoger): what about including the config type within outputFilename? That way, | 296 // TODO(epoger): what about including the config type within outputFilename? That way, |
300 // we could combine results of different config types without conflicting fi lenames. | 297 // we could combine results of different config types without conflicting fi lenames. |
301 SkString outputFilename; | 298 SkString outputFilename; |
299 const ImageDigest *imageDigestPtr = bitmapAndDigest.getImageDigestPtr(); | |
302 const char *outputSubdirPtr = NULL; | 300 const char *outputSubdirPtr = NULL; |
303 if (useChecksumBasedFilenames) { | 301 if (useChecksumBasedFilenames) { |
304 SkASSERT(!generatedHash); | |
305 SkAssertResult(SkBitmapHasher::ComputeDigest(bitmap, &hash)); | |
306 generatedHash = true; | |
307 | |
308 outputSubdirPtr = escapedInputFilename.c_str(); | 302 outputSubdirPtr = escapedInputFilename.c_str(); |
309 // TODO(epoger): The string constant below will be removed when I land | 303 outputFilename.set(imageDigestPtr->getHashType()); |
310 // the second part of https://codereview.chromium.org/261313004/ | 304 outputFilename.append("_"); |
311 // ('add --readJsonSummaryPath to render_pictures') | 305 outputFilename.appendU64(imageDigestPtr->getHashValue()); |
312 outputFilename.set("bitmap-64bitMD5_"); | |
313 outputFilename.appendU64(hash); | |
314 } else { | 306 } else { |
315 outputFilename.set(escapedInputFilename); | 307 outputFilename.set(escapedInputFilename); |
316 if (NULL != tileNumberPtr) { | 308 if (NULL != tileNumberPtr) { |
317 outputFilename.append("-tile"); | 309 outputFilename.append("-tile"); |
318 outputFilename.appendS32(*tileNumberPtr); | 310 outputFilename.appendS32(*tileNumberPtr); |
319 } | 311 } |
320 } | 312 } |
321 outputFilename.append(".png"); | 313 outputFilename.append(".png"); |
322 | 314 |
323 if (NULL != jsonSummaryPtr) { | 315 if (NULL != jsonSummaryPtr) { |
324 if (!generatedHash) { | 316 const ImageDigest *imageDigestPtr = bitmapAndDigest.getImageDigestPtr(); |
325 SkAssertResult(SkBitmapHasher::ComputeDigest(bitmap, &hash)); | |
326 generatedHash = true; | |
327 } | |
328 | |
329 SkString outputRelativePath; | 317 SkString outputRelativePath; |
330 if (outputSubdirPtr) { | 318 if (outputSubdirPtr) { |
331 outputRelativePath.set(outputSubdirPtr); | 319 outputRelativePath.set(outputSubdirPtr); |
332 outputRelativePath.append("/"); // always use "/", even on Windows | 320 outputRelativePath.append("/"); // always use "/", even on Windows |
333 outputRelativePath.append(outputFilename); | 321 outputRelativePath.append(outputFilename); |
334 } else { | 322 } else { |
335 outputRelativePath.set(outputFilename); | 323 outputRelativePath.set(outputFilename); |
336 } | 324 } |
337 | 325 |
338 jsonSummaryPtr->add(inputFilename.c_str(), outputRelativePath.c_str(), | 326 jsonSummaryPtr->add(inputFilename.c_str(), outputRelativePath.c_str(), |
339 hash, tileNumberPtr); | 327 *imageDigestPtr, tileNumberPtr); |
340 } | 328 } |
341 | 329 |
342 if (outputDir.isEmpty()) { | 330 if (outputDir.isEmpty()) { |
343 return true; | 331 return true; |
344 } | 332 } |
345 | 333 |
346 SkString dirPath; | 334 SkString dirPath; |
347 if (outputSubdirPtr) { | 335 if (outputSubdirPtr) { |
348 dirPath = SkOSPath::SkPathJoin(outputDir.c_str(), outputSubdirPtr); | 336 dirPath = SkOSPath::SkPathJoin(outputDir.c_str(), outputSubdirPtr); |
349 sk_mkdir(dirPath.c_str()); | 337 sk_mkdir(dirPath.c_str()); |
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
953 virtual SkString getConfigNameInternal() SK_OVERRIDE { | 941 virtual SkString getConfigNameInternal() SK_OVERRIDE { |
954 return SkString("picture_clone"); | 942 return SkString("picture_clone"); |
955 } | 943 } |
956 }; | 944 }; |
957 | 945 |
958 PictureRenderer* CreatePictureCloneRenderer() { | 946 PictureRenderer* CreatePictureCloneRenderer() { |
959 return SkNEW(PictureCloneRenderer); | 947 return SkNEW(PictureCloneRenderer); |
960 } | 948 } |
961 | 949 |
962 } // namespace sk_tools | 950 } // namespace sk_tools |
OLD | NEW |