OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/painted_scrollbar_layer.h" | 5 #include "cc/layers/painted_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/painted_scrollbar_layer_impl.h" | 10 #include "cc/layers/painted_scrollbar_layer_impl.h" |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 // all of its associated resources. | 141 // all of its associated resources. |
142 if (!host || host != layer_tree_host()) { | 142 if (!host || host != layer_tree_host()) { |
143 track_resource_.reset(); | 143 track_resource_.reset(); |
144 thumb_resource_.reset(); | 144 thumb_resource_.reset(); |
145 } | 145 } |
146 | 146 |
147 ContentsScalingLayer::SetLayerTreeHost(host); | 147 ContentsScalingLayer::SetLayerTreeHost(host); |
148 } | 148 } |
149 | 149 |
150 gfx::Rect PaintedScrollbarLayer::ScrollbarLayerRectToContentRect( | 150 gfx::Rect PaintedScrollbarLayer::ScrollbarLayerRectToContentRect( |
151 gfx::Rect layer_rect) const { | 151 const gfx::Rect& layer_rect) const { |
152 // Don't intersect with the bounds as in LayerRectToContentRect() because | 152 // Don't intersect with the bounds as in LayerRectToContentRect() because |
153 // layer_rect here might be in coordinates of the containing layer. | 153 // layer_rect here might be in coordinates of the containing layer. |
154 gfx::Rect expanded_rect = gfx::ScaleToEnclosingRect( | 154 gfx::Rect expanded_rect = gfx::ScaleToEnclosingRect( |
155 layer_rect, contents_scale_y(), contents_scale_y()); | 155 layer_rect, contents_scale_y(), contents_scale_y()); |
156 // We should never return a rect bigger than the content_bounds(). | 156 // We should never return a rect bigger than the content_bounds(). |
157 gfx::Size clamped_size = expanded_rect.size(); | 157 gfx::Size clamped_size = expanded_rect.size(); |
158 clamped_size.SetToMin(content_bounds()); | 158 clamped_size.SetToMin(content_bounds()); |
159 expanded_rect.set_size(clamped_size); | 159 expanded_rect.set_size(clamped_size); |
160 return expanded_rect; | 160 return expanded_rect; |
161 } | 161 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 thumb_resource_ = ScopedUIResource::Create( | 210 thumb_resource_ = ScopedUIResource::Create( |
211 layer_tree_host(), RasterizeScrollbarPart(thumb_rect, THUMB)); | 211 layer_tree_host(), RasterizeScrollbarPart(thumb_rect, THUMB)); |
212 } | 212 } |
213 | 213 |
214 // UI resources changed so push properties is needed. | 214 // UI resources changed so push properties is needed. |
215 SetNeedsPushProperties(); | 215 SetNeedsPushProperties(); |
216 return true; | 216 return true; |
217 } | 217 } |
218 | 218 |
219 UIResourceBitmap PaintedScrollbarLayer::RasterizeScrollbarPart( | 219 UIResourceBitmap PaintedScrollbarLayer::RasterizeScrollbarPart( |
220 gfx::Rect rect, | 220 const gfx::Rect& rect, |
221 ScrollbarPart part) { | 221 ScrollbarPart part) { |
222 DCHECK(!rect.size().IsEmpty()); | 222 DCHECK(!rect.size().IsEmpty()); |
223 | 223 |
224 SkBitmap skbitmap; | 224 SkBitmap skbitmap; |
225 skbitmap.setConfig(SkBitmap::kARGB_8888_Config, rect.width(), rect.height()); | 225 skbitmap.setConfig(SkBitmap::kARGB_8888_Config, rect.width(), rect.height()); |
226 skbitmap.allocPixels(); | 226 skbitmap.allocPixels(); |
227 | 227 |
228 SkCanvas skcanvas(skbitmap); | 228 SkCanvas skcanvas(skbitmap); |
229 skcanvas.translate(SkFloatToScalar(-rect.x()), SkFloatToScalar(-rect.y())); | 229 skcanvas.translate(SkFloatToScalar(-rect.x()), SkFloatToScalar(-rect.y())); |
230 skcanvas.scale(SkFloatToScalar(contents_scale_x()), | 230 skcanvas.scale(SkFloatToScalar(contents_scale_x()), |
(...skipping 10 matching lines...) Expand all Loading... |
241 | 241 |
242 scrollbar_->PaintPart(&skcanvas, part, layer_rect); | 242 scrollbar_->PaintPart(&skcanvas, part, layer_rect); |
243 // Make sure that the pixels are no longer mutable to unavoid unnecessary | 243 // Make sure that the pixels are no longer mutable to unavoid unnecessary |
244 // allocation and copying. | 244 // allocation and copying. |
245 skbitmap.setImmutable(); | 245 skbitmap.setImmutable(); |
246 | 246 |
247 return UIResourceBitmap(skbitmap); | 247 return UIResourceBitmap(skbitmap); |
248 } | 248 } |
249 | 249 |
250 } // namespace cc | 250 } // namespace cc |
OLD | NEW |