| 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 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 lowercaseMimeType = "image/png"; | 469 lowercaseMimeType = "image/png"; |
| 470 | 470 |
| 471 return lowercaseMimeType; | 471 return lowercaseMimeType; |
| 472 } | 472 } |
| 473 | 473 |
| 474 const AtomicString HTMLCanvasElement::imageSourceURL() const | 474 const AtomicString HTMLCanvasElement::imageSourceURL() const |
| 475 { | 475 { |
| 476 return AtomicString(toDataURLInternal("image/png", 0, FrontBuffer)); | 476 return AtomicString(toDataURLInternal("image/png", 0, FrontBuffer)); |
| 477 } | 477 } |
| 478 | 478 |
| 479 void HTMLCanvasElement::prepareSurfaceForPaintingIfNeeded() const | |
| 480 { | |
| 481 ASSERT(m_context && m_context->is2d()); // This function is called by the 2d
context | |
| 482 if (buffer()) | |
| 483 m_imageBuffer->prepareSurfaceForPaintingIfNeeded(); | |
| 484 } | |
| 485 | |
| 486 ImageData* HTMLCanvasElement::toImageData(SourceDrawingBuffer sourceBuffer) cons
t | 479 ImageData* HTMLCanvasElement::toImageData(SourceDrawingBuffer sourceBuffer) cons
t |
| 487 { | 480 { |
| 488 ImageData* imageData; | 481 ImageData* imageData; |
| 489 if (is3D()) { | 482 if (is3D()) { |
| 490 // Get non-premultiplied data because of inaccurate premultiplied alpha
conversion of buffer()->toDataURL(). | 483 // Get non-premultiplied data because of inaccurate premultiplied alpha
conversion of buffer()->toDataURL(). |
| 491 imageData = m_context->paintRenderingResultsToImageData(sourceBuffer); | 484 imageData = m_context->paintRenderingResultsToImageData(sourceBuffer); |
| 492 if (imageData) | 485 if (imageData) |
| 493 return imageData; | 486 return imageData; |
| 494 | 487 |
| 495 m_context->paintRenderingResultsToCanvas(sourceBuffer); | 488 m_context->paintRenderingResultsToCanvas(sourceBuffer); |
| 496 imageData = ImageData::create(m_size); | 489 imageData = ImageData::create(m_size); |
| 497 RefPtr<SkImage> snapshot = buffer()->newSkImageSnapshot(PreferNoAccelera
tion); | 490 RefPtr<SkImage> snapshot = buffer()->newSkImageSnapshot(); |
| 498 if (snapshot) { | 491 if (snapshot) { |
| 499 SkImageInfo imageInfo = SkImageInfo::Make(width(), height(), kRGBA_8
888_SkColorType, kUnpremul_SkAlphaType); | 492 SkImageInfo imageInfo = SkImageInfo::Make(width(), height(), kRGBA_8
888_SkColorType, kUnpremul_SkAlphaType); |
| 500 snapshot->readPixels(imageInfo, imageData->data()->data(), imageInfo
.minRowBytes(), 0, 0); | 493 snapshot->readPixels(imageInfo, imageData->data()->data(), imageInfo
.minRowBytes(), 0, 0); |
| 501 } | 494 } |
| 502 return imageData; | 495 return imageData; |
| 503 } | 496 } |
| 504 | 497 |
| 505 imageData = ImageData::create(m_size); | 498 imageData = ImageData::create(m_size); |
| 506 | 499 |
| 507 if (!m_context) | 500 if (!m_context) |
| 508 return imageData; | 501 return imageData; |
| 509 | 502 |
| 510 ASSERT(m_context->is2d()); | 503 ASSERT(m_context->is2d()); |
| 511 RefPtr<SkImage> snapshot = buffer()->newSkImageSnapshot(PreferNoAcceleration
); | 504 RefPtr<SkImage> snapshot = buffer()->newSkImageSnapshot(); |
| 512 if (snapshot) { | 505 if (snapshot) { |
| 513 SkImageInfo imageInfo = SkImageInfo::Make(width(), height(), kRGBA_8888_
SkColorType, kUnpremul_SkAlphaType); | 506 SkImageInfo imageInfo = SkImageInfo::Make(width(), height(), kRGBA_8888_
SkColorType, kUnpremul_SkAlphaType); |
| 514 snapshot->readPixels(imageInfo, imageData->data()->data(), imageInfo.min
RowBytes(), 0, 0); | 507 snapshot->readPixels(imageInfo, imageData->data()->data(), imageInfo.min
RowBytes(), 0, 0); |
| 515 } | 508 } |
| 516 | 509 |
| 517 return imageData; | 510 return imageData; |
| 518 } | 511 } |
| 519 | 512 |
| 520 String HTMLCanvasElement::toDataURLInternal(const String& mimeType, const double
* quality, SourceDrawingBuffer sourceBuffer) const | 513 String HTMLCanvasElement::toDataURLInternal(const String& mimeType, const double
* quality, SourceDrawingBuffer sourceBuffer) const |
| 521 { | 514 { |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 // FIXME: Actually, avoid setting m_accelerationDisabled at all when | 665 // FIXME: Actually, avoid setting m_accelerationDisabled at all when |
| 673 // doing GPU-based rasterization. | 666 // doing GPU-based rasterization. |
| 674 if (m_accelerationDisabled) | 667 if (m_accelerationDisabled) |
| 675 return adoptPtr(new UnacceleratedImageBufferSurface(deviceSize, opac
ityMode)); | 668 return adoptPtr(new UnacceleratedImageBufferSurface(deviceSize, opac
ityMode)); |
| 676 return adoptPtr(new AcceleratedImageBufferSurface(deviceSize, opacityMod
e)); | 669 return adoptPtr(new AcceleratedImageBufferSurface(deviceSize, opacityMod
e)); |
| 677 } | 670 } |
| 678 | 671 |
| 679 if (shouldAccelerate(deviceSize)) { | 672 if (shouldAccelerate(deviceSize)) { |
| 680 if (document().settings()) | 673 if (document().settings()) |
| 681 *msaaSampleCount = document().settings()->accelerated2dCanvasMSAASam
pleCount(); | 674 *msaaSampleCount = document().settings()->accelerated2dCanvasMSAASam
pleCount(); |
| 682 OwnPtr<ImageBufferSurface> surface = adoptPtr(new Canvas2DImageBufferSur
face(deviceSize, *msaaSampleCount, opacityMode, Canvas2DLayerBridge::EnableAccel
eration)); | 675 OwnPtr<ImageBufferSurface> surface = adoptPtr(new Canvas2DImageBufferSur
face(deviceSize, opacityMode, *msaaSampleCount)); |
| 683 if (surface->isValid()) | 676 if (surface->isValid()) |
| 684 return surface.release(); | 677 return surface.release(); |
| 685 } | 678 } |
| 686 | 679 |
| 687 OwnPtr<RecordingImageBufferFallbackSurfaceFactory> surfaceFactory = adoptPtr
(new UnacceleratedSurfaceFactory()); | 680 OwnPtr<RecordingImageBufferFallbackSurfaceFactory> surfaceFactory = adoptPtr
(new UnacceleratedSurfaceFactory()); |
| 688 | 681 |
| 689 if (shouldUseDisplayList(deviceSize)) { | 682 if (shouldUseDisplayList(deviceSize)) { |
| 690 OwnPtr<ImageBufferSurface> surface = adoptPtr(new RecordingImageBufferSu
rface(deviceSize, surfaceFactory.release(), opacityMode)); | 683 OwnPtr<ImageBufferSurface> surface = adoptPtr(new RecordingImageBufferSu
rface(deviceSize, surfaceFactory.release(), opacityMode)); |
| 691 if (surface->isValid()) | 684 if (surface->isValid()) |
| 692 return surface.release(); | 685 return surface.release(); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 { | 829 { |
| 837 ASSERT(m_context); | 830 ASSERT(m_context); |
| 838 if ((hasImageBuffer() && !m_imageBuffer->isAccelerated()) || m_didFailToCrea
teImageBuffer) | 831 if ((hasImageBuffer() && !m_imageBuffer->isAccelerated()) || m_didFailToCrea
teImageBuffer) |
| 839 return; | 832 return; |
| 840 discardImageBuffer(); | 833 discardImageBuffer(); |
| 841 OpacityMode opacityMode = m_context->hasAlpha() ? NonOpaque : Opaque; | 834 OpacityMode opacityMode = m_context->hasAlpha() ? NonOpaque : Opaque; |
| 842 m_imageBuffer = ImageBuffer::create(size(), opacityMode); | 835 m_imageBuffer = ImageBuffer::create(size(), opacityMode); |
| 843 m_didFailToCreateImageBuffer = !m_imageBuffer; | 836 m_didFailToCreateImageBuffer = !m_imageBuffer; |
| 844 } | 837 } |
| 845 | 838 |
| 846 PassRefPtr<Image> HTMLCanvasElement::copiedImage(SourceDrawingBuffer sourceBuffe
r, AccelerationHint hint) const | 839 PassRefPtr<Image> HTMLCanvasElement::copiedImage(SourceDrawingBuffer sourceBuffe
r) const |
| 847 { | 840 { |
| 848 if (!isPaintable()) | 841 if (!isPaintable()) |
| 849 return nullptr; | 842 return nullptr; |
| 850 if (!m_context) | 843 if (!m_context) |
| 851 return createTransparentImage(size()); | 844 return createTransparentImage(size()); |
| 852 | 845 |
| 853 bool needToUpdate = !m_copiedImage; | 846 bool needToUpdate = !m_copiedImage; |
| 854 // The concept of SourceDrawingBuffer is valid on only WebGL. | 847 // The concept of SourceDrawingBuffer is valid on only WebGL. |
| 855 if (m_context->is3d()) | 848 if (m_context->is3d()) |
| 856 needToUpdate |= m_context->paintRenderingResultsToCanvas(sourceBuffer); | 849 needToUpdate |= m_context->paintRenderingResultsToCanvas(sourceBuffer); |
| 857 if (needToUpdate && buffer()) { | 850 if (needToUpdate && buffer()) { |
| 858 m_copiedImage = buffer()->newImageSnapshot(hint); | 851 m_copiedImage = buffer()->newImageSnapshot(); |
| 859 updateExternallyAllocatedMemory(); | 852 updateExternallyAllocatedMemory(); |
| 860 } | 853 } |
| 861 return m_copiedImage; | 854 return m_copiedImage; |
| 862 } | 855 } |
| 863 | 856 |
| 864 void HTMLCanvasElement::discardImageBuffer() | 857 void HTMLCanvasElement::discardImageBuffer() |
| 865 { | 858 { |
| 866 m_imageBuffer.clear(); | 859 m_imageBuffer.clear(); |
| 867 m_dirtyRect = FloatRect(); | 860 m_dirtyRect = FloatRect(); |
| 868 updateExternallyAllocatedMemory(); | 861 updateExternallyAllocatedMemory(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 903 } | 896 } |
| 904 | 897 |
| 905 void HTMLCanvasElement::didMoveToNewDocument(Document& oldDocument) | 898 void HTMLCanvasElement::didMoveToNewDocument(Document& oldDocument) |
| 906 { | 899 { |
| 907 setObservedDocument(document()); | 900 setObservedDocument(document()); |
| 908 if (m_context) | 901 if (m_context) |
| 909 m_context->didMoveToNewDocument(&document()); | 902 m_context->didMoveToNewDocument(&document()); |
| 910 HTMLElement::didMoveToNewDocument(oldDocument); | 903 HTMLElement::didMoveToNewDocument(oldDocument); |
| 911 } | 904 } |
| 912 | 905 |
| 913 PassRefPtr<Image> HTMLCanvasElement::getSourceImageForCanvas(SourceImageStatus*
status, AccelerationHint hint) const | 906 PassRefPtr<Image> HTMLCanvasElement::getSourceImageForCanvas(SourceImageStatus*
status) const |
| 914 { | 907 { |
| 915 if (!width() || !height()) { | 908 if (!width() || !height()) { |
| 916 *status = ZeroSizeCanvasSourceImageStatus; | 909 *status = ZeroSizeCanvasSourceImageStatus; |
| 917 return nullptr; | 910 return nullptr; |
| 918 } | 911 } |
| 919 | 912 |
| 920 if (!isPaintable()) { | 913 if (!isPaintable()) { |
| 921 *status = InvalidSourceImageStatus; | 914 *status = InvalidSourceImageStatus; |
| 922 return nullptr; | 915 return nullptr; |
| 923 } | 916 } |
| 924 | 917 |
| 925 if (!m_context) { | 918 if (!m_context) { |
| 926 *status = NormalSourceImageStatus; | 919 *status = NormalSourceImageStatus; |
| 927 return createTransparentImage(size()); | 920 return createTransparentImage(size()); |
| 928 } | 921 } |
| 929 | 922 |
| 930 if (m_context->is3d()) { | 923 if (m_context->is3d()) { |
| 931 m_context->paintRenderingResultsToCanvas(BackBuffer); | 924 m_context->paintRenderingResultsToCanvas(BackBuffer); |
| 932 } | 925 } |
| 933 | 926 |
| 934 RefPtr<SkImage> image = buffer()->newSkImageSnapshot(hint); | 927 RefPtr<SkImage> image = buffer()->newSkImageSnapshot(); |
| 935 if (image) { | 928 if (image) { |
| 936 *status = NormalSourceImageStatus; | 929 *status = NormalSourceImageStatus; |
| 937 return StaticBitmapImage::create(image.release()); | 930 return StaticBitmapImage::create(image.release()); |
| 938 } | 931 } |
| 939 | 932 |
| 940 *status = InvalidSourceImageStatus; | 933 *status = InvalidSourceImageStatus; |
| 941 return nullptr; | 934 return nullptr; |
| 942 } | 935 } |
| 943 | 936 |
| 944 bool HTMLCanvasElement::wouldTaintOrigin(SecurityOrigin*) const | 937 bool HTMLCanvasElement::wouldTaintOrigin(SecurityOrigin*) const |
| 945 { | 938 { |
| 946 return !originClean(); | 939 return !originClean(); |
| 947 } | 940 } |
| 948 | 941 |
| 949 FloatSize HTMLCanvasElement::elementSize() const | 942 FloatSize HTMLCanvasElement::elementSize() const |
| 950 { | 943 { |
| 951 return FloatSize(width(), height()); | 944 return FloatSize(width(), height()); |
| 952 } | 945 } |
| 953 | 946 |
| 954 bool HTMLCanvasElement::isOpaque() const | 947 bool HTMLCanvasElement::isOpaque() const |
| 955 { | 948 { |
| 956 return m_context && !m_context->hasAlpha(); | 949 return m_context && !m_context->hasAlpha(); |
| 957 } | 950 } |
| 958 | 951 |
| 959 } // blink | 952 } // blink |
| OLD | NEW |