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

Unified Diff: content/common/host_shared_bitmap_manager.cc

Issue 307973004: Allow creating SharedBitmaps backed by new[] (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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
« no previous file with comments | « cc/resources/shared_bitmap.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/common/host_shared_bitmap_manager.cc
diff --git a/content/common/host_shared_bitmap_manager.cc b/content/common/host_shared_bitmap_manager.cc
index 88d9f65acb6bf7788c99fbe3832f03772d13e013..1f412e42eef04f38f1c5acae05d55b8c90636d8e 100644
--- a/content/common/host_shared_bitmap_manager.cc
+++ b/content/common/host_shared_bitmap_manager.cc
@@ -22,6 +22,7 @@ class BitmapData : public base::RefCountedThreadSafe<BitmapData> {
base::ProcessHandle process_handle;
base::SharedMemoryHandle memory_handle;
scoped_ptr<base::SharedMemory> memory;
+ scoped_ptr<uint8[]> pixels;
size_t buffer_size;
private:
@@ -46,9 +47,23 @@ HostSharedBitmapManager* HostSharedBitmapManager::current() {
scoped_ptr<cc::SharedBitmap> HostSharedBitmapManager::AllocateSharedBitmap(
const gfx::Size& size) {
+ base::AutoLock lock(lock_);
+ size_t bitmap_size;
+ if (!cc::SharedBitmap::SizeInBytes(size, &bitmap_size))
+ return scoped_ptr<cc::SharedBitmap>();
+
+ scoped_refptr<BitmapData> data(
+ new BitmapData(base::GetCurrentProcessHandle(),
+ base::SharedMemory::NULLHandle(),
+ bitmap_size));
// Bitmaps allocated in host don't need to be shared to other processes, so
// allocate them with new instead.
- return scoped_ptr<cc::SharedBitmap>();
+ data->pixels = scoped_ptr<uint8[]>(new uint8[bitmap_size]);
+
+ cc::SharedBitmapId id = cc::SharedBitmap::GenerateId();
+ handle_map_[id] = data;
+ return make_scoped_ptr(new cc::SharedBitmap(
+ data->pixels.get(), id, base::Bind(&FreeSharedMemory, data)));
}
scoped_ptr<cc::SharedBitmap> HostSharedBitmapManager::GetSharedBitmapFromId(
@@ -66,6 +81,10 @@ scoped_ptr<cc::SharedBitmap> HostSharedBitmapManager::GetSharedBitmapFromId(
bitmap_size > data->buffer_size)
return scoped_ptr<cc::SharedBitmap>();
+ if (data->pixels) {
+ return make_scoped_ptr(new cc::SharedBitmap(
+ data->pixels.get(), id, base::Bind(&FreeSharedMemory, it->second)));
+ }
if (!data->memory->memory()) {
TRACE_EVENT0("renderer_host",
"HostSharedBitmapManager::GetSharedBitmapFromId");
« no previous file with comments | « cc/resources/shared_bitmap.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698