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

Unified Diff: content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.cc

Issue 1916923004: Request context sharing via content::ContextProviderCommandBuffer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sharegroup: . Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.cc
diff --git a/content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.cc b/content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.cc
index 01357764c75977c07d89afd429d849f3b75e0599..8b7d96c5d3d460273ffdf4f7f5290919a3e4c418 100644
--- a/content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.cc
+++ b/content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.cc
@@ -39,51 +39,13 @@
namespace content {
-namespace {
-
-static base::LazyInstance<base::Lock>::Leaky
- g_default_share_groups_lock = LAZY_INSTANCE_INITIALIZER;
-
-typedef std::map<
- gpu::GpuChannelHost*,
- scoped_refptr<WebGraphicsContext3DCommandBufferImpl::ShareGroup>>
- ShareGroupMap;
-static base::LazyInstance<ShareGroupMap> g_default_share_groups =
- LAZY_INSTANCE_INITIALIZER;
-
-scoped_refptr<WebGraphicsContext3DCommandBufferImpl::ShareGroup>
-GetDefaultShareGroupForHost(gpu::GpuChannelHost* host) {
- base::AutoLock lock(g_default_share_groups_lock.Get());
-
- ShareGroupMap& share_groups = g_default_share_groups.Get();
- ShareGroupMap::iterator it = share_groups.find(host);
- if (it == share_groups.end()) {
- scoped_refptr<WebGraphicsContext3DCommandBufferImpl::ShareGroup> group =
- new WebGraphicsContext3DCommandBufferImpl::ShareGroup();
- share_groups[host] = group;
- return group;
- }
- return it->second;
-}
-
-} // namespace anonymous
-
-WebGraphicsContext3DCommandBufferImpl::ShareGroup::ShareGroup() {
-}
-
-WebGraphicsContext3DCommandBufferImpl::ShareGroup::~ShareGroup() {
- DCHECK(contexts_.empty());
-}
-
WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl(
gpu::SurfaceHandle surface_handle,
const GURL& active_url,
gpu::GpuChannelHost* host,
const gpu::gles2::ContextCreationAttribHelper& attributes,
gfx::GpuPreference gpu_preference,
- bool share_resources,
- bool automatic_flushes,
- WebGraphicsContext3DCommandBufferImpl* share_context)
+ bool automatic_flushes)
: automatic_flushes_(automatic_flushes),
attributes_(attributes),
host_(host),
@@ -100,14 +62,6 @@ WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl(
case gpu::gles2::CONTEXT_TYPE_WEBGL2:
context_type_ = OFFSCREEN_CONTEXT_FOR_WEBGL;
}
- if (share_context) {
- DCHECK(!share_resources);
- share_group_ = share_context->share_group_;
- } else if (share_resources) {
- share_group_ = GetDefaultShareGroupForHost(host);
- } else {
- share_group_ = make_scoped_refptr(new ShareGroup);
- }
}
WebGraphicsContext3DCommandBufferImpl::
@@ -119,7 +73,9 @@ WebGraphicsContext3DCommandBufferImpl::
}
bool WebGraphicsContext3DCommandBufferImpl::MaybeInitializeGL(
- const gpu::SharedMemoryLimits& memory_limits) {
+ const gpu::SharedMemoryLimits& memory_limits,
+ gpu::CommandBufferProxyImpl* shared_command_buffer,
+ scoped_refptr<gpu::gles2::ShareGroup> share_group) {
if (initialized_)
return true;
@@ -133,7 +89,7 @@ bool WebGraphicsContext3DCommandBufferImpl::MaybeInitializeGL(
FROM_HERE_WITH_EXPLICIT_FUNCTION(
"125248 WebGraphicsContext3DCommandBufferImpl::MaybeInitializeGL"));
- if (!CreateContext(memory_limits)) {
+ if (!CreateContext(memory_limits, shared_command_buffer, share_group)) {
piman 2016/04/27 22:09:33 nit: std::move(share_group)
danakj 2016/04/28 00:25:58 Done.
Destroy();
initialize_failed_ = true;
@@ -153,23 +109,17 @@ bool WebGraphicsContext3DCommandBufferImpl::MaybeInitializeGL(
}
bool WebGraphicsContext3DCommandBufferImpl::InitializeCommandBuffer(
- WebGraphicsContext3DCommandBufferImpl* share_context) {
+ gpu::CommandBufferProxyImpl* shared_command_buffer) {
if (!host_.get())
return false;
- gpu::CommandBufferProxyImpl* share_group_command_buffer = NULL;
-
- if (share_context) {
- share_group_command_buffer = share_context->GetCommandBufferProxy();
- }
-
DCHECK(attributes_.buffer_preserved);
std::vector<int32_t> serialized_attributes;
attributes_.Serialize(&serialized_attributes);
// Create a proxy to a command buffer in the GPU process.
command_buffer_ = host_->CreateCommandBuffer(
- surface_handle_, gfx::Size(), share_group_command_buffer,
+ surface_handle_, gfx::Size(), shared_command_buffer,
gpu::GpuChannelHost::kDefaultStreamId,
gpu::GpuChannelHost::kDefaultStreamPriority, serialized_attributes,
active_url_, gpu_preference_);
@@ -192,27 +142,15 @@ bool WebGraphicsContext3DCommandBufferImpl::InitializeCommandBuffer(
}
bool WebGraphicsContext3DCommandBufferImpl::CreateContext(
- const gpu::SharedMemoryLimits& memory_limits) {
+ const gpu::SharedMemoryLimits& memory_limits,
+ gpu::CommandBufferProxyImpl* shared_command_buffer,
+ scoped_refptr<gpu::gles2::ShareGroup> share_group) {
TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::CreateContext");
- scoped_refptr<gpu::gles2::ShareGroup> gles2_share_group;
+ DCHECK_EQ(!!shared_command_buffer, !!share_group);
- std::unique_ptr<base::AutoLock> share_group_lock;
- bool add_to_share_group = false;
- if (!command_buffer_) {
- WebGraphicsContext3DCommandBufferImpl* share_context = NULL;
-
- share_group_lock.reset(new base::AutoLock(share_group_->lock()));
- share_context = share_group_->GetAnyContextLocked();
-
- if (!InitializeCommandBuffer(share_context)) {
- LOG(ERROR) << "Failed to initialize command buffer.";
- return false;
- }
-
- if (share_context)
- gles2_share_group = share_context->GetImplementation()->share_group();
-
- add_to_share_group = true;
+ if (!InitializeCommandBuffer(shared_command_buffer)) {
+ LOG(ERROR) << "Failed to initialize command buffer.";
+ return false;
}
// Create the GLES2 helper, which writes the command buffer protocol.
@@ -237,7 +175,7 @@ bool WebGraphicsContext3DCommandBufferImpl::CreateContext(
// Create the object exposing the OpenGL API.
real_gl_.reset(new gpu::gles2::GLES2Implementation(
- gles2_helper_.get(), gles2_share_group.get(), transfer_buffer_.get(),
+ gles2_helper_.get(), std::move(share_group), transfer_buffer_.get(),
bind_generates_resource, lose_context_when_out_of_memory,
support_client_side_arrays, command_buffer_.get()));
if (!real_gl_->Initialize(memory_limits.start_transfer_buffer_size,
@@ -248,15 +186,14 @@ bool WebGraphicsContext3DCommandBufferImpl::CreateContext(
return false;
}
- if (add_to_share_group)
- share_group_->AddContextLocked(this);
-
return true;
}
bool WebGraphicsContext3DCommandBufferImpl::InitializeOnCurrentThread(
- const gpu::SharedMemoryLimits& memory_limits) {
- if (!MaybeInitializeGL(memory_limits)) {
+ const gpu::SharedMemoryLimits& memory_limits,
+ gpu::CommandBufferProxyImpl* shared_command_buffer,
+ scoped_refptr<gpu::gles2::ShareGroup> share_group) {
+ if (!MaybeInitializeGL(memory_limits, shared_command_buffer, share_group)) {
piman 2016/04/27 22:09:33 nit: std::move(share_group)
danakj 2016/04/28 00:25:58 Done.
DLOG(ERROR) << "Failed to initialize context.";
return false;
}
@@ -270,8 +207,6 @@ bool WebGraphicsContext3DCommandBufferImpl::InitializeOnCurrentThread(
}
void WebGraphicsContext3DCommandBufferImpl::Destroy() {
- share_group_->RemoveContext(this);
-
trace_gl_.reset();
real_gl_.reset();
transfer_buffer_.reset();
@@ -291,14 +226,6 @@ void WebGraphicsContext3DCommandBufferImpl::OnContextLost() {
if (context_lost_callback_)
context_lost_callback_->onContextLost();
- share_group_->RemoveAllContexts();
-
- DCHECK(host_.get());
- {
- base::AutoLock lock(g_default_share_groups_lock.Get());
- g_default_share_groups.Get().erase(host_.get());
- }
-
gpu::CommandBuffer::State state = command_buffer_->GetLastState();
UmaRecordContextLost(context_type_, state.error, state.context_lost_reason);
}

Powered by Google App Engine
This is Rietveld 408576698