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 : target_(GL_TEXTURE_2D), | 13 : target_(GL_TEXTURE_2D), |
14 sync_point_(0) { | 14 sync_point_(0), |
15 handle_(base::SharedMemory::NULLHandle()) { | |
15 } | 16 } |
16 | 17 |
17 TextureMailbox::TextureMailbox( | 18 TextureMailbox::TextureMailbox( |
18 const std::string& mailbox_name, | 19 const std::string& mailbox_name, |
19 const ReleaseCallback& mailbox_callback) | 20 const ReleaseCallback& callback) |
20 : callback_(mailbox_callback), | 21 : callback_(callback), |
21 target_(GL_TEXTURE_2D), | 22 target_(GL_TEXTURE_2D), |
22 sync_point_(0) { | 23 sync_point_(0), |
23 DCHECK(mailbox_name.empty() == mailbox_callback.is_null()); | 24 handle_(base::SharedMemory::NULLHandle()) { |
25 DCHECK(mailbox_name.empty() == callback.is_null()); | |
24 if (!mailbox_name.empty()) { | 26 if (!mailbox_name.empty()) { |
25 CHECK(mailbox_name.size() == sizeof(name_.name)); | 27 CHECK(mailbox_name.size() == sizeof(name_.name)); |
26 name_.SetName(reinterpret_cast<const int8*>(mailbox_name.data())); | 28 name_.SetName(reinterpret_cast<const int8*>(mailbox_name.data())); |
27 } | 29 } |
28 } | 30 } |
29 | 31 |
30 TextureMailbox::TextureMailbox( | 32 TextureMailbox::TextureMailbox( |
31 const gpu::Mailbox& mailbox_name, | 33 const gpu::Mailbox& mailbox_name, |
32 const ReleaseCallback& mailbox_callback) | 34 const ReleaseCallback& callback) |
33 : callback_(mailbox_callback), | 35 : callback_(callback), |
34 target_(GL_TEXTURE_2D), | 36 target_(GL_TEXTURE_2D), |
35 sync_point_(0) { | 37 sync_point_(0), |
36 DCHECK(mailbox_name.IsZero() == mailbox_callback.is_null()); | 38 handle_(base::SharedMemory::NULLHandle()) { |
39 DCHECK(mailbox_name.IsZero() == callback.is_null()); | |
37 name_.SetName(mailbox_name.name); | 40 name_.SetName(mailbox_name.name); |
38 } | 41 } |
39 | 42 |
40 TextureMailbox::TextureMailbox( | 43 TextureMailbox::TextureMailbox( |
41 const gpu::Mailbox& mailbox_name, | 44 const gpu::Mailbox& mailbox_name, |
42 const ReleaseCallback& mailbox_callback, | 45 const ReleaseCallback& callback, |
43 unsigned sync_point) | 46 unsigned sync_point) |
44 : callback_(mailbox_callback), | 47 : callback_(callback), |
45 target_(GL_TEXTURE_2D), | 48 target_(GL_TEXTURE_2D), |
46 sync_point_(sync_point) { | 49 sync_point_(sync_point), |
47 DCHECK(mailbox_name.IsZero() == mailbox_callback.is_null()); | 50 handle_(base::SharedMemory::NULLHandle()) { |
51 DCHECK(mailbox_name.IsZero() == callback.is_null()); | |
48 name_.SetName(mailbox_name.name); | 52 name_.SetName(mailbox_name.name); |
49 } | 53 } |
50 | 54 |
51 TextureMailbox::TextureMailbox( | 55 TextureMailbox::TextureMailbox( |
52 const gpu::Mailbox& mailbox_name, | 56 const gpu::Mailbox& mailbox_name, |
53 const ReleaseCallback& mailbox_callback, | 57 const ReleaseCallback& callback, |
54 unsigned texture_target, | 58 unsigned texture_target, |
55 unsigned sync_point) | 59 unsigned sync_point) |
56 : callback_(mailbox_callback), | 60 : callback_(callback), |
57 target_(texture_target), | 61 target_(texture_target), |
58 sync_point_(sync_point) { | 62 sync_point_(sync_point), |
59 DCHECK(mailbox_name.IsZero() == mailbox_callback.is_null()); | 63 handle_(base::SharedMemory::NULLHandle()) { |
64 DCHECK(mailbox_name.IsZero() == callback.is_null()); | |
60 name_.SetName(mailbox_name.name); | 65 name_.SetName(mailbox_name.name); |
61 } | 66 } |
62 | 67 |
68 TextureMailbox::TextureMailbox( | |
69 base::SharedMemoryHandle handle, | |
70 gfx::Size size, | |
71 const ReleaseCallback& callback) | |
72 : callback_(callback), | |
73 target_(GL_TEXTURE_2D), | |
74 sync_point_(0), | |
75 handle_(handle), | |
76 shared_memory_size_(size) { | |
77 } | |
78 | |
63 TextureMailbox::~TextureMailbox() { | 79 TextureMailbox::~TextureMailbox() { |
64 } | 80 } |
65 | 81 |
66 bool TextureMailbox::Equals(const gpu::Mailbox& other) const { | 82 bool TextureMailbox::Equals(const TextureMailbox& other) const { |
67 return !memcmp(data(), other.name, sizeof(name_.name)); | 83 if (other.IsTexture()) |
84 return ContainsMailbox(other.name()); | |
85 else if (other.IsSharedMemory()) | |
86 return ContainsHandle(other.handle()); | |
87 | |
88 DCHECK(!other.IsValid()); | |
89 return !IsValid(); | |
68 } | 90 } |
69 | 91 |
70 bool TextureMailbox::Equals(const TextureMailbox& other) const { | 92 bool TextureMailbox::ContainsMailbox(const gpu::Mailbox& other) const { |
71 return Equals(other.name()); | 93 return IsTexture() && !memcmp(data(), other.name, sizeof(name_.name)); |
72 } | 94 } |
73 | 95 |
74 bool TextureMailbox::IsEmpty() const { | 96 bool TextureMailbox::ContainsHandle(base::SharedMemoryHandle handle) const { |
75 return name_.IsZero(); | 97 return IsSharedMemory() && handle_ == handle; |
76 } | 98 } |
77 | 99 |
78 void TextureMailbox::RunReleaseCallback(unsigned sync_point, | 100 void TextureMailbox::RunReleaseCallback(unsigned sync_point, |
79 bool lost_resource) const { | 101 bool lost_resource) const { |
80 if (!callback_.is_null()) | 102 if (!callback_.is_null()) |
81 callback_.Run(sync_point, lost_resource); | 103 callback_.Run(sync_point, lost_resource); |
82 } | 104 } |
83 | 105 |
84 void TextureMailbox::SetName(const gpu::Mailbox& other) { | 106 void TextureMailbox::SetName(const gpu::Mailbox& other) { |
107 DCHECK(!base::SharedMemory::IsHandleValid(handle_)); | |
85 name_.SetName(other.name); | 108 name_.SetName(other.name); |
86 } | 109 } |
87 | 110 |
111 void TextureMailbox::SetHandle(base::SharedMemoryHandle handle, | |
112 gfx::Size size) { | |
113 DCHECK(name_.IsZero()); | |
114 handle_ = handle; | |
115 shared_memory_size_ = size; | |
116 } | |
117 | |
118 TextureMailbox TextureMailbox::CopyWithNewCallback( | |
119 const ReleaseCallback& callback) const { | |
120 if (IsTexture()) | |
121 return TextureMailbox(name(), callback, sync_point()); | |
122 else if (IsSharedMemory()) | |
123 return TextureMailbox(handle(), shared_memory_size(), callback); | |
124 | |
125 DCHECK(!IsValid()); | |
126 return TextureMailbox(); | |
piman
2013/05/29 20:00:10
How about:
TextureMailbox copy(*this);
copy.callba
slavi
2013/06/03 22:14:16
Done.
| |
127 } | |
128 | |
88 } // namespace cc | 129 } // namespace cc |
OLD | NEW |