OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "SkAnnotation.h" | 9 #include "SkAnnotation.h" |
10 #include "SkBitmapHeap.h" | 10 #include "SkBitmapHeap.h" |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 return index; | 430 return index; |
431 } | 431 } |
432 | 432 |
433 /////////////////////////////////////////////////////////////////////////////// | 433 /////////////////////////////////////////////////////////////////////////////// |
434 | 434 |
435 #define MIN_BLOCK_SIZE (16 * 1024) | 435 #define MIN_BLOCK_SIZE (16 * 1024) |
436 #define BITMAPS_TO_KEEP 5 | 436 #define BITMAPS_TO_KEEP 5 |
437 #define FLATTENABLES_TO_KEEP 10 | 437 #define FLATTENABLES_TO_KEEP 10 |
438 | 438 |
439 SkGPipeCanvas::SkGPipeCanvas(SkGPipeController* controller, | 439 SkGPipeCanvas::SkGPipeCanvas(SkGPipeController* controller, |
440 SkWriter32* writer, uint32_t flags, | 440 SkWriter32* writer, |
441 uint32_t width, uint32_t height) | 441 uint32_t flags, |
| 442 uint32_t width, |
| 443 uint32_t height) |
442 : SkCanvas(width, height) | 444 : SkCanvas(width, height) |
443 , fFactorySet(is_cross_process(flags) ? SkNEW(SkNamedFactorySet) : NULL) | 445 , fFactorySet(is_cross_process(flags) ? new SkNamedFactorySet : NULL) |
444 , fWriter(*writer) | 446 , fWriter(*writer) |
445 , fFlags(flags) | 447 , fFlags(flags) |
446 , fFlattenableHeap(FLATTENABLES_TO_KEEP, fFactorySet, is_cross_process(flags
)) | 448 , fFlattenableHeap(FLATTENABLES_TO_KEEP, fFactorySet, is_cross_process(flags
)) |
447 , fFlatDictionary(&fFlattenableHeap) | 449 , fFlatDictionary(&fFlattenableHeap) { |
448 { | |
449 fController = controller; | 450 fController = controller; |
450 fDone = false; | 451 fDone = false; |
451 fBlockSize = 0; // need first block from controller | 452 fBlockSize = 0; // need first block from controller |
452 fBytesNotified = 0; | 453 fBytesNotified = 0; |
453 sk_bzero(fCurrFlatIndex, sizeof(fCurrFlatIndex)); | 454 sk_bzero(fCurrFlatIndex, sizeof(fCurrFlatIndex)); |
454 | 455 |
455 // Tell the reader the appropriate flags to use. | 456 // Tell the reader the appropriate flags to use. |
456 if (this->needOpBytes()) { | 457 if (this->needOpBytes()) { |
457 this->writeOp(kReportFlags_DrawOp, fFlags, 0); | 458 this->writeOp(kReportFlags_DrawOp, fFlags, 0); |
458 } | 459 } |
459 | 460 |
460 if (shouldFlattenBitmaps(flags)) { | 461 if (shouldFlattenBitmaps(flags)) { |
461 fBitmapShuttle.reset(SkNEW_ARGS(BitmapShuttle, (this))); | 462 fBitmapShuttle.reset(new BitmapShuttle(this)); |
462 fBitmapHeap = SkNEW_ARGS(SkBitmapHeap, (fBitmapShuttle.get(), BITMAPS_TO
_KEEP)); | 463 fBitmapHeap = new SkBitmapHeap(fBitmapShuttle.get(), BITMAPS_TO_KEEP); |
463 } else { | 464 } else { |
464 fBitmapHeap = SkNEW_ARGS(SkBitmapHeap, | 465 fBitmapHeap = new SkBitmapHeap(BITMAPS_TO_KEEP, controller->numberOfRead
ers()); |
465 (BITMAPS_TO_KEEP, controller->numberOfReaders()
)); | |
466 if (this->needOpBytes(sizeof(void*))) { | 466 if (this->needOpBytes(sizeof(void*))) { |
467 this->writeOp(kShareBitmapHeap_DrawOp); | 467 this->writeOp(kShareBitmapHeap_DrawOp); |
468 fWriter.writePtr(static_cast<void*>(fBitmapHeap)); | 468 fWriter.writePtr(static_cast<void*>(fBitmapHeap)); |
469 } | 469 } |
470 } | 470 } |
471 fFlattenableHeap.setBitmapStorage(fBitmapHeap); | 471 fFlattenableHeap.setBitmapStorage(fBitmapHeap); |
472 | 472 |
473 fImageHeap = SkNEW(SkImageHeap); | 473 fImageHeap = new SkImageHeap; |
474 if (this->needOpBytes(sizeof(void*))) { | 474 if (this->needOpBytes(sizeof(void*))) { |
475 this->writeOp(kShareImageHeap_DrawOp); | 475 this->writeOp(kShareImageHeap_DrawOp); |
476 fWriter.writePtr(static_cast<void*>(fImageHeap)); | 476 fWriter.writePtr(static_cast<void*>(fImageHeap)); |
477 } | 477 } |
478 | 478 |
479 this->doNotify(); | 479 this->doNotify(); |
480 } | 480 } |
481 | 481 |
482 SkGPipeCanvas::~SkGPipeCanvas() { | 482 SkGPipeCanvas::~SkGPipeCanvas() { |
483 this->finish(true); | 483 this->finish(true); |
(...skipping 908 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1392 } | 1392 } |
1393 | 1393 |
1394 SkGPipeWriter::~SkGPipeWriter() { | 1394 SkGPipeWriter::~SkGPipeWriter() { |
1395 this->endRecording(); | 1395 this->endRecording(); |
1396 } | 1396 } |
1397 | 1397 |
1398 SkCanvas* SkGPipeWriter::startRecording(SkGPipeController* controller, uint32_t
flags, | 1398 SkCanvas* SkGPipeWriter::startRecording(SkGPipeController* controller, uint32_t
flags, |
1399 uint32_t width, uint32_t height) { | 1399 uint32_t width, uint32_t height) { |
1400 if (NULL == fCanvas) { | 1400 if (NULL == fCanvas) { |
1401 fWriter.reset(NULL, 0); | 1401 fWriter.reset(NULL, 0); |
1402 fCanvas = SkNEW_ARGS(SkGPipeCanvas, (controller, &fWriter, flags, width,
height)); | 1402 fCanvas = new SkGPipeCanvas(controller, &fWriter, flags, width, height); |
1403 } | 1403 } |
1404 controller->setCanvas(fCanvas); | 1404 controller->setCanvas(fCanvas); |
1405 return fCanvas; | 1405 return fCanvas; |
1406 } | 1406 } |
1407 | 1407 |
1408 void SkGPipeWriter::endRecording() { | 1408 void SkGPipeWriter::endRecording() { |
1409 if (fCanvas) { | 1409 if (fCanvas) { |
1410 fCanvas->finish(true); | 1410 fCanvas->finish(true); |
1411 fCanvas->unref(); | 1411 fCanvas->unref(); |
1412 fCanvas = NULL; | 1412 fCanvas = NULL; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1486 int32_t slot = this->find(img); | 1486 int32_t slot = this->find(img); |
1487 if (slot) { | 1487 if (slot) { |
1488 return slot; | 1488 return slot; |
1489 } | 1489 } |
1490 // TODO: SkImage does not expose bytes per pixel, 4 is just a best guess. | 1490 // TODO: SkImage does not expose bytes per pixel, 4 is just a best guess. |
1491 fBytesInCache += img->width() * img->height() * 4; | 1491 fBytesInCache += img->width() * img->height() * 4; |
1492 *fArray.append() = SkRef(img); | 1492 *fArray.append() = SkRef(img); |
1493 return fArray.count(); // slot is always index+1 | 1493 return fArray.count(); // slot is always index+1 |
1494 } | 1494 } |
1495 | 1495 |
OLD | NEW |