OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/compositor/layer.h" | 5 #include "ui/compositor/layer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
469 cc_layer_->SetHideLayerAndSubtree(!visible_); | 469 cc_layer_->SetHideLayerAndSubtree(!visible_); |
470 } | 470 } |
471 | 471 |
472 void Layer::SwitchCCLayerForTest() { | 472 void Layer::SwitchCCLayerForTest() { |
473 scoped_refptr<cc::ContentLayer> new_layer = cc::ContentLayer::Create(this); | 473 scoped_refptr<cc::ContentLayer> new_layer = cc::ContentLayer::Create(this); |
474 SwitchToLayer(new_layer); | 474 SwitchToLayer(new_layer); |
475 content_layer_ = new_layer; | 475 content_layer_ = new_layer; |
476 } | 476 } |
477 | 477 |
478 void Layer::SetExternalTexture(Texture* texture) { | 478 void Layer::SetExternalTexture(Texture* texture) { |
479 DCHECK(texture); | |
480 | |
479 // Hold a ref to the old |Texture| until we have updated all | 481 // Hold a ref to the old |Texture| until we have updated all |
480 // compositor references to the texture id that it holds. | 482 // compositor references to the texture id that it holds. |
481 scoped_refptr<ui::Texture> old_texture = texture_; | 483 scoped_refptr<ui::Texture> old_texture = texture_; |
482 | 484 |
483 DCHECK_EQ(type_, LAYER_TEXTURED); | 485 DCHECK_EQ(type_, LAYER_TEXTURED); |
484 DCHECK(!solid_color_layer_.get()); | 486 DCHECK(!solid_color_layer_.get()); |
485 bool has_texture = !!texture; | 487 layer_updated_externally_ = true; |
486 layer_updated_externally_ = has_texture; | |
487 texture_ = texture; | 488 texture_ = texture; |
488 if (!!texture_layer_.get() != has_texture) { | 489 if (!texture_layer_.get()) { |
489 // Switch to a different type of layer. | 490 scoped_refptr<cc::TextureLayer> new_layer = cc::TextureLayer::Create(this); |
490 if (has_texture) { | 491 new_layer->SetFlipped(texture_->flipped()); |
491 scoped_refptr<cc::TextureLayer> new_layer = | 492 SwitchToLayer(new_layer); |
492 cc::TextureLayer::Create(this); | 493 texture_layer_ = new_layer; |
493 new_layer->SetFlipped(texture_->flipped()); | |
494 SwitchToLayer(new_layer); | |
495 texture_layer_ = new_layer; | |
496 } else { | |
497 scoped_refptr<cc::ContentLayer> new_layer = | |
498 cc::ContentLayer::Create(this); | |
499 SwitchToLayer(new_layer); | |
500 content_layer_ = new_layer; | |
501 mailbox_ = cc::TextureMailbox(); | |
502 } | |
503 } | 494 } |
504 RecomputeDrawsContentAndUVRect(); | 495 RecomputeDrawsContentAndUVRect(); |
505 } | 496 } |
506 | 497 |
507 void Layer::SetTextureMailbox( | 498 void Layer::SetTextureMailbox( |
508 const cc::TextureMailbox& mailbox, | 499 const cc::TextureMailbox& mailbox, |
509 scoped_ptr<cc::SingleReleaseCallback> release_callback, | 500 scoped_ptr<cc::SingleReleaseCallback> release_callback, |
510 float scale_factor) { | 501 float scale_factor) { |
511 DCHECK_EQ(type_, LAYER_TEXTURED); | 502 DCHECK_EQ(type_, LAYER_TEXTURED); |
512 DCHECK(!solid_color_layer_.get()); | 503 DCHECK(!solid_color_layer_.get()); |
(...skipping 13 matching lines...) Expand all Loading... | |
526 } | 517 } |
527 | 518 |
528 cc::TextureMailbox Layer::GetTextureMailbox(float* scale_factor) { | 519 cc::TextureMailbox Layer::GetTextureMailbox(float* scale_factor) { |
529 if (scale_factor) | 520 if (scale_factor) |
530 *scale_factor = mailbox_scale_factor_; | 521 *scale_factor = mailbox_scale_factor_; |
531 return mailbox_; | 522 return mailbox_; |
532 } | 523 } |
533 | 524 |
534 void Layer::SetDelegatedFrame(scoped_ptr<cc::DelegatedFrameData> frame, | 525 void Layer::SetDelegatedFrame(scoped_ptr<cc::DelegatedFrameData> frame, |
535 gfx::Size frame_size_in_dip) { | 526 gfx::Size frame_size_in_dip) { |
527 DCHECK(frame && !frame->render_pass_list.empty()); | |
528 | |
536 DCHECK_EQ(type_, LAYER_TEXTURED); | 529 DCHECK_EQ(type_, LAYER_TEXTURED); |
537 bool has_frame = frame.get() && !frame->render_pass_list.empty(); | 530 layer_updated_externally_ = true; |
538 layer_updated_externally_ = has_frame; | |
539 delegated_frame_size_in_dip_ = frame_size_in_dip; | 531 delegated_frame_size_in_dip_ = frame_size_in_dip; |
540 if (!!delegated_renderer_layer_.get() != has_frame) { | 532 if (!delegated_renderer_layer_.get()) { |
541 if (has_frame) { | 533 scoped_refptr<cc::DelegatedRendererLayer> new_layer = |
542 scoped_refptr<cc::DelegatedRendererLayer> new_layer = | 534 cc::DelegatedRendererLayer::Create(NULL); |
543 cc::DelegatedRendererLayer::Create(NULL); | 535 SwitchToLayer(new_layer); |
544 SwitchToLayer(new_layer); | 536 delegated_renderer_layer_ = new_layer; |
545 delegated_renderer_layer_ = new_layer; | |
546 } else { | |
547 scoped_refptr<cc::ContentLayer> new_layer = | |
548 cc::ContentLayer::Create(this); | |
549 SwitchToLayer(new_layer); | |
550 content_layer_ = new_layer; | |
551 } | |
552 } | 537 } |
553 if (has_frame) | 538 delegated_renderer_layer_->SetFrameData(frame.Pass()); |
554 delegated_renderer_layer_->SetFrameData(frame.Pass()); | |
555 RecomputeDrawsContentAndUVRect(); | 539 RecomputeDrawsContentAndUVRect(); |
556 } | 540 } |
557 | 541 |
558 void Layer::TakeUnusedResourcesForChildCompositor( | 542 void Layer::TakeUnusedResourcesForChildCompositor( |
559 cc::ReturnedResourceArray* list) { | 543 cc::ReturnedResourceArray* list) { |
560 if (delegated_renderer_layer_.get()) | 544 if (delegated_renderer_layer_.get()) |
561 delegated_renderer_layer_->TakeUnusedResourcesForChildCompositor(list); | 545 delegated_renderer_layer_->TakeUnusedResourcesForChildCompositor(list); |
562 } | 546 } |
563 | 547 |
564 void Layer::SetColor(SkColor color) { | 548 void Layer::SetShowPaintedContent() { |
565 GetAnimator()->SetColor(color); | 549 if (content_layer_.get()) |
550 return; | |
551 | |
552 // Hold a ref to the old |texture_| until we have updated all | |
553 // compositor references to the texture id that it holds. | |
554 scoped_refptr<ui::Texture> old_texture = texture_; | |
piman
2013/10/01 21:21:45
nit: I don't think that's necessary in this functi
danakj
2013/10/01 22:37:19
Done.
| |
555 | |
556 layer_updated_externally_ = false; | |
557 | |
558 scoped_refptr<cc::ContentLayer> new_layer = cc::ContentLayer::Create(this); | |
559 SwitchToLayer(new_layer); | |
560 content_layer_ = new_layer; | |
561 | |
562 mailbox_ = cc::TextureMailbox(); | |
563 texture_ = NULL; | |
564 | |
565 RecomputeDrawsContentAndUVRect(); | |
566 } | 566 } |
567 | 567 |
568 void Layer::SetColor(SkColor color) { GetAnimator()->SetColor(color); } | |
569 | |
568 bool Layer::SchedulePaint(const gfx::Rect& invalid_rect) { | 570 bool Layer::SchedulePaint(const gfx::Rect& invalid_rect) { |
569 if (type_ == LAYER_SOLID_COLOR || (!delegate_ && !texture_.get())) | 571 if (type_ == LAYER_SOLID_COLOR || (!delegate_ && !texture_.get())) |
570 return false; | 572 return false; |
571 | 573 |
572 damaged_region_.op(invalid_rect.x(), | 574 damaged_region_.op(invalid_rect.x(), |
573 invalid_rect.y(), | 575 invalid_rect.y(), |
574 invalid_rect.right(), | 576 invalid_rect.right(), |
575 invalid_rect.bottom(), | 577 invalid_rect.bottom(), |
576 SkRegion::kUnion_Op); | 578 SkRegion::kUnion_Op); |
577 ScheduleDraw(); | 579 ScheduleDraw(); |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
975 cc_layer_->SetBounds(ConvertSizeToPixel(this, size)); | 977 cc_layer_->SetBounds(ConvertSizeToPixel(this, size)); |
976 } | 978 } |
977 | 979 |
978 void Layer::RecomputePosition() { | 980 void Layer::RecomputePosition() { |
979 cc_layer_->SetPosition(gfx::ScalePoint( | 981 cc_layer_->SetPosition(gfx::ScalePoint( |
980 gfx::PointF(bounds_.x(), bounds_.y()), | 982 gfx::PointF(bounds_.x(), bounds_.y()), |
981 device_scale_factor_)); | 983 device_scale_factor_)); |
982 } | 984 } |
983 | 985 |
984 } // namespace ui | 986 } // namespace ui |
OLD | NEW |