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

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

Issue 1990063004: Move bindToCurrentThread out to the creators of WebGL contexts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: bindwebgl: . 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
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 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 formatWebGLStatusString("Sandboxed", info.sandboxed ? "yes" : "no", statusMe ssage); 524 formatWebGLStatusString("Sandboxed", info.sandboxed ? "yes" : "no", statusMe ssage);
525 formatWebGLStatusString("Optimus", info.optimus ? "yes" : "no", statusMessag e); 525 formatWebGLStatusString("Optimus", info.optimus ? "yes" : "no", statusMessag e);
526 formatWebGLStatusString("AMD switchable", info.amdSwitchable ? "yes" : "no", statusMessage); 526 formatWebGLStatusString("AMD switchable", info.amdSwitchable ? "yes" : "no", statusMessage);
527 formatWebGLStatusString("Reset notification strategy", String::format("0x%04 x", info.resetNotificationStrategy).utf8().data(), statusMessage); 527 formatWebGLStatusString("Reset notification strategy", String::format("0x%04 x", info.resetNotificationStrategy).utf8().data(), statusMessage);
528 formatWebGLStatusString("GPU process crash count", String::number(info.proce ssCrashCount).utf8().data(), statusMessage); 528 formatWebGLStatusString("GPU process crash count", String::number(info.proce ssCrashCount).utf8().data(), statusMessage);
529 formatWebGLStatusString("ErrorMessage", info.errorMessage.utf8().data(), sta tusMessage); 529 formatWebGLStatusString("ErrorMessage", info.errorMessage.utf8().data(), sta tusMessage);
530 statusMessage.append("."); 530 statusMessage.append(".");
531 return statusMessage; 531 return statusMessage;
532 } 532 }
533 533
534 class WebGLRenderingContextBase::ContextProviderCreationInfo { 534 struct ContextProviderCreationInfo {
535 public: 535 // Inputs.
536 ContextProviderCreationInfo(Platform::ContextAttributes contextAttributes, P latform::GraphicsInfo glInfo, ScriptState* scriptState) 536 Platform::ContextAttributes contextAttributes;
537 { 537 Platform::GraphicsInfo* glInfo;
538 m_contextAttributes = contextAttributes; 538 ScriptState* scriptState;
539 m_glInfo = glInfo; 539 // Outputs.
540 m_scriptState = scriptState; 540 OwnPtr<WebGraphicsContext3DProvider> createdContextProvider;
541 }
542 Platform::ContextAttributes contextAttributes() { return m_contextAttributes ; }
543 Platform::GraphicsInfo glInfo() { return m_glInfo; }
544 ScriptState* scriptState() { return m_scriptState; }
545 void setContextProvider(PassOwnPtr<WebGraphicsContext3DProvider> provider) { m_provider = std::move(provider); }
546 PassOwnPtr<WebGraphicsContext3DProvider> releaseContextProvider() { return s td::move(m_provider); }
547 private:
548 Platform::ContextAttributes m_contextAttributes;
549 Platform::GraphicsInfo m_glInfo;
550 ScriptState* m_scriptState;
551 OwnPtr<WebGraphicsContext3DProvider> m_provider;
552 }; 541 };
553 542
554 void WebGLRenderingContextBase::createContextProviderOnMainThread(ContextProvide rCreationInfo* creationInfo, WaitableEvent* waitableEvent) 543 static void createContextProviderOnMainThread(ContextProviderCreationInfo* creat ionInfo, WaitableEvent* waitableEvent)
555 { 544 {
556 ASSERT(isMainThread()); 545 ASSERT(isMainThread());
557 Platform::GraphicsInfo glInfo = creationInfo->glInfo(); 546 creationInfo->createdContextProvider = adoptPtr(Platform::current()->createO ffscreenGraphicsContext3DProvider(
558 OwnPtr<WebGraphicsContext3DProvider> provider = adoptPtr(Platform::current() ->createOffscreenGraphicsContext3DProvider( 547 creationInfo->contextAttributes, creationInfo->scriptState->getExecution Context()->url(), 0, creationInfo->glInfo));
559 creationInfo->contextAttributes(), creationInfo->scriptState()->getExecu tionContext()->url(), 0, &glInfo, Platform::DoNotBindToCurrentThread));
560 creationInfo->setContextProvider(std::move(provider));
561 waitableEvent->signal(); 548 waitableEvent->signal();
562 } 549 }
563 550
564 PassOwnPtr<WebGraphicsContext3DProvider> WebGLRenderingContextBase::createContex tProviderOnWorkerThread(Platform::ContextAttributes contextAttributes, Platform: :GraphicsInfo glInfo, ScriptState* scriptState) 551 static PassOwnPtr<WebGraphicsContext3DProvider> createContextProviderOnWorkerThr ead(Platform::ContextAttributes contextAttributes, Platform::GraphicsInfo* glInf o, ScriptState* scriptState)
565 { 552 {
566 WaitableEvent waitableEvent; 553 WaitableEvent waitableEvent;
567 OwnPtr<ContextProviderCreationInfo> creationInfo = adoptPtr(new ContextProvi derCreationInfo(contextAttributes, glInfo, scriptState)); 554 ContextProviderCreationInfo creationInfo;
555 creationInfo.contextAttributes = contextAttributes;
556 creationInfo.glInfo = glInfo;
557 creationInfo.scriptState = scriptState;
568 WebTaskRunner* taskRunner = Platform::current()->mainThread()->getWebTaskRun ner(); 558 WebTaskRunner* taskRunner = Platform::current()->mainThread()->getWebTaskRun ner();
569 taskRunner->postTask(BLINK_FROM_HERE, threadSafeBind(&createContextProviderO nMainThread, AllowCrossThreadAccess(creationInfo.get()), AllowCrossThreadAccess( &waitableEvent))); 559 taskRunner->postTask(BLINK_FROM_HERE, threadSafeBind(&createContextProviderO nMainThread, AllowCrossThreadAccess(&creationInfo), AllowCrossThreadAccess(&wait ableEvent)));
570 waitableEvent.wait(); 560 waitableEvent.wait();
571 return creationInfo->releaseContextProvider(); 561 return std::move(creationInfo.createdContextProvider);
572 } 562 }
573 563
574 PassOwnPtr<WebGraphicsContext3DProvider> WebGLRenderingContextBase::createContex tProviderInternal(HTMLCanvasElement* canvas, ScriptState* scriptState, WebGLCont extAttributes attributes, unsigned webGLVersion) 564 PassOwnPtr<WebGraphicsContext3DProvider> WebGLRenderingContextBase::createContex tProviderInternal(HTMLCanvasElement* canvas, ScriptState* scriptState, WebGLCont extAttributes attributes, unsigned webGLVersion)
575 { 565 {
566 // Exactly one of these must be provided.
567 DCHECK_EQ(!canvas, !!scriptState);
568 // The canvas is only given on the main thread.
569 DCHECK(!canvas || isMainThread());
570
576 Platform::ContextAttributes contextAttributes = toPlatformContextAttributes( attributes, webGLVersion); 571 Platform::ContextAttributes contextAttributes = toPlatformContextAttributes( attributes, webGLVersion);
577 Platform::GraphicsInfo glInfo; 572 Platform::GraphicsInfo glInfo;
578 OwnPtr<WebGraphicsContext3DProvider> contextProvider; 573 OwnPtr<WebGraphicsContext3DProvider> contextProvider;
579 if (canvas) { 574 if (isMainThread()) {
575 const auto& url = canvas ? canvas->document().topDocument().url() : scri ptState->getExecutionContext()->url();
580 contextProvider = adoptPtr(Platform::current()->createOffscreenGraphicsC ontext3DProvider( 576 contextProvider = adoptPtr(Platform::current()->createOffscreenGraphicsC ontext3DProvider(
581 contextAttributes, canvas->document().topDocument().url(), 0, &glInf o, Platform::BindToCurrentThread)); 577 contextAttributes, url, 0, &glInfo));
582 } else { 578 } else {
583 if (isMainThread()) { 579 contextProvider = createContextProviderOnWorkerThread(contextAttributes, &glInfo, scriptState);
584 contextProvider = adoptPtr(Platform::current()->createOffscreenGraph icsContext3DProvider( 580 }
585 contextAttributes, scriptState->getExecutionContext()->url(), 0, &glInfo, Platform::BindToCurrentThread)); 581 if (contextProvider && !contextProvider->bindToCurrentThread()) {
586 } else { 582 contextProvider = nullptr;
587 contextProvider = createContextProviderOnWorkerThread(contextAttribu tes, glInfo, scriptState); 583 String errorString(glInfo.errorMessage.utf8().data());
588 if (!contextProvider->bindToCurrentThread()) 584 errorString.insert("bindToCurrentThread failed: ", 0);
589 return nullptr; 585 glInfo.errorMessage = errorString;
590 }
591 } 586 }
592 if (!contextProvider || shouldFailContextCreationForTesting) { 587 if (!contextProvider || shouldFailContextCreationForTesting) {
593 shouldFailContextCreationForTesting = false; 588 shouldFailContextCreationForTesting = false;
594 if (canvas) 589 if (canvas)
595 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webg lcontextcreationerror, false, true, extractWebGLContextCreationError(glInfo))); 590 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webg lcontextcreationerror, false, true, extractWebGLContextCreationError(glInfo)));
596 return nullptr; 591 return nullptr;
597 } 592 }
598 gpu::gles2::GLES2Interface* gl = contextProvider->contextGL(); 593 gpu::gles2::GLES2Interface* gl = contextProvider->contextGL();
599 if (!String(gl->GetString(GL_EXTENSIONS)).contains("GL_OES_packed_depth_sten cil")) { 594 if (!String(gl->GetString(GL_EXTENSIONS)).contains("GL_OES_packed_depth_sten cil")) {
600 if (canvas) 595 if (canvas)
(...skipping 5443 matching lines...) Expand 10 before | Expand all | Expand 10 after
6044 6039
6045 // If the context was lost due to RealLostContext, we need to destroy the ol d DrawingBuffer before creating new DrawingBuffer to ensure resource budget enou gh. 6040 // If the context was lost due to RealLostContext, we need to destroy the ol d DrawingBuffer before creating new DrawingBuffer to ensure resource budget enou gh.
6046 if (drawingBuffer()) { 6041 if (drawingBuffer()) {
6047 m_drawingBuffer->beginDestruction(); 6042 m_drawingBuffer->beginDestruction();
6048 m_drawingBuffer.clear(); 6043 m_drawingBuffer.clear();
6049 } 6044 }
6050 6045
6051 Platform::ContextAttributes attributes = toPlatformContextAttributes(m_reque stedAttributes, version()); 6046 Platform::ContextAttributes attributes = toPlatformContextAttributes(m_reque stedAttributes, version());
6052 Platform::GraphicsInfo glInfo; 6047 Platform::GraphicsInfo glInfo;
6053 OwnPtr<WebGraphicsContext3DProvider> contextProvider = adoptPtr(Platform::cu rrent()->createOffscreenGraphicsContext3DProvider( 6048 OwnPtr<WebGraphicsContext3DProvider> contextProvider = adoptPtr(Platform::cu rrent()->createOffscreenGraphicsContext3DProvider(
6054 attributes, canvas()->document().topDocument().url(), 0, &glInfo, Platfo rm::BindToCurrentThread)); 6049 attributes, canvas()->document().topDocument().url(), 0, &glInfo));
6055 RefPtr<DrawingBuffer> buffer; 6050 RefPtr<DrawingBuffer> buffer;
6056 if (contextProvider) { 6051 if (contextProvider->bindToCurrentThread()) {
6057 // Construct a new drawing buffer with the new GL context. 6052 // Construct a new drawing buffer with the new GL context.
6058 buffer = createDrawingBuffer(std::move(contextProvider)); 6053 buffer = createDrawingBuffer(std::move(contextProvider));
6059 // If DrawingBuffer::create() fails to allocate a fbo, |drawingBuffer| i s set to null. 6054 // If DrawingBuffer::create() fails to allocate a fbo, |drawingBuffer| i s set to null.
6060 } 6055 }
6061 if (!buffer) { 6056 if (!buffer) {
6062 if (m_contextLostMode == RealLostContext) { 6057 if (m_contextLostMode == RealLostContext) {
6063 m_restoreTimer.startOneShot(secondsBetweenRestoreAttempts, BLINK_FRO M_HERE); 6058 m_restoreTimer.startOneShot(secondsBetweenRestoreAttempts, BLINK_FRO M_HERE);
6064 } else { 6059 } else {
6065 // This likely shouldn't happen but is the best way to report it to the WebGL app. 6060 // This likely shouldn't happen but is the best way to report it to the WebGL app.
6066 synthesizeGLError(GL_INVALID_OPERATION, "", "error restoring context "); 6061 synthesizeGLError(GL_INVALID_OPERATION, "", "error restoring context ");
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
6384 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1); 6379 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1);
6385 } 6380 }
6386 6381
6387 void WebGLRenderingContextBase::restoreUnpackParameters() 6382 void WebGLRenderingContextBase::restoreUnpackParameters()
6388 { 6383 {
6389 if (m_unpackAlignment != 1) 6384 if (m_unpackAlignment != 1)
6390 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); 6385 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
6391 } 6386 }
6392 6387
6393 } // namespace blink 6388 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.h ('k') | third_party/WebKit/public/platform/Platform.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698