| 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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 return nullptr; | 255 return nullptr; |
| 256 } | 256 } |
| 257 | 257 |
| 258 m_context = factory->create(this, attributes, document()); | 258 m_context = factory->create(this, attributes, document()); |
| 259 if (!m_context) | 259 if (!m_context) |
| 260 return nullptr; | 260 return nullptr; |
| 261 | 261 |
| 262 if (m_context->is3d()) { | 262 if (m_context->is3d()) { |
| 263 updateExternallyAllocatedMemory(); | 263 updateExternallyAllocatedMemory(); |
| 264 } | 264 } |
| 265 |
| 266 LayoutObject* layoutObject = this->layoutObject(); |
| 267 if (layoutObject && m_context->is2d() && |
| 268 !m_context->creationAttributes().alpha()) { |
| 269 // In the alpha false case, canvas is initially opaque even though there is |
| 270 // no ImageBuffer, so we need to trigger an invalidation. |
| 271 didDraw(FloatRect(0, 0, size().width(), size().height())); |
| 272 } |
| 273 |
| 265 setNeedsCompositingUpdate(); | 274 setNeedsCompositingUpdate(); |
| 266 | 275 |
| 267 return m_context.get(); | 276 return m_context.get(); |
| 268 } | 277 } |
| 269 | 278 |
| 270 bool HTMLCanvasElement::shouldBeDirectComposited() const { | 279 bool HTMLCanvasElement::shouldBeDirectComposited() const { |
| 271 return (m_context && m_context->isAccelerated()) || | 280 return (m_context && m_context->isAccelerated()) || |
| 272 (hasImageBuffer() && buffer()->isExpensiveToPaint()) || | 281 (hasImageBuffer() && buffer()->isExpensiveToPaint()) || |
| 273 (!!m_surfaceLayerBridge); | 282 (!!m_surfaceLayerBridge); |
| 274 } | 283 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 // FIXME: is this invalidation using the correct compositing state? | 340 // FIXME: is this invalidation using the correct compositing state? |
| 332 DisableCompositingQueryAsserts disabler; | 341 DisableCompositingQueryAsserts disabler; |
| 333 ro->invalidatePaintRectangle(mappedDirtyRect); | 342 ro->invalidatePaintRectangle(mappedDirtyRect); |
| 334 } | 343 } |
| 335 m_dirtyRect = FloatRect(); | 344 m_dirtyRect = FloatRect(); |
| 336 | 345 |
| 337 m_numFramesSinceLastRenderingModeSwitch++; | 346 m_numFramesSinceLastRenderingModeSwitch++; |
| 338 if (RuntimeEnabledFeatures:: | 347 if (RuntimeEnabledFeatures:: |
| 339 enableCanvas2dDynamicRenderingModeSwitchingEnabled() && | 348 enableCanvas2dDynamicRenderingModeSwitchingEnabled() && |
| 340 !RuntimeEnabledFeatures::canvas2dFixedRenderingModeEnabled()) { | 349 !RuntimeEnabledFeatures::canvas2dFixedRenderingModeEnabled()) { |
| 341 if (m_context->is2d() && buffer() && buffer()->isAccelerated() && | 350 if (m_context->is2d() && hasImageBuffer() && buffer()->isAccelerated() && |
| 342 m_numFramesSinceLastRenderingModeSwitch >= | 351 m_numFramesSinceLastRenderingModeSwitch >= |
| 343 ExpensiveCanvasHeuristicParameters::MinFramesBeforeSwitch && | 352 ExpensiveCanvasHeuristicParameters::MinFramesBeforeSwitch && |
| 344 !m_pendingRenderingModeSwitch) { | 353 !m_pendingRenderingModeSwitch) { |
| 345 if (!m_context->isAccelerationOptimalForCanvasContent()) { | 354 if (!m_context->isAccelerationOptimalForCanvasContent()) { |
| 346 // The switch must be done asynchronously in order to avoid switching | 355 // The switch must be done asynchronously in order to avoid switching |
| 347 // during the paint invalidation step. | 356 // during the paint invalidation step. |
| 348 Platform::current()->currentThread()->getWebTaskRunner()->postTask( | 357 Platform::current()->currentThread()->getWebTaskRunner()->postTask( |
| 349 BLINK_FROM_HERE, | 358 BLINK_FROM_HERE, |
| 350 WTF::bind( | 359 WTF::bind( |
| 351 [](WeakPtr<ImageBuffer> buffer) { | 360 [](WeakPtr<ImageBuffer> buffer) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 376 void HTMLCanvasElement::restoreCanvasMatrixClipStack(SkCanvas* canvas) const { | 385 void HTMLCanvasElement::restoreCanvasMatrixClipStack(SkCanvas* canvas) const { |
| 377 if (m_context) | 386 if (m_context) |
| 378 m_context->restoreCanvasMatrixClipStack(canvas); | 387 m_context->restoreCanvasMatrixClipStack(canvas); |
| 379 } | 388 } |
| 380 | 389 |
| 381 void HTMLCanvasElement::doDeferredPaintInvalidation() { | 390 void HTMLCanvasElement::doDeferredPaintInvalidation() { |
| 382 DCHECK(!m_dirtyRect.isEmpty()); | 391 DCHECK(!m_dirtyRect.isEmpty()); |
| 383 if (!m_context->is2d()) { | 392 if (!m_context->is2d()) { |
| 384 didFinalizeFrame(); | 393 didFinalizeFrame(); |
| 385 } else { | 394 } else { |
| 386 DCHECK(hasImageBuffer()); | |
| 387 FloatRect srcRect(0, 0, size().width(), size().height()); | 395 FloatRect srcRect(0, 0, size().width(), size().height()); |
| 388 m_dirtyRect.intersect(srcRect); | 396 m_dirtyRect.intersect(srcRect); |
| 389 LayoutBox* lb = layoutBox(); | 397 LayoutBox* lb = layoutBox(); |
| 398 FloatRect invalidationRect; |
| 390 if (lb) { | 399 if (lb) { |
| 391 FloatRect mappedDirtyRect = | 400 FloatRect mappedDirtyRect = |
| 392 mapRect(m_dirtyRect, srcRect, FloatRect(lb->contentBoxRect())); | 401 mapRect(m_dirtyRect, srcRect, FloatRect(lb->contentBoxRect())); |
| 393 if (m_context->isAccelerated()) { | 402 if (m_context->isAccelerated()) { |
| 394 // Accelerated 2D canvases need the dirty rect to be expressed relative | 403 // Accelerated 2D canvases need the dirty rect to be expressed relative |
| 395 // to the content box, as opposed to the layout box. | 404 // to the content box, as opposed to the layout box. |
| 396 mappedDirtyRect.move(-lb->contentBoxOffset()); | 405 mappedDirtyRect.move(-lb->contentBoxOffset()); |
| 397 } | 406 } |
| 398 m_imageBuffer->finalizeFrame(mappedDirtyRect); | 407 invalidationRect = mappedDirtyRect; |
| 399 } else { | 408 } else { |
| 400 m_imageBuffer->finalizeFrame(m_dirtyRect); | 409 invalidationRect = m_dirtyRect; |
| 410 } |
| 411 if (hasImageBuffer()) { |
| 412 m_imageBuffer->finalizeFrame(invalidationRect); |
| 413 } else { |
| 414 didFinalizeFrame(); |
| 401 } | 415 } |
| 402 } | 416 } |
| 403 DCHECK(m_dirtyRect.isEmpty()); | 417 DCHECK(m_dirtyRect.isEmpty()); |
| 404 } | 418 } |
| 405 | 419 |
| 406 void HTMLCanvasElement::reset() { | 420 void HTMLCanvasElement::reset() { |
| 407 if (m_ignoreReset) | 421 if (m_ignoreReset) |
| 408 return; | 422 return; |
| 409 | 423 |
| 410 m_dirtyRect = FloatRect(); | 424 m_dirtyRect = FloatRect(); |
| (...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1369 mojom::blink::OffscreenCanvasSurfacePtr service; | 1383 mojom::blink::OffscreenCanvasSurfacePtr service; |
| 1370 Platform::current()->interfaceProvider()->getInterface( | 1384 Platform::current()->interfaceProvider()->getInterface( |
| 1371 mojo::GetProxy(&service)); | 1385 mojo::GetProxy(&service)); |
| 1372 m_surfaceLayerBridge = | 1386 m_surfaceLayerBridge = |
| 1373 wrapUnique(new CanvasSurfaceLayerBridge(std::move(service))); | 1387 wrapUnique(new CanvasSurfaceLayerBridge(std::move(service))); |
| 1374 return m_surfaceLayerBridge->createSurfaceLayer(this->width(), | 1388 return m_surfaceLayerBridge->createSurfaceLayer(this->width(), |
| 1375 this->height()); | 1389 this->height()); |
| 1376 } | 1390 } |
| 1377 | 1391 |
| 1378 } // namespace blink | 1392 } // namespace blink |
| OLD | NEW |