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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 #include "core/html/canvas/WebGLDebugRendererInfo.h" | 66 #include "core/html/canvas/WebGLDebugRendererInfo.h" |
67 #include "core/html/canvas/WebGLDebugShaders.h" | 67 #include "core/html/canvas/WebGLDebugShaders.h" |
68 #include "core/html/canvas/WebGLDepthTexture.h" | 68 #include "core/html/canvas/WebGLDepthTexture.h" |
69 #include "core/html/canvas/WebGLDrawBuffers.h" | 69 #include "core/html/canvas/WebGLDrawBuffers.h" |
70 #include "core/html/canvas/WebGLFramebuffer.h" | 70 #include "core/html/canvas/WebGLFramebuffer.h" |
71 #include "core/html/canvas/WebGLLoseContext.h" | 71 #include "core/html/canvas/WebGLLoseContext.h" |
72 #include "core/html/canvas/WebGLProgram.h" | 72 #include "core/html/canvas/WebGLProgram.h" |
73 #include "core/html/canvas/WebGLRenderbuffer.h" | 73 #include "core/html/canvas/WebGLRenderbuffer.h" |
74 #include "core/html/canvas/WebGLShader.h" | 74 #include "core/html/canvas/WebGLShader.h" |
75 #include "core/html/canvas/WebGLShaderPrecisionFormat.h" | 75 #include "core/html/canvas/WebGLShaderPrecisionFormat.h" |
76 #include "core/html/canvas/WebGLSharedWebGraphicsContext3D.h" | |
77 #include "core/html/canvas/WebGLTexture.h" | 76 #include "core/html/canvas/WebGLTexture.h" |
78 #include "core/html/canvas/WebGLUniformLocation.h" | 77 #include "core/html/canvas/WebGLUniformLocation.h" |
79 #include "core/html/canvas/WebGLVertexArrayObject.h" | 78 #include "core/html/canvas/WebGLVertexArrayObject.h" |
80 #include "core/html/canvas/WebGLVertexArrayObjectOES.h" | 79 #include "core/html/canvas/WebGLVertexArrayObjectOES.h" |
81 #include "core/inspector/ConsoleMessage.h" | 80 #include "core/inspector/ConsoleMessage.h" |
82 #include "core/inspector/InspectorInstrumentation.h" | 81 #include "core/inspector/InspectorInstrumentation.h" |
83 #include "core/layout/LayoutBox.h" | 82 #include "core/layout/LayoutBox.h" |
84 #include "core/loader/FrameLoader.h" | 83 #include "core/loader/FrameLoader.h" |
85 #include "core/loader/FrameLoaderClient.h" | 84 #include "core/loader/FrameLoaderClient.h" |
86 #include "platform/CheckedInt.h" | 85 #include "platform/CheckedInt.h" |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 | 642 |
644 m_maxViewportDims[0] = m_maxViewportDims[1] = 0; | 643 m_maxViewportDims[0] = m_maxViewportDims[1] = 0; |
645 context->getIntegerv(GL_MAX_VIEWPORT_DIMS, m_maxViewportDims); | 644 context->getIntegerv(GL_MAX_VIEWPORT_DIMS, m_maxViewportDims); |
646 | 645 |
647 RefPtr<DrawingBuffer> buffer = createDrawingBuffer(context); | 646 RefPtr<DrawingBuffer> buffer = createDrawingBuffer(context); |
648 if (!buffer) { | 647 if (!buffer) { |
649 m_contextLostMode = SyntheticLostContext; | 648 m_contextLostMode = SyntheticLostContext; |
650 return; | 649 return; |
651 } | 650 } |
652 | 651 |
653 #if ENABLE(OILPAN) | |
654 m_sharedWebGraphicsContext3D = WebGLSharedWebGraphicsContext3D::create(buffe
r.release()); | |
655 #else | |
656 m_drawingBuffer = buffer.release(); | 652 m_drawingBuffer = buffer.release(); |
657 #endif | |
658 | 653 |
659 drawingBuffer()->bind(); | 654 drawingBuffer()->bind(); |
660 setupFlags(); | 655 setupFlags(); |
661 } | 656 } |
662 | 657 |
663 PassRefPtr<DrawingBuffer> WebGLRenderingContextBase::createDrawingBuffer(PassOwn
Ptr<WebGraphicsContext3D> context) | 658 PassRefPtr<DrawingBuffer> WebGLRenderingContextBase::createDrawingBuffer(PassOwn
Ptr<WebGraphicsContext3D> context) |
664 { | 659 { |
665 WebGraphicsContext3D::Attributes attrs; | 660 WebGraphicsContext3D::Attributes attrs; |
666 attrs.alpha = m_requestedAttributes.alpha(); | 661 attrs.alpha = m_requestedAttributes.alpha(); |
667 attrs.depth = m_requestedAttributes.depth(); | 662 attrs.depth = m_requestedAttributes.depth(); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 // Helper function for V8 bindings to identify what version of WebGL a CanvasRen
deringContext supports. | 784 // Helper function for V8 bindings to identify what version of WebGL a CanvasRen
deringContext supports. |
790 unsigned WebGLRenderingContextBase::getWebGLVersion(const CanvasRenderingContext
* context) | 785 unsigned WebGLRenderingContextBase::getWebGLVersion(const CanvasRenderingContext
* context) |
791 { | 786 { |
792 if (!context->is3d()) | 787 if (!context->is3d()) |
793 return 0; | 788 return 0; |
794 return static_cast<const WebGLRenderingContextBase*>(context)->version(); | 789 return static_cast<const WebGLRenderingContextBase*>(context)->version(); |
795 } | 790 } |
796 | 791 |
797 WebGLRenderingContextBase::~WebGLRenderingContextBase() | 792 WebGLRenderingContextBase::~WebGLRenderingContextBase() |
798 { | 793 { |
799 #if !ENABLE(OILPAN) | |
800 // Remove all references to WebGLObjects so if they are the last reference | 794 // Remove all references to WebGLObjects so if they are the last reference |
801 // they will be freed before the last context is removed from the context gr
oup. | 795 // they will be freed before the last context is removed from the context gr
oup. |
802 m_boundArrayBuffer = nullptr; | 796 m_boundArrayBuffer = nullptr; |
803 m_defaultVertexArrayObject = nullptr; | 797 m_defaultVertexArrayObject = nullptr; |
804 m_boundVertexArrayObject = nullptr; | 798 m_boundVertexArrayObject = nullptr; |
805 m_vertexAttrib0Buffer = nullptr; | 799 m_vertexAttrib0Buffer = nullptr; |
806 m_currentProgram = nullptr; | 800 m_currentProgram = nullptr; |
807 m_framebufferBinding = nullptr; | 801 m_framebufferBinding = nullptr; |
808 m_renderbufferBinding = nullptr; | 802 m_renderbufferBinding = nullptr; |
809 m_valuebufferBinding = nullptr; | 803 m_valuebufferBinding = nullptr; |
810 | 804 |
811 for (size_t i = 0; i < m_textureUnits.size(); ++i) { | 805 for (size_t i = 0; i < m_textureUnits.size(); ++i) { |
812 m_textureUnits[i].m_texture2DBinding = nullptr; | 806 m_textureUnits[i].m_texture2DBinding = nullptr; |
813 m_textureUnits[i].m_textureCubeMapBinding = nullptr; | 807 m_textureUnits[i].m_textureCubeMapBinding = nullptr; |
814 m_textureUnits[i].m_texture3DBinding = nullptr; | 808 m_textureUnits[i].m_texture3DBinding = nullptr; |
815 m_textureUnits[i].m_texture2DArrayBinding = nullptr; | 809 m_textureUnits[i].m_texture2DArrayBinding = nullptr; |
816 } | 810 } |
817 | 811 |
818 m_blackTexture2D = nullptr; | 812 m_blackTexture2D = nullptr; |
819 m_blackTextureCubeMap = nullptr; | 813 m_blackTextureCubeMap = nullptr; |
820 | 814 |
821 detachAndRemoveAllObjects(); | 815 detachAndRemoveAllObjects(); |
822 | 816 |
823 // Release all extensions now. | 817 // Release all extensions now. |
824 m_extensions.clear(); | 818 m_extensions.clear(); |
825 #endif | |
826 | 819 |
827 // Context must be removed from the group prior to the destruction of the | 820 // Context must be removed from the group prior to the destruction of the |
828 // WebGraphicsContext3D, otherwise shared objects may not be properly delete
d. | 821 // WebGraphicsContext3D, otherwise shared objects may not be properly delete
d. |
829 m_contextGroup->removeContext(this); | 822 m_contextGroup->removeContext(this); |
830 | 823 |
831 destroyContext(); | 824 destroyContext(); |
832 | 825 |
833 #if !ENABLE(OILPAN) | |
834 if (m_multisamplingObserverRegistered) | 826 if (m_multisamplingObserverRegistered) |
835 if (Page* page = canvas()->document().page()) | 827 if (Page* page = canvas()->document().page()) |
836 page->removeMultisamplingChangedObserver(this); | 828 page->removeMultisamplingChangedObserver(this); |
837 #endif | |
838 | 829 |
839 willDestroyContext(this); | 830 willDestroyContext(this); |
840 } | 831 } |
841 | 832 |
842 void WebGLRenderingContextBase::destroyContext() | 833 void WebGLRenderingContextBase::destroyContext() |
843 { | 834 { |
844 if (!drawingBuffer()) | 835 if (!drawingBuffer()) |
845 return; | 836 return; |
846 | 837 |
847 m_extensionsUtil.clear(); | 838 m_extensionsUtil.clear(); |
848 | 839 |
849 webContext()->setContextLostCallback(nullptr); | 840 webContext()->setContextLostCallback(nullptr); |
850 webContext()->setErrorMessageCallback(nullptr); | 841 webContext()->setErrorMessageCallback(nullptr); |
851 | 842 |
852 ASSERT(drawingBuffer()); | 843 ASSERT(drawingBuffer()); |
853 #if ENABLE(OILPAN) | |
854 // The DrawingBuffer ref pointers are cleared, but the | |
855 // WebGLSharedWebGraphicsContext3D object will hold onto the | |
856 // DrawingBuffer for as long as needed (== until all | |
857 // context objects have been finalized), at which point | |
858 // DrawingBuffer destruction happens. | |
859 m_sharedWebGraphicsContext3D.clear(); | |
860 #else | |
861 m_drawingBuffer->beginDestruction(); | 844 m_drawingBuffer->beginDestruction(); |
862 m_drawingBuffer.clear(); | 845 m_drawingBuffer.clear(); |
863 #endif | |
864 } | 846 } |
865 | 847 |
866 void WebGLRenderingContextBase::markContextChanged(ContentChangeType changeType) | 848 void WebGLRenderingContextBase::markContextChanged(ContentChangeType changeType) |
867 { | 849 { |
868 if (m_framebufferBinding || isContextLost()) | 850 if (m_framebufferBinding || isContextLost()) |
869 return; | 851 return; |
870 | 852 |
871 drawingBuffer()->markContentsChanged(); | 853 drawingBuffer()->markContentsChanged(); |
872 | 854 |
873 LayoutBox* layoutBox = canvas()->layoutBox(); | 855 LayoutBox* layoutBox = canvas()->layoutBox(); |
(...skipping 5055 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5929 if (!frame) | 5911 if (!frame) |
5930 return; | 5912 return; |
5931 | 5913 |
5932 Settings* settings = frame->settings(); | 5914 Settings* settings = frame->settings(); |
5933 | 5915 |
5934 if (!frame->loader().client()->allowWebGL(settings && settings->webGLEnabled
())) | 5916 if (!frame->loader().client()->allowWebGL(settings && settings->webGLEnabled
())) |
5935 return; | 5917 return; |
5936 | 5918 |
5937 // If the context was lost due to RealLostContext, we need to destroy the ol
d DrawingBuffer before creating new DrawingBuffer to ensure resource budget enou
gh. | 5919 // If the context was lost due to RealLostContext, we need to destroy the ol
d DrawingBuffer before creating new DrawingBuffer to ensure resource budget enou
gh. |
5938 if (drawingBuffer()) { | 5920 if (drawingBuffer()) { |
5939 #if ENABLE(OILPAN) | |
5940 m_sharedWebGraphicsContext3D->dispose(); | |
5941 #else | |
5942 m_drawingBuffer->beginDestruction(); | 5921 m_drawingBuffer->beginDestruction(); |
5943 m_drawingBuffer.clear(); | 5922 m_drawingBuffer.clear(); |
5944 #endif | |
5945 } | 5923 } |
5946 | 5924 |
5947 WebGraphicsContext3D::Attributes attributes = toWebGraphicsContext3DAttribut
es(m_requestedAttributes, canvas()->document().topDocument().url().string(), set
tings, version()); | 5925 WebGraphicsContext3D::Attributes attributes = toWebGraphicsContext3DAttribut
es(m_requestedAttributes, canvas()->document().topDocument().url().string(), set
tings, version()); |
5948 OwnPtr<WebGraphicsContext3D> context = adoptPtr(Platform::current()->createO
ffscreenGraphicsContext3D(attributes, 0)); | 5926 OwnPtr<WebGraphicsContext3D> context = adoptPtr(Platform::current()->createO
ffscreenGraphicsContext3D(attributes, 0)); |
5949 RefPtr<DrawingBuffer> buffer; | 5927 RefPtr<DrawingBuffer> buffer; |
5950 if (context) { | 5928 if (context) { |
5951 // Construct a new drawing buffer with the new WebGraphicsContext3D. | 5929 // Construct a new drawing buffer with the new WebGraphicsContext3D. |
5952 buffer = createDrawingBuffer(context.release()); | 5930 buffer = createDrawingBuffer(context.release()); |
5953 // If DrawingBuffer::create() fails to allocate a fbo, |drawingBuffer| i
s set to null. | 5931 // If DrawingBuffer::create() fails to allocate a fbo, |drawingBuffer| i
s set to null. |
5954 } | 5932 } |
5955 if (!buffer) { | 5933 if (!buffer) { |
5956 if (m_contextLostMode == RealLostContext) { | 5934 if (m_contextLostMode == RealLostContext) { |
5957 m_restoreTimer.startOneShot(secondsBetweenRestoreAttempts, FROM_HERE
); | 5935 m_restoreTimer.startOneShot(secondsBetweenRestoreAttempts, FROM_HERE
); |
5958 } else { | 5936 } else { |
5959 // This likely shouldn't happen but is the best way to report it to
the WebGL app. | 5937 // This likely shouldn't happen but is the best way to report it to
the WebGL app. |
5960 synthesizeGLError(GL_INVALID_OPERATION, "", "error restoring context
"); | 5938 synthesizeGLError(GL_INVALID_OPERATION, "", "error restoring context
"); |
5961 } | 5939 } |
5962 return; | 5940 return; |
5963 } | 5941 } |
5964 | 5942 |
5965 #if ENABLE(OILPAN) | |
5966 if (m_sharedWebGraphicsContext3D) | |
5967 m_sharedWebGraphicsContext3D->update(buffer.release()); | |
5968 else | |
5969 m_sharedWebGraphicsContext3D = WebGLSharedWebGraphicsContext3D::create(b
uffer.release()); | |
5970 #else | |
5971 m_drawingBuffer = buffer.release(); | 5943 m_drawingBuffer = buffer.release(); |
5972 #endif | |
5973 | 5944 |
5974 drawingBuffer()->bind(); | 5945 drawingBuffer()->bind(); |
5975 m_lostContextErrors.clear(); | 5946 m_lostContextErrors.clear(); |
5976 m_contextLostMode = NotLostContext; | 5947 m_contextLostMode = NotLostContext; |
5977 m_autoRecoveryMethod = Manual; | 5948 m_autoRecoveryMethod = Manual; |
5978 m_restoreAllowed = false; | 5949 m_restoreAllowed = false; |
5979 removeFromEvictedList(this); | 5950 removeFromEvictedList(this); |
5980 | 5951 |
5981 setupFlags(); | 5952 setupFlags(); |
5982 initializeNewContext(); | 5953 initializeNewContext(); |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6234 totalBytesPerPixel += samples * bytesPerPixel; // depth/stencil
multisample buffer | 6205 totalBytesPerPixel += samples * bytesPerPixel; // depth/stencil
multisample buffer |
6235 totalBytesPerPixel += samples * bytesPerPixel; // color multisample
buffer | 6206 totalBytesPerPixel += samples * bytesPerPixel; // color multisample
buffer |
6236 } else if (attribs.get().depth() || attribs.get().stencil()) { | 6207 } else if (attribs.get().depth() || attribs.get().stencil()) { |
6237 totalBytesPerPixel += bytesPerPixel; // regular depth/stencil buffer | 6208 totalBytesPerPixel += bytesPerPixel; // regular depth/stencil buffer |
6238 } | 6209 } |
6239 } | 6210 } |
6240 | 6211 |
6241 return totalBytesPerPixel; | 6212 return totalBytesPerPixel; |
6242 } | 6213 } |
6243 | 6214 |
6244 #if ENABLE(OILPAN) | |
6245 PassRefPtr<WebGLSharedWebGraphicsContext3D> WebGLRenderingContextBase::sharedWeb
GraphicsContext3D() const | |
6246 { | |
6247 return m_sharedWebGraphicsContext3D; | |
6248 } | |
6249 | |
6250 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const | 6215 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const |
6251 { | 6216 { |
6252 return m_sharedWebGraphicsContext3D ? m_sharedWebGraphicsContext3D->drawingB
uffer() : 0; | |
6253 } | |
6254 #else | |
6255 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const | |
6256 { | |
6257 return m_drawingBuffer.get(); | 6217 return m_drawingBuffer.get(); |
6258 } | 6218 } |
6259 #endif | |
6260 | 6219 |
6261 } // namespace blink | 6220 } // namespace blink |
OLD | NEW |