summaryrefslogtreecommitdiffstats
path: root/cc/resources/shared_bitmap.cc
diff options
context:
space:
mode:
Diffstat (limited to 'cc/resources/shared_bitmap.cc')
-rw-r--r--cc/resources/shared_bitmap.cc25
1 files changed, 25 insertions, 0 deletions
diff --git a/cc/resources/shared_bitmap.cc b/cc/resources/shared_bitmap.cc
index 3a6fc35..3b94d45 100644
--- a/cc/resources/shared_bitmap.cc
+++ b/cc/resources/shared_bitmap.cc
@@ -4,6 +4,9 @@
#include "cc/resources/shared_bitmap.h"
+#include "base/numerics/safe_math.h"
+#include "base/rand_util.h"
+
namespace cc {
SharedBitmap::SharedBitmap(
@@ -14,4 +17,26 @@ SharedBitmap::SharedBitmap(
SharedBitmap::~SharedBitmap() { free_callback_.Run(this); }
+// static
+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;
+}
+
+// static
+SharedBitmapId SharedBitmap::GenerateId() {
+ SharedBitmapId id;
+ // Needs cryptographically-secure random numbers.
+ base::RandBytes(id.name, sizeof(id.name));
+ return id;
+}
+
} // namespace cc