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

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

Issue 2653933003: Make stream captures work on canvases that are not in the DOM. (Closed)
Patch Set: Created 3 years, 11 months 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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 FloatRect inflatedRect = rect; 312 FloatRect inflatedRect = rect;
313 inflatedRect.inflate(1); 313 inflatedRect.inflate(1);
314 m_dirtyRect.unite(inflatedRect); 314 m_dirtyRect.unite(inflatedRect);
315 } else { 315 } else {
316 m_dirtyRect.unite(rect); 316 m_dirtyRect.unite(rect);
317 } 317 }
318 if (m_context && m_context->is2d() && hasImageBuffer()) 318 if (m_context && m_context->is2d() && hasImageBuffer())
319 buffer()->didDraw(rect); 319 buffer()->didDraw(rect);
320 } 320 }
321 321
322 void HTMLCanvasElement::didFinalizeFrame() { 322 void HTMLCanvasElement::finalizeFrame() {
323 if (hasImageBuffer())
324 m_imageBuffer->finalizeFrame();
325 m_context->incrementFrameCount();
323 notifyListenersCanvasChanged(); 326 notifyListenersCanvasChanged();
327 }
328
329 void HTMLCanvasElement::didDisableAcceleration() {
330 // We must force a paint invalidation on the canvas even if it's
331 // content did not change because it layer was destroyed.
332 didDraw(FloatRect(0, 0, size().width(), size().height()));
333 }
334
335 void HTMLCanvasElement::restoreCanvasMatrixClipStack(SkCanvas* canvas) const {
336 if (m_context)
337 m_context->restoreCanvasMatrixClipStack(canvas);
338 }
339
340 void HTMLCanvasElement::doDeferredPaintInvalidation() {
341 DCHECK(!m_dirtyRect.isEmpty());
342 if (m_context->is2d()) {
343 FloatRect srcRect(0, 0, size().width(), size().height());
344 m_dirtyRect.intersect(srcRect);
345 LayoutBox* lb = layoutBox();
346 FloatRect invalidationRect;
347 if (lb) {
348 FloatRect mappedDirtyRect =
349 mapRect(m_dirtyRect, srcRect, FloatRect(lb->contentBoxRect()));
350 if (m_context->isAccelerated()) {
351 // Accelerated 2D canvases need the dirty rect to be expressed relative
352 // to the content box, as opposed to the layout box.
353 mappedDirtyRect.move(-lb->contentBoxOffset());
354 }
355 invalidationRect = mappedDirtyRect;
356 } else {
357 invalidationRect = m_dirtyRect;
358 }
359 if (hasImageBuffer()) {
360 m_imageBuffer->doPaintInvalidation(invalidationRect);
361 }
362 }
324 363
325 if (m_dirtyRect.isEmpty()) 364 if (m_dirtyRect.isEmpty())
326 return; 365 return;
327 366
328 // Propagate the m_dirtyRect accumulated so far to the compositor 367 // Propagate the m_dirtyRect accumulated so far to the compositor
329 // before restarting with a blank dirty rect. 368 // before restarting with a blank dirty rect.
330 FloatRect srcRect(0, 0, size().width(), size().height()); 369 FloatRect srcRect(0, 0, size().width(), size().height());
331 370
332 LayoutBox* ro = layoutBox(); 371 LayoutBox* ro = layoutBox();
333 // Canvas content updates do not need to be propagated as 372 // Canvas content updates do not need to be propagated as
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 m_numFramesSinceLastRenderingModeSwitch = 0; 414 m_numFramesSinceLastRenderingModeSwitch = 0;
376 m_pendingRenderingModeSwitch = true; 415 m_pendingRenderingModeSwitch = true;
377 } 416 }
378 } 417 }
379 } 418 }
380 419
381 if (m_pendingRenderingModeSwitch && buffer() && !buffer()->isAccelerated()) { 420 if (m_pendingRenderingModeSwitch && buffer() && !buffer()->isAccelerated()) {
382 m_pendingRenderingModeSwitch = false; 421 m_pendingRenderingModeSwitch = false;
383 } 422 }
384 423
385 m_context->incrementFrameCount();
386 }
387
388 void HTMLCanvasElement::didDisableAcceleration() {
389 // We must force a paint invalidation on the canvas even if it's
390 // content did not change because it layer was destroyed.
391 didDraw(FloatRect(0, 0, size().width(), size().height()));
392 }
393
394 void HTMLCanvasElement::restoreCanvasMatrixClipStack(SkCanvas* canvas) const {
395 if (m_context)
396 m_context->restoreCanvasMatrixClipStack(canvas);
397 }
398
399 void HTMLCanvasElement::doDeferredPaintInvalidation() {
400 DCHECK(!m_dirtyRect.isEmpty());
401 if (!m_context->is2d()) {
402 didFinalizeFrame();
403 } else {
404 FloatRect srcRect(0, 0, size().width(), size().height());
405 m_dirtyRect.intersect(srcRect);
406 LayoutBox* lb = layoutBox();
407 FloatRect invalidationRect;
408 if (lb) {
409 FloatRect mappedDirtyRect =
410 mapRect(m_dirtyRect, srcRect, FloatRect(lb->contentBoxRect()));
411 if (m_context->isAccelerated()) {
412 // Accelerated 2D canvases need the dirty rect to be expressed relative
413 // to the content box, as opposed to the layout box.
414 mappedDirtyRect.move(-lb->contentBoxOffset());
415 }
416 invalidationRect = mappedDirtyRect;
417 } else {
418 invalidationRect = m_dirtyRect;
419 }
420 if (hasImageBuffer()) {
421 m_imageBuffer->finalizeFrame(invalidationRect);
422 } else {
423 didFinalizeFrame();
424 }
425 }
426 DCHECK(m_dirtyRect.isEmpty()); 424 DCHECK(m_dirtyRect.isEmpty());
427 } 425 }
428 426
429 void HTMLCanvasElement::reset() { 427 void HTMLCanvasElement::reset() {
430 if (m_ignoreReset) 428 if (m_ignoreReset)
431 return; 429 return;
432 430
433 m_dirtyRect = FloatRect(); 431 m_dirtyRect = FloatRect();
434 432
435 bool ok; 433 bool ok;
(...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after
1426 m_surfaceLayerBridge = WTF::wrapUnique(new CanvasSurfaceLayerBridge(this)); 1424 m_surfaceLayerBridge = WTF::wrapUnique(new CanvasSurfaceLayerBridge(this));
1427 // Creates a placeholder layer first before Surface is created. 1425 // Creates a placeholder layer first before Surface is created.
1428 m_surfaceLayerBridge->createSolidColorLayer(); 1426 m_surfaceLayerBridge->createSolidColorLayer();
1429 } 1427 }
1430 1428
1431 void HTMLCanvasElement::OnWebLayerReplaced() { 1429 void HTMLCanvasElement::OnWebLayerReplaced() {
1432 setNeedsCompositingUpdate(); 1430 setNeedsCompositingUpdate();
1433 } 1431 }
1434 1432
1435 } // namespace blink 1433 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698