Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(564)

Side by Side Diff: components/viz/display_compositor/host_shared_bitmap_manager.cc

Issue 2873243002: Move components/display_compositor to components/viz/display_compositor (Closed)
Patch Set: Rebase Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/display_compositor/host_shared_bitmap_manager.h" 5 #include "components/viz/display_compositor/host_shared_bitmap_manager.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
17 #include "base/trace_event/process_memory_dump.h" 17 #include "base/trace_event/process_memory_dump.h"
18 #include "build/build_config.h" 18 #include "build/build_config.h"
19 #include "mojo/public/cpp/system/platform_handle.h" 19 #include "mojo/public/cpp/system/platform_handle.h"
20 #include "ui/gfx/geometry/size.h" 20 #include "ui/gfx/geometry/size.h"
21 21
22 namespace display_compositor { 22 namespace viz {
23 23
24 class BitmapData : public base::RefCountedThreadSafe<BitmapData> { 24 class BitmapData : public base::RefCountedThreadSafe<BitmapData> {
25 public: 25 public:
26 explicit BitmapData(size_t buffer_size) : buffer_size(buffer_size) {} 26 explicit BitmapData(size_t buffer_size) : buffer_size(buffer_size) {}
27 std::unique_ptr<base::SharedMemory> memory; 27 std::unique_ptr<base::SharedMemory> memory;
28 std::unique_ptr<uint8_t[]> pixels; 28 std::unique_ptr<uint8_t[]> pixels;
29 size_t buffer_size; 29 size_t buffer_size;
30 30
31 private: 31 private:
32 friend class base::RefCountedThreadSafe<BitmapData>; 32 friend class base::RefCountedThreadSafe<BitmapData>;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 112
113 HostSharedBitmapManager* HostSharedBitmapManager::current() { 113 HostSharedBitmapManager* HostSharedBitmapManager::current() {
114 return g_shared_memory_manager.Pointer(); 114 return g_shared_memory_manager.Pointer();
115 } 115 }
116 116
117 std::unique_ptr<cc::SharedBitmap> HostSharedBitmapManager::AllocateSharedBitmap( 117 std::unique_ptr<cc::SharedBitmap> HostSharedBitmapManager::AllocateSharedBitmap(
118 const gfx::Size& size) { 118 const gfx::Size& size) {
119 base::AutoLock lock(lock_); 119 base::AutoLock lock(lock_);
120 size_t bitmap_size; 120 size_t bitmap_size;
121 if (!cc::SharedBitmap::SizeInBytes(size, &bitmap_size)) 121 if (!cc::SharedBitmap::SizeInBytes(size, &bitmap_size))
122 return std::unique_ptr<cc::SharedBitmap>(); 122 return nullptr;
123 123
124 scoped_refptr<BitmapData> data(new BitmapData(bitmap_size)); 124 scoped_refptr<BitmapData> data(new BitmapData(bitmap_size));
125 // Bitmaps allocated in host don't need to be shared to other processes, so 125 // Bitmaps allocated in host don't need to be shared to other processes, so
126 // allocate them with new instead. 126 // allocate them with new instead.
127 data->pixels = std::unique_ptr<uint8_t[]>(new uint8_t[bitmap_size]); 127 data->pixels = std::unique_ptr<uint8_t[]>(new uint8_t[bitmap_size]);
128 128
129 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId(); 129 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId();
130 handle_map_[id] = data; 130 handle_map_[id] = data;
131 return base::MakeUnique<HostSharedBitmap>(data->pixels.get(), data, id, this); 131 return base::MakeUnique<HostSharedBitmap>(data->pixels.get(), data, id, this);
132 } 132 }
133 133
134 std::unique_ptr<cc::SharedBitmap> 134 std::unique_ptr<cc::SharedBitmap>
135 HostSharedBitmapManager::GetSharedBitmapFromId(const gfx::Size& size, 135 HostSharedBitmapManager::GetSharedBitmapFromId(const gfx::Size& size,
136 const cc::SharedBitmapId& id) { 136 const cc::SharedBitmapId& id) {
137 base::AutoLock lock(lock_); 137 base::AutoLock lock(lock_);
138 BitmapMap::iterator it = handle_map_.find(id); 138 BitmapMap::iterator it = handle_map_.find(id);
139 if (it == handle_map_.end()) 139 if (it == handle_map_.end())
140 return std::unique_ptr<cc::SharedBitmap>(); 140 return nullptr;
141 141
142 BitmapData* data = it->second.get(); 142 BitmapData* data = it->second.get();
143 143
144 size_t bitmap_size; 144 size_t bitmap_size;
145 if (!cc::SharedBitmap::SizeInBytes(size, &bitmap_size) || 145 if (!cc::SharedBitmap::SizeInBytes(size, &bitmap_size) ||
146 bitmap_size > data->buffer_size) 146 bitmap_size > data->buffer_size)
147 return std::unique_ptr<cc::SharedBitmap>(); 147 return nullptr;
148 148
149 if (data->pixels) { 149 if (data->pixels) {
150 return base::MakeUnique<HostSharedBitmap>(data->pixels.get(), data, id, 150 return base::MakeUnique<HostSharedBitmap>(data->pixels.get(), data, id,
151 nullptr); 151 nullptr);
152 } 152 }
153 if (!data->memory->memory()) { 153 if (!data->memory->memory()) {
154 return std::unique_ptr<cc::SharedBitmap>(); 154 return nullptr;
155 } 155 }
156 156
157 return base::MakeUnique<HostSharedBitmap>( 157 return base::MakeUnique<HostSharedBitmap>(
158 static_cast<uint8_t*>(data->memory->memory()), data, id, nullptr); 158 static_cast<uint8_t*>(data->memory->memory()), data, id, nullptr);
159 } 159 }
160 160
161 bool HostSharedBitmapManager::OnMemoryDump( 161 bool HostSharedBitmapManager::OnMemoryDump(
162 const base::trace_event::MemoryDumpArgs& args, 162 const base::trace_event::MemoryDumpArgs& args,
163 base::trace_event::ProcessMemoryDump* pmd) { 163 base::trace_event::ProcessMemoryDump* pmd) {
164 base::AutoLock lock(lock_); 164 base::AutoLock lock(lock_);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 base::AutoLock lock(lock_); 212 base::AutoLock lock(lock_);
213 return handle_map_.size(); 213 return handle_map_.size();
214 } 214 }
215 215
216 void HostSharedBitmapManager::FreeSharedMemoryFromMap( 216 void HostSharedBitmapManager::FreeSharedMemoryFromMap(
217 const cc::SharedBitmapId& id) { 217 const cc::SharedBitmapId& id) {
218 base::AutoLock lock(lock_); 218 base::AutoLock lock(lock_);
219 handle_map_.erase(id); 219 handle_map_.erase(id);
220 } 220 }
221 221
222 } // namespace display_compositor 222 } // namespace viz
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698