Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2007 Alp Toker <alp@atoker.com> | 3 * Copyright (C) 2007 Alp Toker <alp@atoker.com> |
| 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. | 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 inline HTMLCanvasElement::HTMLCanvasElement(Document& document) | 141 inline HTMLCanvasElement::HTMLCanvasElement(Document& document) |
| 142 : HTMLElement(canvasTag, document) | 142 : HTMLElement(canvasTag, document) |
| 143 , ContextLifecycleObserver(&document) | 143 , ContextLifecycleObserver(&document) |
| 144 , PageVisibilityObserver(document.page()) | 144 , PageVisibilityObserver(document.page()) |
| 145 , m_size(DefaultWidth, DefaultHeight) | 145 , m_size(DefaultWidth, DefaultHeight) |
| 146 , m_ignoreReset(false) | 146 , m_ignoreReset(false) |
| 147 , m_externallyAllocatedMemory(0) | 147 , m_externallyAllocatedMemory(0) |
| 148 , m_originClean(true) | 148 , m_originClean(true) |
| 149 , m_didFailToCreateImageBuffer(false) | 149 , m_didFailToCreateImageBuffer(false) |
| 150 , m_imageBufferIsClear(false) | 150 , m_imageBufferIsClear(false) |
| 151 , m_numFramesSinceLastRenderingModeSwitch(0) | |
| 151 { | 152 { |
| 152 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::CanvasCreated); | 153 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::CanvasCreated); |
| 153 } | 154 } |
| 154 | 155 |
| 155 DEFINE_NODE_FACTORY(HTMLCanvasElement) | 156 DEFINE_NODE_FACTORY(HTMLCanvasElement) |
| 156 | 157 |
| 157 HTMLCanvasElement::~HTMLCanvasElement() | 158 HTMLCanvasElement::~HTMLCanvasElement() |
| 158 { | 159 { |
| 159 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_external lyAllocatedMemory); | 160 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_external lyAllocatedMemory); |
| 160 } | 161 } |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 // paint invalidations if the canvas is accelerated, since | 310 // paint invalidations if the canvas is accelerated, since |
| 310 // the canvas contents are sent separately through a texture layer. | 311 // the canvas contents are sent separately through a texture layer. |
| 311 if (ro && (!m_context || !m_context->isAccelerated())) { | 312 if (ro && (!m_context || !m_context->isAccelerated())) { |
| 312 LayoutRect mappedDirtyRect(enclosingIntRect(mapRect(m_dirtyRect, srcRect , FloatRect(ro->contentBoxRect())))); | 313 LayoutRect mappedDirtyRect(enclosingIntRect(mapRect(m_dirtyRect, srcRect , FloatRect(ro->contentBoxRect())))); |
| 313 // For querying PaintLayer::compositingState() | 314 // For querying PaintLayer::compositingState() |
| 314 // FIXME: is this invalidation using the correct compositing state? | 315 // FIXME: is this invalidation using the correct compositing state? |
| 315 DisableCompositingQueryAsserts disabler; | 316 DisableCompositingQueryAsserts disabler; |
| 316 ro->invalidatePaintRectangle(mappedDirtyRect); | 317 ro->invalidatePaintRectangle(mappedDirtyRect); |
| 317 } | 318 } |
| 318 m_dirtyRect = FloatRect(); | 319 m_dirtyRect = FloatRect(); |
| 320 | |
| 321 m_numFramesSinceLastRenderingModeSwitch++; | |
| 322 if (m_context->is2d() && buffer()->isAccelerated() | |
| 323 && m_numFramesSinceLastRenderingModeSwitch >= ExpensiveCanvasHeuristicPa rameters::MinFramesBeforeSwitch) { | |
| 324 if (RuntimeEnabledFeatures::enableCanvas2dDynamicRenderingModeSwitchingE nabled()) { | |
|
Stephen White
2016/07/19 15:47:41
Nit: perhaps this check should be outside of all o
sebastienlc
2016/07/19 18:59:24
Done.
| |
| 325 if (!m_context->isAccelerationOptimalForCanvasContent()) { | |
| 326 // The switch must be done asynchronously in order to avoid swit ching during the paint invalidation step. | |
| 327 Platform::current()->currentThread()->getWebTaskRunner()->postTa sk( | |
| 328 BLINK_FROM_HERE, | |
| 329 WTF::bind([](WeakPtr<ImageBuffer> buffer) { | |
|
Stephen White
2016/07/19 15:47:41
Do you still need WTF::bind() here, or could you j
sebastienlc
2016/07/19 18:59:24
I tried but the type conversion doesn't seem to wo
| |
| 330 if (buffer) { | |
| 331 buffer->disableAcceleration(); | |
| 332 } | |
| 333 }, | |
| 334 m_imageBuffer->m_weakPtrFactory.createWeakPtr())); | |
| 335 m_numFramesSinceLastRenderingModeSwitch = 0; | |
| 336 } | |
| 337 } | |
| 338 } | |
| 319 } | 339 } |
| 320 | 340 |
| 321 void HTMLCanvasElement::didDisableAcceleration() | 341 void HTMLCanvasElement::didDisableAcceleration() |
| 322 { | 342 { |
| 323 // We must force a paint invalidation on the canvas even if it's | 343 // We must force a paint invalidation on the canvas even if it's |
| 324 // content did not change because it layer was destroyed. | 344 // content did not change because it layer was destroyed. |
| 325 didDraw(FloatRect(0, 0, size().width(), size().height())); | 345 didDraw(FloatRect(0, 0, size().width(), size().height())); |
| 326 } | 346 } |
| 327 | 347 |
| 328 void HTMLCanvasElement::restoreCanvasMatrixClipStack(SkCanvas* canvas) const | 348 void HTMLCanvasElement::restoreCanvasMatrixClipStack(SkCanvas* canvas) const |
| (...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1195 | 1215 |
| 1196 bool HTMLCanvasElement::createSurfaceLayer() | 1216 bool HTMLCanvasElement::createSurfaceLayer() |
| 1197 { | 1217 { |
| 1198 DCHECK(!m_surfaceLayerBridge); | 1218 DCHECK(!m_surfaceLayerBridge); |
| 1199 std::unique_ptr<CanvasSurfaceLayerBridgeClient> bridgeClient = wrapUnique(ne w CanvasSurfaceLayerBridgeClientImpl()); | 1219 std::unique_ptr<CanvasSurfaceLayerBridgeClient> bridgeClient = wrapUnique(ne w CanvasSurfaceLayerBridgeClientImpl()); |
| 1200 m_surfaceLayerBridge = wrapUnique(new CanvasSurfaceLayerBridge(std::move(bri dgeClient))); | 1220 m_surfaceLayerBridge = wrapUnique(new CanvasSurfaceLayerBridge(std::move(bri dgeClient))); |
| 1201 return m_surfaceLayerBridge->createSurfaceLayer(this->width(), this->height( )); | 1221 return m_surfaceLayerBridge->createSurfaceLayer(this->width(), this->height( )); |
| 1202 } | 1222 } |
| 1203 | 1223 |
| 1204 } // namespace blink | 1224 } // namespace blink |
| OLD | NEW |