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 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 499 formatWebGLStatusString("Sandboxed", info.sandboxed ? "yes" : "no", statusMe ssage); | 499 formatWebGLStatusString("Sandboxed", info.sandboxed ? "yes" : "no", statusMe ssage); |
| 500 formatWebGLStatusString("Optimus", info.optimus ? "yes" : "no", statusMessag e); | 500 formatWebGLStatusString("Optimus", info.optimus ? "yes" : "no", statusMessag e); |
| 501 formatWebGLStatusString("AMD switchable", info.amdSwitchable ? "yes" : "no", statusMessage); | 501 formatWebGLStatusString("AMD switchable", info.amdSwitchable ? "yes" : "no", statusMessage); |
| 502 formatWebGLStatusString("Reset notification strategy", String::format("0x%04 x", info.resetNotificationStrategy).utf8().data(), statusMessage); | 502 formatWebGLStatusString("Reset notification strategy", String::format("0x%04 x", info.resetNotificationStrategy).utf8().data(), statusMessage); |
| 503 formatWebGLStatusString("GPU process crash count", String::number(info.proce ssCrashCount).utf8().data(), statusMessage); | 503 formatWebGLStatusString("GPU process crash count", String::number(info.proce ssCrashCount).utf8().data(), statusMessage); |
| 504 formatWebGLStatusString("ErrorMessage", info.errorMessage.utf8().data(), sta tusMessage); | 504 formatWebGLStatusString("ErrorMessage", info.errorMessage.utf8().data(), sta tusMessage); |
| 505 statusMessage.append("."); | 505 statusMessage.append("."); |
| 506 return statusMessage; | 506 return statusMessage; |
| 507 } | 507 } |
| 508 | 508 |
| 509 static PassOwnPtr<WebGraphicsContext3DProvider> createWebGraphicsContext3DProvid erHelper(HTMLCanvasElement* canvas, ScriptState* scriptState, WebGLContextAttrib utes attributes, unsigned webGLVersion) | |
| 510 { | |
| 511 Platform::ContextAttributes contextAttributes = toPlatformContextAttributes( attributes, webGLVersion); | |
| 512 Platform::GraphicsInfo glInfo; | |
| 513 OwnPtr<WebGraphicsContext3DProvider> contextProvider; | |
| 514 if (canvas) { | |
| 515 contextProvider = adoptPtr(Platform::current()->createOffscreenGraphicsC ontext3DProvider( | |
| 516 contextAttributes, canvas->document().topDocument().url(), 0, &glInf o)); | |
| 517 } else { | |
| 518 contextProvider = adoptPtr(Platform::current()->createOffscreenGraphicsC ontext3DProvider( | |
| 519 contextAttributes, scriptState->getExecutionContext()->url(), 0, &gl Info)); | |
|
xidachen
2016/04/20 19:31:09
Doing offscreenCanvas.getContext('webgl') works fi
| |
| 520 } | |
| 521 if (!contextProvider || shouldFailContextCreationForTesting) { | |
| 522 shouldFailContextCreationForTesting = false; | |
| 523 if (canvas) | |
| 524 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webg lcontextcreationerror, false, true, extractWebGLContextCreationError(glInfo))); | |
| 525 return nullptr; | |
| 526 } | |
| 527 gpu::gles2::GLES2Interface* gl = contextProvider->contextGL(); | |
| 528 if (!String(gl->GetString(GL_EXTENSIONS)).contains("GL_OES_packed_depth_sten cil")) { | |
| 529 if (canvas) | |
| 530 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webg lcontextcreationerror, false, true, "OES_packed_depth_stencil support is require d.")); | |
| 531 return nullptr; | |
| 532 } | |
| 533 | |
| 534 return contextProvider.release(); | |
| 535 } | |
| 536 | |
| 509 PassOwnPtr<WebGraphicsContext3DProvider> WebGLRenderingContextBase::createWebGra phicsContext3DProvider(HTMLCanvasElement* canvas, WebGLContextAttributes attribu tes, unsigned webGLVersion) | 537 PassOwnPtr<WebGraphicsContext3DProvider> WebGLRenderingContextBase::createWebGra phicsContext3DProvider(HTMLCanvasElement* canvas, WebGLContextAttributes attribu tes, unsigned webGLVersion) |
| 510 { | 538 { |
| 511 Document& document = canvas->document(); | 539 Document& document = canvas->document(); |
| 512 LocalFrame* frame = document.frame(); | 540 LocalFrame* frame = document.frame(); |
| 513 if (!frame) { | 541 if (!frame) { |
| 514 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Web page was not allowed to create a WebGL cont ext.")); | 542 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Web page was not allowed to create a WebGL cont ext.")); |
| 515 return nullptr; | 543 return nullptr; |
| 516 } | 544 } |
| 517 Settings* settings = frame->settings(); | 545 Settings* settings = frame->settings(); |
| 518 | 546 |
| 519 // The FrameLoaderClient might block creation of a new WebGL context despite the page settings; in | 547 // The FrameLoaderClient might block creation of a new WebGL context despite the page settings; in |
| 520 // particular, if WebGL contexts were lost one or more times via the GL_ARB_ robustness extension. | 548 // particular, if WebGL contexts were lost one or more times via the GL_ARB_ robustness extension. |
| 521 if (!frame->loader().client()->allowWebGL(settings && settings->webGLEnabled ())) { | 549 if (!frame->loader().client()->allowWebGL(settings && settings->webGLEnabled ())) { |
| 522 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Web page was not allowed to create a WebGL cont ext.")); | 550 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Web page was not allowed to create a WebGL cont ext.")); |
| 523 return nullptr; | 551 return nullptr; |
| 524 } | 552 } |
| 525 | 553 |
| 526 Platform::ContextAttributes contextAttributes = toPlatformContextAttributes( attributes, webGLVersion); | 554 return createWebGraphicsContext3DProviderHelper(canvas, static_cast<ScriptSt ate*>(nullptr), attributes, webGLVersion); |
| 527 Platform::GraphicsInfo glInfo; | 555 } |
| 528 OwnPtr<WebGraphicsContext3DProvider> contextProvider = adoptPtr(Platform::cu rrent()->createOffscreenGraphicsContext3DProvider( | |
| 529 contextAttributes, document.topDocument().url(), 0, &glInfo)); | |
| 530 if (!contextProvider || shouldFailContextCreationForTesting) { | |
| 531 shouldFailContextCreationForTesting = false; | |
| 532 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, extractWebGLContextCreationError(glInfo))); | |
| 533 return nullptr; | |
| 534 } | |
| 535 gpu::gles2::GLES2Interface* gl = contextProvider->contextGL(); | |
| 536 if (!String(gl->GetString(GL_EXTENSIONS)).contains("GL_OES_packed_depth_sten cil")) { | |
| 537 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "OES_packed_depth_stencil support is required.") ); | |
| 538 return nullptr; | |
| 539 } | |
| 540 | 556 |
| 541 return contextProvider.release(); | 557 PassOwnPtr<WebGraphicsContext3DProvider> WebGLRenderingContextBase::createWebGra phicsContext3DProvider(ScriptState* scriptState, WebGLContextAttributes attribut es, unsigned webGLVersion) |
| 558 { | |
| 559 return createWebGraphicsContext3DProviderHelper(static_cast<HTMLCanvasElemen t*>(nullptr), scriptState, attributes, webGLVersion); | |
| 542 } | 560 } |
| 543 | 561 |
| 544 void WebGLRenderingContextBase::forceNextWebGLContextCreationToFail() | 562 void WebGLRenderingContextBase::forceNextWebGLContextCreationToFail() |
| 545 { | 563 { |
| 546 shouldFailContextCreationForTesting = true; | 564 shouldFailContextCreationForTesting = true; |
| 547 } | 565 } |
| 548 | 566 |
| 549 namespace { | 567 namespace { |
| 550 | 568 |
| 551 // ES2 enums | 569 // ES2 enums |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 776 case GL_SRGB8: | 794 case GL_SRGB8: |
| 777 case GL_SRGB8_ALPHA8: | 795 case GL_SRGB8_ALPHA8: |
| 778 return true; | 796 return true; |
| 779 default: | 797 default: |
| 780 return false; | 798 return false; |
| 781 } | 799 } |
| 782 } | 800 } |
| 783 | 801 |
| 784 } // namespace | 802 } // namespace |
| 785 | 803 |
| 804 WebGLRenderingContextBase::WebGLRenderingContextBase(OffscreenCanvas* passedOffs creenCanvas, PassOwnPtr<WebGraphicsContext3DProvider> contextProvider, const Web GLContextAttributes& requestedAttributes) | |
| 805 : WebGLRenderingContextBase(static_cast<HTMLCanvasElement*>(nullptr), passed OffscreenCanvas, contextProvider, requestedAttributes) | |
| 806 { } | |
| 807 | |
| 786 WebGLRenderingContextBase::WebGLRenderingContextBase(HTMLCanvasElement* passedCa nvas, PassOwnPtr<WebGraphicsContext3DProvider> contextProvider, const WebGLConte xtAttributes& requestedAttributes) | 808 WebGLRenderingContextBase::WebGLRenderingContextBase(HTMLCanvasElement* passedCa nvas, PassOwnPtr<WebGraphicsContext3DProvider> contextProvider, const WebGLConte xtAttributes& requestedAttributes) |
| 809 : WebGLRenderingContextBase(passedCanvas, static_cast<OffscreenCanvas*>(null ptr), contextProvider, requestedAttributes) | |
| 810 { } | |
| 811 | |
| 812 WebGLRenderingContextBase::WebGLRenderingContextBase(HTMLCanvasElement* passedCa nvas, OffscreenCanvas* passedOffscreenCanvas, PassOwnPtr<WebGraphicsContext3DPro vider> contextProvider, const WebGLContextAttributes& requestedAttributes) | |
| 787 : CanvasRenderingContext(passedCanvas) | 813 : CanvasRenderingContext(passedCanvas) |
| 814 , OffscreenCanvasRenderingContext(passedOffscreenCanvas) | |
| 788 , m_isHidden(false) | 815 , m_isHidden(false) |
| 789 , m_contextLostMode(NotLostContext) | 816 , m_contextLostMode(NotLostContext) |
| 790 , m_autoRecoveryMethod(Manual) | 817 , m_autoRecoveryMethod(Manual) |
| 791 , m_dispatchContextLostEventTimer(this, &WebGLRenderingContextBase::dispatch ContextLostEvent) | 818 , m_dispatchContextLostEventTimer(this, &WebGLRenderingContextBase::dispatch ContextLostEvent) |
| 792 , m_restoreAllowed(false) | 819 , m_restoreAllowed(false) |
| 793 , m_restoreTimer(this, &WebGLRenderingContextBase::maybeRestoreContext) | 820 , m_restoreTimer(this, &WebGLRenderingContextBase::maybeRestoreContext) |
| 794 , m_preservedDefaultVAOObjectWrapper(false) | 821 , m_preservedDefaultVAOObjectWrapper(false) |
| 795 , m_generatedImageCache(4) | 822 , m_generatedImageCache(4) |
| 796 , m_requestedAttributes(requestedAttributes) | 823 , m_requestedAttributes(requestedAttributes) |
| 797 , m_synthesizedErrorsToConsole(true) | 824 , m_synthesizedErrorsToConsole(true) |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 973 ADD_VALUES_TO_SET(m_supportedFormats, kSupportedFormatsES2); | 1000 ADD_VALUES_TO_SET(m_supportedFormats, kSupportedFormatsES2); |
| 974 m_supportedTypes.clear(); | 1001 m_supportedTypes.clear(); |
| 975 ADD_VALUES_TO_SET(m_supportedTypes, kSupportedTypesES2); | 1002 ADD_VALUES_TO_SET(m_supportedTypes, kSupportedTypesES2); |
| 976 | 1003 |
| 977 activateContext(this); | 1004 activateContext(this); |
| 978 } | 1005 } |
| 979 | 1006 |
| 980 void WebGLRenderingContextBase::setupFlags() | 1007 void WebGLRenderingContextBase::setupFlags() |
| 981 { | 1008 { |
| 982 ASSERT(drawingBuffer()); | 1009 ASSERT(drawingBuffer()); |
| 983 if (Page* p = canvas()->document().page()) { | 1010 if (canvas()) { |
| 984 m_synthesizedErrorsToConsole = p->settings().webGLErrorsToConsoleEnabled (); | 1011 if (Page* p = canvas()->document().page()) { |
| 1012 m_synthesizedErrorsToConsole = p->settings().webGLErrorsToConsoleEna bled(); | |
| 1013 } | |
| 985 } | 1014 } |
| 986 | 1015 |
| 987 m_isDepthStencilSupported = extensionsUtil()->isExtensionEnabled("GL_OES_pac ked_depth_stencil"); | 1016 m_isDepthStencilSupported = extensionsUtil()->isExtensionEnabled("GL_OES_pac ked_depth_stencil"); |
| 988 } | 1017 } |
| 989 | 1018 |
| 990 void WebGLRenderingContextBase::addCompressedTextureFormat(GLenum format) | 1019 void WebGLRenderingContextBase::addCompressedTextureFormat(GLenum format) |
| 991 { | 1020 { |
| 992 if (!m_compressedTextureFormats.contains(format)) | 1021 if (!m_compressedTextureFormats.contains(format)) |
| 993 m_compressedTextureFormats.append(format); | 1022 m_compressedTextureFormats.append(format); |
| 994 } | 1023 } |
| (...skipping 5109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6104 if (isContextLost()) | 6133 if (isContextLost()) |
| 6105 return; | 6134 return; |
| 6106 if (enable) | 6135 if (enable) |
| 6107 contextGL()->Enable(capability); | 6136 contextGL()->Enable(capability); |
| 6108 else | 6137 else |
| 6109 contextGL()->Disable(capability); | 6138 contextGL()->Disable(capability); |
| 6110 } | 6139 } |
| 6111 | 6140 |
| 6112 IntSize WebGLRenderingContextBase::clampedCanvasSize() | 6141 IntSize WebGLRenderingContextBase::clampedCanvasSize() |
| 6113 { | 6142 { |
| 6114 return IntSize(clamp(canvas()->width(), 1, m_maxViewportDims[0]), | 6143 int width, height; |
| 6115 clamp(canvas()->height(), 1, m_maxViewportDims[1])); | 6144 if (canvas()) { |
| 6145 width = canvas()->width(); | |
| 6146 height = canvas()->height(); | |
| 6147 } else { | |
| 6148 width = getOffscreenCanvas()->width(); | |
| 6149 height = getOffscreenCanvas()->height(); | |
| 6150 } | |
| 6151 return IntSize(clamp(width, 1, m_maxViewportDims[0]), | |
| 6152 clamp(height, 1, m_maxViewportDims[1])); | |
| 6116 } | 6153 } |
| 6117 | 6154 |
| 6118 GLint WebGLRenderingContextBase::maxDrawBuffers() | 6155 GLint WebGLRenderingContextBase::maxDrawBuffers() |
| 6119 { | 6156 { |
| 6120 if (isContextLost() || !(extensionEnabled(WebGLDrawBuffersName) || isWebGL2O rHigher())) | 6157 if (isContextLost() || !(extensionEnabled(WebGLDrawBuffersName) || isWebGL2O rHigher())) |
| 6121 return 0; | 6158 return 0; |
| 6122 if (!m_maxDrawBuffers) | 6159 if (!m_maxDrawBuffers) |
| 6123 contextGL()->GetIntegerv(GL_MAX_DRAW_BUFFERS_EXT, &m_maxDrawBuffers); | 6160 contextGL()->GetIntegerv(GL_MAX_DRAW_BUFFERS_EXT, &m_maxDrawBuffers); |
| 6124 if (!m_maxColorAttachments) | 6161 if (!m_maxColorAttachments) |
| 6125 contextGL()->GetIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &m_maxColorAttach ments); | 6162 contextGL()->GetIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &m_maxColorAttach ments); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6244 visitor->trace(m_boundArrayBuffer); | 6281 visitor->trace(m_boundArrayBuffer); |
| 6245 visitor->trace(m_defaultVertexArrayObject); | 6282 visitor->trace(m_defaultVertexArrayObject); |
| 6246 visitor->trace(m_boundVertexArrayObject); | 6283 visitor->trace(m_boundVertexArrayObject); |
| 6247 visitor->trace(m_currentProgram); | 6284 visitor->trace(m_currentProgram); |
| 6248 visitor->trace(m_framebufferBinding); | 6285 visitor->trace(m_framebufferBinding); |
| 6249 visitor->trace(m_renderbufferBinding); | 6286 visitor->trace(m_renderbufferBinding); |
| 6250 visitor->trace(m_valuebufferBinding); | 6287 visitor->trace(m_valuebufferBinding); |
| 6251 visitor->trace(m_textureUnits); | 6288 visitor->trace(m_textureUnits); |
| 6252 visitor->trace(m_extensions); | 6289 visitor->trace(m_extensions); |
| 6253 CanvasRenderingContext::trace(visitor); | 6290 CanvasRenderingContext::trace(visitor); |
| 6291 OffscreenCanvasRenderingContext::trace(visitor); | |
| 6254 } | 6292 } |
| 6255 | 6293 |
| 6256 int WebGLRenderingContextBase::externallyAllocatedBytesPerPixel() | 6294 int WebGLRenderingContextBase::externallyAllocatedBytesPerPixel() |
| 6257 { | 6295 { |
| 6258 if (isContextLost()) | 6296 if (isContextLost()) |
| 6259 return 0; | 6297 return 0; |
| 6260 | 6298 |
| 6261 int bytesPerPixel = 4; | 6299 int bytesPerPixel = 4; |
| 6262 int totalBytesPerPixel = bytesPerPixel * 2; // WebGL's front and back color buffers. | 6300 int totalBytesPerPixel = bytesPerPixel * 2; // WebGL's front and back color buffers. |
| 6263 int samples = drawingBuffer() ? drawingBuffer()->sampleCount() : 0; | 6301 int samples = drawingBuffer() ? drawingBuffer()->sampleCount() : 0; |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 6290 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1); | 6328 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 6291 } | 6329 } |
| 6292 | 6330 |
| 6293 void WebGLRenderingContextBase::restoreUnpackParameters() | 6331 void WebGLRenderingContextBase::restoreUnpackParameters() |
| 6294 { | 6332 { |
| 6295 if (m_unpackAlignment != 1) | 6333 if (m_unpackAlignment != 1) |
| 6296 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); | 6334 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); |
| 6297 } | 6335 } |
| 6298 | 6336 |
| 6299 } // namespace blink | 6337 } // namespace blink |
| OLD | NEW |