Chromium Code Reviews| 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() |
| 13 : sync_point_(0) { | 13 : sync_point_(0), |
| 14 handle_(base::SharedMemory::NULLHandle()) { | |
| 14 } | 15 } |
| 15 | 16 |
| 16 TextureMailbox::TextureMailbox( | 17 TextureMailbox::TextureMailbox( |
| 17 const std::string& mailbox_name, | 18 const std::string& mailbox_name, |
| 18 const ReleaseCallback& mailbox_callback) | 19 const ReleaseCallback& callback) |
| 19 : callback_(mailbox_callback), | 20 : callback_(callback), |
| 20 target_(GL_TEXTURE_2D), | 21 target_(GL_TEXTURE_2D), |
| 21 sync_point_(0) { | 22 sync_point_(0), |
| 22 DCHECK(mailbox_name.empty() == mailbox_callback.is_null()); | 23 handle_(base::SharedMemory::NULLHandle()) { |
| 24 DCHECK(mailbox_name.empty() == callback.is_null()); | |
| 23 if (!mailbox_name.empty()) { | 25 if (!mailbox_name.empty()) { |
| 24 CHECK(mailbox_name.size() == sizeof(name_.name)); | 26 CHECK(mailbox_name.size() == sizeof(name_.name)); |
| 25 name_.SetName(reinterpret_cast<const int8*>(mailbox_name.data())); | 27 name_.SetName(reinterpret_cast<const int8*>(mailbox_name.data())); |
| 26 } | 28 } |
| 27 } | 29 } |
| 28 | 30 |
| 29 TextureMailbox::TextureMailbox( | 31 TextureMailbox::TextureMailbox( |
| 30 const gpu::Mailbox& mailbox_name, | 32 const gpu::Mailbox& mailbox_name, |
| 31 const ReleaseCallback& mailbox_callback) | 33 const ReleaseCallback& callback) |
| 32 : callback_(mailbox_callback), | 34 : callback_(callback), |
| 33 target_(GL_TEXTURE_2D), | 35 target_(GL_TEXTURE_2D), |
| 34 sync_point_(0) { | 36 sync_point_(0), |
| 35 DCHECK(mailbox_name.IsZero() == mailbox_callback.is_null()); | 37 handle_(base::SharedMemory::NULLHandle()) { |
| 38 DCHECK(mailbox_name.IsZero() == callback.is_null()); | |
| 36 name_.SetName(mailbox_name.name); | 39 name_.SetName(mailbox_name.name); |
| 37 } | 40 } |
| 38 | 41 |
| 39 TextureMailbox::TextureMailbox( | 42 TextureMailbox::TextureMailbox( |
| 40 const gpu::Mailbox& mailbox_name, | 43 const gpu::Mailbox& mailbox_name, |
| 41 const ReleaseCallback& mailbox_callback, | 44 const ReleaseCallback& callback, |
| 42 unsigned sync_point) | 45 unsigned sync_point) |
| 43 : callback_(mailbox_callback), | 46 : callback_(callback), |
| 44 target_(GL_TEXTURE_2D), | 47 target_(GL_TEXTURE_2D), |
| 45 sync_point_(sync_point) { | 48 sync_point_(sync_point), |
| 46 DCHECK(mailbox_name.IsZero() == mailbox_callback.is_null()); | 49 handle_(base::SharedMemory::NULLHandle()) { |
| 50 DCHECK(mailbox_name.IsZero() == callback.is_null()); | |
| 47 name_.SetName(mailbox_name.name); | 51 name_.SetName(mailbox_name.name); |
| 48 } | 52 } |
| 49 | 53 |
| 50 TextureMailbox::TextureMailbox( | 54 TextureMailbox::TextureMailbox( |
| 51 const gpu::Mailbox& mailbox_name, | 55 const gpu::Mailbox& mailbox_name, |
| 52 const ReleaseCallback& mailbox_callback, | 56 const ReleaseCallback& callback, |
| 53 unsigned texture_target, | 57 unsigned texture_target, |
| 54 unsigned sync_point) | 58 unsigned sync_point) |
| 55 : callback_(mailbox_callback), | 59 : callback_(callback), |
| 56 target_(texture_target), | 60 target_(texture_target), |
| 57 sync_point_(sync_point) { | 61 sync_point_(sync_point), |
| 58 DCHECK(mailbox_name.IsZero() == mailbox_callback.is_null()); | 62 handle_(base::SharedMemory::NULLHandle()) { |
| 63 DCHECK(mailbox_name.IsZero() == callback.is_null()); | |
| 59 name_.SetName(mailbox_name.name); | 64 name_.SetName(mailbox_name.name); |
| 60 } | 65 } |
| 61 | 66 |
| 67 TextureMailbox::TextureMailbox( | |
| 68 base::SharedMemoryHandle handle, | |
| 69 gfx::Size size, | |
| 70 const ReleaseCallback& callback) | |
| 71 : callback_(callback), | |
| 72 target_(GL_TEXTURE_2D), | |
| 73 sync_point_(0), | |
| 74 handle_(handle), | |
| 75 size_(size) { | |
| 76 } | |
| 77 | |
| 62 TextureMailbox::~TextureMailbox() { | 78 TextureMailbox::~TextureMailbox() { |
| 63 } | 79 } |
| 64 | 80 |
| 65 bool TextureMailbox::Equals(const gpu::Mailbox& other) const { | 81 bool TextureMailbox::Equals(const gpu::Mailbox& other) const { |
| 66 return !memcmp(data(), other.name, sizeof(name_.name)); | 82 return IsTexture() && !memcmp(data(), other.name, sizeof(name_.name)); |
| 83 } | |
| 84 | |
| 85 bool TextureMailbox::Equals(base::SharedMemoryHandle handle) const { | |
| 86 return IsSharedMemory() && handle_ == handle; | |
| 67 } | 87 } |
| 68 | 88 |
| 69 bool TextureMailbox::Equals(const TextureMailbox& other) const { | 89 bool TextureMailbox::Equals(const TextureMailbox& other) const { |
| 70 return Equals(other.name()); | 90 return Equals(other.name()) || Equals(other.handle()); |
|
danakj
2013/05/23 15:34:33
check that IsTexture() and IsSharedMemory() also m
slavi
2013/05/28 18:55:13
Done.
| |
| 71 } | |
| 72 | |
| 73 bool TextureMailbox::IsEmpty() const { | |
| 74 return name_.IsZero(); | |
| 75 } | 91 } |
| 76 | 92 |
| 77 void TextureMailbox::RunReleaseCallback(unsigned sync_point, | 93 void TextureMailbox::RunReleaseCallback(unsigned sync_point, |
| 78 bool lost_resource) const { | 94 bool lost_resource) const { |
| 79 if (!callback_.is_null()) | 95 if (!callback_.is_null()) |
| 80 callback_.Run(sync_point, lost_resource); | 96 callback_.Run(sync_point, lost_resource); |
| 81 } | 97 } |
| 82 | 98 |
| 83 void TextureMailbox::SetName(const gpu::Mailbox& other) { | 99 void TextureMailbox::SetName(const gpu::Mailbox& other) { |
| 84 name_.SetName(other.name); | 100 name_.SetName(other.name); |
| 101 handle_ = base::SharedMemory::NULLHandle(); | |
| 102 } | |
| 103 | |
| 104 void TextureMailbox::SetHandle(base::SharedMemoryHandle handle, | |
| 105 gfx::Size size) { | |
| 106 name_.SetZero(); | |
| 107 handle_ = handle; | |
| 108 size_ = size; | |
| 85 } | 109 } |
| 86 | 110 |
| 87 } // namespace cc | 111 } // namespace cc |
| OLD | NEW |