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_TEXTURE_MAILBOX_H_ | 5 #ifndef CC_RESOURCES_TEXTURE_MAILBOX_H_ |
6 #define CC_RESOURCES_TEXTURE_MAILBOX_H_ | 6 #define CC_RESOURCES_TEXTURE_MAILBOX_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/memory/shared_memory.h" | 11 #include "base/memory/shared_memory.h" |
12 #include "cc/base/cc_export.h" | 12 #include "cc/base/cc_export.h" |
13 #include "gpu/command_buffer/common/mailbox.h" | 13 #include "gpu/command_buffer/common/mailbox.h" |
| 14 #include "third_party/skia/include/core/SkBitmap.h" |
14 #include "ui/gfx/size.h" | 15 #include "ui/gfx/size.h" |
15 | 16 |
16 namespace cc { | 17 namespace cc { |
17 | 18 |
18 // TODO(skaslev, danakj) Rename this class more apropriately since now it | 19 // TODO(skaslev, danakj) Rename this class more apropriately since now it |
19 // can hold a shared memory resource as well as a texture mailbox. | 20 // can hold a shared memory resource as well as a texture mailbox. |
20 class CC_EXPORT TextureMailbox { | 21 class CC_EXPORT TextureMailbox { |
21 public: | 22 public: |
22 typedef base::Callback<void(unsigned sync_point, | 23 typedef base::Callback<void(unsigned sync_point, |
23 bool lost_resource)> ReleaseCallback; | 24 bool lost_resource)> ReleaseCallback; |
24 TextureMailbox(); | 25 TextureMailbox(); |
25 TextureMailbox(const std::string& mailbox_name, | 26 TextureMailbox(const std::string& mailbox_name, |
26 const ReleaseCallback& callback); | 27 const ReleaseCallback& callback); |
27 TextureMailbox(const gpu::Mailbox& mailbox_name, | 28 TextureMailbox(const gpu::Mailbox& mailbox_name, |
28 const ReleaseCallback& callback); | 29 const ReleaseCallback& callback); |
29 TextureMailbox(const gpu::Mailbox& mailbox_name, | 30 TextureMailbox(const gpu::Mailbox& mailbox_name, |
30 const ReleaseCallback& callback, | 31 const ReleaseCallback& callback, |
31 unsigned sync_point); | 32 unsigned sync_point); |
32 TextureMailbox(const gpu::Mailbox& mailbox_name, | 33 TextureMailbox(const gpu::Mailbox& mailbox_name, |
33 const ReleaseCallback& callback, | 34 const ReleaseCallback& callback, |
34 unsigned texture_target, | 35 unsigned texture_target, |
35 unsigned sync_point); | 36 unsigned sync_point); |
36 TextureMailbox(base::SharedMemory* shared_memory, | 37 TextureMailbox(base::SharedMemory* shared_memory, |
37 gfx::Size size, | 38 gfx::Size size, |
38 const ReleaseCallback& callback); | 39 const ReleaseCallback& callback); |
| 40 TextureMailbox(SkBitmap bitmap, |
| 41 gfx::Size size, |
| 42 const ReleaseCallback& callback); |
39 | 43 |
40 ~TextureMailbox(); | 44 ~TextureMailbox(); |
41 | 45 |
42 bool IsValid() const { return IsTexture() || IsSharedMemory(); } | 46 bool IsValid() const { return IsTexture() || IsSharedMemory() || IsBitmap(); } |
43 bool IsTexture() const { return !name_.IsZero(); } | 47 bool IsTexture() const { return !name_.IsZero(); } |
44 bool IsSharedMemory() const { return shared_memory_ != NULL; } | 48 bool IsSharedMemory() const { return shared_memory_ != NULL; } |
| 49 bool IsBitmap() const { return !bitmap_.isNull(); } |
45 | 50 |
46 bool Equals(const TextureMailbox&) const; | 51 bool Equals(const TextureMailbox&) const; |
47 bool ContainsMailbox(const gpu::Mailbox&) const; | 52 bool ContainsMailbox(const gpu::Mailbox&) const; |
48 bool ContainsHandle(base::SharedMemoryHandle handle) const; | 53 bool ContainsHandle(base::SharedMemoryHandle handle) const; |
49 | 54 |
50 const ReleaseCallback& callback() const { return callback_; } | 55 const ReleaseCallback& callback() const { return callback_; } |
51 const int8* data() const { return name_.name; } | 56 const int8* data() const { return name_.name; } |
52 const gpu::Mailbox& name() const { return name_; } | 57 const gpu::Mailbox& name() const { return name_; } |
53 void ResetSyncPoint() { sync_point_ = 0; } | 58 void ResetSyncPoint() { sync_point_ = 0; } |
54 void RunReleaseCallback(unsigned sync_point, bool lost_resource) const; | 59 void RunReleaseCallback(unsigned sync_point, bool lost_resource) const; |
55 void SetName(const gpu::Mailbox&); | 60 void SetName(const gpu::Mailbox&); |
56 unsigned target() const { return target_; } | 61 unsigned target() const { return target_; } |
57 unsigned sync_point() const { return sync_point_; } | 62 unsigned sync_point() const { return sync_point_; } |
58 | 63 |
59 base::SharedMemory* shared_memory() const { return shared_memory_; } | 64 base::SharedMemory* shared_memory() const { return shared_memory_; } |
60 gfx::Size shared_memory_size() const { return shared_memory_size_; } | 65 gfx::Size shared_memory_size() const { return shared_memory_size_; } |
61 size_t shared_memory_size_in_bytes() const; | 66 size_t shared_memory_size_in_bytes() const; |
| 67 const SkBitmap& bitmap() const { return bitmap_; } |
62 | 68 |
63 TextureMailbox CopyWithNewCallback(const ReleaseCallback& callback) const; | 69 TextureMailbox CopyWithNewCallback(const ReleaseCallback& callback) const; |
64 | 70 |
65 private: | 71 private: |
66 gpu::Mailbox name_; | 72 gpu::Mailbox name_; |
67 ReleaseCallback callback_; | 73 ReleaseCallback callback_; |
68 unsigned target_; | 74 unsigned target_; |
69 unsigned sync_point_; | 75 unsigned sync_point_; |
70 base::SharedMemory* shared_memory_; | 76 base::SharedMemory* shared_memory_; |
71 gfx::Size shared_memory_size_; | 77 gfx::Size shared_memory_size_; |
| 78 SkBitmap bitmap_; |
72 }; | 79 }; |
73 | 80 |
74 } // namespace cc | 81 } // namespace cc |
75 | 82 |
76 #endif // CC_RESOURCES_TEXTURE_MAILBOX_H_ | 83 #endif // CC_RESOURCES_TEXTURE_MAILBOX_H_ |
OLD | NEW |