Chromium Code Reviews| Index: cc/resources/shared_bitmap.cc |
| diff --git a/cc/resources/shared_bitmap.cc b/cc/resources/shared_bitmap.cc |
| index 3a6fc3589e3a8471b9a4d10e75278c76bfbe0a41..3caab4050d13d26e630c52af16cdf86013a9e516 100644 |
| --- a/cc/resources/shared_bitmap.cc |
| +++ b/cc/resources/shared_bitmap.cc |
| @@ -4,6 +4,8 @@ |
| #include "cc/resources/shared_bitmap.h" |
| +#include "base/rand_util.h" |
| + |
| namespace cc { |
| SharedBitmap::SharedBitmap( |
| @@ -14,4 +16,28 @@ SharedBitmap::SharedBitmap( |
| SharedBitmap::~SharedBitmap() { free_callback_.Run(this); } |
| +// static |
| +bool SharedBitmap::GetSizeInBytes(const gfx::Size& size, |
| + size_t* size_in_bytes) { |
| + static const size_t kMaxSize = static_cast<size_t>(INT_MAX); |
| + const size_t stride = 4 * size.width(); |
| + if (size.width() <= 0 || size.height() <= 0 || |
| + static_cast<size_t>(size.width()) > (kMaxSize / 4) || |
| + static_cast<size_t>(size.height()) > (kMaxSize / stride)) { |
| + return false; |
| + } |
| + |
| + *size_in_bytes = size.GetArea() * 4; |
|
jschuh
2014/03/08 00:58:11
I think the base::CheckedNumeric template would ma
|
| + |
| + return true; |
| +} |
| + |
| +// static |
| +SharedBitmapId SharedBitmap::GenerateId() { |
| + SharedBitmapId id; |
| + // Needs cryptographically-secure random numbers. |
| + base::RandBytes(id.name, sizeof(id.name)); |
| + return id; |
| +} |
| + |
| } // namespace cc |