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

Unified Diff: content/child/child_shared_bitmap_manager.cc

Issue 148243013: Add shared bitmap managers for browser and renderer processes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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/child/child_shared_bitmap_manager.cc
diff --git a/content/child/child_shared_bitmap_manager.cc b/content/child/child_shared_bitmap_manager.cc
new file mode 100644
index 0000000000000000000000000000000000000000..acdd8b8bc726b6b5c4a01793df29307e4c67ab69
--- /dev/null
+++ b/content/child/child_shared_bitmap_manager.cc
@@ -0,0 +1,85 @@
+// Copyright (c) 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/child/child_shared_bitmap_manager.h"
+
+#include "content/child/child_thread.h"
+#include "content/common/child_process_messages.h"
+#include "ui/gfx/size.h"
+
+namespace content {
+
+ChildSharedBitmapManager::ChildSharedBitmapManager(
+ scoped_refptr<ThreadSafeSender> sender)
+ : sender_(sender) {}
+
+ChildSharedBitmapManager::~ChildSharedBitmapManager() {}
+
+scoped_ptr<cc::SharedBitmap> ChildSharedBitmapManager::AllocateSharedBitmap(
+ gfx::Size size) {
+ TRACE_EVENT2("renderer",
+ "ChildSharedBitmapManager::AllocateSharedMemory",
+ "width",
+ size.width(),
+ "height",
+ size.height());
+ size_t memory_size = cc::SharedBitmap::GetSizeInBytes(size);
+ cc::SharedBitmapId id = cc::SharedBitmap::GenerateId();
danakj 2014/01/30 22:59:01 It seems potentially problematic to me that the ch
+ scoped_ptr<base::SharedMemory> memory;
+#if defined(OS_POSIX)
+ base::SharedMemoryHandle handle;
+ sender_->Send(new ChildProcessHostMsg_SyncAllocateSharedBitmap(
+ memory_size, id, &handle));
+ memory = make_scoped_ptr(new base::SharedMemory(handle, false));
+ memory->Map(memory_size);
+#else
+ memory =
+ make_scoped_ptr(ChildThread::AllocateSharedMemory(memory_size, sender_));
+ CHECK(memory);
+ memory->Map(memory_size);
+ base::SharedMemoryHandle handle_to_send = memory->handle();
+ sender_->Send(
+ new ChildProcessHostMsg_AllocatedSharedBitmap(handle_to_send, id));
+#endif
+ return scoped_ptr<cc::SharedBitmap>(new cc::SharedBitmap(
+ memory.release(),
+ id,
+ base::Bind(&ChildSharedBitmapManager::FreeSharedMemory,
+ base::Unretained(this))));
+}
+
+scoped_ptr<cc::SharedBitmap> ChildSharedBitmapManager::GetSharedBitmapFromId(
+ gfx::Size,
+ const cc::SharedBitmapId&) {
+ return scoped_ptr<cc::SharedBitmap>();
danakj 2014/01/30 22:59:01 Future: It looks like ResourceProvider::ReceiveFro
danakj 2014/01/31 17:44:22 dongseong pointed out that returning NULL here cau
+}
+
+scoped_ptr<cc::SharedBitmap> ChildSharedBitmapManager::GetBitmapForSharedMemory(
+ base::SharedMemory* mem) {
+ cc::SharedBitmapId id = cc::SharedBitmap::GenerateId();
+ base::SharedMemoryHandle handle_to_send = mem->handle();
danakj 2014/01/30 22:59:01 Could the id here come from the browser where the
+#if defined(OS_POSIX)
+ if (!mem->ShareToProcess(base::GetCurrentProcessHandle(), &handle_to_send))
+ return scoped_ptr<cc::SharedBitmap>();
+#endif
+ sender_->Send(
+ new ChildProcessHostMsg_AllocatedSharedBitmap(handle_to_send, id));
+ return scoped_ptr<cc::SharedBitmap>(new cc::SharedBitmap(
+ mem,
+ id,
+ base::Bind(&ChildSharedBitmapManager::ReleaseSharedBitmap,
+ base::Unretained(this))));
+}
+
+void ChildSharedBitmapManager::FreeSharedMemory(cc::SharedBitmap* bitmap) {
+ TRACE_EVENT0("renderer", "ChildSharedBitmapManager::FreeSharedMemory");
+ sender_->Send(new ChildProcessHostMsg_DeletedSharedBitmap(bitmap->id()));
+ delete bitmap->memory();
+}
+
+void ChildSharedBitmapManager::ReleaseSharedBitmap(cc::SharedBitmap* handle) {
+ sender_->Send(new ChildProcessHostMsg_DeletedSharedBitmap(handle->id()));
danakj 2014/01/30 22:59:01 TRACE_EVENT here?
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698