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

Unified Diff: cc/resources/shared_bitmap.cc

Issue 1531403002: Revert "Delete CC." (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years 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/shared_bitmap_manager.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
new file mode 100644
index 0000000000000000000000000000000000000000..1ac03233dfb94e02750573723fa1aeb325db2f8d
--- /dev/null
+++ b/cc/resources/shared_bitmap.cc
@@ -0,0 +1,69 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cc/resources/shared_bitmap.h"
+
+#include "base/logging.h"
+#include "base/numerics/safe_math.h"
+#include "base/rand_util.h"
+
+namespace cc {
+
+SharedBitmap::SharedBitmap(uint8* pixels, const SharedBitmapId& id)
+ : pixels_(pixels), id_(id) {
+}
+
+SharedBitmap::~SharedBitmap() {
+}
+
+// static
+bool SharedBitmap::SizeInBytes(const gfx::Size& size, size_t* size_in_bytes) {
+ if (size.IsEmpty())
+ return false;
+ base::CheckedNumeric<size_t> s = 4;
+ s *= size.width();
+ s *= size.height();
+ if (!s.IsValid())
+ return false;
+ *size_in_bytes = s.ValueOrDie();
+ return true;
+}
+
+// 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.
+ base::RandBytes(id.name, sizeof(id.name));
+ return id;
+}
+
+} // namespace cc
« no previous file with comments | « cc/resources/shared_bitmap.h ('k') | cc/resources/shared_bitmap_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698