diff options
52 files changed, 1012 insertions, 2023 deletions
diff --git a/content/browser/gpu/browser_gpu_channel_host_factory.cc b/content/browser/gpu/browser_gpu_channel_host_factory.cc index 6f325a7..a1d9da1 100644 --- a/content/browser/gpu/browser_gpu_channel_host_factory.cc +++ b/content/browser/gpu/browser_gpu_channel_host_factory.cc @@ -14,6 +14,7 @@ #include "content/browser/gpu/gpu_process_host.h" #include "content/browser/gpu/gpu_surface_tracker.h" #include "content/common/child_process_host_impl.h" +#include "content/common/gpu/gpu_memory_buffer_factory.h" #include "content/common/gpu/gpu_messages.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/gpu_data_manager.h" @@ -22,6 +23,18 @@ #include "ipc/ipc_forwarding_message_filter.h" #include "ipc/message_filter.h" +#if defined(OS_MACOSX) +#include "content/common/gpu/gpu_memory_buffer_factory_io_surface.h" +#endif + +#if defined(OS_ANDROID) +#include "content/common/gpu/gpu_memory_buffer_factory_surface_texture.h" +#endif + +#if defined(USE_OZONE) +#include "content/common/gpu/gpu_memory_buffer_factory_ozone_native_buffer.h" +#endif + namespace content { BrowserGpuChannelHostFactory* BrowserGpuChannelHostFactory::instance_ = NULL; @@ -223,7 +236,7 @@ BrowserGpuChannelHostFactory::BrowserGpuChannelHostFactory() : gpu_client_id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), shutdown_event_(new base::WaitableEvent(true, false)), gpu_memory_buffer_manager_( - new BrowserGpuMemoryBufferManager(gpu_client_id_)), + new BrowserGpuMemoryBufferManager(this, gpu_client_id_)), gpu_host_id_(0), next_create_gpu_memory_buffer_request_id_(0) { } @@ -412,8 +425,39 @@ void BrowserGpuChannelHostFactory::SetHandlerForControlMessages( filter)); } +bool BrowserGpuChannelHostFactory::IsGpuMemoryBufferConfigurationSupported( + gfx::GpuMemoryBuffer::Format format, + gfx::GpuMemoryBuffer::Usage usage) { + // Preferred type is always used by factory. + std::vector<gfx::GpuMemoryBufferType> supported_types; + GpuMemoryBufferFactory::GetSupportedTypes(&supported_types); + DCHECK(!supported_types.empty()); + switch (supported_types[0]) { + case gfx::SHARED_MEMORY_BUFFER: + // Shared memory buffers must be created in-process. + return false; +#if defined(OS_MACOSX) + case gfx::IO_SURFACE_BUFFER: + return GpuMemoryBufferFactoryIOSurface:: + IsGpuMemoryBufferConfigurationSupported(format, usage); +#endif +#if defined(OS_ANDROID) + case gfx::SURFACE_TEXTURE_BUFFER: + return GpuMemoryBufferFactorySurfaceTexture:: + IsGpuMemoryBufferConfigurationSupported(format, usage); +#endif +#if defined(USE_OZONE) + case gfx::OZONE_NATIVE_BUFFER: + return GpuMemoryBufferFactoryOzoneNativeBuffer:: + IsGpuMemoryBufferConfigurationSupported(format, usage); +#endif + default: + NOTREACHED(); + return false; + } +} + void BrowserGpuChannelHostFactory::CreateGpuMemoryBuffer( - gfx::GpuMemoryBufferType type, gfx::GpuMemoryBufferId id, const gfx::Size& size, gfx::GpuMemoryBuffer::Format format, @@ -432,7 +476,6 @@ void BrowserGpuChannelHostFactory::CreateGpuMemoryBuffer( create_gpu_memory_buffer_requests_[request_id] = callback; host->CreateGpuMemoryBuffer( - type, id, size, format, @@ -444,7 +487,6 @@ void BrowserGpuChannelHostFactory::CreateGpuMemoryBuffer( } void BrowserGpuChannelHostFactory::DestroyGpuMemoryBuffer( - gfx::GpuMemoryBufferType type, gfx::GpuMemoryBufferId id, int client_id, int32 sync_point) { @@ -453,14 +495,12 @@ void BrowserGpuChannelHostFactory::DestroyGpuMemoryBuffer( FROM_HERE, base::Bind(&BrowserGpuChannelHostFactory::DestroyGpuMemoryBufferOnIO, base::Unretained(this), - type, id, client_id, sync_point)); } void BrowserGpuChannelHostFactory::DestroyGpuMemoryBufferOnIO( - gfx::GpuMemoryBufferType type, gfx::GpuMemoryBufferId id, int client_id, int32 sync_point) { @@ -470,7 +510,7 @@ void BrowserGpuChannelHostFactory::DestroyGpuMemoryBufferOnIO( if (!host) return; - host->DestroyGpuMemoryBuffer(type, id, client_id, sync_point); + host->DestroyGpuMemoryBuffer(id, client_id, sync_point); } void BrowserGpuChannelHostFactory::OnGpuMemoryBufferCreated( diff --git a/content/browser/gpu/browser_gpu_channel_host_factory.h b/content/browser/gpu/browser_gpu_channel_host_factory.h index 4eb47e7..76e77f8 100644 --- a/content/browser/gpu/browser_gpu_channel_host_factory.h +++ b/content/browser/gpu/browser_gpu_channel_host_factory.h @@ -36,16 +36,17 @@ class CONTENT_EXPORT BrowserGpuChannelHostFactory int32 route_id) override; // Overridden from GpuMemoryBufferFactoryHost: + virtual bool IsGpuMemoryBufferConfigurationSupported( + gfx::GpuMemoryBuffer::Format format, + gfx::GpuMemoryBuffer::Usage usage) override; void CreateGpuMemoryBuffer( - gfx::GpuMemoryBufferType type, gfx::GpuMemoryBufferId id, const gfx::Size& size, gfx::GpuMemoryBuffer::Format format, gfx::GpuMemoryBuffer::Usage usage, int client_id, const CreateGpuMemoryBufferCallback& callback) override; - void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, + void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, int client_id, int32 sync_point) override; @@ -86,8 +87,7 @@ class CONTENT_EXPORT BrowserGpuChannelHostFactory CreateCommandBufferResult result); static void AddFilterOnIO(int gpu_host_id, scoped_refptr<IPC::MessageFilter> filter); - void DestroyGpuMemoryBufferOnIO(gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, + void DestroyGpuMemoryBufferOnIO(gfx::GpuMemoryBufferId id, int client_id, int32 sync_point); void OnGpuMemoryBufferCreated(uint32 request_id, diff --git a/content/browser/gpu/browser_gpu_memory_buffer_manager.cc b/content/browser/gpu/browser_gpu_memory_buffer_manager.cc index fe8e792..11af884 100644 --- a/content/browser/gpu/browser_gpu_memory_buffer_manager.cc +++ b/content/browser/gpu/browser_gpu_memory_buffer_manager.cc @@ -10,33 +10,14 @@ #include "base/lazy_instance.h" #include "base/synchronization/waitable_event.h" #include "base/threading/thread_restrictions.h" +#include "content/common/gpu/client/gpu_memory_buffer_factory_host.h" #include "content/common/gpu/client/gpu_memory_buffer_impl.h" +#include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h" #include "content/public/browser/browser_thread.h" namespace content { namespace { -// Note: To keep things simple this function will only return one out of two -// types; the preferred GPU memory buffer type or the shared memory type. -gfx::GpuMemoryBufferType GetPreferredGpuMemoryBufferTypeForConfiguration( - gfx::GpuMemoryBuffer::Format format, - gfx::GpuMemoryBuffer::Usage usage) { - // First check if this configuration is supported by the preferred type. - if (GpuMemoryBufferImpl::IsConfigurationSupported( - GpuMemoryBufferImpl::GetPreferredType(), format, usage)) { - return GpuMemoryBufferImpl::GetPreferredType(); - } - - // If configuration is not supported by the preferred type, use shared - // memory type if it supports this configuration. - if (GpuMemoryBufferImpl::IsConfigurationSupported( - gfx::SHARED_MEMORY_BUFFER, format, usage)) { - return gfx::SHARED_MEMORY_BUFFER; - } - - return gfx::EMPTY_BUFFER; -} - BrowserGpuMemoryBufferManager* g_gpu_memory_buffer_manager = nullptr; // Global atomic to generate gpu memory buffer unique IDs. @@ -63,8 +44,12 @@ struct BrowserGpuMemoryBufferManager::AllocateGpuMemoryBufferRequest { scoped_ptr<gfx::GpuMemoryBuffer> result; }; -BrowserGpuMemoryBufferManager::BrowserGpuMemoryBufferManager(int gpu_client_id) - : gpu_client_id_(gpu_client_id) { +BrowserGpuMemoryBufferManager::BrowserGpuMemoryBufferManager( + GpuMemoryBufferFactoryHost* gpu_memory_buffer_factory_host, + int gpu_client_id) + : gpu_memory_buffer_factory_host_(gpu_memory_buffer_factory_host), + gpu_client_id_(gpu_client_id), + weak_ptr_factory_(this) { DCHECK(!g_gpu_memory_buffer_manager); g_gpu_memory_buffer_manager = this; } @@ -85,11 +70,22 @@ BrowserGpuMemoryBufferManager::AllocateGpuMemoryBuffer( gfx::GpuMemoryBuffer::Usage usage) { DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); + // Fallback to shared memory buffer if |format| and |usage| are not supported + // by factory. + if (!gpu_memory_buffer_factory_host_->IsGpuMemoryBufferConfigurationSupported( + format, usage)) { + DCHECK(GpuMemoryBufferImplSharedMemory::IsFormatSupported(format)); + DCHECK_EQ(usage, gfx::GpuMemoryBuffer::MAP); + return GpuMemoryBufferImplSharedMemory::Create( + g_next_gpu_memory_buffer_id.GetNext(), size, format); + } + AllocateGpuMemoryBufferRequest request(size, format, usage, gpu_client_id_); BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, base::Bind(&BrowserGpuMemoryBufferManager::AllocateGpuMemoryBufferOnIO, + base::Unretained(this), // Safe as we wait for result below. base::Unretained(&request))); // We're blocking the UI thread, which is generally undesirable. @@ -109,38 +105,43 @@ void BrowserGpuMemoryBufferManager::AllocateGpuMemoryBufferForChildProcess( const AllocationCallback& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - // Determine what GPU memory buffer type to use and early out if |format| and - // |usage| configuration is not supported. - gfx::GpuMemoryBufferType type = - GetPreferredGpuMemoryBufferTypeForConfiguration(format, usage); - if (type == gfx::EMPTY_BUFFER) { - callback.Run(gfx::GpuMemoryBufferHandle()); - return; - } - gfx::GpuMemoryBufferId new_id = g_next_gpu_memory_buffer_id.GetNext(); BufferMap& buffers = clients_[child_client_id]; DCHECK(buffers.find(new_id) == buffers.end()); + // Fallback to shared memory buffer if |format| and |usage| are not supported + // by factory. + if (!gpu_memory_buffer_factory_host_->IsGpuMemoryBufferConfigurationSupported( + format, usage)) { + // Early out if we cannot fallback to shared memory buffer. + if (!GpuMemoryBufferImplSharedMemory::IsFormatSupported(format) || + usage != gfx::GpuMemoryBuffer::MAP) { + callback.Run(gfx::GpuMemoryBufferHandle()); + return; + } + + buffers[new_id] = gfx::SHARED_MEMORY_BUFFER; + callback.Run(GpuMemoryBufferImplSharedMemory::AllocateForChildProcess( + new_id, size, format, child_process_handle)); + return; + } + // Note: Handling of cases where the child process is removed before the // allocation completes is less subtle if we set the buffer type to // EMPTY_BUFFER here and verify that this has not changed when allocation // completes. buffers[new_id] = gfx::EMPTY_BUFFER; - GpuMemoryBufferImpl::AllocateForChildProcess( - type, + gpu_memory_buffer_factory_host_->CreateGpuMemoryBuffer( new_id, size, format, usage, - child_process_handle, child_client_id, base::Bind(&BrowserGpuMemoryBufferManager:: GpuMemoryBufferAllocatedForChildProcess, - base::Unretained(this), - child_process_handle, + weak_ptr_factory_.GetWeakPtr(), child_client_id, callback)); } @@ -181,8 +182,13 @@ void BrowserGpuMemoryBufferManager::ChildProcessDeletedGpuMemoryBuffer( return; } - GpuMemoryBufferImpl::DeletedByChildProcess( - buffer_it->second, id, child_process_handle, child_client_id, sync_point); + // Buffers allocated using the factory need to be destroyed through the + // factory. + if (buffer_it->second != gfx::SHARED_MEMORY_BUFFER) { + gpu_memory_buffer_factory_host_->DestroyGpuMemoryBuffer(id, + child_client_id, + sync_point); + } buffers.erase(buffer_it); } @@ -203,18 +209,66 @@ void BrowserGpuMemoryBufferManager::ProcessRemoved( if (buffer_it.second == gfx::EMPTY_BUFFER) continue; - GpuMemoryBufferImpl::DeletedByChildProcess(buffer_it.second, - buffer_it.first, - process_handle, - client_id, - 0); + // Skip shared memory buffers as they were not allocated using the factory. + if (buffer_it.second == gfx::SHARED_MEMORY_BUFFER) + continue; + + gpu_memory_buffer_factory_host_->DestroyGpuMemoryBuffer(buffer_it.first, + client_id, + 0); } clients_.erase(client_it); } +void BrowserGpuMemoryBufferManager::AllocateGpuMemoryBufferOnIO( + AllocateGpuMemoryBufferRequest* request) { + // Note: Unretained is safe as this is only used for synchronous allocation + // from a non-IO thread. + gpu_memory_buffer_factory_host_->CreateGpuMemoryBuffer( + g_next_gpu_memory_buffer_id.GetNext(), + request->size, + request->format, + request->usage, + request->client_id, + base::Bind(&BrowserGpuMemoryBufferManager::GpuMemoryBufferAllocatedOnIO, + base::Unretained(this), + base::Unretained(request))); +} + +void BrowserGpuMemoryBufferManager::GpuMemoryBufferAllocatedOnIO( + AllocateGpuMemoryBufferRequest* request, + const gfx::GpuMemoryBufferHandle& handle) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + + // Early out if factory failed to allocate the buffer. + if (handle.is_null()) { + request->event.Signal(); + return; + } + + DCHECK_NE(handle.type, gfx::SHARED_MEMORY_BUFFER); + request->result = GpuMemoryBufferImpl::CreateFromHandle( + handle, + request->size, + request->format, + base::Bind(&BrowserGpuMemoryBufferManager::GpuMemoryBufferDeleted, + weak_ptr_factory_.GetWeakPtr(), + handle.id, + request->client_id)); + request->event.Signal(); +} + +void BrowserGpuMemoryBufferManager::GpuMemoryBufferDeleted( + gfx::GpuMemoryBufferId id, + int client_id, + uint32 sync_point) { + gpu_memory_buffer_factory_host_->DestroyGpuMemoryBuffer(id, + client_id, + sync_point); +} + void BrowserGpuMemoryBufferManager::GpuMemoryBufferAllocatedForChildProcess( - base::ProcessHandle child_process_handle, int child_client_id, const AllocationCallback& callback, const gfx::GpuMemoryBufferHandle& handle) { @@ -226,11 +280,8 @@ void BrowserGpuMemoryBufferManager::GpuMemoryBufferAllocatedForChildProcess( // allocated. if (client_it == clients_.end()) { if (!handle.is_null()) { - GpuMemoryBufferImpl::DeletedByChildProcess(handle.type, - handle.id, - child_process_handle, - child_client_id, - 0); + gpu_memory_buffer_factory_host_->DestroyGpuMemoryBuffer( + handle.id, child_client_id, 0); } callback.Run(gfx::GpuMemoryBufferHandle()); return; @@ -248,36 +299,14 @@ void BrowserGpuMemoryBufferManager::GpuMemoryBufferAllocatedForChildProcess( return; } - // Store the type for this buffer so it can be cleaned up if the child + // The factory should never return a shared memory backed buffer. + DCHECK_NE(handle.type, gfx::SHARED_MEMORY_BUFFER); + + // Store the type of this buffer so it can be cleaned up if the child // process is removed. buffer_it->second = handle.type; callback.Run(handle); } -// static -void BrowserGpuMemoryBufferManager::AllocateGpuMemoryBufferOnIO( - AllocateGpuMemoryBufferRequest* request) { - GpuMemoryBufferImpl::Create( - GetPreferredGpuMemoryBufferTypeForConfiguration( - request->format, request->usage), - g_next_gpu_memory_buffer_id.GetNext(), - request->size, - request->format, - request->usage, - request->client_id, - base::Bind(&BrowserGpuMemoryBufferManager::GpuMemoryBufferCreatedOnIO, - base::Unretained(request))); -} - -// static -void BrowserGpuMemoryBufferManager::GpuMemoryBufferCreatedOnIO( - AllocateGpuMemoryBufferRequest* request, - scoped_ptr<GpuMemoryBufferImpl> buffer) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - - request->result = buffer.Pass(); - request->event.Signal(); -} - } // namespace content diff --git a/content/browser/gpu/browser_gpu_memory_buffer_manager.h b/content/browser/gpu/browser_gpu_memory_buffer_manager.h index 84ad9e5..08ab881 100644 --- a/content/browser/gpu/browser_gpu_memory_buffer_manager.h +++ b/content/browser/gpu/browser_gpu_memory_buffer_manager.h @@ -6,10 +6,12 @@ #define CONTENT_BROWSER_GPU_BROWSER_GPU_MEMORY_BUFFER_MANAGER_H_ #include "base/callback.h" +#include "base/memory/weak_ptr.h" #include "content/common/content_export.h" #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" namespace content { +class GpuMemoryBufferFactoryHost; class GpuMemoryBufferImpl; class CONTENT_EXPORT BrowserGpuMemoryBufferManager @@ -18,7 +20,9 @@ class CONTENT_EXPORT BrowserGpuMemoryBufferManager typedef base::Callback<void(const gfx::GpuMemoryBufferHandle& handle)> AllocationCallback; - explicit BrowserGpuMemoryBufferManager(int gpu_client_id); + BrowserGpuMemoryBufferManager( + GpuMemoryBufferFactoryHost* gpu_memory_buffer_factory_host, + int gpu_client_id); ~BrowserGpuMemoryBufferManager() override; static BrowserGpuMemoryBufferManager* current(); @@ -50,18 +54,18 @@ class CONTENT_EXPORT BrowserGpuMemoryBufferManager private: struct AllocateGpuMemoryBufferRequest; + void AllocateGpuMemoryBufferOnIO(AllocateGpuMemoryBufferRequest* request); + void GpuMemoryBufferAllocatedOnIO(AllocateGpuMemoryBufferRequest* request, + const gfx::GpuMemoryBufferHandle& handle); + void GpuMemoryBufferDeleted(gfx::GpuMemoryBufferId id, + int client_id, + uint32 sync_point); void GpuMemoryBufferAllocatedForChildProcess( - base::ProcessHandle child_process_handle, int child_client_id, const AllocationCallback& callback, const gfx::GpuMemoryBufferHandle& handle); - static void AllocateGpuMemoryBufferOnIO( - AllocateGpuMemoryBufferRequest* request); - static void GpuMemoryBufferCreatedOnIO( - AllocateGpuMemoryBufferRequest* request, - scoped_ptr<GpuMemoryBufferImpl> buffer); - + GpuMemoryBufferFactoryHost* gpu_memory_buffer_factory_host_; int gpu_client_id_; typedef base::hash_map<gfx::GpuMemoryBufferId, gfx::GpuMemoryBufferType> @@ -69,6 +73,8 @@ class CONTENT_EXPORT BrowserGpuMemoryBufferManager typedef base::hash_map<int, BufferMap> ClientMap; ClientMap clients_; + base::WeakPtrFactory<BrowserGpuMemoryBufferManager> weak_ptr_factory_; + DISALLOW_COPY_AND_ASSIGN(BrowserGpuMemoryBufferManager); }; diff --git a/content/browser/gpu/gpu_process_host.cc b/content/browser/gpu/gpu_process_host.cc index d8e244d..2d04cb9 100644 --- a/content/browser/gpu/gpu_process_host.cc +++ b/content/browser/gpu/gpu_process_host.cc @@ -652,7 +652,6 @@ void GpuProcessHost::CreateViewCommandBuffer( } void GpuProcessHost::CreateGpuMemoryBuffer( - gfx::GpuMemoryBufferType type, gfx::GpuMemoryBufferId id, const gfx::Size& size, gfx::GpuMemoryBuffer::Format format, @@ -663,29 +662,22 @@ void GpuProcessHost::CreateGpuMemoryBuffer( DCHECK(CalledOnValidThread()); - GpuMsg_CreateGpuMemoryBuffer_Params params; - params.type = type; - params.id = id; - params.size = size; - params.format = format; - params.usage = usage; - params.client_id = client_id; - if (Send(new GpuMsg_CreateGpuMemoryBuffer(params))) { + if (Send(new GpuMsg_CreateGpuMemoryBuffer( + id, size, format, usage, client_id))) { create_gpu_memory_buffer_requests_.push(callback); } else { callback.Run(gfx::GpuMemoryBufferHandle()); } } -void GpuProcessHost::DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, +void GpuProcessHost::DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, int client_id, int sync_point) { TRACE_EVENT0("gpu", "GpuProcessHost::DestroyGpuMemoryBuffer"); DCHECK(CalledOnValidThread()); - Send(new GpuMsg_DestroyGpuMemoryBuffer(type, id, client_id, sync_point)); + Send(new GpuMsg_DestroyGpuMemoryBuffer(id, client_id, sync_point)); } void GpuProcessHost::OnInitialized(bool result, const gpu::GPUInfo& gpu_info) { diff --git a/content/browser/gpu/gpu_process_host.h b/content/browser/gpu/gpu_process_host.h index 2952d38..145cdcc 100644 --- a/content/browser/gpu/gpu_process_host.h +++ b/content/browser/gpu/gpu_process_host.h @@ -119,8 +119,7 @@ class GpuProcessHost : public BrowserChildProcessHostDelegate, const CreateCommandBufferCallback& callback); // Tells the GPU process to create a new GPU memory buffer. - void CreateGpuMemoryBuffer(gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, + void CreateGpuMemoryBuffer(gfx::GpuMemoryBufferId id, const gfx::Size& size, gfx::GpuMemoryBuffer::Format format, gfx::GpuMemoryBuffer::Usage usage, @@ -128,8 +127,7 @@ class GpuProcessHost : public BrowserChildProcessHostDelegate, const CreateGpuMemoryBufferCallback& callback); // Tells the GPU process to destroy GPU memory buffer. - void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, + void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, int client_id, int sync_point); diff --git a/content/common/BUILD.gn b/content/common/BUILD.gn index dc93071..af4c97a 100644 --- a/content/common/BUILD.gn +++ b/content/common/BUILD.gn @@ -178,10 +178,6 @@ source_set("common") { } if (use_ozone) { - sources -= [ - "gpu/client/gpu_memory_buffer_impl_linux.cc", - "gpu/gpu_memory_buffer_factory_linux.cc", - ] deps += [ "//ui/ozone:ozone", "//ui/ozone:ozone_base", @@ -191,10 +187,10 @@ source_set("common") { sources -= [ "cursors/webcursor_ozone.cc", "font_list_ozone.cc", - "gpu/client/gpu_memory_buffer_impl_ozone.cc", "gpu/client/gpu_memory_buffer_impl_ozone_native_buffer.cc", "gpu/client/gpu_memory_buffer_impl_ozone_native_buffer.h", - "gpu/gpu_memory_buffer_factory_ozone.cc", + "gpu/gpu_memory_buffer_factory_ozone_native_buffer.cc", + "gpu/gpu_memory_buffer_factory_ozone_native_buffer.h", ] } diff --git a/content/common/child_process_host_impl.cc b/content/common/child_process_host_impl.cc index 25699bf..f22d57a 100644 --- a/content/common/child_process_host_impl.cc +++ b/content/common/child_process_host_impl.cc @@ -327,25 +327,22 @@ void ChildProcessHostImpl::OnAllocateGpuMemoryBuffer( IPC::Message* reply) { // TODO(reveman): Add support for other types of GpuMemoryBuffers. + gfx::GpuMemoryBufferHandle handle; // AllocateForChildProcess() will check if |width| and |height| are valid // and handle failure in a controlled way when not. We just need to make // sure |format| and |usage| are supported here. - if (!GpuMemoryBufferImplSharedMemory::IsFormatSupported(format) || - !GpuMemoryBufferImplSharedMemory::IsUsageSupported(usage)) { - GpuMemoryBufferAllocated(reply, gfx::GpuMemoryBufferHandle()); - return; + if (GpuMemoryBufferImplSharedMemory::IsFormatSupported(format) && + usage == gfx::GpuMemoryBuffer::MAP) { + handle = GpuMemoryBufferImplSharedMemory::AllocateForChildProcess( + g_next_gpu_memory_buffer_id.GetNext(), + gfx::Size(width, height), + format, + peer_process_.Handle()); } - // Note: It is safe to use base::Unretained here as the shared memory - // implementation of AllocateForChildProcess() calls this synchronously. - GpuMemoryBufferImplSharedMemory::AllocateForChildProcess( - g_next_gpu_memory_buffer_id.GetNext(), - gfx::Size(width, height), - format, - peer_process_.Handle(), - base::Bind(&ChildProcessHostImpl::GpuMemoryBufferAllocated, - base::Unretained(this), - reply)); + ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer::WriteReplyParams(reply, + handle); + Send(reply); } void ChildProcessHostImpl::OnDeletedGpuMemoryBuffer( @@ -355,12 +352,4 @@ void ChildProcessHostImpl::OnDeletedGpuMemoryBuffer( // GpuMemoryBuffers is passed with IPC. } -void ChildProcessHostImpl::GpuMemoryBufferAllocated( - IPC::Message* reply, - const gfx::GpuMemoryBufferHandle& handle) { - ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer::WriteReplyParams(reply, - handle); - Send(reply); -} - } // namespace content diff --git a/content/common/child_process_host_impl.h b/content/common/child_process_host_impl.h index 352cf8e..1578b17 100644 --- a/content/common/child_process_host_impl.h +++ b/content/common/child_process_host_impl.h @@ -88,9 +88,6 @@ class CONTENT_EXPORT ChildProcessHostImpl : public ChildProcessHost, void OnDeletedGpuMemoryBuffer(gfx::GpuMemoryBufferId id, uint32 sync_point); - void GpuMemoryBufferAllocated(IPC::Message* reply, - const gfx::GpuMemoryBufferHandle& handle); - ChildProcessHostDelegate* delegate_; base::Process peer_process_; bool opening_channel_; // True while we're waiting the channel to be opened. diff --git a/content/common/gpu/client/gpu_memory_buffer_factory_host.cc b/content/common/gpu/client/gpu_memory_buffer_factory_host.cc deleted file mode 100644 index ea7a321..0000000 --- a/content/common/gpu/client/gpu_memory_buffer_factory_host.cc +++ /dev/null @@ -1,27 +0,0 @@ -// 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. - -#include "content/common/gpu/client/gpu_memory_buffer_factory_host.h" - -#include "base/logging.h" - -namespace content { -namespace { -GpuMemoryBufferFactoryHost* instance = NULL; -} - -// static -GpuMemoryBufferFactoryHost* GpuMemoryBufferFactoryHost::GetInstance() { - return instance; -} - -GpuMemoryBufferFactoryHost::GpuMemoryBufferFactoryHost() { - DCHECK(instance == NULL); - instance = this; -} - -GpuMemoryBufferFactoryHost::~GpuMemoryBufferFactoryHost() { - instance = NULL; -} -} diff --git a/content/common/gpu/client/gpu_memory_buffer_factory_host.h b/content/common/gpu/client/gpu_memory_buffer_factory_host.h index 827308e..c206911 100644 --- a/content/common/gpu/client/gpu_memory_buffer_factory_host.h +++ b/content/common/gpu/client/gpu_memory_buffer_factory_host.h @@ -20,24 +20,22 @@ class CONTENT_EXPORT GpuMemoryBufferFactoryHost { typedef base::Callback<void(const gfx::GpuMemoryBufferHandle& handle)> CreateGpuMemoryBufferCallback; - static GpuMemoryBufferFactoryHost* GetInstance(); - + virtual bool IsGpuMemoryBufferConfigurationSupported( + gfx::GpuMemoryBuffer::Format format, + gfx::GpuMemoryBuffer::Usage usage) = 0; virtual void CreateGpuMemoryBuffer( - gfx::GpuMemoryBufferType type, gfx::GpuMemoryBufferId id, const gfx::Size& size, gfx::GpuMemoryBuffer::Format format, gfx::GpuMemoryBuffer::Usage usage, int client_id, const CreateGpuMemoryBufferCallback& callback) = 0; - virtual void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, + virtual void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, int client_id, int32 sync_point) = 0; protected: - GpuMemoryBufferFactoryHost(); - virtual ~GpuMemoryBufferFactoryHost(); + virtual ~GpuMemoryBufferFactoryHost() {} }; } // namespace content diff --git a/content/common/gpu/client/gpu_memory_buffer_impl.cc b/content/common/gpu/client/gpu_memory_buffer_impl.cc index 972ffa6..da8e438 100644 --- a/content/common/gpu/client/gpu_memory_buffer_impl.cc +++ b/content/common/gpu/client/gpu_memory_buffer_impl.cc @@ -4,28 +4,24 @@ #include "content/common/gpu/client/gpu_memory_buffer_impl.h" -#include "base/lazy_instance.h" #include "base/logging.h" +#include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h" #include "ui/gl/gl_bindings.h" -namespace content { -namespace { +#if defined(OS_MACOSX) +#include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h" +#endif -gfx::GpuMemoryBufferType g_preferred_type = gfx::EMPTY_BUFFER; +#if defined(OS_ANDROID) +#include "content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.h" +#endif -struct DefaultPreferredType { - DefaultPreferredType() : value(gfx::EMPTY_BUFFER) { - std::vector<gfx::GpuMemoryBufferType> supported_types; - GpuMemoryBufferImpl::GetSupportedTypes(&supported_types); - DCHECK(!supported_types.empty()); - value = supported_types[0]; - } - gfx::GpuMemoryBufferType value; -}; -base::LazyInstance<DefaultPreferredType> g_default_preferred_type = - LAZY_INSTANCE_INITIALIZER; +#if defined(USE_OZONE) +#include "content/common/gpu/client/gpu_memory_buffer_impl_ozone_native_buffer.h" +#endif + +namespace content { -} // namespace GpuMemoryBufferImpl::GpuMemoryBufferImpl(gfx::GpuMemoryBufferId id, const gfx::Size& size, @@ -44,23 +40,34 @@ GpuMemoryBufferImpl::~GpuMemoryBufferImpl() { } // static -void GpuMemoryBufferImpl::SetPreferredType(gfx::GpuMemoryBufferType type) { - // EMPTY_BUFFER is a reserved value and not a valid preferred type. - DCHECK_NE(gfx::EMPTY_BUFFER, type); - - // Make sure this function is only called once before the first call - // to GetPreferredType(). - DCHECK_EQ(gfx::EMPTY_BUFFER, g_preferred_type); - - g_preferred_type = type; -} - -// static -gfx::GpuMemoryBufferType GpuMemoryBufferImpl::GetPreferredType() { - if (g_preferred_type == gfx::EMPTY_BUFFER) - g_preferred_type = g_default_preferred_type.Get().value; - - return g_preferred_type; +scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImpl::CreateFromHandle( + const gfx::GpuMemoryBufferHandle& handle, + const gfx::Size& size, + Format format, + const DestructionCallback& callback) { + switch (handle.type) { + case gfx::SHARED_MEMORY_BUFFER: + return GpuMemoryBufferImplSharedMemory::CreateFromHandle( + handle, size, format, callback); +#if defined(OS_MACOSX) + case gfx::IO_SURFACE_BUFFER: + return GpuMemoryBufferImplIOSurface::CreateFromHandle( + handle, size, format, callback); +#endif +#if defined(OS_ANDROID) + case gfx::SURFACE_TEXTURE_BUFFER: + return GpuMemoryBufferImplSurfaceTexture::CreateFromHandle( + handle, size, format, callback); +#endif +#if defined(USE_OZONE) + case gfx::OZONE_NATIVE_BUFFER: + return GpuMemoryBufferImplOzoneNativeBuffer::CreateFromHandle( + handle, size, format, callback); +#endif + default: + NOTREACHED(); + return scoped_ptr<GpuMemoryBufferImpl>(); + } } // static diff --git a/content/common/gpu/client/gpu_memory_buffer_impl.h b/content/common/gpu/client/gpu_memory_buffer_impl.h index 5409c54..dc792246 100644 --- a/content/common/gpu/client/gpu_memory_buffer_impl.h +++ b/content/common/gpu/client/gpu_memory_buffer_impl.h @@ -5,8 +5,6 @@ #ifndef CONTENT_COMMON_GPU_CLIENT_GPU_MEMORY_BUFFER_IMPL_H_ #define CONTENT_COMMON_GPU_CLIENT_GPU_MEMORY_BUFFER_IMPL_H_ -#include <vector> - #include "base/callback.h" #include "base/memory/scoped_ptr.h" #include "content/common/content_export.h" @@ -18,61 +16,10 @@ namespace content { // Provides common implementation of a GPU memory buffer. class CONTENT_EXPORT GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { public: - typedef base::Callback<void(scoped_ptr<GpuMemoryBufferImpl> buffer)> - CreationCallback; - typedef base::Callback<void(const gfx::GpuMemoryBufferHandle& handle)> - AllocationCallback; typedef base::Callback<void(uint32 sync_point)> DestructionCallback; ~GpuMemoryBufferImpl() override; - // Gets system supported GPU memory buffer types. Preferred type at the front - // of vector. - static void GetSupportedTypes(std::vector<gfx::GpuMemoryBufferType>* types); - - // Sets the preferred GPU memory buffer type. This overrides the default - // preferred type. Can only be called once prior to GetPreferredType(). - // Caller is responsible for correct ordering. - static void SetPreferredType(gfx::GpuMemoryBufferType type); - - // Gets the preferred discardable memory type. - static gfx::GpuMemoryBufferType GetPreferredType(); - - // Returns true if |format| and |usage| is a supported configuration for - // |type|. |type| must be a supported GPU memory buffer type. - static bool IsConfigurationSupported(gfx::GpuMemoryBufferType type, - Format format, - Usage usage); - - // Creates a GPU memory buffer instance with |size| and |format| for |usage| - // by the current process and |client_id|. - static void Create(gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, - const gfx::Size& size, - Format format, - Usage usage, - int client_id, - const CreationCallback& callback); - - // Allocates a GPU memory buffer with |size| and |internalformat| for |usage| - // by |child_process| and |child_client_id|. The |handle| returned can be - // used by the |child_process| to create an instance of this class. - static void AllocateForChildProcess(gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, - const gfx::Size& size, - Format format, - Usage usage, - base::ProcessHandle child_process, - int child_client_id, - const AllocationCallback& callback); - - // Notify that GPU memory buffer has been deleted by |child_process|. - static void DeletedByChildProcess(gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, - base::ProcessHandle child_process, - int child_client_id, - uint32 sync_point); - // Creates an instance from the given |handle|. |size| and |internalformat| // should match what was used to allocate the |handle|. |callback| is // called when instance is deleted, which is not necessarily on the same diff --git a/content/common/gpu/client/gpu_memory_buffer_impl_android.cc b/content/common/gpu/client/gpu_memory_buffer_impl_android.cc deleted file mode 100644 index cc82b06..0000000 --- a/content/common/gpu/client/gpu_memory_buffer_impl_android.cc +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright 2013 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. - -#include "content/common/gpu/client/gpu_memory_buffer_impl.h" - -#include "base/logging.h" -#include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h" -#include "content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.h" - -namespace content { - -// static -void GpuMemoryBufferImpl::GetSupportedTypes( - std::vector<gfx::GpuMemoryBufferType>* types) { - const gfx::GpuMemoryBufferType supported_types[] = { - gfx::SURFACE_TEXTURE_BUFFER, - gfx::SHARED_MEMORY_BUFFER - }; - types->assign(supported_types, supported_types + arraysize(supported_types)); -} - -// static -bool GpuMemoryBufferImpl::IsConfigurationSupported( - gfx::GpuMemoryBufferType type, - Format format, - Usage usage) { - switch (type) { - case gfx::SHARED_MEMORY_BUFFER: - return GpuMemoryBufferImplSharedMemory::IsFormatSupported(format) && - GpuMemoryBufferImplSharedMemory::IsUsageSupported(usage); - case gfx::SURFACE_TEXTURE_BUFFER: - return GpuMemoryBufferImplSurfaceTexture::IsFormatSupported(format) && - GpuMemoryBufferImplSurfaceTexture::IsUsageSupported(usage); - default: - NOTREACHED(); - return false; - } -} - -// static -void GpuMemoryBufferImpl::Create(gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, - const gfx::Size& size, - Format format, - Usage usage, - int client_id, - const CreationCallback& callback) { - switch (type) { - case gfx::SHARED_MEMORY_BUFFER: - GpuMemoryBufferImplSharedMemory::Create(id, size, format, callback); - break; - case gfx::SURFACE_TEXTURE_BUFFER: - GpuMemoryBufferImplSurfaceTexture::Create( - id, size, format, client_id, callback); - break; - default: - NOTREACHED(); - break; - } -} - -// static -void GpuMemoryBufferImpl::AllocateForChildProcess( - gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, - const gfx::Size& size, - Format format, - Usage usage, - base::ProcessHandle child_process, - int child_client_id, - const AllocationCallback& callback) { - switch (type) { - case gfx::SHARED_MEMORY_BUFFER: - GpuMemoryBufferImplSharedMemory::AllocateForChildProcess( - id, size, format, child_process, callback); - break; - case gfx::SURFACE_TEXTURE_BUFFER: - GpuMemoryBufferImplSurfaceTexture::AllocateForChildProcess( - id, size, format, child_client_id, callback); - break; - default: - NOTREACHED(); - break; - } -} - -// static -void GpuMemoryBufferImpl::DeletedByChildProcess( - gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, - base::ProcessHandle child_process, - int child_client_id, - uint32 sync_point) { - switch (type) { - case gfx::SHARED_MEMORY_BUFFER: - break; - case gfx::SURFACE_TEXTURE_BUFFER: - GpuMemoryBufferImplSurfaceTexture::DeletedByChildProcess( - id, child_client_id, sync_point); - break; - default: - NOTREACHED(); - break; - } -} - -// static -scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImpl::CreateFromHandle( - const gfx::GpuMemoryBufferHandle& handle, - const gfx::Size& size, - Format format, - const DestructionCallback& callback) { - switch (handle.type) { - case gfx::SHARED_MEMORY_BUFFER: - return GpuMemoryBufferImplSharedMemory::CreateFromHandle( - handle, size, format, callback); - case gfx::SURFACE_TEXTURE_BUFFER: - return GpuMemoryBufferImplSurfaceTexture::CreateFromHandle( - handle, size, format, callback); - default: - NOTREACHED(); - return scoped_ptr<GpuMemoryBufferImpl>(); - } -} - -} // namespace content diff --git a/content/common/gpu/client/gpu_memory_buffer_impl_io_surface.cc b/content/common/gpu/client/gpu_memory_buffer_impl_io_surface.cc index 51855d3..e8ac048 100644 --- a/content/common/gpu/client/gpu_memory_buffer_impl_io_surface.cc +++ b/content/common/gpu/client/gpu_memory_buffer_impl_io_surface.cc @@ -4,49 +4,9 @@ #include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h" -#include "base/bind.h" #include "base/logging.h" -#include "content/common/gpu/client/gpu_memory_buffer_factory_host.h" -#include "ui/gl/gl_bindings.h" namespace content { -namespace { - -void GpuMemoryBufferDeleted(gfx::GpuMemoryBufferId id, - int client_id, - uint32 sync_point) { - GpuMemoryBufferFactoryHost::GetInstance()->DestroyGpuMemoryBuffer( - gfx::IO_SURFACE_BUFFER, id, client_id, sync_point); -} - -void GpuMemoryBufferCreated( - const gfx::Size& size, - gfx::GpuMemoryBuffer::Format format, - int client_id, - const GpuMemoryBufferImpl::CreationCallback& callback, - const gfx::GpuMemoryBufferHandle& handle) { - if (handle.is_null()) { - callback.Run(scoped_ptr<GpuMemoryBufferImpl>()); - return; - } - - DCHECK_EQ(gfx::IO_SURFACE_BUFFER, handle.type); - callback.Run(GpuMemoryBufferImplIOSurface::CreateFromHandle( - handle, - size, - format, - base::Bind(&GpuMemoryBufferDeleted, handle.id, client_id))); -} - -void GpuMemoryBufferCreatedForChildProcess( - const GpuMemoryBufferImpl::AllocationCallback& callback, - const gfx::GpuMemoryBufferHandle& handle) { - DCHECK_IMPLIES(!handle.is_null(), gfx::IO_SURFACE_BUFFER == handle.type); - - callback.Run(handle); -} - -} // namespace GpuMemoryBufferImplIOSurface::GpuMemoryBufferImplIOSurface( gfx::GpuMemoryBufferId id, @@ -61,46 +21,11 @@ GpuMemoryBufferImplIOSurface::~GpuMemoryBufferImplIOSurface() { } // static -void GpuMemoryBufferImplIOSurface::Create(gfx::GpuMemoryBufferId id, - const gfx::Size& size, - Format format, - int client_id, - const CreationCallback& callback) { - GpuMemoryBufferFactoryHost::GetInstance()->CreateGpuMemoryBuffer( - gfx::IO_SURFACE_BUFFER, - id, - size, - format, - MAP, - client_id, - base::Bind(&GpuMemoryBufferCreated, size, format, client_id, callback)); -} - -// static -void GpuMemoryBufferImplIOSurface::AllocateForChildProcess( - gfx::GpuMemoryBufferId id, - const gfx::Size& size, - Format format, - int child_client_id, - const AllocationCallback& callback) { - GpuMemoryBufferFactoryHost::GetInstance()->CreateGpuMemoryBuffer( - gfx::IO_SURFACE_BUFFER, - id, - size, - format, - MAP, - child_client_id, - base::Bind(&GpuMemoryBufferCreatedForChildProcess, callback)); -} - -// static scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImplIOSurface::CreateFromHandle( const gfx::GpuMemoryBufferHandle& handle, const gfx::Size& size, Format format, const DestructionCallback& callback) { - DCHECK(IsFormatSupported(format)); - base::ScopedCFTypeRef<IOSurfaceRef> io_surface( IOSurfaceLookup(handle.io_surface_id)); if (!io_surface) @@ -110,42 +35,6 @@ scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImplIOSurface::CreateFromHandle( handle.id, size, format, callback, io_surface.release())); } -// static -void GpuMemoryBufferImplIOSurface::DeletedByChildProcess( - gfx::GpuMemoryBufferId id, - int child_client_id, - uint32_t sync_point) { - GpuMemoryBufferFactoryHost::GetInstance()->DestroyGpuMemoryBuffer( - gfx::IO_SURFACE_BUFFER, id, child_client_id, sync_point); -} - -// static -bool GpuMemoryBufferImplIOSurface::IsFormatSupported(Format format) { - switch (format) { - case BGRA_8888: - return true; - case RGBA_8888: - case RGBX_8888: - return false; - } - - NOTREACHED(); - return false; -} - -// static -bool GpuMemoryBufferImplIOSurface::IsUsageSupported(Usage usage) { - switch (usage) { - case MAP: - return true; - case SCANOUT: - return false; - } - - NOTREACHED(); - return false; -} - void* GpuMemoryBufferImplIOSurface::Map() { DCHECK(!mapped_); IOSurfaceLock(io_surface_, 0, NULL); diff --git a/content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h b/content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h index 3181571..d9db52f 100644 --- a/content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h +++ b/content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h @@ -15,31 +15,12 @@ namespace content { // Implementation of GPU memory buffer based on IO surfaces. class GpuMemoryBufferImplIOSurface : public GpuMemoryBufferImpl { public: - static void Create(gfx::GpuMemoryBufferId id, - const gfx::Size& size, - Format format, - int client_id, - const CreationCallback& callback); - - static void AllocateForChildProcess(gfx::GpuMemoryBufferId id, - const gfx::Size& size, - Format format, - int child_client_id, - const AllocationCallback& callback); - static scoped_ptr<GpuMemoryBufferImpl> CreateFromHandle( const gfx::GpuMemoryBufferHandle& handle, const gfx::Size& size, Format format, const DestructionCallback& callback); - static void DeletedByChildProcess(gfx::GpuMemoryBufferId id, - int child_client_id, - uint32_t sync_point); - - static bool IsFormatSupported(Format format); - static bool IsUsageSupported(Usage usage); - // Overridden from gfx::GpuMemoryBuffer: void* Map() override; void Unmap() override; diff --git a/content/common/gpu/client/gpu_memory_buffer_impl_linux.cc b/content/common/gpu/client/gpu_memory_buffer_impl_linux.cc deleted file mode 100644 index ef50898..0000000 --- a/content/common/gpu/client/gpu_memory_buffer_impl_linux.cc +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright 2013 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. - -#include "content/common/gpu/client/gpu_memory_buffer_impl.h" - -#include "base/logging.h" -#include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h" - -namespace content { - -// static -void GpuMemoryBufferImpl::GetSupportedTypes( - std::vector<gfx::GpuMemoryBufferType>* types) { - const gfx::GpuMemoryBufferType supported_types[] = { - gfx::SHARED_MEMORY_BUFFER - }; - types->assign(supported_types, supported_types + arraysize(supported_types)); -} - -// static -bool GpuMemoryBufferImpl::IsConfigurationSupported( - gfx::GpuMemoryBufferType type, - Format format, - Usage usage) { - switch (type) { - case gfx::SHARED_MEMORY_BUFFER: - return GpuMemoryBufferImplSharedMemory::IsFormatSupported(format) && - GpuMemoryBufferImplSharedMemory::IsUsageSupported(usage); - default: - NOTREACHED(); - return false; - } -} - -// static -void GpuMemoryBufferImpl::Create(gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, - const gfx::Size& size, - Format format, - Usage usage, - int client_id, - const CreationCallback& callback) { - switch (type) { - case gfx::SHARED_MEMORY_BUFFER: - GpuMemoryBufferImplSharedMemory::Create(id, size, format, callback); - break; - default: - NOTREACHED(); - break; - } -} - -// static -void GpuMemoryBufferImpl::AllocateForChildProcess( - gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, - const gfx::Size& size, - Format format, - Usage usage, - base::ProcessHandle child_process, - int child_client_id, - const AllocationCallback& callback) { - switch (type) { - case gfx::SHARED_MEMORY_BUFFER: - GpuMemoryBufferImplSharedMemory::AllocateForChildProcess( - id, size, format, child_process, callback); - break; - default: - NOTREACHED(); - break; - } -} - -// static -void GpuMemoryBufferImpl::DeletedByChildProcess( - gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, - base::ProcessHandle child_process, - int child_client_id, - uint32 sync_point) { - switch (type) { - case gfx::SHARED_MEMORY_BUFFER: - break; - default: - NOTREACHED(); - break; - } -} - -// static -scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImpl::CreateFromHandle( - const gfx::GpuMemoryBufferHandle& handle, - const gfx::Size& size, - Format format, - const DestructionCallback& callback) { - switch (handle.type) { - case gfx::SHARED_MEMORY_BUFFER: - return GpuMemoryBufferImplSharedMemory::CreateFromHandle( - handle, size, format, callback); - default: - NOTREACHED(); - return scoped_ptr<GpuMemoryBufferImpl>(); - } -} - -} // namespace content diff --git a/content/common/gpu/client/gpu_memory_buffer_impl_mac.cc b/content/common/gpu/client/gpu_memory_buffer_impl_mac.cc deleted file mode 100644 index 478d7c9..0000000 --- a/content/common/gpu/client/gpu_memory_buffer_impl_mac.cc +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright 2013 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. - -#include "content/common/gpu/client/gpu_memory_buffer_impl.h" - -#include "base/logging.h" -#include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h" -#include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h" - -namespace content { - -// static -void GpuMemoryBufferImpl::GetSupportedTypes( - std::vector<gfx::GpuMemoryBufferType>* types) { - const gfx::GpuMemoryBufferType supported_types[] = { - gfx::IO_SURFACE_BUFFER, - gfx::SHARED_MEMORY_BUFFER - }; - types->assign(supported_types, supported_types + arraysize(supported_types)); -} - -// static -bool GpuMemoryBufferImpl::IsConfigurationSupported( - gfx::GpuMemoryBufferType type, - Format format, - Usage usage) { - switch (type) { - case gfx::SHARED_MEMORY_BUFFER: - return GpuMemoryBufferImplSharedMemory::IsFormatSupported(format) && - GpuMemoryBufferImplSharedMemory::IsUsageSupported(usage); - case gfx::IO_SURFACE_BUFFER: - return GpuMemoryBufferImplIOSurface::IsFormatSupported(format) && - GpuMemoryBufferImplIOSurface::IsUsageSupported(usage); - default: - NOTREACHED(); - return false; - } -} - -// static -void GpuMemoryBufferImpl::Create(gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, - const gfx::Size& size, - Format format, - Usage usage, - int client_id, - const CreationCallback& callback) { - switch (type) { - case gfx::SHARED_MEMORY_BUFFER: - GpuMemoryBufferImplSharedMemory::Create(id, size, format, callback); - break; - case gfx::IO_SURFACE_BUFFER: - GpuMemoryBufferImplIOSurface::Create( - id, size, format, client_id, callback); - break; - default: - NOTREACHED(); - break; - } -} - -// static -void GpuMemoryBufferImpl::AllocateForChildProcess( - gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, - const gfx::Size& size, - Format format, - Usage usage, - base::ProcessHandle child_process, - int child_client_id, - const AllocationCallback& callback) { - switch (type) { - case gfx::SHARED_MEMORY_BUFFER: - GpuMemoryBufferImplSharedMemory::AllocateForChildProcess( - id, size, format, child_process, callback); - break; - case gfx::IO_SURFACE_BUFFER: - GpuMemoryBufferImplIOSurface::AllocateForChildProcess( - id, size, format, child_client_id, callback); - break; - default: - NOTREACHED(); - break; - } -} - -// static -void GpuMemoryBufferImpl::DeletedByChildProcess( - gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, - base::ProcessHandle child_process, - int child_client_id, - uint32 sync_point) { - switch (type) { - case gfx::SHARED_MEMORY_BUFFER: - break; - case gfx::IO_SURFACE_BUFFER: - GpuMemoryBufferImplIOSurface::DeletedByChildProcess( - id, child_client_id, sync_point); - break; - default: - NOTREACHED(); - break; - } -} - -// static -scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImpl::CreateFromHandle( - const gfx::GpuMemoryBufferHandle& handle, - const gfx::Size& size, - Format format, - const DestructionCallback& callback) { - switch (handle.type) { - case gfx::SHARED_MEMORY_BUFFER: - return GpuMemoryBufferImplSharedMemory::CreateFromHandle( - handle, size, format, callback); - case gfx::IO_SURFACE_BUFFER: - return GpuMemoryBufferImplIOSurface::CreateFromHandle( - handle, size, format, callback); - default: - NOTREACHED(); - return scoped_ptr<GpuMemoryBufferImpl>(); - } -} - -} // namespace content diff --git a/content/common/gpu/client/gpu_memory_buffer_impl_ozone.cc b/content/common/gpu/client/gpu_memory_buffer_impl_ozone.cc deleted file mode 100644 index ac00380..0000000 --- a/content/common/gpu/client/gpu_memory_buffer_impl_ozone.cc +++ /dev/null @@ -1,126 +0,0 @@ -// 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. - -#include "content/common/gpu/client/gpu_memory_buffer_impl.h" - -#include "content/common/gpu/client/gpu_memory_buffer_impl_ozone_native_buffer.h" -#include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h" - -namespace content { - -// static -void GpuMemoryBufferImpl::GetSupportedTypes( - std::vector<gfx::GpuMemoryBufferType>* types) { - const gfx::GpuMemoryBufferType supported_types[] = { - gfx::OZONE_NATIVE_BUFFER, - gfx::SHARED_MEMORY_BUFFER - }; - types->assign(supported_types, supported_types + arraysize(supported_types)); -} - -// static -bool GpuMemoryBufferImpl::IsConfigurationSupported( - gfx::GpuMemoryBufferType type, - Format format, - Usage usage) { - switch (type) { - case gfx::SHARED_MEMORY_BUFFER: - return GpuMemoryBufferImplSharedMemory::IsFormatSupported(format) && - GpuMemoryBufferImplSharedMemory::IsUsageSupported(usage); - case gfx::OZONE_NATIVE_BUFFER: - return GpuMemoryBufferImplOzoneNativeBuffer::IsFormatSupported(format) && - GpuMemoryBufferImplOzoneNativeBuffer::IsUsageSupported(usage); - default: - NOTREACHED(); - return false; - } -} - -// static -void GpuMemoryBufferImpl::Create(gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, - const gfx::Size& size, - Format format, - Usage usage, - int client_id, - const CreationCallback& callback) { - switch (type) { - case gfx::SHARED_MEMORY_BUFFER: - GpuMemoryBufferImplSharedMemory::Create(id, size, format, callback); - break; - case gfx::OZONE_NATIVE_BUFFER: - GpuMemoryBufferImplOzoneNativeBuffer::Create( - id, size, format, client_id, callback); - break; - default: - NOTREACHED(); - break; - } -} - -// static -void GpuMemoryBufferImpl::AllocateForChildProcess( - gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, - const gfx::Size& size, - Format format, - Usage usage, - base::ProcessHandle child_process, - int child_client_id, - const AllocationCallback& callback) { - switch (type) { - case gfx::SHARED_MEMORY_BUFFER: - GpuMemoryBufferImplSharedMemory::AllocateForChildProcess( - id, size, format, child_process, callback); - break; - case gfx::OZONE_NATIVE_BUFFER: - GpuMemoryBufferImplOzoneNativeBuffer::AllocateForChildProcess( - id, size, format, child_client_id, callback); - break; - default: - NOTREACHED(); - break; - } -} - -// static -void GpuMemoryBufferImpl::DeletedByChildProcess( - gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, - base::ProcessHandle child_process, - int child_client_id, - uint32_t sync_point) { - switch (type) { - case gfx::SHARED_MEMORY_BUFFER: - break; - case gfx::OZONE_NATIVE_BUFFER: - GpuMemoryBufferImplOzoneNativeBuffer::DeletedByChildProcess( - id, child_client_id, sync_point); - break; - default: - NOTREACHED(); - break; - } -} - -// static -scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImpl::CreateFromHandle( - const gfx::GpuMemoryBufferHandle& handle, - const gfx::Size& size, - Format format, - const DestructionCallback& callback) { - switch (handle.type) { - case gfx::SHARED_MEMORY_BUFFER: - return GpuMemoryBufferImplSharedMemory::CreateFromHandle( - handle, size, format, callback); - case gfx::OZONE_NATIVE_BUFFER: - return GpuMemoryBufferImplOzoneNativeBuffer::CreateFromHandle( - handle, size, format, callback); - default: - NOTREACHED(); - return scoped_ptr<GpuMemoryBufferImpl>(); - } -} - -} // namespace content diff --git a/content/common/gpu/client/gpu_memory_buffer_impl_ozone_native_buffer.cc b/content/common/gpu/client/gpu_memory_buffer_impl_ozone_native_buffer.cc index 0747cea..24dfb3f 100644 --- a/content/common/gpu/client/gpu_memory_buffer_impl_ozone_native_buffer.cc +++ b/content/common/gpu/client/gpu_memory_buffer_impl_ozone_native_buffer.cc @@ -4,49 +4,9 @@ #include "content/common/gpu/client/gpu_memory_buffer_impl_ozone_native_buffer.h" -#include "base/bind.h" -#include "content/common/gpu/client/gpu_memory_buffer_factory_host.h" -#include "ui/gl/gl_bindings.h" #include "ui/ozone/public/surface_factory_ozone.h" namespace content { -namespace { - -void GpuMemoryBufferDeleted(gfx::GpuMemoryBufferId id, - int client_id, - uint32 sync_point) { - GpuMemoryBufferFactoryHost::GetInstance()->DestroyGpuMemoryBuffer( - gfx::OZONE_NATIVE_BUFFER, id, client_id, sync_point); -} - -void GpuMemoryBufferCreated( - const gfx::Size& size, - gfx::GpuMemoryBuffer::Format format, - int client_id, - const GpuMemoryBufferImpl::CreationCallback& callback, - const gfx::GpuMemoryBufferHandle& handle) { - if (handle.is_null()) { - callback.Run(scoped_ptr<GpuMemoryBufferImpl>()); - return; - } - - DCHECK_EQ(gfx::OZONE_NATIVE_BUFFER, handle.type); - callback.Run(GpuMemoryBufferImplOzoneNativeBuffer::CreateFromHandle( - handle, - size, - format, - base::Bind(&GpuMemoryBufferDeleted, handle.id, client_id))); -} - -void GpuMemoryBufferCreatedForChildProcess( - const GpuMemoryBufferImpl::AllocationCallback& callback, - const gfx::GpuMemoryBufferHandle& handle) { - DCHECK_IMPLIES(!handle.is_null(), gfx::OZONE_NATIVE_BUFFER == handle.type); - - callback.Run(handle); -} - -} // namespace GpuMemoryBufferImplOzoneNativeBuffer::GpuMemoryBufferImplOzoneNativeBuffer( gfx::GpuMemoryBufferId id, @@ -60,90 +20,17 @@ GpuMemoryBufferImplOzoneNativeBuffer::~GpuMemoryBufferImplOzoneNativeBuffer() { } // static -void GpuMemoryBufferImplOzoneNativeBuffer::Create( - gfx::GpuMemoryBufferId id, - const gfx::Size& size, - Format format, - int client_id, - const CreationCallback& callback) { - GpuMemoryBufferFactoryHost::GetInstance()->CreateGpuMemoryBuffer( - gfx::OZONE_NATIVE_BUFFER, - id, - size, - format, - SCANOUT, - client_id, - base::Bind(&GpuMemoryBufferCreated, size, format, client_id, callback)); -} - -// static -void GpuMemoryBufferImplOzoneNativeBuffer::AllocateForChildProcess( - gfx::GpuMemoryBufferId id, - const gfx::Size& size, - Format format, - int child_client_id, - const AllocationCallback& callback) { - GpuMemoryBufferFactoryHost::GetInstance()->CreateGpuMemoryBuffer( - gfx::OZONE_NATIVE_BUFFER, - id, - size, - format, - SCANOUT, - child_client_id, - base::Bind(&GpuMemoryBufferCreatedForChildProcess, callback)); -} - -// static scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImplOzoneNativeBuffer::CreateFromHandle( const gfx::GpuMemoryBufferHandle& handle, const gfx::Size& size, Format format, const DestructionCallback& callback) { - DCHECK(IsFormatSupported(format)); - return make_scoped_ptr<GpuMemoryBufferImpl>( new GpuMemoryBufferImplOzoneNativeBuffer( handle.id, size, format, callback)); } -// static -void GpuMemoryBufferImplOzoneNativeBuffer::DeletedByChildProcess( - gfx::GpuMemoryBufferId id, - int child_client_id, - uint32_t sync_point) { - GpuMemoryBufferFactoryHost::GetInstance()->DestroyGpuMemoryBuffer( - gfx::OZONE_NATIVE_BUFFER, id, child_client_id, sync_point); -} - -// static -bool GpuMemoryBufferImplOzoneNativeBuffer::IsFormatSupported(Format format) { - switch (format) { - case RGBA_8888: - case RGBX_8888: - return true; - case BGRA_8888: - return false; - } - - NOTREACHED(); - return false; -} - -// static -bool GpuMemoryBufferImplOzoneNativeBuffer::IsUsageSupported(Usage usage) { - switch (usage) { - case MAP: - return false; - case SCANOUT: - return ui::SurfaceFactoryOzone::GetInstance()->CanCreateNativePixmap( - ui::SurfaceFactoryOzone::SCANOUT); - } - - NOTREACHED(); - return false; -} - void* GpuMemoryBufferImplOzoneNativeBuffer::Map() { NOTREACHED(); return NULL; diff --git a/content/common/gpu/client/gpu_memory_buffer_impl_ozone_native_buffer.h b/content/common/gpu/client/gpu_memory_buffer_impl_ozone_native_buffer.h index 296d8b2..d88e070 100644 --- a/content/common/gpu/client/gpu_memory_buffer_impl_ozone_native_buffer.h +++ b/content/common/gpu/client/gpu_memory_buffer_impl_ozone_native_buffer.h @@ -12,31 +12,12 @@ namespace content { // Implementation of GPU memory buffer based on Ozone native buffers. class GpuMemoryBufferImplOzoneNativeBuffer : public GpuMemoryBufferImpl { public: - static void Create(gfx::GpuMemoryBufferId id, - const gfx::Size& size, - Format format, - int client_id, - const CreationCallback& callback); - - static void AllocateForChildProcess(gfx::GpuMemoryBufferId id, - const gfx::Size& size, - Format format, - int child_client_id, - const AllocationCallback& callback); - static scoped_ptr<GpuMemoryBufferImpl> CreateFromHandle( const gfx::GpuMemoryBufferHandle& handle, const gfx::Size& size, Format format, const DestructionCallback& callback); - static void DeletedByChildProcess(gfx::GpuMemoryBufferId id, - int child_client_id, - uint32_t sync_point); - - static bool IsFormatSupported(Format format); - static bool IsUsageSupported(Usage usage); - // Overridden from gfx::GpuMemoryBuffer: void* Map() override; void Unmap() override; diff --git a/content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.cc b/content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.cc index 9adca18..5572c1f 100644 --- a/content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.cc +++ b/content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.cc @@ -30,49 +30,40 @@ GpuMemoryBufferImplSharedMemory::~GpuMemoryBufferImplSharedMemory() { } // static -void GpuMemoryBufferImplSharedMemory::Create(gfx::GpuMemoryBufferId id, - const gfx::Size& size, - Format format, - const CreationCallback& callback) { - DCHECK(IsFormatSupported(format)); - +scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImplSharedMemory::Create( + gfx::GpuMemoryBufferId id, + const gfx::Size& size, + Format format) { scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); - if (!shared_memory->CreateAnonymous(size.GetArea() * BytesPerPixel(format))) { - callback.Run(scoped_ptr<GpuMemoryBufferImpl>()); - return; - } + if (!shared_memory->CreateAnonymous(size.GetArea() * BytesPerPixel(format))) + return scoped_ptr<GpuMemoryBufferImpl>(); - callback.Run( - make_scoped_ptr<GpuMemoryBufferImpl>(new GpuMemoryBufferImplSharedMemory( - id, size, format, base::Bind(&Noop), shared_memory.Pass()))); + return make_scoped_ptr(new GpuMemoryBufferImplSharedMemory( + id, size, format, base::Bind(&Noop), shared_memory.Pass())); } // static -void GpuMemoryBufferImplSharedMemory::AllocateForChildProcess( +gfx::GpuMemoryBufferHandle +GpuMemoryBufferImplSharedMemory::AllocateForChildProcess( gfx::GpuMemoryBufferId id, const gfx::Size& size, Format format, - base::ProcessHandle child_process, - const AllocationCallback& callback) { - DCHECK(IsFormatSupported(format)); - + base::ProcessHandle child_process) { base::CheckedNumeric<int> buffer_size = size.width(); buffer_size *= size.height(); buffer_size *= BytesPerPixel(format); - if (!buffer_size.IsValid()) { - callback.Run(gfx::GpuMemoryBufferHandle()); - return; - } + if (!buffer_size.IsValid()) + return gfx::GpuMemoryBufferHandle(); + base::SharedMemory shared_memory; - if (!shared_memory.CreateAnonymous(buffer_size.ValueOrDie())) { - callback.Run(gfx::GpuMemoryBufferHandle()); - return; - } + if (!shared_memory.CreateAnonymous(buffer_size.ValueOrDie())) + return gfx::GpuMemoryBufferHandle(); + gfx::GpuMemoryBufferHandle handle; handle.type = gfx::SHARED_MEMORY_BUFFER; handle.id = id; shared_memory.GiveToProcess(child_process, &handle.handle); - callback.Run(handle); + return handle; } // static @@ -82,8 +73,6 @@ GpuMemoryBufferImplSharedMemory::CreateFromHandle( const gfx::Size& size, Format format, const DestructionCallback& callback) { - DCHECK(IsFormatSupported(format)); - if (!base::SharedMemory::IsHandleValid(handle.handle)) return scoped_ptr<GpuMemoryBufferImpl>(); @@ -110,19 +99,6 @@ bool GpuMemoryBufferImplSharedMemory::IsFormatSupported(Format format) { return false; } -// static -bool GpuMemoryBufferImplSharedMemory::IsUsageSupported(Usage usage) { - switch (usage) { - case MAP: - return true; - case SCANOUT: - return false; - } - - NOTREACHED(); - return false; -} - void* GpuMemoryBufferImplSharedMemory::Map() { DCHECK(!mapped_); if (!shared_memory_->Map(size_.GetArea() * BytesPerPixel(format_))) diff --git a/content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h b/content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h index c8b4967..e76e317 100644 --- a/content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h +++ b/content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h @@ -12,16 +12,17 @@ namespace content { // Implementation of GPU memory buffer based on shared memory. class GpuMemoryBufferImplSharedMemory : public GpuMemoryBufferImpl { public: - static void Create(gfx::GpuMemoryBufferId id, - const gfx::Size& size, - Format format, - const CreationCallback& callback); + ~GpuMemoryBufferImplSharedMemory() override; - static void AllocateForChildProcess(gfx::GpuMemoryBufferId id, - const gfx::Size& size, - Format format, - base::ProcessHandle child_process, - const AllocationCallback& callback); + static scoped_ptr<GpuMemoryBufferImpl> Create(gfx::GpuMemoryBufferId id, + const gfx::Size& size, + Format format); + + static gfx::GpuMemoryBufferHandle AllocateForChildProcess( + gfx::GpuMemoryBufferId id, + const gfx::Size& size, + Format format, + base::ProcessHandle child_process); static scoped_ptr<GpuMemoryBufferImpl> CreateFromHandle( const gfx::GpuMemoryBufferHandle& handle, @@ -30,7 +31,6 @@ class GpuMemoryBufferImplSharedMemory : public GpuMemoryBufferImpl { const DestructionCallback& callback); static bool IsFormatSupported(Format format); - static bool IsUsageSupported(Usage usage); // Overridden from gfx::GpuMemoryBuffer: void* Map() override; @@ -44,7 +44,6 @@ class GpuMemoryBufferImplSharedMemory : public GpuMemoryBufferImpl { Format format, const DestructionCallback& callback, scoped_ptr<base::SharedMemory> shared_memory); - ~GpuMemoryBufferImplSharedMemory() override; scoped_ptr<base::SharedMemory> shared_memory_; diff --git a/content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.cc b/content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.cc index 4ec2b79..401d37a 100644 --- a/content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.cc +++ b/content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.cc @@ -4,48 +4,26 @@ #include "content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.h" -#include "base/bind.h" #include "base/debug/trace_event.h" #include "base/logging.h" #include "content/common/android/surface_texture_manager.h" -#include "content/common/gpu/client/gpu_memory_buffer_factory_host.h" #include "ui/gl/gl_bindings.h" namespace content { namespace { -void GpuMemoryBufferDeleted(gfx::GpuMemoryBufferId id, - int client_id, - uint32 sync_point) { - GpuMemoryBufferFactoryHost::GetInstance()->DestroyGpuMemoryBuffer( - gfx::SURFACE_TEXTURE_BUFFER, id, client_id, sync_point); -} - -void GpuMemoryBufferCreated( - const gfx::Size& size, - gfx::GpuMemoryBuffer::Format format, - int client_id, - const GpuMemoryBufferImpl::CreationCallback& callback, - const gfx::GpuMemoryBufferHandle& handle) { - if (handle.is_null()) { - callback.Run(scoped_ptr<GpuMemoryBufferImpl>()); - return; +int WindowFormat(gfx::GpuMemoryBuffer::Format format) { + switch (format) { + case gfx::GpuMemoryBuffer::RGBA_8888: + return WINDOW_FORMAT_RGBA_8888; + case gfx::GpuMemoryBuffer::RGBX_8888: + case gfx::GpuMemoryBuffer::BGRA_8888: + NOTREACHED(); + return 0; } - DCHECK_EQ(gfx::SURFACE_TEXTURE_BUFFER, handle.type); - callback.Run(GpuMemoryBufferImplSurfaceTexture::CreateFromHandle( - handle, - size, - format, - base::Bind(&GpuMemoryBufferDeleted, handle.id, client_id))); -} - -void GpuMemoryBufferCreatedForChildProcess( - const GpuMemoryBufferImpl::AllocationCallback& callback, - const gfx::GpuMemoryBufferHandle& handle) { - DCHECK_IMPLIES(!handle.is_null(), gfx::SURFACE_TEXTURE_BUFFER == handle.type); - - callback.Run(handle); + NOTREACHED(); + return 0; } } // namespace @@ -66,48 +44,12 @@ GpuMemoryBufferImplSurfaceTexture::~GpuMemoryBufferImplSurfaceTexture() { } // static -void GpuMemoryBufferImplSurfaceTexture::Create( - gfx::GpuMemoryBufferId id, - const gfx::Size& size, - Format format, - int client_id, - const CreationCallback& callback) { - GpuMemoryBufferFactoryHost::GetInstance()->CreateGpuMemoryBuffer( - gfx::SURFACE_TEXTURE_BUFFER, - id, - size, - format, - MAP, - client_id, - base::Bind(&GpuMemoryBufferCreated, size, format, client_id, callback)); -} - -// static -void GpuMemoryBufferImplSurfaceTexture::AllocateForChildProcess( - gfx::GpuMemoryBufferId id, - const gfx::Size& size, - Format format, - int child_client_id, - const AllocationCallback& callback) { - GpuMemoryBufferFactoryHost::GetInstance()->CreateGpuMemoryBuffer( - gfx::SURFACE_TEXTURE_BUFFER, - id, - size, - format, - MAP, - child_client_id, - base::Bind(&GpuMemoryBufferCreatedForChildProcess, callback)); -} - -// static scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImplSurfaceTexture::CreateFromHandle( const gfx::GpuMemoryBufferHandle& handle, const gfx::Size& size, Format format, const DestructionCallback& callback) { - DCHECK(IsFormatSupported(format)); - ANativeWindow* native_window = SurfaceTextureManager::GetInstance()-> AcquireNativeWidgetForSurfaceTexture(handle.id); if (!native_window) @@ -121,57 +63,6 @@ GpuMemoryBufferImplSurfaceTexture::CreateFromHandle( handle.id, size, format, callback, native_window)); } -// static -void GpuMemoryBufferImplSurfaceTexture::DeletedByChildProcess( - gfx::GpuMemoryBufferId id, - int child_client_id, - uint32_t sync_point) { - GpuMemoryBufferFactoryHost::GetInstance()->DestroyGpuMemoryBuffer( - gfx::SURFACE_TEXTURE_BUFFER, id, child_client_id, sync_point); -} - -// static -bool GpuMemoryBufferImplSurfaceTexture::IsFormatSupported(Format format) { - switch (format) { - case RGBA_8888: - return true; - case RGBX_8888: - case BGRA_8888: - return false; - } - - NOTREACHED(); - return false; -} - -// static -bool GpuMemoryBufferImplSurfaceTexture::IsUsageSupported(Usage usage) { - switch (usage) { - case MAP: - return true; - case SCANOUT: - return false; - } - - NOTREACHED(); - return false; -} - -// static -int GpuMemoryBufferImplSurfaceTexture::WindowFormat(Format format) { - switch (format) { - case RGBA_8888: - return WINDOW_FORMAT_RGBA_8888; - case RGBX_8888: - case BGRA_8888: - NOTREACHED(); - return 0; - } - - NOTREACHED(); - return 0; -} - void* GpuMemoryBufferImplSurfaceTexture::Map() { TRACE_EVENT0("gpu", "GpuMemoryBufferImplSurfaceTexture::Map"); diff --git a/content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.h b/content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.h index 80c6742..683aea7 100644 --- a/content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.h +++ b/content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.h @@ -14,31 +14,12 @@ namespace content { // Implementation of GPU memory buffer based on SurfaceTextures. class GpuMemoryBufferImplSurfaceTexture : public GpuMemoryBufferImpl { public: - static void Create(gfx::GpuMemoryBufferId id, - const gfx::Size& size, - Format format, - int client_id, - const CreationCallback& callback); - - static void AllocateForChildProcess(gfx::GpuMemoryBufferId id, - const gfx::Size& size, - Format format, - int child_client_id, - const AllocationCallback& callback); - static scoped_ptr<GpuMemoryBufferImpl> CreateFromHandle( const gfx::GpuMemoryBufferHandle& handle, const gfx::Size& size, Format format, const DestructionCallback& callback); - static void DeletedByChildProcess(gfx::GpuMemoryBufferId id, - int child_client_id, - uint32_t sync_point); - - static bool IsFormatSupported(Format format); - static bool IsUsageSupported(Usage usage); - // Overridden from gfx::GpuMemoryBuffer: void* Map() override; void Unmap() override; @@ -53,8 +34,6 @@ class GpuMemoryBufferImplSurfaceTexture : public GpuMemoryBufferImpl { ANativeWindow* native_window); ~GpuMemoryBufferImplSurfaceTexture() override; - static int WindowFormat(Format format); - ANativeWindow* native_window_; size_t stride_; diff --git a/content/common/gpu/client/gpu_memory_buffer_impl_unittest.cc b/content/common/gpu/client/gpu_memory_buffer_impl_unittest.cc index 84740cf..615cc93 100644 --- a/content/common/gpu/client/gpu_memory_buffer_impl_unittest.cc +++ b/content/common/gpu/client/gpu_memory_buffer_impl_unittest.cc @@ -4,259 +4,104 @@ #include "content/common/gpu/client/gpu_memory_buffer_impl.h" -#if defined(OS_ANDROID) -#include <android/native_window_jni.h> -#include <map> -#endif - #include "base/bind.h" -#include "content/common/gpu/client/gpu_memory_buffer_factory_host.h" #include "content/common/gpu/gpu_memory_buffer_factory.h" #include "testing/gtest/include/gtest/gtest.h" -#if defined(OS_ANDROID) -#include "base/android/jni_android.h" -#include "base/memory/linked_ptr.h" -#include "content/common/android/surface_texture_manager.h" -#include "ui/gl/android/scoped_java_surface.h" -#include "ui/gl/android/surface_texture.h" -#endif - namespace content { namespace { -#if defined(OS_ANDROID) -class SurfaceTextureManagerImpl : public SurfaceTextureManager { - public: - // Overridden from SurfaceTextureManager: - void RegisterSurfaceTexture(int surface_texture_id, - int client_id, - gfx::SurfaceTexture* surface_texture) override { - surfaces_[surface_texture_id] = make_linked_ptr( - new gfx::ScopedJavaSurface(surface_texture)); - } - void UnregisterSurfaceTexture(int surface_texture_id, - int client_id) override { - surfaces_.erase(surface_texture_id); - } - gfx::AcceleratedWidget AcquireNativeWidgetForSurfaceTexture( - int surface_texture_id) override { - JNIEnv* env = base::android::AttachCurrentThread(); - return ANativeWindow_fromSurface( - env, surfaces_[surface_texture_id]->j_surface().obj()); - } - - private: - typedef std::map<int, linked_ptr<gfx::ScopedJavaSurface>> SurfaceMap; - SurfaceMap surfaces_; -}; -#endif +const int kClientId = 1; class GpuMemoryBufferImplTest - : public testing::TestWithParam<gfx::GpuMemoryBufferType>, - public GpuMemoryBufferFactoryHost { + : public testing::TestWithParam<gfx::GpuMemoryBufferType> { public: - GpuMemoryBufferImplTest() : factory_(GpuMemoryBufferFactory::Create()) { -#if defined(OS_ANDROID) - SurfaceTextureManager::InitInstance(&surface_texture_manager_); -#endif - } - ~GpuMemoryBufferImplTest() override { -#if defined(OS_ANDROID) - SurfaceTextureManager::InitInstance(NULL); -#endif + GpuMemoryBufferImplTest() : buffer_count_(0), factory_(nullptr) {} + + // Overridden from testing::Test: + void SetUp() override { + factory_ = GpuMemoryBufferFactory::Create(GetParam()); + factory_->GetSupportedGpuMemoryBufferConfigurations( + &supported_configurations_); } + void TearDown() override { factory_.reset(); } - // Overridden from GpuMemoryBufferFactoryHost: - void CreateGpuMemoryBuffer( - gfx::GpuMemoryBufferType type, + gfx::GpuMemoryBufferHandle CreateGpuMemoryBuffer( gfx::GpuMemoryBufferId id, const gfx::Size& size, gfx::GpuMemoryBuffer::Format format, - gfx::GpuMemoryBuffer::Usage usage, - int client_id, - const CreateGpuMemoryBufferCallback& callback) override { - callback.Run(factory_->CreateGpuMemoryBuffer(type, - id, - size, - format, - usage, - client_id)); + gfx::GpuMemoryBuffer::Usage usage) { + ++buffer_count_; + return factory_->CreateGpuMemoryBuffer(id, size, format, usage, kClientId); } - void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, - int client_id, - int32 sync_point) override { - factory_->DestroyGpuMemoryBuffer(type, id, client_id); + + void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, uint32 sync_point) { + factory_->DestroyGpuMemoryBuffer(id, kClientId); + DCHECK_GT(buffer_count_, 0); + --buffer_count_; } + std::vector<GpuMemoryBufferFactory::Configuration> supported_configurations_; + int buffer_count_; + private: scoped_ptr<GpuMemoryBufferFactory> factory_; -#if defined(OS_ANDROID) - SurfaceTextureManagerImpl surface_texture_manager_; -#endif }; -struct CreateRequest { - scoped_ptr<GpuMemoryBufferImpl> result; -}; - -void GpuMemoryBufferCreated(CreateRequest* request, - scoped_ptr<GpuMemoryBufferImpl> buffer) { - request->result = buffer.Pass(); -} - -TEST_P(GpuMemoryBufferImplTest, Create) { +TEST_P(GpuMemoryBufferImplTest, CreateFromHandle) { const int kBufferId = 1; - const int kClientId = 0; gfx::Size buffer_size(1, 1); - const gfx::GpuMemoryBuffer::Format formats[] = { - gfx::GpuMemoryBuffer::RGBA_8888, - gfx::GpuMemoryBuffer::RGBX_8888, - gfx::GpuMemoryBuffer::BGRA_8888 - }; - for (gfx::GpuMemoryBuffer::Format format : formats) { - const gfx::GpuMemoryBuffer::Usage usages[] = { - gfx::GpuMemoryBuffer::MAP, - gfx::GpuMemoryBuffer::SCANOUT - }; - for (gfx::GpuMemoryBuffer::Usage usage : usages) { - if (!GpuMemoryBufferImpl::IsConfigurationSupported( - GetParam(), format, usage)) - continue; - - CreateRequest request; - GpuMemoryBufferImpl::Create(GetParam(), - kBufferId, + for (auto configuration : supported_configurations_) { + scoped_ptr<GpuMemoryBufferImpl> buffer( + GpuMemoryBufferImpl::CreateFromHandle( + CreateGpuMemoryBuffer(kBufferId, buffer_size, - format, - usage, - kClientId, - base::Bind(GpuMemoryBufferCreated, &request)); - - ASSERT_TRUE(request.result); - - scoped_ptr<GpuMemoryBufferImpl> buffer = request.result.Pass(); - EXPECT_EQ(buffer->GetFormat(), format); - } - } -} - -struct AllocateRequest { - gfx::GpuMemoryBufferHandle result; -}; - -void GpuMemoryBufferAllocated(AllocateRequest* request, - const gfx::GpuMemoryBufferHandle& handle) { - request->result = handle; -} - -void DeletedGpuMemoryBuffer(gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, - int child_client_id, - uint32 sync_point) { - GpuMemoryBufferImpl::DeletedByChildProcess(type, - id, - base::GetCurrentProcessHandle(), - child_client_id, - sync_point); -} - -TEST_P(GpuMemoryBufferImplTest, AllocateForChildProcess) { - const int kBufferId = 1; - const int kChildClientId = 1; - - gfx::Size buffer_size(1, 1); - - const gfx::GpuMemoryBuffer::Format formats[] = { - gfx::GpuMemoryBuffer::RGBA_8888, - gfx::GpuMemoryBuffer::RGBX_8888, - gfx::GpuMemoryBuffer::BGRA_8888 - }; - for (gfx::GpuMemoryBuffer::Format format : formats) { - const gfx::GpuMemoryBuffer::Usage usages[] = { - gfx::GpuMemoryBuffer::MAP, - gfx::GpuMemoryBuffer::SCANOUT - }; - for (gfx::GpuMemoryBuffer::Usage usage : usages) { - if (!GpuMemoryBufferImpl::IsConfigurationSupported( - GetParam(), format, usage)) - continue; - - AllocateRequest request; - GpuMemoryBufferImpl::AllocateForChildProcess( - GetParam(), - kBufferId, - buffer_size, - format, - usage, - base::GetCurrentProcessHandle(), - kChildClientId, - base::Bind(GpuMemoryBufferAllocated, &request)); - - EXPECT_EQ(request.result.type, GetParam()); + configuration.format, + configuration.usage), + buffer_size, + configuration.format, + base::Bind(&GpuMemoryBufferImplTest::DestroyGpuMemoryBuffer, + base::Unretained(this), + kBufferId))); + EXPECT_EQ(1, buffer_count_); + ASSERT_TRUE(buffer); + EXPECT_EQ(buffer->GetFormat(), configuration.format); - scoped_ptr<GpuMemoryBufferImpl> buffer( - GpuMemoryBufferImpl::CreateFromHandle( - request.result, - buffer_size, - format, - base::Bind(DeletedGpuMemoryBuffer, - GetParam(), - kBufferId, - kChildClientId))); - ASSERT_TRUE(buffer); - EXPECT_EQ(buffer->GetFormat(), format); - } + // Check if destruction callback is executed when deleting the buffer. + buffer.reset(); + EXPECT_EQ(0, buffer_count_); } } TEST_P(GpuMemoryBufferImplTest, Map) { const int kBufferId = 1; - const int kChildClientId = 1; gfx::Size buffer_size(1, 1); - const gfx::GpuMemoryBuffer::Format formats[] = { - gfx::GpuMemoryBuffer::RGBA_8888, - gfx::GpuMemoryBuffer::RGBX_8888, - gfx::GpuMemoryBuffer::BGRA_8888 - }; - for (gfx::GpuMemoryBuffer::Format format : formats) { - if (!GpuMemoryBufferImpl::IsConfigurationSupported( - GetParam(), format, gfx::GpuMemoryBuffer::MAP)) + for (auto configuration : supported_configurations_) { + if (configuration.usage != gfx::GpuMemoryBuffer::MAP) continue; size_t width_in_bytes = - GpuMemoryBufferImpl::BytesPerPixel(format) * buffer_size.width(); + GpuMemoryBufferImpl::BytesPerPixel(configuration.format) * + buffer_size.width(); EXPECT_GT(width_in_bytes, 0u); scoped_ptr<char[]> data(new char[width_in_bytes]); memset(data.get(), 0x2a, width_in_bytes); - AllocateRequest request; - GpuMemoryBufferImpl::AllocateForChildProcess( - GetParam(), - kBufferId, - buffer_size, - format, - gfx::GpuMemoryBuffer::MAP, - base::GetCurrentProcessHandle(), - kChildClientId, - base::Bind(GpuMemoryBufferAllocated, &request)); - - EXPECT_EQ(request.result.type, GetParam()); - scoped_ptr<GpuMemoryBufferImpl> buffer( GpuMemoryBufferImpl::CreateFromHandle( - request.result, + CreateGpuMemoryBuffer(kBufferId, + buffer_size, + configuration.format, + configuration.usage), buffer_size, - format, - base::Bind(DeletedGpuMemoryBuffer, - GetParam(), - kBufferId, - kChildClientId))); + configuration.format, + base::Bind(&GpuMemoryBufferImplTest::DestroyGpuMemoryBuffer, + base::Unretained(this), + kBufferId))); ASSERT_TRUE(buffer); EXPECT_FALSE(buffer->IsMapped()); @@ -274,7 +119,7 @@ TEST_P(GpuMemoryBufferImplTest, Map) { std::vector<gfx::GpuMemoryBufferType> GetSupportedGpuMemoryBufferTypes() { std::vector<gfx::GpuMemoryBufferType> supported_types; - GpuMemoryBufferImpl::GetSupportedTypes(&supported_types); + GpuMemoryBufferFactory::GetSupportedTypes(&supported_types); return supported_types; } diff --git a/content/common/gpu/client/gpu_memory_buffer_impl_win.cc b/content/common/gpu/client/gpu_memory_buffer_impl_win.cc deleted file mode 100644 index ef50898..0000000 --- a/content/common/gpu/client/gpu_memory_buffer_impl_win.cc +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright 2013 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. - -#include "content/common/gpu/client/gpu_memory_buffer_impl.h" - -#include "base/logging.h" -#include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h" - -namespace content { - -// static -void GpuMemoryBufferImpl::GetSupportedTypes( - std::vector<gfx::GpuMemoryBufferType>* types) { - const gfx::GpuMemoryBufferType supported_types[] = { - gfx::SHARED_MEMORY_BUFFER - }; - types->assign(supported_types, supported_types + arraysize(supported_types)); -} - -// static -bool GpuMemoryBufferImpl::IsConfigurationSupported( - gfx::GpuMemoryBufferType type, - Format format, - Usage usage) { - switch (type) { - case gfx::SHARED_MEMORY_BUFFER: - return GpuMemoryBufferImplSharedMemory::IsFormatSupported(format) && - GpuMemoryBufferImplSharedMemory::IsUsageSupported(usage); - default: - NOTREACHED(); - return false; - } -} - -// static -void GpuMemoryBufferImpl::Create(gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, - const gfx::Size& size, - Format format, - Usage usage, - int client_id, - const CreationCallback& callback) { - switch (type) { - case gfx::SHARED_MEMORY_BUFFER: - GpuMemoryBufferImplSharedMemory::Create(id, size, format, callback); - break; - default: - NOTREACHED(); - break; - } -} - -// static -void GpuMemoryBufferImpl::AllocateForChildProcess( - gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, - const gfx::Size& size, - Format format, - Usage usage, - base::ProcessHandle child_process, - int child_client_id, - const AllocationCallback& callback) { - switch (type) { - case gfx::SHARED_MEMORY_BUFFER: - GpuMemoryBufferImplSharedMemory::AllocateForChildProcess( - id, size, format, child_process, callback); - break; - default: - NOTREACHED(); - break; - } -} - -// static -void GpuMemoryBufferImpl::DeletedByChildProcess( - gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, - base::ProcessHandle child_process, - int child_client_id, - uint32 sync_point) { - switch (type) { - case gfx::SHARED_MEMORY_BUFFER: - break; - default: - NOTREACHED(); - break; - } -} - -// static -scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImpl::CreateFromHandle( - const gfx::GpuMemoryBufferHandle& handle, - const gfx::Size& size, - Format format, - const DestructionCallback& callback) { - switch (handle.type) { - case gfx::SHARED_MEMORY_BUFFER: - return GpuMemoryBufferImplSharedMemory::CreateFromHandle( - handle, size, format, callback); - default: - NOTREACHED(); - return scoped_ptr<GpuMemoryBufferImpl>(); - } -} - -} // namespace content diff --git a/content/common/gpu/gpu_channel.cc b/content/common/gpu/gpu_channel.cc index c89914d..ab751fd 100644 --- a/content/common/gpu/gpu_channel.cc +++ b/content/common/gpu/gpu_channel.cc @@ -20,15 +20,18 @@ #include "base/timer/timer.h" #include "content/common/gpu/devtools_gpu_agent.h" #include "content/common/gpu/gpu_channel_manager.h" +#include "content/common/gpu/gpu_memory_buffer_factory.h" #include "content/common/gpu/gpu_messages.h" #include "content/public/common/content_switches.h" #include "gpu/command_buffer/common/mailbox.h" #include "gpu/command_buffer/service/gpu_scheduler.h" +#include "gpu/command_buffer/service/image_factory.h" #include "gpu/command_buffer/service/mailbox_manager_impl.h" #include "gpu/command_buffer/service/sync_point_manager.h" #include "ipc/ipc_channel.h" #include "ipc/message_filter.h" #include "ui/gl/gl_context.h" +#include "ui/gl/gl_image_shared_memory.h" #include "ui/gl/gl_surface.h" #if defined(OS_POSIX) @@ -819,4 +822,34 @@ uint64 GpuChannel::GetMemoryUsage() { return size; } +scoped_refptr<gfx::GLImage> GpuChannel::CreateImageForGpuMemoryBuffer( + const gfx::GpuMemoryBufferHandle& handle, + const gfx::Size& size, + gfx::GpuMemoryBuffer::Format format, + uint32 internalformat) { + switch (handle.type) { + case gfx::SHARED_MEMORY_BUFFER: { + scoped_refptr<gfx::GLImageSharedMemory> image( + new gfx::GLImageSharedMemory(size, internalformat)); + if (!image->Initialize(handle, format)) + return scoped_refptr<gfx::GLImage>(); + + return image; + } + default: { + GpuChannelManager* manager = gpu_channel_manager(); + if (!manager->gpu_memory_buffer_factory()) + return scoped_refptr<gfx::GLImage>(); + + return manager->gpu_memory_buffer_factory() + ->AsImageFactory() + ->CreateImageForGpuMemoryBuffer(handle, + size, + format, + internalformat, + client_id_); + } + } +} + } // namespace content diff --git a/content/common/gpu/gpu_channel.h b/content/common/gpu/gpu_channel.h index 0d8538f..73ed312 100644 --- a/content/common/gpu/gpu_channel.h +++ b/content/common/gpu/gpu_channel.h @@ -143,6 +143,12 @@ class GpuChannel : public IPC::Listener, public IPC::Sender { uint64 GetMemoryUsage(); + scoped_refptr<gfx::GLImage> CreateImageForGpuMemoryBuffer( + const gfx::GpuMemoryBufferHandle& handle, + const gfx::Size& size, + gfx::GpuMemoryBuffer::Format format, + uint32 internalformat); + bool allow_future_sync_points() const { return allow_future_sync_points_; } private: diff --git a/content/common/gpu/gpu_channel_manager.cc b/content/common/gpu/gpu_channel_manager.cc index d9285313..5c3b1dc 100644 --- a/content/common/gpu/gpu_channel_manager.cc +++ b/content/common/gpu/gpu_channel_manager.cc @@ -58,27 +58,36 @@ class GpuChannelManagerMessageFilter : public IPC::MessageFilter { protected: ~GpuChannelManagerMessageFilter() override {} - void OnCreateGpuMemoryBuffer( - const GpuMsg_CreateGpuMemoryBuffer_Params& params) { + void OnCreateGpuMemoryBuffer(gfx::GpuMemoryBufferId id, + const gfx::Size& size, + gfx::GpuMemoryBuffer::Format format, + gfx::GpuMemoryBuffer::Usage usage, + int client_id) { TRACE_EVENT2("gpu", "GpuChannelManagerMessageFilter::OnCreateGpuMemoryBuffer", "id", - params.id, + id, "client_id", - params.client_id); + client_id); sender_->Send(new GpuHostMsg_GpuMemoryBufferCreated( - gpu_memory_buffer_factory_->CreateGpuMemoryBuffer(params.type, - params.id, - params.size, - params.format, - params.usage, - params.client_id))); + gpu_memory_buffer_factory_->CreateGpuMemoryBuffer(id, + size, + format, + usage, + client_id))); } IPC::Sender* sender_; GpuMemoryBufferFactory* gpu_memory_buffer_factory_; }; +gfx::GpuMemoryBufferType GetGpuMemoryBufferFactoryType() { + std::vector<gfx::GpuMemoryBufferType> supported_types; + GpuMemoryBufferFactory::GetSupportedTypes(&supported_types); + DCHECK(!supported_types.empty()); + return supported_types[0]; +} + } // namespace GpuChannelManager::GpuChannelManager(MessageRouter* router, @@ -94,7 +103,8 @@ GpuChannelManager::GpuChannelManager(MessageRouter* router, GpuMemoryManager::kDefaultMaxSurfacesWithFrontbufferSoftLimit), watchdog_(watchdog), sync_point_manager_(new gpu::SyncPointManager), - gpu_memory_buffer_factory_(GpuMemoryBufferFactory::Create()), + gpu_memory_buffer_factory_( + GpuMemoryBufferFactory::Create(GetGpuMemoryBufferFactoryType())), channel_(channel), filter_( new GpuChannelManagerMessageFilter(gpu_memory_buffer_factory_.get())), @@ -244,38 +254,33 @@ void GpuChannelManager::OnCreateViewCommandBuffer( } void GpuChannelManager::DestroyGpuMemoryBuffer( - gfx::GpuMemoryBufferType type, gfx::GpuMemoryBufferId id, int client_id) { io_message_loop_->PostTask( FROM_HERE, base::Bind(&GpuChannelManager::DestroyGpuMemoryBufferOnIO, base::Unretained(this), - type, id, client_id)); } void GpuChannelManager::DestroyGpuMemoryBufferOnIO( - gfx::GpuMemoryBufferType type, gfx::GpuMemoryBufferId id, int client_id) { - gpu_memory_buffer_factory_->DestroyGpuMemoryBuffer(type, id, client_id); + gpu_memory_buffer_factory_->DestroyGpuMemoryBuffer(id, client_id); } void GpuChannelManager::OnDestroyGpuMemoryBuffer( - gfx::GpuMemoryBufferType type, gfx::GpuMemoryBufferId id, int client_id, int32 sync_point) { if (!sync_point) { - DestroyGpuMemoryBuffer(type, id, client_id); + DestroyGpuMemoryBuffer(id, client_id); } else { sync_point_manager()->AddSyncPointCallback( sync_point, base::Bind(&GpuChannelManager::DestroyGpuMemoryBuffer, base::Unretained(this), - type, id, client_id)); } diff --git a/content/common/gpu/gpu_channel_manager.h b/content/common/gpu/gpu_channel_manager.h index 037758f..c00380a 100644 --- a/content/common/gpu/gpu_channel_manager.h +++ b/content/common/gpu/gpu_channel_manager.h @@ -124,14 +124,9 @@ class GpuChannelManager : public IPC::Listener, const GPUCreateCommandBufferConfig& init_params, int32 route_id); void OnLoadedShader(std::string shader); - void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, - int client_id); - void DestroyGpuMemoryBufferOnIO(gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, - int client_id); - void OnDestroyGpuMemoryBuffer(gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, + void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, int client_id); + void DestroyGpuMemoryBufferOnIO(gfx::GpuMemoryBufferId id, int client_id); + void OnDestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, int client_id, int32 sync_point); void OnRelinquishResources(); diff --git a/content/common/gpu/gpu_command_buffer_stub.cc b/content/common/gpu/gpu_command_buffer_stub.cc index 5a6a72a..b31f70d 100644 --- a/content/common/gpu/gpu_command_buffer_stub.cc +++ b/content/common/gpu/gpu_command_buffer_stub.cc @@ -15,7 +15,6 @@ #include "content/common/gpu/gpu_channel.h" #include "content/common/gpu/gpu_channel_manager.h" #include "content/common/gpu/gpu_command_buffer_stub.h" -#include "content/common/gpu/gpu_memory_buffer_factory.h" #include "content/common/gpu/gpu_memory_manager.h" #include "content/common/gpu/gpu_memory_tracking.h" #include "content/common/gpu/gpu_messages.h" @@ -29,7 +28,6 @@ #include "gpu/command_buffer/common/mailbox.h" #include "gpu/command_buffer/service/gl_context_virtual.h" #include "gpu/command_buffer/service/gl_state_restorer_impl.h" -#include "gpu/command_buffer/service/image_factory.h" #include "gpu/command_buffer/service/image_manager.h" #include "gpu/command_buffer/service/logger.h" #include "gpu/command_buffer/service/mailbox_manager.h" @@ -961,12 +959,8 @@ void GpuCommandBufferStub::OnCreateImage(int32 id, return; } - GpuChannelManager* manager = channel_->gpu_channel_manager(); - scoped_refptr<gfx::GLImage> image = - manager->gpu_memory_buffer_factory() - ->AsImageFactory() - ->CreateImageForGpuMemoryBuffer( - handle, size, format, internalformat, channel()->client_id()); + scoped_refptr<gfx::GLImage> image = channel()->CreateImageForGpuMemoryBuffer( + handle, size, format, internalformat); if (!image.get()) return; diff --git a/content/common/gpu/gpu_memory_buffer_factory.cc b/content/common/gpu/gpu_memory_buffer_factory.cc new file mode 100644 index 0000000..019bdd8 --- /dev/null +++ b/content/common/gpu/gpu_memory_buffer_factory.cc @@ -0,0 +1,66 @@ +// 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. + +#include "content/common/gpu/gpu_memory_buffer_factory.h" + +#include "base/logging.h" +#include "content/common/gpu/gpu_memory_buffer_factory_shared_memory.h" + +#if defined(OS_MACOSX) +#include "content/common/gpu/gpu_memory_buffer_factory_io_surface.h" +#endif + +#if defined(OS_ANDROID) +#include "content/common/gpu/gpu_memory_buffer_factory_surface_texture.h" +#endif + +#if defined(USE_OZONE) +#include "content/common/gpu/gpu_memory_buffer_factory_ozone_native_buffer.h" +#endif + +namespace content { + +// static +void GpuMemoryBufferFactory::GetSupportedTypes( + std::vector<gfx::GpuMemoryBufferType>* types) { + const gfx::GpuMemoryBufferType supported_types[] = { +#if defined(OS_MACOSX) + gfx::IO_SURFACE_BUFFER, +#endif +#if defined(OS_ANDROID) + gfx::SURFACE_TEXTURE_BUFFER, +#endif +#if defined(USE_OZONE) + gfx::OZONE_NATIVE_BUFFER, +#endif + gfx::SHARED_MEMORY_BUFFER + }; + types->assign(supported_types, supported_types + arraysize(supported_types)); +} + +// static +scoped_ptr<GpuMemoryBufferFactory> GpuMemoryBufferFactory::Create( + gfx::GpuMemoryBufferType type) { + switch (type) { + case gfx::SHARED_MEMORY_BUFFER: + return make_scoped_ptr(new GpuMemoryBufferFactorySharedMemory); +#if defined(OS_MACOSX) + case gfx::IO_SURFACE_BUFFER: + return make_scoped_ptr(new GpuMemoryBufferFactoryIOSurface); +#endif +#if defined(OS_ANDROID) + case gfx::SURFACE_TEXTURE_BUFFER: + return make_scoped_ptr(new GpuMemoryBufferFactorySurfaceTexture); +#endif +#if defined(USE_OZONE) + case gfx::OZONE_NATIVE_BUFFER: + return make_scoped_ptr(new GpuMemoryBufferFactoryOzoneNativeBuffer); +#endif + default: + NOTREACHED(); + return scoped_ptr<GpuMemoryBufferFactory>(); + } +} + +} // namespace content diff --git a/content/common/gpu/gpu_memory_buffer_factory.h b/content/common/gpu/gpu_memory_buffer_factory.h index f55f838..7df2773 100644 --- a/content/common/gpu/gpu_memory_buffer_factory.h +++ b/content/common/gpu/gpu_memory_buffer_factory.h @@ -5,6 +5,8 @@ #ifndef CONTENT_COMMON_GPU_GPU_MEMORY_BUFFER_FACTORY_H_ #define CONTENT_COMMON_GPU_GPU_MEMORY_BUFFER_FACTORY_H_ +#include <vector> + #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "content/common/content_export.h" @@ -23,16 +25,29 @@ namespace content { class CONTENT_EXPORT GpuMemoryBufferFactory { public: + struct Configuration { + gfx::GpuMemoryBuffer::Format format; + gfx::GpuMemoryBuffer::Usage usage; + }; + GpuMemoryBufferFactory() {} virtual ~GpuMemoryBufferFactory() {} - // Creates a new platform specific factory instance. - static scoped_ptr<GpuMemoryBufferFactory> Create(); + // Gets system supported GPU memory buffer factory types. Preferred type at + // the front of vector. + static void GetSupportedTypes(std::vector<gfx::GpuMemoryBufferType>* types); + + // Creates a new factory instance for |type|. + static scoped_ptr<GpuMemoryBufferFactory> Create( + gfx::GpuMemoryBufferType type); + + // Gets supported format/usage configurations. + virtual void GetSupportedGpuMemoryBufferConfigurations( + std::vector<Configuration>* configurations) = 0; - // Creates a GPU memory buffer instance of |type|. A valid handle is - // returned on success. + // Creates a new GPU memory buffer instance. A valid handle is returned on + // success. virtual gfx::GpuMemoryBufferHandle CreateGpuMemoryBuffer( - gfx::GpuMemoryBufferType type, gfx::GpuMemoryBufferId id, const gfx::Size& size, gfx::GpuMemoryBuffer::Format format, @@ -40,8 +55,7 @@ class CONTENT_EXPORT GpuMemoryBufferFactory { int client_id) = 0; // Destroys GPU memory buffer identified by |id|. - virtual void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, + virtual void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, int client_id) = 0; // Type-checking downcast routine. diff --git a/content/common/gpu/gpu_memory_buffer_factory_android.cc b/content/common/gpu/gpu_memory_buffer_factory_android.cc deleted file mode 100644 index 1fce6b6..0000000 --- a/content/common/gpu/gpu_memory_buffer_factory_android.cc +++ /dev/null @@ -1,88 +0,0 @@ -// 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. - -#include "content/common/gpu/gpu_memory_buffer_factory.h" - -#include "base/logging.h" -#include "content/common/gpu/gpu_memory_buffer_factory_surface_texture.h" -#include "gpu/command_buffer/service/image_factory.h" -#include "ui/gl/gl_image.h" -#include "ui/gl/gl_image_shared_memory.h" - -namespace content { -namespace { - -class GpuMemoryBufferFactoryImpl : public GpuMemoryBufferFactory, - public gpu::ImageFactory { - public: - // Overridden from GpuMemoryBufferFactory: - virtual gfx::GpuMemoryBufferHandle CreateGpuMemoryBuffer( - gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, - const gfx::Size& size, - gfx::GpuMemoryBuffer::Format format, - gfx::GpuMemoryBuffer::Usage usage, - int client_id) override { - switch (type) { - case gfx::SURFACE_TEXTURE_BUFFER: - return surface_texture_factory_.CreateGpuMemoryBuffer( - id, size, format, client_id); - default: - NOTREACHED(); - return gfx::GpuMemoryBufferHandle(); - } - } - virtual void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, - int client_id) override { - switch (type) { - case gfx::SURFACE_TEXTURE_BUFFER: - surface_texture_factory_.DestroyGpuMemoryBuffer(id, client_id); - break; - default: - NOTREACHED(); - break; - } - } - virtual gpu::ImageFactory* AsImageFactory() override { return this; } - - // Overridden from gpu::ImageFactory: - virtual scoped_refptr<gfx::GLImage> CreateImageForGpuMemoryBuffer( - const gfx::GpuMemoryBufferHandle& handle, - const gfx::Size& size, - gfx::GpuMemoryBuffer::Format format, - unsigned internalformat, - int client_id) override { - switch (handle.type) { - case gfx::SHARED_MEMORY_BUFFER: { - scoped_refptr<gfx::GLImageSharedMemory> image( - new gfx::GLImageSharedMemory(size, internalformat)); - if (!image->Initialize(handle, format)) - return NULL; - - return image; - } - case gfx::SURFACE_TEXTURE_BUFFER: { - return surface_texture_factory_.CreateImageForGpuMemoryBuffer( - handle.id, size, internalformat, client_id); - } - default: - NOTREACHED(); - return scoped_refptr<gfx::GLImage>(); - } - } - - private: - GpuMemoryBufferFactorySurfaceTexture surface_texture_factory_; -}; - -} // namespace - -// static -scoped_ptr<GpuMemoryBufferFactory> GpuMemoryBufferFactory::Create() { - return make_scoped_ptr<GpuMemoryBufferFactory>( - new GpuMemoryBufferFactoryImpl); -} - -} // namespace content diff --git a/content/common/gpu/gpu_memory_buffer_factory_io_surface.cc b/content/common/gpu/gpu_memory_buffer_factory_io_surface.cc index 66bfd8c..f13231d 100644 --- a/content/common/gpu/gpu_memory_buffer_factory_io_surface.cc +++ b/content/common/gpu/gpu_memory_buffer_factory_io_surface.cc @@ -6,7 +6,7 @@ #include <CoreFoundation/CoreFoundation.h> -#include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h" +#include "base/logging.h" #include "ui/gl/gl_image_io_surface.h" namespace content { @@ -27,6 +27,20 @@ void AddIntegerValue(CFMutableDictionaryRef dictionary, CFDictionaryAddValue(dictionary, key, number.get()); } +int32 BytesPerPixel(gfx::GpuMemoryBuffer::Format format) { + switch (format) { + case gfx::GpuMemoryBuffer::BGRA_8888: + return 4; + case gfx::GpuMemoryBuffer::RGBA_8888: + case gfx::GpuMemoryBuffer::RGBX_8888: + NOTREACHED(); + return 0; + } + + NOTREACHED(); + return 0; +} + int32 PixelFormat(gfx::GpuMemoryBuffer::Format format) { switch (format) { case gfx::GpuMemoryBuffer::BGRA_8888: @@ -41,6 +55,10 @@ int32 PixelFormat(gfx::GpuMemoryBuffer::Format format) { return 0; } +const GpuMemoryBufferFactory::Configuration kSupportedConfigurations[] = { + { gfx::GpuMemoryBuffer::BGRA_8888, gfx::GpuMemoryBuffer::MAP } +}; + } // namespace GpuMemoryBufferFactoryIOSurface::GpuMemoryBufferFactoryIOSurface() { @@ -49,11 +67,31 @@ GpuMemoryBufferFactoryIOSurface::GpuMemoryBufferFactoryIOSurface() { GpuMemoryBufferFactoryIOSurface::~GpuMemoryBufferFactoryIOSurface() { } +// static +bool GpuMemoryBufferFactoryIOSurface::IsGpuMemoryBufferConfigurationSupported( + gfx::GpuMemoryBuffer::Format format, + gfx::GpuMemoryBuffer::Usage usage) { + for (auto& configuration : kSupportedConfigurations) { + if (configuration.format == format && configuration.usage == usage) + return true; + } + + return false; +} + +void GpuMemoryBufferFactoryIOSurface::GetSupportedGpuMemoryBufferConfigurations( + std::vector<Configuration>* configurations) { + configurations->assign( + kSupportedConfigurations, + kSupportedConfigurations + arraysize(kSupportedConfigurations)); +} + gfx::GpuMemoryBufferHandle GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer( gfx::GpuMemoryBufferId id, const gfx::Size& size, gfx::GpuMemoryBuffer::Format format, + gfx::GpuMemoryBuffer::Usage usage, int client_id) { base::ScopedCFTypeRef<CFMutableDictionaryRef> properties; properties.reset(CFDictionaryCreateMutable(kCFAllocatorDefault, @@ -62,9 +100,7 @@ GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer( &kCFTypeDictionaryValueCallBacks)); AddIntegerValue(properties, kIOSurfaceWidth, size.width()); AddIntegerValue(properties, kIOSurfaceHeight, size.height()); - AddIntegerValue(properties, - kIOSurfaceBytesPerElement, - GpuMemoryBufferImpl::BytesPerPixel(format)); + AddIntegerValue(properties, kIOSurfaceBytesPerElement, BytesPerPixel(format)); AddIntegerValue(properties, kIOSurfacePixelFormat, PixelFormat(format)); // TODO(reveman): Remove this when using a mach_port_t to transfer // IOSurface to browser and renderer process. crbug.com/323304 @@ -94,13 +130,19 @@ void GpuMemoryBufferFactoryIOSurface::DestroyGpuMemoryBuffer( io_surfaces_.erase(it); } +gpu::ImageFactory* GpuMemoryBufferFactoryIOSurface::AsImageFactory() { + return this; +} + scoped_refptr<gfx::GLImage> GpuMemoryBufferFactoryIOSurface::CreateImageForGpuMemoryBuffer( - gfx::GpuMemoryBufferId id, + const gfx::GpuMemoryBufferHandle& handle, const gfx::Size& size, gfx::GpuMemoryBuffer::Format format, + unsigned internalformat, int client_id) { - IOSurfaceMapKey key(id, client_id); + DCHECK_EQ(handle.type, gfx::IO_SURFACE_BUFFER); + IOSurfaceMapKey key(handle.id, client_id); IOSurfaceMap::iterator it = io_surfaces_.find(key); if (it == io_surfaces_.end()) return scoped_refptr<gfx::GLImage>(); diff --git a/content/common/gpu/gpu_memory_buffer_factory_io_surface.h b/content/common/gpu/gpu_memory_buffer_factory_io_surface.h index 1ee16ef..e2c64ee 100644 --- a/content/common/gpu/gpu_memory_buffer_factory_io_surface.h +++ b/content/common/gpu/gpu_memory_buffer_factory_io_surface.h @@ -10,6 +10,8 @@ #include "base/containers/hash_tables.h" #include "base/mac/scoped_cftyperef.h" #include "base/memory/ref_counted.h" +#include "content/common/gpu/gpu_memory_buffer_factory.h" +#include "gpu/command_buffer/service/image_factory.h" #include "ui/gfx/geometry/size.h" #include "ui/gfx/gpu_memory_buffer.h" @@ -19,34 +21,44 @@ class GLImage; namespace content { -class GpuMemoryBufferFactoryIOSurface { +class GpuMemoryBufferFactoryIOSurface : public GpuMemoryBufferFactory, + public gpu::ImageFactory { public: GpuMemoryBufferFactoryIOSurface(); ~GpuMemoryBufferFactoryIOSurface(); - // Creates a IOSurface backed GPU memory buffer with |size| and - // |internalformat|. A valid handle is returned on success. + static bool IsGpuMemoryBufferConfigurationSupported( + gfx::GpuMemoryBuffer::Format format, + gfx::GpuMemoryBuffer::Usage usage); + + // Overridden from GpuMemoryBufferFactory: + void GetSupportedGpuMemoryBufferConfigurations( + std::vector<Configuration>* configurations) override; gfx::GpuMemoryBufferHandle CreateGpuMemoryBuffer( gfx::GpuMemoryBufferId id, const gfx::Size& size, gfx::GpuMemoryBuffer::Format format, - int client_id); - - // Destroy a previously created GPU memory buffer. - void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, int client_id); + gfx::GpuMemoryBuffer::Usage usage, + int client_id) override; + void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, + int client_id) override; + gpu::ImageFactory* AsImageFactory() override; - // Creates a GLImage instance for a GPU memory buffer. + // Overridden from gpu::ImageFactory: scoped_refptr<gfx::GLImage> CreateImageForGpuMemoryBuffer( - gfx::GpuMemoryBufferId id, + const gfx::GpuMemoryBufferHandle& handle, const gfx::Size& size, gfx::GpuMemoryBuffer::Format format, - int client_id); + unsigned internalformat, + int client_id) override; private: typedef std::pair<int, int> IOSurfaceMapKey; typedef base::hash_map<IOSurfaceMapKey, base::ScopedCFTypeRef<IOSurfaceRef>> IOSurfaceMap; IOSurfaceMap io_surfaces_; + + DISALLOW_COPY_AND_ASSIGN(GpuMemoryBufferFactoryIOSurface); }; } // namespace content diff --git a/content/common/gpu/gpu_memory_buffer_factory_linux.cc b/content/common/gpu/gpu_memory_buffer_factory_linux.cc deleted file mode 100644 index 6746551..0000000 --- a/content/common/gpu/gpu_memory_buffer_factory_linux.cc +++ /dev/null @@ -1,67 +0,0 @@ -// 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. - -#include "content/common/gpu/gpu_memory_buffer_factory.h" - -#include "base/logging.h" -#include "gpu/command_buffer/service/image_factory.h" -#include "ui/gl/gl_image.h" -#include "ui/gl/gl_image_shared_memory.h" - -namespace content { -namespace { - -class GpuMemoryBufferFactoryImpl : public GpuMemoryBufferFactory, - public gpu::ImageFactory { - public: - // Overridden from GpuMemoryBufferFactory: - gfx::GpuMemoryBufferHandle CreateGpuMemoryBuffer( - gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, - const gfx::Size& size, - gfx::GpuMemoryBuffer::Format format, - gfx::GpuMemoryBuffer::Usage usage, - int client_id) override { - NOTREACHED(); - return gfx::GpuMemoryBufferHandle(); - } - void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, - int client_id) override { - NOTREACHED(); - } - gpu::ImageFactory* AsImageFactory() override { return this; } - - // Overridden from gpu::ImageFactory: - scoped_refptr<gfx::GLImage> CreateImageForGpuMemoryBuffer( - const gfx::GpuMemoryBufferHandle& handle, - const gfx::Size& size, - gfx::GpuMemoryBuffer::Format format, - unsigned internalformat, - int client_id) override { - switch (handle.type) { - case gfx::SHARED_MEMORY_BUFFER: { - scoped_refptr<gfx::GLImageSharedMemory> image( - new gfx::GLImageSharedMemory(size, internalformat)); - if (!image->Initialize(handle, format)) - return NULL; - - return image; - } - default: - NOTREACHED(); - return scoped_refptr<gfx::GLImage>(); - } - } -}; - -} // namespace - -// static -scoped_ptr<GpuMemoryBufferFactory> GpuMemoryBufferFactory::Create() { - return make_scoped_ptr<GpuMemoryBufferFactory>( - new GpuMemoryBufferFactoryImpl); -} - -} // namespace content diff --git a/content/common/gpu/gpu_memory_buffer_factory_mac.cc b/content/common/gpu/gpu_memory_buffer_factory_mac.cc deleted file mode 100644 index aa04b27..0000000 --- a/content/common/gpu/gpu_memory_buffer_factory_mac.cc +++ /dev/null @@ -1,88 +0,0 @@ -// 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. - -#include "content/common/gpu/gpu_memory_buffer_factory.h" - -#include "base/logging.h" -#include "content/common/gpu/gpu_memory_buffer_factory_io_surface.h" -#include "gpu/command_buffer/service/image_factory.h" -#include "ui/gl/gl_image.h" -#include "ui/gl/gl_image_shared_memory.h" - -namespace content { -namespace { - -class GpuMemoryBufferFactoryImpl : public GpuMemoryBufferFactory, - public gpu::ImageFactory { - public: - // Overridden from GpuMemoryBufferFactory: - gfx::GpuMemoryBufferHandle CreateGpuMemoryBuffer( - gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, - const gfx::Size& size, - gfx::GpuMemoryBuffer::Format format, - gfx::GpuMemoryBuffer::Usage usage, - int client_id) override { - switch (type) { - case gfx::IO_SURFACE_BUFFER: - return io_surface_factory_.CreateGpuMemoryBuffer( - id, size, format, client_id); - default: - NOTREACHED(); - return gfx::GpuMemoryBufferHandle(); - } - } - void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, - int client_id) override { - switch (type) { - case gfx::IO_SURFACE_BUFFER: - io_surface_factory_.DestroyGpuMemoryBuffer(id, client_id); - break; - default: - NOTREACHED(); - break; - } - } - gpu::ImageFactory* AsImageFactory() override { return this; } - - // Overridden from gpu::ImageFactory: - scoped_refptr<gfx::GLImage> CreateImageForGpuMemoryBuffer( - const gfx::GpuMemoryBufferHandle& handle, - const gfx::Size& size, - gfx::GpuMemoryBuffer::Format format, - unsigned internalformat, - int client_id) override { - switch (handle.type) { - case gfx::SHARED_MEMORY_BUFFER: { - scoped_refptr<gfx::GLImageSharedMemory> image( - new gfx::GLImageSharedMemory(size, internalformat)); - if (!image->Initialize(handle, format)) - return NULL; - - return image; - } - case gfx::IO_SURFACE_BUFFER: { - return io_surface_factory_.CreateImageForGpuMemoryBuffer( - handle.id, size, format, client_id); - } - default: - NOTREACHED(); - return scoped_refptr<gfx::GLImage>(); - } - } - - private: - GpuMemoryBufferFactoryIOSurface io_surface_factory_; -}; - -} // namespace - -// static -scoped_ptr<GpuMemoryBufferFactory> GpuMemoryBufferFactory::Create() { - return make_scoped_ptr<GpuMemoryBufferFactory>( - new GpuMemoryBufferFactoryImpl); -} - -} // namespace content diff --git a/content/common/gpu/gpu_memory_buffer_factory_ozone.cc b/content/common/gpu/gpu_memory_buffer_factory_ozone.cc deleted file mode 100644 index f2a296e..0000000 --- a/content/common/gpu/gpu_memory_buffer_factory_ozone.cc +++ /dev/null @@ -1,94 +0,0 @@ -// 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. - -#include "content/common/gpu/gpu_memory_buffer_factory.h" - -#include "base/logging.h" -#include "gpu/command_buffer/service/image_factory.h" -#include "ui/gl/gl_image.h" -#include "ui/gl/gl_image_shared_memory.h" -#include "ui/ozone/gpu/gpu_memory_buffer_factory_ozone_native_buffer.h" - -namespace content { -namespace { - -class GpuMemoryBufferFactoryImpl : public GpuMemoryBufferFactory, - public gpu::ImageFactory { - public: - // Overridden from GpuMemoryBufferFactory: - virtual gfx::GpuMemoryBufferHandle CreateGpuMemoryBuffer( - gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, - const gfx::Size& size, - gfx::GpuMemoryBuffer::Format format, - gfx::GpuMemoryBuffer::Usage usage, - int client_id) override { - switch (type) { - case gfx::OZONE_NATIVE_BUFFER: { - if (!ozone_buffer_factory_.CreateGpuMemoryBuffer( - id, size, format, usage, client_id)) { - return gfx::GpuMemoryBufferHandle(); - } - gfx::GpuMemoryBufferHandle handle; - handle.type = gfx::OZONE_NATIVE_BUFFER; - handle.id = id; - return handle; - } - default: - NOTREACHED(); - return gfx::GpuMemoryBufferHandle(); - } - } - virtual void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, - int client_id) override { - switch (type) { - case gfx::OZONE_NATIVE_BUFFER: - ozone_buffer_factory_.DestroyGpuMemoryBuffer(id, client_id); - break; - default: - NOTREACHED(); - break; - } - } - virtual gpu::ImageFactory* AsImageFactory() override { return this; } - - // Overridden from gpu::ImageFactory: - virtual scoped_refptr<gfx::GLImage> CreateImageForGpuMemoryBuffer( - const gfx::GpuMemoryBufferHandle& handle, - const gfx::Size& size, - gfx::GpuMemoryBuffer::Format format, - unsigned internalformat, - int client_id) override { - switch (handle.type) { - case gfx::SHARED_MEMORY_BUFFER: { - scoped_refptr<gfx::GLImageSharedMemory> image( - new gfx::GLImageSharedMemory(size, internalformat)); - if (!image->Initialize(handle, format)) - return NULL; - - return image; - } - case gfx::OZONE_NATIVE_BUFFER: - return ozone_buffer_factory_.CreateImageForGpuMemoryBuffer( - handle.id, size, format, internalformat, client_id); - default: - NOTREACHED(); - return scoped_refptr<gfx::GLImage>(); - } - } - - private: - ui::GpuMemoryBufferFactoryOzoneNativeBuffer ozone_buffer_factory_; -}; - -} // namespace - -// static -scoped_ptr<GpuMemoryBufferFactory> GpuMemoryBufferFactory::Create() { - return make_scoped_ptr<GpuMemoryBufferFactory>( - new GpuMemoryBufferFactoryImpl); -} - -} // namespace content diff --git a/content/common/gpu/gpu_memory_buffer_factory_ozone_native_buffer.cc b/content/common/gpu/gpu_memory_buffer_factory_ozone_native_buffer.cc new file mode 100644 index 0000000..c4f8e82 --- /dev/null +++ b/content/common/gpu/gpu_memory_buffer_factory_ozone_native_buffer.cc @@ -0,0 +1,92 @@ +// 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. + +#include "content/common/gpu/gpu_memory_buffer_factory_ozone_native_buffer.h" + +#include "base/logging.h" +#include "ui/gl/gl_image.h" +#include "ui/ozone/public/surface_factory_ozone.h" + +namespace content { +namespace { + +const GpuMemoryBufferFactory::Configuration kSupportedConfigurations[] = { + { gfx::GpuMemoryBuffer::RGBA_8888, gfx::GpuMemoryBuffer::SCANOUT }, + { gfx::GpuMemoryBuffer::RGBX_8888, gfx::GpuMemoryBuffer::SCANOUT } +}; + +} // namespace + +GpuMemoryBufferFactoryOzoneNativeBuffer:: + GpuMemoryBufferFactoryOzoneNativeBuffer() { +} + +GpuMemoryBufferFactoryOzoneNativeBuffer:: + ~GpuMemoryBufferFactoryOzoneNativeBuffer() { +} + +// static +bool GpuMemoryBufferFactoryOzoneNativeBuffer:: + IsGpuMemoryBufferConfigurationSupported(gfx::GpuMemoryBuffer::Format format, + gfx::GpuMemoryBuffer::Usage usage) { + for (auto& configuration : kSupportedConfigurations) { + if (configuration.format == format && configuration.usage == usage) + return true; + } + + return false; +} + +void GpuMemoryBufferFactoryOzoneNativeBuffer:: + GetSupportedGpuMemoryBufferConfigurations( + std::vector<Configuration>* configurations) { + if (!ui::SurfaceFactoryOzone::GetInstance()->CanCreateNativePixmap( + ui::SurfaceFactoryOzone::SCANOUT)) + return; + + configurations->assign( + kSupportedConfigurations, + kSupportedConfigurations + arraysize(kSupportedConfigurations)); +} + +gfx::GpuMemoryBufferHandle +GpuMemoryBufferFactoryOzoneNativeBuffer::CreateGpuMemoryBuffer( + gfx::GpuMemoryBufferId id, + const gfx::Size& size, + gfx::GpuMemoryBuffer::Format format, + gfx::GpuMemoryBuffer::Usage usage, + int client_id) { + if (!ozone_native_buffer_factory_.CreateGpuMemoryBuffer( + id, size, format, usage, client_id)) { + return gfx::GpuMemoryBufferHandle(); + } + gfx::GpuMemoryBufferHandle handle; + handle.type = gfx::OZONE_NATIVE_BUFFER; + handle.id = id; + return handle; +} + +void GpuMemoryBufferFactoryOzoneNativeBuffer::DestroyGpuMemoryBuffer( + gfx::GpuMemoryBufferId id, + int client_id) { + ozone_native_buffer_factory_.DestroyGpuMemoryBuffer(id, client_id); +} + +gpu::ImageFactory* GpuMemoryBufferFactoryOzoneNativeBuffer::AsImageFactory() { + return this; +} + +scoped_refptr<gfx::GLImage> +GpuMemoryBufferFactoryOzoneNativeBuffer::CreateImageForGpuMemoryBuffer( + const gfx::GpuMemoryBufferHandle& handle, + const gfx::Size& size, + gfx::GpuMemoryBuffer::Format format, + unsigned internalformat, + int client_id) { + DCHECK_EQ(handle.type, gfx::OZONE_NATIVE_BUFFER); + return ozone_native_buffer_factory_.CreateImageForGpuMemoryBuffer( + handle.id, size, format, internalformat, client_id); +} + +} // namespace content diff --git a/content/common/gpu/gpu_memory_buffer_factory_ozone_native_buffer.h b/content/common/gpu/gpu_memory_buffer_factory_ozone_native_buffer.h new file mode 100644 index 0000000..9b311de --- /dev/null +++ b/content/common/gpu/gpu_memory_buffer_factory_ozone_native_buffer.h @@ -0,0 +1,60 @@ +// 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 CONTENT_COMMON_GPU_GPU_MEMORY_BUFFER_FACTORY_OZONE_NATIVE_BUFFER_H_ +#define CONTENT_COMMON_GPU_GPU_MEMORY_BUFFER_FACTORY_OZONE_NATIVE_BUFFER_H_ + +#include "base/memory/ref_counted.h" +#include "content/common/gpu/gpu_memory_buffer_factory.h" +#include "gpu/command_buffer/service/image_factory.h" +#include "ui/gfx/geometry/size.h" +#include "ui/gfx/gpu_memory_buffer.h" +#include "ui/ozone/gpu/gpu_memory_buffer_factory_ozone_native_buffer.h" + +namespace gfx { +class GLImage; +} + +namespace content { + +class GpuMemoryBufferFactoryOzoneNativeBuffer : public GpuMemoryBufferFactory, + public gpu::ImageFactory { + public: + GpuMemoryBufferFactoryOzoneNativeBuffer(); + ~GpuMemoryBufferFactoryOzoneNativeBuffer() override; + + static bool IsGpuMemoryBufferConfigurationSupported( + gfx::GpuMemoryBuffer::Format format, + gfx::GpuMemoryBuffer::Usage usage); + + // Overridden from GpuMemoryBufferFactory: + void GetSupportedGpuMemoryBufferConfigurations( + std::vector<Configuration>* configurations) override; + gfx::GpuMemoryBufferHandle CreateGpuMemoryBuffer( + gfx::GpuMemoryBufferId id, + const gfx::Size& size, + gfx::GpuMemoryBuffer::Format format, + gfx::GpuMemoryBuffer::Usage usage, + int client_id) override; + void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, + int client_id) override; + gpu::ImageFactory* AsImageFactory() override; + + // Overridden from gpu::ImageFactory: + scoped_refptr<gfx::GLImage> CreateImageForGpuMemoryBuffer( + const gfx::GpuMemoryBufferHandle& handle, + const gfx::Size& size, + gfx::GpuMemoryBuffer::Format format, + unsigned internalformat, + int client_id) override; + + private: + ui::GpuMemoryBufferFactoryOzoneNativeBuffer ozone_native_buffer_factory_; + + DISALLOW_COPY_AND_ASSIGN(GpuMemoryBufferFactoryOzoneNativeBuffer); +}; + +} // namespace content + +#endif // CONTENT_COMMON_GPU_GPU_MEMORY_BUFFER_FACTORY_OZONE_NATIVE_BUFFER_H_ diff --git a/content/common/gpu/gpu_memory_buffer_factory_shared_memory.cc b/content/common/gpu/gpu_memory_buffer_factory_shared_memory.cc new file mode 100644 index 0000000..3a65c7c --- /dev/null +++ b/content/common/gpu/gpu_memory_buffer_factory_shared_memory.cc @@ -0,0 +1,75 @@ +// 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. + +#include "content/common/gpu/gpu_memory_buffer_factory_shared_memory.h" + +#include "base/logging.h" +#include "content/common/gpu/client/gpu_memory_buffer_impl.h" +#include "ui/gl/gl_image.h" +#include "ui/gl/gl_image_shared_memory.h" + +namespace content { + +GpuMemoryBufferFactorySharedMemory::GpuMemoryBufferFactorySharedMemory() { +} + +GpuMemoryBufferFactorySharedMemory::~GpuMemoryBufferFactorySharedMemory() { +} + +void GpuMemoryBufferFactorySharedMemory:: + GetSupportedGpuMemoryBufferConfigurations( + std::vector<Configuration>* configurations) { + const Configuration supported_configurations[] = { + { gfx::GpuMemoryBuffer::RGBA_8888, gfx::GpuMemoryBuffer::MAP }, + { gfx::GpuMemoryBuffer::BGRA_8888, gfx::GpuMemoryBuffer::MAP } + }; + configurations->assign( + supported_configurations, + supported_configurations + arraysize(supported_configurations)); +} + +gfx::GpuMemoryBufferHandle +GpuMemoryBufferFactorySharedMemory::CreateGpuMemoryBuffer( + gfx::GpuMemoryBufferId id, + const gfx::Size& size, + gfx::GpuMemoryBuffer::Format format, + gfx::GpuMemoryBuffer::Usage usage, + int client_id) { + base::SharedMemory shared_memory; + if (!shared_memory.CreateAnonymous( + size.GetArea() * GpuMemoryBufferImpl::BytesPerPixel(format))) + return gfx::GpuMemoryBufferHandle(); + + gfx::GpuMemoryBufferHandle handle; + handle.type = gfx::SHARED_MEMORY_BUFFER; + handle.id = id; + shared_memory.ShareToProcess(base::GetCurrentProcessHandle(), &handle.handle); + return handle; +} + +void GpuMemoryBufferFactorySharedMemory::DestroyGpuMemoryBuffer( + gfx::GpuMemoryBufferId id, + int client_id) { +} + +gpu::ImageFactory* GpuMemoryBufferFactorySharedMemory::AsImageFactory() { + return this; +} + +scoped_refptr<gfx::GLImage> +GpuMemoryBufferFactorySharedMemory::CreateImageForGpuMemoryBuffer( + const gfx::GpuMemoryBufferHandle& handle, + const gfx::Size& size, + gfx::GpuMemoryBuffer::Format format, + unsigned internalformat, + int client_id) { + scoped_refptr<gfx::GLImageSharedMemory> image( + new gfx::GLImageSharedMemory(size, internalformat)); + if (!image->Initialize(handle, format)) + return scoped_refptr<gfx::GLImage>(); + + return image; +} + +} // namespace content diff --git a/content/common/gpu/gpu_memory_buffer_factory_shared_memory.h b/content/common/gpu/gpu_memory_buffer_factory_shared_memory.h new file mode 100644 index 0000000..521021c --- /dev/null +++ b/content/common/gpu/gpu_memory_buffer_factory_shared_memory.h @@ -0,0 +1,53 @@ +// 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 CONTENT_COMMON_GPU_GPU_MEMORY_BUFFER_FACTORY_SHARED_MEMORY_H_ +#define CONTENT_COMMON_GPU_GPU_MEMORY_BUFFER_FACTORY_SHARED_MEMORY_H_ + +#include "base/memory/ref_counted.h" +#include "content/common/gpu/gpu_memory_buffer_factory.h" +#include "gpu/command_buffer/service/image_factory.h" +#include "ui/gfx/geometry/size.h" +#include "ui/gfx/gpu_memory_buffer.h" + +namespace gfx { +class GLImage; +} + +namespace content { + +class GpuMemoryBufferFactorySharedMemory : public GpuMemoryBufferFactory, + public gpu::ImageFactory { + public: + GpuMemoryBufferFactorySharedMemory(); + ~GpuMemoryBufferFactorySharedMemory() override; + + // Overridden from GpuMemoryBufferFactory: + void GetSupportedGpuMemoryBufferConfigurations( + std::vector<Configuration>* configurations) override; + gfx::GpuMemoryBufferHandle CreateGpuMemoryBuffer( + gfx::GpuMemoryBufferId id, + const gfx::Size& size, + gfx::GpuMemoryBuffer::Format format, + gfx::GpuMemoryBuffer::Usage usage, + int client_id) override; + void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, + int client_id) override; + gpu::ImageFactory* AsImageFactory() override; + + // Overridden from gpu::ImageFactory: + scoped_refptr<gfx::GLImage> CreateImageForGpuMemoryBuffer( + const gfx::GpuMemoryBufferHandle& handle, + const gfx::Size& size, + gfx::GpuMemoryBuffer::Format format, + unsigned internalformat, + int client_id) override; + + private: + DISALLOW_COPY_AND_ASSIGN(GpuMemoryBufferFactorySharedMemory); +}; + +} // namespace content + +#endif // CONTENT_COMMON_GPU_GPU_MEMORY_BUFFER_FACTORY_SHARED_MEMORY_H_ diff --git a/content/common/gpu/gpu_memory_buffer_factory_surface_texture.cc b/content/common/gpu/gpu_memory_buffer_factory_surface_texture.cc index 91b81cb..779cfa2 100644 --- a/content/common/gpu/gpu_memory_buffer_factory_surface_texture.cc +++ b/content/common/gpu/gpu_memory_buffer_factory_surface_texture.cc @@ -9,6 +9,13 @@ #include "ui/gl/gl_image_surface_texture.h" namespace content { +namespace { + +const GpuMemoryBufferFactory::Configuration kSupportedConfigurations[] = { + { gfx::GpuMemoryBuffer::RGBA_8888, gfx::GpuMemoryBuffer::MAP } +}; + +} // namespace GpuMemoryBufferFactorySurfaceTexture::GpuMemoryBufferFactorySurfaceTexture() { } @@ -16,11 +23,32 @@ GpuMemoryBufferFactorySurfaceTexture::GpuMemoryBufferFactorySurfaceTexture() { GpuMemoryBufferFactorySurfaceTexture::~GpuMemoryBufferFactorySurfaceTexture() { } +// static +bool GpuMemoryBufferFactorySurfaceTexture:: + IsGpuMemoryBufferConfigurationSupported(gfx::GpuMemoryBuffer::Format format, + gfx::GpuMemoryBuffer::Usage usage) { + for (auto& configuration : kSupportedConfigurations) { + if (configuration.format == format && configuration.usage == usage) + return true; + } + + return false; +} + +void GpuMemoryBufferFactorySurfaceTexture:: + GetSupportedGpuMemoryBufferConfigurations( + std::vector<Configuration>* configurations) { + configurations->assign( + kSupportedConfigurations, + kSupportedConfigurations + arraysize(kSupportedConfigurations)); +} + gfx::GpuMemoryBufferHandle GpuMemoryBufferFactorySurfaceTexture::CreateGpuMemoryBuffer( gfx::GpuMemoryBufferId id, const gfx::Size& size, - unsigned internalformat, + gfx::GpuMemoryBuffer::Format format, + gfx::GpuMemoryBuffer::Usage usage, int client_id) { // Note: this needs to be 0 as the surface texture implemenation will take // ownership of the texture and call glDeleteTextures when the GPU service @@ -56,13 +84,19 @@ void GpuMemoryBufferFactorySurfaceTexture::DestroyGpuMemoryBuffer( SurfaceTextureManager::GetInstance()->UnregisterSurfaceTexture(id, client_id); } +gpu::ImageFactory* GpuMemoryBufferFactorySurfaceTexture::AsImageFactory() { + return this; +} + scoped_refptr<gfx::GLImage> GpuMemoryBufferFactorySurfaceTexture::CreateImageForGpuMemoryBuffer( - gfx::GpuMemoryBufferId id, + const gfx::GpuMemoryBufferHandle& handle, const gfx::Size& size, + gfx::GpuMemoryBuffer::Format format, unsigned internalformat, int client_id) { - SurfaceTextureMapKey key(id, client_id); + DCHECK_EQ(handle.type, gfx::SURFACE_TEXTURE_BUFFER); + SurfaceTextureMapKey key(handle.id, client_id); SurfaceTextureMap::iterator it = surface_textures_.find(key); if (it == surface_textures_.end()) return scoped_refptr<gfx::GLImage>(); diff --git a/content/common/gpu/gpu_memory_buffer_factory_surface_texture.h b/content/common/gpu/gpu_memory_buffer_factory_surface_texture.h index c9103ed..80a5efc 100644 --- a/content/common/gpu/gpu_memory_buffer_factory_surface_texture.h +++ b/content/common/gpu/gpu_memory_buffer_factory_surface_texture.h @@ -7,6 +7,8 @@ #include "base/containers/hash_tables.h" #include "base/memory/ref_counted.h" +#include "content/common/gpu/gpu_memory_buffer_factory.h" +#include "gpu/command_buffer/service/image_factory.h" #include "ui/gfx/geometry/size.h" #include "ui/gfx/gpu_memory_buffer.h" @@ -17,27 +19,36 @@ class SurfaceTexture; namespace content { -class GpuMemoryBufferFactorySurfaceTexture { +class GpuMemoryBufferFactorySurfaceTexture : public GpuMemoryBufferFactory, + public gpu::ImageFactory { public: GpuMemoryBufferFactorySurfaceTexture(); ~GpuMemoryBufferFactorySurfaceTexture(); - // Creates a SurfaceTexture backed GPU memory buffer with |size| and - // |internalformat|. A valid handle is returned on success. - gfx::GpuMemoryBufferHandle CreateGpuMemoryBuffer(gfx::GpuMemoryBufferId id, - const gfx::Size& size, - unsigned internalformat, - int client_id); + static bool IsGpuMemoryBufferConfigurationSupported( + gfx::GpuMemoryBuffer::Format format, + gfx::GpuMemoryBuffer::Usage usage); - // Destroy a previously created GPU memory buffer. - void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, int client_id); - - // Creates a GLImage instance for a GPU memory buffer. - scoped_refptr<gfx::GLImage> CreateImageForGpuMemoryBuffer( + // Overridden from GpuMemoryBufferFactory: + void GetSupportedGpuMemoryBufferConfigurations( + std::vector<Configuration>* configurations) override; + gfx::GpuMemoryBufferHandle CreateGpuMemoryBuffer( gfx::GpuMemoryBufferId id, const gfx::Size& size, + gfx::GpuMemoryBuffer::Format format, + gfx::GpuMemoryBuffer::Usage usage, + int client_id) override; + void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, + int client_id) override; + gpu::ImageFactory* AsImageFactory() override; + + // Overridden from gpu::ImageFactory: + scoped_refptr<gfx::GLImage> CreateImageForGpuMemoryBuffer( + const gfx::GpuMemoryBufferHandle& handle, + const gfx::Size& size, + gfx::GpuMemoryBuffer::Format format, unsigned internalformat, - int client_id); + int client_id) override; private: typedef std::pair<int, int> SurfaceTextureMapKey; diff --git a/content/common/gpu/gpu_memory_buffer_factory_unittest.cc b/content/common/gpu/gpu_memory_buffer_factory_unittest.cc new file mode 100644 index 0000000..174c36c --- /dev/null +++ b/content/common/gpu/gpu_memory_buffer_factory_unittest.cc @@ -0,0 +1,61 @@ +// 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. + +#include "content/common/gpu/gpu_memory_buffer_factory.h" + +#include "testing/gtest/include/gtest/gtest.h" + +namespace content { +namespace { + +class GpuMemoryBufferFactoryTest + : public testing::TestWithParam<gfx::GpuMemoryBufferType> { + public: + GpuMemoryBufferFactoryTest() : factory_(nullptr) {} + + // Overridden from testing::Test: + void SetUp() override { + factory_ = GpuMemoryBufferFactory::Create(GetParam()); + factory_->GetSupportedGpuMemoryBufferConfigurations( + &supported_configurations_); + } + void TearDown() override { factory_.reset(); } + + protected: + scoped_ptr<GpuMemoryBufferFactory> factory_; + std::vector<GpuMemoryBufferFactory::Configuration> supported_configurations_; +}; + +TEST_P(GpuMemoryBufferFactoryTest, CreateAndDestroy) { + const int kBufferId = 1; + const int kClientId = 1; + + gfx::Size buffer_size(1, 1); + + for (auto configuration : supported_configurations_) { + gfx::GpuMemoryBufferHandle handle = factory_->CreateGpuMemoryBuffer( + kBufferId, + buffer_size, + configuration.format, + configuration.usage, + kClientId); + EXPECT_EQ(handle.type, GetParam()); + factory_->DestroyGpuMemoryBuffer(kBufferId, kClientId); + } +} + +std::vector<gfx::GpuMemoryBufferType> +GetSupportedGpuMemoryBufferFactoryTypes() { + std::vector<gfx::GpuMemoryBufferType> supported_types; + GpuMemoryBufferFactory::GetSupportedTypes(&supported_types); + return supported_types; +} + +INSTANTIATE_TEST_CASE_P( + GpuMemoryBufferFactoryTests, + GpuMemoryBufferFactoryTest, + ::testing::ValuesIn(GetSupportedGpuMemoryBufferFactoryTypes())); + +} // namespace +} // namespace content diff --git a/content/common/gpu/gpu_memory_buffer_factory_win.cc b/content/common/gpu/gpu_memory_buffer_factory_win.cc deleted file mode 100644 index 618ecc5..0000000 --- a/content/common/gpu/gpu_memory_buffer_factory_win.cc +++ /dev/null @@ -1,67 +0,0 @@ -// 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. - -#include "content/common/gpu/gpu_memory_buffer_factory.h" - -#include "base/logging.h" -#include "gpu/command_buffer/service/image_factory.h" -#include "ui/gl/gl_image.h" -#include "ui/gl/gl_image_shared_memory.h" - -namespace content { -namespace { - -class GpuMemoryBufferFactoryImpl : public GpuMemoryBufferFactory, - public gpu::ImageFactory { - public: - // Overridden from GpuMemoryBufferFactory: - virtual gfx::GpuMemoryBufferHandle CreateGpuMemoryBuffer( - gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, - const gfx::Size& size, - gfx::GpuMemoryBuffer::Format format, - gfx::GpuMemoryBuffer::Usage usage, - int client_id) override { - NOTREACHED(); - return gfx::GpuMemoryBufferHandle(); - } - virtual void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferType type, - gfx::GpuMemoryBufferId id, - int client_id) override { - NOTREACHED(); - } - virtual gpu::ImageFactory* AsImageFactory() override { return this; } - - // Overridden from gpu::ImageFactory: - virtual scoped_refptr<gfx::GLImage> CreateImageForGpuMemoryBuffer( - const gfx::GpuMemoryBufferHandle& handle, - const gfx::Size& size, - gfx::GpuMemoryBuffer::Format format, - unsigned internalformat, - int client_id) override { - switch (handle.type) { - case gfx::SHARED_MEMORY_BUFFER: { - scoped_refptr<gfx::GLImageSharedMemory> image( - new gfx::GLImageSharedMemory(size, internalformat)); - if (!image->Initialize(handle, format)) - return NULL; - - return image; - } - default: - NOTREACHED(); - return scoped_refptr<gfx::GLImage>(); - } - } -}; - -} // namespace - -// static -scoped_ptr<GpuMemoryBufferFactory> GpuMemoryBufferFactory::Create() { - return make_scoped_ptr<GpuMemoryBufferFactory>( - new GpuMemoryBufferFactoryImpl); -} - -} // namespace content diff --git a/content/common/gpu/gpu_messages.h b/content/common/gpu/gpu_messages.h index 52ab4c0..9bb7b3d 100644 --- a/content/common/gpu/gpu_messages.h +++ b/content/common/gpu/gpu_messages.h @@ -75,15 +75,6 @@ IPC_STRUCT_BEGIN(GPUCreateCommandBufferConfig) IPC_STRUCT_MEMBER(gfx::GpuPreference, gpu_preference) IPC_STRUCT_END() -IPC_STRUCT_BEGIN(GpuMsg_CreateGpuMemoryBuffer_Params) - IPC_STRUCT_MEMBER(gfx::GpuMemoryBufferType, type) - IPC_STRUCT_MEMBER(int32, id) - IPC_STRUCT_MEMBER(gfx::Size, size) - IPC_STRUCT_MEMBER(gfx::GpuMemoryBuffer::Format, format) - IPC_STRUCT_MEMBER(gfx::GpuMemoryBuffer::Usage, usage) - IPC_STRUCT_MEMBER(int32, client_id) -IPC_STRUCT_END() - IPC_STRUCT_BEGIN(GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params) IPC_STRUCT_MEMBER(int32, surface_id) IPC_STRUCT_MEMBER(uint64, surface_handle) @@ -259,12 +250,15 @@ IPC_MESSAGE_CONTROL5(GpuMsg_CreateViewCommandBuffer, int32 /* route_id */) // Tells the GPU process to create a new gpu memory buffer. -IPC_MESSAGE_CONTROL1(GpuMsg_CreateGpuMemoryBuffer, - GpuMsg_CreateGpuMemoryBuffer_Params) +IPC_MESSAGE_CONTROL5(GpuMsg_CreateGpuMemoryBuffer, + gfx::GpuMemoryBufferId, /* id */ + gfx::Size, /* size */ + gfx::GpuMemoryBuffer::Format, /* format */ + gfx::GpuMemoryBuffer::Usage, /* usage */ + int32 /* client_id */) // Tells the GPU process to destroy buffer. -IPC_MESSAGE_CONTROL4(GpuMsg_DestroyGpuMemoryBuffer, - gfx::GpuMemoryBufferType, /* type */ +IPC_MESSAGE_CONTROL3(GpuMsg_DestroyGpuMemoryBuffer, gfx::GpuMemoryBufferId, /* id */ int32, /* client_id */ int32 /* sync_point */) diff --git a/content/content_common.gypi b/content/content_common.gypi index eb16af7..19b2c20 100644 --- a/content/content_common.gypi +++ b/content/content_common.gypi @@ -259,19 +259,13 @@ 'common/gpu/client/gl_helper_scaling.h', 'common/gpu/client/gpu_channel_host.cc', 'common/gpu/client/gpu_channel_host.h', - 'common/gpu/client/gpu_memory_buffer_factory_host.cc', 'common/gpu/client/gpu_memory_buffer_factory_host.h', 'common/gpu/client/gpu_memory_buffer_impl.cc', 'common/gpu/client/gpu_memory_buffer_impl.h', - 'common/gpu/client/gpu_memory_buffer_impl_android.cc', - 'common/gpu/client/gpu_memory_buffer_impl_linux.cc', - 'common/gpu/client/gpu_memory_buffer_impl_mac.cc', - 'common/gpu/client/gpu_memory_buffer_impl_ozone.cc', 'common/gpu/client/gpu_memory_buffer_impl_ozone_native_buffer.cc', 'common/gpu/client/gpu_memory_buffer_impl_ozone_native_buffer.h', 'common/gpu/client/gpu_memory_buffer_impl_shared_memory.cc', 'common/gpu/client/gpu_memory_buffer_impl_shared_memory.h', - 'common/gpu/client/gpu_memory_buffer_impl_win.cc', 'common/gpu/client/gpu_video_decode_accelerator_host.cc', 'common/gpu/client/gpu_video_decode_accelerator_host.h', 'common/gpu/client/gpu_video_encode_accelerator_host.cc', @@ -289,12 +283,12 @@ 'common/gpu/gpu_command_buffer_stub.cc', 'common/gpu/gpu_command_buffer_stub.h', 'common/gpu/gpu_config.h', + 'common/gpu/gpu_memory_buffer_factory.cc', 'common/gpu/gpu_memory_buffer_factory.h', - 'common/gpu/gpu_memory_buffer_factory_android.cc', - 'common/gpu/gpu_memory_buffer_factory_linux.cc', - 'common/gpu/gpu_memory_buffer_factory_mac.cc', - 'common/gpu/gpu_memory_buffer_factory_ozone.cc', - 'common/gpu/gpu_memory_buffer_factory_win.cc', + 'common/gpu/gpu_memory_buffer_factory_ozone_native_buffer.cc', + 'common/gpu/gpu_memory_buffer_factory_ozone_native_buffer.h', + 'common/gpu/gpu_memory_buffer_factory_shared_memory.cc', + 'common/gpu/gpu_memory_buffer_factory_shared_memory.h', 'common/gpu/gpu_memory_manager.cc', 'common/gpu/gpu_memory_manager.h', 'common/gpu/gpu_memory_manager_client.cc', @@ -927,6 +921,8 @@ 'common/gpu/client/gpu_memory_buffer_impl_ozone_native_buffer.cc', 'common/gpu/client/gpu_memory_buffer_impl_ozone_native_buffer.h', 'common/gpu/gpu_memory_buffer_factory_ozone.cc', + 'common/gpu/gpu_memory_buffer_factory_ozone_native_buffer.cc', + 'common/gpu/gpu_memory_buffer_factory_ozone_native_buffer.h', ], }], ], diff --git a/content/content_tests.gypi b/content/content_tests.gypi index bf1a32d..269a057 100644 --- a/content/content_tests.gypi +++ b/content/content_tests.gypi @@ -705,6 +705,7 @@ 'common/dwrite_font_platform_win_unittest.cc', 'common/fileapi/file_system_util_unittest.cc', 'common/gpu/client/gpu_memory_buffer_impl_unittest.cc', + 'common/gpu/gpu_memory_buffer_factory_unittest.cc', 'common/gpu/gpu_memory_manager_unittest.cc', 'common/host_discardable_shared_memory_manager_unittest.cc', 'common/host_shared_bitmap_manager_unittest.cc', diff --git a/content/test/content_test_suite.cc b/content/test/content_test_suite.cc index 24bad08..0feb361 100644 --- a/content/test/content_test_suite.cc +++ b/content/test/content_test_suite.cc @@ -4,6 +4,12 @@ #include "content/test/content_test_suite.h" +#if defined(OS_ANDROID) +#include <android/native_window.h> +#include <android/native_window_jni.h> +#include <map> +#endif + #include "base/base_paths.h" #include "base/logging.h" #include "content/public/common/content_client.h" @@ -30,6 +36,15 @@ #include "ui/gl/gl_surface.h" #endif +#if defined(OS_ANDROID) +#include "base/android/jni_android.h" +#include "base/memory/linked_ptr.h" +#include "content/common/android/surface_texture_manager.h" +#include "ui/gl/android/scoped_java_surface.h" +#include "ui/gl/android/surface_texture.h" +#endif + +namespace content { namespace { class TestInitializationListener : public testing::EmptyTestEventListener { @@ -52,9 +67,34 @@ class TestInitializationListener : public testing::EmptyTestEventListener { DISALLOW_COPY_AND_ASSIGN(TestInitializationListener); }; -} // namespace +#if defined(OS_ANDROID) +class SurfaceTextureManagerImpl : public SurfaceTextureManager { + public: + // Overridden from SurfaceTextureManager: + void RegisterSurfaceTexture(int surface_texture_id, + int client_id, + gfx::SurfaceTexture* surface_texture) override { + surfaces_[surface_texture_id] = + make_linked_ptr(new gfx::ScopedJavaSurface(surface_texture)); + } + void UnregisterSurfaceTexture(int surface_texture_id, + int client_id) override { + surfaces_.erase(surface_texture_id); + } + gfx::AcceleratedWidget AcquireNativeWidgetForSurfaceTexture( + int surface_texture_id) override { + JNIEnv* env = base::android::AttachCurrentThread(); + return ANativeWindow_fromSurface( + env, surfaces_[surface_texture_id]->j_surface().obj()); + } -namespace content { + private: + typedef std::map<int, linked_ptr<gfx::ScopedJavaSurface>> SurfaceMap; + SurfaceMap surfaces_; +}; +#endif + +} // namespace ContentTestSuite::ContentTestSuite(int argc, char** argv) : ContentTestSuiteBase(argc, argv) { @@ -94,6 +134,9 @@ void ContentTestSuite::Initialize() { testing::TestEventListeners& listeners = testing::UnitTest::GetInstance()->listeners(); listeners.Append(new TestInitializationListener); +#if defined(OS_ANDROID) + SurfaceTextureManager::InitInstance(new SurfaceTextureManagerImpl); +#endif } } // namespace content |