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