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"
10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/stringprintf.h"
15 SharedBitmap::SharedBitmap(uint8
* pixels
, const SharedBitmapId
& id
)
16 : pixels_(pixels
), id_(id
) {
19 SharedBitmap::~SharedBitmap() {
23 bool SharedBitmap::SizeInBytes(const gfx::Size
& size
, size_t* size_in_bytes
) {
26 base::CheckedNumeric
<size_t> s
= 4;
31 *size_in_bytes
= s
.ValueOrDie();
36 size_t SharedBitmap::CheckedSizeInBytes(const gfx::Size
& size
) {
37 CHECK(!size
.IsEmpty());
38 base::CheckedNumeric
<size_t> s
= 4;
41 return s
.ValueOrDie();
45 size_t SharedBitmap::UncheckedSizeInBytes(const gfx::Size
& size
) {
46 DCHECK(VerifySizeInBytes(size
));
54 bool SharedBitmap::VerifySizeInBytes(const gfx::Size
& size
) {
57 base::CheckedNumeric
<size_t> s
= 4;
64 SharedBitmapId
SharedBitmap::GenerateId() {
66 // Needs cryptographically-secure random numbers.
67 base::RandBytes(id
.name
, sizeof(id
.name
));
71 base::trace_event::MemoryAllocatorDumpGuid
GetSharedBitmapGUIDForTracing(
72 const SharedBitmapId
& bitmap_id
) {
73 auto bitmap_id_hex
= base::HexEncode(bitmap_id
.name
, sizeof(bitmap_id
.name
));
74 return base::trace_event::MemoryAllocatorDumpGuid(
75 base::StringPrintf("sharedbitmap-x-process/%s", bitmap_id_hex
.c_str()));