Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(732)

Unified Diff: content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.cc

Issue 1417363006: ui: Add support for creating GLImage instances from shared memory pools. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@usage-rename
Patch Set: windows build fix Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.cc
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 a3e611020d39eebdcaa49c2281a442ce7f383115..b8c1d7ba417b7bbf78502a7778a8fbfe10b53ead 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
@@ -22,9 +22,11 @@ GpuMemoryBufferImplSharedMemory::GpuMemoryBufferImplSharedMemory(
const gfx::Size& size,
gfx::BufferFormat format,
const DestructionCallback& callback,
- scoped_ptr<base::SharedMemory> shared_memory)
+ scoped_ptr<base::SharedMemory> shared_memory,
+ off_t offset)
: GpuMemoryBufferImpl(id, size, format, callback),
- shared_memory_(shared_memory.Pass()) {
+ shared_memory_(shared_memory.Pass()),
+ offset_(offset) {
DCHECK(IsSizeValidForFormat(size, format));
}
@@ -46,7 +48,7 @@ GpuMemoryBufferImplSharedMemory::Create(gfx::GpuMemoryBufferId id,
return nullptr;
return make_scoped_ptr(new GpuMemoryBufferImplSharedMemory(
- id, size, format, callback, shared_memory.Pass()));
+ id, size, format, callback, shared_memory.Pass(), 0));
}
// static
@@ -67,6 +69,7 @@ GpuMemoryBufferImplSharedMemory::AllocateForChildProcess(
gfx::GpuMemoryBufferHandle handle;
handle.type = gfx::SHARED_MEMORY_BUFFER;
handle.id = id;
+ handle.offset = 0;
shared_memory.GiveToProcess(child_process, &handle.handle);
return handle;
}
@@ -82,14 +85,10 @@ GpuMemoryBufferImplSharedMemory::CreateFromHandle(
if (!base::SharedMemory::IsHandleValid(handle.handle))
return nullptr;
- size_t buffer_size = gfx::BufferSizeForBufferFormat(size, format);
- scoped_ptr<base::SharedMemory> shared_memory(
- new base::SharedMemory(handle.handle, false));
- if (!shared_memory->Map(buffer_size))
- base::TerminateBecauseOutOfMemory(buffer_size);
-
return make_scoped_ptr(new GpuMemoryBufferImplSharedMemory(
- handle.id, size, format, callback, shared_memory.Pass()));
+ handle.id, size, format, callback,
+ make_scoped_ptr(new base::SharedMemory(handle.handle, false)),
+ handle.offset));
}
// static
@@ -162,12 +161,22 @@ base::Closure GpuMemoryBufferImplSharedMemory::AllocateForTesting(
gfx::BufferSizeForBufferFormat(size, format));
DCHECK(rv);
handle->type = gfx::SHARED_MEMORY_BUFFER;
+ handle->offset = 0;
handle->handle = base::SharedMemory::DuplicateHandle(shared_memory.handle());
return base::Bind(&Noop);
}
bool GpuMemoryBufferImplSharedMemory::Map() {
DCHECK(!mapped_);
+ DCHECK_EQ(offset_, 0) << "Buffer offset is not supported by Map()";
piman 2015/10/26 16:17:50 nit: you could map the entire buffer, but add the
reveman 2015/10/26 17:25:34 Doing that in latest patch but without the GLImage
+
+ // Map the buffer first time Map() is called then keep it mapped for the
+ // lifetime of the buffer. This avoids mapping the buffer unless necessary.
+ if (!shared_memory_->memory()) {
+ size_t buffer_size = gfx::BufferSizeForBufferFormat(size_, format_);
+ if (!shared_memory_->Map(buffer_size))
+ base::TerminateBecauseOutOfMemory(buffer_size);
+ }
mapped_ = true;
return true;
}
@@ -193,6 +202,7 @@ gfx::GpuMemoryBufferHandle GpuMemoryBufferImplSharedMemory::GetHandle() const {
gfx::GpuMemoryBufferHandle handle;
handle.type = gfx::SHARED_MEMORY_BUFFER;
handle.id = id_;
+ handle.offset = offset_;
handle.handle = shared_memory_->handle();
return handle;
}

Powered by Google App Engine
This is Rietveld 408576698