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

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

Issue 307973004: Allow creating SharedBitmaps backed by new[] (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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') | content/common/host_shared_bitmap_manager.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(
14 base::SharedMemory* memory, 14 base::SharedMemory* memory,
15 const SharedBitmapId& id, 15 const SharedBitmapId& id,
16 const base::Callback<void(SharedBitmap* bitmap)>& free_callback) 16 const base::Callback<void(SharedBitmap* bitmap)>& free_callback)
17 : memory_(memory), id_(id), free_callback_(free_callback) {} 17 : memory_(memory),
18 pixels_(static_cast<uint8*>(memory_->memory())),
19 id_(id),
20 free_callback_(free_callback) {
21 }
22
23 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 SharedBitmap::~SharedBitmap() { free_callback_.Run(this); } 30 SharedBitmap::~SharedBitmap() { free_callback_.Run(this); }
20 31
21 // static 32 // static
22 bool SharedBitmap::SizeInBytes(const gfx::Size& size, size_t* size_in_bytes) { 33 bool SharedBitmap::SizeInBytes(const gfx::Size& size, size_t* size_in_bytes) {
23 if (size.IsEmpty()) 34 if (size.IsEmpty())
24 return false; 35 return false;
25 base::CheckedNumeric<size_t> s = 4; 36 base::CheckedNumeric<size_t> s = 4;
26 s *= size.width(); 37 s *= size.width();
27 s *= size.height(); 38 s *= size.height();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 72
62 // static 73 // static
63 SharedBitmapId SharedBitmap::GenerateId() { 74 SharedBitmapId SharedBitmap::GenerateId() {
64 SharedBitmapId id; 75 SharedBitmapId id;
65 // Needs cryptographically-secure random numbers. 76 // Needs cryptographically-secure random numbers.
66 base::RandBytes(id.name, sizeof(id.name)); 77 base::RandBytes(id.name, sizeof(id.name));
67 return id; 78 return id;
68 } 79 }
69 80
70 } // namespace cc 81 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/shared_bitmap.h ('k') | content/common/host_shared_bitmap_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698