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