Index: components/display_compositor/host_shared_bitmap_manager.cc |
diff --git a/content/common/host_shared_bitmap_manager.cc b/components/display_compositor/host_shared_bitmap_manager.cc |
similarity index 83% |
rename from content/common/host_shared_bitmap_manager.cc |
rename to components/display_compositor/host_shared_bitmap_manager.cc |
index 51f4fc79160d8f6c39f84f468930c95ba0504606..10cbfa09463f1972555dcbf5ee9395ac1a585afe 100644 |
--- a/content/common/host_shared_bitmap_manager.cc |
+++ b/components/display_compositor/host_shared_bitmap_manager.cc |
@@ -2,7 +2,7 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "content/common/host_shared_bitmap_manager.h" |
+#include "components/display_compositor/host_shared_bitmap_manager.h" |
#include <stdint.h> |
@@ -13,12 +13,14 @@ |
#include "base/memory/ptr_util.h" |
#include "base/memory/ref_counted.h" |
#include "base/strings/string_number_conversions.h" |
+#include "base/strings/stringprintf.h" |
#include "base/trace_event/process_memory_dump.h" |
#include "build/build_config.h" |
-#include "content/common/view_messages.h" |
+#include "mojo/public/cpp/bindings/strong_binding.h" |
+#include "mojo/public/cpp/system/platform_handle.h" |
#include "ui/gfx/geometry/size.h" |
-namespace content { |
+namespace display_compositor { |
class BitmapData : public base::RefCountedThreadSafe<BitmapData> { |
public: |
@@ -57,19 +59,49 @@ class HostSharedBitmap : public cc::SharedBitmap { |
} // namespace |
+class MojoSharedBitmapManagerImpl : public mojom::SharedBitmapManager { |
+ public: |
+ MojoSharedBitmapManagerImpl( |
+ HostSharedBitmapManagerClient* bitmap_manager_client) |
+ : bitmap_manager_client_(bitmap_manager_client) {} |
+ |
+ // mojom::SharedBitmapManager overrides: |
+ void AllocatedSharedBitmap(mojo::ScopedSharedBufferHandle buffer, |
+ const cc::SharedBitmapId& id) override { |
+ base::SharedMemoryHandle memory_handle; |
+ size_t size; |
+ MojoResult result = mojo::UnwrapSharedMemoryHandle( |
+ std::move(buffer), &memory_handle, &size, NULL); |
+ DCHECK_EQ(result, MOJO_RESULT_OK); |
+ bitmap_manager_client_->ChildAllocatedSharedBitmap(size, memory_handle, id); |
+ } |
+ |
+ void DeletedSharedBitmap(const cc::SharedBitmapId& id) override { |
+ bitmap_manager_client_->ChildDeletedSharedBitmap(id); |
+ } |
+ |
+ private: |
+ HostSharedBitmapManagerClient* bitmap_manager_client_; |
+}; |
+ |
base::LazyInstance<HostSharedBitmapManager> g_shared_memory_manager = |
LAZY_INSTANCE_INITIALIZER; |
HostSharedBitmapManagerClient::HostSharedBitmapManagerClient( |
HostSharedBitmapManager* manager) |
- : manager_(manager) { |
-} |
+ : manager_(manager) {} |
HostSharedBitmapManagerClient::~HostSharedBitmapManagerClient() { |
for (const auto& id : owned_bitmaps_) |
manager_->ChildDeletedSharedBitmap(id); |
} |
+void HostSharedBitmapManagerClient::Bind( |
+ mojom::SharedBitmapManagerRequest request) { |
+ mojo::MakeStrongBinding(base::MakeUnique<MojoSharedBitmapManagerImpl>(this), |
+ std::move(request)); |
+} |
+ |
void HostSharedBitmapManagerClient::AllocateSharedBitmapForChild( |
base::ProcessHandle process_handle, |
size_t buffer_size, |
@@ -225,7 +257,7 @@ void HostSharedBitmapManager::AllocateSharedBitmapForChild( |
*shared_memory_handle = base::SharedMemory::NULLHandle(); |
return; |
} |
- data->memory->Close(); |
+ data->memory->Close(); |
} |
void HostSharedBitmapManager::ChildDeletedSharedBitmap( |
@@ -245,4 +277,4 @@ void HostSharedBitmapManager::FreeSharedMemoryFromMap( |
handle_map_.erase(id); |
} |
-} // namespace content |
+} // namespace display_compositor |