diff options
author | jbauman@chromium.org <jbauman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-30 07:02:27 +0000 |
---|---|---|
committer | jbauman@chromium.org <jbauman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-30 07:02:27 +0000 |
commit | 34d6734d673656488fc07b0c015866707af696d9 (patch) | |
tree | a59062afcc93e61ccda37b9aa55cf4f2a2db2707 /content/common | |
parent | 1980f18478ce919b8ee445841470f40b092f6a2f (diff) | |
download | chromium_src-34d6734d673656488fc07b0c015866707af696d9.zip chromium_src-34d6734d673656488fc07b0c015866707af696d9.tar.gz chromium_src-34d6734d673656488fc07b0c015866707af696d9.tar.bz2 |
Allow creating SharedBitmaps backed by new[]
Bitmaps allocated in the browser process may have to be shared between compositors (for surfaces) but not between processes, so they should be backed by new[] and use the SharedBitmap mechanism.
BUG=
Review URL: https://codereview.chromium.org/307973004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@273743 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/common')
-rw-r--r-- | content/common/host_shared_bitmap_manager.cc | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/content/common/host_shared_bitmap_manager.cc b/content/common/host_shared_bitmap_manager.cc index 88d9f65..1f412e4 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"); |