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/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 void TextureLayer::SetTextureMailboxInternal( | 135 void TextureLayer::SetTextureMailboxInternal( |
136 const TextureMailbox& mailbox, | 136 const TextureMailbox& mailbox, |
137 scoped_ptr<SingleReleaseCallback> release_callback, | 137 scoped_ptr<SingleReleaseCallback> release_callback, |
138 bool requires_commit) { | 138 bool requires_commit) { |
139 DCHECK(uses_mailbox_); | 139 DCHECK(uses_mailbox_); |
140 DCHECK(!mailbox.IsValid() || !holder_ref_ || | 140 DCHECK(!mailbox.IsValid() || !holder_ref_ || |
141 !mailbox.Equals(holder_ref_->holder()->mailbox())); | 141 !mailbox.Equals(holder_ref_->holder()->mailbox())); |
142 DCHECK_EQ(mailbox.IsValid(), !!release_callback); | 142 DCHECK_EQ(mailbox.IsValid(), !!release_callback); |
143 | 143 |
144 // If we never commited the mailbox, we need to release it here. | 144 // If we never commited the mailbox, we need to release it here. |
145 if (mailbox.IsValid()) | 145 if (mailbox.IsValid()) { |
146 holder_ref_ = MailboxHolder::Create(mailbox, release_callback.Pass()); | 146 holder_ref_ = |
147 else | 147 TextureMailboxHolder::Create(mailbox, release_callback.Pass()); |
| 148 } else { |
148 holder_ref_.reset(); | 149 holder_ref_.reset(); |
| 150 } |
149 needs_set_mailbox_ = true; | 151 needs_set_mailbox_ = true; |
150 // If we are within a commit, no need to do it again immediately after. | 152 // If we are within a commit, no need to do it again immediately after. |
151 if (requires_commit) | 153 if (requires_commit) |
152 SetNeedsCommit(); | 154 SetNeedsCommit(); |
153 else | 155 else |
154 SetNeedsPushProperties(); | 156 SetNeedsPushProperties(); |
155 | 157 |
156 // The active frame needs to be replaced and the mailbox returned before the | 158 // The active frame needs to be replaced and the mailbox returned before the |
157 // commit is called complete. | 159 // commit is called complete. |
158 SetNextCommitWaitsForActivation(); | 160 SetNextCommitWaitsForActivation(); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 texture_layer->SetFlipped(flipped_); | 257 texture_layer->SetFlipped(flipped_); |
256 texture_layer->SetUVTopLeft(uv_top_left_); | 258 texture_layer->SetUVTopLeft(uv_top_left_); |
257 texture_layer->SetUVBottomRight(uv_bottom_right_); | 259 texture_layer->SetUVBottomRight(uv_bottom_right_); |
258 texture_layer->SetVertexOpacity(vertex_opacity_); | 260 texture_layer->SetVertexOpacity(vertex_opacity_); |
259 texture_layer->SetPremultipliedAlpha(premultiplied_alpha_); | 261 texture_layer->SetPremultipliedAlpha(premultiplied_alpha_); |
260 texture_layer->SetBlendBackgroundColor(blend_background_color_); | 262 texture_layer->SetBlendBackgroundColor(blend_background_color_); |
261 if (uses_mailbox_ && needs_set_mailbox_) { | 263 if (uses_mailbox_ && needs_set_mailbox_) { |
262 TextureMailbox texture_mailbox; | 264 TextureMailbox texture_mailbox; |
263 scoped_ptr<SingleReleaseCallback> release_callback; | 265 scoped_ptr<SingleReleaseCallback> release_callback; |
264 if (holder_ref_) { | 266 if (holder_ref_) { |
265 MailboxHolder* holder = holder_ref_->holder(); | 267 TextureMailboxHolder* holder = holder_ref_->holder(); |
266 texture_mailbox = holder->mailbox(); | 268 texture_mailbox = holder->mailbox(); |
267 release_callback = holder->GetCallbackForImplThread(); | 269 release_callback = holder->GetCallbackForImplThread(); |
268 } | 270 } |
269 texture_layer->SetTextureMailbox(texture_mailbox, release_callback.Pass()); | 271 texture_layer->SetTextureMailbox(texture_mailbox, release_callback.Pass()); |
270 needs_set_mailbox_ = false; | 272 needs_set_mailbox_ = false; |
271 } else { | 273 } else { |
272 texture_layer->SetTextureId(texture_id_); | 274 texture_layer->SetTextureId(texture_id_); |
273 content_committed_ = DrawsContent(); | 275 content_committed_ = DrawsContent(); |
274 } | 276 } |
275 } | 277 } |
276 | 278 |
277 Region TextureLayer::VisibleContentOpaqueRegion() const { | 279 Region TextureLayer::VisibleContentOpaqueRegion() const { |
278 if (contents_opaque()) | 280 if (contents_opaque()) |
279 return visible_content_rect(); | 281 return visible_content_rect(); |
280 | 282 |
281 if (blend_background_color_ && (SkColorGetA(background_color()) == 0xFF)) | 283 if (blend_background_color_ && (SkColorGetA(background_color()) == 0xFF)) |
282 return visible_content_rect(); | 284 return visible_content_rect(); |
283 | 285 |
284 return Region(); | 286 return Region(); |
285 } | 287 } |
286 | 288 |
287 TextureLayer::MailboxHolder::MainThreadReference::MainThreadReference( | 289 TextureLayer::TextureMailboxHolder::MainThreadReference::MainThreadReference( |
288 MailboxHolder* holder) | 290 TextureMailboxHolder* holder) |
289 : holder_(holder) { | 291 : holder_(holder) { |
290 holder_->InternalAddRef(); | 292 holder_->InternalAddRef(); |
291 } | 293 } |
292 | 294 |
293 TextureLayer::MailboxHolder::MainThreadReference::~MainThreadReference() { | 295 TextureLayer::TextureMailboxHolder::MainThreadReference:: |
| 296 ~MainThreadReference() { |
294 holder_->InternalRelease(); | 297 holder_->InternalRelease(); |
295 } | 298 } |
296 | 299 |
297 TextureLayer::MailboxHolder::MailboxHolder( | 300 TextureLayer::TextureMailboxHolder::TextureMailboxHolder( |
298 const TextureMailbox& mailbox, | 301 const TextureMailbox& mailbox, |
299 scoped_ptr<SingleReleaseCallback> release_callback) | 302 scoped_ptr<SingleReleaseCallback> release_callback) |
300 : message_loop_(BlockingTaskRunner::current()), | 303 : message_loop_(BlockingTaskRunner::current()), |
301 internal_references_(0), | 304 internal_references_(0), |
302 mailbox_(mailbox), | 305 mailbox_(mailbox), |
303 release_callback_(release_callback.Pass()), | 306 release_callback_(release_callback.Pass()), |
304 sync_point_(mailbox.sync_point()), | 307 sync_point_(mailbox.sync_point()), |
305 is_lost_(false) { | 308 is_lost_(false) {} |
306 } | |
307 | 309 |
308 TextureLayer::MailboxHolder::~MailboxHolder() { | 310 TextureLayer::TextureMailboxHolder::~TextureMailboxHolder() { |
309 DCHECK_EQ(0u, internal_references_); | 311 DCHECK_EQ(0u, internal_references_); |
310 } | 312 } |
311 | 313 |
312 scoped_ptr<TextureLayer::MailboxHolder::MainThreadReference> | 314 scoped_ptr<TextureLayer::TextureMailboxHolder::MainThreadReference> |
313 TextureLayer::MailboxHolder::Create( | 315 TextureLayer::TextureMailboxHolder::Create( |
314 const TextureMailbox& mailbox, | 316 const TextureMailbox& mailbox, |
315 scoped_ptr<SingleReleaseCallback> release_callback) { | 317 scoped_ptr<SingleReleaseCallback> release_callback) { |
316 return scoped_ptr<MainThreadReference>(new MainThreadReference( | 318 return scoped_ptr<MainThreadReference>(new MainThreadReference( |
317 new MailboxHolder(mailbox, release_callback.Pass()))); | 319 new TextureMailboxHolder(mailbox, release_callback.Pass()))); |
318 } | 320 } |
319 | 321 |
320 void TextureLayer::MailboxHolder::Return(unsigned sync_point, bool is_lost) { | 322 void TextureLayer::TextureMailboxHolder::Return(uint32 sync_point, |
| 323 bool is_lost) { |
321 base::AutoLock lock(arguments_lock_); | 324 base::AutoLock lock(arguments_lock_); |
322 sync_point_ = sync_point; | 325 sync_point_ = sync_point; |
323 is_lost_ = is_lost; | 326 is_lost_ = is_lost; |
324 } | 327 } |
325 | 328 |
326 scoped_ptr<SingleReleaseCallback> | 329 scoped_ptr<SingleReleaseCallback> |
327 TextureLayer::MailboxHolder::GetCallbackForImplThread() { | 330 TextureLayer::TextureMailboxHolder::GetCallbackForImplThread() { |
328 // We can't call GetCallbackForImplThread if we released the main thread | 331 // We can't call GetCallbackForImplThread if we released the main thread |
329 // reference. | 332 // reference. |
330 DCHECK_GT(internal_references_, 0u); | 333 DCHECK_GT(internal_references_, 0u); |
331 InternalAddRef(); | 334 InternalAddRef(); |
332 return SingleReleaseCallback::Create( | 335 return SingleReleaseCallback::Create( |
333 base::Bind(&MailboxHolder::ReturnAndReleaseOnImplThread, this)); | 336 base::Bind(&TextureMailboxHolder::ReturnAndReleaseOnImplThread, this)); |
334 } | 337 } |
335 | 338 |
336 void TextureLayer::MailboxHolder::InternalAddRef() { | 339 void TextureLayer::TextureMailboxHolder::InternalAddRef() { |
337 ++internal_references_; | 340 ++internal_references_; |
338 } | 341 } |
339 | 342 |
340 void TextureLayer::MailboxHolder::InternalRelease() { | 343 void TextureLayer::TextureMailboxHolder::InternalRelease() { |
341 DCHECK(message_loop_->BelongsToCurrentThread()); | 344 DCHECK(message_loop_->BelongsToCurrentThread()); |
342 if (!--internal_references_) { | 345 if (!--internal_references_) { |
343 release_callback_->Run(sync_point_, is_lost_); | 346 release_callback_->Run(sync_point_, is_lost_); |
344 mailbox_ = TextureMailbox(); | 347 mailbox_ = TextureMailbox(); |
345 release_callback_.reset(); | 348 release_callback_.reset(); |
346 } | 349 } |
347 } | 350 } |
348 | 351 |
349 void TextureLayer::MailboxHolder::ReturnAndReleaseOnImplThread( | 352 void TextureLayer::TextureMailboxHolder::ReturnAndReleaseOnImplThread( |
350 unsigned sync_point, bool is_lost) { | 353 uint32 sync_point, |
| 354 bool is_lost) { |
351 Return(sync_point, is_lost); | 355 Return(sync_point, is_lost); |
352 message_loop_->PostTask(FROM_HERE, | 356 message_loop_->PostTask( |
353 base::Bind(&MailboxHolder::InternalRelease, this)); | 357 FROM_HERE, base::Bind(&TextureMailboxHolder::InternalRelease, this)); |
354 } | 358 } |
355 | 359 |
356 } // namespace cc | 360 } // namespace cc |
OLD | NEW |