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 "cc/resources/shared_bitmap_manager.h"
19 #include "content/common/content_export.h"
21 namespace BASE_HASH_NAMESPACE
{
23 struct hash
<cc::SharedBitmapId
> {
24 size_t operator()(const cc::SharedBitmapId
& id
) const {
25 return base::Hash(reinterpret_cast<const char*>(id
.name
), sizeof(id
.name
));
28 } // namespace BASE_HASH_NAMESPACE
32 class HostSharedBitmapManager
;
34 class CONTENT_EXPORT HostSharedBitmapManagerClient
{
36 explicit HostSharedBitmapManagerClient(HostSharedBitmapManager
* manager
);
38 ~HostSharedBitmapManagerClient();
40 void AllocateSharedBitmapForChild(
41 base::ProcessHandle process_handle
,
43 const cc::SharedBitmapId
& id
,
44 base::SharedMemoryHandle
* shared_memory_handle
);
45 void ChildAllocatedSharedBitmap(size_t buffer_size
,
46 const base::SharedMemoryHandle
& handle
,
47 base::ProcessHandle process_handle
,
48 const cc::SharedBitmapId
& id
);
49 void ChildDeletedSharedBitmap(const cc::SharedBitmapId
& id
);
52 HostSharedBitmapManager
* manager_
;
53 base::hash_set
<cc::SharedBitmapId
> owned_bitmaps_
;
55 DISALLOW_COPY_AND_ASSIGN(HostSharedBitmapManagerClient
);
58 class CONTENT_EXPORT HostSharedBitmapManager
: public cc::SharedBitmapManager
{
60 HostSharedBitmapManager();
61 ~HostSharedBitmapManager() override
;
63 static HostSharedBitmapManager
* current();
65 // cc::SharedBitmapManager implementation.
66 scoped_ptr
<cc::SharedBitmap
> AllocateSharedBitmap(
67 const gfx::Size
& size
) override
;
68 scoped_ptr
<cc::SharedBitmap
> GetSharedBitmapFromId(
69 const gfx::Size
& size
,
70 const cc::SharedBitmapId
&) override
;
72 size_t AllocatedBitmapCount() const;
74 void FreeSharedMemoryFromMap(const cc::SharedBitmapId
& id
);
77 friend class HostSharedBitmapManagerClient
;
79 void AllocateSharedBitmapForChild(
80 base::ProcessHandle process_handle
,
82 const cc::SharedBitmapId
& id
,
83 base::SharedMemoryHandle
* shared_memory_handle
);
84 void ChildAllocatedSharedBitmap(size_t buffer_size
,
85 const base::SharedMemoryHandle
& handle
,
86 base::ProcessHandle process_handle
,
87 const cc::SharedBitmapId
& id
);
88 void ChildDeletedSharedBitmap(const cc::SharedBitmapId
& id
);
90 mutable base::Lock lock_
;
92 typedef base::hash_map
<cc::SharedBitmapId
, scoped_refptr
<BitmapData
> >
94 BitmapMap handle_map_
;
96 DISALLOW_COPY_AND_ASSIGN(HostSharedBitmapManager
);
99 } // namespace content
101 #endif // CONTENT_COMMON_HOST_SHARED_BITMAP_MANAGER_H_