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

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
« no previous file with comments | « cc/resources/shared_bitmap.h ('k') | cc/resources/texture_mailbox.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 if (size.IsEmpty())
23 if (size.width() <= 0 || size.height() <= 0)
24 return false; 24 return false;
25 base::CheckedNumeric<int> s = size.width(); 25 base::CheckedNumeric<size_t> s = 4;
26 s *= size.width();
26 s *= size.height(); 27 s *= size.height();
27 s *= 4;
28 if (!s.IsValid()) 28 if (!s.IsValid())
29 return false; 29 return false;
30 *size_in_bytes = s.ValueOrDie(); 30 *size_in_bytes = s.ValueOrDie();
31 return true; 31 return true;
32 } 32 }
33 33
34 // static 34 // static
35 size_t SharedBitmap::CheckedSizeInBytes(const gfx::Size& size) {
36 CHECK(!size.IsEmpty());
37 base::CheckedNumeric<size_t> s = 4;
38 s *= size.width();
39 s *= size.height();
40 return s.ValueOrDie();
41 }
42
43 // static
44 size_t SharedBitmap::UncheckedSizeInBytes(const gfx::Size& size) {
45 DCHECK(VerifySizeInBytes(size));
46 size_t s = 4;
47 s *= size.width();
48 s *= size.height();
49 return s;
50 }
51
52 // static
53 bool SharedBitmap::VerifySizeInBytes(const gfx::Size& size) {
54 if (size.IsEmpty())
55 return false;
56 base::CheckedNumeric<size_t> s = 4;
57 s *= size.width();
58 s *= size.height();
59 return s.IsValid();
60 }
61
62 // static
35 SharedBitmapId SharedBitmap::GenerateId() { 63 SharedBitmapId SharedBitmap::GenerateId() {
36 SharedBitmapId id; 64 SharedBitmapId id;
37 // Needs cryptographically-secure random numbers. 65 // Needs cryptographically-secure random numbers.
38 base::RandBytes(id.name, sizeof(id.name)); 66 base::RandBytes(id.name, sizeof(id.name));
39 return id; 67 return id;
40 } 68 }
41 69
42 } // namespace cc 70 } // namespace cc
OLDNEW
« 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