| 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/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/numerics/safe_math.h" | 8 #include "base/numerics/safe_math.h" |
| 9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
| 10 | 10 |
| 11 namespace cc { | 11 namespace cc { |
| 12 | 12 |
| 13 SharedBitmap::SharedBitmap( | 13 SharedBitmap::SharedBitmap(uint8* pixels, const SharedBitmapId& id) |
| 14 base::SharedMemory* memory, | 14 : pixels_(pixels), id_(id) { |
| 15 const SharedBitmapId& id, | |
| 16 const base::Callback<void(SharedBitmap* bitmap)>& free_callback) | |
| 17 : memory_(memory), | |
| 18 pixels_(static_cast<uint8*>(memory_->memory())), | |
| 19 id_(id), | |
| 20 free_callback_(free_callback) { | |
| 21 } | 15 } |
| 22 | 16 |
| 23 SharedBitmap::SharedBitmap( | 17 SharedBitmap::~SharedBitmap() { |
| 24 uint8* pixels, | |
| 25 const SharedBitmapId& id, | |
| 26 const base::Callback<void(SharedBitmap* bitmap)>& free_callback) | |
| 27 : memory_(NULL), pixels_(pixels), id_(id), free_callback_(free_callback) { | |
| 28 } | 18 } |
| 29 | 19 |
| 30 SharedBitmap::~SharedBitmap() { free_callback_.Run(this); } | |
| 31 | |
| 32 // static | 20 // static |
| 33 bool SharedBitmap::SizeInBytes(const gfx::Size& size, size_t* size_in_bytes) { | 21 bool SharedBitmap::SizeInBytes(const gfx::Size& size, size_t* size_in_bytes) { |
| 34 if (size.IsEmpty()) | 22 if (size.IsEmpty()) |
| 35 return false; | 23 return false; |
| 36 base::CheckedNumeric<size_t> s = 4; | 24 base::CheckedNumeric<size_t> s = 4; |
| 37 s *= size.width(); | 25 s *= size.width(); |
| 38 s *= size.height(); | 26 s *= size.height(); |
| 39 if (!s.IsValid()) | 27 if (!s.IsValid()) |
| 40 return false; | 28 return false; |
| 41 *size_in_bytes = s.ValueOrDie(); | 29 *size_in_bytes = s.ValueOrDie(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 72 | 60 |
| 73 // static | 61 // static |
| 74 SharedBitmapId SharedBitmap::GenerateId() { | 62 SharedBitmapId SharedBitmap::GenerateId() { |
| 75 SharedBitmapId id; | 63 SharedBitmapId id; |
| 76 // Needs cryptographically-secure random numbers. | 64 // Needs cryptographically-secure random numbers. |
| 77 base::RandBytes(id.name, sizeof(id.name)); | 65 base::RandBytes(id.name, sizeof(id.name)); |
| 78 return id; | 66 return id; |
| 79 } | 67 } |
| 80 | 68 |
| 81 } // namespace cc | 69 } // namespace cc |
| OLD | NEW |