Skip to content

Commit

Permalink
gpu: Separate GpuControlService from GpuControl
Browse files Browse the repository at this point in the history
Orignal goal of this CL is to make
InProcessCommandBuffer::CreateGpuMemoryBuffer and
DestroyGpuMemoryBuffer thread safe. Before this, Create runs
on the client thread and Destroy runs on the service thread
without any kind of synchronization. This change makes the
division closer to the cross-process implementation, moving
parts of the implementation from GpuControlService to
GpuControl/InProcessViewRenderer.

As a result, GpuControlService no longer needs to inherit
GpuControl. And GLES2Decoder has enough information to
decide on all gpu::Capabilities.

Need to implement the bare minimum client GpuControl for
gl_tests and gles2_conform_test. This currently involves
some boilerplate and duplication.

BUG=362346

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@267753 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
boliu@chromium.org committed May 2, 2014
1 parent 5ed381a commit 01952a6
Show file tree
Hide file tree
Showing 29 changed files with 279 additions and 255 deletions.
2 changes: 1 addition & 1 deletion content/common/gpu/client/command_buffer_proxy_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "gpu/command_buffer/client/gpu_control.h"
#include "gpu/command_buffer/common/command_buffer.h"
#include "gpu/command_buffer/common/command_buffer_shared.h"
#include "gpu/command_buffer/common/gpu_control.h"
#include "gpu/command_buffer/common/gpu_memory_allocation.h"
#include "ipc/ipc_listener.h"
#include "ui/events/latency_info.h"
Expand Down
23 changes: 8 additions & 15 deletions content/common/gpu/gpu_command_buffer_stub.cc
Original file line number Diff line number Diff line change
Expand Up @@ -538,12 +538,8 @@ void GpuCommandBufferStub::OnInitialize(
return;
}

gpu_control_.reset(
new gpu::GpuControlService(context_group_->image_manager(),
NULL,
context_group_->mailbox_manager(),
NULL,
decoder_->GetCapabilities()));
gpu_control_service_.reset(
new gpu::GpuControlService(context_group_->image_manager(), NULL));

if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableGPUServiceLogging)) {
Expand Down Expand Up @@ -587,7 +583,7 @@ void GpuCommandBufferStub::OnInitialize(
shared_state_shm.Pass(), kSharedStateSize));

GpuCommandBufferMsg_Initialize::WriteReplyParams(
reply_message, true, gpu_control_->GetCapabilities());
reply_message, true, decoder_->GetCapabilities());
Send(reply_message);

if (handle_.is_null() && !active_url_.is_empty()) {
Expand Down Expand Up @@ -942,19 +938,16 @@ void GpuCommandBufferStub::OnRegisterGpuMemoryBuffer(
return;
}
#endif
if (gpu_control_) {
gpu_control_->RegisterGpuMemoryBuffer(id,
gpu_memory_buffer,
width,
height,
internalformat);
if (gpu_control_service_) {
gpu_control_service_->RegisterGpuMemoryBuffer(
id, gpu_memory_buffer, width, height, internalformat);
}
}

void GpuCommandBufferStub::OnDestroyGpuMemoryBuffer(int32 id) {
TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnDestroyGpuMemoryBuffer");
if (gpu_control_)
gpu_control_->DestroyGpuMemoryBuffer(id);
if (gpu_control_service_)
gpu_control_service_->UnregisterGpuMemoryBuffer(id);
}

void GpuCommandBufferStub::SendConsoleMessage(
Expand Down
2 changes: 1 addition & 1 deletion content/common/gpu/gpu_command_buffer_stub.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class GpuCommandBufferStub
scoped_ptr<gpu::gles2::GLES2Decoder> decoder_;
scoped_ptr<gpu::GpuScheduler> scheduler_;
scoped_refptr<gfx::GLSurface> surface_;
scoped_ptr<gpu::GpuControlService> gpu_control_;
scoped_ptr<gpu::GpuControlService> gpu_control_service_;

scoped_ptr<GpuMemoryManagerClientState> memory_manager_client_state_;
// The last memory allocation received from the GpuMemoryManager (used to
Expand Down
2 changes: 1 addition & 1 deletion gpu/command_buffer/client/client_test_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "gpu/command_buffer/client/gpu_control.h"
#include "gpu/command_buffer/common/cmd_buffer_common.h"
#include "gpu/command_buffer/common/gpu_control.h"
#include "gpu/command_buffer/common/gpu_memory_allocation.h"
#include "gpu/command_buffer/service/command_buffer_service.h"
#include "testing/gmock/include/gmock/gmock.h"
Expand Down
10 changes: 5 additions & 5 deletions gpu/command_buffer/client/gles2_implementation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@

#include "gpu/command_buffer/client/gles2_implementation.h"

#include <GLES2/gl2ext.h>
#include <GLES2/gl2extchromium.h>
#include <algorithm>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <limits>
#include <sstream>
#include <string>
#include <GLES2/gl2ext.h>
#include <GLES2/gl2extchromium.h>
#include "base/bind.h"
#include "gpu/command_buffer/client/buffer_tracker.h"
#include "gpu/command_buffer/client/gpu_control.h"
#include "gpu/command_buffer/client/gpu_memory_buffer_tracker.h"
#include "gpu/command_buffer/client/program_info_manager.h"
#include "gpu/command_buffer/client/query_tracker.h"
#include "gpu/command_buffer/client/transfer_buffer.h"
#include "gpu/command_buffer/client/vertex_array_object_manager.h"
#include "gpu/command_buffer/common/gles2_cmd_utils.h"
#include "gpu/command_buffer/common/gpu_control.h"
#include "gpu/command_buffer/common/trace_event.h"
#include "ui/gfx/gpu_memory_buffer.h"

Expand All @@ -32,8 +32,8 @@
#endif

#if defined(GPU_CLIENT_DEBUG)
#include "ui/gl/gl_switches.h"
#include "base/command_line.h"
#include "ui/gl/gl_switches.h"
#endif

namespace gpu {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright 2013 The Chromium Authors. All rights reserved.
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef GPU_COMMAND_BUFFER_COMMON_GPU_CONTROL_H_
#define GPU_COMMAND_BUFFER_COMMON_GPU_CONTROL_H_
#ifndef GPU_COMMAND_BUFFER_CLIENT_GPU_CONTROL_H_
#define GPU_COMMAND_BUFFER_CLIENT_GPU_CONTROL_H_

#include <vector>

Expand Down Expand Up @@ -68,4 +68,4 @@ class GPU_EXPORT GpuControl {

} // namespace gpu

#endif // GPU_COMMAND_BUFFER_COMMON_GPU_CONTROL_H_
#endif // GPU_COMMAND_BUFFER_CLIENT_GPU_CONTROL_H_
2 changes: 1 addition & 1 deletion gpu/command_buffer/client/gpu_memory_buffer_tracker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "base/memory/scoped_ptr.h"
#include "gpu/command_buffer/client/gles2_implementation.h"
#include "gpu/command_buffer/common/gpu_control.h"
#include "gpu/command_buffer/client/gpu_control.h"

namespace gpu {
namespace gles2 {
Expand Down
2 changes: 0 additions & 2 deletions gpu/command_buffer/common/capabilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ struct GPU_EXPORT Capabilities {
bool texture_storage;
bool discard_framebuffer;
bool sync_query;

// Capabilities below are not populated by GLES2Decoder.
bool map_image;

Capabilities();
Expand Down
29 changes: 10 additions & 19 deletions gpu/command_buffer/service/gles2_cmd_decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1105,12 +1105,9 @@ class GLES2DecoderImpl : public GLES2Decoder,
}

// Creates a vertex attrib manager for the given vertex array.
scoped_refptr<VertexAttribManager> CreateVertexAttribManager(
GLuint client_id,
GLuint service_id,
bool client_visible) {
void CreateVertexAttribManager(GLuint client_id, GLuint service_id) {
return vertex_array_manager()->CreateVertexAttribManager(
client_id, service_id, group_->max_vertex_attribs(), client_visible);
client_id, service_id, group_->max_vertex_attribs());
}

void DoBindAttribLocation(GLuint client_id, GLuint index, const char* name);
Expand Down Expand Up @@ -2358,17 +2355,7 @@ bool GLES2DecoderImpl::Initialize(
disallowed_features_ = disallowed_features;

state_.attrib_values.resize(group_->max_vertex_attribs());
vertex_array_manager_.reset(new VertexArrayManager());

GLuint default_vertex_attrib_service_id = 0;
if (features().native_vertex_array_object) {
glGenVertexArraysOES(1, &default_vertex_attrib_service_id);
glBindVertexArrayOES(default_vertex_attrib_service_id);
}

state_.default_vertex_attrib_manager =
CreateVertexAttribManager(0, default_vertex_attrib_service_id, false);

state_.default_vertex_attrib_manager = new VertexAttribManager();
state_.default_vertex_attrib_manager->Initialize(
group_->max_vertex_attribs(),
feature_info_->workarounds().init_vertex_attributes);
Expand All @@ -2377,6 +2364,7 @@ bool GLES2DecoderImpl::Initialize(
DoBindVertexArrayOES(0);

query_manager_.reset(new QueryManager(this, feature_info_.get()));
vertex_array_manager_.reset(new VertexArrayManager());

util_.set_num_compressed_texture_formats(
validators_->compressed_texture_format.GetValues().size());
Expand Down Expand Up @@ -2688,6 +2676,7 @@ Capabilities GLES2DecoderImpl::GetCapabilities() {
#endif

caps.post_sub_buffer = supports_post_sub_buffer_;
caps.map_image = !!image_manager();

return caps;
}
Expand Down Expand Up @@ -9695,14 +9684,14 @@ bool GLES2DecoderImpl::GenVertexArraysOESHelper(
if (!features().native_vertex_array_object) {
// Emulated VAO
for (GLsizei ii = 0; ii < n; ++ii) {
CreateVertexAttribManager(client_ids[ii], 0, true);
CreateVertexAttribManager(client_ids[ii], 0);
}
} else {
scoped_ptr<GLuint[]> service_ids(new GLuint[n]);

glGenVertexArraysOES(n, service_ids.get());
for (GLsizei ii = 0; ii < n; ++ii) {
CreateVertexAttribManager(client_ids[ii], service_ids[ii], true);
CreateVertexAttribManager(client_ids[ii], service_ids[ii]);
}
}

Expand All @@ -9725,6 +9714,7 @@ void GLES2DecoderImpl::DeleteVertexArraysOESHelper(

void GLES2DecoderImpl::DoBindVertexArrayOES(GLuint client_id) {
VertexAttribManager* vao = NULL;
GLuint service_id = 0;
if (client_id != 0) {
vao = GetVertexAttribManager(client_id);
if (!vao) {
Expand All @@ -9736,6 +9726,8 @@ void GLES2DecoderImpl::DoBindVertexArrayOES(GLuint client_id) {
"glBindVertexArrayOES", "bad vertex array id.");
current_decoder_error_ = error::kNoError;
return;
} else {
service_id = vao->service_id();
}
} else {
vao = state_.default_vertex_attrib_manager.get();
Expand All @@ -9747,7 +9739,6 @@ void GLES2DecoderImpl::DoBindVertexArrayOES(GLuint client_id) {
if (!features().native_vertex_array_object) {
EmulateVertexArrayState();
} else {
GLuint service_id = vao->service_id();
glBindVertexArrayOES(service_id);
}
}
Expand Down
5 changes: 0 additions & 5 deletions gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,6 @@ void GLES2DecoderTestBase::InitDecoderWithCommandLine(
EXPECT_TRUE(
group_->Initialize(mock_decoder_.get(), DisallowedFeatures()));

if (group_->feature_info()->feature_flags().native_vertex_array_object) {
EXPECT_CALL(*gl_, GenVertexArraysOES(1, _)).Times(1).RetiresOnSaturation();
EXPECT_CALL(*gl_, BindVertexArrayOES(_)).Times(1).RetiresOnSaturation();
}

if (group_->feature_info()->workarounds().init_vertex_attributes)
AddExpectationsForVertexAttribManager();

Expand Down
98 changes: 9 additions & 89 deletions gpu/command_buffer/service/gpu_control_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,84 +4,21 @@

#include "gpu/command_buffer/service/gpu_control_service.h"

#include "gpu/command_buffer/client/gpu_memory_buffer_factory.h"
#include "gpu/command_buffer/service/gpu_memory_buffer_manager.h"
#include "gpu/command_buffer/service/mailbox_manager.h"
#include "gpu/command_buffer/service/query_manager.h"

namespace gpu {

GpuControlService::GpuControlService(
GpuMemoryBufferManagerInterface* gpu_memory_buffer_manager,
GpuMemoryBufferFactory* gpu_memory_buffer_factory,
gles2::MailboxManager* mailbox_manager,
gles2::QueryManager* query_manager,
const gpu::Capabilities& decoder_capabilities)
gles2::QueryManager* query_manager)
: gpu_memory_buffer_manager_(gpu_memory_buffer_manager),
gpu_memory_buffer_factory_(gpu_memory_buffer_factory),
mailbox_manager_(mailbox_manager),
query_manager_(query_manager),
capabilities_(decoder_capabilities) {
capabilities_.map_image =
gpu_memory_buffer_manager_ && gpu_memory_buffer_factory_;
query_manager_(query_manager) {
}

GpuControlService::~GpuControlService() {
}

gpu::Capabilities GpuControlService::GetCapabilities() {
return capabilities_;
}

gfx::GpuMemoryBuffer* GpuControlService::CreateGpuMemoryBuffer(
size_t width,
size_t height,
unsigned internalformat,
int32* id) {
*id = -1;

CHECK(gpu_memory_buffer_factory_) << "No GPU memory buffer factory provided";
linked_ptr<gfx::GpuMemoryBuffer> buffer = make_linked_ptr(
gpu_memory_buffer_factory_->CreateGpuMemoryBuffer(width,
height,
internalformat));
if (!buffer.get())
return NULL;

static int32 next_id = 1;
*id = next_id++;

if (!RegisterGpuMemoryBuffer(*id,
buffer->GetHandle(),
width,
height,
internalformat)) {
*id = -1;
return NULL;
}

gpu_memory_buffers_[*id] = buffer;
return buffer.get();
}

void GpuControlService::DestroyGpuMemoryBuffer(int32 id) {
GpuMemoryBufferMap::iterator it = gpu_memory_buffers_.find(id);
if (it != gpu_memory_buffers_.end())
gpu_memory_buffers_.erase(it);

gpu_memory_buffer_manager_->DestroyGpuMemoryBuffer(id);
}

uint32 GpuControlService::InsertSyncPoint() {
NOTREACHED();
return 0u;
}

void GpuControlService::SignalSyncPoint(uint32 sync_point,
const base::Closure& callback) {
NOTREACHED();
}

void GpuControlService::SignalQuery(uint32 query_id,
const base::Closure& callback) {
DCHECK(query_manager_);
Expand All @@ -92,35 +29,18 @@ void GpuControlService::SignalQuery(uint32 query_id,
query->AddCallback(callback);
}

void GpuControlService::SetSurfaceVisible(bool visible) {
NOTREACHED();
}

void GpuControlService::SendManagedMemoryStats(
const ManagedMemoryStats& stats) {
NOTREACHED();
}

void GpuControlService::Echo(const base::Closure& callback) {
NOTREACHED();
}

uint32 GpuControlService::CreateStreamTexture(uint32 texture_id) {
NOTREACHED();
return 0;
}

bool GpuControlService::RegisterGpuMemoryBuffer(
void GpuControlService::RegisterGpuMemoryBuffer(
int32 id,
gfx::GpuMemoryBufferHandle buffer,
size_t width,
size_t height,
unsigned internalformat) {
return gpu_memory_buffer_manager_->RegisterGpuMemoryBuffer(id,
buffer,
width,
height,
internalformat);
gpu_memory_buffer_manager_->RegisterGpuMemoryBuffer(
id, buffer, width, height, internalformat);
}

void GpuControlService::UnregisterGpuMemoryBuffer(int32 id) {
gpu_memory_buffer_manager_->UnregisterGpuMemoryBuffer(id);
}

} // namespace gpu
Loading

0 comments on commit 01952a6

Please sign in to comment.