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 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
271 { | 271 { |
272 if (rect.isEmpty()) | 272 if (rect.isEmpty()) |
273 return; | 273 return; |
274 m_imageBufferIsClear = false; | 274 m_imageBufferIsClear = false; |
275 clearCopiedImage(); | 275 clearCopiedImage(); |
276 if (layoutObject()) | 276 if (layoutObject()) |
277 layoutObject()->setMayNeedPaintInvalidation(); | 277 layoutObject()->setMayNeedPaintInvalidation(); |
278 m_dirtyRect.unite(rect); | 278 m_dirtyRect.unite(rect); |
279 if (m_context && m_context->is2d() && hasImageBuffer()) | 279 if (m_context && m_context->is2d() && hasImageBuffer()) |
280 buffer()->didDraw(rect); | 280 buffer()->didDraw(rect); |
281 notifyListenersCanvasChanged(); | |
281 } | 282 } |
282 | 283 |
283 void HTMLCanvasElement::didFinalizeFrame() | 284 void HTMLCanvasElement::didFinalizeFrame() |
284 { | 285 { |
285 if (m_dirtyRect.isEmpty()) | 286 if (m_dirtyRect.isEmpty()) |
286 return; | 287 return; |
287 | 288 |
288 // Propagate the m_dirtyRect accumulated so far to the compositor | 289 // Propagate the m_dirtyRect accumulated so far to the compositor |
289 // before restarting with a blank dirty rect. | 290 // before restarting with a blank dirty rect. |
290 FloatRect srcRect(0, 0, size().width(), size().height()); | 291 FloatRect srcRect(0, 0, size().width(), size().height()); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
385 } | 386 } |
386 } | 387 } |
387 } | 388 } |
388 | 389 |
389 bool HTMLCanvasElement::paintsIntoCanvasBuffer() const | 390 bool HTMLCanvasElement::paintsIntoCanvasBuffer() const |
390 { | 391 { |
391 ASSERT(m_context); | 392 ASSERT(m_context); |
392 | 393 |
393 if (!m_context->isAccelerated()) | 394 if (!m_context->isAccelerated()) |
394 return true; | 395 return true; |
395 | |
396 if (layoutBox() && layoutBox()->hasAcceleratedCompositing()) | 396 if (layoutBox() && layoutBox()->hasAcceleratedCompositing()) |
397 return false; | 397 return false; |
398 | 398 |
399 return true; | 399 return true; |
400 } | 400 } |
401 | 401 |
402 void HTMLCanvasElement::notifyListenersCanvasChanged() | |
403 { | |
404 for (CanvasDrawListener* listener : m_listeners) { | |
405 if (listener->needsNewFrameCapture()) { | |
406 SourceImageStatus status; | |
407 RefPtr<Image> sourceImage = getSourceImageForCanvas(&status, PreferA cceleration); | |
408 ASSERT(status == NormalSourceImageStatus); | |
Justin Novosad
2015/11/25 02:38:05
Are you sure about this? I think you should be doi
emircan
2015/11/26 01:03:52
Are you refering to ZeroSizeCanvasSourceImageStatu
| |
409 listener->setNewFrameCapture(sourceImage->imageForCurrentFrame()); | |
Justin Novosad
2015/11/25 02:38:05
Before sending the new frame, you need to check th
emircan
2015/11/26 01:03:52
I was planning to leave those checks for later as
| |
410 } | |
411 } | |
412 } | |
413 | |
402 void HTMLCanvasElement::paint(GraphicsContext* context, const LayoutRect& r) | 414 void HTMLCanvasElement::paint(GraphicsContext* context, const LayoutRect& r) |
403 { | 415 { |
404 // FIXME: crbug.com/438240; there is a bug with the new CSS blending and com positing feature. | 416 // FIXME: crbug.com/438240; there is a bug with the new CSS blending and com positing feature. |
405 if (!m_context) | 417 if (!m_context) |
406 return; | 418 return; |
407 if (!paintsIntoCanvasBuffer() && !document().printing()) | 419 if (!paintsIntoCanvasBuffer() && !document().printing()) |
408 return; | 420 return; |
409 | 421 |
410 m_context->paintRenderingResultsToCanvas(FrontBuffer); | 422 m_context->paintRenderingResultsToCanvas(FrontBuffer); |
411 if (hasImageBuffer()) { | 423 if (hasImageBuffer()) { |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
560 RefPtr<DOMUint8ClampedArray> imageDataRef(imageData->data()); | 572 RefPtr<DOMUint8ClampedArray> imageDataRef(imageData->data()); |
561 | 573 |
562 RefPtr<CanvasAsyncBlobCreator> asyncCreatorRef = CanvasAsyncBlobCreator::cre ate(imageDataRef.release(), encodingMimeType, imageData->size(), callback); | 574 RefPtr<CanvasAsyncBlobCreator> asyncCreatorRef = CanvasAsyncBlobCreator::cre ate(imageDataRef.release(), encodingMimeType, imageData->size(), callback); |
563 if (Platform::current()->isThreadedCompositingEnabled() && (encodingMimeType == DefaultMimeType)) { | 575 if (Platform::current()->isThreadedCompositingEnabled() && (encodingMimeType == DefaultMimeType)) { |
564 asyncCreatorRef->scheduleAsyncBlobCreation(true); | 576 asyncCreatorRef->scheduleAsyncBlobCreation(true); |
565 } else { | 577 } else { |
566 asyncCreatorRef->scheduleAsyncBlobCreation(false, quality); | 578 asyncCreatorRef->scheduleAsyncBlobCreation(false, quality); |
567 } | 579 } |
568 } | 580 } |
569 | 581 |
582 void HTMLCanvasElement::addListener(CanvasDrawListener* listener) | |
583 { | |
584 m_listeners.add(listener); | |
585 notifyListenersCanvasChanged(); | |
586 } | |
587 | |
588 void HTMLCanvasElement::removeListener(CanvasDrawListener* listener) | |
589 { | |
590 m_listeners.remove(listener); | |
591 } | |
592 | |
570 SecurityOrigin* HTMLCanvasElement::securityOrigin() const | 593 SecurityOrigin* HTMLCanvasElement::securityOrigin() const |
571 { | 594 { |
572 return document().securityOrigin(); | 595 return document().securityOrigin(); |
573 } | 596 } |
574 | 597 |
575 bool HTMLCanvasElement::originClean() const | 598 bool HTMLCanvasElement::originClean() const |
576 { | 599 { |
577 if (document().settings() && document().settings()->disableReadingFromCanvas ()) | 600 if (document().settings() && document().settings()->disableReadingFromCanvas ()) |
578 return false; | 601 return false; |
579 return m_originClean; | 602 return m_originClean; |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
932 { | 955 { |
933 return FloatSize(width(), height()); | 956 return FloatSize(width(), height()); |
934 } | 957 } |
935 | 958 |
936 bool HTMLCanvasElement::isOpaque() const | 959 bool HTMLCanvasElement::isOpaque() const |
937 { | 960 { |
938 return m_context && !m_context->hasAlpha(); | 961 return m_context && !m_context->hasAlpha(); |
939 } | 962 } |
940 | 963 |
941 } // blink | 964 } // blink |
OLD | NEW |