| OLD | NEW |
| 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 "content/browser/renderer_host/software_frame_manager.h" | 5 #include "content/browser/renderer_host/software_frame_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/debug/alias.h" | 9 #include "base/debug/alias.h" |
| 10 #include "base/numerics/safe_math.h" | 10 #include "base/numerics/safe_math.h" |
| 11 #include "cc/resources/shared_bitmap.h" |
| 11 #include "content/browser/renderer_host/dip_util.h" | 12 #include "content/browser/renderer_host/dip_util.h" |
| 12 #include "content/public/browser/user_metrics.h" | 13 #include "content/public/browser/user_metrics.h" |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 void ReleaseMailbox(scoped_refptr<content::SoftwareFrame> frame, | 17 void ReleaseMailbox(scoped_refptr<content::SoftwareFrame> frame, |
| 17 uint32 sync_point, | 18 uint32 sync_point, |
| 18 bool lost_resource) {} | 19 bool lost_resource) {} |
| 19 | 20 |
| 20 } // namespace | 21 } // namespace |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 scoped_ptr<base::SharedMemory> shared_memory( | 91 scoped_ptr<base::SharedMemory> shared_memory( |
| 91 new base::SharedMemory(frame_data->handle, true, | 92 new base::SharedMemory(frame_data->handle, true, |
| 92 process_handle)); | 93 process_handle)); |
| 93 #else | 94 #else |
| 94 scoped_ptr<base::SharedMemory> shared_memory( | 95 scoped_ptr<base::SharedMemory> shared_memory( |
| 95 new base::SharedMemory(frame_data->handle, true)); | 96 new base::SharedMemory(frame_data->handle, true)); |
| 96 #endif | 97 #endif |
| 97 | 98 |
| 98 // The NULL handle is used in testing. | 99 // The NULL handle is used in testing. |
| 99 if (base::SharedMemory::IsHandleValid(shared_memory->handle())) { | 100 if (base::SharedMemory::IsHandleValid(shared_memory->handle())) { |
| 100 DCHECK(frame_data->CheckedSizeInBytes().IsValid()) | 101 DCHECK(cc::SharedBitmap::VerifySizeInBytes(frame_data->size)); |
| 101 << "Integer overflow when computing bytes to map."; | 102 // UncheckedSizeInBytes is okay because the frame_data size was verified |
| 102 size_t size_in_bytes = frame_data->SizeInBytes(); | 103 // when frame_data was received over IPC. |
| 104 size_t size_in_bytes = |
| 105 cc::SharedBitmap::UncheckedSizeInBytes(frame_data->size); |
| 103 #ifdef OS_WIN | 106 #ifdef OS_WIN |
| 104 if (!shared_memory->Map(0)) { | 107 if (!shared_memory->Map(0)) { |
| 105 DLOG(ERROR) << "Unable to map renderer memory."; | 108 DLOG(ERROR) << "Unable to map renderer memory."; |
| 106 RecordAction( | 109 RecordAction( |
| 107 base::UserMetricsAction("BadMessageTerminate_SharedMemoryManager1")); | 110 base::UserMetricsAction("BadMessageTerminate_SharedMemoryManager1")); |
| 108 return false; | 111 return false; |
| 109 } | 112 } |
| 110 | 113 |
| 111 if (shared_memory->mapped_size() < size_in_bytes) { | 114 if (shared_memory->mapped_size() < size_in_bytes) { |
| 112 DLOG(ERROR) << "Shared memory too small for given rectangle"; | 115 DLOG(ERROR) << "Shared memory too small for given rectangle"; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 } | 203 } |
| 201 | 204 |
| 202 void SoftwareFrameManager::EvictCurrentFrame() { | 205 void SoftwareFrameManager::EvictCurrentFrame() { |
| 203 DCHECK(HasCurrentFrame()); | 206 DCHECK(HasCurrentFrame()); |
| 204 DiscardCurrentFrame(); | 207 DiscardCurrentFrame(); |
| 205 if (client_) | 208 if (client_) |
| 206 client_->ReleaseReferencesToSoftwareFrame(); | 209 client_->ReleaseReferencesToSoftwareFrame(); |
| 207 } | 210 } |
| 208 | 211 |
| 209 } // namespace content | 212 } // namespace content |
| OLD | NEW |