| 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 #include "cc/resources/texture_mailbox.h" | 5 #include "cc/resources/texture_mailbox.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "third_party/khronos/GLES2/gl2.h" | 8 #include "third_party/khronos/GLES2/gl2.h" |
| 9 | 9 |
| 10 namespace cc { | 10 namespace cc { |
| 11 | 11 |
| 12 TextureMailbox::TextureMailbox() | 12 TextureMailbox::TextureMailbox() : shared_memory_(NULL) {} |
| 13 : target_(GL_TEXTURE_2D), | |
| 14 sync_point_(0), | |
| 15 shared_memory_(NULL) { | |
| 16 } | |
| 17 | 13 |
| 18 TextureMailbox::TextureMailbox(const std::string& mailbox_name) | 14 TextureMailbox::TextureMailbox(const gpu::MailboxHolder& mailbox_holder) |
| 19 : target_(GL_TEXTURE_2D), | 15 : mailbox_holder_(mailbox_holder), shared_memory_(NULL) {} |
| 20 sync_point_(0), | |
| 21 shared_memory_(NULL) { | |
| 22 if (!mailbox_name.empty()) { | |
| 23 CHECK(mailbox_name.size() == sizeof(name_.name)); | |
| 24 name_.SetName(reinterpret_cast<const int8*>(mailbox_name.data())); | |
| 25 } | |
| 26 } | |
| 27 | 16 |
| 28 TextureMailbox::TextureMailbox(const gpu::Mailbox& mailbox_name) | 17 TextureMailbox::TextureMailbox(const gpu::Mailbox& mailbox, |
| 29 : target_(GL_TEXTURE_2D), | 18 uint32 target, |
| 30 sync_point_(0), | 19 uint32 sync_point) |
| 31 shared_memory_(NULL) { | 20 : mailbox_holder_(mailbox, target, sync_point), shared_memory_(NULL) {} |
| 32 name_.SetName(mailbox_name.name); | |
| 33 } | |
| 34 | |
| 35 TextureMailbox::TextureMailbox(const gpu::Mailbox& mailbox_name, | |
| 36 unsigned sync_point) | |
| 37 : target_(GL_TEXTURE_2D), | |
| 38 sync_point_(sync_point), | |
| 39 shared_memory_(NULL) { | |
| 40 name_.SetName(mailbox_name.name); | |
| 41 } | |
| 42 | |
| 43 TextureMailbox::TextureMailbox(const gpu::Mailbox& mailbox_name, | |
| 44 unsigned texture_target, | |
| 45 unsigned sync_point) | |
| 46 : target_(texture_target), | |
| 47 sync_point_(sync_point), | |
| 48 shared_memory_(NULL) { | |
| 49 name_.SetName(mailbox_name.name); | |
| 50 } | |
| 51 | 21 |
| 52 TextureMailbox::TextureMailbox(base::SharedMemory* shared_memory, | 22 TextureMailbox::TextureMailbox(base::SharedMemory* shared_memory, |
| 53 gfx::Size size) | 23 gfx::Size size) |
| 54 : target_(GL_TEXTURE_2D), | 24 : shared_memory_(shared_memory), shared_memory_size_(size) {} |
| 55 sync_point_(0), | |
| 56 shared_memory_(shared_memory), | |
| 57 shared_memory_size_(size) {} | |
| 58 | 25 |
| 59 TextureMailbox::~TextureMailbox() {} | 26 TextureMailbox::~TextureMailbox() {} |
| 60 | 27 |
| 61 bool TextureMailbox::Equals(const TextureMailbox& other) const { | 28 bool TextureMailbox::Equals(const TextureMailbox& other) const { |
| 62 if (other.IsTexture()) | 29 if (other.IsTexture()) { |
| 63 return ContainsMailbox(other.name()); | 30 return IsTexture() && !memcmp(mailbox_holder_.mailbox.name, |
| 64 else if (other.IsSharedMemory()) | 31 other.mailbox_holder_.mailbox.name, |
| 65 return ContainsHandle(other.shared_memory_->handle()); | 32 sizeof(mailbox_holder_.mailbox.name)); |
| 33 } else if (other.IsSharedMemory()) { |
| 34 return IsSharedMemory() && |
| 35 shared_memory_->handle() == other.shared_memory_->handle(); |
| 36 } |
| 66 | 37 |
| 67 DCHECK(!other.IsValid()); | 38 DCHECK(!other.IsValid()); |
| 68 return !IsValid(); | 39 return !IsValid(); |
| 69 } | 40 } |
| 70 | 41 |
| 71 bool TextureMailbox::ContainsMailbox(const gpu::Mailbox& other) const { | |
| 72 return IsTexture() && !memcmp(data(), other.name, sizeof(name_.name)); | |
| 73 } | |
| 74 | |
| 75 bool TextureMailbox::ContainsHandle(base::SharedMemoryHandle handle) const { | |
| 76 return shared_memory_ && shared_memory_->handle() == handle; | |
| 77 } | |
| 78 | |
| 79 void TextureMailbox::SetName(const gpu::Mailbox& name) { | |
| 80 DCHECK(shared_memory_ == NULL); | |
| 81 name_ = name; | |
| 82 } | |
| 83 | |
| 84 size_t TextureMailbox::shared_memory_size_in_bytes() const { | 42 size_t TextureMailbox::shared_memory_size_in_bytes() const { |
| 85 return 4 * shared_memory_size_.GetArea(); | 43 return 4 * shared_memory_size_.GetArea(); |
| 86 } | 44 } |
| 87 | 45 |
| 88 } // namespace cc | 46 } // namespace cc |
| OLD | NEW |