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/rand_util.h" | |
| 8 | |
| 7 namespace cc { | 9 namespace cc { |
| 8 | 10 |
| 9 SharedBitmap::SharedBitmap( | 11 SharedBitmap::SharedBitmap( |
| 10 base::SharedMemory* memory, | 12 base::SharedMemory* memory, |
| 11 const SharedBitmapId& id, | 13 const SharedBitmapId& id, |
| 12 const base::Callback<void(SharedBitmap*)>& free_callback) | 14 const base::Callback<void(SharedBitmap*)>& free_callback) |
| 13 : memory_(memory), id_(id), free_callback_(free_callback) {} | 15 : memory_(memory), id_(id), free_callback_(free_callback) {} |
| 14 | 16 |
| 15 SharedBitmap::~SharedBitmap() { free_callback_.Run(this); } | 17 SharedBitmap::~SharedBitmap() { free_callback_.Run(this); } |
| 16 | 18 |
| 19 // static | |
| 20 bool SharedBitmap::GetSizeInBytes(const gfx::Size& size, | |
| 21 size_t* size_in_bytes) { | |
| 22 static const size_t kMaxSize = static_cast<size_t>(INT_MAX); | |
| 23 const size_t stride = 4 * size.width(); | |
| 24 if (size.width() <= 0 || size.height() <= 0 || | |
| 25 static_cast<size_t>(size.width()) > (kMaxSize / 4) || | |
| 26 static_cast<size_t>(size.height()) > (kMaxSize / stride)) { | |
| 27 return false; | |
| 28 } | |
| 29 | |
| 30 *size_in_bytes = size.GetArea() * 4; | |
|
jschuh
2014/03/08 00:58:11
I think the base::CheckedNumeric template would ma
| |
| 31 | |
| 32 return true; | |
| 33 } | |
| 34 | |
| 35 // static | |
| 36 SharedBitmapId SharedBitmap::GenerateId() { | |
| 37 SharedBitmapId id; | |
| 38 // Needs cryptographically-secure random numbers. | |
| 39 base::RandBytes(id.name, sizeof(id.name)); | |
| 40 return id; | |
| 41 } | |
| 42 | |
| 17 } // namespace cc | 43 } // namespace cc |
| OLD | NEW |