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.
5 #include "cc/resources/shared_bitmap.h"
7 #include "base/logging.h"
8 #include "base/numerics/safe_math.h"
9 #include "base/rand_util.h"
13 SharedBitmap::SharedBitmap(uint8
* pixels
, const SharedBitmapId
& id
)
14 : pixels_(pixels
), id_(id
) {
17 SharedBitmap::~SharedBitmap() {
21 bool SharedBitmap::SizeInBytes(const gfx::Size
& size
, size_t* size_in_bytes
) {
24 base::CheckedNumeric
<size_t> s
= 4;
29 *size_in_bytes
= s
.ValueOrDie();
34 size_t SharedBitmap::CheckedSizeInBytes(const gfx::Size
& size
) {
35 CHECK(!size
.IsEmpty());
36 base::CheckedNumeric
<size_t> s
= 4;
39 return s
.ValueOrDie();
43 size_t SharedBitmap::UncheckedSizeInBytes(const gfx::Size
& size
) {
44 DCHECK(VerifySizeInBytes(size
));
52 bool SharedBitmap::VerifySizeInBytes(const gfx::Size
& size
) {
55 base::CheckedNumeric
<size_t> s
= 4;
62 SharedBitmapId
SharedBitmap::GenerateId() {
64 // Needs cryptographically-secure random numbers.
65 base::RandBytes(id
.name
, sizeof(id
.name
));