This source file includes following definitions.
- free_callback_
- GetSizeInBytes
- GenerateId
#include "cc/resources/shared_bitmap.h"
#include "base/numerics/safe_math.h"
#include "base/rand_util.h"
namespace cc {
SharedBitmap::SharedBitmap(
base::SharedMemory* memory,
const SharedBitmapId& id,
const base::Callback<void(SharedBitmap*)>& free_callback)
: memory_(memory), id_(id), free_callback_(free_callback) {}
SharedBitmap::~SharedBitmap() { free_callback_.Run(this); }
bool SharedBitmap::GetSizeInBytes(const gfx::Size& size,
size_t* size_in_bytes) {
if (size.width() <= 0 || size.height() <= 0)
return false;
base::CheckedNumeric<int> s = size.width();
s *= size.height();
s *= 4;
if (!s.IsValid())
return false;
*size_in_bytes = s.ValueOrDie();
return true;
}
SharedBitmapId SharedBitmap::GenerateId() {
SharedBitmapId id;
base::RandBytes(id.name, sizeof(id.name));
return id;
}
}