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..c06561447577e6961f1996c8947afe33a9f6f7b5 100644 |
| --- a/cc/resources/shared_bitmap.cc |
| +++ b/cc/resources/shared_bitmap.cc |
| @@ -4,6 +4,9 @@ |
| #include "cc/resources/shared_bitmap.h" |
| +#include "base/numerics/safe_math.h" |
| +#include "base/rand_util.h" |
| + |
| namespace cc { |
| SharedBitmap::SharedBitmap( |
| @@ -14,4 +17,24 @@ SharedBitmap::SharedBitmap( |
| SharedBitmap::~SharedBitmap() { free_callback_.Run(this); } |
| +// static |
| +bool SharedBitmap::GetSizeInBytes(const gfx::Size& size, |
| + size_t* size_in_bytes) { |
| + base::CheckedNumeric<int> s = size.width(); |
|
jschuh
2014/03/10 22:18:54
Do you still want a check that height and width ar
|
| + s *= size.height(); |
| + s *= 4; |
| + if (!s.IsValid()) |
| + return false; |
| + *size_in_bytes = s.ValueOrDie(); |
| + return true; |
| +} |
| + |
| +// static |
| +SharedBitmapId SharedBitmap::GenerateId() { |
| + SharedBitmapId id; |
| + // Needs cryptographically-secure random numbers. |
| + base::RandBytes(id.name, sizeof(id.name)); |
| + return id; |
| +} |
| + |
| } // namespace cc |