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 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 m_context->printGLErrorToConsole(message); | 487 m_context->printGLErrorToConsole(message); |
488 InspectorInstrumentation::didFireWebGLErrorOrWarning(m_context->canvas()
, message); | 488 InspectorInstrumentation::didFireWebGLErrorOrWarning(m_context->canvas()
, message); |
489 } | 489 } |
490 virtual ~WebGLRenderingContextErrorMessageCallback() { } | 490 virtual ~WebGLRenderingContextErrorMessageCallback() { } |
491 private: | 491 private: |
492 WebGLRenderingContext* m_context; | 492 WebGLRenderingContext* m_context; |
493 }; | 493 }; |
494 | 494 |
495 PassOwnPtr<WebGLRenderingContext> WebGLRenderingContext::create(HTMLCanvasElemen
t* canvas, WebGLContextAttributes* attrs) | 495 PassOwnPtr<WebGLRenderingContext> WebGLRenderingContext::create(HTMLCanvasElemen
t* canvas, WebGLContextAttributes* attrs) |
496 { | 496 { |
497 Document* document = canvas->document(); | 497 Document& document = canvas->document(); |
498 Frame* frame = document->frame(); | 498 Frame* frame = document.frame(); |
499 if (!frame) | 499 if (!frame) |
500 return nullptr; | 500 return nullptr; |
501 Settings* settings = frame->settings(); | 501 Settings* settings = frame->settings(); |
502 | 502 |
503 // The FrameLoaderClient might block creation of a new WebGL context despite
the page settings; in | 503 // The FrameLoaderClient might block creation of a new WebGL context despite
the page settings; in |
504 // particular, if WebGL contexts were lost one or more times via the GL_ARB_
robustness extension. | 504 // particular, if WebGL contexts were lost one or more times via the GL_ARB_
robustness extension. |
505 if (!frame->loader()->client()->allowWebGL(settings && settings->webGLEnable
d())) { | 505 if (!frame->loader()->client()->allowWebGL(settings && settings->webGLEnable
d())) { |
506 canvas->dispatchEvent(WebGLContextEvent::create(eventNames().webglcontex
tcreationerrorEvent, false, true, "Web page was not allowed to create a WebGL co
ntext.")); | 506 canvas->dispatchEvent(WebGLContextEvent::create(eventNames().webglcontex
tcreationerrorEvent, false, true, "Web page was not allowed to create a WebGL co
ntext.")); |
507 return nullptr; | 507 return nullptr; |
508 } | 508 } |
509 | 509 |
510 GraphicsContext3D::Attributes requestedAttributes = attrs ? attrs->attribute
s() : GraphicsContext3D::Attributes(); | 510 GraphicsContext3D::Attributes requestedAttributes = attrs ? attrs->attribute
s() : GraphicsContext3D::Attributes(); |
511 requestedAttributes.noExtensions = true; | 511 requestedAttributes.noExtensions = true; |
512 requestedAttributes.shareResources = true; | 512 requestedAttributes.shareResources = true; |
513 requestedAttributes.preferDiscreteGPU = true; | 513 requestedAttributes.preferDiscreteGPU = true; |
514 requestedAttributes.topDocumentURL = document->topDocument()->url(); | 514 requestedAttributes.topDocumentURL = document.topDocument()->url(); |
515 | 515 |
516 GraphicsContext3D::Attributes attributes = adjustAttributes(requestedAttribu
tes, settings); | 516 GraphicsContext3D::Attributes attributes = adjustAttributes(requestedAttribu
tes, settings); |
517 | 517 |
518 RefPtr<GraphicsContext3D> context(GraphicsContext3D::create(attributes)); | 518 RefPtr<GraphicsContext3D> context(GraphicsContext3D::create(attributes)); |
519 | 519 |
520 if (!context || !context->makeContextCurrent()) { | 520 if (!context || !context->makeContextCurrent()) { |
521 canvas->dispatchEvent(WebGLContextEvent::create(eventNames().webglcontex
tcreationerrorEvent, false, true, "Could not create a WebGL context.")); | 521 canvas->dispatchEvent(WebGLContextEvent::create(eventNames().webglcontex
tcreationerrorEvent, false, true, "Could not create a WebGL context.")); |
522 return nullptr; | 522 return nullptr; |
523 } | 523 } |
524 | 524 |
525 Extensions3D* extensions = context->getExtensions(); | 525 Extensions3D* extensions = context->getExtensions(); |
526 if (extensions->supports("GL_EXT_debug_marker")) | 526 if (extensions->supports("GL_EXT_debug_marker")) |
527 extensions->pushGroupMarkerEXT("WebGLRenderingContext"); | 527 extensions->pushGroupMarkerEXT("WebGLRenderingContext"); |
528 | 528 |
529 OwnPtr<WebGLRenderingContext> renderingContext = adoptPtr(new WebGLRendering
Context(canvas, context, attributes, requestedAttributes)); | 529 OwnPtr<WebGLRenderingContext> renderingContext = adoptPtr(new WebGLRendering
Context(canvas, context, attributes, requestedAttributes)); |
530 renderingContext->suspendIfNeeded(); | 530 renderingContext->suspendIfNeeded(); |
531 | 531 |
532 if (renderingContext->m_drawingBuffer->isZeroSized()) { | 532 if (renderingContext->m_drawingBuffer->isZeroSized()) { |
533 canvas->dispatchEvent(WebGLContextEvent::create(eventNames().webglcontex
tcreationerrorEvent, false, true, "Could not create a WebGL context.")); | 533 canvas->dispatchEvent(WebGLContextEvent::create(eventNames().webglcontex
tcreationerrorEvent, false, true, "Could not create a WebGL context.")); |
534 return nullptr; | 534 return nullptr; |
535 } | 535 } |
536 | 536 |
537 return renderingContext.release(); | 537 return renderingContext.release(); |
538 } | 538 } |
539 | 539 |
540 WebGLRenderingContext::WebGLRenderingContext(HTMLCanvasElement* passedCanvas, Pa
ssRefPtr<GraphicsContext3D> context, GraphicsContext3D::Attributes attributes, G
raphicsContext3D::Attributes requestedAttributes) | 540 WebGLRenderingContext::WebGLRenderingContext(HTMLCanvasElement* passedCanvas, Pa
ssRefPtr<GraphicsContext3D> context, GraphicsContext3D::Attributes attributes, G
raphicsContext3D::Attributes requestedAttributes) |
541 : CanvasRenderingContext(passedCanvas) | 541 : CanvasRenderingContext(passedCanvas) |
542 , ActiveDOMObject(passedCanvas->document()) | 542 , ActiveDOMObject(&passedCanvas->document()) |
543 , m_context(context) | 543 , m_context(context) |
544 , m_drawingBuffer(0) | 544 , m_drawingBuffer(0) |
545 , m_dispatchContextLostEventTimer(this, &WebGLRenderingContext::dispatchCont
extLostEvent) | 545 , m_dispatchContextLostEventTimer(this, &WebGLRenderingContext::dispatchCont
extLostEvent) |
546 , m_restoreAllowed(false) | 546 , m_restoreAllowed(false) |
547 , m_restoreTimer(this, &WebGLRenderingContext::maybeRestoreContext) | 547 , m_restoreTimer(this, &WebGLRenderingContext::maybeRestoreContext) |
548 , m_videoCache(4) | 548 , m_videoCache(4) |
549 , m_contextLost(false) | 549 , m_contextLost(false) |
550 , m_contextLostMode(SyntheticLostContext) | 550 , m_contextLostMode(SyntheticLostContext) |
551 , m_attributes(attributes) | 551 , m_attributes(attributes) |
552 , m_requestedAttributes(requestedAttributes) | 552 , m_requestedAttributes(requestedAttributes) |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 | 678 |
679 m_context->setContextLostCallback(adoptPtr(new WebGLRenderingContextLostCall
back(this))); | 679 m_context->setContextLostCallback(adoptPtr(new WebGLRenderingContextLostCall
back(this))); |
680 m_context->setErrorMessageCallback(adoptPtr(new WebGLRenderingContextErrorMe
ssageCallback(this))); | 680 m_context->setErrorMessageCallback(adoptPtr(new WebGLRenderingContextErrorMe
ssageCallback(this))); |
681 | 681 |
682 activateContext(this); | 682 activateContext(this); |
683 } | 683 } |
684 | 684 |
685 void WebGLRenderingContext::setupFlags() | 685 void WebGLRenderingContext::setupFlags() |
686 { | 686 { |
687 ASSERT(m_context); | 687 ASSERT(m_context); |
688 if (Page* p = canvas()->document()->page()) { | 688 if (Page* p = canvas()->document().page()) { |
689 m_synthesizedErrorsToConsole = p->settings().webGLErrorsToConsoleEnabled
(); | 689 m_synthesizedErrorsToConsole = p->settings().webGLErrorsToConsoleEnabled
(); |
690 | 690 |
691 if (!m_multisamplingObserverRegistered && m_requestedAttributes.antialia
s) { | 691 if (!m_multisamplingObserverRegistered && m_requestedAttributes.antialia
s) { |
692 m_multisamplingAllowed = m_drawingBuffer->multisample(); | 692 m_multisamplingAllowed = m_drawingBuffer->multisample(); |
693 p->addMultisamplingChangedObserver(this); | 693 p->addMultisamplingChangedObserver(this); |
694 m_multisamplingObserverRegistered = true; | 694 m_multisamplingObserverRegistered = true; |
695 } | 695 } |
696 } | 696 } |
697 | 697 |
698 m_isGLES2NPOTStrict = !m_context->getExtensions()->isEnabled("GL_OES_texture
_npot"); | 698 m_isGLES2NPOTStrict = !m_context->getExtensions()->isEnabled("GL_OES_texture
_npot"); |
699 m_isDepthStencilSupported = m_context->getExtensions()->isEnabled("GL_OES_pa
cked_depth_stencil"); | 699 m_isDepthStencilSupported = m_context->getExtensions()->isEnabled("GL_OES_pa
cked_depth_stencil"); |
700 } | 700 } |
701 | 701 |
702 bool WebGLRenderingContext::allowPrivilegedExtensions() const | 702 bool WebGLRenderingContext::allowPrivilegedExtensions() const |
703 { | 703 { |
704 if (Page* p = canvas()->document()->page()) | 704 if (Page* p = canvas()->document().page()) |
705 return p->settings().privilegedWebGLExtensionsEnabled(); | 705 return p->settings().privilegedWebGLExtensionsEnabled(); |
706 return false; | 706 return false; |
707 } | 707 } |
708 | 708 |
709 void WebGLRenderingContext::addCompressedTextureFormat(GC3Denum format) | 709 void WebGLRenderingContext::addCompressedTextureFormat(GC3Denum format) |
710 { | 710 { |
711 if (!m_compressedTextureFormats.contains(format)) | 711 if (!m_compressedTextureFormats.contains(format)) |
712 m_compressedTextureFormats.append(format); | 712 m_compressedTextureFormats.append(format); |
713 } | 713 } |
714 | 714 |
(...skipping 28 matching lines...) Expand all Loading... |
743 for (size_t i = 0; i < m_extensions.size(); ++i) | 743 for (size_t i = 0; i < m_extensions.size(); ++i) |
744 delete m_extensions[i]; | 744 delete m_extensions[i]; |
745 | 745 |
746 // Context must be removed from the group prior to the destruction of the | 746 // Context must be removed from the group prior to the destruction of the |
747 // GraphicsContext3D, otherwise shared objects may not be properly deleted. | 747 // GraphicsContext3D, otherwise shared objects may not be properly deleted. |
748 m_contextGroup->removeContext(this); | 748 m_contextGroup->removeContext(this); |
749 | 749 |
750 destroyGraphicsContext3D(); | 750 destroyGraphicsContext3D(); |
751 | 751 |
752 if (m_multisamplingObserverRegistered) { | 752 if (m_multisamplingObserverRegistered) { |
753 Page* page = canvas()->document()->page(); | 753 Page* page = canvas()->document().page(); |
754 if (page) | 754 if (page) |
755 page->removeMultisamplingChangedObserver(this); | 755 page->removeMultisamplingChangedObserver(this); |
756 } | 756 } |
757 | 757 |
758 willDestroyContext(this); | 758 willDestroyContext(this); |
759 } | 759 } |
760 | 760 |
761 void WebGLRenderingContext::destroyGraphicsContext3D() | 761 void WebGLRenderingContext::destroyGraphicsContext3D() |
762 { | 762 { |
763 m_contextLost = true; | 763 m_contextLost = true; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 m_context->markLayerComposited(); | 868 m_context->markLayerComposited(); |
869 } | 869 } |
870 | 870 |
871 void WebGLRenderingContext::paintRenderingResultsToCanvas() | 871 void WebGLRenderingContext::paintRenderingResultsToCanvas() |
872 { | 872 { |
873 if (isContextLost()) { | 873 if (isContextLost()) { |
874 canvas()->clearPresentationCopy(); | 874 canvas()->clearPresentationCopy(); |
875 return; | 875 return; |
876 } | 876 } |
877 | 877 |
878 if (canvas()->document()->printing()) | 878 if (canvas()->document().printing()) |
879 canvas()->clearPresentationCopy(); | 879 canvas()->clearPresentationCopy(); |
880 | 880 |
881 // Until the canvas is written to by the application, the clear that | 881 // Until the canvas is written to by the application, the clear that |
882 // happened after it was composited should be ignored by the compositor. | 882 // happened after it was composited should be ignored by the compositor. |
883 if (m_context->layerComposited() && !m_attributes.preserveDrawingBuffer) { | 883 if (m_context->layerComposited() && !m_attributes.preserveDrawingBuffer) { |
884 m_drawingBuffer->paintCompositedResultsToCanvas(canvas()->buffer()); | 884 m_drawingBuffer->paintCompositedResultsToCanvas(canvas()->buffer()); |
885 | 885 |
886 canvas()->makePresentationCopy(); | 886 canvas()->makePresentationCopy(); |
887 } else | 887 } else |
888 canvas()->clearPresentationCopy(); | 888 canvas()->clearPresentationCopy(); |
(...skipping 3214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4103 { | 4103 { |
4104 if (isContextLost()) | 4104 if (isContextLost()) |
4105 return; | 4105 return; |
4106 | 4106 |
4107 m_contextLost = true; | 4107 m_contextLost = true; |
4108 m_contextLostMode = mode; | 4108 m_contextLostMode = mode; |
4109 | 4109 |
4110 if (mode == RealLostContext) { | 4110 if (mode == RealLostContext) { |
4111 // Inform the embedder that a lost context was received. In response, th
e embedder might | 4111 // Inform the embedder that a lost context was received. In response, th
e embedder might |
4112 // decide to take action such as asking the user for permission to use W
ebGL again. | 4112 // decide to take action such as asking the user for permission to use W
ebGL again. |
4113 if (Document* document = canvas()->document()) { | 4113 if (Frame* frame = canvas()->document().frame()) |
4114 if (Frame* frame = document->frame()) | 4114 frame->loader()->client()->didLoseWebGLContext(m_context->getExtensi
ons()->getGraphicsResetStatusARB()); |
4115 frame->loader()->client()->didLoseWebGLContext(m_context->getExt
ensions()->getGraphicsResetStatusARB()); | |
4116 } | |
4117 } | 4115 } |
4118 | 4116 |
4119 // Make absolutely sure we do not refer to an already-deleted texture or fra
mebuffer. | 4117 // Make absolutely sure we do not refer to an already-deleted texture or fra
mebuffer. |
4120 m_drawingBuffer->setTexture2DBinding(0); | 4118 m_drawingBuffer->setTexture2DBinding(0); |
4121 m_drawingBuffer->setFramebufferBinding(0); | 4119 m_drawingBuffer->setFramebufferBinding(0); |
4122 | 4120 |
4123 detachAndRemoveAllObjects(); | 4121 detachAndRemoveAllObjects(); |
4124 | 4122 |
4125 // Lose all the extensions. | 4123 // Lose all the extensions. |
4126 for (size_t i = 0; i < m_extensions.size(); ++i) { | 4124 for (size_t i = 0; i < m_extensions.size(); ++i) { |
(...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4932 if (!m_numGLErrorsToConsoleAllowed) | 4930 if (!m_numGLErrorsToConsoleAllowed) |
4933 printWarningToConsole("WebGL: too many errors, no more errors will be re
ported to the console for this context."); | 4931 printWarningToConsole("WebGL: too many errors, no more errors will be re
ported to the console for this context."); |
4934 | 4932 |
4935 return; | 4933 return; |
4936 } | 4934 } |
4937 | 4935 |
4938 void WebGLRenderingContext::printWarningToConsole(const String& message) | 4936 void WebGLRenderingContext::printWarningToConsole(const String& message) |
4939 { | 4937 { |
4940 if (!canvas()) | 4938 if (!canvas()) |
4941 return; | 4939 return; |
4942 Document* document = canvas()->document(); | 4940 canvas()->document().addConsoleMessage(RenderingMessageSource, WarningMessag
eLevel, message); |
4943 if (!document) | |
4944 return; | |
4945 document->addConsoleMessage(RenderingMessageSource, WarningMessageLevel, mes
sage); | |
4946 } | 4941 } |
4947 | 4942 |
4948 bool WebGLRenderingContext::validateFramebufferFuncParameters(const char* functi
onName, GC3Denum target, GC3Denum attachment) | 4943 bool WebGLRenderingContext::validateFramebufferFuncParameters(const char* functi
onName, GC3Denum target, GC3Denum attachment) |
4949 { | 4944 { |
4950 if (target != GraphicsContext3D::FRAMEBUFFER) { | 4945 if (target != GraphicsContext3D::FRAMEBUFFER) { |
4951 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, "invali
d target"); | 4946 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, "invali
d target"); |
4952 return false; | 4947 return false; |
4953 } | 4948 } |
4954 switch (attachment) { | 4949 switch (attachment) { |
4955 case GraphicsContext3D::COLOR_ATTACHMENT0: | 4950 case GraphicsContext3D::COLOR_ATTACHMENT0: |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5335 | 5330 |
5336 // The rendering context is not restored unless the default behavior of the | 5331 // The rendering context is not restored unless the default behavior of the |
5337 // webglcontextlost event was prevented earlier. | 5332 // webglcontextlost event was prevented earlier. |
5338 // | 5333 // |
5339 // Because of the way m_restoreTimer is set up for real vs. synthetic lost | 5334 // Because of the way m_restoreTimer is set up for real vs. synthetic lost |
5340 // context events, we don't have to worry about this test short-circuiting | 5335 // context events, we don't have to worry about this test short-circuiting |
5341 // the retry loop for real context lost events. | 5336 // the retry loop for real context lost events. |
5342 if (!m_restoreAllowed) | 5337 if (!m_restoreAllowed) |
5343 return; | 5338 return; |
5344 | 5339 |
5345 Document* document = canvas()->document(); | 5340 Frame* frame = canvas()->document().frame(); |
5346 if (!document) | |
5347 return; | |
5348 Frame* frame = document->frame(); | |
5349 if (!frame) | 5341 if (!frame) |
5350 return; | 5342 return; |
5351 | 5343 |
5352 Settings* settings = frame->settings(); | 5344 Settings* settings = frame->settings(); |
5353 | 5345 |
5354 if (!frame->loader()->client()->allowWebGL(settings && settings->webGLEnable
d())) | 5346 if (!frame->loader()->client()->allowWebGL(settings && settings->webGLEnable
d())) |
5355 return; | 5347 return; |
5356 | 5348 |
5357 // Reset the context attributes back to the requested attributes and re-appl
y restrictions | 5349 // Reset the context attributes back to the requested attributes and re-appl
y restrictions |
5358 m_attributes = adjustAttributes(m_requestedAttributes, settings); | 5350 m_attributes = adjustAttributes(m_requestedAttributes, settings); |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5577 if (m_textureUnits[i].m_texture2DBinding | 5569 if (m_textureUnits[i].m_texture2DBinding |
5578 || m_textureUnits[i].m_textureCubeMapBinding) { | 5570 || m_textureUnits[i].m_textureCubeMapBinding) { |
5579 m_onePlusMaxNonDefaultTextureUnit = i + 1; | 5571 m_onePlusMaxNonDefaultTextureUnit = i + 1; |
5580 return; | 5572 return; |
5581 } | 5573 } |
5582 } | 5574 } |
5583 m_onePlusMaxNonDefaultTextureUnit = 0; | 5575 m_onePlusMaxNonDefaultTextureUnit = 0; |
5584 } | 5576 } |
5585 | 5577 |
5586 } // namespace WebCore | 5578 } // namespace WebCore |
OLD | NEW |