| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 #include "platform/graphics/GraphicsContext.h" | 84 #include "platform/graphics/GraphicsContext.h" |
| 85 #include "platform/graphics/UnacceleratedImageBufferSurface.h" | 85 #include "platform/graphics/UnacceleratedImageBufferSurface.h" |
| 86 #include "platform/graphics/gpu/AcceleratedImageBufferSurface.h" | 86 #include "platform/graphics/gpu/AcceleratedImageBufferSurface.h" |
| 87 #include "platform/graphics/gpu/DrawingBuffer.h" | 87 #include "platform/graphics/gpu/DrawingBuffer.h" |
| 88 #include "public/platform/Platform.h" | 88 #include "public/platform/Platform.h" |
| 89 #include "wtf/PassOwnPtr.h" | 89 #include "wtf/PassOwnPtr.h" |
| 90 #include "wtf/text/StringBuilder.h" | 90 #include "wtf/text/StringBuilder.h" |
| 91 | 91 |
| 92 namespace blink { | 92 namespace blink { |
| 93 | 93 |
| 94 namespace { |
| 95 |
| 94 const double secondsBetweenRestoreAttempts = 1.0; | 96 const double secondsBetweenRestoreAttempts = 1.0; |
| 95 const int maxGLErrorsAllowedToConsole = 256; | 97 const int maxGLErrorsAllowedToConsole = 256; |
| 96 const unsigned maxGLActiveContexts = 16; | 98 const unsigned maxGLActiveContexts = 16; |
| 97 | 99 |
| 100 } // namesapce |
| 101 |
| 98 // FIXME: Oilpan: static vectors to heap allocated WebGLRenderingContextBase obj
ects | 102 // FIXME: Oilpan: static vectors to heap allocated WebGLRenderingContextBase obj
ects |
| 99 // are kept here. This relies on the WebGLRenderingContextBase finalization to | 103 // are kept here. This relies on the WebGLRenderingContextBase finalization to |
| 100 // explicitly retire themselves from these vectors, but it'd be preferable if | 104 // explicitly retire themselves from these vectors, but it'd be preferable if |
| 101 // the references were traced as per usual. | 105 // the references were traced as per usual. |
| 102 Vector<WebGLRenderingContextBase*>& WebGLRenderingContextBase::activeContexts() | 106 Vector<WebGLRenderingContextBase*>& WebGLRenderingContextBase::activeContexts() |
| 103 { | 107 { |
| 104 DEFINE_STATIC_LOCAL(Vector<WebGLRenderingContextBase*>, activeContexts, ()); | 108 DEFINE_STATIC_LOCAL(Vector<WebGLRenderingContextBase*>, activeContexts, ()); |
| 105 return activeContexts; | 109 return activeContexts; |
| 106 } | 110 } |
| 107 | 111 |
| (...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 880 if (!isContextLost()) | 884 if (!isContextLost()) |
| 881 drawingBuffer()->markLayerComposited(); | 885 drawingBuffer()->markLayerComposited(); |
| 882 } | 886 } |
| 883 | 887 |
| 884 void WebGLRenderingContextBase::setIsHidden(bool hidden) | 888 void WebGLRenderingContextBase::setIsHidden(bool hidden) |
| 885 { | 889 { |
| 886 if (drawingBuffer()) | 890 if (drawingBuffer()) |
| 887 drawingBuffer()->setIsHidden(hidden); | 891 drawingBuffer()->setIsHidden(hidden); |
| 888 } | 892 } |
| 889 | 893 |
| 890 void WebGLRenderingContextBase::paintRenderingResultsToCanvas(SourceBuffer sourc
e) | 894 void WebGLRenderingContextBase::paintRenderingResultsToCanvas(SourceDrawingBuffe
r sourceBuffer) |
| 891 { | 895 { |
| 892 if (isContextLost()) | 896 if (isContextLost()) |
| 893 return; | 897 return; |
| 894 | 898 |
| 895 clearIfComposited(); | 899 clearIfComposited(); |
| 896 | 900 |
| 897 if (!m_markedCanvasDirty && !m_layerCleared) | 901 if (!m_markedCanvasDirty && !m_layerCleared) |
| 898 return; | 902 return; |
| 899 | 903 |
| 900 canvas()->clearCopiedImage(); | 904 canvas()->clearCopiedImage(); |
| 901 m_markedCanvasDirty = false; | 905 m_markedCanvasDirty = false; |
| 902 | 906 |
| 903 ScopedTexture2DRestorer restorer(this); | 907 ScopedTexture2DRestorer restorer(this); |
| 904 | 908 |
| 905 drawingBuffer()->commit(); | 909 drawingBuffer()->commit(); |
| 906 if (!canvas()->buffer()->copyRenderingResultsFromDrawingBuffer(drawingBuffer
(), source == Front)) { | 910 if (!canvas()->buffer()->copyRenderingResultsFromDrawingBuffer(drawingBuffer
(), sourceBuffer)) { |
| 907 canvas()->ensureUnacceleratedImageBuffer(); | 911 canvas()->ensureUnacceleratedImageBuffer(); |
| 908 if (canvas()->hasImageBuffer()) | 912 if (canvas()->hasImageBuffer()) |
| 909 drawingBuffer()->paintRenderingResultsToCanvas(canvas()->buffer()); | 913 drawingBuffer()->paintRenderingResultsToCanvas(canvas()->buffer()); |
| 910 } | 914 } |
| 911 | 915 |
| 912 if (m_framebufferBinding) | 916 if (m_framebufferBinding) |
| 913 webContext()->bindFramebuffer(GL_FRAMEBUFFER, objectOrZero(m_framebuffer
Binding.get())); | 917 webContext()->bindFramebuffer(GL_FRAMEBUFFER, objectOrZero(m_framebuffer
Binding.get())); |
| 914 else | 918 else |
| 915 drawingBuffer()->bind(); | 919 drawingBuffer()->bind(); |
| 916 } | 920 } |
| 917 | 921 |
| 918 PassRefPtrWillBeRawPtr<ImageData> WebGLRenderingContextBase::paintRenderingResul
tsToImageData() | 922 PassRefPtrWillBeRawPtr<ImageData> WebGLRenderingContextBase::paintRenderingResul
tsToImageData(SourceDrawingBuffer sourceBuffer) |
| 919 { | 923 { |
| 920 if (isContextLost()) | 924 if (isContextLost()) |
| 921 return nullptr; | 925 return nullptr; |
| 922 | 926 |
| 923 clearIfComposited(); | 927 clearIfComposited(); |
| 924 drawingBuffer()->commit(); | 928 drawingBuffer()->commit(); |
| 925 int width, height; | 929 int width, height; |
| 926 RefPtr<Uint8ClampedArray> imageDataPixels = drawingBuffer()->paintRenderingR
esultsToImageData(width, height); | 930 RefPtr<Uint8ClampedArray> imageDataPixels = |
| 931 drawingBuffer()->paintRenderingResultsToImageData(width, height, sourceB
uffer); |
| 927 if (!imageDataPixels) | 932 if (!imageDataPixels) |
| 928 return nullptr; | 933 return nullptr; |
| 929 | 934 |
| 930 if (m_framebufferBinding) | |
| 931 webContext()->bindFramebuffer(GL_FRAMEBUFFER, objectOrZero(m_framebuffer
Binding.get())); | |
| 932 else | |
| 933 drawingBuffer()->bind(); | |
| 934 | |
| 935 return ImageData::create(IntSize(width, height), imageDataPixels); | 935 return ImageData::create(IntSize(width, height), imageDataPixels); |
| 936 } | 936 } |
| 937 | 937 |
| 938 void WebGLRenderingContextBase::reshape(int width, int height) | 938 void WebGLRenderingContextBase::reshape(int width, int height) |
| 939 { | 939 { |
| 940 if (isContextLost()) | 940 if (isContextLost()) |
| 941 return; | 941 return; |
| 942 | 942 |
| 943 // This is an approximation because at WebGLRenderingContextBase level we do
n't | 943 // This is an approximation because at WebGLRenderingContextBase level we do
n't |
| 944 // know if the underlying FBO uses textures or renderbuffers. | 944 // know if the underlying FBO uses textures or renderbuffers. |
| (...skipping 2598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3543 ImageBuffer* buffer = canvas->buffer(); | 3543 ImageBuffer* buffer = canvas->buffer(); |
| 3544 if (buffer && buffer->copyToPlatformTexture(webContext(), texture->o
bject(), internalformat, type, | 3544 if (buffer && buffer->copyToPlatformTexture(webContext(), texture->o
bject(), internalformat, type, |
| 3545 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) { | 3545 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) { |
| 3546 texture->setLevelInfo(target, level, internalformat, canvas->wid
th(), canvas->height(), type); | 3546 texture->setLevelInfo(target, level, internalformat, canvas->wid
th(), canvas->height(), type); |
| 3547 return; | 3547 return; |
| 3548 } | 3548 } |
| 3549 } else { | 3549 } else { |
| 3550 WebGLRenderingContextBase* gl = toWebGLRenderingContextBase(canvas->
renderingContext()); | 3550 WebGLRenderingContextBase* gl = toWebGLRenderingContextBase(canvas->
renderingContext()); |
| 3551 ScopedTexture2DRestorer restorer(gl); | 3551 ScopedTexture2DRestorer restorer(gl); |
| 3552 if (gl && gl->drawingBuffer()->copyToPlatformTexture(webContext(), t
exture->object(), internalformat, type, | 3552 if (gl && gl->drawingBuffer()->copyToPlatformTexture(webContext(), t
exture->object(), internalformat, type, |
| 3553 level, m_unpackPremultiplyAlpha, !m_unpackFlipY, DrawingBuffer::
Back)) { | 3553 level, m_unpackPremultiplyAlpha, !m_unpackFlipY, BackBuffer)) { |
| 3554 texture->setLevelInfo(target, level, internalformat, canvas->wid
th(), canvas->height(), type); | 3554 texture->setLevelInfo(target, level, internalformat, canvas->wid
th(), canvas->height(), type); |
| 3555 return; | 3555 return; |
| 3556 } | 3556 } |
| 3557 } | 3557 } |
| 3558 } | 3558 } |
| 3559 | 3559 |
| 3560 RefPtrWillBeRawPtr<ImageData> imageData = canvas->getImageData(); | 3560 texImage2DImpl(target, level, internalformat, format, type, canvas->copiedIm
age(BackBuffer), WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpackPre
multiplyAlpha, exceptionState); |
| 3561 if (imageData) | |
| 3562 texImage2D(target, level, internalformat, format, type, imageData.get(),
exceptionState); | |
| 3563 else | |
| 3564 texImage2DImpl(target, level, internalformat, format, type, canvas->copi
edImage(), WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpackPremultip
lyAlpha, exceptionState); | |
| 3565 } | 3561 } |
| 3566 | 3562 |
| 3567 PassRefPtr<Image> WebGLRenderingContextBase::videoFrameToImage(HTMLVideoElement*
video, BackingStoreCopy backingStoreCopy) | 3563 PassRefPtr<Image> WebGLRenderingContextBase::videoFrameToImage(HTMLVideoElement*
video, BackingStoreCopy backingStoreCopy) |
| 3568 { | 3564 { |
| 3569 IntSize size(video->videoWidth(), video->videoHeight()); | 3565 IntSize size(video->videoWidth(), video->videoHeight()); |
| 3570 ImageBuffer* buf = m_generatedImageCache.imageBuffer(size); | 3566 ImageBuffer* buf = m_generatedImageCache.imageBuffer(size); |
| 3571 if (!buf) { | 3567 if (!buf) { |
| 3572 synthesizeGLError(GL_OUT_OF_MEMORY, "texImage2D", "out of memory"); | 3568 synthesizeGLError(GL_OUT_OF_MEMORY, "texImage2D", "out of memory"); |
| 3573 return nullptr; | 3569 return nullptr; |
| 3574 } | 3570 } |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3788 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, imageForRen
der.get(), WebGLImageConversion::HtmlDomImage, m_unpackFlipY, m_unpackPremultipl
yAlpha, exceptionState); | 3784 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, imageForRen
der.get(), WebGLImageConversion::HtmlDomImage, m_unpackFlipY, m_unpackPremultipl
yAlpha, exceptionState); |
| 3789 } | 3785 } |
| 3790 | 3786 |
| 3791 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint
xoffset, GLint yoffset, | 3787 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint
xoffset, GLint yoffset, |
| 3792 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep
tionState) | 3788 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep
tionState) |
| 3793 { | 3789 { |
| 3794 if (isContextLost() || !validateHTMLCanvasElement("texSubImage2D", canvas, e
xceptionState) | 3790 if (isContextLost() || !validateHTMLCanvasElement("texSubImage2D", canvas, e
xceptionState) |
| 3795 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLCanvasElem
ent, target, level, format, canvas->width(), canvas->height(), 0, format, type,
xoffset, yoffset)) | 3791 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLCanvasElem
ent, target, level, format, canvas->width(), canvas->height(), 0, format, type,
xoffset, yoffset)) |
| 3796 return; | 3792 return; |
| 3797 | 3793 |
| 3798 RefPtrWillBeRawPtr<ImageData> imageData = canvas->getImageData(); | 3794 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, canvas->cop
iedImage(BackBuffer), WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpa
ckPremultiplyAlpha, exceptionState); |
| 3799 if (imageData) | |
| 3800 texSubImage2D(target, level, xoffset, yoffset, format, type, imageData.g
et(), exceptionState); | |
| 3801 else | |
| 3802 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, canvas-
>copiedImage(), WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpackPrem
ultiplyAlpha, exceptionState); | |
| 3803 } | 3795 } |
| 3804 | 3796 |
| 3805 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint
xoffset, GLint yoffset, | 3797 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint
xoffset, GLint yoffset, |
| 3806 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti
onState) | 3798 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti
onState) |
| 3807 { | 3799 { |
| 3808 if (isContextLost() || !validateHTMLVideoElement("texSubImage2D", video, exc
eptionState) | 3800 if (isContextLost() || !validateHTMLVideoElement("texSubImage2D", video, exc
eptionState) |
| 3809 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLVideoEleme
nt, target, level, format, video->videoWidth(), video->videoHeight(), 0, format,
type, xoffset, yoffset)) | 3801 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLVideoEleme
nt, target, level, format, video->videoWidth(), video->videoHeight(), 0, format,
type, xoffset, yoffset)) |
| 3810 return; | 3802 return; |
| 3811 | 3803 |
| 3812 RefPtr<Image> image = videoFrameToImage(video, ImageBuffer::fastCopyImageMod
e()); | 3804 RefPtr<Image> image = videoFrameToImage(video, ImageBuffer::fastCopyImageMod
e()); |
| (...skipping 1993 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5806 return m_sharedWebGraphicsContext3D ? m_sharedWebGraphicsContext3D->drawingB
uffer() : 0; | 5798 return m_sharedWebGraphicsContext3D ? m_sharedWebGraphicsContext3D->drawingB
uffer() : 0; |
| 5807 } | 5799 } |
| 5808 #else | 5800 #else |
| 5809 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const | 5801 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const |
| 5810 { | 5802 { |
| 5811 return m_drawingBuffer.get(); | 5803 return m_drawingBuffer.get(); |
| 5812 } | 5804 } |
| 5813 #endif | 5805 #endif |
| 5814 | 5806 |
| 5815 } // namespace blink | 5807 } // namespace blink |
| OLD | NEW |