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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 } | 123 } |
124 | 124 |
125 WebKit::WebScrollbar* m_scrollbar; | 125 WebKit::WebScrollbar* m_scrollbar; |
126 WebKit::WebScrollbarThemePainter m_painter; | 126 WebKit::WebScrollbarThemePainter m_painter; |
127 WebKit::WebScrollbarThemeGeometry* m_geometry; | 127 WebKit::WebScrollbarThemeGeometry* m_geometry; |
128 WebKit::WebScrollbar::ScrollbarPart m_trackPart; | 128 WebKit::WebScrollbar::ScrollbarPart m_trackPart; |
129 | 129 |
130 DISALLOW_COPY_AND_ASSIGN(ScrollbarBackgroundPainter); | 130 DISALLOW_COPY_AND_ASSIGN(ScrollbarBackgroundPainter); |
131 }; | 131 }; |
132 | 132 |
133 bool ScrollbarLayer::needsContentsScale() const | |
134 { | |
135 return true; | |
136 } | |
137 | |
138 IntSize ScrollbarLayer::contentBounds() const | |
139 { | |
140 return IntSize(lroundf(bounds().width() * contentsScale()), lroundf(bounds()
.height() * contentsScale())); | |
141 } | |
142 | |
143 class ScrollbarThumbPainter : public LayerPainter { | 133 class ScrollbarThumbPainter : public LayerPainter { |
144 public: | 134 public: |
145 static scoped_ptr<ScrollbarThumbPainter> create(WebKit::WebScrollbar* scroll
bar, WebKit::WebScrollbarThemePainter painter, WebKit::WebScrollbarThemeGeometry
* geometry) | 135 static scoped_ptr<ScrollbarThumbPainter> create(WebKit::WebScrollbar* scroll
bar, WebKit::WebScrollbarThemePainter painter, WebKit::WebScrollbarThemeGeometry
* geometry) |
146 { | 136 { |
147 return make_scoped_ptr(new ScrollbarThumbPainter(scrollbar, painter, geo
metry)); | 137 return make_scoped_ptr(new ScrollbarThumbPainter(scrollbar, painter, geo
metry)); |
148 } | 138 } |
149 | 139 |
150 virtual void paint(SkCanvas* skCanvas, const gfx::Rect& contentRect, gfx::Re
ctF& opaque) OVERRIDE | 140 virtual void paint(SkCanvas* skCanvas, const gfx::Rect& contentRect, gfx::Re
ctF& opaque) OVERRIDE |
151 { | 141 { |
152 WebKit::WebCanvas* canvas = skCanvas; | 142 WebKit::WebCanvas* canvas = skCanvas; |
(...skipping 22 matching lines...) Expand all Loading... |
175 | 165 |
176 void ScrollbarLayer::setLayerTreeHost(LayerTreeHost* host) | 166 void ScrollbarLayer::setLayerTreeHost(LayerTreeHost* host) |
177 { | 167 { |
178 if (!host || host != layerTreeHost()) { | 168 if (!host || host != layerTreeHost()) { |
179 m_backTrackUpdater = NULL; | 169 m_backTrackUpdater = NULL; |
180 m_backTrack.reset(); | 170 m_backTrack.reset(); |
181 m_thumbUpdater = NULL; | 171 m_thumbUpdater = NULL; |
182 m_thumb.reset(); | 172 m_thumb.reset(); |
183 } | 173 } |
184 | 174 |
185 Layer::setLayerTreeHost(host); | 175 ContentsScalingLayer::setLayerTreeHost(host); |
186 } | 176 } |
187 | 177 |
188 void ScrollbarLayer::createUpdaterIfNeeded() | 178 void ScrollbarLayer::createUpdaterIfNeeded() |
189 { | 179 { |
190 m_textureFormat = layerTreeHost()->rendererCapabilities().bestTextureFormat; | 180 m_textureFormat = layerTreeHost()->rendererCapabilities().bestTextureFormat; |
191 | 181 |
192 if (!m_backTrackUpdater) | 182 if (!m_backTrackUpdater) |
193 m_backTrackUpdater = CachingBitmapContentLayerUpdater::Create(ScrollbarB
ackgroundPainter::create(m_scrollbar.get(), m_painter, m_geometry.get(), WebKit:
:WebScrollbar::BackTrackPart).PassAs<LayerPainter>()); | 183 m_backTrackUpdater = CachingBitmapContentLayerUpdater::Create(ScrollbarB
ackgroundPainter::create(m_scrollbar.get(), m_painter, m_geometry.get(), WebKit:
:WebScrollbar::BackTrackPart).PassAs<LayerPainter>()); |
194 if (!m_backTrack) | 184 if (!m_backTrack) |
195 m_backTrack = m_backTrackUpdater->createResource(layerTreeHost()->conten
tsTextureManager()); | 185 m_backTrack = m_backTrackUpdater->createResource(layerTreeHost()->conten
tsTextureManager()); |
(...skipping 20 matching lines...) Expand all Loading... |
216 && texture->texture()->size() == rect.size() | 206 && texture->texture()->size() == rect.size() |
217 && m_updateRect.isEmpty()) | 207 && m_updateRect.isEmpty()) |
218 return; | 208 return; |
219 | 209 |
220 // We should always have enough memory for UI. | 210 // We should always have enough memory for UI. |
221 DCHECK(texture->texture()->canAcquireBackingTexture()); | 211 DCHECK(texture->texture()->canAcquireBackingTexture()); |
222 if (!texture->texture()->canAcquireBackingTexture()) | 212 if (!texture->texture()->canAcquireBackingTexture()) |
223 return; | 213 return; |
224 | 214 |
225 // Paint and upload the entire part. | 215 // Paint and upload the entire part. |
226 float widthScale = static_cast<float>(contentBounds().width()) / bounds().wi
dth(); | |
227 float heightScale = static_cast<float>(contentBounds().height()) / bounds().
height(); | |
228 gfx::Rect paintedOpaqueRect; | 216 gfx::Rect paintedOpaqueRect; |
229 painter->prepareToUpdate(rect, rect.size(), widthScale, heightScale, painted
OpaqueRect, stats); | 217 painter->prepareToUpdate(rect, rect.size(), contentsScaleX(), contentsScaleY
(), paintedOpaqueRect, stats); |
230 if (!painter->pixelsDidChange() && texture->texture()->haveBackingTexture())
{ | 218 if (!painter->pixelsDidChange() && texture->texture()->haveBackingTexture())
{ |
231 TRACE_EVENT_INSTANT0("cc","ScrollbarLayer::updatePart no texture upload
needed"); | 219 TRACE_EVENT_INSTANT0("cc","ScrollbarLayer::updatePart no texture upload
needed"); |
232 return; | 220 return; |
233 } | 221 } |
234 | 222 |
235 gfx::Vector2d destOffset(0, 0); | 223 gfx::Vector2d destOffset(0, 0); |
236 texture->update(queue, rect, destOffset, false, stats); | 224 texture->update(queue, rect, destOffset, false, stats); |
237 } | 225 } |
238 | 226 |
| 227 IntRect ScrollbarLayer::scrollbarLayerRectToContentRect(const WebRect& layerRect
) const |
| 228 { |
| 229 // Don't intersect with the bounds as in layerRectToContentRect() because |
| 230 // layerRect here might be in coordinates of the containing layer. |
| 231 FloatRect contentRect(layerRect.x, layerRect.y, layerRect.width, layerRect.h
eight); |
| 232 contentRect.scale(contentsScaleX(), contentsScaleY()); |
| 233 return enclosingIntRect(contentRect); |
| 234 } |
239 | 235 |
240 void ScrollbarLayer::setTexturePriorities(const PriorityCalculator&) | 236 void ScrollbarLayer::setTexturePriorities(const PriorityCalculator&) |
241 { | 237 { |
242 if (contentBounds().isEmpty()) | 238 if (contentBounds().isEmpty()) |
243 return; | 239 return; |
244 | 240 |
245 createUpdaterIfNeeded(); | 241 createUpdaterIfNeeded(); |
246 | 242 |
247 bool drawsToRoot = !renderTarget()->parent(); | 243 bool drawsToRoot = !renderTarget()->parent(); |
248 if (m_backTrack) { | 244 if (m_backTrack) { |
249 m_backTrack->texture()->setDimensions(contentBounds(), m_textureFormat); | 245 m_backTrack->texture()->setDimensions(contentBounds(), m_textureFormat); |
250 m_backTrack->texture()->setRequestPriority(PriorityCalculator::uiPriorit
y(drawsToRoot)); | 246 m_backTrack->texture()->setRequestPriority(PriorityCalculator::uiPriorit
y(drawsToRoot)); |
251 } | 247 } |
252 if (m_foreTrack) { | 248 if (m_foreTrack) { |
253 m_foreTrack->texture()->setDimensions(contentBounds(), m_textureFormat); | 249 m_foreTrack->texture()->setDimensions(contentBounds(), m_textureFormat); |
254 m_foreTrack->texture()->setRequestPriority(PriorityCalculator::uiPriorit
y(drawsToRoot)); | 250 m_foreTrack->texture()->setRequestPriority(PriorityCalculator::uiPriorit
y(drawsToRoot)); |
255 } | 251 } |
256 if (m_thumb) { | 252 if (m_thumb) { |
257 IntSize thumbSize = layerRectToContentRect(m_geometry->thumbRect(m_scrol
lbar.get())).size(); | 253 IntSize thumbSize = scrollbarLayerRectToContentRect(m_geometry->thumbRec
t(m_scrollbar.get())).size(); |
258 m_thumb->texture()->setDimensions(thumbSize, m_textureFormat); | 254 m_thumb->texture()->setDimensions(thumbSize, m_textureFormat); |
259 m_thumb->texture()->setRequestPriority(PriorityCalculator::uiPriority(dr
awsToRoot)); | 255 m_thumb->texture()->setRequestPriority(PriorityCalculator::uiPriority(dr
awsToRoot)); |
260 } | 256 } |
261 } | 257 } |
262 | 258 |
263 void ScrollbarLayer::update(ResourceUpdateQueue& queue, const OcclusionTracker*,
RenderingStats& stats) | 259 void ScrollbarLayer::update(ResourceUpdateQueue& queue, const OcclusionTracker*,
RenderingStats& stats) |
264 { | 260 { |
265 if (contentBounds().isEmpty()) | 261 if (contentBounds().isEmpty()) |
266 return; | 262 return; |
267 | 263 |
268 createUpdaterIfNeeded(); | 264 createUpdaterIfNeeded(); |
269 | 265 |
270 IntPoint scrollbarOrigin(m_scrollbar->location().x, m_scrollbar->location().
y); | 266 IntRect contentRect = scrollbarLayerRectToContentRect(WebRect(m_scrollbar->l
ocation().x, m_scrollbar->location().y, bounds().width(), bounds().height())); |
271 IntRect contentRect = layerRectToContentRect(WebKit::WebRect(scrollbarOrigin
.x(), scrollbarOrigin.y(), bounds().width(), bounds().height())); | |
272 updatePart(m_backTrackUpdater.get(), m_backTrack.get(), contentRect, queue,
stats); | 267 updatePart(m_backTrackUpdater.get(), m_backTrack.get(), contentRect, queue,
stats); |
273 if (m_foreTrack && m_foreTrackUpdater) | 268 if (m_foreTrack && m_foreTrackUpdater) |
274 updatePart(m_foreTrackUpdater.get(), m_foreTrack.get(), contentRect, que
ue, stats); | 269 updatePart(m_foreTrackUpdater.get(), m_foreTrack.get(), contentRect, que
ue, stats); |
275 | 270 |
276 // Consider the thumb to be at the origin when painting. | 271 // Consider the thumb to be at the origin when painting. |
277 WebKit::WebRect thumbRect = m_geometry->thumbRect(m_scrollbar.get()); | 272 WebKit::WebRect thumbRect = m_geometry->thumbRect(m_scrollbar.get()); |
278 IntRect originThumbRect = layerRectToContentRect(WebKit::WebRect(0, 0, thumb
Rect.width, thumbRect.height)); | 273 IntRect originThumbRect = scrollbarLayerRectToContentRect(WebRect(0, 0, thum
bRect.width, thumbRect.height)); |
279 if (!originThumbRect.isEmpty()) | 274 if (!originThumbRect.isEmpty()) |
280 updatePart(m_thumbUpdater.get(), m_thumb.get(), originThumbRect, queue,
stats); | 275 updatePart(m_thumbUpdater.get(), m_thumb.get(), originThumbRect, queue,
stats); |
281 } | 276 } |
282 | 277 |
283 } | 278 } |
OLD | NEW |