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

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

Issue 600693002: content: Cleanup GpuMemoryBufferImpl destruction. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove scoped_refptr<> from sender param of DeletedGpuMemoryBuffer Created 6 years, 3 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 4c1534db191be9824d9603454e1fd2e762f06936..9566b7f68a883981c74d3f7f82f115f3ee7abc48 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
@@ -4,15 +4,25 @@
#include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h"
+#include "base/bind.h"
#include "base/numerics/safe_math.h"
#include "ui/gl/gl_bindings.h"
namespace content {
+namespace {
+
+void Noop() {
+}
+
+} // namespace
GpuMemoryBufferImplSharedMemory::GpuMemoryBufferImplSharedMemory(
const gfx::Size& size,
- unsigned internalformat)
- : GpuMemoryBufferImpl(size, internalformat) {
+ unsigned internalformat,
+ const DestructionCallback& callback,
+ scoped_ptr<base::SharedMemory> shared_memory)
+ : GpuMemoryBufferImpl(size, internalformat, callback),
+ shared_memory_(shared_memory.Pass()) {
}
GpuMemoryBufferImplSharedMemory::~GpuMemoryBufferImplSharedMemory() {
@@ -26,18 +36,20 @@ void GpuMemoryBufferImplSharedMemory::Create(const gfx::Size& size,
DCHECK(GpuMemoryBufferImplSharedMemory::IsConfigurationSupported(
size, internalformat, usage));
- scoped_ptr<GpuMemoryBufferImplSharedMemory> buffer(
- new GpuMemoryBufferImplSharedMemory(size, internalformat));
- if (buffer->Initialize()) {
- callback.Run(buffer.PassAs<GpuMemoryBufferImpl>());
+ scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory());
+ if (!shared_memory->CreateAnonymous(size.GetArea() *
+ BytesPerPixel(internalformat))) {
+ callback.Run(scoped_ptr<GpuMemoryBufferImpl>());
return;
}
- callback.Run(scoped_ptr<GpuMemoryBufferImpl>());
+ callback.Run(
+ make_scoped_ptr<GpuMemoryBufferImpl>(new GpuMemoryBufferImplSharedMemory(
+ size, internalformat, base::Bind(&Noop), shared_memory.Pass())));
}
// static
-void GpuMemoryBufferImplSharedMemory::AllocateSharedMemoryForChildProcess(
+void GpuMemoryBufferImplSharedMemory::AllocateForChildProcess(
const gfx::Size& size,
unsigned internalformat,
base::ProcessHandle child_process,
@@ -56,6 +68,26 @@ void GpuMemoryBufferImplSharedMemory::AllocateSharedMemoryForChildProcess(
}
// static
+scoped_ptr<GpuMemoryBufferImpl>
+GpuMemoryBufferImplSharedMemory::CreateFromHandle(
+ const gfx::GpuMemoryBufferHandle& handle,
+ const gfx::Size& size,
+ unsigned internalformat,
+ const DestructionCallback& callback) {
+ DCHECK(IsLayoutSupported(size, internalformat));
+
+ if (!base::SharedMemory::IsHandleValid(handle.handle))
+ return scoped_ptr<GpuMemoryBufferImpl>();
+
+ return make_scoped_ptr<GpuMemoryBufferImpl>(
+ new GpuMemoryBufferImplSharedMemory(
+ size,
+ internalformat,
+ callback,
+ make_scoped_ptr(new base::SharedMemory(handle.handle, false))));
+}
+
+// static
bool GpuMemoryBufferImplSharedMemory::IsLayoutSupported(
const gfx::Size& size,
unsigned internalformat) {
@@ -83,27 +115,6 @@ bool GpuMemoryBufferImplSharedMemory::IsConfigurationSupported(
return IsLayoutSupported(size, internalformat) && IsUsageSupported(usage);
}
-bool GpuMemoryBufferImplSharedMemory::Initialize() {
- DCHECK(IsLayoutSupported(size_, internalformat_));
- scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory());
- if (!shared_memory->CreateAnonymous(size_.GetArea() *
- BytesPerPixel(internalformat_)))
- return false;
- shared_memory_ = shared_memory.Pass();
- DCHECK(!shared_memory_->memory());
- return true;
-}
-
-bool GpuMemoryBufferImplSharedMemory::InitializeFromHandle(
- const gfx::GpuMemoryBufferHandle& handle) {
- DCHECK(IsLayoutSupported(size_, internalformat_));
- if (!base::SharedMemory::IsHandleValid(handle.handle))
- return false;
- shared_memory_.reset(new base::SharedMemory(handle.handle, false));
- DCHECK(!shared_memory_->memory());
- return true;
-}
-
void* GpuMemoryBufferImplSharedMemory::Map() {
DCHECK(!mapped_);
if (!shared_memory_->Map(size_.GetArea() * BytesPerPixel(internalformat_)))

Powered by Google App Engine
This is Rietveld 408576698