| 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) |
| 152 , m_pendingRenderingModeSwitch(false) |
| 151 { | 153 { |
| 152 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::CanvasCreated); | 154 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::CanvasCreated); |
| 153 } | 155 } |
| 154 | 156 |
| 155 DEFINE_NODE_FACTORY(HTMLCanvasElement) | 157 DEFINE_NODE_FACTORY(HTMLCanvasElement) |
| 156 | 158 |
| 157 HTMLCanvasElement::~HTMLCanvasElement() | 159 HTMLCanvasElement::~HTMLCanvasElement() |
| 158 { | 160 { |
| 159 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_external
lyAllocatedMemory); | 161 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_external
lyAllocatedMemory); |
| 160 } | 162 } |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 // paint invalidations if the canvas is accelerated, since | 311 // paint invalidations if the canvas is accelerated, since |
| 310 // the canvas contents are sent separately through a texture layer. | 312 // the canvas contents are sent separately through a texture layer. |
| 311 if (ro && (!m_context || !m_context->isAccelerated())) { | 313 if (ro && (!m_context || !m_context->isAccelerated())) { |
| 312 LayoutRect mappedDirtyRect(enclosingIntRect(mapRect(m_dirtyRect, srcRect
, FloatRect(ro->contentBoxRect())))); | 314 LayoutRect mappedDirtyRect(enclosingIntRect(mapRect(m_dirtyRect, srcRect
, FloatRect(ro->contentBoxRect())))); |
| 313 // For querying PaintLayer::compositingState() | 315 // For querying PaintLayer::compositingState() |
| 314 // FIXME: is this invalidation using the correct compositing state? | 316 // FIXME: is this invalidation using the correct compositing state? |
| 315 DisableCompositingQueryAsserts disabler; | 317 DisableCompositingQueryAsserts disabler; |
| 316 ro->invalidatePaintRectangle(mappedDirtyRect); | 318 ro->invalidatePaintRectangle(mappedDirtyRect); |
| 317 } | 319 } |
| 318 m_dirtyRect = FloatRect(); | 320 m_dirtyRect = FloatRect(); |
| 321 |
| 322 m_numFramesSinceLastRenderingModeSwitch++; |
| 323 if (RuntimeEnabledFeatures::enableCanvas2dDynamicRenderingModeSwitchingEnabl
ed() |
| 324 && !RuntimeEnabledFeatures::canvas2dFixedRenderingModeEnabled()) { |
| 325 if (m_context->is2d() && buffer()->isAccelerated() |
| 326 && m_numFramesSinceLastRenderingModeSwitch >= ExpensiveCanvasHeurist
icParameters::MinFramesBeforeSwitch |
| 327 && !m_pendingRenderingModeSwitch) { |
| 328 if (!m_context->isAccelerationOptimalForCanvasContent()) { |
| 329 // The switch must be done asynchronously in order to avoid swit
ching during the paint invalidation step. |
| 330 Platform::current()->currentThread()->getWebTaskRunner()->postTa
sk( |
| 331 BLINK_FROM_HERE, |
| 332 WTF::bind([](WeakPtr<ImageBuffer> buffer) { |
| 333 if (buffer) { |
| 334 buffer->disableAcceleration(); |
| 335 } |
| 336 }, |
| 337 m_imageBuffer->m_weakPtrFactory.createWeakPtr())); |
| 338 m_numFramesSinceLastRenderingModeSwitch = 0; |
| 339 m_pendingRenderingModeSwitch = true; |
| 340 } |
| 341 } |
| 342 } |
| 343 |
| 344 if (m_pendingRenderingModeSwitch && !buffer()->isAccelerated()) { |
| 345 m_pendingRenderingModeSwitch = false; |
| 346 } |
| 319 } | 347 } |
| 320 | 348 |
| 321 void HTMLCanvasElement::didDisableAcceleration() | 349 void HTMLCanvasElement::didDisableAcceleration() |
| 322 { | 350 { |
| 323 // We must force a paint invalidation on the canvas even if it's | 351 // We must force a paint invalidation on the canvas even if it's |
| 324 // content did not change because it layer was destroyed. | 352 // content did not change because it layer was destroyed. |
| 325 didDraw(FloatRect(0, 0, size().width(), size().height())); | 353 didDraw(FloatRect(0, 0, size().width(), size().height())); |
| 326 } | 354 } |
| 327 | 355 |
| 328 void HTMLCanvasElement::restoreCanvasMatrixClipStack(SkCanvas* canvas) const | 356 void HTMLCanvasElement::restoreCanvasMatrixClipStack(SkCanvas* canvas) const |
| (...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1195 | 1223 |
| 1196 bool HTMLCanvasElement::createSurfaceLayer() | 1224 bool HTMLCanvasElement::createSurfaceLayer() |
| 1197 { | 1225 { |
| 1198 DCHECK(!m_surfaceLayerBridge); | 1226 DCHECK(!m_surfaceLayerBridge); |
| 1199 std::unique_ptr<CanvasSurfaceLayerBridgeClient> bridgeClient = wrapUnique(ne
w CanvasSurfaceLayerBridgeClientImpl()); | 1227 std::unique_ptr<CanvasSurfaceLayerBridgeClient> bridgeClient = wrapUnique(ne
w CanvasSurfaceLayerBridgeClientImpl()); |
| 1200 m_surfaceLayerBridge = wrapUnique(new CanvasSurfaceLayerBridge(std::move(bri
dgeClient))); | 1228 m_surfaceLayerBridge = wrapUnique(new CanvasSurfaceLayerBridge(std::move(bri
dgeClient))); |
| 1201 return m_surfaceLayerBridge->createSurfaceLayer(this->width(), this->height(
)); | 1229 return m_surfaceLayerBridge->createSurfaceLayer(this->width(), this->height(
)); |
| 1202 } | 1230 } |
| 1203 | 1231 |
| 1204 } // namespace blink | 1232 } // namespace blink |
| OLD | NEW |