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

Side by Side 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, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/resources/shared_bitmap.h" 5 #include "cc/resources/shared_bitmap.h"
6 6
7 #include "base/logging.h"
7 #include "base/numerics/safe_math.h" 8 #include "base/numerics/safe_math.h"
8 #include "base/rand_util.h" 9 #include "base/rand_util.h"
9 10
10 namespace cc { 11 namespace cc {
11 12
12 SharedBitmap::SharedBitmap( 13 SharedBitmap::SharedBitmap(
13 base::SharedMemory* memory, 14 base::SharedMemory* memory,
14 const SharedBitmapId& id, 15 const SharedBitmapId& id,
15 const base::Callback<void(SharedBitmap*)>& free_callback) 16 const base::Callback<void(SharedBitmap* bitmap)>& free_callback)
16 : memory_(memory), id_(id), free_callback_(free_callback) {} 17 : memory_(memory), id_(id), free_callback_(free_callback) {}
17 18
18 SharedBitmap::~SharedBitmap() { free_callback_.Run(this); } 19 SharedBitmap::~SharedBitmap() { free_callback_.Run(this); }
19 20
20 // static 21 // static
21 bool SharedBitmap::GetSizeInBytes(const gfx::Size& size, 22 bool SharedBitmap::SizeInBytes(const gfx::Size& size, size_t* size_in_bytes) {
22 size_t* size_in_bytes) { 23 base::CheckedNumeric<size_t> s = 4;
23 if (size.width() <= 0 || size.height() <= 0) 24 s *= size.width();
24 return false;
25 base::CheckedNumeric<int> s = size.width();
26 s *= size.height(); 25 s *= size.height();
27 s *= 4;
28 if (!s.IsValid()) 26 if (!s.IsValid())
29 return false; 27 return false;
30 *size_in_bytes = s.ValueOrDie(); 28 *size_in_bytes = s.ValueOrDie();
31 return true; 29 return true;
32 } 30 }
33 31
34 // static 32 // static
33 size_t SharedBitmap::CheckedSizeInBytes(const gfx::Size& size) {
34 base::CheckedNumeric<size_t> s = 4;
35 s *= size.width();
jbauman 2014/04/03 21:47:17 How does CheckedNumeric deal with multiplication w
danakj 2014/04/03 21:48:46 gfx::Size clamps it's values >= 0. https://code.g
36 s *= size.height();
37 return s.ValueOrDie();
38 }
39
40 // static
41 size_t SharedBitmap::UncheckedSizeInBytes(const gfx::Size& size) {
42 DCHECK(VerifySizeInBytes(size));
43 size_t s = 4;
44 s *= size.width();
45 s *= size.height();
46 return s;
47 }
48
49 // static
50 bool SharedBitmap::VerifySizeInBytes(const gfx::Size& size) {
51 base::CheckedNumeric<size_t> s = 4;
52 s *= size.width();
53 s *= size.height();
54 return s.IsValid();
55 }
56
57 // static
35 SharedBitmapId SharedBitmap::GenerateId() { 58 SharedBitmapId SharedBitmap::GenerateId() {
36 SharedBitmapId id; 59 SharedBitmapId id;
37 // Needs cryptographically-secure random numbers. 60 // Needs cryptographically-secure random numbers.
38 base::RandBytes(id.name, sizeof(id.name)); 61 base::RandBytes(id.name, sizeof(id.name));
39 return id; 62 return id;
40 } 63 }
41 64
42 } // namespace cc 65 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698