Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp

Issue 1881563003: Implement OffscreenCanvas.getContext('webgl') (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: almost identical as PS8 Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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> createWebGraphicsContext3DProvid erHelper(HTMLCanvasElement* canvas, WebGLContextAttributes attributes, unsigned webGLVersion)
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 ScriptState* scriptState = ScriptState::current(v8::Isolate::GetCurrent( ));
xlai (Olivia) 2016/04/27 15:11:27 I need to take back my previous comment. Today I j
516 contextProvider = adoptPtr(Platform::current()->createOffscreenGraphicsC ontext3DProvider(
517 contextAttributes, scriptState->getExecutionContext()->url(), 0, &gl Info));
xidachen 2016/04/26 13:47:29 kbr@, zmo@, bajones@: when calling createOffscreen
Ken Russell (switch to Gerrit) 2016/04/27 10:30:47 That's probably expected at this point. Look at ht
518 }
519 if (!contextProvider || shouldFailContextCreationForTesting) {
520 shouldFailContextCreationForTesting = false;
521 if (canvas)
522 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webg lcontextcreationerror, false, true, extractWebGLContextCreationError(glInfo)));
523 return nullptr;
524 }
525 gpu::gles2::GLES2Interface* gl = contextProvider->contextGL();
526 if (!String(gl->GetString(GL_EXTENSIONS)).contains("GL_OES_packed_depth_sten cil")) {
527 if (canvas)
528 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webg lcontextcreationerror, false, true, "OES_packed_depth_stencil support is require d."));
529 return nullptr;
530 }
531
532 return contextProvider.release();
533 }
534
506 PassOwnPtr<WebGraphicsContext3DProvider> WebGLRenderingContextBase::createWebGra phicsContext3DProvider(HTMLCanvasElement* canvas, WebGLContextAttributes attribu tes, unsigned webGLVersion) 535 PassOwnPtr<WebGraphicsContext3DProvider> WebGLRenderingContextBase::createWebGra phicsContext3DProvider(HTMLCanvasElement* canvas, WebGLContextAttributes attribu tes, unsigned webGLVersion)
507 { 536 {
508 Document& document = canvas->document(); 537 Document& document = canvas->document();
509 LocalFrame* frame = document.frame(); 538 LocalFrame* frame = document.frame();
510 if (!frame) { 539 if (!frame) {
511 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Web page was not allowed to create a WebGL cont ext.")); 540 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Web page was not allowed to create a WebGL cont ext."));
512 return nullptr; 541 return nullptr;
513 } 542 }
514 Settings* settings = frame->settings(); 543 Settings* settings = frame->settings();
515 544
516 // The FrameLoaderClient might block creation of a new WebGL context despite the page settings; in 545 // 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. 546 // 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 ())) { 547 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.")); 548 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Web page was not allowed to create a WebGL cont ext."));
520 return nullptr; 549 return nullptr;
521 } 550 }
522 551
523 Platform::ContextAttributes contextAttributes = toPlatformContextAttributes( attributes, webGLVersion); 552 return createWebGraphicsContext3DProviderHelper(canvas, attributes, webGLVer sion);
524 Platform::GraphicsInfo glInfo; 553 }
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 554
538 return contextProvider.release(); 555 PassOwnPtr<WebGraphicsContext3DProvider> WebGLRenderingContextBase::createWebGra phicsContext3DProvider(WebGLContextAttributes attributes, unsigned webGLVersion)
556 {
557 return createWebGraphicsContext3DProviderHelper(static_cast<HTMLCanvasElemen t*>(nullptr), attributes, webGLVersion);
539 } 558 }
540 559
541 void WebGLRenderingContextBase::forceNextWebGLContextCreationToFail() 560 void WebGLRenderingContextBase::forceNextWebGLContextCreationToFail()
542 { 561 {
543 shouldFailContextCreationForTesting = true; 562 shouldFailContextCreationForTesting = true;
544 } 563 }
545 564
546 namespace { 565 namespace {
547 566
548 // ES2 enums 567 // ES2 enums
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 case GL_SRGB8: 792 case GL_SRGB8:
774 case GL_SRGB8_ALPHA8: 793 case GL_SRGB8_ALPHA8:
775 return true; 794 return true;
776 default: 795 default:
777 return false; 796 return false;
778 } 797 }
779 } 798 }
780 799
781 } // namespace 800 } // namespace
782 801
802 WebGLRenderingContextBase::WebGLRenderingContextBase(OffscreenCanvas* passedOffs creenCanvas, PassOwnPtr<WebGraphicsContext3DProvider> contextProvider, const Web GLContextAttributes& requestedAttributes)
803 : WebGLRenderingContextBase(static_cast<HTMLCanvasElement*>(nullptr), passed OffscreenCanvas, contextProvider, requestedAttributes)
804 { }
805
783 WebGLRenderingContextBase::WebGLRenderingContextBase(HTMLCanvasElement* passedCa nvas, PassOwnPtr<WebGraphicsContext3DProvider> contextProvider, const WebGLConte xtAttributes& requestedAttributes) 806 WebGLRenderingContextBase::WebGLRenderingContextBase(HTMLCanvasElement* passedCa nvas, PassOwnPtr<WebGraphicsContext3DProvider> contextProvider, const WebGLConte xtAttributes& requestedAttributes)
784 : CanvasRenderingContext(passedCanvas) 807 : WebGLRenderingContextBase(passedCanvas, static_cast<OffscreenCanvas*>(null ptr), contextProvider, requestedAttributes)
808 { }
809
810 WebGLRenderingContextBase::WebGLRenderingContextBase(HTMLCanvasElement* passedCa nvas, OffscreenCanvas* passedOffscreenCanvas, PassOwnPtr<WebGraphicsContext3DPro vider> contextProvider, const WebGLContextAttributes& requestedAttributes)
811 : CanvasRenderingContext(passedCanvas, passedOffscreenCanvas)
785 , m_isHidden(false) 812 , m_isHidden(false)
786 , m_contextLostMode(NotLostContext) 813 , m_contextLostMode(NotLostContext)
787 , m_autoRecoveryMethod(Manual) 814 , m_autoRecoveryMethod(Manual)
788 , m_dispatchContextLostEventTimer(this, &WebGLRenderingContextBase::dispatch ContextLostEvent) 815 , m_dispatchContextLostEventTimer(this, &WebGLRenderingContextBase::dispatch ContextLostEvent)
789 , m_restoreAllowed(false) 816 , m_restoreAllowed(false)
790 , m_restoreTimer(this, &WebGLRenderingContextBase::maybeRestoreContext) 817 , m_restoreTimer(this, &WebGLRenderingContextBase::maybeRestoreContext)
791 , m_preservedDefaultVAOObjectWrapper(false) 818 , m_preservedDefaultVAOObjectWrapper(false)
792 , m_generatedImageCache(4) 819 , m_generatedImageCache(4)
793 , m_requestedAttributes(requestedAttributes) 820 , m_requestedAttributes(requestedAttributes)
794 , m_synthesizedErrorsToConsole(true) 821 , m_synthesizedErrorsToConsole(true)
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 ADD_VALUES_TO_SET(m_supportedFormats, kSupportedFormatsES2); 996 ADD_VALUES_TO_SET(m_supportedFormats, kSupportedFormatsES2);
970 m_supportedTypes.clear(); 997 m_supportedTypes.clear();
971 ADD_VALUES_TO_SET(m_supportedTypes, kSupportedTypesES2); 998 ADD_VALUES_TO_SET(m_supportedTypes, kSupportedTypesES2);
972 999
973 activateContext(this); 1000 activateContext(this);
974 } 1001 }
975 1002
976 void WebGLRenderingContextBase::setupFlags() 1003 void WebGLRenderingContextBase::setupFlags()
977 { 1004 {
978 ASSERT(drawingBuffer()); 1005 ASSERT(drawingBuffer());
979 if (Page* p = canvas()->document().page()) { 1006 if (canvas()) {
980 m_synthesizedErrorsToConsole = p->settings().webGLErrorsToConsoleEnabled (); 1007 if (Page* p = canvas()->document().page()) {
1008 m_synthesizedErrorsToConsole = p->settings().webGLErrorsToConsoleEna bled();
1009 }
981 } 1010 }
982 1011
983 m_isDepthStencilSupported = extensionsUtil()->isExtensionEnabled("GL_OES_pac ked_depth_stencil"); 1012 m_isDepthStencilSupported = extensionsUtil()->isExtensionEnabled("GL_OES_pac ked_depth_stencil");
984 } 1013 }
985 1014
986 void WebGLRenderingContextBase::addCompressedTextureFormat(GLenum format) 1015 void WebGLRenderingContextBase::addCompressedTextureFormat(GLenum format)
987 { 1016 {
988 if (!m_compressedTextureFormats.contains(format)) 1017 if (!m_compressedTextureFormats.contains(format))
989 m_compressedTextureFormats.append(format); 1018 m_compressedTextureFormats.append(format);
990 } 1019 }
(...skipping 5046 matching lines...) Expand 10 before | Expand all | Expand 10 after
6037 if (isContextLost()) 6066 if (isContextLost())
6038 return; 6067 return;
6039 if (enable) 6068 if (enable)
6040 contextGL()->Enable(capability); 6069 contextGL()->Enable(capability);
6041 else 6070 else
6042 contextGL()->Disable(capability); 6071 contextGL()->Disable(capability);
6043 } 6072 }
6044 6073
6045 IntSize WebGLRenderingContextBase::clampedCanvasSize() 6074 IntSize WebGLRenderingContextBase::clampedCanvasSize()
6046 { 6075 {
6047 return IntSize(clamp(canvas()->width(), 1, m_maxViewportDims[0]), 6076 int width, height;
6048 clamp(canvas()->height(), 1, m_maxViewportDims[1])); 6077 if (canvas()) {
6078 width = canvas()->width();
6079 height = canvas()->height();
6080 } else {
6081 width = getOffscreenCanvas()->width();
6082 height = getOffscreenCanvas()->height();
6083 }
6084 return IntSize(clamp(width, 1, m_maxViewportDims[0]),
6085 clamp(height, 1, m_maxViewportDims[1]));
6049 } 6086 }
6050 6087
6051 GLint WebGLRenderingContextBase::maxDrawBuffers() 6088 GLint WebGLRenderingContextBase::maxDrawBuffers()
6052 { 6089 {
6053 if (isContextLost() || !(extensionEnabled(WebGLDrawBuffersName) || isWebGL2O rHigher())) 6090 if (isContextLost() || !(extensionEnabled(WebGLDrawBuffersName) || isWebGL2O rHigher()))
6054 return 0; 6091 return 0;
6055 if (!m_maxDrawBuffers) 6092 if (!m_maxDrawBuffers)
6056 contextGL()->GetIntegerv(GL_MAX_DRAW_BUFFERS_EXT, &m_maxDrawBuffers); 6093 contextGL()->GetIntegerv(GL_MAX_DRAW_BUFFERS_EXT, &m_maxDrawBuffers);
6057 if (!m_maxColorAttachments) 6094 if (!m_maxColorAttachments)
6058 contextGL()->GetIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &m_maxColorAttach ments); 6095 contextGL()->GetIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &m_maxColorAttach ments);
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
6222 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1); 6259 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1);
6223 } 6260 }
6224 6261
6225 void WebGLRenderingContextBase::restoreUnpackParameters() 6262 void WebGLRenderingContextBase::restoreUnpackParameters()
6226 { 6263 {
6227 if (m_unpackAlignment != 1) 6264 if (m_unpackAlignment != 1)
6228 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); 6265 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
6229 } 6266 }
6230 6267
6231 } // namespace blink 6268 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698