diff options
13 files changed, 303 insertions, 3 deletions
diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc index 4bcda41..471d9da 100644 --- a/content/browser/renderer_host/render_process_host_impl.cc +++ b/content/browser/renderer_host/render_process_host_impl.cc @@ -2334,6 +2334,7 @@ void RenderProcessHostImpl::OnAllocateGpuMemoryBuffer(uint32 width, internalformat, usage, GetHandle(), + GetID(), base::Bind(&RenderProcessHostImpl::GpuMemoryBufferAllocated, weak_factory_.GetWeakPtr(), reply)); diff --git a/content/common/gpu/client/gpu_channel_host.cc b/content/common/gpu/client/gpu_channel_host.cc index 492e696..d0ceecd 100644 --- a/content/common/gpu/client/gpu_channel_host.cc +++ b/content/common/gpu/client/gpu_channel_host.cc @@ -304,6 +304,10 @@ gfx::GpuMemoryBufferHandle GpuChannelHost::ShareGpuMemoryBufferToGpuProcess( handle.handle = ShareToGpuProcess(source_handle.handle); return handle; } +#if defined(USE_OZONE) + case gfx::OZONE_NATIVE_BUFFER: + return source_handle; +#endif #if defined(OS_MACOSX) case gfx::IO_SURFACE_BUFFER: return source_handle; diff --git a/content/common/gpu/client/gpu_memory_buffer_factory_host.cc b/content/common/gpu/client/gpu_memory_buffer_factory_host.cc new file mode 100644 index 0000000..ea7a321 --- /dev/null +++ b/content/common/gpu/client/gpu_memory_buffer_factory_host.cc @@ -0,0 +1,27 @@ +// 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 6dfd58b..9e616e2 100644 --- a/content/common/gpu/client/gpu_memory_buffer_factory_host.h +++ b/content/common/gpu/client/gpu_memory_buffer_factory_host.h @@ -6,6 +6,7 @@ #define CONTENT_COMMON_GPU_CLIENT_GPU_MEMORY_BUFFER_FACTORY_HOST_H_ #include "base/callback.h" +#include "content/common/content_export.h" namespace gfx { class Size; @@ -19,6 +20,8 @@ class CONTENT_EXPORT GpuMemoryBufferFactoryHost { typedef base::Callback<void(const gfx::GpuMemoryBufferHandle& handle)> CreateGpuMemoryBufferCallback; + static GpuMemoryBufferFactoryHost* GetInstance(); + virtual void CreateGpuMemoryBuffer( const gfx::GpuMemoryBufferHandle& handle, const gfx::Size& size, @@ -29,7 +32,8 @@ class CONTENT_EXPORT GpuMemoryBufferFactoryHost { int32 sync_point) = 0; protected: - virtual ~GpuMemoryBufferFactoryHost() {} + GpuMemoryBufferFactoryHost(); + virtual ~GpuMemoryBufferFactoryHost(); }; } // namespace content diff --git a/content/common/gpu/client/gpu_memory_buffer_impl.h b/content/common/gpu/client/gpu_memory_buffer_impl.h index 2565c02..e3323f0 100644 --- a/content/common/gpu/client/gpu_memory_buffer_impl.h +++ b/content/common/gpu/client/gpu_memory_buffer_impl.h @@ -27,12 +27,13 @@ class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { unsigned usage); // Allocates a GPU memory buffer with |size| and |internalformat| for |usage| - // by |child_process|. The |handle| returned can be used by the - // |child_process| to create an instance of this class. + // by |child_process| identified by |child_id|. The |handle| returned can be + // used by the |child_process| to create an instance of this class. static void AllocateForChildProcess(const gfx::Size& size, unsigned internalformat, unsigned usage, base::ProcessHandle child_process, + int child_id, const AllocationCallback& callback); // Notify that GPU memory buffer has been deleted by |child_process|. diff --git a/content/common/gpu/client/gpu_memory_buffer_impl_android.cc b/content/common/gpu/client/gpu_memory_buffer_impl_android.cc index 44efda0..799eff5 100644 --- a/content/common/gpu/client/gpu_memory_buffer_impl_android.cc +++ b/content/common/gpu/client/gpu_memory_buffer_impl_android.cc @@ -33,6 +33,7 @@ void GpuMemoryBufferImpl::AllocateForChildProcess( unsigned internalformat, unsigned usage, base::ProcessHandle child_process, + int child_id, const AllocationCallback& callback) { if (GpuMemoryBufferImplSharedMemory::IsConfigurationSupported( size, internalformat, usage)) { diff --git a/content/common/gpu/client/gpu_memory_buffer_impl_linux.cc b/content/common/gpu/client/gpu_memory_buffer_impl_linux.cc index 0fc371b..5c04cd8 100644 --- a/content/common/gpu/client/gpu_memory_buffer_impl_linux.cc +++ b/content/common/gpu/client/gpu_memory_buffer_impl_linux.cc @@ -32,6 +32,7 @@ void GpuMemoryBufferImpl::AllocateForChildProcess( unsigned internalformat, unsigned usage, base::ProcessHandle child_process, + int child_id, const AllocationCallback& callback) { if (GpuMemoryBufferImplSharedMemory::IsConfigurationSupported( size, internalformat, usage)) { diff --git a/content/common/gpu/client/gpu_memory_buffer_impl_mac.cc b/content/common/gpu/client/gpu_memory_buffer_impl_mac.cc index 24e39a6..11949c9 100644 --- a/content/common/gpu/client/gpu_memory_buffer_impl_mac.cc +++ b/content/common/gpu/client/gpu_memory_buffer_impl_mac.cc @@ -33,6 +33,7 @@ void GpuMemoryBufferImpl::AllocateForChildProcess( unsigned internalformat, unsigned usage, base::ProcessHandle child_process, + int child_id, const AllocationCallback& callback) { if (GpuMemoryBufferImplSharedMemory::IsConfigurationSupported( size, internalformat, usage)) { diff --git a/content/common/gpu/client/gpu_memory_buffer_impl_ozone.cc b/content/common/gpu/client/gpu_memory_buffer_impl_ozone.cc new file mode 100644 index 0000000..784f75c --- /dev/null +++ b/content/common/gpu/client/gpu_memory_buffer_impl_ozone.cc @@ -0,0 +1,88 @@ +// 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 +scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImpl::Create( + const gfx::Size& size, + unsigned internalformat, + unsigned usage) { + if (GpuMemoryBufferImplSharedMemory::IsConfigurationSupported( + size, internalformat, usage)) { + scoped_ptr<GpuMemoryBufferImplSharedMemory> buffer( + new GpuMemoryBufferImplSharedMemory(size, internalformat)); + if (!buffer->Initialize()) + return scoped_ptr<GpuMemoryBufferImpl>(); + + return buffer.PassAs<GpuMemoryBufferImpl>(); + } + + return scoped_ptr<GpuMemoryBufferImpl>(); +} + +// static +void GpuMemoryBufferImpl::AllocateForChildProcess( + const gfx::Size& size, + unsigned internalformat, + unsigned usage, + base::ProcessHandle child_process, + int child_id, + const AllocationCallback& callback) { + if (GpuMemoryBufferImplOzoneNativeBuffer::IsConfigurationSupported( + internalformat, usage)) { + GpuMemoryBufferImplOzoneNativeBuffer::AllocateOzoneNativeBufferForChildId( + size, internalformat, usage, child_id, callback); + return; + } + if (GpuMemoryBufferImplSharedMemory::IsConfigurationSupported( + size, internalformat, usage)) { + GpuMemoryBufferImplSharedMemory::AllocateSharedMemoryForChildProcess( + size, internalformat, child_process, callback); + return; + } + + callback.Run(gfx::GpuMemoryBufferHandle()); +} + +// static +void GpuMemoryBufferImpl::DeletedByChildProcess( + gfx::GpuMemoryBufferType type, + const gfx::GpuMemoryBufferId& id, + base::ProcessHandle child_process) { +} + +// static +scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImpl::CreateFromHandle( + const gfx::GpuMemoryBufferHandle& handle, + const gfx::Size& size, + unsigned internalformat) { + switch (handle.type) { + case gfx::SHARED_MEMORY_BUFFER: { + scoped_ptr<GpuMemoryBufferImplSharedMemory> buffer( + new GpuMemoryBufferImplSharedMemory(size, internalformat)); + if (!buffer->InitializeFromHandle(handle)) + return scoped_ptr<GpuMemoryBufferImpl>(); + + return buffer.PassAs<GpuMemoryBufferImpl>(); + } + case gfx::OZONE_NATIVE_BUFFER: { + scoped_ptr<GpuMemoryBufferImplOzoneNativeBuffer> buffer( + new GpuMemoryBufferImplOzoneNativeBuffer(size, internalformat)); + if (!buffer->InitializeFromHandle(handle)) + return scoped_ptr<GpuMemoryBufferImpl>(); + + return buffer.PassAs<GpuMemoryBufferImpl>(); + } + default: + 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 new file mode 100644 index 0000000..fe2681b --- /dev/null +++ b/content/common/gpu/client/gpu_memory_buffer_impl_ozone_native_buffer.cc @@ -0,0 +1,110 @@ +// 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_ozone_native_buffer.h" + +#include "base/atomic_sequence_num.h" +#include "base/bind.h" +#include "content/common/gpu/client/gpu_memory_buffer_factory_host.h" +#include "ui/gl/gl_bindings.h" + +namespace content { +namespace { + +base::StaticAtomicSequenceNumber g_next_buffer_id; + +} // namespace + +GpuMemoryBufferImplOzoneNativeBuffer::GpuMemoryBufferImplOzoneNativeBuffer( + const gfx::Size& size, + unsigned internalformat) + : GpuMemoryBufferImpl(size, internalformat) { +} + +GpuMemoryBufferImplOzoneNativeBuffer::~GpuMemoryBufferImplOzoneNativeBuffer() { +} + +// static +void GpuMemoryBufferImplOzoneNativeBuffer::AllocateOzoneNativeBufferForChildId( + const gfx::Size& size, + unsigned internalformat, + unsigned usage, + int child_id, + const AllocationCallback& callback) { + gfx::GpuMemoryBufferHandle handle; + // +1 ensures we always get non-zero IDs. + handle.global_id.primary_id = g_next_buffer_id.GetNext() + 1; + handle.global_id.secondary_id = child_id; + handle.type = gfx::OZONE_NATIVE_BUFFER; + GpuMemoryBufferFactoryHost::GetInstance()->CreateGpuMemoryBuffer( + handle, + size, + internalformat, + usage, + base::Bind(&OnGpuMemoryBufferCreated, callback)); +} + +// static +bool GpuMemoryBufferImplOzoneNativeBuffer::IsFormatSupported( + unsigned internalformat) { + switch (internalformat) { + case GL_RGBA8_OES: + return true; + default: + return false; + } +} + +// static +bool GpuMemoryBufferImplOzoneNativeBuffer::IsUsageSupported(unsigned usage) { + switch (usage) { + case GL_IMAGE_SCANOUT_CHROMIUM: + return true; + default: + return false; + } +} + +// static +bool GpuMemoryBufferImplOzoneNativeBuffer::IsConfigurationSupported( + unsigned internalformat, + unsigned usage) { + return IsFormatSupported(internalformat) && IsUsageSupported(usage); +} + +bool GpuMemoryBufferImplOzoneNativeBuffer::InitializeFromHandle( + const gfx::GpuMemoryBufferHandle& handle) { + id_ = handle.global_id; + return true; +} + +void* GpuMemoryBufferImplOzoneNativeBuffer::Map() { + NOTREACHED(); + return NULL; +} + +void GpuMemoryBufferImplOzoneNativeBuffer::Unmap() { + NOTREACHED(); +} + +uint32 GpuMemoryBufferImplOzoneNativeBuffer::GetStride() const { + NOTREACHED(); + return 0; +} + +gfx::GpuMemoryBufferHandle GpuMemoryBufferImplOzoneNativeBuffer::GetHandle() + const { + gfx::GpuMemoryBufferHandle handle; + handle.type = gfx::OZONE_NATIVE_BUFFER; + handle.global_id = id_; + return handle; +} + +void GpuMemoryBufferImplOzoneNativeBuffer::OnGpuMemoryBufferCreated( + const AllocationCallback& callback, + const gfx::GpuMemoryBufferHandle& handle) { + callback.Run(handle); +} + +} // namespace content 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 new file mode 100644 index 0000000..ab4cc56 --- /dev/null +++ b/content/common/gpu/client/gpu_memory_buffer_impl_ozone_native_buffer.h @@ -0,0 +1,52 @@ +// 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_CLIENT_GPU_MEMORY_BUFFER_IMPL_OZONE_H_ +#define CONTENT_COMMON_GPU_CLIENT_GPU_MEMORY_BUFFER_IMPL_OZONE_H_ + +#include "content/common/gpu/client/gpu_memory_buffer_impl.h" + +namespace content { + +// Implementation of GPU memory buffer based on Ozone native buffers. +class GpuMemoryBufferImplOzoneNativeBuffer : public GpuMemoryBufferImpl { + public: + GpuMemoryBufferImplOzoneNativeBuffer(const gfx::Size& size, + unsigned internalformat); + virtual ~GpuMemoryBufferImplOzoneNativeBuffer(); + + // Allocates an Ozone native buffer backed GPU memory buffer with |size| and + // |internalformat| with usage |usage| for use by |child_id|. + static void AllocateOzoneNativeBufferForChildId( + const gfx::Size& size, + unsigned internalformat, + unsigned usage, + int child_id, + const AllocationCallback& callback); + + static bool IsFormatSupported(unsigned internalformat); + static bool IsUsageSupported(unsigned usage); + static bool IsConfigurationSupported(unsigned internalformat, unsigned usage); + + bool InitializeFromHandle(const gfx::GpuMemoryBufferHandle& handle); + + // Overridden from gfx::GpuMemoryBuffer: + virtual void* Map() OVERRIDE; + virtual void Unmap() OVERRIDE; + virtual uint32 GetStride() const OVERRIDE; + virtual gfx::GpuMemoryBufferHandle GetHandle() const OVERRIDE; + + private: + static void OnGpuMemoryBufferCreated( + const AllocationCallback& callback, + const gfx::GpuMemoryBufferHandle& handle); + + gfx::GpuMemoryBufferId id_; + + DISALLOW_COPY_AND_ASSIGN(GpuMemoryBufferImplOzoneNativeBuffer); +}; + +} // namespace content + +#endif // CONTENT_COMMON_GPU_CLIENT_GPU_MEMORY_BUFFER_IMPL_OZONE_H_ diff --git a/content/common/gpu/client/gpu_memory_buffer_impl_win.cc b/content/common/gpu/client/gpu_memory_buffer_impl_win.cc index 0fc371b..5c04cd8 100644 --- a/content/common/gpu/client/gpu_memory_buffer_impl_win.cc +++ b/content/common/gpu/client/gpu_memory_buffer_impl_win.cc @@ -32,6 +32,7 @@ void GpuMemoryBufferImpl::AllocateForChildProcess( unsigned internalformat, unsigned usage, base::ProcessHandle child_process, + int child_id, const AllocationCallback& callback) { if (GpuMemoryBufferImplSharedMemory::IsConfigurationSupported( size, internalformat, usage)) { diff --git a/content/content_common.gypi b/content/content_common.gypi index 048ab0d..b5ffcf3 100644 --- a/content/content_common.gypi +++ b/content/content_common.gypi @@ -251,12 +251,15 @@ '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_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', @@ -892,6 +895,12 @@ '../ui/ozone/ozone.gyp:ozone', '../ui/ozone/gpu/ozone_gpu.gyp:ozone_gpu', ], + 'sources': [ + 'common/gpu/client/gpu_memory_buffer_impl_ozone.cc', + ], + 'sources!': [ + 'common/gpu/client/gpu_memory_buffer_impl_linux.cc', + ], }], ], } |