OLD | NEW |
1 // Copyright 2010 The Chromium Authors. All rights reserved. | 1 // Copyright 2010 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/layers/texture_layer.h" | 5 #include "cc/layers/texture_layer.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/synchronization/lock.h" | 9 #include "base/synchronization/lock.h" |
10 #include "cc/layers/texture_layer_client.h" | 10 #include "cc/layers/texture_layer_client.h" |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 DCHECK(uses_mailbox_); | 131 DCHECK(uses_mailbox_); |
132 DCHECK(!mailbox.IsValid() || !holder_ref_ || | 132 DCHECK(!mailbox.IsValid() || !holder_ref_ || |
133 !mailbox.Equals(holder_ref_->holder()->mailbox())); | 133 !mailbox.Equals(holder_ref_->holder()->mailbox())); |
134 // If we never commited the mailbox, we need to release it here. | 134 // If we never commited the mailbox, we need to release it here. |
135 if (mailbox.IsValid()) | 135 if (mailbox.IsValid()) |
136 holder_ref_ = MailboxHolder::Create(mailbox); | 136 holder_ref_ = MailboxHolder::Create(mailbox); |
137 else | 137 else |
138 holder_ref_.reset(); | 138 holder_ref_.reset(); |
139 needs_set_mailbox_ = true; | 139 needs_set_mailbox_ = true; |
140 SetNeedsCommit(); | 140 SetNeedsCommit(); |
| 141 // The active frame needs to be replaced and the mailbox returned before the |
| 142 // commit is called complete. |
| 143 SetNextCommitWaitsForActivation(); |
141 } | 144 } |
142 | 145 |
143 void TextureLayer::WillModifyTexture() { | 146 void TextureLayer::WillModifyTexture() { |
144 if (layer_tree_host() && (DrawsContent() || content_committed_)) { | 147 if (layer_tree_host() && (DrawsContent() || content_committed_)) { |
145 layer_tree_host()->AcquireLayerTextures(); | 148 layer_tree_host()->AcquireLayerTextures(); |
146 content_committed_ = false; | 149 content_committed_ = false; |
147 } | 150 } |
148 } | 151 } |
149 | 152 |
150 void TextureLayer::SetNeedsDisplayRect(const gfx::RectF& dirty_rect) { | 153 void TextureLayer::SetNeedsDisplayRect(const gfx::RectF& dirty_rect) { |
151 Layer::SetNeedsDisplayRect(dirty_rect); | 154 Layer::SetNeedsDisplayRect(dirty_rect); |
152 | 155 |
153 if (rate_limit_context_ && client_ && layer_tree_host() && DrawsContent()) | 156 if (rate_limit_context_ && client_ && layer_tree_host() && DrawsContent()) |
154 layer_tree_host()->StartRateLimiter(client_->Context3d()); | 157 layer_tree_host()->StartRateLimiter(client_->Context3d()); |
155 } | 158 } |
156 | 159 |
157 void TextureLayer::SetLayerTreeHost(LayerTreeHost* host) { | 160 void TextureLayer::SetLayerTreeHost(LayerTreeHost* host) { |
158 if (layer_tree_host() == host) { | 161 if (layer_tree_host() == host) { |
159 Layer::SetLayerTreeHost(host); | 162 Layer::SetLayerTreeHost(host); |
160 return; | 163 return; |
161 } | 164 } |
162 | 165 |
163 if (layer_tree_host()) { | 166 if (layer_tree_host()) { |
164 if (texture_id_) | 167 if (texture_id_) { |
165 layer_tree_host()->AcquireLayerTextures(); | 168 layer_tree_host()->AcquireLayerTextures(); |
| 169 // The texture id needs to be removed from the active tree before the |
| 170 // commit is called complete. |
| 171 SetNextCommitWaitsForActivation(); |
| 172 } |
166 if (rate_limit_context_ && client_) | 173 if (rate_limit_context_ && client_) |
167 layer_tree_host()->StopRateLimiter(client_->Context3d()); | 174 layer_tree_host()->StopRateLimiter(client_->Context3d()); |
168 } | 175 } |
169 // If we're removed from the tree, the TextureLayerImpl will be destroyed, and | 176 // If we're removed from the tree, the TextureLayerImpl will be destroyed, and |
170 // we will need to set the mailbox again on a new TextureLayerImpl the next | 177 // we will need to set the mailbox again on a new TextureLayerImpl the next |
171 // time we push. | 178 // time we push. |
172 if (!host && uses_mailbox_ && holder_ref_) | 179 if (!host && uses_mailbox_ && holder_ref_) { |
173 needs_set_mailbox_ = true; | 180 needs_set_mailbox_ = true; |
| 181 // The active frame needs to be replaced and the mailbox returned before the |
| 182 // commit is called complete. |
| 183 SetNextCommitWaitsForActivation(); |
| 184 } |
174 Layer::SetLayerTreeHost(host); | 185 Layer::SetLayerTreeHost(host); |
175 } | 186 } |
176 | 187 |
177 bool TextureLayer::DrawsContent() const { | 188 bool TextureLayer::DrawsContent() const { |
178 return (client_ || texture_id_ || holder_ref_) && Layer::DrawsContent(); | 189 return (client_ || texture_id_ || holder_ref_) && Layer::DrawsContent(); |
179 } | 190 } |
180 | 191 |
181 bool TextureLayer::Update(ResourceUpdateQueue* queue, | 192 bool TextureLayer::Update(ResourceUpdateQueue* queue, |
182 const OcclusionTracker* occlusion) { | 193 const OcclusionTracker* occlusion) { |
183 bool updated = Layer::Update(queue, occlusion); | 194 bool updated = Layer::Update(queue, occlusion); |
184 if (client_) { | 195 if (client_) { |
185 if (uses_mailbox_) { | 196 if (uses_mailbox_) { |
186 TextureMailbox mailbox; | 197 TextureMailbox mailbox; |
187 if (client_->PrepareTextureMailbox( | 198 if (client_->PrepareTextureMailbox( |
188 &mailbox, layer_tree_host()->UsingSharedMemoryResources())) { | 199 &mailbox, layer_tree_host()->UsingSharedMemoryResources())) { |
189 SetTextureMailbox(mailbox); | 200 SetTextureMailbox(mailbox); |
190 updated = true; | 201 updated = true; |
191 } | 202 } |
192 } else { | 203 } else { |
193 texture_id_ = client_->PrepareTexture(); | 204 texture_id_ = client_->PrepareTexture(); |
194 DCHECK_EQ(!!texture_id_, !!client_->Context3d()); | 205 DCHECK_EQ(!!texture_id_, !!client_->Context3d()); |
195 if (client_->Context3d() && | 206 if (client_->Context3d() && |
196 client_->Context3d()->getGraphicsResetStatusARB() != GL_NO_ERROR) | 207 client_->Context3d()->getGraphicsResetStatusARB() != GL_NO_ERROR) |
197 texture_id_ = 0; | 208 texture_id_ = 0; |
198 updated = true; | 209 updated = true; |
| 210 // The texture id needs to be removed from the active tree before the |
| 211 // commit is called complete. |
| 212 SetNextCommitWaitsForActivation(); |
199 } | 213 } |
200 } | 214 } |
201 | 215 |
202 // SetTextureMailbox could be called externally and the same mailbox used for | 216 // SetTextureMailbox could be called externally and the same mailbox used for |
203 // different textures. Such callers notify this layer that the texture has | 217 // different textures. Such callers notify this layer that the texture has |
204 // changed by calling SetNeedsDisplay, so check for that here. | 218 // changed by calling SetNeedsDisplay, so check for that here. |
205 return updated || !update_rect_.IsEmpty(); | 219 return updated || !update_rect_.IsEmpty(); |
206 } | 220 } |
207 | 221 |
208 void TextureLayer::PushPropertiesTo(LayerImpl* layer) { | 222 void TextureLayer::PushPropertiesTo(LayerImpl* layer) { |
(...skipping 25 matching lines...) Expand all Loading... |
234 Region TextureLayer::VisibleContentOpaqueRegion() const { | 248 Region TextureLayer::VisibleContentOpaqueRegion() const { |
235 if (contents_opaque()) | 249 if (contents_opaque()) |
236 return visible_content_rect(); | 250 return visible_content_rect(); |
237 | 251 |
238 if (blend_background_color_ && (SkColorGetA(background_color()) == 0xFF)) | 252 if (blend_background_color_ && (SkColorGetA(background_color()) == 0xFF)) |
239 return visible_content_rect(); | 253 return visible_content_rect(); |
240 | 254 |
241 return Region(); | 255 return Region(); |
242 } | 256 } |
243 | 257 |
244 bool TextureLayer::BlocksPendingCommit() const { | |
245 // Double-buffered texture layers need to be blocked until they can be made | |
246 // triple-buffered. Single-buffered layers already prevent draws, so | |
247 // can block too for simplicity. | |
248 return DrawsContent(); | |
249 } | |
250 | |
251 bool TextureLayer::CanClipSelf() const { | 258 bool TextureLayer::CanClipSelf() const { |
252 return true; | 259 return true; |
253 } | 260 } |
254 | 261 |
255 TextureLayer::MailboxHolder::MainThreadReference::MainThreadReference( | 262 TextureLayer::MailboxHolder::MainThreadReference::MainThreadReference( |
256 MailboxHolder* holder) | 263 MailboxHolder* holder) |
257 : holder_(holder) { | 264 : holder_(holder) { |
258 holder_->InternalAddRef(); | 265 holder_->InternalAddRef(); |
259 } | 266 } |
260 | 267 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 } | 315 } |
309 | 316 |
310 void TextureLayer::MailboxHolder::ReturnAndReleaseOnImplThread( | 317 void TextureLayer::MailboxHolder::ReturnAndReleaseOnImplThread( |
311 unsigned sync_point, bool is_lost) { | 318 unsigned sync_point, bool is_lost) { |
312 Return(sync_point, is_lost); | 319 Return(sync_point, is_lost); |
313 message_loop_->PostTask(FROM_HERE, | 320 message_loop_->PostTask(FROM_HERE, |
314 base::Bind(&MailboxHolder::InternalRelease, this)); | 321 base::Bind(&MailboxHolder::InternalRelease, this)); |
315 } | 322 } |
316 | 323 |
317 } // namespace cc | 324 } // namespace cc |
OLD | NEW |