Chromium Code Reviews| 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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 thumb_resource_.reset(); | 162 thumb_resource_.reset(); |
| 163 } | 163 } |
| 164 | 164 |
| 165 ContentsScalingLayer::SetLayerTreeHost(host); | 165 ContentsScalingLayer::SetLayerTreeHost(host); |
| 166 } | 166 } |
| 167 | 167 |
| 168 gfx::Rect PaintedScrollbarLayer::ScrollbarLayerRectToContentRect( | 168 gfx::Rect PaintedScrollbarLayer::ScrollbarLayerRectToContentRect( |
| 169 const gfx::Rect& layer_rect) const { | 169 const gfx::Rect& layer_rect) const { |
| 170 // Don't intersect with the bounds as in LayerRectToContentRect() because | 170 // Don't intersect with the bounds as in LayerRectToContentRect() because |
| 171 // layer_rect here might be in coordinates of the containing layer. | 171 // layer_rect here might be in coordinates of the containing layer. |
| 172 gfx::Rect expanded_rect = gfx::ScaleToEnclosingRect( | 172 gfx::Rect expanded_rect = gfx::ScaleToEnclosedRect( |
|
danakj
2014/02/10 19:17:28
I don't believe this is correct.
Say you have a s
| |
| 173 layer_rect, contents_scale_y(), contents_scale_y()); | 173 layer_rect, contents_scale_y(), contents_scale_y()); |
| 174 // We should never return a rect bigger than the content_bounds(). | 174 // We should never return a rect bigger than the content_bounds(). |
| 175 gfx::Size clamped_size = expanded_rect.size(); | 175 gfx::Size clamped_size = expanded_rect.size(); |
| 176 clamped_size.SetToMin(content_bounds()); | 176 clamped_size.SetToMin(content_bounds()); |
| 177 expanded_rect.set_size(clamped_size); | 177 expanded_rect.set_size(clamped_size); |
| 178 return expanded_rect; | 178 return expanded_rect; |
| 179 } | 179 } |
| 180 | 180 |
| 181 gfx::Rect PaintedScrollbarLayer::OriginThumbRect() const { | 181 gfx::Rect PaintedScrollbarLayer::OriginThumbRect() const { |
| 182 gfx::Size thumb_size; | 182 gfx::Size thumb_size; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 | 241 |
| 242 SkBitmap skbitmap; | 242 SkBitmap skbitmap; |
| 243 skbitmap.setConfig(SkBitmap::kARGB_8888_Config, rect.width(), rect.height()); | 243 skbitmap.setConfig(SkBitmap::kARGB_8888_Config, rect.width(), rect.height()); |
| 244 skbitmap.allocPixels(); | 244 skbitmap.allocPixels(); |
| 245 | 245 |
| 246 SkCanvas skcanvas(skbitmap); | 246 SkCanvas skcanvas(skbitmap); |
| 247 skcanvas.translate(SkFloatToScalar(-rect.x()), SkFloatToScalar(-rect.y())); | 247 skcanvas.translate(SkFloatToScalar(-rect.x()), SkFloatToScalar(-rect.y())); |
| 248 skcanvas.scale(SkFloatToScalar(contents_scale_x()), | 248 skcanvas.scale(SkFloatToScalar(contents_scale_x()), |
| 249 SkFloatToScalar(contents_scale_y())); | 249 SkFloatToScalar(contents_scale_y())); |
| 250 | 250 |
| 251 // Since rect is an enclosed rect around the scaled layer_rect, we must take | |
| 252 // the enclosing rect when unscaling so we don't lose a pixel in truncation. | |
| 251 gfx::Rect layer_rect = gfx::ScaleToEnclosingRect( | 253 gfx::Rect layer_rect = gfx::ScaleToEnclosingRect( |
|
danakj
2014/02/10 19:17:28
It seems like this one is the one we should switch
danakj
2014/02/10 19:19:37
A possible nice change would be to pass in the lay
bokan
2014/02/11 00:01:53
If the one above is enclosed then it can be clippe
| |
| 252 rect, 1.f / contents_scale_x(), 1.f / contents_scale_y()); | 254 rect, 1.f / contents_scale_x(), 1.f / contents_scale_y()); |
| 253 SkRect layer_skrect = RectToSkRect(layer_rect); | 255 SkRect layer_skrect = RectToSkRect(layer_rect); |
| 254 SkPaint paint; | 256 SkPaint paint; |
| 255 paint.setAntiAlias(false); | 257 paint.setAntiAlias(false); |
| 256 paint.setXfermodeMode(SkXfermode::kClear_Mode); | 258 paint.setXfermodeMode(SkXfermode::kClear_Mode); |
| 257 skcanvas.drawRect(layer_skrect, paint); | 259 skcanvas.drawRect(layer_skrect, paint); |
| 258 skcanvas.clipRect(layer_skrect); | 260 skcanvas.clipRect(layer_skrect); |
| 259 | 261 |
| 260 scrollbar_->PaintPart(&skcanvas, part, layer_rect); | 262 scrollbar_->PaintPart(&skcanvas, part, layer_rect); |
| 261 // Make sure that the pixels are no longer mutable to unavoid unnecessary | 263 // Make sure that the pixels are no longer mutable to unavoid unnecessary |
| 262 // allocation and copying. | 264 // allocation and copying. |
| 263 skbitmap.setImmutable(); | 265 skbitmap.setImmutable(); |
| 264 | 266 |
| 265 return UIResourceBitmap(skbitmap); | 267 return UIResourceBitmap(skbitmap); |
| 266 } | 268 } |
| 267 | 269 |
| 268 } // namespace cc | 270 } // namespace cc |
| OLD | NEW |