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

Side by Side 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, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/child/child_shared_bitmap_manager.h ('k') | content/child/child_thread.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/child/child_shared_bitmap_manager.h"
6
7 #include "content/child/child_thread.h"
8 #include "content/common/child_process_messages.h"
9 #include "ui/gfx/size.h"
10
11 namespace content {
12
13 ChildSharedBitmapManager::ChildSharedBitmapManager(
14 scoped_refptr<ThreadSafeSender> sender)
15 : sender_(sender) {}
16
17 ChildSharedBitmapManager::~ChildSharedBitmapManager() {}
18
19 scoped_ptr<cc::SharedBitmap> ChildSharedBitmapManager::AllocateSharedBitmap(
20 const gfx::Size& size) {
21 TRACE_EVENT2("renderer",
22 "ChildSharedBitmapManager::AllocateSharedMemory",
23 "width",
24 size.width(),
25 "height",
26 size.height());
27 size_t memory_size;
28 if (!cc::SharedBitmap::GetSizeInBytes(size, &memory_size))
29 return scoped_ptr<cc::SharedBitmap>();
30 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId();
31 scoped_ptr<base::SharedMemory> memory;
32 #if defined(OS_POSIX)
33 base::SharedMemoryHandle handle;
34 sender_->Send(new ChildProcessHostMsg_SyncAllocateSharedBitmap(
35 memory_size, id, &handle));
36 memory = make_scoped_ptr(new base::SharedMemory(handle, false));
37 memory->Map(memory_size);
38 #else
39 memory.reset(ChildThread::AllocateSharedMemory(memory_size, sender_));
40 CHECK(memory);
41 memory->Map(memory_size);
42 base::SharedMemoryHandle handle_to_send = memory->handle();
43 sender_->Send(new ChildProcessHostMsg_AllocatedSharedBitmap(
44 memory_size, handle_to_send, id));
45 #endif
46 // The compositor owning the SharedBitmap will be closed before the
47 // ChildThread containng this, making the use of base::Unretained safe.
48 return scoped_ptr<cc::SharedBitmap>(new cc::SharedBitmap(
49 memory.release(),
50 id,
51 base::Bind(&ChildSharedBitmapManager::FreeSharedMemory,
52 base::Unretained(this))));
53 }
54
55 scoped_ptr<cc::SharedBitmap> ChildSharedBitmapManager::GetSharedBitmapFromId(
56 const gfx::Size&,
57 const cc::SharedBitmapId&) {
58 NOTREACHED();
59 return scoped_ptr<cc::SharedBitmap>();
60 }
61
62 scoped_ptr<cc::SharedBitmap> ChildSharedBitmapManager::GetBitmapForSharedMemory(
63 base::SharedMemory* mem) {
64 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId();
65 base::SharedMemoryHandle handle_to_send = mem->handle();
66 #if defined(OS_POSIX)
67 if (!mem->ShareToProcess(base::GetCurrentProcessHandle(), &handle_to_send))
68 return scoped_ptr<cc::SharedBitmap>();
69 #endif
70 sender_->Send(new ChildProcessHostMsg_AllocatedSharedBitmap(
71 mem->mapped_size(), handle_to_send, id));
72 // The compositor owning the SharedBitmap will be closed before the
73 // ChildThread containng this, making the use of base::Unretained safe.
74 return scoped_ptr<cc::SharedBitmap>(new cc::SharedBitmap(
75 mem,
76 id,
77 base::Bind(&ChildSharedBitmapManager::ReleaseSharedBitmap,
78 base::Unretained(this))));
79 }
80
81 void ChildSharedBitmapManager::FreeSharedMemory(cc::SharedBitmap* bitmap) {
82 TRACE_EVENT0("renderer", "ChildSharedBitmapManager::FreeSharedMemory");
83 sender_->Send(new ChildProcessHostMsg_DeletedSharedBitmap(bitmap->id()));
84 delete bitmap->memory();
85 }
86
87 void ChildSharedBitmapManager::ReleaseSharedBitmap(cc::SharedBitmap* handle) {
88 TRACE_EVENT0("renderer", "ChildSharedBitmapManager::ReleaseSharedBitmap");
89 sender_->Send(new ChildProcessHostMsg_DeletedSharedBitmap(handle->id()));
90 }
91
92 } // namespace content
OLDNEW
« no previous file with comments | « content/child/child_shared_bitmap_manager.h ('k') | content/child/child_thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698