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

Side by Side Diff: components/viz/client/client_shared_bitmap_manager.cc

Issue 2965103003: Test
Patch Set: c Created 3 years, 5 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 (c) 2013 The Chromium Authors. All rights reserved. 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 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/viz/client/client_shared_bitmap_manager.h" 5 #include "components/viz/client/client_shared_bitmap_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 ~ClientSharedBitmap() override { 48 ~ClientSharedBitmap() override {
49 (*shared_bitmap_allocation_notifier_)->DidDeleteSharedBitmap(id()); 49 (*shared_bitmap_allocation_notifier_)->DidDeleteSharedBitmap(id());
50 } 50 }
51 51
52 // cc::SharedBitmap: 52 // cc::SharedBitmap:
53 base::SharedMemoryHandle GetSharedMemoryHandle() const override { 53 base::SharedMemoryHandle GetSharedMemoryHandle() const override {
54 if (!shared_memory_holder_) 54 if (!shared_memory_holder_)
55 return base::SharedMemoryHandle(); 55 return base::SharedMemoryHandle();
56 return shared_memory_holder_->handle(); 56 return shared_memory_holder_->handle();
57 } 57 }
58 base::SharedMemory* GetSharedMemory() const override {
59 return shared_memory_holder_.get();
60 }
58 61
59 private: 62 private:
60 scoped_refptr< 63 scoped_refptr<
61 cc::mojom::ThreadSafeSharedBitmapAllocationNotifierAssociatedPtr> 64 cc::mojom::ThreadSafeSharedBitmapAllocationNotifierAssociatedPtr>
62 shared_bitmap_allocation_notifier_; 65 shared_bitmap_allocation_notifier_;
63 std::unique_ptr<base::SharedMemory> shared_memory_holder_; 66 std::unique_ptr<base::SharedMemory> shared_memory_holder_;
64 }; 67 };
65 68
66 // Collect extra information for debugging bitmap creation failures. 69 // Collect extra information for debugging bitmap creation failures.
67 void CollectMemoryUsageAndDie(const gfx::Size& size, size_t alloc_size) { 70 void CollectMemoryUsageAndDie(const gfx::Size& size, size_t alloc_size) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId(); 131 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId();
129 std::unique_ptr<base::SharedMemory> memory = 132 std::unique_ptr<base::SharedMemory> memory =
130 AllocateSharedMemory(memory_size); 133 AllocateSharedMemory(memory_size);
131 if (!memory || !memory->Map(memory_size)) 134 if (!memory || !memory->Map(memory_size))
132 CollectMemoryUsageAndDie(size, memory_size); 135 CollectMemoryUsageAndDie(size, memory_size);
133 136
134 NotifyAllocatedSharedBitmap(memory.get(), id); 137 NotifyAllocatedSharedBitmap(memory.get(), id);
135 138
136 // Close the associated FD to save resources, the previously mapped memory 139 // Close the associated FD to save resources, the previously mapped memory
137 // remains available. 140 // remains available.
138 memory->Close(); 141 //memory->Close();
139 142
140 return base::MakeUnique<ClientSharedBitmap>( 143 return base::MakeUnique<ClientSharedBitmap>(
141 shared_bitmap_allocation_notifier_, std::move(memory), id); 144 shared_bitmap_allocation_notifier_, std::move(memory), id);
142 } 145 }
143 146
144 std::unique_ptr<cc::SharedBitmap> 147 std::unique_ptr<cc::SharedBitmap>
145 ClientSharedBitmapManager::GetSharedBitmapFromId(const gfx::Size&, 148 ClientSharedBitmapManager::GetSharedBitmapFromId(const gfx::Size&,
146 const cc::SharedBitmapId&) { 149 const cc::SharedBitmapId&) {
147 NOTREACHED(); 150 NOTREACHED();
148 return nullptr; 151 return nullptr;
149 } 152 }
150 153
151 std::unique_ptr<cc::SharedBitmap> 154 std::unique_ptr<cc::SharedBitmap>
152 ClientSharedBitmapManager::GetBitmapForSharedMemory(base::SharedMemory* mem) { 155 ClientSharedBitmapManager::GetBitmapForSharedMemory(base::SharedMemory* mem) {
153 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId(); 156 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId();
154 NotifyAllocatedSharedBitmap(mem, cc::SharedBitmap::GenerateId()); 157 NotifyAllocatedSharedBitmap(mem, cc::SharedBitmap::GenerateId());
155 return base::MakeUnique<ClientSharedBitmap>( 158 return base::MakeUnique<ClientSharedBitmap>(
156 shared_bitmap_allocation_notifier_, mem, id); 159 shared_bitmap_allocation_notifier_, mem, id);
157 } 160 }
158 161
159 // Notifies the browser process that a shared bitmap with the given ID was 162 // Notifies the browser process that a shared bitmap with the given ID was
160 // allocated. Caller keeps ownership of |memory|. 163 // allocated. Caller keeps ownership of |memory|.
161 void ClientSharedBitmapManager::NotifyAllocatedSharedBitmap( 164 void ClientSharedBitmapManager::NotifyAllocatedSharedBitmap(
162 base::SharedMemory* memory, 165 base::SharedMemory* memory,
163 const cc::SharedBitmapId& id) { 166 const cc::SharedBitmapId& id) {
167 return;
164 base::SharedMemoryHandle handle_to_send = 168 base::SharedMemoryHandle handle_to_send =
165 base::SharedMemory::DuplicateHandle(memory->handle()); 169 base::SharedMemory::DuplicateHandle(memory->handle());
166 if (!base::SharedMemory::IsHandleValid(handle_to_send)) { 170 if (!base::SharedMemory::IsHandleValid(handle_to_send)) {
167 LOG(ERROR) << "Failed to duplicate shared memory handle for bitmap."; 171 LOG(ERROR) << "Failed to duplicate shared memory handle for bitmap.";
168 return; 172 return;
169 } 173 }
170 174
171 mojo::ScopedSharedBufferHandle buffer_handle = mojo::WrapSharedMemoryHandle( 175 mojo::ScopedSharedBufferHandle buffer_handle = mojo::WrapSharedMemoryHandle(
172 handle_to_send, memory->mapped_size(), true /* read_only */); 176 handle_to_send, memory->mapped_size(), true /* read_only */);
173 177
174 (*shared_bitmap_allocation_notifier_) 178 (*shared_bitmap_allocation_notifier_)
175 ->DidAllocateSharedBitmap(std::move(buffer_handle), id); 179 ->DidAllocateSharedBitmap(std::move(buffer_handle), id);
176 } 180 }
177 181
178 } // namespace viz 182 } // namespace viz
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl.cc ('k') | components/viz/service/display_embedder/server_shared_bitmap_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698