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

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

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 | « no previous file | cc/resources/shared_bitmap.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 #ifndef CC_RESOURCES_SHARED_BITMAP_H_ 5 #ifndef CC_RESOURCES_SHARED_BITMAP_H_
6 #define CC_RESOURCES_SHARED_BITMAP_H_ 6 #define CC_RESOURCES_SHARED_BITMAP_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/memory/shared_memory.h" 10 #include "base/memory/shared_memory.h"
11 #include "cc/base/cc_export.h" 11 #include "cc/base/cc_export.h"
12 #include "gpu/command_buffer/common/mailbox.h" 12 #include "gpu/command_buffer/common/mailbox.h"
13 #include "ui/gfx/size.h" 13 #include "ui/gfx/size.h"
14 14
15 namespace base { class SharedMemory; } 15 namespace base { class SharedMemory; }
16 16
17 namespace cc { 17 namespace cc {
18 typedef gpu::Mailbox SharedBitmapId; 18 typedef gpu::Mailbox SharedBitmapId;
19 19
20 class CC_EXPORT SharedBitmap { 20 class CC_EXPORT SharedBitmap {
21 public: 21 public:
22 SharedBitmap(base::SharedMemory* memory, 22 SharedBitmap(base::SharedMemory* memory,
23 const SharedBitmapId& id, 23 const SharedBitmapId& id,
24 const base::Callback<void(SharedBitmap* bitmap)>& free_callback); 24 const base::Callback<void(SharedBitmap* bitmap)>& free_callback);
25 25
26 SharedBitmap(uint8* pixels,
27 const SharedBitmapId& id,
28 const base::Callback<void(SharedBitmap* bitmap)>& free_callback);
29
26 ~SharedBitmap(); 30 ~SharedBitmap();
27 31
28 bool operator<(const SharedBitmap& right) const { 32 bool operator<(const SharedBitmap& right) const {
29 if (memory_ < right.memory_) 33 if (memory_ < right.memory_)
30 return true; 34 return true;
31 if (memory_ > right.memory_) 35 if (memory_ > right.memory_)
32 return false; 36 return false;
33 return id_ < right.id_; 37 return id_ < right.id_;
34 } 38 }
35 39
36 uint8* pixels() { return static_cast<uint8*>(memory_->memory()); } 40 uint8* pixels() { return pixels_; }
37 41
38 base::SharedMemory* memory() { return memory_; } 42 base::SharedMemory* memory() { return memory_; }
39 43
40 SharedBitmapId id() { return id_; } 44 SharedBitmapId id() { return id_; }
41 45
42 // Returns true if the size is valid and false otherwise. 46 // Returns true if the size is valid and false otherwise.
43 static bool SizeInBytes(const gfx::Size& size, size_t* size_in_bytes); 47 static bool SizeInBytes(const gfx::Size& size, size_t* size_in_bytes);
44 // Dies with a CRASH() if the size can not be represented as a positive number 48 // Dies with a CRASH() if the size can not be represented as a positive number
45 // of bytes. 49 // of bytes.
46 static size_t CheckedSizeInBytes(const gfx::Size& size); 50 static size_t CheckedSizeInBytes(const gfx::Size& size);
47 // Returns the size in bytes but may overflow or return 0. Only do this for 51 // Returns the size in bytes but may overflow or return 0. Only do this for
48 // sizes that have already been checked. 52 // sizes that have already been checked.
49 static size_t UncheckedSizeInBytes(const gfx::Size& size); 53 static size_t UncheckedSizeInBytes(const gfx::Size& size);
50 // Returns true if the size is valid and false otherwise. 54 // Returns true if the size is valid and false otherwise.
51 static bool VerifySizeInBytes(const gfx::Size& size); 55 static bool VerifySizeInBytes(const gfx::Size& size);
52 56
53 static SharedBitmapId GenerateId(); 57 static SharedBitmapId GenerateId();
54 58
55 private: 59 private:
56 base::SharedMemory* memory_; 60 base::SharedMemory* memory_;
61 uint8* pixels_;
57 SharedBitmapId id_; 62 SharedBitmapId id_;
58 base::Callback<void(SharedBitmap* bitmap)> free_callback_; 63 base::Callback<void(SharedBitmap* bitmap)> free_callback_;
59 64
60 DISALLOW_COPY_AND_ASSIGN(SharedBitmap); 65 DISALLOW_COPY_AND_ASSIGN(SharedBitmap);
61 }; 66 };
62 67
63 } // namespace cc 68 } // namespace cc
64 69
65 #endif // CC_RESOURCES_SHARED_BITMAP_H_ 70 #endif // CC_RESOURCES_SHARED_BITMAP_H_
OLDNEW
« no previous file with comments | « no previous file | cc/resources/shared_bitmap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698