| 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 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 #include "config.h" | 26 #include "config.h" |
| 27 | 27 |
| 28 #include "platform/graphics/Canvas2DLayerBridge.h" | 28 #include "platform/graphics/Canvas2DLayerBridge.h" |
| 29 | 29 |
| 30 #include "GrContext.h" | 30 #include "GrContext.h" |
| 31 #include "SkDevice.h" | 31 #include "SkDevice.h" |
| 32 #include "SkSurface.h" | 32 #include "SkSurface.h" |
| 33 | 33 |
| 34 #include "platform/TraceEvent.h" | 34 #include "platform/TraceEvent.h" |
| 35 #include "platform/graphics/ExpensiveCanvasHeuristicParameters.h" |
| 35 #include "platform/graphics/GraphicsLayer.h" | 36 #include "platform/graphics/GraphicsLayer.h" |
| 36 #include "platform/graphics/ImageBuffer.h" | 37 #include "platform/graphics/ImageBuffer.h" |
| 37 #include "public/platform/Platform.h" | 38 #include "public/platform/Platform.h" |
| 38 #include "public/platform/WebCompositorSupport.h" | 39 #include "public/platform/WebCompositorSupport.h" |
| 39 #include "public/platform/WebGraphicsContext3D.h" | 40 #include "public/platform/WebGraphicsContext3D.h" |
| 40 #include "public/platform/WebGraphicsContext3DProvider.h" | 41 #include "public/platform/WebGraphicsContext3DProvider.h" |
| 41 #include "third_party/skia/include/core/SkData.h" | 42 #include "third_party/skia/include/core/SkData.h" |
| 42 #include "third_party/skia/include/core/SkPictureRecorder.h" | 43 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 43 #include "third_party/skia/include/core/SkSurface.h" | 44 #include "third_party/skia/include/core/SkSurface.h" |
| 44 #include "wtf/RefCountedLeakCounter.h" | 45 #include "wtf/RefCountedLeakCounter.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 } | 133 } |
| 133 | 134 |
| 134 void Canvas2DLayerBridge::startRecording() | 135 void Canvas2DLayerBridge::startRecording() |
| 135 { | 136 { |
| 136 ASSERT(m_isDeferralEnabled); | 137 ASSERT(m_isDeferralEnabled); |
| 137 m_recorder = adoptPtr(new SkPictureRecorder); | 138 m_recorder = adoptPtr(new SkPictureRecorder); |
| 138 m_recorder->beginRecording(m_size.width(), m_size.height(), nullptr); | 139 m_recorder->beginRecording(m_size.width(), m_size.height(), nullptr); |
| 139 if (m_imageBuffer) { | 140 if (m_imageBuffer) { |
| 140 m_imageBuffer->resetCanvas(m_recorder->getRecordingCanvas()); | 141 m_imageBuffer->resetCanvas(m_recorder->getRecordingCanvas()); |
| 141 } | 142 } |
| 143 m_recordingPixelCount = 0; |
| 142 } | 144 } |
| 143 | 145 |
| 144 SkCanvas* Canvas2DLayerBridge::canvas() | 146 SkCanvas* Canvas2DLayerBridge::canvas() |
| 145 { | 147 { |
| 146 if (!m_isDeferralEnabled) | 148 if (!m_isDeferralEnabled) |
| 147 return m_surface->getCanvas(); | 149 return m_surface->getCanvas(); |
| 148 return m_recorder->getRecordingCanvas(); | 150 return m_recorder->getRecordingCanvas(); |
| 149 } | 151 } |
| 150 | 152 |
| 151 void Canvas2DLayerBridge::disableDeferral() | 153 void Canvas2DLayerBridge::disableDeferral() |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 m_mailboxes.remove(releasedMailboxInfo); | 484 m_mailboxes.remove(releasedMailboxInfo); |
| 483 } | 485 } |
| 484 | 486 |
| 485 WebLayer* Canvas2DLayerBridge::layer() const | 487 WebLayer* Canvas2DLayerBridge::layer() const |
| 486 { | 488 { |
| 487 ASSERT(!m_destructionInProgress); | 489 ASSERT(!m_destructionInProgress); |
| 488 ASSERT(m_layer); | 490 ASSERT(m_layer); |
| 489 return m_layer->layer(); | 491 return m_layer->layer(); |
| 490 } | 492 } |
| 491 | 493 |
| 492 void Canvas2DLayerBridge::didDraw() | 494 void Canvas2DLayerBridge::didDraw(const FloatRect& rect) |
| 493 { | 495 { |
| 494 if (m_isDeferralEnabled) | 496 if (m_isDeferralEnabled) { |
| 495 m_haveRecordedDrawCommands = true; | 497 m_haveRecordedDrawCommands = true; |
| 498 IntRect pixelBounds = enclosingIntRect(rect); |
| 499 m_recordingPixelCount += pixelBounds.width() * pixelBounds.height(); |
| 500 if (m_recordingPixelCount >= (m_size.width() * m_size.height() * Expensi
veCanvasHeuristicParameters::ExpensiveOverdrawThreshold)) |
| 501 disableDeferral(); |
| 502 } |
| 496 } | 503 } |
| 497 | 504 |
| 498 void Canvas2DLayerBridge::finalizeFrame(const FloatRect &dirtyRect) | 505 void Canvas2DLayerBridge::finalizeFrame(const FloatRect &dirtyRect) |
| 499 { | 506 { |
| 500 ASSERT(!m_destructionInProgress); | 507 ASSERT(!m_destructionInProgress); |
| 501 m_layer->layer()->invalidateRect(enclosingIntRect(dirtyRect)); | 508 m_layer->layer()->invalidateRect(enclosingIntRect(dirtyRect)); |
| 502 m_framesPending++; | 509 m_framesPending++; |
| 503 if (m_framesPending > 1) { | 510 if (m_framesPending > 1) { |
| 504 // Turn on the rate limiter if this layer tends to accumulate a | 511 // Turn on the rate limiter if this layer tends to accumulate a |
| 505 // non-discardable multi-frame backlog of draw commands. | 512 // non-discardable multi-frame backlog of draw commands. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 528 skipQueuedDrawCommands(); | 535 skipQueuedDrawCommands(); |
| 529 } | 536 } |
| 530 | 537 |
| 531 Canvas2DLayerBridge::MailboxInfo::MailboxInfo(const MailboxInfo& other) { | 538 Canvas2DLayerBridge::MailboxInfo::MailboxInfo(const MailboxInfo& other) { |
| 532 memcpy(&m_mailbox, &other.m_mailbox, sizeof(m_mailbox)); | 539 memcpy(&m_mailbox, &other.m_mailbox, sizeof(m_mailbox)); |
| 533 m_image = other.m_image; | 540 m_image = other.m_image; |
| 534 m_parentLayerBridge = other.m_parentLayerBridge; | 541 m_parentLayerBridge = other.m_parentLayerBridge; |
| 535 } | 542 } |
| 536 | 543 |
| 537 } // namespace blink | 544 } // namespace blink |
| OLD | NEW |