OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
317 // required multiple times per frame, the repeated flushing of deferred | 317 // required multiple times per frame, the repeated flushing of deferred |
318 // commands would cause significant overhead, so it is better to just stop | 318 // commands would cause significant overhead, so it is better to just stop |
319 // trying to defer altogether. | 319 // trying to defer altogether. |
320 if (!m_isDeferralEnabled) | 320 if (!m_isDeferralEnabled) |
321 return; | 321 return; |
322 | 322 |
323 m_isDeferralEnabled = false; | 323 m_isDeferralEnabled = false; |
324 flushRecordingOnly(); | 324 flushRecordingOnly(); |
325 m_recorder.clear(); | 325 m_recorder.clear(); |
326 // install the current matrix/clip stack onto the immediate canvas | 326 // install the current matrix/clip stack onto the immediate canvas |
327 if (m_imageBuffer) | 327 SkSurface* surface = getOrCreateSurface(); |
328 m_imageBuffer->resetCanvas(getOrCreateSurface()->getCanvas()); | 328 if (m_imageBuffer && surface) |
329 m_imageBuffer->resetCanvas(surface->getCanvas()); | |
329 } | 330 } |
330 | 331 |
331 void Canvas2DLayerBridge::setImageBuffer(ImageBuffer* imageBuffer) | 332 void Canvas2DLayerBridge::setImageBuffer(ImageBuffer* imageBuffer) |
332 { | 333 { |
333 m_imageBuffer = imageBuffer; | 334 m_imageBuffer = imageBuffer; |
334 if (m_imageBuffer && m_isDeferralEnabled) { | 335 if (m_imageBuffer && m_isDeferralEnabled) { |
335 m_imageBuffer->resetCanvas(m_recorder->getRecordingCanvas()); | 336 m_imageBuffer->resetCanvas(m_recorder->getRecordingCanvas()); |
336 } | 337 } |
337 } | 338 } |
338 | 339 |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
519 if (m_contextProvider) | 520 if (m_contextProvider) |
520 sharedContext = m_contextProvider->context3d(); | 521 sharedContext = m_contextProvider->context3d(); |
521 | 522 |
522 if (sharedContext && !sharedContext->isContextLost()) { | 523 if (sharedContext && !sharedContext->isContextLost()) { |
523 GrContext* grCtx = m_contextProvider->grContext(); | 524 GrContext* grCtx = m_contextProvider->grContext(); |
524 bool surfaceIsAccelerated; | 525 bool surfaceIsAccelerated; |
525 RefPtr<SkSurface> surface(createSkSurface(grCtx, m_size, m_msaaSampleCou nt, m_opacityMode, &surfaceIsAccelerated)); | 526 RefPtr<SkSurface> surface(createSkSurface(grCtx, m_size, m_msaaSampleCou nt, m_opacityMode, &surfaceIsAccelerated)); |
526 // Current paradigm does support switching from accelerated to non-accel erated, which would be tricky | 527 // Current paradigm does support switching from accelerated to non-accel erated, which would be tricky |
527 // due to changes to the layer tree, which can only happen at specific t imes during the document lifecycle. | 528 // due to changes to the layer tree, which can only happen at specific t imes during the document lifecycle. |
528 // Therefore, we can only accept the restored surface if it is accelerat ed. | 529 // Therefore, we can only accept the restored surface if it is accelerat ed. |
529 if (surface.get() && surfaceIsAccelerated) { | 530 if (surface && surfaceIsAccelerated) { |
530 m_surface = surface.release(); | 531 m_surface = surface.release(); |
531 // FIXME: draw sad canvas picture into new buffer crbug.com/243842 | 532 // FIXME: draw sad canvas picture into new buffer crbug.com/243842 |
532 } | 533 } |
533 } | 534 } |
534 if (m_imageBuffer) | 535 if (m_imageBuffer) |
535 m_imageBuffer->updateGPUMemoryUsage(); | 536 m_imageBuffer->updateGPUMemoryUsage(); |
536 | 537 |
537 return m_surface; | 538 return m_surface; |
538 } | 539 } |
539 | 540 |
(...skipping 16 matching lines...) Expand all Loading... | |
556 | 557 |
557 if (bitmap) { | 558 if (bitmap) { |
558 // Using accelerated 2d canvas with software renderer, which | 559 // Using accelerated 2d canvas with software renderer, which |
559 // should only happen in tests that use fake graphics contexts | 560 // should only happen in tests that use fake graphics contexts |
560 // or in Android WebView in software mode. In this case, we do | 561 // or in Android WebView in software mode. In this case, we do |
561 // not care about producing any results for this canvas. | 562 // not care about producing any results for this canvas. |
562 skipQueuedDrawCommands(); | 563 skipQueuedDrawCommands(); |
563 m_lastImageId = 0; | 564 m_lastImageId = 0; |
564 return false; | 565 return false; |
565 } | 566 } |
566 if (!checkSurfaceValid()) | 567 |
Justin Novosad
2015/12/15 18:55:55
This check is expensive and was redundant with the
| |
568 RefPtr<SkImage> image = newImageSnapshot(PreferAcceleration); | |
569 if (!image) | |
567 return false; | 570 return false; |
568 | 571 |
569 WebGraphicsContext3D* webContext = context(); | 572 WebGraphicsContext3D* webContext = context(); |
570 | 573 |
571 RefPtr<SkImage> image = newImageSnapshot(PreferAcceleration); | |
572 | |
573 // Early exit if canvas was not drawn to since last prepareMailbox | 574 // Early exit if canvas was not drawn to since last prepareMailbox |
574 GLenum filter = m_filterQuality == kNone_SkFilterQuality ? GL_NEAREST : GL_L INEAR; | 575 GLenum filter = m_filterQuality == kNone_SkFilterQuality ? GL_NEAREST : GL_L INEAR; |
575 if (image->uniqueID() == m_lastImageId && filter == m_lastFilter) | 576 if (image->uniqueID() == m_lastImageId && filter == m_lastFilter) |
576 return false; | 577 return false; |
577 m_lastImageId = image->uniqueID(); | 578 m_lastImageId = image->uniqueID(); |
578 m_lastFilter = filter; | 579 m_lastFilter = filter; |
579 | 580 |
580 { | 581 { |
581 MailboxInfo tmp; | 582 MailboxInfo tmp; |
582 tmp.m_image = image; | 583 tmp.m_image = image; |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
755 | 756 |
756 void Canvas2DLayerBridge::willProcessTask() | 757 void Canvas2DLayerBridge::willProcessTask() |
757 { | 758 { |
758 ASSERT_NOT_REACHED(); | 759 ASSERT_NOT_REACHED(); |
759 } | 760 } |
760 | 761 |
761 PassRefPtr<SkImage> Canvas2DLayerBridge::newImageSnapshot(AccelerationHint hint) | 762 PassRefPtr<SkImage> Canvas2DLayerBridge::newImageSnapshot(AccelerationHint hint) |
762 { | 763 { |
763 if (!checkSurfaceValid()) | 764 if (!checkSurfaceValid()) |
764 return nullptr; | 765 return nullptr; |
765 getOrCreateSurface(hint); | 766 if (!getOrCreateSurface(hint)) |
767 return nullptr; | |
766 flush(); | 768 flush(); |
767 // A readback operation may alter the texture parameters, which may affect | 769 // A readback operation may alter the texture parameters, which may affect |
768 // the compositor's behavior. Therefore, we must trigger copy-on-write | 770 // the compositor's behavior. Therefore, we must trigger copy-on-write |
769 // even though we are not technically writing to the texture, only to its | 771 // even though we are not technically writing to the texture, only to its |
770 // parameters. | 772 // parameters. |
771 getOrCreateSurface()->notifyContentWillChange(SkSurface::kRetain_ContentChan geMode); | 773 getOrCreateSurface()->notifyContentWillChange(SkSurface::kRetain_ContentChan geMode); |
772 return adoptRef(m_surface->newImageSnapshot()); | 774 return adoptRef(m_surface->newImageSnapshot()); |
773 } | 775 } |
774 | 776 |
775 void Canvas2DLayerBridge::willOverwriteCanvas() | 777 void Canvas2DLayerBridge::willOverwriteCanvas() |
776 { | 778 { |
777 skipQueuedDrawCommands(); | 779 skipQueuedDrawCommands(); |
778 } | 780 } |
779 | 781 |
780 Canvas2DLayerBridge::MailboxInfo::MailboxInfo(const MailboxInfo& other) | 782 Canvas2DLayerBridge::MailboxInfo::MailboxInfo(const MailboxInfo& other) |
781 { | 783 { |
782 memcpy(&m_mailbox, &other.m_mailbox, sizeof(m_mailbox)); | 784 memcpy(&m_mailbox, &other.m_mailbox, sizeof(m_mailbox)); |
783 m_image = other.m_image; | 785 m_image = other.m_image; |
784 m_parentLayerBridge = other.m_parentLayerBridge; | 786 m_parentLayerBridge = other.m_parentLayerBridge; |
785 } | 787 } |
786 | 788 |
787 void Canvas2DLayerBridge::Logger::reportHibernationEvent(HibernationEvent event) | 789 void Canvas2DLayerBridge::Logger::reportHibernationEvent(HibernationEvent event) |
788 { | 790 { |
789 blink::Platform::current()->histogramEnumeration("Canvas.HibernationEvents", event, HibernationEventCount); | 791 blink::Platform::current()->histogramEnumeration("Canvas.HibernationEvents", event, HibernationEventCount); |
790 } | 792 } |
791 | 793 |
792 } // namespace blink | 794 } // namespace blink |
OLD | NEW |