Blink roll 25b6bd3a7a131ffe68d809546ad1a20707915cdc:3a503f41ae42e5b79cfcd2ff10e65afde...
[chromium-blink-merge.git] / content / common / host_shared_bitmap_manager.h
blob71af0e36ec682a76b5e6cdc740a7859b2d1e4d4a
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_
8 #include <map>
9 #include <set>
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 {
22 template <>
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
30 namespace content {
31 class BitmapData;
33 class CONTENT_EXPORT HostSharedBitmapManager : public cc::SharedBitmapManager {
34 public:
35 HostSharedBitmapManager();
36 ~HostSharedBitmapManager() override;
38 static HostSharedBitmapManager* current();
40 // cc::SharedBitmapManager implementation.
41 scoped_ptr<cc::SharedBitmap> AllocateSharedBitmap(
42 const gfx::Size& size) override;
43 scoped_ptr<cc::SharedBitmap> GetSharedBitmapFromId(
44 const gfx::Size& size,
45 const cc::SharedBitmapId&) override;
46 scoped_ptr<cc::SharedBitmap> GetBitmapForSharedMemory(
47 base::SharedMemory*) override;
49 void AllocateSharedBitmapForChild(
50 base::ProcessHandle process_handle,
51 size_t buffer_size,
52 const cc::SharedBitmapId& id,
53 base::SharedMemoryHandle* shared_memory_handle);
54 void ChildAllocatedSharedBitmap(size_t buffer_size,
55 const base::SharedMemoryHandle& handle,
56 base::ProcessHandle process_handle,
57 const cc::SharedBitmapId& id);
58 void ChildDeletedSharedBitmap(const cc::SharedBitmapId& id);
59 void ProcessRemoved(base::ProcessHandle process_handle);
61 size_t AllocatedBitmapCount() const;
63 private:
64 void FreeSharedMemoryFromMap(cc::SharedBitmap* bitmap);
66 mutable base::Lock lock_;
68 typedef base::hash_map<cc::SharedBitmapId, scoped_refptr<BitmapData> >
69 BitmapMap;
70 BitmapMap handle_map_;
72 typedef base::hash_map<base::ProcessHandle,
73 base::hash_set<cc::SharedBitmapId> > ProcessMap;
74 ProcessMap process_map_;
77 } // namespace content
79 #endif // CONTENT_COMMON_HOST_SHARED_BITMAP_MANAGER_H_