Skip to content

Commit

Permalink
gpu: Remove WebGraphicsContext3D::makeContextCurrent()
Browse files Browse the repository at this point in the history
We don't need to call it before using GL context anymore.

BUG=404121

Review URL: https://codereview.chromium.org/470973002

Cr-Commit-Position: refs/heads/master@{#292592}
  • Loading branch information
ds-hwang authored and Commit bot committed Aug 29, 2014
1 parent e407013 commit 3ed758c
Show file tree
Hide file tree
Showing 22 changed files with 87 additions and 109 deletions.
2 changes: 1 addition & 1 deletion cc/test/test_context_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class TestContextProvider : public ContextProvider {
// This returns the TestWebGraphicsContext3D but is valid to call
// before the context is bound to a thread. This is needed to set up
// state on the test context before binding. Don't call
// makeContextCurrent on the context returned from this method.
// InitializeOnCurrentThread on the context returned from this method.
TestWebGraphicsContext3D* UnboundTestContext3d();

TestContextSupport* support() { return &support_; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ SynchronousCompositorFactoryImpl::CreateStreamTextureFactory(int frame_id) {
return factory;
}

blink::WebGraphicsContext3D*
webkit::gpu::WebGraphicsContext3DImpl*
SynchronousCompositorFactoryImpl::CreateOffscreenGraphicsContext3D(
const blink::WebGraphicsContext3D::Attributes& attributes) {
return WrapContextWithAttributes(CreateOffscreenContext(attributes),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ class SynchronousCompositorFactoryImpl : public SynchronousCompositorFactory {
const std::string& debug_name) OVERRIDE;
virtual scoped_refptr<StreamTextureFactory> CreateStreamTextureFactory(
int view_id) OVERRIDE;
virtual blink::WebGraphicsContext3D* CreateOffscreenGraphicsContext3D(
const blink::WebGraphicsContext3D::Attributes& attributes) OVERRIDE;

virtual webkit::gpu::WebGraphicsContext3DImpl*
CreateOffscreenGraphicsContext3D(
const blink::WebGraphicsContext3D::Attributes& attributes) OVERRIDE;

SynchronousInputEventFilter* synchronous_input_event_filter() {
return &synchronous_input_event_filter_;
Expand Down
2 changes: 1 addition & 1 deletion content/browser/gpu/gpu_ipc_browsertests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ContextTestBase : public content::ContentBrowserTest {
WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits(),
NULL));
CHECK(context_.get());
context_->makeContextCurrent();
context_->InitializeOnCurrentThread();
context_support_ = context_->GetContextSupport();
ContentBrowserTest::SetUpOnMainThread();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ CmdBufferImageTransportFactory::CmdBufferImageTransportFactory() {
limits,
NULL));
context_->setContextLostCallback(context_lost_listener_.get());
if (context_->makeContextCurrent())
if (context_->InitializeOnCurrentThread())
context_->pushGroupMarkerEXT(
base::StringPrintf("CmdBufferImageTransportFactory-%p",
context_.get()).c_str());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ bool ContextProviderCommandBuffer::BindToCurrentThread() {
if (lost_context_callback_proxy_)
return true;

if (!context3d_->makeContextCurrent())
if (!context3d_->InitializeOnCurrentThread())
return false;

InitializeCapabilities();
Expand Down
2 changes: 1 addition & 1 deletion content/common/gpu/client/gl_helper_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class GLHelperTest : public testing::Test {
bool lose_context_when_out_of_memory = false;
context_ = webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl::
CreateOffscreenContext(attributes, lose_context_when_out_of_memory);
context_->makeContextCurrent();
context_->InitializeOnCurrentThread();

helper_.reset(
new content::GLHelper(context_->GetGLInterface(),
Expand Down
2 changes: 1 addition & 1 deletion content/common/gpu/client/gl_helper_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class GLHelperTest : public testing::Test {
context_ =
WebGraphicsContext3DInProcessCommandBufferImpl::CreateOffscreenContext(
attributes, lose_context_when_out_of_memory);
context_->makeContextCurrent();
context_->InitializeOnCurrentThread();
context_support_ = context_->GetContextSupport();
helper_.reset(
new content::GLHelper(context_->GetGLInterface(), context_support_));
Expand Down
2 changes: 1 addition & 1 deletion content/common/gpu/client/gpu_in_process_context_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ContextTestBase : public testing::Test {
typedef WebGraphicsContext3DInProcessCommandBufferImpl WGC3DIPCBI;
context_ = WGC3DIPCBI::CreateOffscreenContext(
attributes, lose_context_when_out_of_memory);
context_->makeContextCurrent();
context_->InitializeOnCurrentThread();
context_support_ = context_->GetContextSupport();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include "gpu/GLES2/gl2extchromium.h"
#include "gpu/command_buffer/client/gles2_cmd_helper.h"
#include "gpu/command_buffer/client/gles2_implementation.h"
#include "gpu/command_buffer/client/gles2_lib.h"
#include "gpu/command_buffer/client/gles2_trace_implementation.h"
#include "gpu/command_buffer/client/transfer_buffer.h"
#include "gpu/command_buffer/common/constants.h"
Expand Down Expand Up @@ -65,28 +64,6 @@ scoped_refptr<WebGraphicsContext3DCommandBufferImpl::ShareGroup>
return it->second;
}

// Singleton used to initialize and terminate the gles2 library.
class GLES2Initializer {
public:
GLES2Initializer() {
gles2::Initialize();
}

~GLES2Initializer() {
gles2::Terminate();
}

private:
DISALLOW_COPY_AND_ASSIGN(GLES2Initializer);
};

////////////////////////////////////////////////////////////////////////////////

base::LazyInstance<GLES2Initializer> g_gles2_initializer =
LAZY_INSTANCE_INITIALIZER;

////////////////////////////////////////////////////////////////////////////////

} // namespace anonymous

WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits::SharedMemoryLimits()
Expand Down Expand Up @@ -226,9 +203,6 @@ bool WebGraphicsContext3DCommandBufferImpl::InitializeCommandBuffer(

bool WebGraphicsContext3DCommandBufferImpl::CreateContext(bool onscreen) {
TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::CreateContext");
// Ensure the gles2 library is initialized first in a thread safe way.
g_gles2_initializer.Get();

scoped_refptr<gpu::gles2::ShareGroup> gles2_share_group;

scoped_ptr<base::AutoLock> share_group_lock;
Expand Down Expand Up @@ -296,12 +270,11 @@ bool WebGraphicsContext3DCommandBufferImpl::CreateContext(bool onscreen) {
return true;
}

bool WebGraphicsContext3DCommandBufferImpl::makeContextCurrent() {
bool WebGraphicsContext3DCommandBufferImpl::InitializeOnCurrentThread() {
if (!MaybeInitializeGL()) {
DLOG(ERROR) << "Failed to initialize context.";
return false;
}
gles2::SetGLContext(GetGLInterface());
if (gpu::error::IsError(command_buffer_->GetLastError())) {
LOG(ERROR) << "Context dead on arrival. Last error: "
<< command_buffer_->GetLastError();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,11 @@ class WebGraphicsContext3DCommandBufferImpl
return mem_limits_.mapped_memory_reclaim_limit;
}

// WebGraphicsContext3DImpl methods
virtual bool InitializeOnCurrentThread() OVERRIDE;

//----------------------------------------------------------------------
// WebGraphicsContext3D methods

// Must be called after initialize() and before any of the following methods.
// Permanently binds to the first calling thread. Returns false if the
// graphics context fails to create. Do not call from more than one thread.
virtual bool makeContextCurrent();

virtual bool isContextLost();

virtual WGC3Denum getGraphicsResetStatusARB();
Expand Down
6 changes: 4 additions & 2 deletions content/renderer/android/synchronous_compositor_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class OutputSurface;
namespace webkit {
namespace gpu {
class ContextProviderWebContext;
class WebGraphicsContext3DImpl;
}
}

Expand Down Expand Up @@ -57,8 +58,9 @@ class SynchronousCompositorFactory {
const std::string& debug_name) = 0;
virtual scoped_refptr<StreamTextureFactory> CreateStreamTextureFactory(
int frame_id) = 0;
virtual blink::WebGraphicsContext3D* CreateOffscreenGraphicsContext3D(
const blink::WebGraphicsContext3D::Attributes& attributes) = 0;
virtual webkit::gpu::WebGraphicsContext3DImpl*
CreateOffscreenGraphicsContext3D(
const blink::WebGraphicsContext3D::Attributes& attributes) = 0;

protected:
SynchronousCompositorFactory() {}
Expand Down
2 changes: 1 addition & 1 deletion content/renderer/media/android/webmediaplayer_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ void WebMediaPlayerAndroid::paint(blink::WebCanvas* canvas,
if (!provider)
return;
blink::WebGraphicsContext3D* context3D = provider->context3d();
if (!context3D || !context3D->makeContextCurrent())
if (!context3D)
return;

// Copy video texture into a RGBA texture based bitmap first as video texture
Expand Down
39 changes: 24 additions & 15 deletions content/renderer/renderer_webkitplatformsupport_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -952,26 +952,35 @@ RendererWebKitPlatformSupportImpl::createOffscreenGraphicsContext3D(
if (!RenderThreadImpl::current())
return NULL;

scoped_ptr<webkit::gpu::WebGraphicsContext3DImpl> context;
bool must_use_synchronous_factory = false;
#if defined(OS_ANDROID)
if (SynchronousCompositorFactory* factory =
SynchronousCompositorFactory::GetInstance()) {
return factory->CreateOffscreenGraphicsContext3D(attributes);
context.reset(factory->CreateOffscreenGraphicsContext3D(attributes));
must_use_synchronous_factory = true;
}
#endif

scoped_refptr<GpuChannelHost> gpu_channel_host(
RenderThreadImpl::current()->EstablishGpuChannelSync(
CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE));

WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits;
bool lose_context_when_out_of_memory = false;
return WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext(
gpu_channel_host.get(),
attributes,
lose_context_when_out_of_memory,
GURL(attributes.topDocumentURL),
limits,
static_cast<WebGraphicsContext3DCommandBufferImpl*>(share_context));
if (!must_use_synchronous_factory) {
scoped_refptr<GpuChannelHost> gpu_channel_host(
RenderThreadImpl::current()->EstablishGpuChannelSync(
CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE));

WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits;
bool lose_context_when_out_of_memory = false;
context.reset(WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext(
gpu_channel_host.get(),
attributes,
lose_context_when_out_of_memory,
GURL(attributes.topDocumentURL),
limits,
static_cast<WebGraphicsContext3DCommandBufferImpl*>(share_context)));
}
// Most likely the GPU process exited and the attempt to reconnect to it
// failed. Need to try to restore the context again later.
if (!context || !context->InitializeOnCurrentThread())
return NULL;
return context.release();
}

//------------------------------------------------------------------------------
Expand Down
4 changes: 0 additions & 4 deletions content/shell/renderer/test_runner/TestPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,6 @@ bool TestPlugin::initialize(WebPluginContainer* container)
{
WebGraphicsContext3D::Attributes attrs;
m_context = Platform::current()->createOffscreenGraphicsContext3D(attrs);
if (m_context && !m_context->makeContextCurrent()) {
delete m_context;
m_context = 0;
}

if (!initScene())
return false;
Expand Down
2 changes: 1 addition & 1 deletion webkit/common/gpu/context_provider_in_process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ bool ContextProviderInProcess::BindToCurrentThread() {
if (lost_context_callback_proxy_)
return true;

if (!context3d_->makeContextCurrent())
if (!context3d_->InitializeOnCurrentThread())
return false;

InitializeCapabilities();
Expand Down
34 changes: 28 additions & 6 deletions webkit/common/gpu/grcontext_for_webgraphicscontext3d.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,46 @@
#include "webkit/common/gpu/grcontext_for_webgraphicscontext3d.h"

#include "base/debug/trace_event.h"
#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
#include "base/lazy_instance.h"
#include "gpu/command_buffer/client/gles2_lib.h"
#include "third_party/skia/include/gpu/GrContext.h"
#include "third_party/skia/include/gpu/gl/GrGLInterface.h"
#include "webkit/common/gpu/webgraphicscontext3d_impl.h"

namespace webkit {
namespace gpu {

static void BindWebGraphicsContext3DGLContextCallback(
const GrGLInterface* interface) {
reinterpret_cast<blink::WebGraphicsContext3D*>(
interface->fCallbackData)->makeContextCurrent();
namespace {

// Singleton used to initialize and terminate the gles2 library.
class GLES2Initializer {
public:
GLES2Initializer() { gles2::Initialize(); }

~GLES2Initializer() { gles2::Terminate(); }

private:
DISALLOW_COPY_AND_ASSIGN(GLES2Initializer);
};

base::LazyInstance<GLES2Initializer> g_gles2_initializer =
LAZY_INSTANCE_INITIALIZER;

void BindWebGraphicsContext3DGLContextCallback(const GrGLInterface* interface) {
gles2::SetGLContext(reinterpret_cast<WebGraphicsContext3DImpl*>(
interface->fCallbackData)->GetGLInterface());
}

} // namespace anonymous

GrContextForWebGraphicsContext3D::GrContextForWebGraphicsContext3D(
blink::WebGraphicsContext3D* context3d) {
WebGraphicsContext3DImpl* context3d) {
if (!context3d)
return;

// Ensure the gles2 library is initialized first in a thread safe way.
g_gles2_initializer.Get();
gles2::SetGLContext(context3d->GetGLInterface());
skia::RefPtr<GrGLInterface> interface = skia::AdoptRef(
context3d->createGrGLInterface());
if (!interface)
Expand Down
4 changes: 2 additions & 2 deletions webkit/common/gpu/grcontext_for_webgraphicscontext3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
#include "webkit/common/gpu/webkit_gpu_export.h"

class GrContext;
namespace blink { class WebGraphicsContext3D; }

namespace webkit {
namespace gpu {
class WebGraphicsContext3DImpl;

// This class binds an offscreen GrContext to an offscreen context3d. The
// context3d is used by the GrContext so must be valid as long as this class
// is alive.
class WEBKIT_GPU_EXPORT GrContextForWebGraphicsContext3D {
public:
explicit GrContextForWebGraphicsContext3D(
blink::WebGraphicsContext3D* context3d);
WebGraphicsContext3DImpl* context3d);
virtual ~GrContextForWebGraphicsContext3D();

GrContext* get() { return gr_context_.get(); }
Expand Down
1 change: 0 additions & 1 deletion webkit/common/gpu/webgraphicscontext3d_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,6 @@ DELEGATE_TO_GL_5(renderbufferStorageMultisampleEXT,
WGC3Denum, WGC3Dsizei, WGC3Dsizei)

GrGLInterface* WebGraphicsContext3DImpl::createGrGLInterface() {
makeContextCurrent();
return skia_bindings::CreateCommandBufferSkiaGLBinding();
}

Expand Down
8 changes: 7 additions & 1 deletion webkit/common/gpu/webgraphicscontext3d_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ class WebGraphicsContext3DErrorMessageCallback;
class WEBKIT_GPU_EXPORT WebGraphicsContext3DImpl
: public NON_EXPORTED_BASE(blink::WebGraphicsContext3D) {
public:
virtual ~WebGraphicsContext3DImpl();

// Must be called before any of the following methods. Permanently binds to
// the first calling thread. Returns false if the graphics context fails to
// initialize. Do not call from more than one thread.
virtual bool InitializeOnCurrentThread() = 0;

//----------------------------------------------------------------------
// WebGraphicsContext3D methods

Expand Down Expand Up @@ -570,7 +577,6 @@ class WEBKIT_GPU_EXPORT WebGraphicsContext3DImpl
friend class WebGraphicsContext3DErrorMessageCallback;

WebGraphicsContext3DImpl();
virtual ~WebGraphicsContext3DImpl();

::gpu::gles2::GLES2ImplementationErrorMessageCallback*
getErrorMessageCallback();
Expand Down
Loading

0 comments on commit 3ed758c

Please sign in to comment.