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

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

Issue 1384233003: Improve usefulness of webglcontextcreationerror statusMessage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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
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 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 visitor->trace(m_context); 519 visitor->trace(m_context);
520 } 520 }
521 521
522 private: 522 private:
523 explicit WebGLRenderingContextErrorMessageCallback(WebGLRenderingContextBase * context) 523 explicit WebGLRenderingContextErrorMessageCallback(WebGLRenderingContextBase * context)
524 : m_context(context) { } 524 : m_context(context) { }
525 525
526 RawPtrWillBeMember<WebGLRenderingContextBase> m_context; 526 RawPtrWillBeMember<WebGLRenderingContextBase> m_context;
527 }; 527 };
528 528
529 static void formatWebGLStatusString(const String& glInfo, const String& infostri ng, String& statusMessage)
530 {
531 if (!infostring.isEmpty())
532 statusMessage.append(", " + glInfo + " = " + infostring);
533 }
534
535 static String extractWebGLContextCreationError(const WebGraphicsContext3D::WebGr aphicsInfo& info)
536 {
537 String statusMessage("Could not create a WebGL context");
538 if (info.vendorId)
539 formatWebGLStatusString("VENDOR", String::format("0x%04x", info.vendorId ).utf8().data(), statusMessage);
540 if (info.deviceId)
541 formatWebGLStatusString("DEVICE", String::format("0x%04x", info.deviceId ).utf8().data(), statusMessage);
542 formatWebGLStatusString("GL_VENDOR", info.vendorInfo.utf8().data(), statusMe ssage);
543 formatWebGLStatusString("GL_RENDERER", info.rendererInfo.utf8().data(), stat usMessage);
544 formatWebGLStatusString("GL_VERSION", info.driverVersion.utf8().data(), stat usMessage);
545 formatWebGLStatusString("Sandboxed", info.sandboxed ? "yes" : "no", statusMe ssage);
546 formatWebGLStatusString("Optimus", info.optimus ? "yes" : "no", statusMessag e);
547 formatWebGLStatusString("AMD switchable", info.amdSwitchable ? "yes" : "no", statusMessage);
548 formatWebGLStatusString("Reset notification strategy", String::format("0x%04 x", info.resetNotificationStrategy).utf8().data(), statusMessage);
549 formatWebGLStatusString("GPU process crash count", String::number(info.proce ssCrashCount).utf8().data(), statusMessage);
550 formatWebGLStatusString("ErrorMessage", info.errorMessage.utf8().data(), sta tusMessage);
551 statusMessage.append(".");
552 return statusMessage;
553 }
554
529 PassOwnPtr<WebGraphicsContext3D> WebGLRenderingContextBase::createWebGraphicsCon text3D(HTMLCanvasElement* canvas, WebGLContextAttributes attributes, unsigned we bGLVersion) 555 PassOwnPtr<WebGraphicsContext3D> WebGLRenderingContextBase::createWebGraphicsCon text3D(HTMLCanvasElement* canvas, WebGLContextAttributes attributes, unsigned we bGLVersion)
530 { 556 {
531 Document& document = canvas->document(); 557 Document& document = canvas->document();
532 LocalFrame* frame = document.frame(); 558 LocalFrame* frame = document.frame();
533 if (!frame) { 559 if (!frame) {
534 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Web page was not allowed to create a WebGL cont ext.")); 560 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Web page was not allowed to create a WebGL cont ext."));
535 return nullptr; 561 return nullptr;
536 } 562 }
537 Settings* settings = frame->settings(); 563 Settings* settings = frame->settings();
538 564
539 // The FrameLoaderClient might block creation of a new WebGL context despite the page settings; in 565 // The FrameLoaderClient might block creation of a new WebGL context despite the page settings; in
540 // particular, if WebGL contexts were lost one or more times via the GL_ARB_ robustness extension. 566 // particular, if WebGL contexts were lost one or more times via the GL_ARB_ robustness extension.
541 if (!frame->loader().client()->allowWebGL(settings && settings->webGLEnabled ())) { 567 if (!frame->loader().client()->allowWebGL(settings && settings->webGLEnabled ())) {
542 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Web page was not allowed to create a WebGL cont ext.")); 568 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Web page was not allowed to create a WebGL cont ext."));
543 return nullptr; 569 return nullptr;
544 } 570 }
545 571
546 WebGraphicsContext3D::Attributes wgc3dAttributes = toWebGraphicsContext3DAtt ributes(attributes, document.topDocument().url().string(), settings, webGLVersio n); 572 WebGraphicsContext3D::Attributes wgc3dAttributes = toWebGraphicsContext3DAtt ributes(attributes, document.topDocument().url().string(), settings, webGLVersio n);
547 WebGLInfo glInfo; 573 WebGraphicsContext3D::WebGraphicsInfo glInfo;
548 OwnPtr<WebGraphicsContext3D> context = adoptPtr(Platform::current()->createO ffscreenGraphicsContext3D(wgc3dAttributes, 0, &glInfo)); 574 glInfo.testFailContext = shouldFailContextCreationForTesting;
575 OwnPtr<WebGraphicsContext3D> context = adoptPtr(Platform::current()->createO ffscreenGraphicsContext3D(wgc3dAttributes, 0, glInfo));
549 if (!context || shouldFailContextCreationForTesting) { 576 if (!context || shouldFailContextCreationForTesting) {
550 shouldFailContextCreationForTesting = false; 577 shouldFailContextCreationForTesting = false;
551 String statusMessage; 578 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, extractWebGLContextCreationError(glInfo)));
552 if (!glInfo.contextInfoCollectionFailure.isEmpty()) {
553 statusMessage.append("Could not create a WebGL context. ");
554 statusMessage.append(glInfo.contextInfoCollectionFailure);
555 String vendorId = String::number(glInfo.vendorId);
556 String deviceId = String::number(glInfo.deviceId);
557 if (vendorId.isEmpty())
558 statusMessage.append("VendorId = Not Available");
559 else
560 statusMessage.append("VendorId = " + vendorId);
561 if (deviceId.isEmpty())
562 statusMessage.append(", DeviceId = Not Available");
563 else
564 statusMessage.append(", DeviceId = " + deviceId);
565 } else {
566 statusMessage.append("Could not create a WebGL context");
567 if (!glInfo.vendorInfo.isEmpty()) {
568 statusMessage.append(", VendorInfo = ");
569 statusMessage.append(glInfo.vendorInfo);
570 } else {
571 statusMessage.append(", VendorInfo = Not Available");
572 }
573 if (!glInfo.rendererInfo.isEmpty()) {
574 statusMessage.append(", RendererInfo = ");
575 statusMessage.append(glInfo.rendererInfo);
576 } else {
577 statusMessage.append(", RendererInfo = Not Available");
578 }
579 if (!glInfo.driverVersion.isEmpty()) {
580 statusMessage.append(", DriverInfo = ");
581 statusMessage.append(glInfo.driverVersion);
582 } else {
583 statusMessage.append(", DriverInfo = Not Available");
584 }
585 statusMessage.append(".");
586 }
587 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, statusMessage));
588 return nullptr; 579 return nullptr;
589 } 580 }
590 581
591 return context.release(); 582 return context.release();
592 } 583 }
593 584
594 void WebGLRenderingContextBase::forceNextWebGLContextCreationToFail() 585 void WebGLRenderingContextBase::forceNextWebGLContextCreationToFail()
595 { 586 {
596 shouldFailContextCreationForTesting = true; 587 shouldFailContextCreationForTesting = true;
597 } 588 }
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
897 RefPtr<DrawingBuffer> buffer = createDrawingBuffer(context); 888 RefPtr<DrawingBuffer> buffer = createDrawingBuffer(context);
898 if (!buffer) { 889 if (!buffer) {
899 m_contextLostMode = SyntheticLostContext; 890 m_contextLostMode = SyntheticLostContext;
900 return; 891 return;
901 } 892 }
902 893
903 m_drawingBuffer = buffer.release(); 894 m_drawingBuffer = buffer.release();
904 895
905 drawingBuffer()->bind(GL_FRAMEBUFFER); 896 drawingBuffer()->bind(GL_FRAMEBUFFER);
906 setupFlags(); 897 setupFlags();
907 898
908 #define ADD_VALUES_TO_SET(set, values) \ 899 #define ADD_VALUES_TO_SET(set, values) \
909 for (size_t i = 0; i < arraysize(values); ++i) { \ 900 for (size_t i = 0; i < arraysize(values); ++i) { \
910 set.insert(values[i]); \ 901 set.insert(values[i]); \
911 } 902 }
912 903
913 ADD_VALUES_TO_SET(m_supportedInternalFormats, kSupportedInternalFormatsES2); 904 ADD_VALUES_TO_SET(m_supportedInternalFormats, kSupportedInternalFormatsES2);
914 ADD_VALUES_TO_SET(m_supportedFormats, kSupportedFormatsES2); 905 ADD_VALUES_TO_SET(m_supportedFormats, kSupportedFormatsES2);
915 ADD_VALUES_TO_SET(m_supportedTypes, kSupportedTypesES2); 906 ADD_VALUES_TO_SET(m_supportedTypes, kSupportedTypesES2);
916 ADD_VALUES_TO_SET(m_supportedFormatTypeCombinations, kSupportedFormatTypesES 2); 907 ADD_VALUES_TO_SET(m_supportedFormatTypeCombinations, kSupportedFormatTypesES 2);
917 } 908 }
(...skipping 5813 matching lines...) Expand 10 before | Expand all | Expand 10 after
6731 6722
6732 return totalBytesPerPixel; 6723 return totalBytesPerPixel;
6733 } 6724 }
6734 6725
6735 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const 6726 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const
6736 { 6727 {
6737 return m_drawingBuffer.get(); 6728 return m_drawingBuffer.get();
6738 } 6729 }
6739 6730
6740 } // namespace blink 6731 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698