Chromium Code Reviews| 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 "cc/resources/shared_bitmap.h" | 5 #include "cc/resources/shared_bitmap.h" |
| 6 | 6 |
| 7 #include "base/numerics/safe_math.h" | |
| 8 #include "base/rand_util.h" | |
| 9 | |
| 7 namespace cc { | 10 namespace cc { |
| 8 | 11 |
| 9 SharedBitmap::SharedBitmap( | 12 SharedBitmap::SharedBitmap( |
| 10 base::SharedMemory* memory, | 13 base::SharedMemory* memory, |
| 11 const SharedBitmapId& id, | 14 const SharedBitmapId& id, |
| 12 const base::Callback<void(SharedBitmap*)>& free_callback) | 15 const base::Callback<void(SharedBitmap*)>& free_callback) |
| 13 : memory_(memory), id_(id), free_callback_(free_callback) {} | 16 : memory_(memory), id_(id), free_callback_(free_callback) {} |
| 14 | 17 |
| 15 SharedBitmap::~SharedBitmap() { free_callback_.Run(this); } | 18 SharedBitmap::~SharedBitmap() { free_callback_.Run(this); } |
| 16 | 19 |
| 20 // static | |
| 21 bool SharedBitmap::GetSizeInBytes(const gfx::Size& size, | |
| 22 size_t* size_in_bytes) { | |
| 23 base::CheckedNumeric<int> s = size.width(); | |
|
jschuh
2014/03/10 22:18:54
Do you still want a check that height and width ar
| |
| 24 s *= size.height(); | |
| 25 s *= 4; | |
| 26 if (!s.IsValid()) | |
| 27 return false; | |
| 28 *size_in_bytes = s.ValueOrDie(); | |
| 29 return true; | |
| 30 } | |
| 31 | |
| 32 // static | |
| 33 SharedBitmapId SharedBitmap::GenerateId() { | |
| 34 SharedBitmapId id; | |
| 35 // Needs cryptographically-secure random numbers. | |
| 36 base::RandBytes(id.name, sizeof(id.name)); | |
| 37 return id; | |
| 38 } | |
| 39 | |
| 17 } // namespace cc | 40 } // namespace cc |
| OLD | NEW |