| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "cc/resources/shared_bitmap.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/numerics/safe_math.h" | |
| 9 #include "base/rand_util.h" | |
| 10 | |
| 11 namespace cc { | |
| 12 | |
| 13 SharedBitmap::SharedBitmap(uint8* pixels, const SharedBitmapId& id) | |
| 14 : pixels_(pixels), id_(id) { | |
| 15 } | |
| 16 | |
| 17 SharedBitmap::~SharedBitmap() { | |
| 18 } | |
| 19 | |
| 20 // static | |
| 21 bool SharedBitmap::SizeInBytes(const gfx::Size& size, size_t* size_in_bytes) { | |
| 22 if (size.IsEmpty()) | |
| 23 return false; | |
| 24 base::CheckedNumeric<size_t> s = 4; | |
| 25 s *= size.width(); | |
| 26 s *= size.height(); | |
| 27 if (!s.IsValid()) | |
| 28 return false; | |
| 29 *size_in_bytes = s.ValueOrDie(); | |
| 30 return true; | |
| 31 } | |
| 32 | |
| 33 // static | |
| 34 size_t SharedBitmap::CheckedSizeInBytes(const gfx::Size& size) { | |
| 35 CHECK(!size.IsEmpty()); | |
| 36 base::CheckedNumeric<size_t> s = 4; | |
| 37 s *= size.width(); | |
| 38 s *= size.height(); | |
| 39 return s.ValueOrDie(); | |
| 40 } | |
| 41 | |
| 42 // static | |
| 43 size_t SharedBitmap::UncheckedSizeInBytes(const gfx::Size& size) { | |
| 44 DCHECK(VerifySizeInBytes(size)); | |
| 45 size_t s = 4; | |
| 46 s *= size.width(); | |
| 47 s *= size.height(); | |
| 48 return s; | |
| 49 } | |
| 50 | |
| 51 // static | |
| 52 bool SharedBitmap::VerifySizeInBytes(const gfx::Size& size) { | |
| 53 if (size.IsEmpty()) | |
| 54 return false; | |
| 55 base::CheckedNumeric<size_t> s = 4; | |
| 56 s *= size.width(); | |
| 57 s *= size.height(); | |
| 58 return s.IsValid(); | |
| 59 } | |
| 60 | |
| 61 // static | |
| 62 SharedBitmapId SharedBitmap::GenerateId() { | |
| 63 SharedBitmapId id; | |
| 64 // Needs cryptographically-secure random numbers. | |
| 65 base::RandBytes(id.name, sizeof(id.name)); | |
| 66 return id; | |
| 67 } | |
| 68 | |
| 69 } // namespace cc | |
| OLD | NEW |