Chromium Code Reviews| 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 950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 961 , m_version(version) | 961 , m_version(version) |
| 962 { | 962 { |
| 963 ASSERT(contextProvider); | 963 ASSERT(contextProvider); |
| 964 | 964 |
| 965 m_contextGroup = WebGLContextGroup::create(); | 965 m_contextGroup = WebGLContextGroup::create(); |
| 966 m_contextGroup->addContext(this); | 966 m_contextGroup->addContext(this); |
| 967 | 967 |
| 968 m_maxViewportDims[0] = m_maxViewportDims[1] = 0; | 968 m_maxViewportDims[0] = m_maxViewportDims[1] = 0; |
| 969 contextProvider->contextGL()->GetIntegerv(GL_MAX_VIEWPORT_DIMS, m_maxViewpor tDims); | 969 contextProvider->contextGL()->GetIntegerv(GL_MAX_VIEWPORT_DIMS, m_maxViewpor tDims); |
| 970 | 970 |
| 971 RefPtr<DrawingBuffer> buffer = createDrawingBuffer(std::move(contextProvider )); | 971 RefPtr<DrawingBuffer> buffer; |
| 972 if (passedOffscreenCanvas) | |
| 973 buffer = createDrawingBuffer(std::move(contextProvider), DrawingBuffer:: DisallowChromiumImage); | |
| 974 else | |
| 975 buffer = createDrawingBuffer(std::move(contextProvider), DrawingBuffer:: AllowChromiumImage); | |
| 972 if (!buffer) { | 976 if (!buffer) { |
| 973 m_contextLostMode = SyntheticLostContext; | 977 m_contextLostMode = SyntheticLostContext; |
| 974 return; | 978 return; |
| 975 } | 979 } |
| 976 | 980 |
| 977 m_drawingBuffer = buffer.release(); | 981 m_drawingBuffer = buffer.release(); |
| 978 m_drawingBuffer->addNewMailboxCallback(WTF::bind(&WebGLRenderingContextBase: :notifyCanvasContextChanged, wrapWeakPersistent(this))); | 982 m_drawingBuffer->addNewMailboxCallback(WTF::bind(&WebGLRenderingContextBase: :notifyCanvasContextChanged, wrapWeakPersistent(this))); |
| 979 drawingBuffer()->bind(GL_FRAMEBUFFER); | 983 drawingBuffer()->bind(GL_FRAMEBUFFER); |
| 980 setupFlags(); | 984 setupFlags(); |
| 981 | 985 |
| 982 #define ADD_VALUES_TO_SET(set, values) \ | 986 #define ADD_VALUES_TO_SET(set, values) \ |
| 983 for (size_t i = 0; i < WTF_ARRAY_LENGTH(values); ++i) { \ | 987 for (size_t i = 0; i < WTF_ARRAY_LENGTH(values); ++i) { \ |
| 984 set.insert(values[i]); \ | 988 set.insert(values[i]); \ |
| 985 } | 989 } |
| 986 | 990 |
| 987 ADD_VALUES_TO_SET(m_supportedInternalFormats, kSupportedInternalFormatsES2); | 991 ADD_VALUES_TO_SET(m_supportedInternalFormats, kSupportedInternalFormatsES2); |
| 988 ADD_VALUES_TO_SET(m_supportedInternalFormatsCopyTexImage, kSupportedInternal FormatsES2); | 992 ADD_VALUES_TO_SET(m_supportedInternalFormatsCopyTexImage, kSupportedInternal FormatsES2); |
| 989 ADD_VALUES_TO_SET(m_supportedFormats, kSupportedFormatsES2); | 993 ADD_VALUES_TO_SET(m_supportedFormats, kSupportedFormatsES2); |
| 990 ADD_VALUES_TO_SET(m_supportedTypes, kSupportedTypesES2); | 994 ADD_VALUES_TO_SET(m_supportedTypes, kSupportedTypesES2); |
| 991 } | 995 } |
| 992 | 996 |
| 993 PassRefPtr<DrawingBuffer> WebGLRenderingContextBase::createDrawingBuffer(std::un ique_ptr<WebGraphicsContext3DProvider> contextProvider) | 997 PassRefPtr<DrawingBuffer> WebGLRenderingContextBase::createDrawingBuffer(std::un ique_ptr<WebGraphicsContext3DProvider> contextProvider, DrawingBuffer::ChromiumI mageUsage chromiumImageUsage) |
| 994 { | 998 { |
| 995 bool premultipliedAlpha = creationAttributes().premultipliedAlpha(); | 999 bool premultipliedAlpha = creationAttributes().premultipliedAlpha(); |
| 996 bool wantAlphaChannel = creationAttributes().alpha(); | 1000 bool wantAlphaChannel = creationAttributes().alpha(); |
| 997 bool wantDepthBuffer = creationAttributes().depth(); | 1001 bool wantDepthBuffer = creationAttributes().depth(); |
| 998 bool wantStencilBuffer = creationAttributes().stencil(); | 1002 bool wantStencilBuffer = creationAttributes().stencil(); |
| 999 bool wantAntialiasing = creationAttributes().antialias(); | 1003 bool wantAntialiasing = creationAttributes().antialias(); |
| 1000 DrawingBuffer::PreserveDrawingBuffer preserve = creationAttributes().preserv eDrawingBuffer() ? DrawingBuffer::Preserve : DrawingBuffer::Discard; | 1004 DrawingBuffer::PreserveDrawingBuffer preserve = creationAttributes().preserv eDrawingBuffer() ? DrawingBuffer::Preserve : DrawingBuffer::Discard; |
| 1001 DrawingBuffer::WebGLVersion webGLVersion = DrawingBuffer::WebGL1; | 1005 DrawingBuffer::WebGLVersion webGLVersion = DrawingBuffer::WebGL1; |
| 1002 if (version() == 1) { | 1006 if (version() == 1) { |
| 1003 webGLVersion = DrawingBuffer::WebGL1; | 1007 webGLVersion = DrawingBuffer::WebGL1; |
| 1004 } else if (version() == 2) { | 1008 } else if (version() == 2) { |
| 1005 webGLVersion = DrawingBuffer::WebGL2; | 1009 webGLVersion = DrawingBuffer::WebGL2; |
| 1006 } else { | 1010 } else { |
| 1007 NOTREACHED(); | 1011 NOTREACHED(); |
| 1008 } | 1012 } |
| 1009 return DrawingBuffer::create( | 1013 return DrawingBuffer::create( |
| 1010 std::move(contextProvider), | 1014 std::move(contextProvider), |
| 1011 clampedCanvasSize(), | 1015 clampedCanvasSize(), |
| 1012 premultipliedAlpha, | 1016 premultipliedAlpha, |
| 1013 wantAlphaChannel, | 1017 wantAlphaChannel, |
| 1014 wantDepthBuffer, | 1018 wantDepthBuffer, |
| 1015 wantStencilBuffer, | 1019 wantStencilBuffer, |
| 1016 wantAntialiasing, | 1020 wantAntialiasing, |
| 1017 preserve, | 1021 preserve, |
| 1018 webGLVersion); | 1022 webGLVersion, |
| 1023 chromiumImageUsage); | |
| 1019 } | 1024 } |
| 1020 | 1025 |
| 1021 void WebGLRenderingContextBase::initializeNewContext() | 1026 void WebGLRenderingContextBase::initializeNewContext() |
| 1022 { | 1027 { |
| 1023 ASSERT(!isContextLost()); | 1028 ASSERT(!isContextLost()); |
| 1024 ASSERT(drawingBuffer()); | 1029 ASSERT(drawingBuffer()); |
| 1025 | 1030 |
| 1026 m_markedCanvasDirty = false; | 1031 m_markedCanvasDirty = false; |
| 1027 m_activeTextureUnit = 0; | 1032 m_activeTextureUnit = 0; |
| 1028 m_packAlignment = 4; | 1033 m_packAlignment = 4; |
| (...skipping 5141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6170 m_drawingBuffer.clear(); | 6175 m_drawingBuffer.clear(); |
| 6171 } | 6176 } |
| 6172 | 6177 |
| 6173 Platform::ContextAttributes attributes = toPlatformContextAttributes(creatio nAttributes(), version()); | 6178 Platform::ContextAttributes attributes = toPlatformContextAttributes(creatio nAttributes(), version()); |
| 6174 Platform::GraphicsInfo glInfo; | 6179 Platform::GraphicsInfo glInfo; |
| 6175 std::unique_ptr<WebGraphicsContext3DProvider> contextProvider = wrapUnique(P latform::current()->createOffscreenGraphicsContext3DProvider( | 6180 std::unique_ptr<WebGraphicsContext3DProvider> contextProvider = wrapUnique(P latform::current()->createOffscreenGraphicsContext3DProvider( |
| 6176 attributes, canvas()->document().topDocument().url(), 0, &glInfo)); | 6181 attributes, canvas()->document().topDocument().url(), 0, &glInfo)); |
| 6177 RefPtr<DrawingBuffer> buffer; | 6182 RefPtr<DrawingBuffer> buffer; |
| 6178 if (contextProvider && contextProvider->bindToCurrentThread()) { | 6183 if (contextProvider && contextProvider->bindToCurrentThread()) { |
| 6179 // Construct a new drawing buffer with the new GL context. | 6184 // Construct a new drawing buffer with the new GL context. |
| 6180 buffer = createDrawingBuffer(std::move(contextProvider)); | 6185 buffer = createDrawingBuffer(std::move(contextProvider), DrawingBuffer:: AllowChromiumImage); |
|
Ken Russell (switch to Gerrit)
2016/09/26 21:47:19
Is this correct in all cases, or does the context
| |
| 6181 // If DrawingBuffer::create() fails to allocate a fbo, |drawingBuffer| i s set to null. | 6186 // If DrawingBuffer::create() fails to allocate a fbo, |drawingBuffer| i s set to null. |
| 6182 } | 6187 } |
| 6183 if (!buffer) { | 6188 if (!buffer) { |
| 6184 if (m_contextLostMode == RealLostContext) { | 6189 if (m_contextLostMode == RealLostContext) { |
| 6185 m_restoreTimer.startOneShot(secondsBetweenRestoreAttempts, BLINK_FRO M_HERE); | 6190 m_restoreTimer.startOneShot(secondsBetweenRestoreAttempts, BLINK_FRO M_HERE); |
| 6186 } else { | 6191 } else { |
| 6187 // This likely shouldn't happen but is the best way to report it to the WebGL app. | 6192 // This likely shouldn't happen but is the best way to report it to the WebGL app. |
| 6188 synthesizeGLError(GL_INVALID_OPERATION, "", "error restoring context "); | 6193 synthesizeGLError(GL_INVALID_OPERATION, "", "error restoring context "); |
| 6189 } | 6194 } |
| 6190 return; | 6195 return; |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6473 | 6478 |
| 6474 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas(HTMLCanvasElementOrOffs creenCanvas& result) const | 6479 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas(HTMLCanvasElementOrOffs creenCanvas& result) const |
| 6475 { | 6480 { |
| 6476 if (canvas()) | 6481 if (canvas()) |
| 6477 result.setHTMLCanvasElement(canvas()); | 6482 result.setHTMLCanvasElement(canvas()); |
| 6478 else | 6483 else |
| 6479 result.setOffscreenCanvas(getOffscreenCanvas()); | 6484 result.setOffscreenCanvas(getOffscreenCanvas()); |
| 6480 } | 6485 } |
| 6481 | 6486 |
| 6482 } // namespace blink | 6487 } // namespace blink |
| OLD | NEW |