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

Unified Diff: components/display_compositor/child/child_shared_bitmap_manager.cc

Issue 2717213004: Move SharedBitmapManager implementation out of content/ (Closed)
Patch Set: rebase Created 3 years, 10 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: components/display_compositor/child/child_shared_bitmap_manager.cc
diff --git a/content/child/child_shared_bitmap_manager.cc b/components/display_compositor/child/child_shared_bitmap_manager.cc
similarity index 74%
rename from content/child/child_shared_bitmap_manager.cc
rename to components/display_compositor/child/child_shared_bitmap_manager.cc
index b26de442161f2ca69c732992761c2b10c418ab31..0b21651c90e976e1ff707a22664df037b135463f 100644
--- a/content/child/child_shared_bitmap_manager.cc
+++ b/components/display_compositor/child/child_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/child/child_shared_bitmap_manager.h"
+#include "components/display_compositor/child/child_shared_bitmap_manager.h"
#include <stddef.h>
@@ -12,30 +12,29 @@
#include "base/memory/ptr_util.h"
#include "base/process/memory.h"
#include "base/process/process_metrics.h"
+#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
-#include "content/child/child_thread_impl.h"
-#include "content/common/child_process_messages.h"
#include "mojo/public/cpp/system/platform_handle.h"
#include "ui/gfx/geometry/size.h"
-namespace content {
+namespace display_compositor {
namespace {
class ChildSharedBitmap : public SharedMemoryBitmap {
public:
ChildSharedBitmap(
- const scoped_refptr<mojom::ThreadSafeRenderMessageFilterAssociatedPtr>&
+ const scoped_refptr<mojom::ThreadSafeSharedBitmapManagerAssociatedPtr>&
render_message_filter_ptr,
base::SharedMemory* shared_memory,
const cc::SharedBitmapId& id)
: SharedMemoryBitmap(static_cast<uint8_t*>(shared_memory->memory()),
id,
shared_memory),
- render_message_filter_ptr_(render_message_filter_ptr) {}
+ shared_bitmap_manager_ptr_(render_message_filter_ptr) {}
ChildSharedBitmap(
- const scoped_refptr<mojom::ThreadSafeRenderMessageFilterAssociatedPtr>&
+ const scoped_refptr<mojom::ThreadSafeSharedBitmapManagerAssociatedPtr>&
render_message_filter_ptr,
std::unique_ptr<base::SharedMemory> shared_memory_holder,
const cc::SharedBitmapId& id)
@@ -46,12 +45,12 @@ class ChildSharedBitmap : public SharedMemoryBitmap {
}
~ChildSharedBitmap() override {
- (*render_message_filter_ptr_)->DeletedSharedBitmap(id());
+ (*shared_bitmap_manager_ptr_)->DeletedSharedBitmap(id());
}
private:
- scoped_refptr<mojom::ThreadSafeRenderMessageFilterAssociatedPtr>
- render_message_filter_ptr_;
+ scoped_refptr<mojom::ThreadSafeSharedBitmapManagerAssociatedPtr>
+ shared_bitmap_manager_ptr_;
std::unique_ptr<base::SharedMemory> shared_memory_holder_;
};
@@ -87,12 +86,32 @@ SharedMemoryBitmap::SharedMemoryBitmap(uint8_t* pixels,
: SharedBitmap(pixels, id), shared_memory_(shared_memory) {}
ChildSharedBitmapManager::ChildSharedBitmapManager(
- const scoped_refptr<mojom::ThreadSafeRenderMessageFilterAssociatedPtr>&
+ const scoped_refptr<mojom::ThreadSafeSharedBitmapManagerAssociatedPtr>&
render_message_filter_ptr)
- : render_message_filter_ptr_(render_message_filter_ptr) {}
+ : shared_bitmap_manager_ptr_(render_message_filter_ptr) {}
ChildSharedBitmapManager::~ChildSharedBitmapManager() {}
+// static
+std::unique_ptr<base::SharedMemory>
+ChildSharedBitmapManager::AllocateSharedMemory(size_t buf_size) {
danakj 2017/02/28 20:34:56 This should be a private method then, in the anon
+ mojo::ScopedSharedBufferHandle mojo_buf =
+ mojo::SharedBufferHandle::Create(buf_size);
+ if (!mojo_buf->is_valid()) {
+ LOG(WARNING) << "Browser failed to allocate shared memory";
+ return nullptr;
+ }
+
+ base::SharedMemoryHandle shared_buf;
+ if (mojo::UnwrapSharedMemoryHandle(std::move(mojo_buf), &shared_buf, nullptr,
+ nullptr) != MOJO_RESULT_OK) {
+ LOG(WARNING) << "Browser failed to allocate shared memory";
+ return nullptr;
+ }
+
+ return base::MakeUnique<base::SharedMemory>(shared_buf, false);
+}
+
std::unique_ptr<cc::SharedBitmap>
ChildSharedBitmapManager::AllocateSharedBitmap(const gfx::Size& size) {
TRACE_EVENT2("renderer",
@@ -103,7 +122,7 @@ ChildSharedBitmapManager::AllocateSharedBitmap(const gfx::Size& size) {
return std::unique_ptr<SharedMemoryBitmap>();
cc::SharedBitmapId id = cc::SharedBitmap::GenerateId();
std::unique_ptr<base::SharedMemory> memory =
- ChildThreadImpl::AllocateSharedMemory(memory_size);
+ ChildSharedBitmapManager::AllocateSharedMemory(memory_size);
if (!memory || !memory->Map(memory_size))
CollectMemoryUsageAndDie(size, memory_size);
@@ -113,7 +132,7 @@ ChildSharedBitmapManager::AllocateSharedBitmap(const gfx::Size& size) {
// remains available.
memory->Close();
- return base::MakeUnique<ChildSharedBitmap>(render_message_filter_ptr_,
+ return base::MakeUnique<ChildSharedBitmap>(shared_bitmap_manager_ptr_,
std::move(memory), id);
}
@@ -128,7 +147,7 @@ std::unique_ptr<cc::SharedBitmap>
ChildSharedBitmapManager::GetBitmapForSharedMemory(base::SharedMemory* mem) {
cc::SharedBitmapId id = cc::SharedBitmap::GenerateId();
NotifyAllocatedSharedBitmap(mem, cc::SharedBitmap::GenerateId());
- return base::MakeUnique<ChildSharedBitmap>(render_message_filter_ptr_,
+ return base::MakeUnique<ChildSharedBitmap>(shared_bitmap_manager_ptr_,
std::move(mem), id);
}
@@ -147,8 +166,8 @@ void ChildSharedBitmapManager::NotifyAllocatedSharedBitmap(
mojo::ScopedSharedBufferHandle buffer_handle = mojo::WrapSharedMemoryHandle(
handle_to_send, memory->mapped_size(), true /* read_only */);
- (*render_message_filter_ptr_)
+ (*shared_bitmap_manager_ptr_)
->AllocatedSharedBitmap(std::move(buffer_handle), id);
}
-} // namespace content
+} // namespace display_compositor

Powered by Google App Engine
This is Rietveld 408576698