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 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 443 advance(); | 443 advance(); |
| 444 break; | 444 break; |
| 445 } | 445 } |
| 446 | 446 |
| 447 // Swallow all other characters. Unclear whether we may | 447 // Swallow all other characters. Unclear whether we may |
| 448 // want or need to just emit a space per character to try | 448 // want or need to just emit a space per character to try |
| 449 // to preserve column numbers for debugging purposes. | 449 // to preserve column numbers for debugging purposes. |
| 450 break; | 450 break; |
| 451 } | 451 } |
| 452 } | 452 } |
| 453 | |
| 454 GraphicsContext3D::Attributes adjustAttributes(const GraphicsContext3D::Attr ibutes attributes, Settings* settings) | |
|
Ken Russell (switch to Gerrit)
2013/05/11 00:21:15
const GraphicsContext3D::Attributes& attributes
| |
| 455 { | |
| 456 GraphicsContext3D::Attributes adjustedAttributes = attributes; | |
| 457 if (adjustedAttributes.antialias) { | |
| 458 if (settings && !settings->openGLMultisamplingEnabled()) | |
| 459 adjustedAttributes.antialias = false; | |
| 460 } | |
| 461 | |
| 462 return adjustedAttributes; | |
| 463 } | |
| 453 } // namespace anonymous | 464 } // namespace anonymous |
| 454 | 465 |
| 455 class WebGLRenderingContextLostCallback : public GraphicsContext3D::ContextLostC allback { | 466 class WebGLRenderingContextLostCallback : public GraphicsContext3D::ContextLostC allback { |
| 456 WTF_MAKE_FAST_ALLOCATED; | 467 WTF_MAKE_FAST_ALLOCATED; |
| 457 public: | 468 public: |
| 458 explicit WebGLRenderingContextLostCallback(WebGLRenderingContext* cb) : m_co ntext(cb) { } | 469 explicit WebGLRenderingContextLostCallback(WebGLRenderingContext* cb) : m_co ntext(cb) { } |
| 459 virtual void onContextLost() { m_context->forceLostContext(WebGLRenderingCon text::RealLostContext); } | 470 virtual void onContextLost() { m_context->forceLostContext(WebGLRenderingCon text::RealLostContext); } |
| 460 virtual ~WebGLRenderingContextLostCallback() {} | 471 virtual ~WebGLRenderingContextLostCallback() {} |
| 461 private: | 472 private: |
| 462 WebGLRenderingContext* m_context; | 473 WebGLRenderingContext* m_context; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 484 return nullptr; | 495 return nullptr; |
| 485 Settings* settings = frame->settings(); | 496 Settings* settings = frame->settings(); |
| 486 | 497 |
| 487 // The FrameLoaderClient might block creation of a new WebGL context despite the page settings; in | 498 // The FrameLoaderClient might block creation of a new WebGL context despite the page settings; in |
| 488 // particular, if WebGL contexts were lost one or more times via the GL_ARB_ robustness extension. | 499 // particular, if WebGL contexts were lost one or more times via the GL_ARB_ robustness extension. |
| 489 if (!frame->loader()->client()->allowWebGL(settings && settings->webGLEnable d())) { | 500 if (!frame->loader()->client()->allowWebGL(settings && settings->webGLEnable d())) { |
| 490 canvas->dispatchEvent(WebGLContextEvent::create(eventNames().webglcontex tcreationerrorEvent, false, true, "Web page was not allowed to create a WebGL co ntext.")); | 501 canvas->dispatchEvent(WebGLContextEvent::create(eventNames().webglcontex tcreationerrorEvent, false, true, "Web page was not allowed to create a WebGL co ntext.")); |
| 491 return nullptr; | 502 return nullptr; |
| 492 } | 503 } |
| 493 | 504 |
| 494 GraphicsContext3D::Attributes attributes = attrs ? attrs->attributes() : Gra phicsContext3D::Attributes(); | 505 GraphicsContext3D::Attributes requestedAttributes = attrs ? attrs->attribute s() : GraphicsContext3D::Attributes(); |
| 506 requestedAttributes.noExtensions = true; | |
| 507 requestedAttributes.shareResources = true; | |
| 508 requestedAttributes.preferDiscreteGPU = true; | |
| 509 requestedAttributes.topDocumentURL = document->topDocument()->url(); | |
| 495 | 510 |
| 496 if (attributes.antialias) { | 511 GraphicsContext3D::Attributes attributes = adjustAttributes(requestedAttribu tes, settings); |
| 497 if (settings && !settings->openGLMultisamplingEnabled()) | |
| 498 attributes.antialias = false; | |
| 499 } | |
| 500 | |
| 501 attributes.noExtensions = true; | |
| 502 attributes.shareResources = true; | |
| 503 attributes.preferDiscreteGPU = true; | |
| 504 attributes.topDocumentURL = document->topDocument()->url(); | |
| 505 | 512 |
| 506 RefPtr<GraphicsContext3D> context(GraphicsContext3D::create(attributes)); | 513 RefPtr<GraphicsContext3D> context(GraphicsContext3D::create(attributes)); |
| 507 | 514 |
| 508 if (!context || !context->makeContextCurrent()) { | 515 if (!context || !context->makeContextCurrent()) { |
| 509 canvas->dispatchEvent(WebGLContextEvent::create(eventNames().webglcontex tcreationerrorEvent, false, true, "Could not create a WebGL context.")); | 516 canvas->dispatchEvent(WebGLContextEvent::create(eventNames().webglcontex tcreationerrorEvent, false, true, "Could not create a WebGL context.")); |
| 510 return nullptr; | 517 return nullptr; |
| 511 } | 518 } |
| 512 | 519 |
| 513 Extensions3D* extensions = context->getExtensions(); | 520 Extensions3D* extensions = context->getExtensions(); |
| 514 if (extensions->supports("GL_EXT_debug_marker")) | 521 if (extensions->supports("GL_EXT_debug_marker")) |
| 515 extensions->pushGroupMarkerEXT("WebGLRenderingContext"); | 522 extensions->pushGroupMarkerEXT("WebGLRenderingContext"); |
| 516 | 523 |
| 517 OwnPtr<WebGLRenderingContext> renderingContext = adoptPtr(new WebGLRendering Context(canvas, context, attributes)); | 524 OwnPtr<WebGLRenderingContext> renderingContext = adoptPtr(new WebGLRendering Context(canvas, context, attributes, requestedAttributes)); |
| 518 renderingContext->suspendIfNeeded(); | 525 renderingContext->suspendIfNeeded(); |
| 519 | 526 |
| 520 if (renderingContext->m_drawingBuffer->isZeroSized()) { | 527 if (renderingContext->m_drawingBuffer->isZeroSized()) { |
| 521 canvas->dispatchEvent(WebGLContextEvent::create(eventNames().webglcontex tcreationerrorEvent, false, true, "Could not create a WebGL context.")); | 528 canvas->dispatchEvent(WebGLContextEvent::create(eventNames().webglcontex tcreationerrorEvent, false, true, "Could not create a WebGL context.")); |
| 522 return nullptr; | 529 return nullptr; |
| 523 } | 530 } |
| 524 | 531 |
| 525 return renderingContext.release(); | 532 return renderingContext.release(); |
| 526 } | 533 } |
| 527 | 534 |
| 528 WebGLRenderingContext::WebGLRenderingContext(HTMLCanvasElement* passedCanvas, Pa ssRefPtr<GraphicsContext3D> context, | 535 WebGLRenderingContext::WebGLRenderingContext(HTMLCanvasElement* passedCanvas, Pa ssRefPtr<GraphicsContext3D> context, GraphicsContext3D::Attributes attributes, G raphicsContext3D::Attributes requestedAttributes) |
| 529 GraphicsContext3D::Attributes attri butes) | |
| 530 : CanvasRenderingContext(passedCanvas) | 536 : CanvasRenderingContext(passedCanvas) |
| 531 , ActiveDOMObject(passedCanvas->document()) | 537 , ActiveDOMObject(passedCanvas->document()) |
| 532 , m_context(context) | 538 , m_context(context) |
| 533 , m_drawingBuffer(0) | 539 , m_drawingBuffer(0) |
| 534 , m_dispatchContextLostEventTimer(this, &WebGLRenderingContext::dispatchCont extLostEvent) | 540 , m_dispatchContextLostEventTimer(this, &WebGLRenderingContext::dispatchCont extLostEvent) |
| 535 , m_restoreAllowed(false) | 541 , m_restoreAllowed(false) |
| 536 , m_restoreTimer(this, &WebGLRenderingContext::maybeRestoreContext) | 542 , m_restoreTimer(this, &WebGLRenderingContext::maybeRestoreContext) |
| 537 , m_videoCache(4) | 543 , m_videoCache(4) |
| 538 , m_contextLost(false) | 544 , m_contextLost(false) |
| 539 , m_contextLostMode(SyntheticLostContext) | 545 , m_contextLostMode(SyntheticLostContext) |
| 540 , m_attributes(attributes) | 546 , m_attributes(attributes) |
| 547 , m_requestedAttributes(requestedAttributes) | |
| 541 , m_synthesizedErrorsToConsole(true) | 548 , m_synthesizedErrorsToConsole(true) |
| 542 , m_numGLErrorsToConsoleAllowed(maxGLErrorsAllowedToConsole) | 549 , m_numGLErrorsToConsoleAllowed(maxGLErrorsAllowedToConsole) |
| 550 , m_multisamplingAllowed(false) | |
| 551 , m_multisamplingObserverRegistered(false) | |
| 543 { | 552 { |
| 544 ASSERT(m_context); | 553 ASSERT(m_context); |
| 545 ScriptWrappable::init(this); | 554 ScriptWrappable::init(this); |
| 546 | 555 |
| 547 m_contextGroup = WebGLContextGroup::create(); | 556 m_contextGroup = WebGLContextGroup::create(); |
| 548 m_contextGroup->addContext(this); | 557 m_contextGroup->addContext(this); |
| 549 | 558 |
| 550 m_maxViewportDims[0] = m_maxViewportDims[1] = 0; | 559 m_maxViewportDims[0] = m_maxViewportDims[1] = 0; |
| 551 m_context->getIntegerv(GraphicsContext3D::MAX_VIEWPORT_DIMS, m_maxViewportDi ms); | 560 m_context->getIntegerv(GraphicsContext3D::MAX_VIEWPORT_DIMS, m_maxViewportDi ms); |
| 552 | 561 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 638 m_context->setErrorMessageCallback(adoptPtr(new WebGLRenderingContextErrorMe ssageCallback(this))); | 647 m_context->setErrorMessageCallback(adoptPtr(new WebGLRenderingContextErrorMe ssageCallback(this))); |
| 639 | 648 |
| 640 activateContext(this); | 649 activateContext(this); |
| 641 } | 650 } |
| 642 | 651 |
| 643 void WebGLRenderingContext::setupFlags() | 652 void WebGLRenderingContext::setupFlags() |
| 644 { | 653 { |
| 645 ASSERT(m_context); | 654 ASSERT(m_context); |
| 646 | 655 |
| 647 Page* p = canvas()->document()->page(); | 656 Page* p = canvas()->document()->page(); |
| 648 if (p) | 657 if (p) { |
| 649 m_synthesizedErrorsToConsole = p->settings()->webGLErrorsToConsoleEnable d(); | 658 m_synthesizedErrorsToConsole = p->settings()->webGLErrorsToConsoleEnable d(); |
| 650 | 659 |
| 660 if (!m_multisamplingObserverRegistered && m_requestedAttributes.antialia s) { | |
| 661 m_multisamplingAllowed = m_drawingBuffer->multisample(); | |
| 662 p->addMultisamplingChangedObserver(this); | |
| 663 m_multisamplingObserverRegistered = true; | |
| 664 } | |
| 665 } | |
| 666 | |
| 651 m_isGLES2NPOTStrict = !m_context->getExtensions()->isEnabled("GL_OES_texture _npot"); | 667 m_isGLES2NPOTStrict = !m_context->getExtensions()->isEnabled("GL_OES_texture _npot"); |
| 652 m_isDepthStencilSupported = m_context->getExtensions()->isEnabled("GL_OES_pa cked_depth_stencil"); | 668 m_isDepthStencilSupported = m_context->getExtensions()->isEnabled("GL_OES_pa cked_depth_stencil"); |
| 653 m_isRobustnessEXTSupported = m_context->getExtensions()->isEnabled("GL_EXT_r obustness"); | 669 m_isRobustnessEXTSupported = m_context->getExtensions()->isEnabled("GL_EXT_r obustness"); |
| 654 } | 670 } |
| 655 | 671 |
| 656 bool WebGLRenderingContext::allowPrivilegedExtensions() const | 672 bool WebGLRenderingContext::allowPrivilegedExtensions() const |
| 657 { | 673 { |
| 658 Page* p = canvas()->document()->page(); | 674 Page* p = canvas()->document()->page(); |
| 659 if (p && p->settings()) | 675 if (p && p->settings()) |
| 660 return p->settings()->privilegedWebGLExtensionsEnabled(); | 676 return p->settings()->privilegedWebGLExtensionsEnabled(); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 684 m_textureUnits[i].m_textureCubeMapBinding = 0; | 700 m_textureUnits[i].m_textureCubeMapBinding = 0; |
| 685 } | 701 } |
| 686 | 702 |
| 687 m_blackTexture2D = 0; | 703 m_blackTexture2D = 0; |
| 688 m_blackTextureCubeMap = 0; | 704 m_blackTextureCubeMap = 0; |
| 689 | 705 |
| 690 detachAndRemoveAllObjects(); | 706 detachAndRemoveAllObjects(); |
| 691 destroyGraphicsContext3D(); | 707 destroyGraphicsContext3D(); |
| 692 m_contextGroup->removeContext(this); | 708 m_contextGroup->removeContext(this); |
| 693 | 709 |
| 710 if (m_multisamplingObserverRegistered) { | |
| 711 Page* page = canvas()->document()->page(); | |
| 712 if (page) | |
| 713 page->removeMultisamplingChangedObserver(this); | |
| 714 } | |
| 715 | |
| 694 willDestroyContext(this); | 716 willDestroyContext(this); |
| 695 } | 717 } |
| 696 | 718 |
| 697 void WebGLRenderingContext::destroyGraphicsContext3D() | 719 void WebGLRenderingContext::destroyGraphicsContext3D() |
| 698 { | 720 { |
| 699 m_contextLost = true; | 721 m_contextLost = true; |
| 700 | 722 |
| 701 // The drawing buffer holds a context reference. It must also be destroyed | 723 // The drawing buffer holds a context reference. It must also be destroyed |
| 702 // in order for the context to be released. | 724 // in order for the context to be released. |
| 703 m_drawingBuffer->releaseResources(); | 725 m_drawingBuffer->releaseResources(); |
| (...skipping 4528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5232 for (int ii = 0; ii < expectedSize; ++ii) | 5254 for (int ii = 0; ii < expectedSize; ++ii) |
| 5233 attribValue.value[ii] = v[ii]; | 5255 attribValue.value[ii] = v[ii]; |
| 5234 } | 5256 } |
| 5235 | 5257 |
| 5236 void WebGLRenderingContext::dispatchContextLostEvent(Timer<WebGLRenderingContext >*) | 5258 void WebGLRenderingContext::dispatchContextLostEvent(Timer<WebGLRenderingContext >*) |
| 5237 { | 5259 { |
| 5238 RefPtr<WebGLContextEvent> event = WebGLContextEvent::create(eventNames().web glcontextlostEvent, false, true, ""); | 5260 RefPtr<WebGLContextEvent> event = WebGLContextEvent::create(eventNames().web glcontextlostEvent, false, true, ""); |
| 5239 canvas()->dispatchEvent(event); | 5261 canvas()->dispatchEvent(event); |
| 5240 m_restoreAllowed = event->defaultPrevented(); | 5262 m_restoreAllowed = event->defaultPrevented(); |
| 5241 deactivateContext(this, m_contextLostMode != RealLostContext && m_restoreAll owed); | 5263 deactivateContext(this, m_contextLostMode != RealLostContext && m_restoreAll owed); |
| 5242 if (m_contextLostMode == RealLostContext && m_restoreAllowed) | 5264 if ((m_contextLostMode == RealLostContext || m_contextLostMode == AutoRecove rSyntheticLostContext) && m_restoreAllowed) |
| 5243 m_restoreTimer.startOneShot(0); | 5265 m_restoreTimer.startOneShot(0); |
| 5244 } | 5266 } |
| 5245 | 5267 |
| 5246 void WebGLRenderingContext::maybeRestoreContext(Timer<WebGLRenderingContext>*) | 5268 void WebGLRenderingContext::maybeRestoreContext(Timer<WebGLRenderingContext>*) |
| 5247 { | 5269 { |
| 5248 ASSERT(isContextLost()); | 5270 ASSERT(isContextLost()); |
| 5249 | 5271 |
| 5250 // The rendering context is not restored unless the default behavior of the | 5272 // The rendering context is not restored unless the default behavior of the |
| 5251 // webglcontextlost event was prevented earlier. | 5273 // webglcontextlost event was prevented earlier. |
| 5252 // | 5274 // |
| 5253 // Because of the way m_restoreTimer is set up for real vs. synthetic lost | 5275 // Because of the way m_restoreTimer is set up for real vs. synthetic lost |
| 5254 // context events, we don't have to worry about this test short-circuiting | 5276 // context events, we don't have to worry about this test short-circuiting |
| 5255 // the retry loop for real context lost events. | 5277 // the retry loop for real context lost events. |
| 5256 if (!m_restoreAllowed) | 5278 if (!m_restoreAllowed) |
| 5257 return; | 5279 return; |
| 5258 | 5280 |
| 5259 Document* document = canvas()->document(); | 5281 Document* document = canvas()->document(); |
| 5260 if (!document) | 5282 if (!document) |
| 5261 return; | 5283 return; |
| 5262 Frame* frame = document->frame(); | 5284 Frame* frame = document->frame(); |
| 5263 if (!frame) | 5285 if (!frame) |
| 5264 return; | 5286 return; |
| 5265 | 5287 |
| 5266 if (!frame->loader()->client()->allowWebGL(frame->settings() && frame->setti ngs()->webGLEnabled())) | 5288 Settings* settings = frame->settings(); |
| 5289 | |
| 5290 if (!frame->loader()->client()->allowWebGL(settings && settings->webGLEnable d())) | |
| 5267 return; | 5291 return; |
| 5268 | 5292 |
| 5293 // Reset the context attributes back to the requested attributes and re-appl y restrictions | |
| 5294 m_attributes = adjustAttributes(m_requestedAttributes, settings); | |
| 5295 | |
| 5269 RefPtr<GraphicsContext3D> context(GraphicsContext3D::create(m_attributes)); | 5296 RefPtr<GraphicsContext3D> context(GraphicsContext3D::create(m_attributes)); |
| 5297 | |
| 5270 if (!context) { | 5298 if (!context) { |
| 5271 if (m_contextLostMode == RealLostContext) | 5299 if (m_contextLostMode == RealLostContext) |
| 5272 m_restoreTimer.startOneShot(secondsBetweenRestoreAttempts); | 5300 m_restoreTimer.startOneShot(secondsBetweenRestoreAttempts); |
| 5273 else | 5301 else |
| 5274 // This likely shouldn't happen but is the best way to report it to the WebGL app. | 5302 // This likely shouldn't happen but is the best way to report it to the WebGL app. |
| 5275 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "", "error r estoring context"); | 5303 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "", "error r estoring context"); |
| 5276 return; | 5304 return; |
| 5277 } | 5305 } |
| 5278 | 5306 |
| 5279 RefPtr<WebGLRenderingContextEvictionManager> contextEvictionManager = adoptR ef(new WebGLRenderingContextEvictionManager()); | 5307 RefPtr<WebGLRenderingContextEvictionManager> contextEvictionManager = adoptR ef(new WebGLRenderingContextEvictionManager()); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5449 ExceptionCode ec; | 5477 ExceptionCode ec; |
| 5450 bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_framebufferBinding.get(), ec); | 5478 bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_framebufferBinding.get(), ec); |
| 5451 } | 5479 } |
| 5452 | 5480 |
| 5453 void WebGLRenderingContext::restoreCurrentTexture2D() | 5481 void WebGLRenderingContext::restoreCurrentTexture2D() |
| 5454 { | 5482 { |
| 5455 ExceptionCode ec; | 5483 ExceptionCode ec; |
| 5456 bindTexture(GraphicsContext3D::TEXTURE_2D, m_textureUnits[m_activeTextureUni t].m_texture2DBinding.get(), ec); | 5484 bindTexture(GraphicsContext3D::TEXTURE_2D, m_textureUnits[m_activeTextureUni t].m_texture2DBinding.get(), ec); |
| 5457 } | 5485 } |
| 5458 | 5486 |
| 5487 void WebGLRenderingContext::multisamplingChanged(bool enabled) | |
| 5488 { | |
| 5489 if (m_multisamplingAllowed != enabled) { | |
| 5490 m_multisamplingAllowed = enabled; | |
| 5491 forceLostContext(WebGLRenderingContext::AutoRecoverSyntheticLostContext) ; | |
| 5492 } | |
| 5493 } | |
| 5494 | |
| 5459 } // namespace WebCore | 5495 } // namespace WebCore |
| OLD | NEW |