| 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 "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "cc/scrollbar_layer.h" | 7 #include "cc/scrollbar_layer.h" |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 , m_textureFormat(GL_INVALID_ENUM) | 36 , m_textureFormat(GL_INVALID_ENUM) |
| 37 { | 37 { |
| 38 } | 38 } |
| 39 | 39 |
| 40 ScrollbarLayer::~ScrollbarLayer() | 40 ScrollbarLayer::~ScrollbarLayer() |
| 41 { | 41 { |
| 42 } | 42 } |
| 43 | 43 |
| 44 void ScrollbarLayer::pushPropertiesTo(LayerImpl* layer) | 44 void ScrollbarLayer::pushPropertiesTo(LayerImpl* layer) |
| 45 { | 45 { |
| 46 Layer::pushPropertiesTo(layer); | 46 ContentsScalingLayer::pushPropertiesTo(layer); |
| 47 | 47 |
| 48 ScrollbarLayerImpl* scrollbarLayer = static_cast<ScrollbarLayerImpl*>(layer)
; | 48 ScrollbarLayerImpl* scrollbarLayer = static_cast<ScrollbarLayerImpl*>(layer)
; |
| 49 | 49 |
| 50 if (!scrollbarLayer->scrollbarGeometry()) | 50 if (!scrollbarLayer->scrollbarGeometry()) |
| 51 scrollbarLayer->setScrollbarGeometry(ScrollbarGeometryFixedThumb::create
(make_scoped_ptr(m_geometry->clone()))); | 51 scrollbarLayer->setScrollbarGeometry(ScrollbarGeometryFixedThumb::create
(make_scoped_ptr(m_geometry->clone()))); |
| 52 | 52 |
| 53 scrollbarLayer->setScrollbarData(m_scrollbar.get()); | 53 scrollbarLayer->setScrollbarData(m_scrollbar.get()); |
| 54 | 54 |
| 55 if (m_backTrack && m_backTrack->texture()->haveBackingTexture()) | 55 if (m_backTrack && m_backTrack->texture()->haveBackingTexture()) |
| 56 scrollbarLayer->setBackTrackResourceId(m_backTrack->texture()->resourceI
d()); | 56 scrollbarLayer->setBackTrackResourceId(m_backTrack->texture()->resourceI
d()); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 } | 124 } |
| 125 | 125 |
| 126 WebKit::WebScrollbar* m_scrollbar; | 126 WebKit::WebScrollbar* m_scrollbar; |
| 127 WebKit::WebScrollbarThemePainter m_painter; | 127 WebKit::WebScrollbarThemePainter m_painter; |
| 128 WebKit::WebScrollbarThemeGeometry* m_geometry; | 128 WebKit::WebScrollbarThemeGeometry* m_geometry; |
| 129 WebKit::WebScrollbar::ScrollbarPart m_trackPart; | 129 WebKit::WebScrollbar::ScrollbarPart m_trackPart; |
| 130 | 130 |
| 131 DISALLOW_COPY_AND_ASSIGN(ScrollbarBackgroundPainter); | 131 DISALLOW_COPY_AND_ASSIGN(ScrollbarBackgroundPainter); |
| 132 }; | 132 }; |
| 133 | 133 |
| 134 bool ScrollbarLayer::needsContentsScale() const | |
| 135 { | |
| 136 return true; | |
| 137 } | |
| 138 | |
| 139 IntSize ScrollbarLayer::contentBounds() const | |
| 140 { | |
| 141 return IntSize(lroundf(bounds().width() * contentsScale()), lroundf(bounds()
.height() * contentsScale())); | |
| 142 } | |
| 143 | |
| 144 class ScrollbarThumbPainter : public LayerPainter { | 134 class ScrollbarThumbPainter : public LayerPainter { |
| 145 public: | 135 public: |
| 146 static scoped_ptr<ScrollbarThumbPainter> create(WebKit::WebScrollbar* scroll
bar, WebKit::WebScrollbarThemePainter painter, WebKit::WebScrollbarThemeGeometry
* geometry) | 136 static scoped_ptr<ScrollbarThumbPainter> create(WebKit::WebScrollbar* scroll
bar, WebKit::WebScrollbarThemePainter painter, WebKit::WebScrollbarThemeGeometry
* geometry) |
| 147 { | 137 { |
| 148 return make_scoped_ptr(new ScrollbarThumbPainter(scrollbar, painter, geo
metry)); | 138 return make_scoped_ptr(new ScrollbarThumbPainter(scrollbar, painter, geo
metry)); |
| 149 } | 139 } |
| 150 | 140 |
| 151 virtual void paint(SkCanvas* skCanvas, const IntRect& contentRect, FloatRect
& opaque) OVERRIDE | 141 virtual void paint(SkCanvas* skCanvas, const IntRect& contentRect, FloatRect
& opaque) OVERRIDE |
| 152 { | 142 { |
| 153 WebKit::WebCanvas* canvas = skCanvas; | 143 WebKit::WebCanvas* canvas = skCanvas; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 176 | 166 |
| 177 void ScrollbarLayer::setLayerTreeHost(LayerTreeHost* host) | 167 void ScrollbarLayer::setLayerTreeHost(LayerTreeHost* host) |
| 178 { | 168 { |
| 179 if (!host || host != layerTreeHost()) { | 169 if (!host || host != layerTreeHost()) { |
| 180 m_backTrackUpdater = NULL; | 170 m_backTrackUpdater = NULL; |
| 181 m_backTrack.reset(); | 171 m_backTrack.reset(); |
| 182 m_thumbUpdater = NULL; | 172 m_thumbUpdater = NULL; |
| 183 m_thumb.reset(); | 173 m_thumb.reset(); |
| 184 } | 174 } |
| 185 | 175 |
| 186 Layer::setLayerTreeHost(host); | 176 ContentsScalingLayer::setLayerTreeHost(host); |
| 187 } | 177 } |
| 188 | 178 |
| 189 void ScrollbarLayer::createUpdaterIfNeeded() | 179 void ScrollbarLayer::createUpdaterIfNeeded() |
| 190 { | 180 { |
| 191 m_textureFormat = layerTreeHost()->rendererCapabilities().bestTextureFormat; | 181 m_textureFormat = layerTreeHost()->rendererCapabilities().bestTextureFormat; |
| 192 | 182 |
| 193 if (!m_backTrackUpdater) | 183 if (!m_backTrackUpdater) |
| 194 m_backTrackUpdater = CachingBitmapContentLayerUpdater::Create(ScrollbarB
ackgroundPainter::create(m_scrollbar.get(), m_painter, m_geometry.get(), WebKit:
:WebScrollbar::BackTrackPart).PassAs<LayerPainter>()); | 184 m_backTrackUpdater = CachingBitmapContentLayerUpdater::Create(ScrollbarB
ackgroundPainter::create(m_scrollbar.get(), m_painter, m_geometry.get(), WebKit:
:WebScrollbar::BackTrackPart).PassAs<LayerPainter>()); |
| 195 if (!m_backTrack) | 185 if (!m_backTrack) |
| 196 m_backTrack = m_backTrackUpdater->createResource(layerTreeHost()->conten
tsTextureManager()); | 186 m_backTrack = m_backTrackUpdater->createResource(layerTreeHost()->conten
tsTextureManager()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 217 && texture->texture()->size() == rect.size() | 207 && texture->texture()->size() == rect.size() |
| 218 && m_updateRect.isEmpty()) | 208 && m_updateRect.isEmpty()) |
| 219 return; | 209 return; |
| 220 | 210 |
| 221 // We should always have enough memory for UI. | 211 // We should always have enough memory for UI. |
| 222 DCHECK(texture->texture()->canAcquireBackingTexture()); | 212 DCHECK(texture->texture()->canAcquireBackingTexture()); |
| 223 if (!texture->texture()->canAcquireBackingTexture()) | 213 if (!texture->texture()->canAcquireBackingTexture()) |
| 224 return; | 214 return; |
| 225 | 215 |
| 226 // Paint and upload the entire part. | 216 // Paint and upload the entire part. |
| 227 float widthScale = static_cast<float>(contentBounds().width()) / bounds().wi
dth(); | |
| 228 float heightScale = static_cast<float>(contentBounds().height()) / bounds().
height(); | |
| 229 IntRect paintedOpaqueRect; | 217 IntRect paintedOpaqueRect; |
| 230 painter->prepareToUpdate(rect, rect.size(), widthScale, heightScale, painted
OpaqueRect, stats); | 218 painter->prepareToUpdate(rect, rect.size(), contentsScaleX(), contentsScaleY
(), paintedOpaqueRect, stats); |
| 231 if (!painter->pixelsDidChange() && texture->texture()->haveBackingTexture())
{ | 219 if (!painter->pixelsDidChange() && texture->texture()->haveBackingTexture())
{ |
| 232 TRACE_EVENT_INSTANT0("cc","ScrollbarLayer::updatePart no texture upload
needed"); | 220 TRACE_EVENT_INSTANT0("cc","ScrollbarLayer::updatePart no texture upload
needed"); |
| 233 return; | 221 return; |
| 234 } | 222 } |
| 235 | 223 |
| 236 IntSize destOffset(0, 0); | 224 IntSize destOffset(0, 0); |
| 237 texture->update(queue, rect, destOffset, false, stats); | 225 texture->update(queue, rect, destOffset, false, stats); |
| 238 } | 226 } |
| 239 | 227 |
| 240 | 228 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 updatePart(m_foreTrackUpdater.get(), m_foreTrack.get(), contentRect, que
ue, stats); | 263 updatePart(m_foreTrackUpdater.get(), m_foreTrack.get(), contentRect, que
ue, stats); |
| 276 | 264 |
| 277 // Consider the thumb to be at the origin when painting. | 265 // Consider the thumb to be at the origin when painting. |
| 278 WebKit::WebRect thumbRect = m_geometry->thumbRect(m_scrollbar.get()); | 266 WebKit::WebRect thumbRect = m_geometry->thumbRect(m_scrollbar.get()); |
| 279 IntRect originThumbRect = layerRectToContentRect(WebKit::WebRect(0, 0, thumb
Rect.width, thumbRect.height)); | 267 IntRect originThumbRect = layerRectToContentRect(WebKit::WebRect(0, 0, thumb
Rect.width, thumbRect.height)); |
| 280 if (!originThumbRect.isEmpty()) | 268 if (!originThumbRect.isEmpty()) |
| 281 updatePart(m_thumbUpdater.get(), m_thumb.get(), originThumbRect, queue,
stats); | 269 updatePart(m_thumbUpdater.get(), m_thumb.get(), originThumbRect, queue,
stats); |
| 282 } | 270 } |
| 283 | 271 |
| 284 } | 272 } |
| OLD | NEW |