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 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 Loading... | |
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 bool listenerNeedsNewFrameCapture = false; | |
412 for (CanvasDrawListener* listener : m_listeners) { | |
esprehn
2015/12/03 18:47:34
const ?
emircan
2015/12/04 03:23:25
Done.
| |
413 if (listener->needsNewFrameCapture()) { | |
414 listenerNeedsNewFrameCapture = true; | |
415 } | |
416 } | |
417 | |
418 if (listenerNeedsNewFrameCapture) { | |
419 SourceImageStatus status; | |
420 RefPtr<Image> sourceImage = getSourceImageForCanvas(&status, PreferNoAcc eleration); | |
421 if (status != NormalSourceImageStatus) | |
422 return; | |
423 RefPtr<SkImage> image = sourceImage->imageForCurrentFrame(); | |
424 for (CanvasDrawListener* listener : m_listeners) { | |
425 if (listener->needsNewFrameCapture()) { | |
426 listener->sendNewFrame(image); | |
427 } | |
428 } | |
429 } | |
430 | |
431 } | |
432 | |
403 void HTMLCanvasElement::paint(GraphicsContext* context, const LayoutRect& r) | 433 void HTMLCanvasElement::paint(GraphicsContext* context, const LayoutRect& r) |
404 { | 434 { |
405 // FIXME: crbug.com/438240; there is a bug with the new CSS blending and com positing feature. | 435 // FIXME: crbug.com/438240; there is a bug with the new CSS blending and com positing feature. |
406 if (!m_context) | 436 if (!m_context) |
407 return; | 437 return; |
408 if (!paintsIntoCanvasBuffer() && !document().printing()) | 438 if (!paintsIntoCanvasBuffer() && !document().printing()) |
409 return; | 439 return; |
410 | 440 |
411 m_context->paintRenderingResultsToCanvas(FrontBuffer); | 441 m_context->paintRenderingResultsToCanvas(FrontBuffer); |
412 if (hasImageBuffer()) { | 442 if (hasImageBuffer()) { |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
561 RefPtr<DOMUint8ClampedArray> imageDataRef(imageData->data()); | 591 RefPtr<DOMUint8ClampedArray> imageDataRef(imageData->data()); |
562 | 592 |
563 RefPtr<CanvasAsyncBlobCreator> asyncCreatorRef = CanvasAsyncBlobCreator::cre ate(imageDataRef.release(), encodingMimeType, imageData->size(), callback); | 593 RefPtr<CanvasAsyncBlobCreator> asyncCreatorRef = CanvasAsyncBlobCreator::cre ate(imageDataRef.release(), encodingMimeType, imageData->size(), callback); |
564 if (Platform::current()->isThreadedCompositingEnabled() && (encodingMimeType == DefaultMimeType)) { | 594 if (Platform::current()->isThreadedCompositingEnabled() && (encodingMimeType == DefaultMimeType)) { |
565 asyncCreatorRef->scheduleAsyncBlobCreation(true); | 595 asyncCreatorRef->scheduleAsyncBlobCreation(true); |
566 } else { | 596 } else { |
567 asyncCreatorRef->scheduleAsyncBlobCreation(false, quality); | 597 asyncCreatorRef->scheduleAsyncBlobCreation(false, quality); |
568 } | 598 } |
569 } | 599 } |
570 | 600 |
601 void HTMLCanvasElement::addListener(CanvasDrawListener* listener) | |
602 { | |
603 m_listeners.add(listener); | |
604 } | |
605 | |
606 void HTMLCanvasElement::removeListener(CanvasDrawListener* listener) | |
607 { | |
608 m_listeners.remove(listener); | |
609 } | |
610 | |
571 SecurityOrigin* HTMLCanvasElement::securityOrigin() const | 611 SecurityOrigin* HTMLCanvasElement::securityOrigin() const |
572 { | 612 { |
573 return document().securityOrigin(); | 613 return document().securityOrigin(); |
574 } | 614 } |
575 | 615 |
576 bool HTMLCanvasElement::originClean() const | 616 bool HTMLCanvasElement::originClean() const |
577 { | 617 { |
578 if (document().settings() && document().settings()->disableReadingFromCanvas ()) | 618 if (document().settings() && document().settings()->disableReadingFromCanvas ()) |
579 return false; | 619 return false; |
580 return m_originClean; | 620 return m_originClean; |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
736 } | 776 } |
737 | 777 |
738 void HTMLCanvasElement::notifySurfaceInvalid() | 778 void HTMLCanvasElement::notifySurfaceInvalid() |
739 { | 779 { |
740 if (m_context && m_context->is2d()) | 780 if (m_context && m_context->is2d()) |
741 m_context->loseContext(CanvasRenderingContext::RealLostContext); | 781 m_context->loseContext(CanvasRenderingContext::RealLostContext); |
742 } | 782 } |
743 | 783 |
744 DEFINE_TRACE(HTMLCanvasElement) | 784 DEFINE_TRACE(HTMLCanvasElement) |
745 { | 785 { |
786 visitor->trace(m_listeners); | |
746 visitor->trace(m_context); | 787 visitor->trace(m_context); |
747 DocumentVisibilityObserver::trace(visitor); | 788 DocumentVisibilityObserver::trace(visitor); |
748 HTMLElement::trace(visitor); | 789 HTMLElement::trace(visitor); |
749 } | 790 } |
750 | 791 |
751 void HTMLCanvasElement::updateExternallyAllocatedMemory() const | 792 void HTMLCanvasElement::updateExternallyAllocatedMemory() const |
752 { | 793 { |
753 int bufferCount = 0; | 794 int bufferCount = 0; |
754 if (m_imageBuffer) { | 795 if (m_imageBuffer) { |
755 bufferCount++; | 796 bufferCount++; |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
952 } | 993 } |
953 return ImageBitmapSource::fulfillImageBitmap(scriptState, isPaintable() ? Im ageBitmap::create(this, IntRect(sx, sy, sw, sh)) : nullptr); | 994 return ImageBitmapSource::fulfillImageBitmap(scriptState, isPaintable() ? Im ageBitmap::create(this, IntRect(sx, sy, sw, sh)) : nullptr); |
954 } | 995 } |
955 | 996 |
956 bool HTMLCanvasElement::isOpaque() const | 997 bool HTMLCanvasElement::isOpaque() const |
957 { | 998 { |
958 return m_context && !m_context->hasAlpha(); | 999 return m_context && !m_context->hasAlpha(); |
959 } | 1000 } |
960 | 1001 |
961 } // blink | 1002 } // blink |
OLD | NEW |