OLD | NEW |
| (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 #ifndef COMPONENTS_DISPLAY_COMPOSITOR_HOST_SHARED_BITMAP_MANAGER_H_ | |
6 #define COMPONENTS_DISPLAY_COMPOSITOR_HOST_SHARED_BITMAP_MANAGER_H_ | |
7 | |
8 #include <stddef.h> | |
9 | |
10 #include <map> | |
11 #include <memory> | |
12 #include <set> | |
13 | |
14 #include "base/containers/hash_tables.h" | |
15 #include "base/hash.h" | |
16 #include "base/macros.h" | |
17 #include "base/memory/ref_counted.h" | |
18 #include "base/memory/shared_memory.h" | |
19 #include "base/synchronization/lock.h" | |
20 #include "base/trace_event/memory_dump_provider.h" | |
21 #include "cc/ipc/shared_bitmap_manager.mojom.h" | |
22 #include "cc/resources/shared_bitmap_manager.h" | |
23 #include "components/display_compositor/display_compositor_export.h" | |
24 #include "mojo/public/cpp/bindings/associated_binding.h" | |
25 | |
26 namespace BASE_HASH_NAMESPACE { | |
27 template <> | |
28 struct hash<cc::SharedBitmapId> { | |
29 size_t operator()(const cc::SharedBitmapId& id) const { | |
30 return base::Hash(reinterpret_cast<const char*>(id.name), sizeof(id.name)); | |
31 } | |
32 }; | |
33 } // namespace BASE_HASH_NAMESPACE | |
34 | |
35 namespace display_compositor { | |
36 class BitmapData; | |
37 class HostSharedBitmapManager; | |
38 | |
39 class DISPLAY_COMPOSITOR_EXPORT HostSharedBitmapManagerClient | |
40 : NON_EXPORTED_BASE(public cc::mojom::SharedBitmapManager) { | |
41 public: | |
42 explicit HostSharedBitmapManagerClient(HostSharedBitmapManager* manager); | |
43 | |
44 ~HostSharedBitmapManagerClient() override; | |
45 | |
46 void Bind(cc::mojom::SharedBitmapManagerAssociatedRequest request); | |
47 | |
48 // cc::mojom::SharedBitmapManager overrides: | |
49 void DidAllocateSharedBitmap(mojo::ScopedSharedBufferHandle buffer, | |
50 const cc::SharedBitmapId& id) override; | |
51 void DidDeleteSharedBitmap(const cc::SharedBitmapId& id) override; | |
52 | |
53 void ChildAllocatedSharedBitmap(size_t buffer_size, | |
54 const base::SharedMemoryHandle& handle, | |
55 const cc::SharedBitmapId& id); | |
56 | |
57 private: | |
58 HostSharedBitmapManager* manager_; | |
59 mojo::AssociatedBinding<cc::mojom::SharedBitmapManager> binding_; | |
60 | |
61 // Lock must be held around access to owned_bitmaps_. | |
62 base::Lock lock_; | |
63 base::hash_set<cc::SharedBitmapId> owned_bitmaps_; | |
64 | |
65 DISALLOW_COPY_AND_ASSIGN(HostSharedBitmapManagerClient); | |
66 }; | |
67 | |
68 class DISPLAY_COMPOSITOR_EXPORT HostSharedBitmapManager | |
69 : public cc::SharedBitmapManager, | |
70 public base::trace_event::MemoryDumpProvider { | |
71 public: | |
72 HostSharedBitmapManager(); | |
73 ~HostSharedBitmapManager() override; | |
74 | |
75 static HostSharedBitmapManager* current(); | |
76 | |
77 // cc::SharedBitmapManager implementation. | |
78 std::unique_ptr<cc::SharedBitmap> AllocateSharedBitmap( | |
79 const gfx::Size& size) override; | |
80 std::unique_ptr<cc::SharedBitmap> GetSharedBitmapFromId( | |
81 const gfx::Size& size, | |
82 const cc::SharedBitmapId&) override; | |
83 | |
84 // base::trace_event::MemoryDumpProvider implementation. | |
85 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, | |
86 base::trace_event::ProcessMemoryDump* pmd) override; | |
87 | |
88 size_t AllocatedBitmapCount() const; | |
89 | |
90 void FreeSharedMemoryFromMap(const cc::SharedBitmapId& id); | |
91 | |
92 private: | |
93 friend class HostSharedBitmapManagerClient; | |
94 | |
95 bool ChildAllocatedSharedBitmap(size_t buffer_size, | |
96 const base::SharedMemoryHandle& handle, | |
97 const cc::SharedBitmapId& id); | |
98 void ChildDeletedSharedBitmap(const cc::SharedBitmapId& id); | |
99 | |
100 mutable base::Lock lock_; | |
101 | |
102 typedef base::hash_map<cc::SharedBitmapId, scoped_refptr<BitmapData>> | |
103 BitmapMap; | |
104 BitmapMap handle_map_; | |
105 | |
106 DISALLOW_COPY_AND_ASSIGN(HostSharedBitmapManager); | |
107 }; | |
108 | |
109 } // namespace display_compositor | |
110 | |
111 #endif // COMPONENTS_DISPLAY_COMPOSITOR_HOST_SHARED_BITMAP_MANAGER_H_ | |
OLD | NEW |