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 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 496 formatWebGLStatusString("Sandboxed", info.sandboxed ? "yes" : "no", statusMe ssage); | 496 formatWebGLStatusString("Sandboxed", info.sandboxed ? "yes" : "no", statusMe ssage); |
| 497 formatWebGLStatusString("Optimus", info.optimus ? "yes" : "no", statusMessag e); | 497 formatWebGLStatusString("Optimus", info.optimus ? "yes" : "no", statusMessag e); |
| 498 formatWebGLStatusString("AMD switchable", info.amdSwitchable ? "yes" : "no", statusMessage); | 498 formatWebGLStatusString("AMD switchable", info.amdSwitchable ? "yes" : "no", statusMessage); |
| 499 formatWebGLStatusString("Reset notification strategy", String::format("0x%04 x", info.resetNotificationStrategy).utf8().data(), statusMessage); | 499 formatWebGLStatusString("Reset notification strategy", String::format("0x%04 x", info.resetNotificationStrategy).utf8().data(), statusMessage); |
| 500 formatWebGLStatusString("GPU process crash count", String::number(info.proce ssCrashCount).utf8().data(), statusMessage); | 500 formatWebGLStatusString("GPU process crash count", String::number(info.proce ssCrashCount).utf8().data(), statusMessage); |
| 501 formatWebGLStatusString("ErrorMessage", info.errorMessage.utf8().data(), sta tusMessage); | 501 formatWebGLStatusString("ErrorMessage", info.errorMessage.utf8().data(), sta tusMessage); |
| 502 statusMessage.append("."); | 502 statusMessage.append("."); |
| 503 return statusMessage; | 503 return statusMessage; |
| 504 } | 504 } |
| 505 | 505 |
| 506 static PassOwnPtr<WebGraphicsContext3DProvider> shouldCreateWebGraphicsContext3D Provider(HTMLCanvasElement* canvas, ScriptState* scriptState, WebGLContextAttrib utes attributes, unsigned webGLVersion) | |
|
bajones
2016/04/27 20:18:48
Similarly, this function doesn't return whether or
| |
| 507 { | |
| 508 Platform::ContextAttributes contextAttributes = toPlatformContextAttributes( attributes, webGLVersion); | |
| 509 Platform::GraphicsInfo glInfo; | |
| 510 OwnPtr<WebGraphicsContext3DProvider> contextProvider; | |
| 511 if (canvas) { | |
| 512 contextProvider = adoptPtr(Platform::current()->createOffscreenGraphicsC ontext3DProvider( | |
| 513 contextAttributes, canvas->document().topDocument().url(), 0, &glInf o)); | |
| 514 } else { | |
| 515 contextProvider = adoptPtr(Platform::current()->createOffscreenGraphicsC ontext3DProvider( | |
| 516 contextAttributes, scriptState->getExecutionContext()->url(), 0, &gl Info)); | |
| 517 } | |
| 518 if (!contextProvider || shouldFailContextCreationForTesting) { | |
| 519 shouldFailContextCreationForTesting = false; | |
| 520 if (canvas) | |
| 521 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webg lcontextcreationerror, false, true, extractWebGLContextCreationError(glInfo))); | |
| 522 return nullptr; | |
| 523 } | |
| 524 gpu::gles2::GLES2Interface* gl = contextProvider->contextGL(); | |
| 525 if (!String(gl->GetString(GL_EXTENSIONS)).contains("GL_OES_packed_depth_sten cil")) { | |
| 526 if (canvas) | |
| 527 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webg lcontextcreationerror, false, true, "OES_packed_depth_stencil support is require d.")); | |
| 528 return nullptr; | |
| 529 } | |
| 530 | |
| 531 return contextProvider.release(); | |
| 532 } | |
| 533 | |
| 506 PassOwnPtr<WebGraphicsContext3DProvider> WebGLRenderingContextBase::createWebGra phicsContext3DProvider(HTMLCanvasElement* canvas, WebGLContextAttributes attribu tes, unsigned webGLVersion) | 534 PassOwnPtr<WebGraphicsContext3DProvider> WebGLRenderingContextBase::createWebGra phicsContext3DProvider(HTMLCanvasElement* canvas, WebGLContextAttributes attribu tes, unsigned webGLVersion) |
| 507 { | 535 { |
| 508 Document& document = canvas->document(); | 536 Document& document = canvas->document(); |
| 509 LocalFrame* frame = document.frame(); | 537 LocalFrame* frame = document.frame(); |
| 510 if (!frame) { | 538 if (!frame) { |
| 511 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Web page was not allowed to create a WebGL cont ext.")); | 539 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Web page was not allowed to create a WebGL cont ext.")); |
| 512 return nullptr; | 540 return nullptr; |
| 513 } | 541 } |
| 514 Settings* settings = frame->settings(); | 542 Settings* settings = frame->settings(); |
| 515 | 543 |
| 516 // The FrameLoaderClient might block creation of a new WebGL context despite the page settings; in | 544 // The FrameLoaderClient might block creation of a new WebGL context despite the page settings; in |
| 517 // particular, if WebGL contexts were lost one or more times via the GL_ARB_ robustness extension. | 545 // particular, if WebGL contexts were lost one or more times via the GL_ARB_ robustness extension. |
| 518 if (!frame->loader().client()->allowWebGL(settings && settings->webGLEnabled ())) { | 546 if (!frame->loader().client()->allowWebGL(settings && settings->webGLEnabled ())) { |
| 519 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Web page was not allowed to create a WebGL cont ext.")); | 547 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Web page was not allowed to create a WebGL cont ext.")); |
| 520 return nullptr; | 548 return nullptr; |
| 521 } | 549 } |
| 522 | 550 |
| 523 Platform::ContextAttributes contextAttributes = toPlatformContextAttributes( attributes, webGLVersion); | 551 return shouldCreateWebGraphicsContext3DProvider(canvas, static_cast<ScriptSt ate*>(nullptr), attributes, webGLVersion); |
| 524 Platform::GraphicsInfo glInfo; | 552 } |
| 525 OwnPtr<WebGraphicsContext3DProvider> contextProvider = adoptPtr(Platform::cu rrent()->createOffscreenGraphicsContext3DProvider( | |
| 526 contextAttributes, document.topDocument().url(), 0, &glInfo)); | |
| 527 if (!contextProvider || shouldFailContextCreationForTesting) { | |
| 528 shouldFailContextCreationForTesting = false; | |
| 529 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, extractWebGLContextCreationError(glInfo))); | |
| 530 return nullptr; | |
| 531 } | |
| 532 gpu::gles2::GLES2Interface* gl = contextProvider->contextGL(); | |
| 533 if (!String(gl->GetString(GL_EXTENSIONS)).contains("GL_OES_packed_depth_sten cil")) { | |
| 534 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "OES_packed_depth_stencil support is required.") ); | |
| 535 return nullptr; | |
| 536 } | |
| 537 | 553 |
| 538 return contextProvider.release(); | 554 PassOwnPtr<WebGraphicsContext3DProvider> WebGLRenderingContextBase::createWebGra phicsContext3DProvider(ScriptState* scriptState, WebGLContextAttributes attribut es, unsigned webGLVersion) |
| 555 { | |
| 556 return shouldCreateWebGraphicsContext3DProvider(static_cast<HTMLCanvasElemen t*>(nullptr), scriptState, attributes, webGLVersion); | |
| 539 } | 557 } |
| 540 | 558 |
| 541 void WebGLRenderingContextBase::forceNextWebGLContextCreationToFail() | 559 void WebGLRenderingContextBase::forceNextWebGLContextCreationToFail() |
| 542 { | 560 { |
| 543 shouldFailContextCreationForTesting = true; | 561 shouldFailContextCreationForTesting = true; |
| 544 } | 562 } |
| 545 | 563 |
| 546 namespace { | 564 namespace { |
| 547 | 565 |
| 548 // ES2 enums | 566 // ES2 enums |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 773 case GL_SRGB8: | 791 case GL_SRGB8: |
| 774 case GL_SRGB8_ALPHA8: | 792 case GL_SRGB8_ALPHA8: |
| 775 return true; | 793 return true; |
| 776 default: | 794 default: |
| 777 return false; | 795 return false; |
| 778 } | 796 } |
| 779 } | 797 } |
| 780 | 798 |
| 781 } // namespace | 799 } // namespace |
| 782 | 800 |
| 801 WebGLRenderingContextBase::WebGLRenderingContextBase(OffscreenCanvas* passedOffs creenCanvas, PassOwnPtr<WebGraphicsContext3DProvider> contextProvider, const Web GLContextAttributes& requestedAttributes) | |
| 802 : WebGLRenderingContextBase(static_cast<HTMLCanvasElement*>(nullptr), passed OffscreenCanvas, contextProvider, requestedAttributes) | |
| 803 { } | |
| 804 | |
| 783 WebGLRenderingContextBase::WebGLRenderingContextBase(HTMLCanvasElement* passedCa nvas, PassOwnPtr<WebGraphicsContext3DProvider> contextProvider, const WebGLConte xtAttributes& requestedAttributes) | 805 WebGLRenderingContextBase::WebGLRenderingContextBase(HTMLCanvasElement* passedCa nvas, PassOwnPtr<WebGraphicsContext3DProvider> contextProvider, const WebGLConte xtAttributes& requestedAttributes) |
| 784 : CanvasRenderingContext(passedCanvas) | 806 : WebGLRenderingContextBase(passedCanvas, static_cast<OffscreenCanvas*>(null ptr), contextProvider, requestedAttributes) |
| 807 { } | |
| 808 | |
| 809 WebGLRenderingContextBase::WebGLRenderingContextBase(HTMLCanvasElement* passedCa nvas, OffscreenCanvas* passedOffscreenCanvas, PassOwnPtr<WebGraphicsContext3DPro vider> contextProvider, const WebGLContextAttributes& requestedAttributes) | |
| 810 : CanvasRenderingContext(passedCanvas, passedOffscreenCanvas) | |
| 785 , m_isHidden(false) | 811 , m_isHidden(false) |
| 786 , m_contextLostMode(NotLostContext) | 812 , m_contextLostMode(NotLostContext) |
| 787 , m_autoRecoveryMethod(Manual) | 813 , m_autoRecoveryMethod(Manual) |
| 788 , m_dispatchContextLostEventTimer(this, &WebGLRenderingContextBase::dispatch ContextLostEvent) | 814 , m_dispatchContextLostEventTimer(this, &WebGLRenderingContextBase::dispatch ContextLostEvent) |
| 789 , m_restoreAllowed(false) | 815 , m_restoreAllowed(false) |
| 790 , m_restoreTimer(this, &WebGLRenderingContextBase::maybeRestoreContext) | 816 , m_restoreTimer(this, &WebGLRenderingContextBase::maybeRestoreContext) |
| 791 , m_preservedDefaultVAOObjectWrapper(false) | 817 , m_preservedDefaultVAOObjectWrapper(false) |
| 792 , m_generatedImageCache(4) | 818 , m_generatedImageCache(4) |
| 793 , m_requestedAttributes(requestedAttributes) | 819 , m_requestedAttributes(requestedAttributes) |
| 794 , m_synthesizedErrorsToConsole(true) | 820 , m_synthesizedErrorsToConsole(true) |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 969 ADD_VALUES_TO_SET(m_supportedFormats, kSupportedFormatsES2); | 995 ADD_VALUES_TO_SET(m_supportedFormats, kSupportedFormatsES2); |
| 970 m_supportedTypes.clear(); | 996 m_supportedTypes.clear(); |
| 971 ADD_VALUES_TO_SET(m_supportedTypes, kSupportedTypesES2); | 997 ADD_VALUES_TO_SET(m_supportedTypes, kSupportedTypesES2); |
| 972 | 998 |
| 973 activateContext(this); | 999 activateContext(this); |
| 974 } | 1000 } |
| 975 | 1001 |
| 976 void WebGLRenderingContextBase::setupFlags() | 1002 void WebGLRenderingContextBase::setupFlags() |
| 977 { | 1003 { |
| 978 ASSERT(drawingBuffer()); | 1004 ASSERT(drawingBuffer()); |
| 979 if (Page* p = canvas()->document().page()) { | 1005 if (canvas()) { |
| 980 m_synthesizedErrorsToConsole = p->settings().webGLErrorsToConsoleEnabled (); | 1006 if (Page* p = canvas()->document().page()) { |
| 1007 m_synthesizedErrorsToConsole = p->settings().webGLErrorsToConsoleEna bled(); | |
| 1008 } | |
| 981 } | 1009 } |
| 982 | 1010 |
| 983 m_isDepthStencilSupported = extensionsUtil()->isExtensionEnabled("GL_OES_pac ked_depth_stencil"); | 1011 m_isDepthStencilSupported = extensionsUtil()->isExtensionEnabled("GL_OES_pac ked_depth_stencil"); |
| 984 } | 1012 } |
| 985 | 1013 |
| 986 void WebGLRenderingContextBase::addCompressedTextureFormat(GLenum format) | 1014 void WebGLRenderingContextBase::addCompressedTextureFormat(GLenum format) |
| 987 { | 1015 { |
| 988 if (!m_compressedTextureFormats.contains(format)) | 1016 if (!m_compressedTextureFormats.contains(format)) |
| 989 m_compressedTextureFormats.append(format); | 1017 m_compressedTextureFormats.append(format); |
| 990 } | 1018 } |
| (...skipping 5046 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6037 if (isContextLost()) | 6065 if (isContextLost()) |
| 6038 return; | 6066 return; |
| 6039 if (enable) | 6067 if (enable) |
| 6040 contextGL()->Enable(capability); | 6068 contextGL()->Enable(capability); |
| 6041 else | 6069 else |
| 6042 contextGL()->Disable(capability); | 6070 contextGL()->Disable(capability); |
| 6043 } | 6071 } |
| 6044 | 6072 |
| 6045 IntSize WebGLRenderingContextBase::clampedCanvasSize() | 6073 IntSize WebGLRenderingContextBase::clampedCanvasSize() |
| 6046 { | 6074 { |
| 6047 return IntSize(clamp(canvas()->width(), 1, m_maxViewportDims[0]), | 6075 int width, height; |
| 6048 clamp(canvas()->height(), 1, m_maxViewportDims[1])); | 6076 if (canvas()) { |
| 6077 width = canvas()->width(); | |
| 6078 height = canvas()->height(); | |
| 6079 } else { | |
| 6080 width = getOffscreenCanvas()->width(); | |
| 6081 height = getOffscreenCanvas()->height(); | |
| 6082 } | |
| 6083 return IntSize(clamp(width, 1, m_maxViewportDims[0]), | |
| 6084 clamp(height, 1, m_maxViewportDims[1])); | |
| 6049 } | 6085 } |
| 6050 | 6086 |
| 6051 GLint WebGLRenderingContextBase::maxDrawBuffers() | 6087 GLint WebGLRenderingContextBase::maxDrawBuffers() |
| 6052 { | 6088 { |
| 6053 if (isContextLost() || !(extensionEnabled(WebGLDrawBuffersName) || isWebGL2O rHigher())) | 6089 if (isContextLost() || !(extensionEnabled(WebGLDrawBuffersName) || isWebGL2O rHigher())) |
| 6054 return 0; | 6090 return 0; |
| 6055 if (!m_maxDrawBuffers) | 6091 if (!m_maxDrawBuffers) |
| 6056 contextGL()->GetIntegerv(GL_MAX_DRAW_BUFFERS_EXT, &m_maxDrawBuffers); | 6092 contextGL()->GetIntegerv(GL_MAX_DRAW_BUFFERS_EXT, &m_maxDrawBuffers); |
| 6057 if (!m_maxColorAttachments) | 6093 if (!m_maxColorAttachments) |
| 6058 contextGL()->GetIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &m_maxColorAttach ments); | 6094 contextGL()->GetIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &m_maxColorAttach ments); |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6222 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1); | 6258 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 6223 } | 6259 } |
| 6224 | 6260 |
| 6225 void WebGLRenderingContextBase::restoreUnpackParameters() | 6261 void WebGLRenderingContextBase::restoreUnpackParameters() |
| 6226 { | 6262 { |
| 6227 if (m_unpackAlignment != 1) | 6263 if (m_unpackAlignment != 1) |
| 6228 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); | 6264 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); |
| 6229 } | 6265 } |
| 6230 | 6266 |
| 6231 } // namespace blink | 6267 } // namespace blink |
| OLD | NEW |