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