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

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

Issue 1467103003: Basic use implementation for MediaStream from Canvas: captureStream() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: perkj@ comments. Created 5 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 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 clearCopiedImage(); 276 clearCopiedImage();
277 if (layoutObject()) 277 if (layoutObject())
278 layoutObject()->setMayNeedPaintInvalidation(); 278 layoutObject()->setMayNeedPaintInvalidation();
279 m_dirtyRect.unite(rect); 279 m_dirtyRect.unite(rect);
280 if (m_context && m_context->is2d() && hasImageBuffer()) 280 if (m_context && m_context->is2d() && hasImageBuffer())
281 buffer()->didDraw(rect); 281 buffer()->didDraw(rect);
282 } 282 }
283 283
284 void HTMLCanvasElement::didFinalizeFrame() 284 void HTMLCanvasElement::didFinalizeFrame()
285 { 285 {
286 notifyListenersCanvasChanged();
287
286 if (m_dirtyRect.isEmpty()) 288 if (m_dirtyRect.isEmpty())
287 return; 289 return;
288 290
289 // Propagate the m_dirtyRect accumulated so far to the compositor 291 // Propagate the m_dirtyRect accumulated so far to the compositor
290 // before restarting with a blank dirty rect. 292 // before restarting with a blank dirty rect.
291 FloatRect srcRect(0, 0, size().width(), size().height()); 293 FloatRect srcRect(0, 0, size().width(), size().height());
292 m_dirtyRect.intersect(srcRect); 294 m_dirtyRect.intersect(srcRect);
293 LayoutBox* ro = layoutBox(); 295 LayoutBox* ro = layoutBox();
294 // Canvas content updates do not need to be propagated as 296 // Canvas content updates do not need to be propagated as
295 // paint invalidations if the canvas is accelerated, since 297 // paint invalidations if the canvas is accelerated, since
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 } 388 }
387 } 389 }
388 } 390 }
389 391
390 bool HTMLCanvasElement::paintsIntoCanvasBuffer() const 392 bool HTMLCanvasElement::paintsIntoCanvasBuffer() const
391 { 393 {
392 ASSERT(m_context); 394 ASSERT(m_context);
393 395
394 if (!m_context->isAccelerated()) 396 if (!m_context->isAccelerated())
395 return true; 397 return true;
396
397 if (layoutBox() && layoutBox()->hasAcceleratedCompositing()) 398 if (layoutBox() && layoutBox()->hasAcceleratedCompositing())
398 return false; 399 return false;
399 400
400 return true; 401 return true;
401 } 402 }
402 403
404 void HTMLCanvasElement::notifyListenersCanvasChanged()
405 {
406 if (!originClean()) {
407 m_listeners.clear();
408 return;
409 }
410
411 for (CanvasDrawListener* listener : m_listeners) {
412 if (listener->needsNewFrameCapture()) {
413 SourceImageStatus status;
414 RefPtr<Image> sourceImage = getSourceImageForCanvas(&status, PreferN oAcceleration);
esprehn 2015/12/01 20:04:26 getSourceImageForCanvas is expensive I think it se
emircan 2015/12/01 21:07:34 Done. My bad, I was initially designing it with a
415 if (status != NormalSourceImageStatus)
416 return;
417 listener->setNewFrameCapture(sourceImage->imageForCurrentFrame());
418 }
419 }
420 }
421
403 void HTMLCanvasElement::paint(GraphicsContext* context, const LayoutRect& r) 422 void HTMLCanvasElement::paint(GraphicsContext* context, const LayoutRect& r)
404 { 423 {
405 // FIXME: crbug.com/438240; there is a bug with the new CSS blending and com positing feature. 424 // FIXME: crbug.com/438240; there is a bug with the new CSS blending and com positing feature.
406 if (!m_context) 425 if (!m_context)
407 return; 426 return;
408 if (!paintsIntoCanvasBuffer() && !document().printing()) 427 if (!paintsIntoCanvasBuffer() && !document().printing())
409 return; 428 return;
410 429
411 m_context->paintRenderingResultsToCanvas(FrontBuffer); 430 m_context->paintRenderingResultsToCanvas(FrontBuffer);
412 if (hasImageBuffer()) { 431 if (hasImageBuffer()) {
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 RefPtr<DOMUint8ClampedArray> imageDataRef(imageData->data()); 580 RefPtr<DOMUint8ClampedArray> imageDataRef(imageData->data());
562 581
563 RefPtr<CanvasAsyncBlobCreator> asyncCreatorRef = CanvasAsyncBlobCreator::cre ate(imageDataRef.release(), encodingMimeType, imageData->size(), callback); 582 RefPtr<CanvasAsyncBlobCreator> asyncCreatorRef = CanvasAsyncBlobCreator::cre ate(imageDataRef.release(), encodingMimeType, imageData->size(), callback);
564 if (Platform::current()->isThreadedCompositingEnabled() && (encodingMimeType == DefaultMimeType)) { 583 if (Platform::current()->isThreadedCompositingEnabled() && (encodingMimeType == DefaultMimeType)) {
565 asyncCreatorRef->scheduleAsyncBlobCreation(true); 584 asyncCreatorRef->scheduleAsyncBlobCreation(true);
566 } else { 585 } else {
567 asyncCreatorRef->scheduleAsyncBlobCreation(false, quality); 586 asyncCreatorRef->scheduleAsyncBlobCreation(false, quality);
568 } 587 }
569 } 588 }
570 589
590 void HTMLCanvasElement::addListener(CanvasDrawListener* listener)
591 {
592 m_listeners.add(listener);
593 notifyListenersCanvasChanged();
esprehn 2015/12/01 20:04:26 hmm, this means we do a sync readback the first ti
emircan 2015/12/01 21:07:34 I see that frame might not be completed. I was try
594 }
595
596 void HTMLCanvasElement::removeListener(CanvasDrawListener* listener)
597 {
598 m_listeners.remove(listener);
599 }
600
571 SecurityOrigin* HTMLCanvasElement::securityOrigin() const 601 SecurityOrigin* HTMLCanvasElement::securityOrigin() const
572 { 602 {
573 return document().securityOrigin(); 603 return document().securityOrigin();
574 } 604 }
575 605
576 bool HTMLCanvasElement::originClean() const 606 bool HTMLCanvasElement::originClean() const
577 { 607 {
578 if (document().settings() && document().settings()->disableReadingFromCanvas ()) 608 if (document().settings() && document().settings()->disableReadingFromCanvas ())
579 return false; 609 return false;
580 return m_originClean; 610 return m_originClean;
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 } 766 }
737 767
738 void HTMLCanvasElement::notifySurfaceInvalid() 768 void HTMLCanvasElement::notifySurfaceInvalid()
739 { 769 {
740 if (m_context && m_context->is2d()) 770 if (m_context && m_context->is2d())
741 m_context->loseContext(CanvasRenderingContext::RealLostContext); 771 m_context->loseContext(CanvasRenderingContext::RealLostContext);
742 } 772 }
743 773
744 DEFINE_TRACE(HTMLCanvasElement) 774 DEFINE_TRACE(HTMLCanvasElement)
745 { 775 {
776 visitor->trace(m_listeners);
746 visitor->trace(m_context); 777 visitor->trace(m_context);
747 DocumentVisibilityObserver::trace(visitor); 778 DocumentVisibilityObserver::trace(visitor);
748 HTMLElement::trace(visitor); 779 HTMLElement::trace(visitor);
749 } 780 }
750 781
751 void HTMLCanvasElement::updateExternallyAllocatedMemory() const 782 void HTMLCanvasElement::updateExternallyAllocatedMemory() const
752 { 783 {
753 int bufferCount = 0; 784 int bufferCount = 0;
754 if (m_imageBuffer) { 785 if (m_imageBuffer) {
755 bufferCount++; 786 bufferCount++;
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 } 983 }
953 return ImageBitmapSource::fulfillImageBitmap(scriptState, isPaintable() ? Im ageBitmap::create(this, IntRect(sx, sy, sw, sh)) : nullptr); 984 return ImageBitmapSource::fulfillImageBitmap(scriptState, isPaintable() ? Im ageBitmap::create(this, IntRect(sx, sy, sw, sh)) : nullptr);
954 } 985 }
955 986
956 bool HTMLCanvasElement::isOpaque() const 987 bool HTMLCanvasElement::isOpaque() const
957 { 988 {
958 return m_context && !m_context->hasAlpha(); 989 return m_context && !m_context->hasAlpha();
959 } 990 }
960 991
961 } // blink 992 } // blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698