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" |
| 11 #include "SkBitmapHasher.h" |
11 #include "SkCanvas.h" | 12 #include "SkCanvas.h" |
12 #include "SkData.h" | 13 #include "SkData.h" |
13 #include "SkDevice.h" | 14 #include "SkDevice.h" |
14 #include "SkGPipe.h" | 15 #include "SkGPipe.h" |
15 #if SK_SUPPORT_GPU | 16 #if SK_SUPPORT_GPU |
16 #include "gl/GrGLDefines.h" | 17 #include "gl/GrGLDefines.h" |
17 #include "SkGpuDevice.h" | 18 #include "SkGpuDevice.h" |
18 #endif | 19 #endif |
19 #include "SkGraphics.h" | 20 #include "SkGraphics.h" |
20 #include "SkImageEncoder.h" | 21 #include "SkImageEncoder.h" |
(...skipping 12 matching lines...) Expand all Loading... |
33 #include "SkThreadUtils.h" | 34 #include "SkThreadUtils.h" |
34 #include "SkTypes.h" | 35 #include "SkTypes.h" |
35 | 36 |
36 namespace sk_tools { | 37 namespace sk_tools { |
37 | 38 |
38 enum { | 39 enum { |
39 kDefaultTileWidth = 256, | 40 kDefaultTileWidth = 256, |
40 kDefaultTileHeight = 256 | 41 kDefaultTileHeight = 256 |
41 }; | 42 }; |
42 | 43 |
| 44 /* TODO(epoger): These constants are already maintained in 2 other places: |
| 45 * gm/gm_json.py and gm/gm_expectations.cpp. We shouldn't add yet a third place
. |
| 46 * Figure out a way to share the definitions instead. |
| 47 */ |
| 48 const static char kJsonKey_ActualResults[] = "actual-results"; |
| 49 const static char kJsonKey_ActualResults_Failed[] = "failed"; |
| 50 const static char kJsonKey_ActualResults_FailureIgnored[]= "failure-ignored"; |
| 51 const static char kJsonKey_ActualResults_NoComparison[] = "no-comparison"; |
| 52 const static char kJsonKey_ActualResults_Succeeded[] = "succeeded"; |
| 53 const static char kJsonKey_ExpectedResults[] = "expected-results"; |
| 54 const static char kJsonKey_ExpectedResults_AllowedDigests[] = "allowed-digests"; |
| 55 const static char kJsonKey_ExpectedResults_IgnoreFailure[] = "ignore-failure"; |
| 56 const static char kJsonKey_Hashtype_Bitmap_64bitMD5[] = "bitmap-64bitMD5"; |
| 57 |
| 58 void ImageResultsSummary::add(const char *testName, const SkBitmap& bitmap) { |
| 59 uint64_t hash; |
| 60 SkAssertResult(SkBitmapHasher::ComputeDigest(bitmap, &hash)); |
| 61 Json::Value jsonTypeValuePair; |
| 62 jsonTypeValuePair.append(Json::Value(kJsonKey_Hashtype_Bitmap_64bitMD5)); |
| 63 jsonTypeValuePair.append(Json::UInt64(hash)); |
| 64 fActualResultsNoComparison[testName] = jsonTypeValuePair; |
| 65 } |
| 66 |
| 67 void ImageResultsSummary::writeToFile(const char *filename) { |
| 68 Json::Value actualResults; |
| 69 actualResults[kJsonKey_ActualResults_NoComparison] = fActualResultsNoCompari
son; |
| 70 Json::Value root; |
| 71 root[kJsonKey_ActualResults] = actualResults; |
| 72 std::string jsonStdString = root.toStyledString(); |
| 73 SkFILEWStream stream(filename); |
| 74 stream.write(jsonStdString.c_str(), jsonStdString.length()); |
| 75 } |
| 76 |
43 void PictureRenderer::init(SkPicture* pict) { | 77 void PictureRenderer::init(SkPicture* pict) { |
44 SkASSERT(NULL == fPicture); | 78 SkASSERT(NULL == fPicture); |
45 SkASSERT(NULL == fCanvas.get()); | 79 SkASSERT(NULL == fCanvas.get()); |
46 if (fPicture != NULL || NULL != fCanvas.get()) { | 80 if (fPicture != NULL || NULL != fCanvas.get()) { |
47 return; | 81 return; |
48 } | 82 } |
49 | 83 |
50 SkASSERT(pict != NULL); | 84 SkASSERT(pict != NULL); |
51 if (NULL == pict) { | 85 if (NULL == pict) { |
52 return; | 86 return; |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 return ((kNone_BBoxHierarchyType == fBBoxHierarchyType) ? 0 : | 244 return ((kNone_BBoxHierarchyType == fBBoxHierarchyType) ? 0 : |
211 SkPicture::kOptimizeForClippedPlayback_RecordingFlag) | | 245 SkPicture::kOptimizeForClippedPlayback_RecordingFlag) | |
212 SkPicture::kUsePathBoundsForClip_RecordingFlag; | 246 SkPicture::kUsePathBoundsForClip_RecordingFlag; |
213 } | 247 } |
214 | 248 |
215 /** | 249 /** |
216 * Write the canvas to the specified path. | 250 * Write the canvas to the specified path. |
217 * @param canvas Must be non-null. Canvas to be written to a file. | 251 * @param canvas Must be non-null. Canvas to be written to a file. |
218 * @param path Path for the file to be written. Should have no extension; write(
) will append | 252 * @param path Path for the file to be written. Should have no extension; write(
) will append |
219 * an appropriate one. Passed in by value so it can be modified. | 253 * an appropriate one. Passed in by value so it can be modified. |
| 254 * @param jsonSummaryPtr If not null, add image results to this summary. |
220 * @return bool True if the Canvas is written to a file. | 255 * @return bool True if the Canvas is written to a file. |
| 256 * |
| 257 * TODO(epoger): Right now, all canvases must pass through this function in orde
r to be appended |
| 258 * to the ImageResultsSummary. We need some way to add bitmaps to the ImageResu
ltsSummary |
| 259 * even if --writePath has not been specified (and thus this function is not cal
led). |
| 260 * |
| 261 * One fix would be to pass in these path elements separately, and allow this fu
nction to be |
| 262 * called even if --writePath was not specified... |
| 263 * const char *outputDir // NULL if we don't want to write image files to dis
k |
| 264 * const char *filename // name we use within JSON summary, and as the filen
ame within outputDir |
221 */ | 265 */ |
222 static bool write(SkCanvas* canvas, SkString path) { | 266 static bool write(SkCanvas* canvas, const SkString* path, ImageResultsSummary *j
sonSummaryPtr) { |
223 SkASSERT(canvas != NULL); | 267 SkASSERT(canvas != NULL); |
224 if (NULL == canvas) { | 268 if (NULL == canvas) { |
225 return false; | 269 return false; |
226 } | 270 } |
227 | 271 |
| 272 SkASSERT(path != NULL); // TODO(epoger): we want to remove this constraint,
as noted above |
| 273 SkString fullPathname(*path); |
| 274 fullPathname.append(".png"); |
| 275 |
228 SkBitmap bitmap; | 276 SkBitmap bitmap; |
229 SkISize size = canvas->getDeviceSize(); | 277 SkISize size = canvas->getDeviceSize(); |
230 sk_tools::setup_bitmap(&bitmap, size.width(), size.height()); | 278 sk_tools::setup_bitmap(&bitmap, size.width(), size.height()); |
231 | 279 |
232 canvas->readPixels(&bitmap, 0, 0); | 280 canvas->readPixels(&bitmap, 0, 0); |
233 sk_tools::force_all_opaque(bitmap); | 281 sk_tools::force_all_opaque(bitmap); |
234 | 282 |
235 // Since path is passed in by value, it is okay to modify it. | 283 if (NULL != jsonSummaryPtr) { |
236 path.append(".png"); | 284 // EPOGER: This is a hacky way of constructing the filename associated w
ith the |
237 return SkImageEncoder::EncodeFile(path.c_str(), bitmap, SkImageEncoder::kPNG
_Type, 100); | 285 // image checksum; we assume that outputDir is not NULL, and we remove o
utputDir |
| 286 // from fullPathname. |
| 287 // |
| 288 // EPOGER: what about including the config type within hashFilename? Th
at way, |
| 289 // we could combine results of different config types without conflictin
g filenames. |
| 290 SkString hashFilename; |
| 291 sk_tools::get_basename(&hashFilename, fullPathname); |
| 292 jsonSummaryPtr->add(hashFilename.c_str(), bitmap); |
| 293 } |
| 294 |
| 295 return SkImageEncoder::EncodeFile(fullPathname.c_str(), bitmap, SkImageEncod
er::kPNG_Type, 100); |
238 } | 296 } |
239 | 297 |
240 /** | 298 /** |
241 * If path is non NULL, append number to it, and call write(SkCanvas*, SkString)
to write the | 299 * If path is non NULL, append number to it, and call write() to write the |
242 * provided canvas to a file. Returns true if path is NULL or if write() succeed
s. | 300 * provided canvas to a file. Returns true if path is NULL or if write() succeed
s. |
243 */ | 301 */ |
244 static bool writeAppendNumber(SkCanvas* canvas, const SkString* path, int number
) { | 302 static bool writeAppendNumber(SkCanvas* canvas, const SkString* path, int number
, |
| 303 ImageResultsSummary *jsonSummaryPtr) { |
245 if (NULL == path) { | 304 if (NULL == path) { |
246 return true; | 305 return true; |
247 } | 306 } |
248 SkString pathWithNumber(*path); | 307 SkString pathWithNumber(*path); |
249 pathWithNumber.appendf("%i", number); | 308 pathWithNumber.appendf("%i", number); |
250 return write(canvas, pathWithNumber); | 309 return write(canvas, &pathWithNumber, jsonSummaryPtr); |
251 } | 310 } |
252 | 311 |
253 ////////////////////////////////////////////////////////////////////////////////
/////////////// | 312 ////////////////////////////////////////////////////////////////////////////////
/////////////// |
254 | 313 |
255 SkCanvas* RecordPictureRenderer::setupCanvas(int width, int height) { | 314 SkCanvas* RecordPictureRenderer::setupCanvas(int width, int height) { |
256 // defer the canvas setup until the render step | 315 // defer the canvas setup until the render step |
257 return NULL; | 316 return NULL; |
258 } | 317 } |
259 | 318 |
260 static SkData* encode_bitmap_to_data(size_t* offset, const SkBitmap& bm) { | 319 static SkData* encode_bitmap_to_data(size_t* offset, const SkBitmap& bm) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 return false; | 361 return false; |
303 } | 362 } |
304 | 363 |
305 PipeController pipeController(fCanvas.get()); | 364 PipeController pipeController(fCanvas.get()); |
306 SkGPipeWriter writer; | 365 SkGPipeWriter writer; |
307 SkCanvas* pipeCanvas = writer.startRecording(&pipeController); | 366 SkCanvas* pipeCanvas = writer.startRecording(&pipeController); |
308 pipeCanvas->drawPicture(*fPicture); | 367 pipeCanvas->drawPicture(*fPicture); |
309 writer.endRecording(); | 368 writer.endRecording(); |
310 fCanvas->flush(); | 369 fCanvas->flush(); |
311 if (NULL != path) { | 370 if (NULL != path) { |
312 return write(fCanvas, *path); | 371 return write(fCanvas, path, fJsonSummaryPtr); |
313 } | 372 } |
314 if (NULL != out) { | 373 if (NULL != out) { |
315 *out = SkNEW(SkBitmap); | 374 *out = SkNEW(SkBitmap); |
316 setup_bitmap(*out, fPicture->width(), fPicture->height()); | 375 setup_bitmap(*out, fPicture->width(), fPicture->height()); |
317 fCanvas->readPixels(*out, 0, 0); | 376 fCanvas->readPixels(*out, 0, 0); |
318 } | 377 } |
319 return true; | 378 return true; |
320 } | 379 } |
321 | 380 |
322 SkString PipePictureRenderer::getConfigNameInternal() { | 381 SkString PipePictureRenderer::getConfigNameInternal() { |
(...skipping 10 matching lines...) Expand all Loading... |
333 bool SimplePictureRenderer::render(const SkString* path, SkBitmap** out) { | 392 bool SimplePictureRenderer::render(const SkString* path, SkBitmap** out) { |
334 SkASSERT(fCanvas.get() != NULL); | 393 SkASSERT(fCanvas.get() != NULL); |
335 SkASSERT(fPicture != NULL); | 394 SkASSERT(fPicture != NULL); |
336 if (NULL == fCanvas.get() || NULL == fPicture) { | 395 if (NULL == fCanvas.get() || NULL == fPicture) { |
337 return false; | 396 return false; |
338 } | 397 } |
339 | 398 |
340 fCanvas->drawPicture(*fPicture); | 399 fCanvas->drawPicture(*fPicture); |
341 fCanvas->flush(); | 400 fCanvas->flush(); |
342 if (NULL != path) { | 401 if (NULL != path) { |
343 return write(fCanvas, *path); | 402 return write(fCanvas, path, fJsonSummaryPtr); |
344 } | 403 } |
345 | 404 |
346 if (NULL != out) { | 405 if (NULL != out) { |
347 *out = SkNEW(SkBitmap); | 406 *out = SkNEW(SkBitmap); |
348 setup_bitmap(*out, fPicture->width(), fPicture->height()); | 407 setup_bitmap(*out, fPicture->width(), fPicture->height()); |
349 fCanvas->readPixels(*out, 0, 0); | 408 fCanvas->readPixels(*out, 0, 0); |
350 } | 409 } |
351 | 410 |
352 return true; | 411 return true; |
353 } | 412 } |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 SkMatrix mat(canvas->getTotalMatrix()); | 558 SkMatrix mat(canvas->getTotalMatrix()); |
500 mat.postTranslate(-tileRect.fLeft, -tileRect.fTop); | 559 mat.postTranslate(-tileRect.fLeft, -tileRect.fTop); |
501 canvas->setMatrix(mat); | 560 canvas->setMatrix(mat); |
502 playback->draw(canvas); | 561 playback->draw(canvas); |
503 canvas->restoreToCount(saveCount); | 562 canvas->restoreToCount(saveCount); |
504 canvas->flush(); | 563 canvas->flush(); |
505 } | 564 } |
506 | 565 |
507 ////////////////////////////////////////////////////////////////////////////////
/////////////// | 566 ////////////////////////////////////////////////////////////////////////////////
/////////////// |
508 | 567 |
509 static void bitmapCopySubset(const SkBitmap& src, SkBitmap* dst, int xDst, | 568 /** |
510 int yDst) { | 569 * Copies the entirety of the src bitmap (typically a tile) into a portion of th
e dst bitmap. |
511 for (int y = 0; y <src.height() && y + yDst < dst->height() ; y++) { | 570 * If the src bitmap is too large to fit within the dst bitmap after the x and y |
512 for (int x = 0; x < src.width() && x + xDst < dst->width() ; x++) { | 571 * offsets have been applied, any excess will be ignored (so only the top-left p
ortion of the |
513 *dst->getAddr32(xDst + x, yDst + y) = *src.getAddr32(x, y); | 572 * src bitmap will be copied). |
| 573 * |
| 574 * @param src source bitmap |
| 575 * @param dst destination bitmap |
| 576 * @param xOffset x-offset within destination bitmap |
| 577 * @param yOffset y-offset within destination bitmap |
| 578 */ |
| 579 static void bitmapCopyAtOffset(const SkBitmap& src, SkBitmap* dst, |
| 580 int xOffset, int yOffset) { |
| 581 for (int y = 0; y <src.height() && y + yOffset < dst->height() ; y++) { |
| 582 for (int x = 0; x < src.width() && x + xOffset < dst->width() ; x++) { |
| 583 *dst->getAddr32(xOffset + x, yOffset + y) = *src.getAddr32(x, y); |
514 } | 584 } |
515 } | 585 } |
516 } | 586 } |
517 | 587 |
518 bool TiledPictureRenderer::nextTile(int &i, int &j) { | 588 bool TiledPictureRenderer::nextTile(int &i, int &j) { |
519 if (++fCurrentTileOffset < fTileRects.count()) { | 589 if (++fCurrentTileOffset < fTileRects.count()) { |
520 i = fCurrentTileOffset % fTilesX; | 590 i = fCurrentTileOffset % fTilesX; |
521 j = fCurrentTileOffset / fTilesX; | 591 j = fCurrentTileOffset / fTilesX; |
522 return true; | 592 return true; |
523 } | 593 } |
(...skipping 14 matching lines...) Expand all Loading... |
538 SkBitmap bitmap; | 608 SkBitmap bitmap; |
539 if (out){ | 609 if (out){ |
540 *out = SkNEW(SkBitmap); | 610 *out = SkNEW(SkBitmap); |
541 setup_bitmap(*out, fPicture->width(), fPicture->height()); | 611 setup_bitmap(*out, fPicture->width(), fPicture->height()); |
542 setup_bitmap(&bitmap, fTileWidth, fTileHeight); | 612 setup_bitmap(&bitmap, fTileWidth, fTileHeight); |
543 } | 613 } |
544 bool success = true; | 614 bool success = true; |
545 for (int i = 0; i < fTileRects.count(); ++i) { | 615 for (int i = 0; i < fTileRects.count(); ++i) { |
546 DrawTileToCanvas(fCanvas, fTileRects[i], fPicture); | 616 DrawTileToCanvas(fCanvas, fTileRects[i], fPicture); |
547 if (NULL != path) { | 617 if (NULL != path) { |
548 success &= writeAppendNumber(fCanvas, path, i); | 618 success &= writeAppendNumber(fCanvas, path, i, fJsonSummaryPtr); |
549 } | 619 } |
550 if (NULL != out) { | 620 if (NULL != out) { |
551 if (fCanvas->readPixels(&bitmap, 0, 0)) { | 621 if (fCanvas->readPixels(&bitmap, 0, 0)) { |
552 bitmapCopySubset(bitmap, *out, SkScalarFloorToInt(fTileRects[i].
left()), | 622 // Add this tile to the entire bitmap. |
553 SkScalarFloorToInt(fTileRects[i].top())); | 623 bitmapCopyAtOffset(bitmap, *out, SkScalarFloorToInt(fTileRects[i
].left()), |
| 624 SkScalarFloorToInt(fTileRects[i].top())); |
554 } else { | 625 } else { |
555 success = false; | 626 success = false; |
556 } | 627 } |
557 } | 628 } |
558 } | 629 } |
559 return success; | 630 return success; |
560 } | 631 } |
561 | 632 |
562 SkCanvas* TiledPictureRenderer::setupCanvas(int width, int height) { | 633 SkCanvas* TiledPictureRenderer::setupCanvas(int width, int height) { |
563 SkCanvas* canvas = this->INHERITED::setupCanvas(width, height); | 634 SkCanvas* canvas = this->INHERITED::setupCanvas(width, height); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 return name; | 667 return name; |
597 } | 668 } |
598 | 669 |
599 ////////////////////////////////////////////////////////////////////////////////
/////////////// | 670 ////////////////////////////////////////////////////////////////////////////////
/////////////// |
600 | 671 |
601 // Holds all of the information needed to draw a set of tiles. | 672 // Holds all of the information needed to draw a set of tiles. |
602 class CloneData : public SkRunnable { | 673 class CloneData : public SkRunnable { |
603 | 674 |
604 public: | 675 public: |
605 CloneData(SkPicture* clone, SkCanvas* canvas, SkTDArray<SkRect>& rects, int
start, int end, | 676 CloneData(SkPicture* clone, SkCanvas* canvas, SkTDArray<SkRect>& rects, int
start, int end, |
606 SkRunnable* done) | 677 SkRunnable* done, ImageResultsSummary* jsonSummaryPtr) |
607 : fClone(clone) | 678 : fClone(clone) |
608 , fCanvas(canvas) | 679 , fCanvas(canvas) |
609 , fPath(NULL) | 680 , fPath(NULL) |
610 , fRects(rects) | 681 , fRects(rects) |
611 , fStart(start) | 682 , fStart(start) |
612 , fEnd(end) | 683 , fEnd(end) |
613 , fSuccess(NULL) | 684 , fSuccess(NULL) |
614 , fDone(done) { | 685 , fDone(done) |
| 686 , fJsonSummaryPtr(jsonSummaryPtr) { |
615 SkASSERT(fDone != NULL); | 687 SkASSERT(fDone != NULL); |
616 } | 688 } |
617 | 689 |
618 virtual void run() SK_OVERRIDE { | 690 virtual void run() SK_OVERRIDE { |
619 SkGraphics::SetTLSFontCacheLimit(1024 * 1024); | 691 SkGraphics::SetTLSFontCacheLimit(1024 * 1024); |
620 | 692 |
621 SkBitmap bitmap; | 693 SkBitmap bitmap; |
622 if (fBitmap != NULL) { | 694 if (fBitmap != NULL) { |
623 // All tiles are the same size. | 695 // All tiles are the same size. |
624 setup_bitmap(&bitmap, SkScalarFloorToInt(fRects[0].width()), SkScala
rFloorToInt(fRects[0].height())); | 696 setup_bitmap(&bitmap, SkScalarFloorToInt(fRects[0].width()), SkScala
rFloorToInt(fRects[0].height())); |
625 } | 697 } |
626 | 698 |
627 for (int i = fStart; i < fEnd; i++) { | 699 for (int i = fStart; i < fEnd; i++) { |
628 DrawTileToCanvas(fCanvas, fRects[i], fClone); | 700 DrawTileToCanvas(fCanvas, fRects[i], fClone); |
629 if (fPath != NULL && !writeAppendNumber(fCanvas, fPath, i) | 701 if ((fPath != NULL) && !writeAppendNumber(fCanvas, fPath, i, fJsonSu
mmaryPtr) |
630 && fSuccess != NULL) { | 702 && fSuccess != NULL) { |
631 *fSuccess = false; | 703 *fSuccess = false; |
632 // If one tile fails to write to a file, do not continue drawing
the rest. | 704 // If one tile fails to write to a file, do not continue drawing
the rest. |
633 break; | 705 break; |
634 } | 706 } |
635 if (fBitmap != NULL) { | 707 if (fBitmap != NULL) { |
636 if (fCanvas->readPixels(&bitmap, 0, 0)) { | 708 if (fCanvas->readPixels(&bitmap, 0, 0)) { |
637 SkAutoLockPixels alp(*fBitmap); | 709 SkAutoLockPixels alp(*fBitmap); |
638 bitmapCopySubset(bitmap, fBitmap, SkScalarFloorToInt(fRects[
i].left()), | 710 bitmapCopyAtOffset(bitmap, fBitmap, SkScalarFloorToInt(fRect
s[i].left()), |
639 SkScalarFloorToInt(fRects[i].top())); | 711 SkScalarFloorToInt(fRects[i].top())); |
640 } else { | 712 } else { |
641 *fSuccess = false; | 713 *fSuccess = false; |
642 // If one tile fails to read pixels, do not continue drawing
the rest. | 714 // If one tile fails to read pixels, do not continue drawing
the rest. |
643 break; | 715 break; |
644 } | 716 } |
645 } | 717 } |
646 } | 718 } |
647 fDone->run(); | 719 fDone->run(); |
648 } | 720 } |
649 | 721 |
(...skipping 12 matching lines...) Expand all Loading... |
662 // is threadsafe. | 734 // is threadsafe. |
663 SkCanvas* fCanvas; // Canvas to draw to. Reused for each tile. | 735 SkCanvas* fCanvas; // Canvas to draw to. Reused for each tile. |
664 const SkString* fPath; // If non-null, path to write the result to
as a PNG. | 736 const SkString* fPath; // If non-null, path to write the result to
as a PNG. |
665 SkTDArray<SkRect>& fRects; // All tiles of the picture. | 737 SkTDArray<SkRect>& fRects; // All tiles of the picture. |
666 const int fStart; // Range of tiles drawn by this thread. | 738 const int fStart; // Range of tiles drawn by this thread. |
667 const int fEnd; | 739 const int fEnd; |
668 bool* fSuccess; // Only meaningful if path is non-null. Shar
ed by all threads, | 740 bool* fSuccess; // Only meaningful if path is non-null. Shar
ed by all threads, |
669 // and only set to false upon failure to wri
te to a PNG. | 741 // and only set to false upon failure to wri
te to a PNG. |
670 SkRunnable* fDone; | 742 SkRunnable* fDone; |
671 SkBitmap* fBitmap; | 743 SkBitmap* fBitmap; |
| 744 ImageResultsSummary* fJsonSummaryPtr; |
672 }; | 745 }; |
673 | 746 |
674 MultiCorePictureRenderer::MultiCorePictureRenderer(int threadCount) | 747 MultiCorePictureRenderer::MultiCorePictureRenderer(int threadCount) |
675 : fNumThreads(threadCount) | 748 : fNumThreads(threadCount) |
676 , fThreadPool(threadCount) | 749 , fThreadPool(threadCount) |
677 , fCountdown(threadCount) { | 750 , fCountdown(threadCount) { |
678 // Only need to create fNumThreads - 1 clones, since one thread will use the
base | 751 // Only need to create fNumThreads - 1 clones, since one thread will use the
base |
679 // picture. | 752 // picture. |
680 fPictureClones = SkNEW_ARRAY(SkPicture, fNumThreads - 1); | 753 fPictureClones = SkNEW_ARRAY(SkPicture, fNumThreads - 1); |
681 fCloneData = SkNEW_ARRAY(CloneData*, fNumThreads); | 754 fCloneData = SkNEW_ARRAY(CloneData*, fNumThreads); |
(...skipping 15 matching lines...) Expand all Loading... |
697 SkPicture* pic; | 770 SkPicture* pic; |
698 if (i == fNumThreads-1) { | 771 if (i == fNumThreads-1) { |
699 // The last set will use the original SkPicture. | 772 // The last set will use the original SkPicture. |
700 pic = fPicture; | 773 pic = fPicture; |
701 } else { | 774 } else { |
702 pic = &fPictureClones[i]; | 775 pic = &fPictureClones[i]; |
703 } | 776 } |
704 const int start = i * chunkSize; | 777 const int start = i * chunkSize; |
705 const int end = SkMin32(start + chunkSize, fTileRects.count()); | 778 const int end = SkMin32(start + chunkSize, fTileRects.count()); |
706 fCloneData[i] = SkNEW_ARGS(CloneData, | 779 fCloneData[i] = SkNEW_ARGS(CloneData, |
707 (pic, fCanvasPool[i], fTileRects, start, end,
&fCountdown)); | 780 (pic, fCanvasPool[i], fTileRects, start, end,
&fCountdown, |
| 781 fJsonSummaryPtr)); |
708 } | 782 } |
709 } | 783 } |
710 | 784 |
711 bool MultiCorePictureRenderer::render(const SkString *path, SkBitmap** out) { | 785 bool MultiCorePictureRenderer::render(const SkString *path, SkBitmap** out) { |
712 bool success = true; | 786 bool success = true; |
713 if (path != NULL) { | 787 if (path != NULL) { |
714 for (int i = 0; i < fNumThreads-1; i++) { | 788 for (int i = 0; i < fNumThreads-1; i++) { |
715 fCloneData[i]->setPathAndSuccess(path, &success); | 789 fCloneData[i]->setPathAndSuccess(path, &success); |
716 } | 790 } |
717 } | 791 } |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 virtual SkString getConfigNameInternal() SK_OVERRIDE { | 926 virtual SkString getConfigNameInternal() SK_OVERRIDE { |
853 return SkString("picture_clone"); | 927 return SkString("picture_clone"); |
854 } | 928 } |
855 }; | 929 }; |
856 | 930 |
857 PictureRenderer* CreatePictureCloneRenderer() { | 931 PictureRenderer* CreatePictureCloneRenderer() { |
858 return SkNEW(PictureCloneRenderer); | 932 return SkNEW(PictureCloneRenderer); |
859 } | 933 } |
860 | 934 |
861 } // namespace sk_tools | 935 } // namespace sk_tools |
OLD | NEW |