Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(511)

Side by Side Diff: third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp

Issue 2558973002: Add missing paint invalidation when creating canvas 2d context with no alpha (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
271 // ImageBuffer, so we need to trigger an invalidation.
Stephen White 2016/12/07 22:27:48 Nit: join this line with previous.
272 didDraw(FloatRect(0, 0, size().width(), size().height()));
273 }
274
265 setNeedsCompositingUpdate(); 275 setNeedsCompositingUpdate();
266 276
267 return m_context.get(); 277 return m_context.get();
268 } 278 }
269 279
270 bool HTMLCanvasElement::shouldBeDirectComposited() const { 280 bool HTMLCanvasElement::shouldBeDirectComposited() const {
271 return (m_context && m_context->isAccelerated()) || 281 return (m_context && m_context->isAccelerated()) ||
272 (hasImageBuffer() && buffer()->isExpensiveToPaint()) || 282 (hasImageBuffer() && buffer()->isExpensiveToPaint()) ||
273 (!!m_surfaceLayerBridge); 283 (!!m_surfaceLayerBridge);
274 } 284 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 // FIXME: is this invalidation using the correct compositing state? 341 // FIXME: is this invalidation using the correct compositing state?
332 DisableCompositingQueryAsserts disabler; 342 DisableCompositingQueryAsserts disabler;
333 ro->invalidatePaintRectangle(mappedDirtyRect); 343 ro->invalidatePaintRectangle(mappedDirtyRect);
334 } 344 }
335 m_dirtyRect = FloatRect(); 345 m_dirtyRect = FloatRect();
336 346
337 m_numFramesSinceLastRenderingModeSwitch++; 347 m_numFramesSinceLastRenderingModeSwitch++;
338 if (RuntimeEnabledFeatures:: 348 if (RuntimeEnabledFeatures::
339 enableCanvas2dDynamicRenderingModeSwitchingEnabled() && 349 enableCanvas2dDynamicRenderingModeSwitchingEnabled() &&
340 !RuntimeEnabledFeatures::canvas2dFixedRenderingModeEnabled()) { 350 !RuntimeEnabledFeatures::canvas2dFixedRenderingModeEnabled()) {
341 if (m_context->is2d() && buffer() && buffer()->isAccelerated() && 351 if (m_context->is2d() && hasImageBuffer() && buffer()->isAccelerated() &&
342 m_numFramesSinceLastRenderingModeSwitch >= 352 m_numFramesSinceLastRenderingModeSwitch >=
343 ExpensiveCanvasHeuristicParameters::MinFramesBeforeSwitch && 353 ExpensiveCanvasHeuristicParameters::MinFramesBeforeSwitch &&
344 !m_pendingRenderingModeSwitch) { 354 !m_pendingRenderingModeSwitch) {
345 if (!m_context->isAccelerationOptimalForCanvasContent()) { 355 if (!m_context->isAccelerationOptimalForCanvasContent()) {
346 // The switch must be done asynchronously in order to avoid switching 356 // The switch must be done asynchronously in order to avoid switching
347 // during the paint invalidation step. 357 // during the paint invalidation step.
348 Platform::current()->currentThread()->getWebTaskRunner()->postTask( 358 Platform::current()->currentThread()->getWebTaskRunner()->postTask(
349 BLINK_FROM_HERE, 359 BLINK_FROM_HERE,
350 WTF::bind( 360 WTF::bind(
351 [](WeakPtr<ImageBuffer> buffer) { 361 [](WeakPtr<ImageBuffer> buffer) {
(...skipping 24 matching lines...) Expand all
376 void HTMLCanvasElement::restoreCanvasMatrixClipStack(SkCanvas* canvas) const { 386 void HTMLCanvasElement::restoreCanvasMatrixClipStack(SkCanvas* canvas) const {
377 if (m_context) 387 if (m_context)
378 m_context->restoreCanvasMatrixClipStack(canvas); 388 m_context->restoreCanvasMatrixClipStack(canvas);
379 } 389 }
380 390
381 void HTMLCanvasElement::doDeferredPaintInvalidation() { 391 void HTMLCanvasElement::doDeferredPaintInvalidation() {
382 DCHECK(!m_dirtyRect.isEmpty()); 392 DCHECK(!m_dirtyRect.isEmpty());
383 if (!m_context->is2d()) { 393 if (!m_context->is2d()) {
384 didFinalizeFrame(); 394 didFinalizeFrame();
385 } else { 395 } else {
386 DCHECK(hasImageBuffer());
387 FloatRect srcRect(0, 0, size().width(), size().height()); 396 FloatRect srcRect(0, 0, size().width(), size().height());
388 m_dirtyRect.intersect(srcRect); 397 m_dirtyRect.intersect(srcRect);
389 LayoutBox* lb = layoutBox(); 398 LayoutBox* lb = layoutBox();
399 FloatRect invalidationRect;
390 if (lb) { 400 if (lb) {
391 FloatRect mappedDirtyRect = 401 FloatRect mappedDirtyRect =
392 mapRect(m_dirtyRect, srcRect, FloatRect(lb->contentBoxRect())); 402 mapRect(m_dirtyRect, srcRect, FloatRect(lb->contentBoxRect()));
393 if (m_context->isAccelerated()) { 403 if (m_context->isAccelerated()) {
394 // Accelerated 2D canvases need the dirty rect to be expressed relative 404 // Accelerated 2D canvases need the dirty rect to be expressed relative
395 // to the content box, as opposed to the layout box. 405 // to the content box, as opposed to the layout box.
396 mappedDirtyRect.move(-lb->contentBoxOffset()); 406 mappedDirtyRect.move(-lb->contentBoxOffset());
397 } 407 }
398 m_imageBuffer->finalizeFrame(mappedDirtyRect); 408 invalidationRect = mappedDirtyRect;
399 } else { 409 } else {
400 m_imageBuffer->finalizeFrame(m_dirtyRect); 410 invalidationRect = m_dirtyRect;
411 }
412 if (hasImageBuffer()) {
413 m_imageBuffer->finalizeFrame(invalidationRect);
414 } else {
415 didFinalizeFrame();
401 } 416 }
402 } 417 }
403 DCHECK(m_dirtyRect.isEmpty()); 418 DCHECK(m_dirtyRect.isEmpty());
404 } 419 }
405 420
406 void HTMLCanvasElement::reset() { 421 void HTMLCanvasElement::reset() {
407 if (m_ignoreReset) 422 if (m_ignoreReset)
408 return; 423 return;
409 424
410 m_dirtyRect = FloatRect(); 425 m_dirtyRect = FloatRect();
(...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 mojom::blink::OffscreenCanvasSurfacePtr service; 1384 mojom::blink::OffscreenCanvasSurfacePtr service;
1370 Platform::current()->interfaceProvider()->getInterface( 1385 Platform::current()->interfaceProvider()->getInterface(
1371 mojo::GetProxy(&service)); 1386 mojo::GetProxy(&service));
1372 m_surfaceLayerBridge = 1387 m_surfaceLayerBridge =
1373 wrapUnique(new CanvasSurfaceLayerBridge(std::move(service))); 1388 wrapUnique(new CanvasSurfaceLayerBridge(std::move(service)));
1374 return m_surfaceLayerBridge->createSurfaceLayer(this->width(), 1389 return m_surfaceLayerBridge->createSurfaceLayer(this->width(),
1375 this->height()); 1390 this->height());
1376 } 1391 }
1377 1392
1378 } // namespace blink 1393 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698