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/compiler_specific.h"
13 #include "base/containers/hash_tables.h"
14 #include "base/hash.h"
15 #include "base/memory/ref_counted.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "base/memory/shared_memory.h"
18 #include "base/synchronization/lock.h"
19 #include "cc/resources/shared_bitmap_manager.h"
20 #include "content/common/content_export.h"
22 namespace BASE_HASH_NAMESPACE
{
23 #if defined(COMPILER_GCC)
25 struct hash
<cc::SharedBitmapId
> {
26 size_t operator()(const cc::SharedBitmapId
& id
) const {
27 return base::Hash(reinterpret_cast<const char*>(id
.name
), sizeof(id
.name
));
30 #elif defined(COMPILER_MSVC)
31 inline std::size_t hash_value(const cc::SharedBitmapId
& id
) {
32 return base::Hash(reinterpret_cast<const char*>(id
.name
), sizeof(id
.name
));
35 } // namespace BASE_HASH_NAMESPACE
40 class CONTENT_EXPORT HostSharedBitmapManager
: public cc::SharedBitmapManager
{
42 HostSharedBitmapManager();
43 ~HostSharedBitmapManager() override
;
45 static HostSharedBitmapManager
* current();
47 // cc::SharedBitmapManager implementation.
48 scoped_ptr
<cc::SharedBitmap
> AllocateSharedBitmap(
49 const gfx::Size
& size
) override
;
50 scoped_ptr
<cc::SharedBitmap
> GetSharedBitmapFromId(
51 const gfx::Size
& size
,
52 const cc::SharedBitmapId
&) override
;
53 scoped_ptr
<cc::SharedBitmap
> GetBitmapForSharedMemory(
54 base::SharedMemory
*) override
;
56 void AllocateSharedBitmapForChild(
57 base::ProcessHandle process_handle
,
59 const cc::SharedBitmapId
& id
,
60 base::SharedMemoryHandle
* shared_memory_handle
);
61 void ChildAllocatedSharedBitmap(size_t buffer_size
,
62 const base::SharedMemoryHandle
& handle
,
63 base::ProcessHandle process_handle
,
64 const cc::SharedBitmapId
& id
);
65 void ChildDeletedSharedBitmap(const cc::SharedBitmapId
& id
);
66 void ProcessRemoved(base::ProcessHandle process_handle
);
68 size_t AllocatedBitmapCount() const;
71 void FreeSharedMemoryFromMap(cc::SharedBitmap
* bitmap
);
73 mutable base::Lock lock_
;
75 typedef base::hash_map
<cc::SharedBitmapId
, scoped_refptr
<BitmapData
> >
77 BitmapMap handle_map_
;
79 typedef base::hash_map
<base::ProcessHandle
,
80 base::hash_set
<cc::SharedBitmapId
> > ProcessMap
;
81 ProcessMap process_map_
;
84 } // namespace content
86 #endif // CONTENT_COMMON_HOST_SHARED_BITMAP_MANAGER_H_