| 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 "ui/gfx/size.h" | 14 #include "ui/gfx/size.h" |
| 15 | 15 |
| 16 namespace cc { | 16 namespace cc { |
| 17 | 17 |
| 18 // TODO(skaslev, danakj) Rename this class more apropriately since now it | 18 // TODO(skaslev, danakj) Rename this class more apropriately since now it |
| 19 // can hold a shared memory resource as well as a texture mailbox. | 19 // can hold a shared memory resource as well as a texture mailbox. |
| 20 class CC_EXPORT TextureMailbox { | 20 class CC_EXPORT TextureMailbox { |
| 21 public: | 21 public: |
| 22 typedef base::Callback<void(unsigned sync_point, | |
| 23 bool lost_resource)> ReleaseCallback; | |
| 24 TextureMailbox(); | 22 TextureMailbox(); |
| 25 TextureMailbox(const std::string& mailbox_name, | 23 explicit TextureMailbox(const std::string& mailbox_name); |
| 26 const ReleaseCallback& callback); | 24 explicit TextureMailbox(const gpu::Mailbox& mailbox_name); |
| 27 TextureMailbox(const gpu::Mailbox& mailbox_name, | 25 TextureMailbox(const gpu::Mailbox& mailbox_name, |
| 28 const ReleaseCallback& callback); | |
| 29 TextureMailbox(const gpu::Mailbox& mailbox_name, | |
| 30 const ReleaseCallback& callback, | |
| 31 unsigned sync_point); | 26 unsigned sync_point); |
| 32 TextureMailbox(const gpu::Mailbox& mailbox_name, | 27 TextureMailbox(const gpu::Mailbox& mailbox_name, |
| 33 const ReleaseCallback& callback, | |
| 34 unsigned texture_target, | 28 unsigned texture_target, |
| 35 unsigned sync_point); | 29 unsigned sync_point); |
| 36 TextureMailbox(base::SharedMemory* shared_memory, | 30 TextureMailbox(base::SharedMemory* shared_memory, |
| 37 gfx::Size size, | 31 gfx::Size size); |
| 38 const ReleaseCallback& callback); | |
| 39 | 32 |
| 40 ~TextureMailbox(); | 33 ~TextureMailbox(); |
| 41 | 34 |
| 42 bool IsValid() const { return IsTexture() || IsSharedMemory(); } | 35 bool IsValid() const { return IsTexture() || IsSharedMemory(); } |
| 43 bool IsTexture() const { return !name_.IsZero(); } | 36 bool IsTexture() const { return !name_.IsZero(); } |
| 44 bool IsSharedMemory() const { return shared_memory_ != NULL; } | 37 bool IsSharedMemory() const { return shared_memory_ != NULL; } |
| 45 | 38 |
| 46 bool Equals(const TextureMailbox&) const; | 39 bool Equals(const TextureMailbox&) const; |
| 47 bool ContainsMailbox(const gpu::Mailbox&) const; | 40 bool ContainsMailbox(const gpu::Mailbox&) const; |
| 48 bool ContainsHandle(base::SharedMemoryHandle handle) const; | 41 bool ContainsHandle(base::SharedMemoryHandle handle) const; |
| 49 | 42 |
| 50 const int8* data() const { return name_.name; } | 43 const int8* data() const { return name_.name; } |
| 51 const gpu::Mailbox& name() const { return name_; } | 44 const gpu::Mailbox& name() const { return name_; } |
| 52 void ResetSyncPoint() { sync_point_ = 0; } | 45 void ResetSyncPoint() { sync_point_ = 0; } |
| 53 unsigned target() const { return target_; } | 46 unsigned target() const { return target_; } |
| 54 unsigned sync_point() const { return sync_point_; } | 47 unsigned sync_point() const { return sync_point_; } |
| 55 | 48 |
| 56 base::SharedMemory* shared_memory() const { return shared_memory_; } | 49 base::SharedMemory* shared_memory() const { return shared_memory_; } |
| 57 gfx::Size shared_memory_size() const { return shared_memory_size_; } | 50 gfx::Size shared_memory_size() const { return shared_memory_size_; } |
| 58 size_t shared_memory_size_in_bytes() const; | 51 size_t shared_memory_size_in_bytes() const; |
| 59 | 52 |
| 60 // TODO(danakj): ReleaseCallback should be separate from this class, and stop | 53 // TODO(danakj): ReleaseCallback should be separate from this class, and stop |
| 61 // storing a TextureMailbox in ResourceProvider. Then we can remove this. | 54 // storing a TextureMailbox in ResourceProvider. Then we can remove this. |
| 62 void SetName(const gpu::Mailbox& name); | 55 void SetName(const gpu::Mailbox& name); |
| 63 | 56 |
| 64 // TODO(danakj): ReleaseCallback should be a separate scoped_ptr outside this | |
| 65 // class to avoid silently adding references to the callback's internals. | |
| 66 void RunReleaseCallback(unsigned sync_point, bool lost_resource); | |
| 67 | |
| 68 TextureMailbox CopyWithNewCallback(const ReleaseCallback& callback) const; | |
| 69 const ReleaseCallback& callback() const { return callback_; } | |
| 70 | |
| 71 private: | 57 private: |
| 72 gpu::Mailbox name_; | 58 gpu::Mailbox name_; |
| 73 ReleaseCallback callback_; | |
| 74 unsigned target_; | 59 unsigned target_; |
| 75 unsigned sync_point_; | 60 unsigned sync_point_; |
| 76 base::SharedMemory* shared_memory_; | 61 base::SharedMemory* shared_memory_; |
| 77 gfx::Size shared_memory_size_; | 62 gfx::Size shared_memory_size_; |
| 78 }; | 63 }; |
| 79 | 64 |
| 80 } // namespace cc | 65 } // namespace cc |
| 81 | 66 |
| 82 #endif // CC_RESOURCES_TEXTURE_MAILBOX_H_ | 67 #endif // CC_RESOURCES_TEXTURE_MAILBOX_H_ |
| OLD | NEW |