OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "cc/layers/scrollbar_layer.h" | 5 #include "cc/layers/scrollbar_layer.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "cc/layers/scrollbar_layer_impl.h" | 10 #include "cc/layers/scrollbar_layer_impl.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 scoped_refptr<ScrollbarLayer> ScrollbarLayer::Create( | 29 scoped_refptr<ScrollbarLayer> ScrollbarLayer::Create( |
30 scoped_ptr<Scrollbar> scrollbar, | 30 scoped_ptr<Scrollbar> scrollbar, |
31 int scroll_layer_id) { | 31 int scroll_layer_id) { |
32 return make_scoped_refptr( | 32 return make_scoped_refptr( |
33 new ScrollbarLayer(scrollbar.Pass(), scroll_layer_id)); | 33 new ScrollbarLayer(scrollbar.Pass(), scroll_layer_id)); |
34 } | 34 } |
35 | 35 |
36 ScrollbarLayer::ScrollbarLayer( | 36 ScrollbarLayer::ScrollbarLayer( |
37 scoped_ptr<Scrollbar> scrollbar, | 37 scoped_ptr<Scrollbar> scrollbar, |
38 int scroll_layer_id) | 38 int scroll_layer_id) |
39 : scrollbar_(scrollbar.Pass()), | 39 : scroll_layer_id_(scroll_layer_id), |
40 scroll_layer_id_(scroll_layer_id) { | 40 scrollbar_(scrollbar.Pass()) { |
41 if (!scrollbar_->IsOverlay()) | 41 if (!scrollbar_->IsOverlay()) |
42 SetShouldScrollOnMainThread(true); | 42 SetShouldScrollOnMainThread(true); |
43 } | 43 } |
44 | 44 |
45 ScrollbarLayer::~ScrollbarLayer() {} | 45 ScrollbarLayer::~ScrollbarLayer() {} |
46 | 46 |
47 void ScrollbarLayer::SetScrollLayerId(int id) { | 47 void ScrollbarLayer::SetScrollLayerId(int id) { |
48 if (id == scroll_layer_id_) | 48 if (id == scroll_layer_id_) |
49 return; | 49 return; |
50 | 50 |
51 scroll_layer_id_ = id; | 51 scroll_layer_id_ = id; |
52 SetNeedsFullTreeSync(); | 52 SetNeedsFullTreeSync(); |
53 } | 53 } |
54 | 54 |
55 bool ScrollbarLayer::OpacityCanAnimateOnImplThread() const { | 55 bool ScrollbarLayer::OpacityCanAnimateOnImplThread() const { |
56 return scrollbar_->IsOverlay(); | 56 return scrollbar_->IsOverlay(); |
57 } | 57 } |
58 | 58 |
59 ScrollbarOrientation ScrollbarLayer::Orientation() const { | 59 ScrollbarLayerInterface* ScrollbarLayer::ToScrollbarLayer() { |
60 return scrollbar_->Orientation(); | 60 return this; |
61 } | 61 } |
62 | 62 |
63 int ScrollbarLayer::MaxTextureSize() { | 63 int ScrollbarLayer::MaxTextureSize() { |
64 DCHECK(layer_tree_host()); | 64 DCHECK(layer_tree_host()); |
65 return layer_tree_host()->GetRendererCapabilities().max_texture_size; | 65 return layer_tree_host()->GetRendererCapabilities().max_texture_size; |
66 } | 66 } |
67 | 67 |
| 68 int ScrollbarLayer::ScrollLayerId() const { |
| 69 return scroll_layer_id_; |
| 70 } |
| 71 |
| 72 ScrollbarOrientation ScrollbarLayer::orientation() const { |
| 73 return scrollbar_->Orientation(); |
| 74 } |
| 75 |
68 float ScrollbarLayer::ClampScaleToMaxTextureSize(float scale) { | 76 float ScrollbarLayer::ClampScaleToMaxTextureSize(float scale) { |
69 if (layer_tree_host()->settings().solid_color_scrollbars) | |
70 return scale; | |
71 | |
72 // If the scaled content_bounds() is bigger than the max texture size of the | 77 // If the scaled content_bounds() is bigger than the max texture size of the |
73 // device, we need to clamp it by rescaling, since content_bounds() is used | 78 // device, we need to clamp it by rescaling, since content_bounds() is used |
74 // below to set the texture size. | 79 // below to set the texture size. |
75 gfx::Size scaled_bounds = ComputeContentBoundsForScale(scale, scale); | 80 gfx::Size scaled_bounds = ComputeContentBoundsForScale(scale, scale); |
76 if (scaled_bounds.width() > MaxTextureSize() || | 81 if (scaled_bounds.width() > MaxTextureSize() || |
77 scaled_bounds.height() > MaxTextureSize()) { | 82 scaled_bounds.height() > MaxTextureSize()) { |
78 if (scaled_bounds.width() > scaled_bounds.height()) | 83 if (scaled_bounds.width() > scaled_bounds.height()) |
79 return (MaxTextureSize() - 1) / static_cast<float>(bounds().width()); | 84 return (MaxTextureSize() - 1) / static_cast<float>(bounds().width()); |
80 else | 85 else |
81 return (MaxTextureSize() - 1) / static_cast<float>(bounds().height()); | 86 return (MaxTextureSize() - 1) / static_cast<float>(bounds().height()); |
(...skipping 16 matching lines...) Expand all Loading... |
98 contents_scale_x, | 103 contents_scale_x, |
99 contents_scale_y, | 104 contents_scale_y, |
100 content_bounds); | 105 content_bounds); |
101 } | 106 } |
102 | 107 |
103 void ScrollbarLayer::PushPropertiesTo(LayerImpl* layer) { | 108 void ScrollbarLayer::PushPropertiesTo(LayerImpl* layer) { |
104 ContentsScalingLayer::PushPropertiesTo(layer); | 109 ContentsScalingLayer::PushPropertiesTo(layer); |
105 | 110 |
106 ScrollbarLayerImpl* scrollbar_layer = static_cast<ScrollbarLayerImpl*>(layer); | 111 ScrollbarLayerImpl* scrollbar_layer = static_cast<ScrollbarLayerImpl*>(layer); |
107 | 112 |
108 if (layer_tree_host() && | 113 scrollbar_layer->SetThumbThickness(thumb_thickness_); |
109 layer_tree_host()->settings().solid_color_scrollbars) { | |
110 int thickness_override = | |
111 layer_tree_host()->settings().solid_color_scrollbar_thickness_dip; | |
112 if (thickness_override != -1) { | |
113 scrollbar_layer->SetThumbThickness(thickness_override); | |
114 } else { | |
115 if (Orientation() == HORIZONTAL) | |
116 scrollbar_layer->SetThumbThickness(bounds().height()); | |
117 else | |
118 scrollbar_layer->SetThumbThickness(bounds().width()); | |
119 } | |
120 } else { | |
121 scrollbar_layer->SetThumbThickness(thumb_thickness_); | |
122 } | |
123 scrollbar_layer->SetThumbLength(thumb_length_); | 114 scrollbar_layer->SetThumbLength(thumb_length_); |
124 if (Orientation() == HORIZONTAL) { | 115 if (orientation() == HORIZONTAL) { |
125 scrollbar_layer->SetTrackStart(track_rect_.x()); | 116 scrollbar_layer->SetTrackStart(track_rect_.x()); |
126 scrollbar_layer->SetTrackLength(track_rect_.width()); | 117 scrollbar_layer->SetTrackLength(track_rect_.width()); |
127 } else { | 118 } else { |
128 scrollbar_layer->SetTrackStart(track_rect_.y()); | 119 scrollbar_layer->SetTrackStart(track_rect_.y()); |
129 scrollbar_layer->SetTrackLength(track_rect_.height()); | 120 scrollbar_layer->SetTrackLength(track_rect_.height()); |
130 } | 121 } |
131 | 122 |
132 if (track_resource_.get()) | 123 if (track_resource_.get()) |
133 scrollbar_layer->set_track_ui_resource_id(track_resource_->id()); | 124 scrollbar_layer->set_track_ui_resource_id(track_resource_->id()); |
134 if (thumb_resource_.get()) | 125 if (thumb_resource_.get()) |
135 scrollbar_layer->set_thumb_ui_resource_id(thumb_resource_->id()); | 126 scrollbar_layer->set_thumb_ui_resource_id(thumb_resource_->id()); |
136 | 127 |
137 scrollbar_layer->set_is_overlay_scrollbar(scrollbar_->IsOverlay()); | 128 scrollbar_layer->set_is_overlay_scrollbar(scrollbar_->IsOverlay()); |
138 | 129 |
139 // ScrollbarLayer must push properties every frame. crbug.com/259095 | 130 // ScrollbarLayer must push properties every frame. crbug.com/259095 |
140 needs_push_properties_ = true; | 131 needs_push_properties_ = true; |
141 } | 132 } |
142 | 133 |
143 ScrollbarLayer* ScrollbarLayer::ToScrollbarLayer() { | |
144 return this; | |
145 } | |
146 | |
147 void ScrollbarLayer::SetLayerTreeHost(LayerTreeHost* host) { | 134 void ScrollbarLayer::SetLayerTreeHost(LayerTreeHost* host) { |
148 // When the LTH is set to null or has changed, then this layer should remove | 135 // When the LTH is set to null or has changed, then this layer should remove |
149 // all of its associated resources. | 136 // all of its associated resources. |
150 if (!host || host != layer_tree_host()) { | 137 if (!host || host != layer_tree_host()) { |
151 track_resource_.reset(); | 138 track_resource_.reset(); |
152 thumb_resource_.reset(); | 139 thumb_resource_.reset(); |
153 } | 140 } |
154 | 141 |
155 ContentsScalingLayer::SetLayerTreeHost(host); | 142 ContentsScalingLayer::SetLayerTreeHost(host); |
156 } | 143 } |
157 | 144 |
158 gfx::Rect ScrollbarLayer::ScrollbarLayerRectToContentRect( | 145 gfx::Rect ScrollbarLayer::ScrollbarLayerRectToContentRect( |
159 gfx::Rect layer_rect) const { | 146 gfx::Rect layer_rect) const { |
160 // Don't intersect with the bounds as in LayerRectToContentRect() because | 147 // Don't intersect with the bounds as in LayerRectToContentRect() because |
161 // layer_rect here might be in coordinates of the containing layer. | 148 // layer_rect here might be in coordinates of the containing layer. |
162 gfx::Rect expanded_rect = gfx::ScaleToEnclosingRect( | 149 gfx::Rect expanded_rect = gfx::ScaleToEnclosingRect( |
163 layer_rect, contents_scale_y(), contents_scale_y()); | 150 layer_rect, contents_scale_y(), contents_scale_y()); |
164 // We should never return a rect bigger than the content_bounds(). | 151 // We should never return a rect bigger than the content_bounds(). |
165 gfx::Size clamped_size = expanded_rect.size(); | 152 gfx::Size clamped_size = expanded_rect.size(); |
166 clamped_size.SetToMin(content_bounds()); | 153 clamped_size.SetToMin(content_bounds()); |
167 expanded_rect.set_size(clamped_size); | 154 expanded_rect.set_size(clamped_size); |
168 return expanded_rect; | 155 return expanded_rect; |
169 } | 156 } |
170 | 157 |
171 gfx::Rect ScrollbarLayer::OriginThumbRect() const { | 158 gfx::Rect ScrollbarLayer::OriginThumbRect() const { |
172 gfx::Size thumb_size; | 159 gfx::Size thumb_size; |
173 if (Orientation() == HORIZONTAL) { | 160 if (orientation() == HORIZONTAL) { |
174 thumb_size = | 161 thumb_size = |
175 gfx::Size(scrollbar_->ThumbLength(), scrollbar_->ThumbThickness()); | 162 gfx::Size(scrollbar_->ThumbLength(), scrollbar_->ThumbThickness()); |
176 } else { | 163 } else { |
177 thumb_size = | 164 thumb_size = |
178 gfx::Size(scrollbar_->ThumbThickness(), scrollbar_->ThumbLength()); | 165 gfx::Size(scrollbar_->ThumbThickness(), scrollbar_->ThumbLength()); |
179 } | 166 } |
180 return ScrollbarLayerRectToContentRect(gfx::Rect(thumb_size)); | 167 return ScrollbarLayerRectToContentRect(gfx::Rect(thumb_size)); |
181 } | 168 } |
182 | 169 |
183 bool ScrollbarLayer::Update(ResourceUpdateQueue* queue, | 170 bool ScrollbarLayer::Update(ResourceUpdateQueue* queue, |
184 const OcclusionTracker* occlusion) { | 171 const OcclusionTracker* occlusion) { |
185 track_rect_ = scrollbar_->TrackRect(); | 172 track_rect_ = scrollbar_->TrackRect(); |
186 gfx::Rect scaled_track_rect = ScrollbarLayerRectToContentRect( | 173 gfx::Rect scaled_track_rect = ScrollbarLayerRectToContentRect( |
187 gfx::Rect(scrollbar_->Location(), bounds())); | 174 gfx::Rect(scrollbar_->Location(), bounds())); |
188 | 175 |
189 if (layer_tree_host()->settings().solid_color_scrollbars || | 176 if (track_rect_.IsEmpty() || scaled_track_rect.IsEmpty()) |
190 track_rect_.IsEmpty() || scaled_track_rect.IsEmpty()) | |
191 return false; | 177 return false; |
192 | 178 |
193 { | 179 { |
194 base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_, | 180 base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_, |
195 true); | 181 true); |
196 ContentsScalingLayer::Update(queue, occlusion); | 182 ContentsScalingLayer::Update(queue, occlusion); |
197 } | 183 } |
198 | 184 |
199 track_resource_ = ScopedUIResource::Create( | 185 track_resource_ = ScopedUIResource::Create( |
200 layer_tree_host(), RasterizeScrollbarPart(scaled_track_rect, TRACK)); | 186 layer_tree_host(), RasterizeScrollbarPart(scaled_track_rect, TRACK)); |
201 gfx::Rect thumb_rect = OriginThumbRect(); | 187 gfx::Rect thumb_rect = OriginThumbRect(); |
202 | 188 |
203 if (scrollbar_->HasThumb() && !thumb_rect.IsEmpty()) { | 189 if (scrollbar_->HasThumb() && !thumb_rect.IsEmpty()) { |
204 thumb_thickness_ = scrollbar_->ThumbThickness(); | 190 thumb_thickness_ = scrollbar_->ThumbThickness(); |
205 thumb_length_ = scrollbar_->ThumbLength(); | 191 thumb_length_ = scrollbar_->ThumbLength(); |
206 thumb_resource_ = ScopedUIResource::Create( | 192 thumb_resource_ = ScopedUIResource::Create( |
207 layer_tree_host(), RasterizeScrollbarPart(thumb_rect, THUMB)); | 193 layer_tree_host(), RasterizeScrollbarPart(thumb_rect, THUMB)); |
208 } | 194 } |
209 | 195 |
210 return true; | 196 return true; |
211 } | 197 } |
212 | 198 |
213 scoped_refptr<UIResourceBitmap> ScrollbarLayer::RasterizeScrollbarPart( | 199 scoped_refptr<UIResourceBitmap> ScrollbarLayer::RasterizeScrollbarPart( |
214 gfx::Rect rect, | 200 gfx::Rect rect, |
215 ScrollbarPart part) { | 201 ScrollbarPart part) { |
216 DCHECK(!layer_tree_host()->settings().solid_color_scrollbars); | |
217 DCHECK(!rect.size().IsEmpty()); | 202 DCHECK(!rect.size().IsEmpty()); |
218 | 203 |
219 scoped_refptr<UIResourceBitmap> bitmap = | 204 scoped_refptr<UIResourceBitmap> bitmap = |
220 UIResourceBitmap::Create(new uint8_t[rect.width() * rect.height() * 4], | 205 UIResourceBitmap::Create(new uint8_t[rect.width() * rect.height() * 4], |
221 UIResourceBitmap::RGBA8, | 206 UIResourceBitmap::RGBA8, |
222 rect.size()); | 207 rect.size()); |
223 | 208 |
224 SkBitmap skbitmap; | 209 SkBitmap skbitmap; |
225 skbitmap.setConfig(SkBitmap::kARGB_8888_Config, rect.width(), rect.height()); | 210 skbitmap.setConfig(SkBitmap::kARGB_8888_Config, rect.width(), rect.height()); |
226 skbitmap.setPixels(bitmap->GetPixels()); | 211 skbitmap.setPixels(bitmap->GetPixels()); |
(...skipping 11 matching lines...) Expand all Loading... |
238 paint.setXfermodeMode(SkXfermode::kClear_Mode); | 223 paint.setXfermodeMode(SkXfermode::kClear_Mode); |
239 skcanvas.drawRect(layer_skrect, paint); | 224 skcanvas.drawRect(layer_skrect, paint); |
240 skcanvas.clipRect(layer_skrect); | 225 skcanvas.clipRect(layer_skrect); |
241 | 226 |
242 scrollbar_->PaintPart(&skcanvas, part, layer_rect); | 227 scrollbar_->PaintPart(&skcanvas, part, layer_rect); |
243 | 228 |
244 return bitmap; | 229 return bitmap; |
245 } | 230 } |
246 | 231 |
247 } // namespace cc | 232 } // namespace cc |
OLD | NEW |