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.
5 #ifndef CONTENT_COMMON_HOST_SHARED_BITMAP_MANAGER_H_
6 #define CONTENT_COMMON_HOST_SHARED_BITMAP_MANAGER_H_
11 #include "base/basictypes.h"
12 #include "base/containers/hash_tables.h"
13 #include "base/hash.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/shared_memory.h"
17 #include "base/synchronization/lock.h"
18 #include "base/trace_event/memory_dump_provider.h"
19 #include "cc/resources/shared_bitmap_manager.h"
20 #include "content/common/content_export.h"
22 namespace BASE_HASH_NAMESPACE
{
24 struct hash
<cc::SharedBitmapId
> {
25 size_t operator()(const cc::SharedBitmapId
& id
) const {
26 return base::Hash(reinterpret_cast<const char*>(id
.name
), sizeof(id
.name
));
29 } // namespace BASE_HASH_NAMESPACE
33 class HostSharedBitmapManager
;
35 class CONTENT_EXPORT HostSharedBitmapManagerClient
{
37 explicit HostSharedBitmapManagerClient(HostSharedBitmapManager
* manager
);
39 ~HostSharedBitmapManagerClient();
41 void AllocateSharedBitmapForChild(
42 base::ProcessHandle process_handle
,
44 const cc::SharedBitmapId
& id
,
45 base::SharedMemoryHandle
* shared_memory_handle
);
46 void ChildAllocatedSharedBitmap(size_t buffer_size
,
47 const base::SharedMemoryHandle
& handle
,
48 base::ProcessHandle process_handle
,
49 const cc::SharedBitmapId
& id
);
50 void ChildDeletedSharedBitmap(const cc::SharedBitmapId
& id
);
53 HostSharedBitmapManager
* manager_
;
54 base::hash_set
<cc::SharedBitmapId
> owned_bitmaps_
;
56 DISALLOW_COPY_AND_ASSIGN(HostSharedBitmapManagerClient
);
59 class CONTENT_EXPORT HostSharedBitmapManager
60 : public cc::SharedBitmapManager
,
61 public base::trace_event::MemoryDumpProvider
{
63 HostSharedBitmapManager();
64 ~HostSharedBitmapManager() override
;
66 static HostSharedBitmapManager
* current();
68 // cc::SharedBitmapManager implementation.
69 scoped_ptr
<cc::SharedBitmap
> AllocateSharedBitmap(
70 const gfx::Size
& size
) override
;
71 scoped_ptr
<cc::SharedBitmap
> GetSharedBitmapFromId(
72 const gfx::Size
& size
,
73 const cc::SharedBitmapId
&) override
;
75 // base::trace_event::MemoryDumpProvider implementation.
76 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs
& args
,
77 base::trace_event::ProcessMemoryDump
* pmd
) override
;
79 size_t AllocatedBitmapCount() const;
81 void FreeSharedMemoryFromMap(const cc::SharedBitmapId
& id
);
84 friend class HostSharedBitmapManagerClient
;
86 void AllocateSharedBitmapForChild(
87 base::ProcessHandle process_handle
,
89 const cc::SharedBitmapId
& id
,
90 base::SharedMemoryHandle
* shared_memory_handle
);
91 void ChildAllocatedSharedBitmap(size_t buffer_size
,
92 const base::SharedMemoryHandle
& handle
,
93 base::ProcessHandle process_handle
,
94 const cc::SharedBitmapId
& id
);
95 void ChildDeletedSharedBitmap(const cc::SharedBitmapId
& id
);
97 mutable base::Lock lock_
;
99 typedef base::hash_map
<cc::SharedBitmapId
, scoped_refptr
<BitmapData
> >
101 BitmapMap handle_map_
;
103 DISALLOW_COPY_AND_ASSIGN(HostSharedBitmapManager
);
106 } // namespace content
108 #endif // CONTENT_COMMON_HOST_SHARED_BITMAP_MANAGER_H_