Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Unified Diff: cc/resources/shared_bitmap.cc

Issue 221523003: cc: Remove all usage of GetArea() from production code in cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: getarea: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/resources/shared_bitmap.h ('k') | cc/resources/texture_mailbox.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/resources/shared_bitmap.cc
diff --git a/cc/resources/shared_bitmap.cc b/cc/resources/shared_bitmap.cc
index 3b94d451dff1bcd9b25e8d83948e1f4f279e946d..6d2ff0af5d5e41049e852f8bd1f7725f5a5b055f 100644
--- a/cc/resources/shared_bitmap.cc
+++ b/cc/resources/shared_bitmap.cc
@@ -4,6 +4,7 @@
#include "cc/resources/shared_bitmap.h"
+#include "base/logging.h"
#include "base/numerics/safe_math.h"
#include "base/rand_util.h"
@@ -12,19 +13,18 @@ namespace cc {
SharedBitmap::SharedBitmap(
base::SharedMemory* memory,
const SharedBitmapId& id,
- const base::Callback<void(SharedBitmap*)>& free_callback)
+ const base::Callback<void(SharedBitmap* bitmap)>& free_callback)
: memory_(memory), id_(id), free_callback_(free_callback) {}
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)
+bool SharedBitmap::SizeInBytes(const gfx::Size& size, size_t* size_in_bytes) {
+ if (size.IsEmpty())
return false;
- base::CheckedNumeric<int> s = size.width();
+ base::CheckedNumeric<size_t> s = 4;
+ s *= size.width();
s *= size.height();
- s *= 4;
if (!s.IsValid())
return false;
*size_in_bytes = s.ValueOrDie();
@@ -32,6 +32,34 @@ bool SharedBitmap::GetSizeInBytes(const gfx::Size& size,
}
// static
+size_t SharedBitmap::CheckedSizeInBytes(const gfx::Size& size) {
+ CHECK(!size.IsEmpty());
+ base::CheckedNumeric<size_t> s = 4;
+ s *= size.width();
+ s *= size.height();
+ return s.ValueOrDie();
+}
+
+// static
+size_t SharedBitmap::UncheckedSizeInBytes(const gfx::Size& size) {
+ DCHECK(VerifySizeInBytes(size));
+ size_t s = 4;
+ s *= size.width();
+ s *= size.height();
+ return s;
+}
+
+// static
+bool SharedBitmap::VerifySizeInBytes(const gfx::Size& size) {
+ if (size.IsEmpty())
+ return false;
+ base::CheckedNumeric<size_t> s = 4;
+ s *= size.width();
+ s *= size.height();
+ return s.IsValid();
+}
+
+// static
SharedBitmapId SharedBitmap::GenerateId() {
SharedBitmapId id;
// Needs cryptographically-secure random numbers.
« no previous file with comments | « cc/resources/shared_bitmap.h ('k') | cc/resources/texture_mailbox.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698