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 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
268 * @param outputDir If nonempty, write the binary image to a file within this di rectory; | 268 * @param outputDir If nonempty, write the binary image to a file within this di rectory; |
269 * if empty, don't write out the image at all. | 269 * if empty, don't write out the image at all. |
270 * @param inputFilename If we are writing out a binary image, use this to build its filename. | 270 * @param inputFilename If we are writing out a binary image, use this to build its filename. |
271 * @param jsonSummaryPtr If not null, add image results (checksum) to this summa ry. | 271 * @param jsonSummaryPtr If not null, add image results (checksum) to this summa ry. |
272 * @param useChecksumBasedFilenames If true, use checksum-based filenames when w riting to disk. | 272 * @param useChecksumBasedFilenames If true, use checksum-based filenames when w riting to disk. |
273 * @param tileNumberPtr If not null, which tile number this image contains. | 273 * @param tileNumberPtr If not null, which tile number this image contains. |
274 * | 274 * |
275 * @return bool True if the operation completed successfully. | 275 * @return bool True if the operation completed successfully. |
276 */ | 276 */ |
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 ImageResultsAndExpectations *jsonSummaryPtr, bool useChecksumB asedFilenames, |
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). | |
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(); | |
epoger
2014/05/20 19:41:57
I think this probably accounts for the measured pe
| |
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 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
700 return name; | 688 return name; |
701 } | 689 } |
702 | 690 |
703 //////////////////////////////////////////////////////////////////////////////// /////////////// | 691 //////////////////////////////////////////////////////////////////////////////// /////////////// |
704 | 692 |
705 // Holds all of the information needed to draw a set of tiles. | 693 // Holds all of the information needed to draw a set of tiles. |
706 class CloneData : public SkRunnable { | 694 class CloneData : public SkRunnable { |
707 | 695 |
708 public: | 696 public: |
709 CloneData(SkPicture* clone, SkCanvas* canvas, SkTDArray<SkRect>& rects, int start, int end, | 697 CloneData(SkPicture* clone, SkCanvas* canvas, SkTDArray<SkRect>& rects, int start, int end, |
710 SkRunnable* done, ImageResultsSummary* jsonSummaryPtr, bool useChe cksumBasedFilenames) | 698 SkRunnable* done, ImageResultsAndExpectations* jsonSummaryPtr, |
699 bool useChecksumBasedFilenames) | |
711 : fClone(clone) | 700 : fClone(clone) |
712 , fCanvas(canvas) | 701 , fCanvas(canvas) |
713 , fRects(rects) | 702 , fRects(rects) |
714 , fStart(start) | 703 , fStart(start) |
715 , fEnd(end) | 704 , fEnd(end) |
716 , fSuccess(NULL) | 705 , fSuccess(NULL) |
717 , fDone(done) | 706 , fDone(done) |
718 , fJsonSummaryPtr(jsonSummaryPtr) | 707 , fJsonSummaryPtr(jsonSummaryPtr) |
719 , fUseChecksumBasedFilenames(useChecksumBasedFilenames) { | 708 , fUseChecksumBasedFilenames(useChecksumBasedFilenames) { |
720 SkASSERT(fDone != NULL); | 709 SkASSERT(fDone != NULL); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
771 SkCanvas* fCanvas; // Canvas to draw to. Reused for each tile. | 760 SkCanvas* fCanvas; // Canvas to draw to. Reused for each tile. |
772 SkString fOutputDir; // If not empty, write results into this dir ectory. | 761 SkString fOutputDir; // If not empty, write results into this dir ectory. |
773 SkString fInputFilename; // Filename of input SkPicture file. | 762 SkString fInputFilename; // Filename of input SkPicture file. |
774 SkTDArray<SkRect>& fRects; // All tiles of the picture. | 763 SkTDArray<SkRect>& fRects; // All tiles of the picture. |
775 const int fStart; // Range of tiles drawn by this thread. | 764 const int fStart; // Range of tiles drawn by this thread. |
776 const int fEnd; | 765 const int fEnd; |
777 bool* fSuccess; // Only meaningful if path is non-null. Shar ed by all threads, | 766 bool* fSuccess; // Only meaningful if path is non-null. Shar ed by all threads, |
778 // and only set to false upon failure to wri te to a PNG. | 767 // and only set to false upon failure to wri te to a PNG. |
779 SkRunnable* fDone; | 768 SkRunnable* fDone; |
780 SkBitmap* fBitmap; | 769 SkBitmap* fBitmap; |
781 ImageResultsSummary* fJsonSummaryPtr; | 770 ImageResultsAndExpectations* fJsonSummaryPtr; |
782 bool fUseChecksumBasedFilenames; | 771 bool fUseChecksumBasedFilenames; |
783 }; | 772 }; |
784 | 773 |
785 MultiCorePictureRenderer::MultiCorePictureRenderer(int threadCount) | 774 MultiCorePictureRenderer::MultiCorePictureRenderer(int threadCount) |
786 : fNumThreads(threadCount) | 775 : fNumThreads(threadCount) |
787 , fThreadPool(threadCount) | 776 , fThreadPool(threadCount) |
788 , fCountdown(threadCount) { | 777 , fCountdown(threadCount) { |
789 // Only need to create fNumThreads - 1 clones, since one thread will use the base | 778 // Only need to create fNumThreads - 1 clones, since one thread will use the base |
790 // picture. | 779 // picture. |
791 fPictureClones = SkNEW_ARRAY(SkPicture, fNumThreads - 1); | 780 fPictureClones = SkNEW_ARRAY(SkPicture, fNumThreads - 1); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
953 virtual SkString getConfigNameInternal() SK_OVERRIDE { | 942 virtual SkString getConfigNameInternal() SK_OVERRIDE { |
954 return SkString("picture_clone"); | 943 return SkString("picture_clone"); |
955 } | 944 } |
956 }; | 945 }; |
957 | 946 |
958 PictureRenderer* CreatePictureCloneRenderer() { | 947 PictureRenderer* CreatePictureCloneRenderer() { |
959 return SkNEW(PictureCloneRenderer); | 948 return SkNEW(PictureCloneRenderer); |
960 } | 949 } |
961 | 950 |
962 } // namespace sk_tools | 951 } // namespace sk_tools |
OLD | NEW |