Commit 2992e56e authored by alexst's avatar alexst Committed by Commit bot

We need to cleanup GpuMemoryBuffers allocated in the GPU process.

This code conditionally stashes a sync point for buffer types that require it for the destruction phase.

BUG=416873

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

Cr-Commit-Position: refs/heads/master@{#302561}
parent 84beeaa3
...@@ -93,4 +93,9 @@ TestGpuMemoryBufferManager::GpuMemoryBufferFromClientBuffer( ...@@ -93,4 +93,9 @@ TestGpuMemoryBufferManager::GpuMemoryBufferFromClientBuffer(
return reinterpret_cast<gfx::GpuMemoryBuffer*>(buffer); return reinterpret_cast<gfx::GpuMemoryBuffer*>(buffer);
} }
void TestGpuMemoryBufferManager::SetDestructionSyncPoint(
gfx::GpuMemoryBuffer* buffer,
uint32 sync_point) {
}
} // namespace cc } // namespace cc
...@@ -21,6 +21,8 @@ class TestGpuMemoryBufferManager : public gpu::GpuMemoryBufferManager { ...@@ -21,6 +21,8 @@ class TestGpuMemoryBufferManager : public gpu::GpuMemoryBufferManager {
gfx::GpuMemoryBuffer::Usage usage) override; gfx::GpuMemoryBuffer::Usage usage) override;
gfx::GpuMemoryBuffer* GpuMemoryBufferFromClientBuffer( gfx::GpuMemoryBuffer* GpuMemoryBufferFromClientBuffer(
ClientBuffer buffer) override; ClientBuffer buffer) override;
void SetDestructionSyncPoint(gfx::GpuMemoryBuffer* buffer,
uint32 sync_point) override;
private: private:
DISALLOW_COPY_AND_ASSIGN(TestGpuMemoryBufferManager); DISALLOW_COPY_AND_ASSIGN(TestGpuMemoryBufferManager);
......
...@@ -110,10 +110,13 @@ BrowserGpuMemoryBufferManager::GpuMemoryBufferFromClientBuffer( ...@@ -110,10 +110,13 @@ BrowserGpuMemoryBufferManager::GpuMemoryBufferFromClientBuffer(
void BrowserGpuMemoryBufferManager::ChildProcessDeletedGpuMemoryBuffer( void BrowserGpuMemoryBufferManager::ChildProcessDeletedGpuMemoryBuffer(
gfx::GpuMemoryBufferType type, gfx::GpuMemoryBufferType type,
const gfx::GpuMemoryBufferId& id, const gfx::GpuMemoryBufferId& id,
base::ProcessHandle child_process_handle) { base::ProcessHandle child_process_handle,
int child_client_id,
uint32 sync_point) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
GpuMemoryBufferImpl::DeletedByChildProcess(type, id, child_process_handle); GpuMemoryBufferImpl::DeletedByChildProcess(
type, id, child_process_handle, child_client_id, sync_point);
} }
void BrowserGpuMemoryBufferManager::ProcessRemoved( void BrowserGpuMemoryBufferManager::ProcessRemoved(
...@@ -143,4 +146,11 @@ void BrowserGpuMemoryBufferManager::GpuMemoryBufferCreatedOnIO( ...@@ -143,4 +146,11 @@ void BrowserGpuMemoryBufferManager::GpuMemoryBufferCreatedOnIO(
request->event.Signal(); request->event.Signal();
} }
void BrowserGpuMemoryBufferManager::SetDestructionSyncPoint(
gfx::GpuMemoryBuffer* buffer,
uint32 sync_point) {
static_cast<GpuMemoryBufferImpl*>(buffer)
->set_destruction_sync_point(sync_point);
}
} // namespace content } // namespace content
...@@ -30,6 +30,8 @@ class CONTENT_EXPORT BrowserGpuMemoryBufferManager ...@@ -30,6 +30,8 @@ class CONTENT_EXPORT BrowserGpuMemoryBufferManager
gfx::GpuMemoryBuffer::Usage usage) override; gfx::GpuMemoryBuffer::Usage usage) override;
gfx::GpuMemoryBuffer* GpuMemoryBufferFromClientBuffer( gfx::GpuMemoryBuffer* GpuMemoryBufferFromClientBuffer(
ClientBuffer buffer) override; ClientBuffer buffer) override;
void SetDestructionSyncPoint(gfx::GpuMemoryBuffer* buffer,
uint32 sync_point) override;
void AllocateGpuMemoryBufferForChildProcess( void AllocateGpuMemoryBufferForChildProcess(
const gfx::Size& size, const gfx::Size& size,
...@@ -41,7 +43,9 @@ class CONTENT_EXPORT BrowserGpuMemoryBufferManager ...@@ -41,7 +43,9 @@ class CONTENT_EXPORT BrowserGpuMemoryBufferManager
void ChildProcessDeletedGpuMemoryBuffer( void ChildProcessDeletedGpuMemoryBuffer(
gfx::GpuMemoryBufferType type, gfx::GpuMemoryBufferType type,
const gfx::GpuMemoryBufferId& id, const gfx::GpuMemoryBufferId& id,
base::ProcessHandle child_process_handle); base::ProcessHandle child_process_handle,
int child_client_id,
uint32 sync_point);
void ProcessRemoved(base::ProcessHandle process_handle); void ProcessRemoved(base::ProcessHandle process_handle);
private: private:
......
...@@ -24,6 +24,24 @@ void GpuMemoryBufferFactoryHostImpl::CreateGpuMemoryBuffer( ...@@ -24,6 +24,24 @@ void GpuMemoryBufferFactoryHostImpl::CreateGpuMemoryBuffer(
gfx::GpuMemoryBuffer::Format format, gfx::GpuMemoryBuffer::Format format,
gfx::GpuMemoryBuffer::Usage usage, gfx::GpuMemoryBuffer::Usage usage,
const CreateGpuMemoryBufferCallback& callback) { const CreateGpuMemoryBufferCallback& callback) {
BrowserThread::PostTask(
BrowserThread::IO,
FROM_HERE,
base::Bind(&GpuMemoryBufferFactoryHostImpl::CreateGpuMemoryBufferOnIO,
base::Unretained(this),
handle,
size,
format,
usage,
callback));
}
void GpuMemoryBufferFactoryHostImpl::CreateGpuMemoryBufferOnIO(
const gfx::GpuMemoryBufferHandle& handle,
const gfx::Size& size,
gfx::GpuMemoryBuffer::Format format,
gfx::GpuMemoryBuffer::Usage usage,
const CreateGpuMemoryBufferCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_); GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_);
...@@ -48,6 +66,18 @@ void GpuMemoryBufferFactoryHostImpl::CreateGpuMemoryBuffer( ...@@ -48,6 +66,18 @@ void GpuMemoryBufferFactoryHostImpl::CreateGpuMemoryBuffer(
void GpuMemoryBufferFactoryHostImpl::DestroyGpuMemoryBuffer( void GpuMemoryBufferFactoryHostImpl::DestroyGpuMemoryBuffer(
const gfx::GpuMemoryBufferHandle& handle, const gfx::GpuMemoryBufferHandle& handle,
int32 sync_point) { int32 sync_point) {
BrowserThread::PostTask(
BrowserThread::IO,
FROM_HERE,
base::Bind(&GpuMemoryBufferFactoryHostImpl::DestroyGpuMemoryBufferOnIO,
base::Unretained(this),
handle,
sync_point));
}
void GpuMemoryBufferFactoryHostImpl::DestroyGpuMemoryBufferOnIO(
const gfx::GpuMemoryBufferHandle& handle,
int32 sync_point) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_); GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_);
......
...@@ -30,6 +30,13 @@ class CONTENT_EXPORT GpuMemoryBufferFactoryHostImpl ...@@ -30,6 +30,13 @@ class CONTENT_EXPORT GpuMemoryBufferFactoryHostImpl
void set_gpu_host_id(int gpu_host_id) { gpu_host_id_ = gpu_host_id; } void set_gpu_host_id(int gpu_host_id) { gpu_host_id_ = gpu_host_id; }
private: private:
void CreateGpuMemoryBufferOnIO(const gfx::GpuMemoryBufferHandle& handle,
const gfx::Size& size,
gfx::GpuMemoryBuffer::Format format,
gfx::GpuMemoryBuffer::Usage usage,
const CreateGpuMemoryBufferCallback& callback);
void DestroyGpuMemoryBufferOnIO(const gfx::GpuMemoryBufferHandle& handle,
int32 sync_point);
void OnGpuMemoryBufferCreated(uint32 request_id, void OnGpuMemoryBufferCreated(uint32 request_id,
const gfx::GpuMemoryBufferHandle& handle); const gfx::GpuMemoryBufferHandle& handle);
......
...@@ -1272,9 +1272,10 @@ void RenderMessageFilter::GpuMemoryBufferAllocated( ...@@ -1272,9 +1272,10 @@ void RenderMessageFilter::GpuMemoryBufferAllocated(
void RenderMessageFilter::OnDeletedGpuMemoryBuffer( void RenderMessageFilter::OnDeletedGpuMemoryBuffer(
gfx::GpuMemoryBufferType type, gfx::GpuMemoryBufferType type,
const gfx::GpuMemoryBufferId& id) { const gfx::GpuMemoryBufferId& id,
uint32 sync_point) {
BrowserGpuMemoryBufferManager::current()->ChildProcessDeletedGpuMemoryBuffer( BrowserGpuMemoryBufferManager::current()->ChildProcessDeletedGpuMemoryBuffer(
type, id, PeerHandle()); type, id, PeerHandle(), render_process_id_, sync_point);
} }
} // namespace content } // namespace content
...@@ -305,7 +305,8 @@ class CONTENT_EXPORT RenderMessageFilter : public BrowserMessageFilter { ...@@ -305,7 +305,8 @@ class CONTENT_EXPORT RenderMessageFilter : public BrowserMessageFilter {
void GpuMemoryBufferAllocated(IPC::Message* reply, void GpuMemoryBufferAllocated(IPC::Message* reply,
const gfx::GpuMemoryBufferHandle& handle); const gfx::GpuMemoryBufferHandle& handle);
void OnDeletedGpuMemoryBuffer(gfx::GpuMemoryBufferType type, void OnDeletedGpuMemoryBuffer(gfx::GpuMemoryBufferType type,
const gfx::GpuMemoryBufferId& id); const gfx::GpuMemoryBufferId& id,
uint32 sync_point);
// Cached resource request dispatcher host and plugin service, guaranteed to // Cached resource request dispatcher host and plugin service, guaranteed to
// be non-null if Init succeeds. We do not own the objects, they are managed // be non-null if Init succeeds. We do not own the objects, they are managed
......
...@@ -13,10 +13,12 @@ namespace { ...@@ -13,10 +13,12 @@ namespace {
void DeletedGpuMemoryBuffer(ThreadSafeSender* sender, void DeletedGpuMemoryBuffer(ThreadSafeSender* sender,
gfx::GpuMemoryBufferType type, gfx::GpuMemoryBufferType type,
const gfx::GpuMemoryBufferId& id) { const gfx::GpuMemoryBufferId& id,
uint32 sync_point) {
TRACE_EVENT0("renderer", TRACE_EVENT0("renderer",
"ChildGpuMemoryBufferManager::DeletedGpuMemoryBuffer"); "ChildGpuMemoryBufferManager::DeletedGpuMemoryBuffer");
sender->Send(new ChildProcessHostMsg_DeletedGpuMemoryBuffer(type, id)); sender->Send(
new ChildProcessHostMsg_DeletedGpuMemoryBuffer(type, id, sync_point));
} }
} // namespace } // namespace
...@@ -56,7 +58,7 @@ ChildGpuMemoryBufferManager::AllocateGpuMemoryBuffer( ...@@ -56,7 +58,7 @@ ChildGpuMemoryBufferManager::AllocateGpuMemoryBuffer(
&DeletedGpuMemoryBuffer, sender_, handle.type, handle.global_id))); &DeletedGpuMemoryBuffer, sender_, handle.type, handle.global_id)));
if (!buffer) { if (!buffer) {
sender_->Send(new ChildProcessHostMsg_DeletedGpuMemoryBuffer( sender_->Send(new ChildProcessHostMsg_DeletedGpuMemoryBuffer(
handle.type, handle.global_id)); handle.type, handle.global_id, 0));
return scoped_ptr<gfx::GpuMemoryBuffer>(); return scoped_ptr<gfx::GpuMemoryBuffer>();
} }
...@@ -69,4 +71,11 @@ ChildGpuMemoryBufferManager::GpuMemoryBufferFromClientBuffer( ...@@ -69,4 +71,11 @@ ChildGpuMemoryBufferManager::GpuMemoryBufferFromClientBuffer(
return GpuMemoryBufferImpl::FromClientBuffer(buffer); return GpuMemoryBufferImpl::FromClientBuffer(buffer);
} }
void ChildGpuMemoryBufferManager::SetDestructionSyncPoint(
gfx::GpuMemoryBuffer* buffer,
uint32 sync_point) {
static_cast<GpuMemoryBufferImpl*>(buffer)
->set_destruction_sync_point(sync_point);
}
} // namespace content } // namespace content
...@@ -22,6 +22,8 @@ class ChildGpuMemoryBufferManager : public gpu::GpuMemoryBufferManager { ...@@ -22,6 +22,8 @@ class ChildGpuMemoryBufferManager : public gpu::GpuMemoryBufferManager {
gfx::GpuMemoryBuffer::Usage usage) override; gfx::GpuMemoryBuffer::Usage usage) override;
gfx::GpuMemoryBuffer* GpuMemoryBufferFromClientBuffer( gfx::GpuMemoryBuffer* GpuMemoryBufferFromClientBuffer(
ClientBuffer buffer) override; ClientBuffer buffer) override;
void SetDestructionSyncPoint(gfx::GpuMemoryBuffer* buffer,
uint32 sync_point) override;
private: private:
scoped_refptr<ThreadSafeSender> sender_; scoped_refptr<ThreadSafeSender> sender_;
......
...@@ -344,7 +344,8 @@ void ChildProcessHostImpl::OnAllocateGpuMemoryBuffer( ...@@ -344,7 +344,8 @@ void ChildProcessHostImpl::OnAllocateGpuMemoryBuffer(
void ChildProcessHostImpl::OnDeletedGpuMemoryBuffer( void ChildProcessHostImpl::OnDeletedGpuMemoryBuffer(
gfx::GpuMemoryBufferType type, gfx::GpuMemoryBufferType type,
const gfx::GpuMemoryBufferId& id) { const gfx::GpuMemoryBufferId& id,
uint32 sync_point) {
// Note: Nothing to do here as ownership of shared memory backed // Note: Nothing to do here as ownership of shared memory backed
// GpuMemoryBuffers is passed with IPC. // GpuMemoryBuffers is passed with IPC.
} }
......
...@@ -85,7 +85,8 @@ class CONTENT_EXPORT ChildProcessHostImpl : public ChildProcessHost, ...@@ -85,7 +85,8 @@ class CONTENT_EXPORT ChildProcessHostImpl : public ChildProcessHost,
gfx::GpuMemoryBuffer::Usage usage, gfx::GpuMemoryBuffer::Usage usage,
IPC::Message* reply); IPC::Message* reply);
void OnDeletedGpuMemoryBuffer(gfx::GpuMemoryBufferType type, void OnDeletedGpuMemoryBuffer(gfx::GpuMemoryBufferType type,
const gfx::GpuMemoryBufferId& id); const gfx::GpuMemoryBufferId& id,
uint32 sync_point);
void GpuMemoryBufferAllocated(IPC::Message* reply, void GpuMemoryBufferAllocated(IPC::Message* reply,
const gfx::GpuMemoryBufferHandle& handle); const gfx::GpuMemoryBufferHandle& handle);
......
...@@ -198,9 +198,10 @@ IPC_SYNC_MESSAGE_CONTROL4_1(ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer, ...@@ -198,9 +198,10 @@ IPC_SYNC_MESSAGE_CONTROL4_1(ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer,
gfx::GpuMemoryBufferHandle) gfx::GpuMemoryBufferHandle)
// Informs the browser that the child deleted a gpu memory buffer. // Informs the browser that the child deleted a gpu memory buffer.
IPC_MESSAGE_CONTROL2(ChildProcessHostMsg_DeletedGpuMemoryBuffer, IPC_MESSAGE_CONTROL3(ChildProcessHostMsg_DeletedGpuMemoryBuffer,
gfx::GpuMemoryBufferType, gfx::GpuMemoryBufferType,
gfx::GpuMemoryBufferId) gfx::GpuMemoryBufferId,
uint32 /* sync_point */)
// Asks the browser to create a block of discardable shared memory for the // Asks the browser to create a block of discardable shared memory for the
// child process. // child process.
......
...@@ -308,17 +308,19 @@ int32_t CommandBufferProxyImpl::CreateImage(ClientBuffer buffer, ...@@ -308,17 +308,19 @@ int32_t CommandBufferProxyImpl::CreateImage(ClientBuffer buffer,
int32 new_id = channel_->ReserveImageId(); int32 new_id = channel_->ReserveImageId();
gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager =
channel_->gpu_memory_buffer_manager();
gfx::GpuMemoryBuffer* gpu_memory_buffer = gfx::GpuMemoryBuffer* gpu_memory_buffer =
channel_->gpu_memory_buffer_manager()->GpuMemoryBufferFromClientBuffer( gpu_memory_buffer_manager->GpuMemoryBufferFromClientBuffer(buffer);
buffer);
DCHECK(gpu_memory_buffer); DCHECK(gpu_memory_buffer);
// This handle is owned by the GPU process and must be passed to it or it // This handle is owned by the GPU process and must be passed to it or it
// will leak. In otherwords, do not early out on error between here and the // will leak. In otherwords, do not early out on error between here and the
// sending of the CreateImage IPC below. // sending of the CreateImage IPC below.
bool requires_sync_point = false;
gfx::GpuMemoryBufferHandle handle = gfx::GpuMemoryBufferHandle handle =
channel_->ShareGpuMemoryBufferToGpuProcess( channel_->ShareGpuMemoryBufferToGpuProcess(gpu_memory_buffer->GetHandle(),
gpu_memory_buffer->GetHandle()); &requires_sync_point);
DCHECK(gpu::ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat( DCHECK(gpu::ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat(
internalformat, gpu_memory_buffer->GetFormat())); internalformat, gpu_memory_buffer->GetFormat()));
...@@ -331,6 +333,11 @@ int32_t CommandBufferProxyImpl::CreateImage(ClientBuffer buffer, ...@@ -331,6 +333,11 @@ int32_t CommandBufferProxyImpl::CreateImage(ClientBuffer buffer,
return -1; return -1;
} }
if (requires_sync_point) {
gpu_memory_buffer_manager->SetDestructionSyncPoint(gpu_memory_buffer,
InsertSyncPoint());
}
return new_id; return new_id;
} }
......
...@@ -281,28 +281,34 @@ int32 GpuChannelHost::ReserveTransferBufferId() { ...@@ -281,28 +281,34 @@ int32 GpuChannelHost::ReserveTransferBufferId() {
} }
gfx::GpuMemoryBufferHandle GpuChannelHost::ShareGpuMemoryBufferToGpuProcess( gfx::GpuMemoryBufferHandle GpuChannelHost::ShareGpuMemoryBufferToGpuProcess(
gfx::GpuMemoryBufferHandle source_handle) { gfx::GpuMemoryBufferHandle source_handle,
bool* requires_sync_point) {
switch (source_handle.type) { switch (source_handle.type) {
case gfx::SHARED_MEMORY_BUFFER: { case gfx::SHARED_MEMORY_BUFFER: {
gfx::GpuMemoryBufferHandle handle; gfx::GpuMemoryBufferHandle handle;
handle.type = gfx::SHARED_MEMORY_BUFFER; handle.type = gfx::SHARED_MEMORY_BUFFER;
handle.handle = ShareToGpuProcess(source_handle.handle); handle.handle = ShareToGpuProcess(source_handle.handle);
*requires_sync_point = false;
return handle; return handle;
} }
#if defined(USE_OZONE) #if defined(USE_OZONE)
case gfx::OZONE_NATIVE_BUFFER: case gfx::OZONE_NATIVE_BUFFER:
*requires_sync_point = true;
return source_handle; return source_handle;
#endif #endif
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
case gfx::IO_SURFACE_BUFFER: case gfx::IO_SURFACE_BUFFER:
*requires_sync_point = true;
return source_handle; return source_handle;
#endif #endif
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
case gfx::SURFACE_TEXTURE_BUFFER: case gfx::SURFACE_TEXTURE_BUFFER:
*requires_sync_point = true;
return source_handle; return source_handle;
#endif #endif
#if defined(USE_X11) #if defined(USE_X11)
case gfx::X11_PIXMAP_BUFFER: case gfx::X11_PIXMAP_BUFFER:
*requires_sync_point = true;
return source_handle; return source_handle;
#endif #endif
default: default:
......
...@@ -153,7 +153,8 @@ class GpuChannelHost : public IPC::Sender, ...@@ -153,7 +153,8 @@ class GpuChannelHost : public IPC::Sender,
// IPC to the GPU process. The caller is responsible for ensuring it is // IPC to the GPU process. The caller is responsible for ensuring it is
// closed. Returns an invalid handle on failure. // closed. Returns an invalid handle on failure.
gfx::GpuMemoryBufferHandle ShareGpuMemoryBufferToGpuProcess( gfx::GpuMemoryBufferHandle ShareGpuMemoryBufferToGpuProcess(
gfx::GpuMemoryBufferHandle source_handle); gfx::GpuMemoryBufferHandle source_handle,
bool* requires_sync_point);
// Reserve one unused image ID. // Reserve one unused image ID.
int32 ReserveImageId(); int32 ReserveImageId();
......
...@@ -11,11 +11,15 @@ namespace content { ...@@ -11,11 +11,15 @@ namespace content {
GpuMemoryBufferImpl::GpuMemoryBufferImpl(const gfx::Size& size, GpuMemoryBufferImpl::GpuMemoryBufferImpl(const gfx::Size& size,
Format format, Format format,
const DestructionCallback& callback) const DestructionCallback& callback)
: size_(size), format_(format), callback_(callback), mapped_(false) { : size_(size),
format_(format),
callback_(callback),
mapped_(false),
destruction_sync_point_(0) {
} }
GpuMemoryBufferImpl::~GpuMemoryBufferImpl() { GpuMemoryBufferImpl::~GpuMemoryBufferImpl() {
callback_.Run(); callback_.Run(destruction_sync_point_);
} }
// static // static
......
...@@ -19,7 +19,7 @@ class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { ...@@ -19,7 +19,7 @@ class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer {
CreationCallback; CreationCallback;
typedef base::Callback<void(const gfx::GpuMemoryBufferHandle& handle)> typedef base::Callback<void(const gfx::GpuMemoryBufferHandle& handle)>
AllocationCallback; AllocationCallback;
typedef base::Closure DestructionCallback; typedef base::Callback<void(uint32 sync_point)> DestructionCallback;
~GpuMemoryBufferImpl() override; ~GpuMemoryBufferImpl() override;
...@@ -44,7 +44,9 @@ class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { ...@@ -44,7 +44,9 @@ class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer {
// Notify that GPU memory buffer has been deleted by |child_process|. // Notify that GPU memory buffer has been deleted by |child_process|.
static void DeletedByChildProcess(gfx::GpuMemoryBufferType type, static void DeletedByChildProcess(gfx::GpuMemoryBufferType type,
const gfx::GpuMemoryBufferId& id, const gfx::GpuMemoryBufferId& id,
base::ProcessHandle child_process); base::ProcessHandle child_process,
int child_client_id,
uint32 sync_point);
// Creates an instance from the given |handle|. |size| and |internalformat| // Creates an instance from the given |handle|. |size| and |internalformat|
// should match what was used to allocate the |handle|. |callback| is // should match what was used to allocate the |handle|. |callback| is
...@@ -68,6 +70,10 @@ class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { ...@@ -68,6 +70,10 @@ class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer {
Format GetFormat() const override; Format GetFormat() const override;
ClientBuffer AsClientBuffer() override; ClientBuffer AsClientBuffer() override;
void set_destruction_sync_point(uint32 sync_point) {
destruction_sync_point_ = sync_point;
}
protected: protected:
GpuMemoryBufferImpl(const gfx::Size& size, GpuMemoryBufferImpl(const gfx::Size& size,
Format format, Format format,
...@@ -77,6 +83,7 @@ class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { ...@@ -77,6 +83,7 @@ class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer {
const Format format_; const Format format_;
const DestructionCallback callback_; const DestructionCallback callback_;
bool mapped_; bool mapped_;
uint32 destruction_sync_point_;
DISALLOW_COPY_AND_ASSIGN(GpuMemoryBufferImpl); DISALLOW_COPY_AND_ASSIGN(GpuMemoryBufferImpl);
}; };
......
...@@ -60,7 +60,24 @@ void GpuMemoryBufferImpl::AllocateForChildProcess( ...@@ -60,7 +60,24 @@ void GpuMemoryBufferImpl::AllocateForChildProcess(
void GpuMemoryBufferImpl::DeletedByChildProcess( void GpuMemoryBufferImpl::DeletedByChildProcess(
gfx::GpuMemoryBufferType type, gfx::GpuMemoryBufferType type,
const gfx::GpuMemoryBufferId& id, const gfx::GpuMemoryBufferId& id,
base::ProcessHandle child_process) { base::ProcessHandle child_process,
int child_client_id,
uint32 sync_point) {
switch (type) {
case gfx::SHARED_MEMORY_BUFFER:
break;
case gfx::SURFACE_TEXTURE_BUFFER:
if (id.secondary_id != child_client_id) {
LOG(ERROR)
<< "Child attempting to delete GpuMemoryBuffer it does not own";
} else {
GpuMemoryBufferImplSurfaceTexture::DeletedByChildProcess(id,
sync_point);
}
break;
default:
NOTREACHED();
}
} }
// static // static
......
...@@ -15,7 +15,10 @@ namespace { ...@@ -15,7 +15,10 @@ namespace {
base::StaticAtomicSequenceNumber g_next_buffer_id; base::StaticAtomicSequenceNumber g_next_buffer_id;
void Noop() { void GpuMemoryBufferDeleted(const gfx::GpuMemoryBufferHandle& handle,
uint32 sync_point) {
GpuMemoryBufferFactoryHost::GetInstance()->DestroyGpuMemoryBuffer(handle,
sync_point);
} }
void GpuMemoryBufferCreated( void GpuMemoryBufferCreated(
...@@ -26,7 +29,7 @@ void GpuMemoryBufferCreated( ...@@ -26,7 +29,7 @@ void GpuMemoryBufferCreated(
DCHECK_EQ(gfx::IO_SURFACE_BUFFER, handle.type); DCHECK_EQ(gfx::IO_SURFACE_BUFFER, handle.type);
callback.Run(GpuMemoryBufferImplIOSurface::CreateFromHandle( callback.Run(GpuMemoryBufferImplIOSurface::CreateFromHandle(
handle, size, format, base::Bind(&Noop))); handle, size, format, base::Bind(&GpuMemoryBufferDeleted, handle)));
} }
void GpuMemoryBufferCreatedForChildProcess( void GpuMemoryBufferCreatedForChildProcess(
...@@ -102,6 +105,16 @@ scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImplIOSurface::CreateFromHandle( ...@@ -102,6 +105,16 @@ scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImplIOSurface::CreateFromHandle(
size, format, callback, io_surface.get())); size, format, callback, io_surface.get()));
} }
void GpuMemoryBufferImplIOSurface::DeletedByChildProcess(
const gfx::GpuMemoryBufferId& id,
uint32_t sync_point) {
gfx::GpuMemoryBufferHandle handle;
handle.type = gfx::IO_SURFACE_BUFFER;
handle.global_id = id;
GpuMemoryBufferFactoryHost::GetInstance()->DestroyGpuMemoryBuffer(handle,
sync_point);
}
// static // static
bool GpuMemoryBufferImplIOSurface::IsFormatSupported(Format format) { bool GpuMemoryBufferImplIOSurface::IsFormatSupported(Format format) {
switch (format) { switch (format) {
......
...@@ -31,6 +31,9 @@ class GpuMemoryBufferImplIOSurface : public GpuMemoryBufferImpl { ...@@ -31,6 +31,9 @@ class GpuMemoryBufferImplIOSurface : public GpuMemoryBufferImpl {
Format format, Format format,
const DestructionCallback& callback); const DestructionCallback& callback);
static void DeletedByChildProcess(const gfx::GpuMemoryBufferId& id,
uint32_t sync_point);
static bool IsFormatSupported(Format format); static bool IsFormatSupported(Format format);
static bool IsUsageSupported(Usage usage); static bool IsUsageSupported(Usage usage);
static bool IsConfigurationSupported(Format format, Usage usage); static bool IsConfigurationSupported(Format format, Usage usage);
......
...@@ -45,7 +45,9 @@ void GpuMemoryBufferImpl::AllocateForChildProcess( ...@@ -45,7 +45,9 @@ void GpuMemoryBufferImpl::AllocateForChildProcess(
void GpuMemoryBufferImpl::DeletedByChildProcess( void GpuMemoryBufferImpl::DeletedByChildProcess(
gfx::GpuMemoryBufferType type, gfx::GpuMemoryBufferType type,
const gfx::GpuMemoryBufferId& id, const gfx::GpuMemoryBufferId& id,
base::ProcessHandle child_process) { base::ProcessHandle child_process,
int child_client_id,
uint32 sync_point) {
} }
// static // static
......
...@@ -57,7 +57,23 @@ void GpuMemoryBufferImpl::AllocateForChildProcess( ...@@ -57,7 +57,23 @@ void GpuMemoryBufferImpl::AllocateForChildProcess(
void GpuMemoryBufferImpl::DeletedByChildProcess( void GpuMemoryBufferImpl::DeletedByChildProcess(
gfx::GpuMemoryBufferType type, gfx::GpuMemoryBufferType type,
const gfx::GpuMemoryBufferId& id, const gfx::GpuMemoryBufferId& id,
base::ProcessHandle child_process) { base::ProcessHandle child_process,
int child_client_id,
uint32 sync_point) {
switch (type) {
case gfx::SHARED_MEMORY_BUFFER:
break;
case gfx::IO_SURFACE_BUFFER:
if (id.secondary_id != child_client_id) {
LOG(ERROR)
<< "Child attempting to delete GpuMemoryBuffer it does not own";
} else {
GpuMemoryBufferImplIOSurface::DeletedByChildProcess(id, sync_point);
}
break;
default:
NOTREACHED();
}
} }
// static // static
......
...@@ -60,7 +60,24 @@ void GpuMemoryBufferImpl::AllocateForChildProcess( ...@@ -60,7 +60,24 @@ void GpuMemoryBufferImpl::AllocateForChildProcess(
void GpuMemoryBufferImpl::DeletedByChildProcess( void GpuMemoryBufferImpl::DeletedByChildProcess(
gfx::GpuMemoryBufferType type, gfx::GpuMemoryBufferType type,
const gfx::GpuMemoryBufferId& id, const gfx::GpuMemoryBufferId& id,
base::ProcessHandle child_process) { 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:
if (id.secondary_id != child_client_id) {
LOG(ERROR)
<< "Child attempting to delete GpuMemoryBuffer it does not own";
} else {
GpuMemoryBufferImplOzoneNativeBuffer::DeletedByChildProcess(id,
sync_point);
}
break;
default:
NOTREACHED();
}
} }
// static // static
......
...@@ -14,7 +14,10 @@ namespace { ...@@ -14,7 +14,10 @@ namespace {
base::StaticAtomicSequenceNumber g_next_buffer_id; base::StaticAtomicSequenceNumber g_next_buffer_id;
void Noop() { void GpuMemoryBufferDeleted(const gfx::GpuMemoryBufferHandle& handle,
uint32 sync_point) {
GpuMemoryBufferFactoryHost::GetInstance()->DestroyGpuMemoryBuffer(handle,
sync_point);
} }
void GpuMemoryBufferCreated( void GpuMemoryBufferCreated(
...@@ -25,7 +28,7 @@ void GpuMemoryBufferCreated( ...@@ -25,7 +28,7 @@ void GpuMemoryBufferCreated(
DCHECK_EQ(gfx::OZONE_NATIVE_BUFFER, handle.type); DCHECK_EQ(gfx::OZONE_NATIVE_BUFFER, handle.type);
callback.Run(GpuMemoryBufferImplOzoneNativeBuffer::CreateFromHandle( callback.Run(GpuMemoryBufferImplOzoneNativeBuffer::CreateFromHandle(
handle, size, format, base::Bind(&Noop))); handle, size, format, base::Bind(&GpuMemoryBufferDeleted, handle)));
} }
void GpuMemoryBufferCreatedForChildProcess( void GpuMemoryBufferCreatedForChildProcess(
...@@ -99,6 +102,17 @@ GpuMemoryBufferImplOzoneNativeBuffer::CreateFromHandle( ...@@ -99,6 +102,17 @@ GpuMemoryBufferImplOzoneNativeBuffer::CreateFromHandle(
size, format, callback, handle.global_id)); size, format, callback, handle.global_id));
} }
// static
void GpuMemoryBufferImplOzoneNativeBuffer::DeletedByChildProcess(
const gfx::GpuMemoryBufferId& id,
uint32_t sync_point) {
gfx::GpuMemoryBufferHandle handle;
handle.type = gfx::OZONE_NATIVE_BUFFER;
handle.global_id = id;
GpuMemoryBufferFactoryHost::GetInstance()->DestroyGpuMemoryBuffer(handle,
sync_point);
}
// static // static
bool GpuMemoryBufferImplOzoneNativeBuffer::IsFormatSupported(Format format) { bool GpuMemoryBufferImplOzoneNativeBuffer::IsFormatSupported(Format format) {
switch (format) { switch (format) {
......
...@@ -28,6 +28,9 @@ class GpuMemoryBufferImplOzoneNativeBuffer : public GpuMemoryBufferImpl { ...@@ -28,6 +28,9 @@ class GpuMemoryBufferImplOzoneNativeBuffer : public GpuMemoryBufferImpl {
Format format, Format format,
const DestructionCallback& callback); const DestructionCallback& callback);
static void DeletedByChildProcess(const gfx::GpuMemoryBufferId& id,
uint32_t sync_point);
static bool IsFormatSupported(Format format); static bool IsFormatSupported(Format format);
static bool IsUsageSupported(Usage usage); static bool IsUsageSupported(Usage usage);
static bool IsConfigurationSupported(Format format, Usage usage); static bool IsConfigurationSupported(Format format, Usage usage);
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
namespace content { namespace content {
namespace { namespace {
void Noop() { void Noop(uint32 sync_point) {
} }
} // namespace } // namespace
......
...@@ -17,7 +17,10 @@ namespace { ...@@ -17,7 +17,10 @@ namespace {
base::StaticAtomicSequenceNumber g_next_buffer_id; base::StaticAtomicSequenceNumber g_next_buffer_id;
void Noop() { void GpuMemoryBufferDeleted(const gfx::GpuMemoryBufferHandle& handle,
uint32 sync_point) {
GpuMemoryBufferFactoryHost::GetInstance()->DestroyGpuMemoryBuffer(handle,
sync_point);
} }
void GpuMemoryBufferCreated( void GpuMemoryBufferCreated(
...@@ -28,7 +31,7 @@ void GpuMemoryBufferCreated( ...@@ -28,7 +31,7 @@ void GpuMemoryBufferCreated(
DCHECK_EQ(gfx::SURFACE_TEXTURE_BUFFER, handle.type); DCHECK_EQ(gfx::SURFACE_TEXTURE_BUFFER, handle.type);
callback.Run(GpuMemoryBufferImplSurfaceTexture::CreateFromHandle( callback.Run(GpuMemoryBufferImplSurfaceTexture::CreateFromHandle(
handle, size, format, base::Bind(&Noop))); handle, size, format, base::Bind(&GpuMemoryBufferDeleted, handle)));
} }
void GpuMemoryBufferCreatedForChildProcess( void GpuMemoryBufferCreatedForChildProcess(
...@@ -116,6 +119,17 @@ GpuMemoryBufferImplSurfaceTexture::CreateFromHandle( ...@@ -116,6 +119,17 @@ GpuMemoryBufferImplSurfaceTexture::CreateFromHandle(
size, format, callback, handle.global_id, native_window)); size, format, callback, handle.global_id, native_window));
} }
// static
void GpuMemoryBufferImplSurfaceTexture::DeletedByChildProcess(
const gfx::GpuMemoryBufferId& id,
uint32_t sync_point) {
gfx::GpuMemoryBufferHandle handle;
handle.type = gfx::SURFACE_TEXTURE_BUFFER;
handle.global_id = id;
GpuMemoryBufferFactoryHost::GetInstance()->DestroyGpuMemoryBuffer(handle,
sync_point);
}
// static // static
bool GpuMemoryBufferImplSurfaceTexture::IsFormatSupported(Format format) { bool GpuMemoryBufferImplSurfaceTexture::IsFormatSupported(Format format) {
switch (format) { switch (format) {
......
...@@ -30,6 +30,9 @@ class GpuMemoryBufferImplSurfaceTexture : public GpuMemoryBufferImpl { ...@@ -30,6 +30,9 @@ class GpuMemoryBufferImplSurfaceTexture : public GpuMemoryBufferImpl {
Format format, Format format,
const DestructionCallback& callback); const DestructionCallback& callback);
static void DeletedByChildProcess(const gfx::GpuMemoryBufferId& id,
uint32_t sync_point);
static bool IsFormatSupported(Format format); static bool IsFormatSupported(Format format);
static bool IsUsageSupported(Usage usage); static bool IsUsageSupported(Usage usage);
static bool IsConfigurationSupported(Format format, Usage usage); static bool IsConfigurationSupported(Format format, Usage usage);
......
...@@ -45,7 +45,9 @@ void GpuMemoryBufferImpl::AllocateForChildProcess( ...@@ -45,7 +45,9 @@ void GpuMemoryBufferImpl::AllocateForChildProcess(
void GpuMemoryBufferImpl::DeletedByChildProcess( void GpuMemoryBufferImpl::DeletedByChildProcess(
gfx::GpuMemoryBufferType type, gfx::GpuMemoryBufferType type,
const gfx::GpuMemoryBufferId& id, const gfx::GpuMemoryBufferId& id,
base::ProcessHandle child_process) { base::ProcessHandle child_process,
int child_client_id,
uint32 sync_point) {
} }
// static // static
......
...@@ -27,6 +27,10 @@ class GPU_EXPORT GpuMemoryBufferManager { ...@@ -27,6 +27,10 @@ class GPU_EXPORT GpuMemoryBufferManager {
virtual gfx::GpuMemoryBuffer* GpuMemoryBufferFromClientBuffer( virtual gfx::GpuMemoryBuffer* GpuMemoryBufferFromClientBuffer(
ClientBuffer buffer) = 0; ClientBuffer buffer) = 0;
// Associates destruction sync point with |buffer|.
virtual void SetDestructionSyncPoint(gfx::GpuMemoryBuffer* buffer,
uint32 sync_point) = 0;
protected: protected:
virtual ~GpuMemoryBufferManager(); virtual ~GpuMemoryBufferManager();
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment