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

Side by Side Diff: chrome/browser/android/compositor/layer/content_layer.cc

Issue 2707403004: Unify background color gutters. (Closed)
Patch Set: Remove debug logging Created 3 years, 10 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/android/compositor/layer/content_layer.h" 5 #include "chrome/browser/android/compositor/layer/content_layer.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "cc/layers/layer.h" 8 #include "cc/layers/layer.h"
9 #include "cc/layers/layer_collections.h" 9 #include "cc/layers/layer_collections.h"
10 #include "cc/layers/surface_layer.h"
10 #include "cc/output/filter_operations.h" 11 #include "cc/output/filter_operations.h"
11 #include "chrome/browser/android/compositor/layer/thumbnail_layer.h" 12 #include "chrome/browser/android/compositor/layer/thumbnail_layer.h"
12 #include "chrome/browser/android/compositor/tab_content_manager.h" 13 #include "chrome/browser/android/compositor/tab_content_manager.h"
13 #include "content/public/browser/android/compositor.h" 14 #include "content/public/browser/android/compositor.h"
14 #include "ui/gfx/geometry/size.h" 15 #include "ui/gfx/geometry/size.h"
15 16
16 namespace android { 17 namespace android {
17 18
18 // static 19 // static
19 scoped_refptr<ContentLayer> ContentLayer::Create( 20 scoped_refptr<ContentLayer> ContentLayer::Create(
20 TabContentManager* tab_content_manager) { 21 TabContentManager* tab_content_manager) {
21 return make_scoped_refptr(new ContentLayer(tab_content_manager)); 22 return make_scoped_refptr(new ContentLayer(tab_content_manager));
22 } 23 }
23 24
24 static void SetOpacityOnLeaf(scoped_refptr<cc::Layer> layer, float alpha) { 25 static void SetOpacityOnLeaf(scoped_refptr<cc::Layer> layer, float alpha) {
25 const cc::LayerList& children = layer->children(); 26 const cc::LayerList& children = layer->children();
26 if (children.size() > 0) { 27 if (children.size() > 0) {
27 layer->SetOpacity(1.0f); 28 layer->SetOpacity(1.0f);
28 for (uint i = 0; i < children.size(); ++i) 29 for (uint i = 0; i < children.size(); ++i)
29 SetOpacityOnLeaf(children[i], alpha); 30 SetOpacityOnLeaf(children[i], alpha);
30 } else { 31 } else {
31 layer->SetOpacity(alpha); 32 layer->SetOpacity(alpha);
32 } 33 }
33 } 34 }
34 35
35 static bool DoesLeafDrawContents(scoped_refptr<cc::Layer> layer) { 36 static cc::Layer* DrawContentsLeaf(scoped_refptr<cc::Layer> layer) {
Changwan Ryu 2017/02/27 14:28:37 nit: The name is a bit confusing to me because it
aelias_OOO_until_Jul13 2017/02/27 19:33:46 Done.
36 if (!layer.get()) 37 if (!layer.get())
37 return false; 38 return nullptr;
38 39
39 // If the subtree is hidden, then any layers in this tree will not be drawn. 40 // If the subtree is hidden, then any layers in this tree will not be drawn.
40 if (layer->hide_layer_and_subtree()) 41 if (layer->hide_layer_and_subtree())
41 return false; 42 return nullptr;
42 43
43 // TODO: Remove the need for this logic. We can't really guess from 44 if (layer->opacity() == 0.0f)
44 // an opaque layer type whether it has valid live contents, or for example 45 return nullptr;
45 // just a background color placeholder. Need to get this from somewhere else 46
46 // like ContentViewCore or RWHV. 47 if (layer->DrawsContent())
47 if (layer->DrawsContent() && !layer->background_color()) { 48 return layer.get();
48 return true;
49 }
50 49
51 const cc::LayerList& children = layer->children(); 50 const cc::LayerList& children = layer->children();
52 for (unsigned i = 0; i < children.size(); i++) { 51 for (unsigned i = 0; i < children.size(); i++) {
53 if (DoesLeafDrawContents(children[i])) 52 cc::Layer* leaf = DrawContentsLeaf(children[i]);
54 return true; 53 if (leaf)
54 return leaf;
55 } 55 }
56 return false; 56 return nullptr;
57 } 57 }
58 58
59 void ContentLayer::SetProperties(int id, 59 void ContentLayer::SetProperties(int id,
60 bool can_use_live_layer, 60 bool can_use_live_layer,
61 float static_to_view_blend, 61 float static_to_view_blend,
62 bool should_override_content_alpha, 62 bool should_override_content_alpha,
63 float content_alpha_override, 63 float content_alpha_override,
64 float saturation, 64 float saturation,
65 bool should_clip, 65 bool should_clip,
66 const gfx::Rect& clip) { 66 const gfx::Rect& clip) {
67 scoped_refptr<cc::Layer> content_layer = 67 scoped_refptr<cc::Layer> live_layer;
68 tab_content_manager_->GetLiveLayer(id); 68 if (can_use_live_layer)
69 bool content_layer_draws = DoesLeafDrawContents(content_layer); 69 live_layer = tab_content_manager_->GetLiveLayer(id);
70 bool live_layer_draws = DrawContentsLeaf(live_layer);
70 71
71 scoped_refptr<ThumbnailLayer> static_layer = 72 scoped_refptr<ThumbnailLayer> static_layer =
72 tab_content_manager_->GetStaticLayer( 73 tab_content_manager_->GetOrCreateStaticLayer(id, !live_layer_draws);
73 id, !(can_use_live_layer && content_layer_draws));
74 74
75 float content_opacity = 75 float content_opacity =
76 should_override_content_alpha ? content_alpha_override : 1.0f; 76 should_override_content_alpha ? content_alpha_override : 1.0f;
77 float static_opacity = 77 float static_opacity =
78 should_override_content_alpha ? content_alpha_override : 1.0f; 78 should_override_content_alpha ? content_alpha_override : 1.0f;
79 if (content_layer.get() && can_use_live_layer && content_layer_draws) 79 if (live_layer_draws)
80 static_opacity = static_to_view_blend; 80 static_opacity = static_to_view_blend;
81 if (!can_use_live_layer)
82 content_opacity = 0.0f;
83 81
84 const cc::LayerList& layer_children = layer_->children(); 82 const cc::LayerList& layer_children = layer_->children();
85 for (unsigned i = 0; i < layer_children.size(); i++) 83 for (unsigned i = 0; i < layer_children.size(); i++)
86 layer_children[i]->RemoveFromParent(); 84 layer_children[i]->RemoveFromParent();
87 85
88 if (content_layer.get()) { 86 if (live_layer.get()) {
89 content_layer->SetMasksToBounds(should_clip); 87 live_layer->SetMasksToBounds(should_clip);
90 content_layer->SetBounds(clip.size()); 88 live_layer->SetBounds(clip.size());
91 SetOpacityOnLeaf(content_layer, content_opacity); 89 SetOpacityOnLeaf(live_layer, content_opacity);
92 90
93 layer_->AddChild(content_layer); 91 layer_->AddChild(live_layer);
94 } 92 }
95 if (static_layer.get()) { 93 if (static_layer.get()) {
96 static_layer->layer()->SetIsDrawable(true); 94 static_layer->layer()->SetIsDrawable(true);
97 if (should_clip) 95 if (should_clip)
98 static_layer->Clip(clip); 96 static_layer->Clip(clip);
99 else 97 else
100 static_layer->ClearClip(); 98 static_layer->ClearClip();
101 SetOpacityOnLeaf(static_layer->layer(), static_opacity); 99 SetOpacityOnLeaf(static_layer->layer(), static_opacity);
102 100
103 cc::FilterOperations static_filter_operations; 101 cc::FilterOperations static_filter_operations;
104 if (saturation < 1.0f) { 102 if (saturation < 1.0f) {
105 static_filter_operations.Append( 103 static_filter_operations.Append(
106 cc::FilterOperation::CreateSaturateFilter(saturation)); 104 cc::FilterOperation::CreateSaturateFilter(saturation));
107 } 105 }
108 static_layer->layer()->SetFilters(static_filter_operations); 106 static_layer->layer()->SetFilters(static_filter_operations);
109 107
110 layer_->AddChild(static_layer->layer()); 108 layer_->AddChild(static_layer->layer());
111 } 109 }
112 } 110 }
113 111
112 gfx::Size ContentLayer::ComputeSize(int id) const {
113 gfx::Size size;
114
115 scoped_refptr<cc::Layer> live_layer = tab_content_manager_->GetLiveLayer(id);
116 cc::SurfaceLayer* surface_layer =
117 static_cast<cc::SurfaceLayer*>(DrawContentsLeaf(live_layer));
118 if (surface_layer)
119 size.SetToMax(surface_layer->primary_surface_info().size_in_pixels());
120
121 scoped_refptr<ThumbnailLayer> static_layer =
122 tab_content_manager_->GetStaticLayer(id);
123 if (static_layer.get() && DrawContentsLeaf(static_layer->layer()))
124 size.SetToMax(static_layer->layer()->bounds());
125
126 return size;
127 }
128
114 scoped_refptr<cc::Layer> ContentLayer::layer() { 129 scoped_refptr<cc::Layer> ContentLayer::layer() {
115 return layer_; 130 return layer_;
116 } 131 }
117 132
118 ContentLayer::ContentLayer(TabContentManager* tab_content_manager) 133 ContentLayer::ContentLayer(TabContentManager* tab_content_manager)
119 : layer_(cc::Layer::Create()), 134 : layer_(cc::Layer::Create()),
120 tab_content_manager_(tab_content_manager) {} 135 tab_content_manager_(tab_content_manager) {}
121 136
122 ContentLayer::~ContentLayer() { 137 ContentLayer::~ContentLayer() {
123 } 138 }
124 139
125 } // namespace android 140 } // namespace android
OLDNEW
« no previous file with comments | « chrome/browser/android/compositor/layer/content_layer.h ('k') | chrome/browser/android/compositor/layer/tab_layer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698