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

Side by Side Diff: cc/resources/shared_bitmap.cc

Issue 761903003: Update from https://crrev.com/306655 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 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 unified diff | Download patch
« no previous file with comments | « cc/resources/shared_bitmap.h ('k') | cc/resources/texture_uploader_unittest.cc » ('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/logging.h"
8 #include "base/numerics/safe_math.h" 8 #include "base/numerics/safe_math.h"
9 #include "base/rand_util.h" 9 #include "base/rand_util.h"
10 10
11 namespace cc { 11 namespace cc {
12 12
13 SharedBitmap::SharedBitmap( 13 SharedBitmap::SharedBitmap(uint8* pixels, const SharedBitmapId& id)
14 base::SharedMemory* memory, 14 : pixels_(pixels), id_(id) {
15 const SharedBitmapId& id,
16 const base::Callback<void(SharedBitmap* bitmap)>& free_callback)
17 : memory_(memory),
18 pixels_(static_cast<uint8*>(memory_->memory())),
19 id_(id),
20 free_callback_(free_callback) {
21 } 15 }
22 16
23 SharedBitmap::SharedBitmap( 17 SharedBitmap::~SharedBitmap() {
24 uint8* pixels,
25 const SharedBitmapId& id,
26 const base::Callback<void(SharedBitmap* bitmap)>& free_callback)
27 : memory_(NULL), pixels_(pixels), id_(id), free_callback_(free_callback) {
28 } 18 }
29 19
30 SharedBitmap::~SharedBitmap() { free_callback_.Run(this); }
31
32 // static 20 // static
33 bool SharedBitmap::SizeInBytes(const gfx::Size& size, size_t* size_in_bytes) { 21 bool SharedBitmap::SizeInBytes(const gfx::Size& size, size_t* size_in_bytes) {
34 if (size.IsEmpty()) 22 if (size.IsEmpty())
35 return false; 23 return false;
36 base::CheckedNumeric<size_t> s = 4; 24 base::CheckedNumeric<size_t> s = 4;
37 s *= size.width(); 25 s *= size.width();
38 s *= size.height(); 26 s *= size.height();
39 if (!s.IsValid()) 27 if (!s.IsValid())
40 return false; 28 return false;
41 *size_in_bytes = s.ValueOrDie(); 29 *size_in_bytes = s.ValueOrDie();
(...skipping 30 matching lines...) Expand all
72 60
73 // static 61 // static
74 SharedBitmapId SharedBitmap::GenerateId() { 62 SharedBitmapId SharedBitmap::GenerateId() {
75 SharedBitmapId id; 63 SharedBitmapId id;
76 // Needs cryptographically-secure random numbers. 64 // Needs cryptographically-secure random numbers.
77 base::RandBytes(id.name, sizeof(id.name)); 65 base::RandBytes(id.name, sizeof(id.name));
78 return id; 66 return id;
79 } 67 }
80 68
81 } // namespace cc 69 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/shared_bitmap.h ('k') | cc/resources/texture_uploader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698