diff options
Diffstat (limited to 'gpu')
23 files changed, 266 insertions, 231 deletions
diff --git a/gpu/command_buffer/client/client_test_helper.h b/gpu/command_buffer/client/client_test_helper.h index 22ffea6..1b42a5c 100644 --- a/gpu/command_buffer/client/client_test_helper.h +++ b/gpu/command_buffer/client/client_test_helper.h @@ -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" diff --git a/gpu/command_buffer/client/gles2_implementation.cc b/gpu/command_buffer/client/gles2_implementation.cc index 3fe999a..ebe39da 100644 --- a/gpu/command_buffer/client/gles2_implementation.cc +++ b/gpu/command_buffer/client/gles2_implementation.cc @@ -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" @@ -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 { diff --git a/gpu/command_buffer/common/gpu_control.h b/gpu/command_buffer/client/gpu_control.h index e15d5e6..a2ccc65 100644 --- a/gpu/command_buffer/common/gpu_control.h +++ b/gpu/command_buffer/client/gpu_control.h @@ -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> @@ -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_ diff --git a/gpu/command_buffer/client/gpu_memory_buffer_tracker.cc b/gpu/command_buffer/client/gpu_memory_buffer_tracker.cc index 863028a..5347f66 100644 --- a/gpu/command_buffer/client/gpu_memory_buffer_tracker.cc +++ b/gpu/command_buffer/client/gpu_memory_buffer_tracker.cc @@ -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 { diff --git a/gpu/command_buffer/common/capabilities.h b/gpu/command_buffer/common/capabilities.h index 81e3d55..ba5cf4b 100644 --- a/gpu/command_buffer/common/capabilities.h +++ b/gpu/command_buffer/common/capabilities.h @@ -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(); diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc index 4b75c2e..1824847 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder.cc +++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc @@ -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); @@ -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); @@ -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()); @@ -2688,6 +2676,7 @@ Capabilities GLES2DecoderImpl::GetCapabilities() { #endif caps.post_sub_buffer = supports_post_sub_buffer_; + caps.map_image = !!image_manager(); return caps; } @@ -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]); } } @@ -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) { @@ -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(); @@ -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); } } diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc index b1ed1df..f644c89 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc +++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc @@ -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(); diff --git a/gpu/command_buffer/service/gpu_control_service.cc b/gpu/command_buffer/service/gpu_control_service.cc index 893b872..f9f19eb 100644 --- a/gpu/command_buffer/service/gpu_control_service.cc +++ b/gpu/command_buffer/service/gpu_control_service.cc @@ -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_); @@ -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 diff --git a/gpu/command_buffer/service/gpu_control_service.h b/gpu/command_buffer/service/gpu_control_service.h index 74fd4d5..9a64946 100644 --- a/gpu/command_buffer/service/gpu_control_service.h +++ b/gpu/command_buffer/service/gpu_control_service.h @@ -5,66 +5,36 @@ #ifndef GPU_COMMAND_BUFFER_SERVICE_GPU_CONTROL_SERVICE_H_ #define GPU_COMMAND_BUFFER_SERVICE_GPU_CONTROL_SERVICE_H_ -#include <map> - -#include "base/memory/linked_ptr.h" -#include "gpu/command_buffer/common/gpu_control.h" +#include "base/callback.h" +#include "gpu/command_buffer/common/capabilities.h" +#include "gpu/gpu_export.h" #include "ui/gfx/gpu_memory_buffer.h" namespace gpu { -class GpuMemoryBufferFactory; class GpuMemoryBufferManagerInterface; namespace gles2 { -class MailboxManager; class QueryManager; } -class GPU_EXPORT GpuControlService : public GpuControl { +class GPU_EXPORT GpuControlService { public: 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); virtual ~GpuControlService(); + void SignalQuery(uint32 query, const base::Closure& callback); - // GpuControl implementation. - virtual gpu::Capabilities GetCapabilities() OVERRIDE; - virtual gfx::GpuMemoryBuffer* CreateGpuMemoryBuffer( - size_t width, - size_t height, - unsigned internalformat, - int32* id) OVERRIDE; - virtual void DestroyGpuMemoryBuffer(int32 id) OVERRIDE; - virtual uint32 InsertSyncPoint() OVERRIDE; - virtual void SignalSyncPoint(uint32 sync_point, - const base::Closure& callback) OVERRIDE; - virtual void SignalQuery(uint32 query, - const base::Closure& callback) OVERRIDE; - virtual void SetSurfaceVisible(bool visible) OVERRIDE; - virtual void SendManagedMemoryStats(const ManagedMemoryStats& stats) - OVERRIDE; - virtual void Echo(const base::Closure& callback) OVERRIDE; - virtual uint32 CreateStreamTexture(uint32 texture_id) OVERRIDE; - - // Register an existing gpu memory buffer and get an ID that can be used - // to identify it in the command buffer. - bool RegisterGpuMemoryBuffer(int32 id, + void RegisterGpuMemoryBuffer(int32 id, gfx::GpuMemoryBufferHandle buffer, size_t width, size_t height, unsigned internalformat); + void UnregisterGpuMemoryBuffer(int32 id); private: GpuMemoryBufferManagerInterface* gpu_memory_buffer_manager_; - GpuMemoryBufferFactory* gpu_memory_buffer_factory_; - gles2::MailboxManager* mailbox_manager_; gles2::QueryManager* query_manager_; - typedef std::map<int32, linked_ptr<gfx::GpuMemoryBuffer> > GpuMemoryBufferMap; - GpuMemoryBufferMap gpu_memory_buffers_; - gpu::Capabilities capabilities_; DISALLOW_COPY_AND_ASSIGN(GpuControlService); }; diff --git a/gpu/command_buffer/service/gpu_memory_buffer_manager.h b/gpu/command_buffer/service/gpu_memory_buffer_manager.h index fb44ede..3ddcaad 100644 --- a/gpu/command_buffer/service/gpu_memory_buffer_manager.h +++ b/gpu/command_buffer/service/gpu_memory_buffer_manager.h @@ -15,12 +15,12 @@ class GPU_EXPORT GpuMemoryBufferManagerInterface { public: virtual ~GpuMemoryBufferManagerInterface() {} - virtual bool RegisterGpuMemoryBuffer(int32 id, + virtual void RegisterGpuMemoryBuffer(int32 id, gfx::GpuMemoryBufferHandle buffer, size_t width, size_t height, unsigned internalformat) = 0; - virtual void DestroyGpuMemoryBuffer(int32 id) = 0; + virtual void UnregisterGpuMemoryBuffer(int32 id) = 0; }; } // namespace gpu diff --git a/gpu/command_buffer/service/image_manager.cc b/gpu/command_buffer/service/image_manager.cc index f39eba2..a3ac435 100644 --- a/gpu/command_buffer/service/image_manager.cc +++ b/gpu/command_buffer/service/image_manager.cc @@ -15,19 +15,19 @@ ImageManager::ImageManager() : release_after_use_(false) { ImageManager::~ImageManager() { } -bool ImageManager::RegisterGpuMemoryBuffer(int32 id, +void ImageManager::RegisterGpuMemoryBuffer(int32 id, gfx::GpuMemoryBufferHandle buffer, size_t width, size_t height, unsigned internalformat) { if (id <= 0) { DVLOG(0) << "Cannot register GPU memory buffer with non-positive ID."; - return false; + return; } if (LookupImage(id)) { DVLOG(0) << "GPU memory buffer ID already in use."; - return false; + return; } scoped_refptr<gfx::GLImage> gl_image = @@ -35,16 +35,15 @@ bool ImageManager::RegisterGpuMemoryBuffer(int32 id, gfx::Size(width, height), internalformat); if (!gl_image) - return false; + return; if (release_after_use_) gl_image->SetReleaseAfterUse(); AddImage(gl_image.get(), id); - return true; } -void ImageManager::DestroyGpuMemoryBuffer(int32 id) { +void ImageManager::UnregisterGpuMemoryBuffer(int32 id) { RemoveImage(id); } diff --git a/gpu/command_buffer/service/image_manager.h b/gpu/command_buffer/service/image_manager.h index 51e006d..95d836f 100644 --- a/gpu/command_buffer/service/image_manager.h +++ b/gpu/command_buffer/service/image_manager.h @@ -26,12 +26,12 @@ class GPU_EXPORT ImageManager ImageManager(); // Overridden from GpuMemoryBufferManagerInterface: - virtual bool RegisterGpuMemoryBuffer(int32 id, + virtual void RegisterGpuMemoryBuffer(int32 id, gfx::GpuMemoryBufferHandle buffer, size_t width, size_t height, unsigned internalformat) OVERRIDE; - virtual void DestroyGpuMemoryBuffer(int32 id) OVERRIDE; + virtual void UnregisterGpuMemoryBuffer(int32 id) OVERRIDE; void AddImage(gfx::GLImage* gl_image, int32 service_id); void RemoveImage(int32 service_id); diff --git a/gpu/command_buffer/service/in_process_command_buffer.cc b/gpu/command_buffer/service/in_process_command_buffer.cc index f9b81db..f83cf17 100644 --- a/gpu/command_buffer/service/in_process_command_buffer.cc +++ b/gpu/command_buffer/service/in_process_command_buffer.cc @@ -24,6 +24,7 @@ #include "base/sequence_checker.h" #include "base/synchronization/condition_variable.h" #include "base/threading/thread.h" +#include "gpu/command_buffer/client/gpu_memory_buffer_factory.h" #include "gpu/command_buffer/service/command_buffer_service.h" #include "gpu/command_buffer/service/context_group.h" #include "gpu/command_buffer/service/gl_context_virtual.h" @@ -296,8 +297,11 @@ bool InProcessCommandBuffer::Initialize( base::Bind(&RunTaskWithResult<bool>, init_task, &result, &completion)); completion.Wait(); - if (result) + if (result) { capabilities_ = capabilities; + capabilities_.map_image = + capabilities_.map_image && g_gpu_memory_buffer_factory; + } return result; } @@ -409,15 +413,11 @@ bool InProcessCommandBuffer::InitializeOnGpuThread( DestroyOnGpuThread(); return false; } + *params.capabilities = decoder_->GetCapabilities(); gpu_control_.reset( new GpuControlService(decoder_->GetContextGroup()->image_manager(), - g_gpu_memory_buffer_factory, - decoder_->GetContextGroup()->mailbox_manager(), - decoder_->GetQueryManager(), - decoder_->GetCapabilities())); - - *params.capabilities = gpu_control_->GetCapabilities(); + decoder_->GetQueryManager())); if (!params.is_offscreen) { decoder_->SetResizeCallback(base::Bind( @@ -609,16 +609,37 @@ gfx::GpuMemoryBuffer* InProcessCommandBuffer::CreateGpuMemoryBuffer( unsigned internalformat, int32* id) { CheckSequencedThread(); - base::AutoLock lock(command_buffer_lock_); - return gpu_control_->CreateGpuMemoryBuffer(width, - height, - internalformat, - id); + + *id = -1; + linked_ptr<gfx::GpuMemoryBuffer> buffer = + make_linked_ptr(g_gpu_memory_buffer_factory->CreateGpuMemoryBuffer( + width, height, internalformat)); + if (!buffer.get()) + return NULL; + + static int32 next_id = 1; + *id = next_id++; + + base::Closure task = base::Bind(&GpuControlService::RegisterGpuMemoryBuffer, + base::Unretained(gpu_control_.get()), + *id, + buffer->GetHandle(), + width, + height, + internalformat); + + QueueTask(task); + + gpu_memory_buffers_[*id] = buffer; + return buffer.get(); } void InProcessCommandBuffer::DestroyGpuMemoryBuffer(int32 id) { CheckSequencedThread(); - base::Closure task = base::Bind(&GpuControl::DestroyGpuMemoryBuffer, + GpuMemoryBufferMap::iterator it = gpu_memory_buffers_.find(id); + if (it != gpu_memory_buffers_.end()) + gpu_memory_buffers_.erase(it); + base::Closure task = base::Bind(&GpuControlService::UnregisterGpuMemoryBuffer, base::Unretained(gpu_control_.get()), id); @@ -667,7 +688,7 @@ void InProcessCommandBuffer::SignalSyncPointOnGpuThread( void InProcessCommandBuffer::SignalQuery(unsigned query, const base::Closure& callback) { CheckSequencedThread(); - QueueTask(base::Bind(&GpuControl::SignalQuery, + QueueTask(base::Bind(&GpuControlService::SignalQuery, base::Unretained(gpu_control_.get()), query, WrapCallback(callback))); diff --git a/gpu/command_buffer/service/in_process_command_buffer.h b/gpu/command_buffer/service/in_process_command_buffer.h index 7045c9f..7cd5b08 100644 --- a/gpu/command_buffer/service/in_process_command_buffer.h +++ b/gpu/command_buffer/service/in_process_command_buffer.h @@ -5,17 +5,19 @@ #ifndef GPU_COMMAND_BUFFER_SERVICE_IN_PROCESS_COMMAND_BUFFER_H_ #define GPU_COMMAND_BUFFER_SERVICE_IN_PROCESS_COMMAND_BUFFER_H_ +#include <map> #include <vector> #include "base/callback.h" #include "base/compiler_specific.h" +#include "base/memory/linked_ptr.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "base/synchronization/lock.h" #include "base/synchronization/waitable_event.h" +#include "gpu/command_buffer/client/gpu_control.h" #include "gpu/command_buffer/common/command_buffer.h" -#include "gpu/command_buffer/common/gpu_control.h" #include "gpu/gpu_export.h" #include "ui/gfx/gpu_memory_buffer.h" #include "ui/gfx/native_widget_types.h" @@ -50,6 +52,7 @@ class ShaderTranslatorCache; } class CommandBufferServiceBase; +class GpuControlService; class GpuMemoryBufferFactory; class GpuScheduler; class TransferBufferManagerInterface; @@ -201,6 +204,8 @@ class GPU_EXPORT InProcessCommandBuffer : public CommandBuffer, State last_state_; int32 last_put_offset_; gpu::Capabilities capabilities_; + typedef std::map<int32, linked_ptr<gfx::GpuMemoryBuffer> > GpuMemoryBufferMap; + GpuMemoryBufferMap gpu_memory_buffers_; // Accessed on both threads: scoped_ptr<CommandBufferServiceBase> command_buffer_; @@ -209,7 +214,7 @@ class GPU_EXPORT InProcessCommandBuffer : public CommandBuffer, scoped_refptr<Service> service_; State state_after_last_flush_; base::Lock state_after_last_flush_lock_; - scoped_ptr<GpuControl> gpu_control_; + scoped_ptr<GpuControlService> gpu_control_; scoped_refptr<gfx::GLShareGroup> gl_share_group_; #if defined(OS_ANDROID) diff --git a/gpu/command_buffer/service/vertex_array_manager.cc b/gpu/command_buffer/service/vertex_array_manager.cc index 1560c04..9747519 100644 --- a/gpu/command_buffer/service/vertex_array_manager.cc +++ b/gpu/command_buffer/service/vertex_array_manager.cc @@ -28,22 +28,14 @@ void VertexArrayManager::Destroy(bool have_context) { vertex_attrib_managers_.clear(); } -scoped_refptr<VertexAttribManager> -VertexArrayManager::CreateVertexAttribManager(GLuint client_id, - GLuint service_id, - uint32 num_vertex_attribs, - bool client_visible) { +void VertexArrayManager::CreateVertexAttribManager( + GLuint client_id, GLuint service_id, uint32 num_vertex_attribs) { scoped_refptr<VertexAttribManager> vertex_attrib_manager( new VertexAttribManager(this, service_id, num_vertex_attribs)); - - if (client_visible) { - std::pair<VertexAttribManagerMap::iterator, bool> result = - vertex_attrib_managers_.insert( - std::make_pair(client_id, vertex_attrib_manager)); - DCHECK(result.second); - } - - return vertex_attrib_manager; + std::pair<VertexAttribManagerMap::iterator, bool> result = + vertex_attrib_managers_.insert( + std::make_pair(client_id, vertex_attrib_manager)); + DCHECK(result.second); } VertexAttribManager* VertexArrayManager::GetVertexAttribManager( diff --git a/gpu/command_buffer/service/vertex_array_manager.h b/gpu/command_buffer/service/vertex_array_manager.h index 97ecc1a..4fc567c 100644 --- a/gpu/command_buffer/service/vertex_array_manager.h +++ b/gpu/command_buffer/service/vertex_array_manager.h @@ -28,13 +28,9 @@ class GPU_EXPORT VertexArrayManager { // Must call before destruction. void Destroy(bool have_context); - // Creates a VertexAttribManager and if client_visible, - // maps it to the client_id. - scoped_refptr<VertexAttribManager> CreateVertexAttribManager( - GLuint client_id, - GLuint service_id, - uint32 num_vertex_attribs, - bool client_visible); + // Creates a VertexArrayInfo for the given vertex array. + void CreateVertexAttribManager(GLuint client_id, GLuint service_id, + uint32 num_vertex_attribs); // Gets the vertex attrib manager for the given vertex array. VertexAttribManager* GetVertexAttribManager(GLuint client_id); diff --git a/gpu/command_buffer/service/vertex_array_manager_unittest.cc b/gpu/command_buffer/service/vertex_array_manager_unittest.cc index 617a5f6..3e3fd89 100644 --- a/gpu/command_buffer/service/vertex_array_manager_unittest.cc +++ b/gpu/command_buffer/service/vertex_array_manager_unittest.cc @@ -58,7 +58,7 @@ TEST_F(VertexArrayManagerTest, Basic) { // Check we can create manager_->CreateVertexAttribManager( - kClient1Id, kService1Id, kNumVertexAttribs, true); + kClient1Id, kService1Id, kNumVertexAttribs); // Check creation success VertexAttribManager* info1 = manager_->GetVertexAttribManager(kClient1Id); ASSERT_TRUE(info1 != NULL); @@ -84,8 +84,7 @@ TEST_F(VertexArrayManagerTest, Destroy) { const GLuint kService1Id = 11; VertexArrayManager manager; // Check we can create - manager.CreateVertexAttribManager( - kClient1Id, kService1Id, kNumVertexAttribs, true); + manager.CreateVertexAttribManager(kClient1Id, kService1Id, kNumVertexAttribs); // Check creation success VertexAttribManager* info1 = manager.GetVertexAttribManager(kClient1Id); ASSERT_TRUE(info1 != NULL); diff --git a/gpu/command_buffer/tests/gl_manager.cc b/gpu/command_buffer/tests/gl_manager.cc index 2471451..eeb3307 100644 --- a/gpu/command_buffer/tests/gl_manager.cc +++ b/gpu/command_buffer/tests/gl_manager.cc @@ -10,6 +10,7 @@ #include "base/bind.h" #include "gpu/command_buffer/client/gles2_implementation.h" #include "gpu/command_buffer/client/gles2_lib.h" +#include "gpu/command_buffer/client/gpu_memory_buffer_factory.h" #include "gpu/command_buffer/client/transfer_buffer.h" #include "gpu/command_buffer/common/constants.h" #include "gpu/command_buffer/common/gles2_cmd_utils.h" @@ -44,7 +45,7 @@ GLManager::Options::Options() image_manager(NULL) {} GLManager::GLManager() - : context_lost_allowed_(false) { + : context_lost_allowed_(false), gpu_memory_buffer_factory_(NULL) { SetupBaseContext(); } @@ -171,12 +172,10 @@ void GLManager::Initialize(const GLManager::Options& options) { ::gpu::gles2::DisallowedFeatures(), attribs)) << "could not initialize decoder"; - gpu_control_.reset( + gpu_control_service_.reset( new GpuControlService(decoder_->GetContextGroup()->image_manager(), - options.gpu_memory_buffer_factory, - decoder_->GetContextGroup()->mailbox_manager(), - decoder_->GetQueryManager(), - decoder_->GetCapabilities())); + decoder_->GetQueryManager())); + gpu_memory_buffer_factory_ = options.gpu_memory_buffer_factory; command_buffer_->SetPutOffsetChangeCallback( base::Bind(&GLManager::PumpCommands, base::Unretained(this))); @@ -197,7 +196,7 @@ void GLManager::Initialize(const GLManager::Options& options) { transfer_buffer_.get(), options.bind_generates_resource, options.lose_context_when_out_of_memory, - gpu_control_.get())); + this)); ASSERT_TRUE(gles2_implementation_->Initialize( kStartTransferBufferSize, @@ -269,4 +268,65 @@ bool GLManager::GetBufferChanged(int32 transfer_buffer_id) { return gpu_scheduler_->SetGetBuffer(transfer_buffer_id); } +Capabilities GLManager::GetCapabilities() { + return decoder_->GetCapabilities(); +} + +gfx::GpuMemoryBuffer* GLManager::CreateGpuMemoryBuffer( + size_t width, + size_t height, + unsigned internalformat, + int32* id) { + *id = -1; + scoped_ptr<gfx::GpuMemoryBuffer> buffer( + gpu_memory_buffer_factory_->CreateGpuMemoryBuffer( + width, height, internalformat)); + if (!buffer.get()) + return NULL; + + static int32 next_id = 1; + *id = next_id++; + gpu_control_service_->RegisterGpuMemoryBuffer( + *id, buffer->GetHandle(), width, height, internalformat); + gfx::GpuMemoryBuffer* raw_buffer = buffer.get(); + memory_buffers_.add(*id, buffer.Pass()); + return raw_buffer; +} + +void GLManager::DestroyGpuMemoryBuffer(int32 id) { + memory_buffers_.erase(id); + gpu_control_service_->UnregisterGpuMemoryBuffer(id); +} + +uint32 GLManager::InsertSyncPoint() { + NOTIMPLEMENTED(); + return 0u; +} + +void GLManager::SignalSyncPoint(uint32 sync_point, + const base::Closure& callback) { + NOTIMPLEMENTED(); +} + +void GLManager::SignalQuery(uint32 query, const base::Closure& callback) { + NOTIMPLEMENTED(); +} + +void GLManager::SetSurfaceVisible(bool visible) { + NOTIMPLEMENTED(); +} + +void GLManager::SendManagedMemoryStats(const ManagedMemoryStats& stats) { + NOTIMPLEMENTED(); +} + +void GLManager::Echo(const base::Closure& callback) { + NOTIMPLEMENTED(); +} + +uint32 GLManager::CreateStreamTexture(uint32 texture_id) { + NOTIMPLEMENTED(); + return 0; +} + } // namespace gpu diff --git a/gpu/command_buffer/tests/gl_manager.h b/gpu/command_buffer/tests/gl_manager.h index 6eb5909..7b51b9e 100644 --- a/gpu/command_buffer/tests/gl_manager.h +++ b/gpu/command_buffer/tests/gl_manager.h @@ -5,8 +5,10 @@ #ifndef GPU_COMMAND_BUFFER_TESTS_GL_MANAGER_H_ #define GPU_COMMAND_BUFFER_TESTS_GL_MANAGER_H_ +#include "base/containers/scoped_ptr_hash_map.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" +#include "gpu/command_buffer/client/gpu_control.h" #include "gpu/command_buffer/service/feature_info.h" #include "ui/gfx/size.h" @@ -39,7 +41,7 @@ class ShareGroup; }; -class GLManager { +class GLManager : private GpuControl { public: struct Options { Options(); @@ -63,7 +65,7 @@ class GLManager { GpuMemoryBufferFactory* gpu_memory_buffer_factory; }; GLManager(); - ~GLManager(); + virtual ~GLManager(); void Initialize(const Options& options); void Destroy(); @@ -94,6 +96,23 @@ class GLManager { const gpu::gles2::FeatureInfo::Workarounds& workarounds() const; + // GpuControl implementation. + virtual Capabilities GetCapabilities() OVERRIDE; + virtual gfx::GpuMemoryBuffer* CreateGpuMemoryBuffer(size_t width, + size_t height, + unsigned internalformat, + int32* id) OVERRIDE; + virtual void DestroyGpuMemoryBuffer(int32 id) OVERRIDE; + virtual uint32 InsertSyncPoint() OVERRIDE; + virtual void SignalSyncPoint(uint32 sync_point, + const base::Closure& callback) OVERRIDE; + virtual void SignalQuery(uint32 query, + const base::Closure& callback) OVERRIDE; + virtual void SetSurfaceVisible(bool visible) OVERRIDE; + virtual void SendManagedMemoryStats(const ManagedMemoryStats& stats) OVERRIDE; + virtual void Echo(const base::Closure& callback) OVERRIDE; + virtual uint32 CreateStreamTexture(uint32 texture_id) OVERRIDE; + private: void PumpCommands(); bool GetBufferChanged(int32 transfer_buffer_id); @@ -102,7 +121,7 @@ class GLManager { scoped_refptr<gles2::MailboxManager> mailbox_manager_; scoped_refptr<gfx::GLShareGroup> share_group_; scoped_ptr<CommandBufferService> command_buffer_; - scoped_ptr<GpuControlService> gpu_control_; + scoped_ptr<GpuControlService> gpu_control_service_; scoped_ptr<gles2::GLES2Decoder> decoder_; scoped_ptr<GpuScheduler> gpu_scheduler_; scoped_refptr<gfx::GLSurface> surface_; @@ -112,6 +131,10 @@ class GLManager { scoped_ptr<gles2::GLES2Implementation> gles2_implementation_; bool context_lost_allowed_; + // Client GpuControl implementation. + GpuMemoryBufferFactory* gpu_memory_buffer_factory_; + base::ScopedPtrHashMap<int32, gfx::GpuMemoryBuffer> memory_buffers_; + // Used on Android to virtualize GL for all contexts. static int use_count_; static scoped_refptr<gfx::GLShareGroup>* base_share_group_; diff --git a/gpu/command_buffer_client.gypi b/gpu/command_buffer_client.gypi index cb52ee7..1e9f778 100644 --- a/gpu/command_buffer_client.gypi +++ b/gpu/command_buffer_client.gypi @@ -19,6 +19,7 @@ 'command_buffer/client/cmd_buffer_helper.h', 'command_buffer/client/fenced_allocator.cc', 'command_buffer/client/fenced_allocator.h', + 'command_buffer/client/gpu_control.h', 'command_buffer/client/mapped_memory.cc', 'command_buffer/client/mapped_memory.h', 'command_buffer/client/ring_buffer.cc', diff --git a/gpu/command_buffer_common.gypi b/gpu/command_buffer_common.gypi index b5f3858..ca8b19c 100644 --- a/gpu/command_buffer_common.gypi +++ b/gpu/command_buffer_common.gypi @@ -23,7 +23,6 @@ 'command_buffer/common/gles2_cmd_format_autogen.h', 'command_buffer/common/gles2_cmd_ids.h', 'command_buffer/common/gles2_cmd_ids_autogen.h', - 'command_buffer/common/gpu_control.h', 'command_buffer/common/id_allocator.cc', 'command_buffer/common/id_allocator.h', 'command_buffer/common/mailbox.cc', diff --git a/gpu/gles2_conform_support/egl/display.cc b/gpu/gles2_conform_support/egl/display.cc index 7e88297..fd2eba4 100644 --- a/gpu/gles2_conform_support/egl/display.cc +++ b/gpu/gles2_conform_support/egl/display.cc @@ -11,7 +11,6 @@ #include "gpu/command_buffer/client/gles2_lib.h" #include "gpu/command_buffer/client/transfer_buffer.h" #include "gpu/command_buffer/service/context_group.h" -#include "gpu/command_buffer/service/gpu_control_service.h" #include "gpu/command_buffer/service/transfer_buffer_manager.h" #include "gpu/gles2_conform_support/egl/config.h" #include "gpu/gles2_conform_support/egl/surface.h" @@ -170,8 +169,7 @@ EGLSurface Display::CreateWindowSurface(EGLConfig config, return EGL_NO_SURFACE; } - gpu_control_.reset(new gpu::GpuControlService( - NULL, NULL, group->mailbox_manager(), NULL, decoder_->GetCapabilities())); + gpu_control_service_.reset(new gpu::GpuControlService(NULL, NULL)); command_buffer->SetPutOffsetChangeCallback( base::Bind(&gpu::GpuScheduler::PutChanged, @@ -237,7 +235,7 @@ EGLContext Display::CreateContext(EGLConfig config, transfer_buffer_.get(), bind_generates_resources, lose_context_when_out_of_memory, - gpu_control_.get())); + this)); if (!context_->Initialize( kTransferBufferSize, @@ -271,4 +269,52 @@ bool Display::MakeCurrent(EGLSurface draw, EGLSurface read, EGLContext ctx) { return true; } +gpu::Capabilities Display::GetCapabilities() { + return decoder_->GetCapabilities(); +} + +gfx::GpuMemoryBuffer* Display::CreateGpuMemoryBuffer( + size_t width, + size_t height, + unsigned internalformat, + int32* id) { + NOTIMPLEMENTED(); + return NULL; +} + +void Display::DestroyGpuMemoryBuffer(int32 id) { + NOTIMPLEMENTED(); +} + +uint32 Display::InsertSyncPoint() { + NOTIMPLEMENTED(); + return 0u; +} + +void Display::SignalSyncPoint(uint32 sync_point, + const base::Closure& callback) { + NOTIMPLEMENTED(); +} + +void Display::SignalQuery(uint32 query, const base::Closure& callback) { + NOTIMPLEMENTED(); +} + +void Display::SetSurfaceVisible(bool visible) { + NOTIMPLEMENTED(); +} + +void Display::SendManagedMemoryStats(const gpu::ManagedMemoryStats& stats) { + NOTIMPLEMENTED(); +} + +void Display::Echo(const base::Closure& callback) { + NOTIMPLEMENTED(); +} + +uint32 Display::CreateStreamTexture(uint32 texture_id) { + NOTIMPLEMENTED(); + return 0; +} + } // namespace egl diff --git a/gpu/gles2_conform_support/egl/display.h b/gpu/gles2_conform_support/egl/display.h index f7c0ff3..3619e1f 100644 --- a/gpu/gles2_conform_support/egl/display.h +++ b/gpu/gles2_conform_support/egl/display.h @@ -9,8 +9,10 @@ #include "base/memory/scoped_ptr.h" #include "gpu/command_buffer/client/gles2_cmd_helper.h" +#include "gpu/command_buffer/client/gpu_control.h" #include "gpu/command_buffer/service/command_buffer_service.h" #include "gpu/command_buffer/service/gles2_cmd_decoder.h" +#include "gpu/command_buffer/service/gpu_control_service.h" #include "gpu/command_buffer/service/gpu_scheduler.h" #include "ui/gfx/native_widget_types.h" #include "ui/gl/gl_context.h" @@ -34,7 +36,7 @@ namespace egl { class Config; class Surface; -class Display { +class Display : private gpu::GpuControl { public: explicit Display(EGLNativeDisplayType display_id); virtual ~Display(); @@ -72,6 +74,24 @@ class Display { void DestroyContext(EGLContext ctx); bool MakeCurrent(EGLSurface draw, EGLSurface read, EGLContext ctx); + // GpuControl implementation. + virtual gpu::Capabilities GetCapabilities() OVERRIDE; + virtual gfx::GpuMemoryBuffer* CreateGpuMemoryBuffer(size_t width, + size_t height, + unsigned internalformat, + int32* id) OVERRIDE; + virtual void DestroyGpuMemoryBuffer(int32 id) OVERRIDE; + virtual uint32 InsertSyncPoint() OVERRIDE; + virtual void SignalSyncPoint(uint32 sync_point, + const base::Closure& callback) OVERRIDE; + virtual void SignalQuery(uint32 query, + const base::Closure& callback) OVERRIDE; + virtual void SetSurfaceVisible(bool visible) OVERRIDE; + virtual void SendManagedMemoryStats( + const gpu::ManagedMemoryStats& stats) OVERRIDE; + virtual void Echo(const base::Closure& callback) OVERRIDE; + virtual uint32 CreateStreamTexture(uint32 texture_id) OVERRIDE; + private: EGLNativeDisplayType display_id_; @@ -84,7 +104,7 @@ class Display { scoped_ptr<gpu::CommandBufferService> command_buffer_; scoped_ptr<gpu::GpuScheduler> gpu_scheduler_; scoped_ptr<gpu::gles2::GLES2Decoder> decoder_; - scoped_ptr<gpu::GpuControl> gpu_control_; + scoped_ptr<gpu::GpuControlService> gpu_control_service_; scoped_refptr<gfx::GLContext> gl_context_; scoped_refptr<gfx::GLSurface> gl_surface_; scoped_ptr<gpu::gles2::GLES2CmdHelper> gles2_cmd_helper_; |