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 3 // found in the LICENSE file. 4 5 #ifndef CC_RESOURCES_TEXTURE_MAILBOX_H_ 6 #define CC_RESOURCES_TEXTURE_MAILBOX_H_ 7 8 #include <string> 9 10 #include "base/callback.h" 11 #include "base/memory/shared_memory.h" 12 #include "cc/base/cc_export.h" 13 #include "gpu/command_buffer/common/mailbox.h" 14 #include "ui/gfx/size.h" 15 16 namespace cc { 17 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. 20 class CC_EXPORT TextureMailbox { 21 public: 22 typedef base::Callback<void(unsigned sync_point, 23 bool lost_resource)> ReleaseCallback; 24 TextureMailbox(); 25 TextureMailbox(const std::string& mailbox_name, 26 const ReleaseCallback& callback); 27 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); 32 TextureMailbox(const gpu::Mailbox& mailbox_name, 33 const ReleaseCallback& callback, 34 unsigned texture_target, 35 unsigned sync_point); 36 TextureMailbox(base::SharedMemory* shared_memory, 37 gfx::Size size, 38 const ReleaseCallback& callback); 39 40 ~TextureMailbox(); 41 42 bool IsValid() const { return IsTexture() || IsSharedMemory(); } 43 bool IsTexture() const { return !name_.IsZero(); } 44 bool IsSharedMemory() const { return shared_memory_ != NULL; } 45 46 bool Equals(const TextureMailbox&) const; 47 bool ContainsMailbox(const gpu::Mailbox&) const; 48 bool ContainsHandle(base::SharedMemoryHandle handle) const; 49 50 const ReleaseCallback& callback() const { return callback_; } 51 const int8* data() const { return name_.name; } 52 const gpu::Mailbox& name() const { return name_; } 53 void ResetSyncPoint() { sync_point_ = 0; } 54 void RunReleaseCallback(unsigned sync_point, bool lost_resource) const; 55 void SetName(const gpu::Mailbox&); 56 unsigned target() const { return target_; } 57 unsigned sync_point() const { return sync_point_; } 58 59 base::SharedMemory* shared_memory() const { return shared_memory_; } 60 gfx::Size shared_memory_size() const { return shared_memory_size_; } 61 size_t shared_memory_size_in_bytes() const; 62 63 TextureMailbox CopyWithNewCallback(const ReleaseCallback& callback) const; 64 65 private: 66 gpu::Mailbox name_; 67 ReleaseCallback callback_; 68 unsigned target_; 69 unsigned sync_point_; 70 base::SharedMemory* shared_memory_; 71 gfx::Size shared_memory_size_; 72 }; 73 74 } // namespace cc 75 76 #endif // CC_RESOURCES_TEXTURE_MAILBOX_H_ 77