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 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 555 } | 555 } |
| 556 Settings* settings = frame->settings(); | 556 Settings* settings = frame->settings(); |
| 557 | 557 |
| 558 // The FrameLoaderClient might block creation of a new WebGL context despite the page settings; in | 558 // The FrameLoaderClient might block creation of a new WebGL context despite the page settings; in |
| 559 // particular, if WebGL contexts were lost one or more times via the GL_ARB_ robustness extension. | 559 // particular, if WebGL contexts were lost one or more times via the GL_ARB_ robustness extension. |
| 560 if (!frame->loader().client()->allowWebGL(settings && settings->webGLEnabled ())) { | 560 if (!frame->loader().client()->allowWebGL(settings && settings->webGLEnabled ())) { |
| 561 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Web page was not allowed to create a WebGL cont ext.")); | 561 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Web page was not allowed to create a WebGL cont ext.")); |
| 562 return nullptr; | 562 return nullptr; |
| 563 } | 563 } |
| 564 | 564 |
| 565 WebGraphicsContext3D::Attributes wgc3dAttributes = toWebGraphicsContext3DAtt ributes(attributes, document.topDocument().url().getString(), settings, webGLVer sion); | 565 WebGraphicsContext3D::Attributes wgc3dAttributes = toWebGraphicsContext3DAtt ributes(attributes, document.topDocument().url().getString(), webGLVersion); |
| 566 Platform::GraphicsInfo glInfo; | 566 Platform::GraphicsInfo glInfo; |
| 567 glInfo.testFailContext = shouldFailContextCreationForTesting; | 567 glInfo.testFailContext = shouldFailContextCreationForTesting; |
| 568 OwnPtr<WebGraphicsContext3DProvider> contextProvider = adoptPtr(Platform::cu rrent()->createOffscreenGraphicsContext3DProvider(wgc3dAttributes, 0, &glInfo)); | 568 OwnPtr<WebGraphicsContext3DProvider> contextProvider = adoptPtr(Platform::cu rrent()->createOffscreenGraphicsContext3DProvider(wgc3dAttributes, 0, &glInfo)); |
| 569 if (!contextProvider || shouldFailContextCreationForTesting) { | 569 if (!contextProvider || shouldFailContextCreationForTesting) { |
| 570 shouldFailContextCreationForTesting = false; | 570 shouldFailContextCreationForTesting = false; |
| 571 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, extractWebGLContextCreationError(glInfo))); | 571 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, extractWebGLContextCreationError(glInfo))); |
| 572 return nullptr; | 572 return nullptr; |
| 573 } | 573 } |
| 574 gpu::gles2::GLES2Interface* gl = contextProvider->contextGL(); | 574 gpu::gles2::GLES2Interface* gl = contextProvider->contextGL(); |
| 575 if (!String(gl->GetString(GL_EXTENSIONS)).contains("GL_OES_packed_depth_sten cil")) { | 575 if (!String(gl->GetString(GL_EXTENSIONS)).contains("GL_OES_packed_depth_sten cil")) { |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 873 } | 873 } |
| 874 | 874 |
| 875 ADD_VALUES_TO_SET(m_supportedInternalFormats, kSupportedInternalFormatsES2); | 875 ADD_VALUES_TO_SET(m_supportedInternalFormats, kSupportedInternalFormatsES2); |
| 876 ADD_VALUES_TO_SET(m_supportedInternalFormatsCopyTexImage, kSupportedInternal FormatsES2); | 876 ADD_VALUES_TO_SET(m_supportedInternalFormatsCopyTexImage, kSupportedInternal FormatsES2); |
| 877 ADD_VALUES_TO_SET(m_supportedFormats, kSupportedFormatsES2); | 877 ADD_VALUES_TO_SET(m_supportedFormats, kSupportedFormatsES2); |
| 878 ADD_VALUES_TO_SET(m_supportedTypes, kSupportedTypesES2); | 878 ADD_VALUES_TO_SET(m_supportedTypes, kSupportedTypesES2); |
| 879 } | 879 } |
| 880 | 880 |
| 881 PassRefPtr<DrawingBuffer> WebGLRenderingContextBase::createDrawingBuffer(PassOwn Ptr<WebGraphicsContext3DProvider> contextProvider) | 881 PassRefPtr<DrawingBuffer> WebGLRenderingContextBase::createDrawingBuffer(PassOwn Ptr<WebGraphicsContext3DProvider> contextProvider) |
| 882 { | 882 { |
| 883 WebGraphicsContext3D::Attributes attrs; | |
| 884 attrs.alpha = m_requestedAttributes.alpha(); | |
| 885 attrs.depth = m_requestedAttributes.depth(); | |
| 886 attrs.stencil = m_requestedAttributes.stencil(); | |
| 887 attrs.antialias = m_requestedAttributes.antialias(); | |
| 888 bool premultipliedAlpha = m_requestedAttributes.premultipliedAlpha(); | 883 bool premultipliedAlpha = m_requestedAttributes.premultipliedAlpha(); |
| 884 bool wantAlphaChannel = m_requestedAttributes.alpha(); | |
| 885 bool wantDepthBuffer = m_requestedAttributes.depth(); | |
| 886 bool wantStencilBuffer = m_requestedAttributes.stencil(); | |
| 887 bool wantAntialiasing = m_requestedAttributes.antialias(); | |
| 889 DrawingBuffer::PreserveDrawingBuffer preserve = m_requestedAttributes.preser veDrawingBuffer() ? DrawingBuffer::Preserve : DrawingBuffer::Discard; | 888 DrawingBuffer::PreserveDrawingBuffer preserve = m_requestedAttributes.preser veDrawingBuffer() ? DrawingBuffer::Preserve : DrawingBuffer::Discard; |
| 890 return DrawingBuffer::create(contextProvider, clampedCanvasSize(), premultip liedAlpha, preserve, attrs); | 889 return DrawingBuffer::create( |
| 890 contextProvider, | |
| 891 clampedCanvasSize(), | |
| 892 premultipliedAlpha, | |
| 893 wantAlphaChannel, | |
| 894 wantDepthBuffer, | |
| 895 wantStencilBuffer, | |
| 896 wantAntialiasing, | |
| 897 preserve); | |
| 891 } | 898 } |
| 892 | 899 |
| 893 void WebGLRenderingContextBase::initializeNewContext() | 900 void WebGLRenderingContextBase::initializeNewContext() |
| 894 { | 901 { |
| 895 ASSERT(!isContextLost()); | 902 ASSERT(!isContextLost()); |
| 896 ASSERT(drawingBuffer()); | 903 ASSERT(drawingBuffer()); |
| 897 | 904 |
| 898 m_markedCanvasDirty = false; | 905 m_markedCanvasDirty = false; |
| 899 m_activeTextureUnit = 0; | 906 m_activeTextureUnit = 0; |
| 900 m_packAlignment = 4; | 907 m_packAlignment = 4; |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1292 int currentArea = width * height; | 1299 int currentArea = width * height; |
| 1293 if (currentArea > maxArea) { | 1300 if (currentArea > maxArea) { |
| 1294 // If we've exceeded the area limit scale the buffer down, preserving as cpect ratio, until it fits. | 1301 // If we've exceeded the area limit scale the buffer down, preserving as cpect ratio, until it fits. |
| 1295 float scaleFactor = sqrtf(static_cast<float>(maxArea) / static_cast<floa t>(currentArea)); | 1302 float scaleFactor = sqrtf(static_cast<float>(maxArea) / static_cast<floa t>(currentArea)); |
| 1296 width = std::max(1, static_cast<int>(width * scaleFactor)); | 1303 width = std::max(1, static_cast<int>(width * scaleFactor)); |
| 1297 height = std::max(1, static_cast<int>(height * scaleFactor)); | 1304 height = std::max(1, static_cast<int>(height * scaleFactor)); |
| 1298 } | 1305 } |
| 1299 | 1306 |
| 1300 // We don't have to mark the canvas as dirty, since the newly created image buffer will also start off | 1307 // We don't have to mark the canvas as dirty, since the newly created image buffer will also start off |
| 1301 // clear (and this matches what reshape will do). | 1308 // clear (and this matches what reshape will do). |
| 1302 drawingBuffer()->reset(IntSize(width, height)); | 1309 bool wantDepthOrStencilBuffer = m_requestedAttributes.depth() || m_requested Attributes.stencil(); |
|
danakj
2016/03/31 22:13:02
kbr: Please check that reading m_requestAttributes
| |
| 1310 drawingBuffer()->reset(IntSize(width, height), wantDepthOrStencilBuffer); | |
| 1303 restoreStateAfterClear(); | 1311 restoreStateAfterClear(); |
| 1304 | 1312 |
| 1305 contextGL()->BindTexture(GL_TEXTURE_2D, objectOrZero(m_textureUnits[m_active TextureUnit].m_texture2DBinding.get())); | 1313 contextGL()->BindTexture(GL_TEXTURE_2D, objectOrZero(m_textureUnits[m_active TextureUnit].m_texture2DBinding.get())); |
| 1306 contextGL()->BindRenderbuffer(GL_RENDERBUFFER, objectOrZero(m_renderbufferBi nding.get())); | 1314 contextGL()->BindRenderbuffer(GL_RENDERBUFFER, objectOrZero(m_renderbufferBi nding.get())); |
| 1307 drawingBuffer()->restoreFramebufferBindings(); | 1315 drawingBuffer()->restoreFramebufferBindings(); |
| 1308 } | 1316 } |
| 1309 | 1317 |
| 1310 int WebGLRenderingContextBase::drawingBufferWidth() const | 1318 int WebGLRenderingContextBase::drawingBufferWidth() const |
| 1311 { | 1319 { |
| 1312 return isContextLost() ? 0 : drawingBuffer()->size().width(); | 1320 return isContextLost() ? 0 : drawingBuffer()->size().width(); |
| (...skipping 1086 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2399 } | 2407 } |
| 2400 } | 2408 } |
| 2401 | 2409 |
| 2402 void WebGLRenderingContextBase::getContextAttributes(Nullable<WebGLContextAttrib utes>& result) | 2410 void WebGLRenderingContextBase::getContextAttributes(Nullable<WebGLContextAttrib utes>& result) |
| 2403 { | 2411 { |
| 2404 if (isContextLost()) | 2412 if (isContextLost()) |
| 2405 return; | 2413 return; |
| 2406 result.set(m_requestedAttributes); | 2414 result.set(m_requestedAttributes); |
| 2407 // Some requested attributes may not be honored, so we need to query the und erlying | 2415 // Some requested attributes may not be honored, so we need to query the und erlying |
| 2408 // context/drawing buffer and adjust accordingly. | 2416 // context/drawing buffer and adjust accordingly. |
| 2409 WebGraphicsContext3D::Attributes attrs = drawingBuffer()->getActualAttribute s(); | 2417 if (m_requestedAttributes.depth() && !drawingBuffer()->hasDepthBuffer()) |
| 2410 if (m_requestedAttributes.depth() && !attrs.depth) | |
| 2411 result.get().setDepth(false); | 2418 result.get().setDepth(false); |
| 2412 if (m_requestedAttributes.stencil() && !attrs.stencil) | 2419 if (m_requestedAttributes.stencil() && !drawingBuffer()->hasStencilBuffer()) |
| 2413 result.get().setStencil(false); | 2420 result.get().setStencil(false); |
| 2414 result.get().setAntialias(drawingBuffer()->multisample()); | 2421 result.get().setAntialias(drawingBuffer()->multisample()); |
| 2415 } | 2422 } |
| 2416 | 2423 |
| 2417 GLenum WebGLRenderingContextBase::getError() | 2424 GLenum WebGLRenderingContextBase::getError() |
| 2418 { | 2425 { |
| 2419 if (!m_lostContextErrors.isEmpty()) { | 2426 if (!m_lostContextErrors.isEmpty()) { |
| 2420 GLenum error = m_lostContextErrors.first(); | 2427 GLenum error = m_lostContextErrors.first(); |
| 2421 m_lostContextErrors.remove(0); | 2428 m_lostContextErrors.remove(0); |
| 2422 return error; | 2429 return error; |
| (...skipping 3570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5993 | 6000 |
| 5994 if (!frame->loader().client()->allowWebGL(settings && settings->webGLEnabled ())) | 6001 if (!frame->loader().client()->allowWebGL(settings && settings->webGLEnabled ())) |
| 5995 return; | 6002 return; |
| 5996 | 6003 |
| 5997 // 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. | 6004 // 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. |
| 5998 if (drawingBuffer()) { | 6005 if (drawingBuffer()) { |
| 5999 m_drawingBuffer->beginDestruction(); | 6006 m_drawingBuffer->beginDestruction(); |
| 6000 m_drawingBuffer.clear(); | 6007 m_drawingBuffer.clear(); |
| 6001 } | 6008 } |
| 6002 | 6009 |
| 6003 WebGraphicsContext3D::Attributes attributes = toWebGraphicsContext3DAttribut es(m_requestedAttributes, canvas()->document().topDocument().url().getString(), settings, version()); | 6010 WebGraphicsContext3D::Attributes attributes = toWebGraphicsContext3DAttribut es(m_requestedAttributes, canvas()->document().topDocument().url().getString(), version()); |
| 6004 Platform::GraphicsInfo glInfo; | 6011 Platform::GraphicsInfo glInfo; |
| 6005 OwnPtr<WebGraphicsContext3DProvider> contextProvider = adoptPtr(Platform::cu rrent()->createOffscreenGraphicsContext3DProvider(attributes, 0, &glInfo)); | 6012 OwnPtr<WebGraphicsContext3DProvider> contextProvider = adoptPtr(Platform::cu rrent()->createOffscreenGraphicsContext3DProvider(attributes, 0, &glInfo)); |
| 6006 RefPtr<DrawingBuffer> buffer; | 6013 RefPtr<DrawingBuffer> buffer; |
| 6007 if (contextProvider) { | 6014 if (contextProvider) { |
| 6008 // Construct a new drawing buffer with the new WebGraphicsContext3D. | 6015 // Construct a new drawing buffer with the new WebGraphicsContext3D. |
| 6009 buffer = createDrawingBuffer(contextProvider.release()); | 6016 buffer = createDrawingBuffer(contextProvider.release()); |
| 6010 // If DrawingBuffer::create() fails to allocate a fbo, |drawingBuffer| i s set to null. | 6017 // If DrawingBuffer::create() fails to allocate a fbo, |drawingBuffer| i s set to null. |
| 6011 } | 6018 } |
| 6012 if (!buffer) { | 6019 if (!buffer) { |
| 6013 if (m_contextLostMode == RealLostContext) { | 6020 if (m_contextLostMode == RealLostContext) { |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6344 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1); | 6351 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 6345 } | 6352 } |
| 6346 | 6353 |
| 6347 void WebGLRenderingContextBase::restoreUnpackParameters() | 6354 void WebGLRenderingContextBase::restoreUnpackParameters() |
| 6348 { | 6355 { |
| 6349 if (m_unpackAlignment != 1) | 6356 if (m_unpackAlignment != 1) |
| 6350 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); | 6357 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); |
| 6351 } | 6358 } |
| 6352 | 6359 |
| 6353 } // namespace blink | 6360 } // namespace blink |
| OLD | NEW |