| 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" |
| 11 #include "cc/layer_painter.h" | 11 #include "cc/layer_painter.h" |
| 12 #include "cc/layer_tree_host.h" | 12 #include "cc/layer_tree_host.h" |
| 13 #include "cc/scrollbar_layer_impl.h" | 13 #include "cc/scrollbar_layer_impl.h" |
| 14 #include "cc/texture_update_queue.h" | 14 #include "cc/texture_update_queue.h" |
| 15 #include "ui/gfx/size_conversions.h" |
| 15 #include <public/WebRect.h> | 16 #include <public/WebRect.h> |
| 16 | 17 |
| 17 using WebKit::WebRect; | 18 using WebKit::WebRect; |
| 18 | 19 |
| 19 namespace cc { | 20 namespace cc { |
| 20 | 21 |
| 21 scoped_ptr<LayerImpl> ScrollbarLayer::createLayerImpl() | 22 scoped_ptr<LayerImpl> ScrollbarLayer::createLayerImpl() |
| 22 { | 23 { |
| 23 return ScrollbarLayerImpl::create(id()).PassAs<LayerImpl>(); | 24 return ScrollbarLayerImpl::create(id()).PassAs<LayerImpl>(); |
| 24 } | 25 } |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 WebKit::WebScrollbar::ScrollbarPart m_trackPart; | 129 WebKit::WebScrollbar::ScrollbarPart m_trackPart; |
| 129 | 130 |
| 130 DISALLOW_COPY_AND_ASSIGN(ScrollbarBackgroundPainter); | 131 DISALLOW_COPY_AND_ASSIGN(ScrollbarBackgroundPainter); |
| 131 }; | 132 }; |
| 132 | 133 |
| 133 bool ScrollbarLayer::needsContentsScale() const | 134 bool ScrollbarLayer::needsContentsScale() const |
| 134 { | 135 { |
| 135 return true; | 136 return true; |
| 136 } | 137 } |
| 137 | 138 |
| 138 IntSize ScrollbarLayer::contentBounds() const | 139 gfx::Size ScrollbarLayer::contentBounds() const |
| 139 { | 140 { |
| 140 return IntSize(lroundf(bounds().width() * contentsScale()), lroundf(bounds()
.height() * contentsScale())); | 141 return gfx::ToRoundedSize(bounds().Scale(contentsScale())); |
| 141 } | 142 } |
| 142 | 143 |
| 143 class ScrollbarThumbPainter : public LayerPainter { | 144 class ScrollbarThumbPainter : public LayerPainter { |
| 144 public: | 145 public: |
| 145 static scoped_ptr<ScrollbarThumbPainter> create(WebKit::WebScrollbar* scroll
bar, WebKit::WebScrollbarThemePainter painter, WebKit::WebScrollbarThemeGeometry
* geometry) | 146 static scoped_ptr<ScrollbarThumbPainter> create(WebKit::WebScrollbar* scroll
bar, WebKit::WebScrollbarThemePainter painter, WebKit::WebScrollbarThemeGeometry
* geometry) |
| 146 { | 147 { |
| 147 return make_scoped_ptr(new ScrollbarThumbPainter(scrollbar, painter, geo
metry)); | 148 return make_scoped_ptr(new ScrollbarThumbPainter(scrollbar, painter, geo
metry)); |
| 148 } | 149 } |
| 149 | 150 |
| 150 virtual void paint(SkCanvas* skCanvas, const gfx::Rect& contentRect, gfx::Re
ctF& opaque) OVERRIDE | 151 virtual void paint(SkCanvas* skCanvas, const gfx::Rect& contentRect, gfx::Re
ctF& opaque) OVERRIDE |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 if (!m_foreTrack) | 202 if (!m_foreTrack) |
| 202 m_foreTrack = m_foreTrackUpdater->createResource(layerTreeHost()->co
ntentsTextureManager()); | 203 m_foreTrack = m_foreTrackUpdater->createResource(layerTreeHost()->co
ntentsTextureManager()); |
| 203 } | 204 } |
| 204 | 205 |
| 205 if (!m_thumbUpdater) | 206 if (!m_thumbUpdater) |
| 206 m_thumbUpdater = CachingBitmapCanvasLayerUpdater::Create(ScrollbarThumbP
ainter::create(m_scrollbar.get(), m_painter, m_geometry.get()).PassAs<LayerPaint
er>()); | 207 m_thumbUpdater = CachingBitmapCanvasLayerUpdater::Create(ScrollbarThumbP
ainter::create(m_scrollbar.get(), m_painter, m_geometry.get()).PassAs<LayerPaint
er>()); |
| 207 if (!m_thumb) | 208 if (!m_thumb) |
| 208 m_thumb = m_thumbUpdater->createResource(layerTreeHost()->contentsTextur
eManager()); | 209 m_thumb = m_thumbUpdater->createResource(layerTreeHost()->contentsTextur
eManager()); |
| 209 } | 210 } |
| 210 | 211 |
| 211 void ScrollbarLayer::updatePart(CachingBitmapCanvasLayerUpdater* painter, LayerU
pdater::Resource* texture, const IntRect& rect, TextureUpdateQueue& queue, Rende
ringStats& stats) | 212 void ScrollbarLayer::updatePart(CachingBitmapCanvasLayerUpdater* painter, LayerU
pdater::Resource* texture, const gfx::Rect& rect, TextureUpdateQueue& queue, Ren
deringStats& stats) |
| 212 { | 213 { |
| 213 // Skip painting and uploading if there are no invalidations and | 214 // Skip painting and uploading if there are no invalidations and |
| 214 // we already have valid texture data. | 215 // we already have valid texture data. |
| 215 if (texture->texture()->haveBackingTexture() | 216 if (texture->texture()->haveBackingTexture() |
| 216 && texture->texture()->size() == rect.size() | 217 && texture->texture()->size() == rect.size() |
| 217 && m_updateRect.isEmpty()) | 218 && m_updateRect.IsEmpty()) |
| 218 return; | 219 return; |
| 219 | 220 |
| 220 // We should always have enough memory for UI. | 221 // We should always have enough memory for UI. |
| 221 DCHECK(texture->texture()->canAcquireBackingTexture()); | 222 DCHECK(texture->texture()->canAcquireBackingTexture()); |
| 222 if (!texture->texture()->canAcquireBackingTexture()) | 223 if (!texture->texture()->canAcquireBackingTexture()) |
| 223 return; | 224 return; |
| 224 | 225 |
| 225 // Paint and upload the entire part. | 226 // Paint and upload the entire part. |
| 226 float widthScale = static_cast<float>(contentBounds().width()) / bounds().wi
dth(); | 227 float widthScale = static_cast<float>(contentBounds().width()) / bounds().wi
dth(); |
| 227 float heightScale = static_cast<float>(contentBounds().height()) / bounds().
height(); | 228 float heightScale = static_cast<float>(contentBounds().height()) / bounds().
height(); |
| 228 gfx::Rect paintedOpaqueRect; | 229 gfx::Rect paintedOpaqueRect; |
| 229 painter->prepareToUpdate(rect, rect.size(), widthScale, heightScale, painted
OpaqueRect, stats); | 230 painter->prepareToUpdate(rect, rect.size(), widthScale, heightScale, painted
OpaqueRect, stats); |
| 230 if (!painter->pixelsDidChange() && texture->texture()->haveBackingTexture())
{ | 231 if (!painter->pixelsDidChange() && texture->texture()->haveBackingTexture())
{ |
| 231 TRACE_EVENT_INSTANT0("cc","ScrollbarLayer::updatePart no texture upload
needed"); | 232 TRACE_EVENT_INSTANT0("cc","ScrollbarLayer::updatePart no texture upload
needed"); |
| 232 return; | 233 return; |
| 233 } | 234 } |
| 234 | 235 |
| 235 gfx::Vector2d destOffset(0, 0); | 236 gfx::Vector2d destOffset(0, 0); |
| 236 texture->update(queue, rect, destOffset, false, stats); | 237 texture->update(queue, rect, destOffset, false, stats); |
| 237 } | 238 } |
| 238 | 239 |
| 239 | 240 |
| 240 void ScrollbarLayer::setTexturePriorities(const PriorityCalculator&) | 241 void ScrollbarLayer::setTexturePriorities(const PriorityCalculator&) |
| 241 { | 242 { |
| 242 if (contentBounds().isEmpty()) | 243 if (contentBounds().IsEmpty()) |
| 243 return; | 244 return; |
| 244 | 245 |
| 245 createUpdaterIfNeeded(); | 246 createUpdaterIfNeeded(); |
| 246 | 247 |
| 247 bool drawsToRoot = !renderTarget()->parent(); | 248 bool drawsToRoot = !renderTarget()->parent(); |
| 248 if (m_backTrack) { | 249 if (m_backTrack) { |
| 249 m_backTrack->texture()->setDimensions(contentBounds(), m_textureFormat); | 250 m_backTrack->texture()->setDimensions(contentBounds(), m_textureFormat); |
| 250 m_backTrack->texture()->setRequestPriority(PriorityCalculator::uiPriorit
y(drawsToRoot)); | 251 m_backTrack->texture()->setRequestPriority(PriorityCalculator::uiPriorit
y(drawsToRoot)); |
| 251 } | 252 } |
| 252 if (m_foreTrack) { | 253 if (m_foreTrack) { |
| 253 m_foreTrack->texture()->setDimensions(contentBounds(), m_textureFormat); | 254 m_foreTrack->texture()->setDimensions(contentBounds(), m_textureFormat); |
| 254 m_foreTrack->texture()->setRequestPriority(PriorityCalculator::uiPriorit
y(drawsToRoot)); | 255 m_foreTrack->texture()->setRequestPriority(PriorityCalculator::uiPriorit
y(drawsToRoot)); |
| 255 } | 256 } |
| 256 if (m_thumb) { | 257 if (m_thumb) { |
| 257 IntSize thumbSize = layerRectToContentRect(m_geometry->thumbRect(m_scrol
lbar.get())).size(); | 258 gfx::Size thumbSize = layerRectToContentRect(m_geometry->thumbRect(m_scr
ollbar.get())).size(); |
| 258 m_thumb->texture()->setDimensions(thumbSize, m_textureFormat); | 259 m_thumb->texture()->setDimensions(thumbSize, m_textureFormat); |
| 259 m_thumb->texture()->setRequestPriority(PriorityCalculator::uiPriority(dr
awsToRoot)); | 260 m_thumb->texture()->setRequestPriority(PriorityCalculator::uiPriority(dr
awsToRoot)); |
| 260 } | 261 } |
| 261 } | 262 } |
| 262 | 263 |
| 263 void ScrollbarLayer::update(TextureUpdateQueue& queue, const OcclusionTracker*,
RenderingStats& stats) | 264 void ScrollbarLayer::update(TextureUpdateQueue& queue, const OcclusionTracker*,
RenderingStats& stats) |
| 264 { | 265 { |
| 265 if (contentBounds().isEmpty()) | 266 if (contentBounds().IsEmpty()) |
| 266 return; | 267 return; |
| 267 | 268 |
| 268 createUpdaterIfNeeded(); | 269 createUpdaterIfNeeded(); |
| 269 | 270 |
| 270 IntPoint scrollbarOrigin(m_scrollbar->location().x, m_scrollbar->location().
y); | 271 gfx::Point scrollbarOrigin(m_scrollbar->location()); |
| 271 IntRect contentRect = layerRectToContentRect(WebKit::WebRect(scrollbarOrigin
.x(), scrollbarOrigin.y(), bounds().width(), bounds().height())); | 272 gfx::Rect contentRect = layerRectToContentRect(gfx::Rect(scrollbarOrigin, bo
unds())); |
| 272 updatePart(m_backTrackUpdater.get(), m_backTrack.get(), contentRect, queue,
stats); | 273 updatePart(m_backTrackUpdater.get(), m_backTrack.get(), contentRect, queue,
stats); |
| 273 if (m_foreTrack && m_foreTrackUpdater) | 274 if (m_foreTrack && m_foreTrackUpdater) |
| 274 updatePart(m_foreTrackUpdater.get(), m_foreTrack.get(), contentRect, que
ue, stats); | 275 updatePart(m_foreTrackUpdater.get(), m_foreTrack.get(), contentRect, que
ue, stats); |
| 275 | 276 |
| 276 // Consider the thumb to be at the origin when painting. | 277 // Consider the thumb to be at the origin when painting. |
| 277 WebKit::WebRect thumbRect = m_geometry->thumbRect(m_scrollbar.get()); | 278 WebKit::WebRect thumbRect = m_geometry->thumbRect(m_scrollbar.get()); |
| 278 IntRect originThumbRect = layerRectToContentRect(WebKit::WebRect(0, 0, thumb
Rect.width, thumbRect.height)); | 279 gfx::Rect originThumbRect = layerRectToContentRect(gfx::Rect(0, 0, thumbRect
.width, thumbRect.height)); |
| 279 if (!originThumbRect.isEmpty()) | 280 if (!originThumbRect.IsEmpty()) |
| 280 updatePart(m_thumbUpdater.get(), m_thumb.get(), originThumbRect, queue,
stats); | 281 updatePart(m_thumbUpdater.get(), m_thumb.get(), originThumbRect, queue,
stats); |
| 281 } | 282 } |
| 282 | 283 |
| 283 } | 284 } |
| OLD | NEW |