Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Side by Side Diff: ui/compositor/layer.cc

Issue 634113002: Use solid color layer for delegated surface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 layer_grayscale_(0.0f), 70 layer_grayscale_(0.0f),
71 layer_inverted_(false), 71 layer_inverted_(false),
72 layer_mask_(NULL), 72 layer_mask_(NULL),
73 layer_mask_back_link_(NULL), 73 layer_mask_back_link_(NULL),
74 zoom_(1), 74 zoom_(1),
75 zoom_inset_(0), 75 zoom_inset_(0),
76 delegate_(NULL), 76 delegate_(NULL),
77 owner_(NULL), 77 owner_(NULL),
78 cc_layer_(NULL), 78 cc_layer_(NULL),
79 device_scale_factor_(1.0f) { 79 device_scale_factor_(1.0f) {
80 CreateWebLayer(); 80 CreateCcLayer();
81 } 81 }
82 82
83 Layer::Layer(LayerType type) 83 Layer::Layer(LayerType type)
84 : type_(type), 84 : type_(type),
85 compositor_(NULL), 85 compositor_(NULL),
86 parent_(NULL), 86 parent_(NULL),
87 visible_(true), 87 visible_(true),
88 force_render_surface_(false), 88 force_render_surface_(false),
89 fills_bounds_opaquely_(true), 89 fills_bounds_opaquely_(true),
90 fills_bounds_completely_(false), 90 fills_bounds_completely_(false),
91 background_blur_radius_(0), 91 background_blur_radius_(0),
92 layer_saturation_(0.0f), 92 layer_saturation_(0.0f),
93 layer_brightness_(0.0f), 93 layer_brightness_(0.0f),
94 layer_grayscale_(0.0f), 94 layer_grayscale_(0.0f),
95 layer_inverted_(false), 95 layer_inverted_(false),
96 layer_mask_(NULL), 96 layer_mask_(NULL),
97 layer_mask_back_link_(NULL), 97 layer_mask_back_link_(NULL),
98 zoom_(1), 98 zoom_(1),
99 zoom_inset_(0), 99 zoom_inset_(0),
100 delegate_(NULL), 100 delegate_(NULL),
101 owner_(NULL), 101 owner_(NULL),
102 cc_layer_(NULL), 102 cc_layer_(NULL),
103 device_scale_factor_(1.0f) { 103 device_scale_factor_(1.0f) {
104 CreateWebLayer(); 104 CreateCcLayer();
105 } 105 }
106 106
107 Layer::~Layer() { 107 Layer::~Layer() {
108 // Destroying the animator may cause observers to use the layer (and 108 // Destroying the animator may cause observers to use the layer (and
109 // indirectly the WebLayer). Destroy the animator first so that the WebLayer 109 // indirectly the WebLayer). Destroy the animator first so that the WebLayer
110 // is still around. 110 // is still around.
111 if (animator_.get()) 111 if (animator_.get())
112 animator_->SetDelegate(NULL); 112 animator_->SetDelegate(NULL);
113 animator_ = NULL; 113 animator_ = NULL;
114 if (compositor_) 114 if (compositor_)
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 484
485 cc_layer_->RemoveAllChildren(); 485 cc_layer_->RemoveAllChildren();
486 if (cc_layer_->parent()) { 486 if (cc_layer_->parent()) {
487 cc_layer_->parent()->ReplaceChild(cc_layer_, new_layer); 487 cc_layer_->parent()->ReplaceChild(cc_layer_, new_layer);
488 } 488 }
489 cc_layer_->SetLayerClient(NULL); 489 cc_layer_->SetLayerClient(NULL);
490 cc_layer_->RemoveLayerAnimationEventObserver(this); 490 cc_layer_->RemoveLayerAnimationEventObserver(this);
491 new_layer->SetOpacity(cc_layer_->opacity()); 491 new_layer->SetOpacity(cc_layer_->opacity());
492 new_layer->SetTransform(cc_layer_->transform()); 492 new_layer->SetTransform(cc_layer_->transform());
493 new_layer->SetPosition(cc_layer_->position()); 493 new_layer->SetPosition(cc_layer_->position());
494 new_layer->SetBackgroundColor(cc_layer_->background_color());
494 495
495 cc_layer_ = new_layer.get(); 496 cc_layer_ = new_layer.get();
496 content_layer_ = NULL; 497 content_layer_ = NULL;
497 solid_color_layer_ = NULL; 498 solid_color_layer_ = NULL;
498 texture_layer_ = NULL; 499 texture_layer_ = NULL;
499 delegated_renderer_layer_ = NULL; 500 delegated_renderer_layer_ = NULL;
500 surface_layer_ = NULL; 501 surface_layer_ = NULL;
501 502
502 cc_layer_->AddLayerAnimationEventObserver(this); 503 cc_layer_->AddLayerAnimationEventObserver(this);
503 for (size_t i = 0; i < children_.size(); ++i) { 504 for (size_t i = 0; i < children_.size(); ++i) {
(...skipping 18 matching lines...) Expand all
522 else 523 else
523 new_layer = cc::ContentLayer::Create(this); 524 new_layer = cc::ContentLayer::Create(this);
524 SwitchToLayer(new_layer); 525 SwitchToLayer(new_layer);
525 content_layer_ = new_layer; 526 content_layer_ = new_layer;
526 } 527 }
527 528
528 void Layer::SetTextureMailbox( 529 void Layer::SetTextureMailbox(
529 const cc::TextureMailbox& mailbox, 530 const cc::TextureMailbox& mailbox,
530 scoped_ptr<cc::SingleReleaseCallback> release_callback, 531 scoped_ptr<cc::SingleReleaseCallback> release_callback,
531 gfx::Size texture_size_in_dip) { 532 gfx::Size texture_size_in_dip) {
532 DCHECK_EQ(type_, LAYER_TEXTURED); 533 DCHECK(type_ == LAYER_TEXTURED || type_ == LAYER_SOLID_COLOR);
533 DCHECK(!solid_color_layer_.get());
534 DCHECK(mailbox.IsValid()); 534 DCHECK(mailbox.IsValid());
535 DCHECK(release_callback); 535 DCHECK(release_callback);
536 if (!texture_layer_.get()) { 536 if (!texture_layer_.get()) {
537 scoped_refptr<cc::TextureLayer> new_layer = 537 scoped_refptr<cc::TextureLayer> new_layer =
538 cc::TextureLayer::CreateForMailbox(this); 538 cc::TextureLayer::CreateForMailbox(this);
539 new_layer->SetFlipped(true); 539 new_layer->SetFlipped(true);
540 SwitchToLayer(new_layer); 540 SwitchToLayer(new_layer);
541 texture_layer_ = new_layer; 541 texture_layer_ = new_layer;
542 } 542 }
543 if (mailbox_release_callback_) 543 if (mailbox_release_callback_)
544 mailbox_release_callback_->Run(0, false); 544 mailbox_release_callback_->Run(0, false);
545 mailbox_release_callback_ = release_callback.Pass(); 545 mailbox_release_callback_ = release_callback.Pass();
546 mailbox_ = mailbox; 546 mailbox_ = mailbox;
547 SetTextureSize(texture_size_in_dip); 547 SetTextureSize(texture_size_in_dip);
548 } 548 }
549 549
550 void Layer::SetTextureSize(gfx::Size texture_size_in_dip) { 550 void Layer::SetTextureSize(gfx::Size texture_size_in_dip) {
551 DCHECK(texture_layer_.get()); 551 DCHECK(texture_layer_.get());
552 if (frame_size_in_dip_ == texture_size_in_dip) 552 if (frame_size_in_dip_ == texture_size_in_dip)
553 return; 553 return;
554 frame_size_in_dip_ = texture_size_in_dip; 554 frame_size_in_dip_ = texture_size_in_dip;
555 RecomputeDrawsContentAndUVRect(); 555 RecomputeDrawsContentAndUVRect();
556 texture_layer_->SetNeedsDisplay(); 556 texture_layer_->SetNeedsDisplay();
557 } 557 }
558 558
559 void Layer::SetShowDelegatedContent(cc::DelegatedFrameProvider* frame_provider, 559 void Layer::SetShowDelegatedContent(cc::DelegatedFrameProvider* frame_provider,
560 gfx::Size frame_size_in_dip) { 560 gfx::Size frame_size_in_dip) {
561 DCHECK_EQ(type_, LAYER_TEXTURED); 561 DCHECK(type_ == LAYER_TEXTURED || type_ == LAYER_SOLID_COLOR);
562 562
563 scoped_refptr<cc::DelegatedRendererLayer> new_layer = 563 scoped_refptr<cc::DelegatedRendererLayer> new_layer =
564 cc::DelegatedRendererLayer::Create(frame_provider); 564 cc::DelegatedRendererLayer::Create(frame_provider);
565 SwitchToLayer(new_layer); 565 SwitchToLayer(new_layer);
566 delegated_renderer_layer_ = new_layer; 566 delegated_renderer_layer_ = new_layer;
567 567
568 frame_size_in_dip_ = frame_size_in_dip; 568 frame_size_in_dip_ = frame_size_in_dip;
569 RecomputeDrawsContentAndUVRect(); 569 RecomputeDrawsContentAndUVRect();
570 } 570 }
571 571
572 void Layer::SetShowSurface(cc::SurfaceId id, gfx::Size frame_size_in_dip) { 572 void Layer::SetShowSurface(cc::SurfaceId id, gfx::Size frame_size_in_dip) {
573 DCHECK_EQ(type_, LAYER_TEXTURED); 573 DCHECK(type_ == LAYER_TEXTURED || type_ == LAYER_SOLID_COLOR);
574 574
575 scoped_refptr<cc::SurfaceLayer> new_layer = cc::SurfaceLayer::Create(); 575 scoped_refptr<cc::SurfaceLayer> new_layer = cc::SurfaceLayer::Create();
576 new_layer->SetSurfaceId(id); 576 new_layer->SetSurfaceId(id);
577 SwitchToLayer(new_layer); 577 SwitchToLayer(new_layer);
578 surface_layer_ = new_layer; 578 surface_layer_ = new_layer;
579 579
580 frame_size_in_dip_ = frame_size_in_dip; 580 frame_size_in_dip_ = frame_size_in_dip;
581 RecomputeDrawsContentAndUVRect(); 581 RecomputeDrawsContentAndUVRect();
582 } 582 }
583 583
584 void Layer::SetShowPaintedContent() { 584 void Layer::SetShowSolidColorContent() {
585 if (content_layer_.get()) 585 DCHECK_EQ(type_, LAYER_SOLID_COLOR);
586
587 if (solid_color_layer_.get())
586 return; 588 return;
587 589
588 scoped_refptr<cc::Layer> new_layer; 590 scoped_refptr<cc::SolidColorLayer> new_layer = cc::SolidColorLayer::Create();
589 if (Layer::UsingPictureLayer())
590 new_layer = cc::PictureLayer::Create(this);
591 else
592 new_layer = cc::ContentLayer::Create(this);
593 SwitchToLayer(new_layer); 591 SwitchToLayer(new_layer);
594 content_layer_ = new_layer; 592 solid_color_layer_ = new_layer;
595 593
596 mailbox_ = cc::TextureMailbox(); 594 mailbox_ = cc::TextureMailbox();
597 if (mailbox_release_callback_) { 595 if (mailbox_release_callback_) {
598 mailbox_release_callback_->Run(0, false); 596 mailbox_release_callback_->Run(0, false);
599 mailbox_release_callback_.reset(); 597 mailbox_release_callback_.reset();
600 } 598 }
601 RecomputeDrawsContentAndUVRect(); 599 RecomputeDrawsContentAndUVRect();
602 } 600 }
603 601
604 void Layer::UpdateNinePatchLayerBitmap(const SkBitmap& bitmap) { 602 void Layer::UpdateNinePatchLayerBitmap(const SkBitmap& bitmap) {
(...skipping 15 matching lines...) Expand all
620 } 618 }
621 619
622 void Layer::UpdateNinePatchLayerBorder(const gfx::Rect& border) { 620 void Layer::UpdateNinePatchLayerBorder(const gfx::Rect& border) {
623 DCHECK(type_ == LAYER_NINE_PATCH && nine_patch_layer_.get()); 621 DCHECK(type_ == LAYER_NINE_PATCH && nine_patch_layer_.get());
624 nine_patch_layer_->SetBorder(border); 622 nine_patch_layer_->SetBorder(border);
625 } 623 }
626 624
627 void Layer::SetColor(SkColor color) { GetAnimator()->SetColor(color); } 625 void Layer::SetColor(SkColor color) { GetAnimator()->SetColor(color); }
628 626
629 bool Layer::SchedulePaint(const gfx::Rect& invalid_rect) { 627 bool Layer::SchedulePaint(const gfx::Rect& invalid_rect) {
630 if (type_ == LAYER_SOLID_COLOR || 628 if ((type_ == LAYER_SOLID_COLOR && !texture_layer_.get()) ||
631 type_ == LAYER_NINE_PATCH || 629 type_ == LAYER_NINE_PATCH || (!delegate_ && !mailbox_.IsValid()))
632 (!delegate_ && !mailbox_.IsValid()))
633 return false; 630 return false;
634 631
635 damaged_region_.op(invalid_rect.x(), 632 damaged_region_.op(invalid_rect.x(),
636 invalid_rect.y(), 633 invalid_rect.y(),
637 invalid_rect.right(), 634 invalid_rect.right(),
638 invalid_rect.bottom(), 635 invalid_rect.bottom(),
639 SkRegion::kUnion_Op); 636 SkRegion::kUnion_Op);
640 ScheduleDraw(); 637 ScheduleDraw();
641 return true; 638 return true;
642 } 639 }
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 SetLayerFilters(); 863 SetLayerFilters();
867 } 864 }
868 865
869 void Layer::SetGrayscaleFromAnimation(float grayscale) { 866 void Layer::SetGrayscaleFromAnimation(float grayscale) {
870 layer_grayscale_ = grayscale; 867 layer_grayscale_ = grayscale;
871 SetLayerFilters(); 868 SetLayerFilters();
872 } 869 }
873 870
874 void Layer::SetColorFromAnimation(SkColor color) { 871 void Layer::SetColorFromAnimation(SkColor color) {
875 DCHECK_EQ(type_, LAYER_SOLID_COLOR); 872 DCHECK_EQ(type_, LAYER_SOLID_COLOR);
876 solid_color_layer_->SetBackgroundColor(color); 873 cc_layer_->SetBackgroundColor(color);
877 SetFillsBoundsOpaquely(SkColorGetA(color) == 0xFF); 874 SetFillsBoundsOpaquely(SkColorGetA(color) == 0xFF);
878 } 875 }
879 876
880 void Layer::ScheduleDrawForAnimation() { 877 void Layer::ScheduleDrawForAnimation() {
881 ScheduleDraw(); 878 ScheduleDraw();
882 } 879 }
883 880
884 const gfx::Rect& Layer::GetBoundsForAnimation() const { 881 const gfx::Rect& Layer::GetBoundsForAnimation() const {
885 return bounds(); 882 return bounds();
886 } 883 }
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 it != pending_threaded_animations_.end(); 966 it != pending_threaded_animations_.end();
970 ++it) 967 ++it)
971 cc_layer_->AddAnimation(pending_threaded_animations_.take(it)); 968 cc_layer_->AddAnimation(pending_threaded_animations_.take(it));
972 969
973 pending_threaded_animations_.clear(); 970 pending_threaded_animations_.clear();
974 971
975 for (size_t i = 0; i < children_.size(); ++i) 972 for (size_t i = 0; i < children_.size(); ++i)
976 children_[i]->SendPendingThreadedAnimations(); 973 children_[i]->SendPendingThreadedAnimations();
977 } 974 }
978 975
979 void Layer::CreateWebLayer() { 976 void Layer::CreateCcLayer() {
980 if (type_ == LAYER_SOLID_COLOR) { 977 if (type_ == LAYER_SOLID_COLOR) {
981 solid_color_layer_ = cc::SolidColorLayer::Create(); 978 solid_color_layer_ = cc::SolidColorLayer::Create();
982 cc_layer_ = solid_color_layer_.get(); 979 cc_layer_ = solid_color_layer_.get();
983 } else if (type_ == LAYER_NINE_PATCH) { 980 } else if (type_ == LAYER_NINE_PATCH) {
984 nine_patch_layer_ = cc::NinePatchLayer::Create(); 981 nine_patch_layer_ = cc::NinePatchLayer::Create();
985 cc_layer_ = nine_patch_layer_.get(); 982 cc_layer_ = nine_patch_layer_.get();
986 } else { 983 } else {
987 if (Layer::UsingPictureLayer()) 984 if (Layer::UsingPictureLayer())
988 content_layer_ = cc::PictureLayer::Create(this); 985 content_layer_ = cc::PictureLayer::Create(this);
989 else 986 else
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 children_.end(), 1041 children_.end(),
1045 std::bind2nd(std::mem_fun(&Layer::RemoveAnimatorsInTreeFromCollection), 1042 std::bind2nd(std::mem_fun(&Layer::RemoveAnimatorsInTreeFromCollection),
1046 collection)); 1043 collection));
1047 } 1044 }
1048 1045
1049 bool Layer::IsAnimating() const { 1046 bool Layer::IsAnimating() const {
1050 return animator_.get() && animator_->is_animating(); 1047 return animator_.get() && animator_->is_animating();
1051 } 1048 }
1052 1049
1053 } // namespace ui 1050 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698