Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: cc/scrollbar_layer.cc

Issue 12297009: cc: SolidColorQuad-based scrollbars for Android [M25] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix DCHECK failure in test by creating render surface Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/layer_tree_settings.cc ('k') | cc/scrollbar_layer_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "cc/scrollbar_layer.h" 5 #include "cc/scrollbar_layer.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "cc/caching_bitmap_content_layer_updater.h" 9 #include "cc/caching_bitmap_content_layer_updater.h"
10 #include "cc/layer_painter.h" 10 #include "cc/layer_painter.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 { 63 {
64 return m_scrollbar->orientation(); 64 return m_scrollbar->orientation();
65 } 65 }
66 66
67 int ScrollbarLayer::maxTextureSize() { 67 int ScrollbarLayer::maxTextureSize() {
68 DCHECK(layerTreeHost()); 68 DCHECK(layerTreeHost());
69 return layerTreeHost()->rendererCapabilities().maxTextureSize; 69 return layerTreeHost()->rendererCapabilities().maxTextureSize;
70 } 70 }
71 71
72 float ScrollbarLayer::clampScaleToMaxTextureSize(float scale) { 72 float ScrollbarLayer::clampScaleToMaxTextureSize(float scale) {
73 if (layerTreeHost()->settings().solidColorScrollbars)
74 return scale;
75
73 // If the scaled contentBounds() is bigger than the max texture size of the 76 // If the scaled contentBounds() is bigger than the max texture size of the
74 // device, we need to clamp it by rescaling, since contentBounds() is used 77 // device, we need to clamp it by rescaling, since contentBounds() is used
75 // below to set the texture size. 78 // below to set the texture size.
76 gfx::Size scaledBounds = computeContentBoundsForScale(scale, scale); 79 gfx::Size scaledBounds = computeContentBoundsForScale(scale, scale);
77 if (scaledBounds.width() > maxTextureSize() || scaledBounds.height() > maxTe xtureSize()) { 80 if (scaledBounds.width() > maxTextureSize() || scaledBounds.height() > maxTe xtureSize()) {
78 if (scaledBounds.width() > scaledBounds.height()) 81 if (scaledBounds.width() > scaledBounds.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( ));
82 } 85 }
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 m_backTrack.reset(); 225 m_backTrack.reset();
223 m_thumbUpdater = NULL; 226 m_thumbUpdater = NULL;
224 m_thumb.reset(); 227 m_thumb.reset();
225 } 228 }
226 229
227 ContentsScalingLayer::setLayerTreeHost(host); 230 ContentsScalingLayer::setLayerTreeHost(host);
228 } 231 }
229 232
230 void ScrollbarLayer::createUpdaterIfNeeded() 233 void ScrollbarLayer::createUpdaterIfNeeded()
231 { 234 {
235 if (layerTreeHost()->settings().solidColorScrollbars)
236 return;
237
232 m_textureFormat = layerTreeHost()->rendererCapabilities().bestTextureFormat; 238 m_textureFormat = layerTreeHost()->rendererCapabilities().bestTextureFormat;
233 239
234 if (!m_backTrackUpdater) 240 if (!m_backTrackUpdater)
235 m_backTrackUpdater = CachingBitmapContentLayerUpdater::Create(ScrollbarB ackgroundPainter::create(m_scrollbar.get(), m_painter.get(), m_geometry.get(), W ebKit::WebScrollbar::BackTrackPart).PassAs<LayerPainter>()); 241 m_backTrackUpdater = CachingBitmapContentLayerUpdater::Create(ScrollbarB ackgroundPainter::create(m_scrollbar.get(), m_painter.get(), m_geometry.get(), W ebKit::WebScrollbar::BackTrackPart).PassAs<LayerPainter>());
236 if (!m_backTrack) 242 if (!m_backTrack)
237 m_backTrack = m_backTrackUpdater->createResource(layerTreeHost()->conten tsTextureManager()); 243 m_backTrack = m_backTrackUpdater->createResource(layerTreeHost()->conten tsTextureManager());
238 244
239 // Only create two-part track if we think the two parts could be different i n appearance. 245 // Only create two-part track if we think the two parts could be different i n appearance.
240 if (m_scrollbar->isCustomScrollbar()) { 246 if (m_scrollbar->isCustomScrollbar()) {
241 if (!m_foreTrackUpdater) 247 if (!m_foreTrackUpdater)
242 m_foreTrackUpdater = CachingBitmapContentLayerUpdater::Create(Scroll barBackgroundPainter::create(m_scrollbar.get(), m_painter.get(), m_geometry.get( ), WebKit::WebScrollbar::ForwardTrackPart).PassAs<LayerPainter>()); 248 m_foreTrackUpdater = CachingBitmapContentLayerUpdater::Create(Scroll barBackgroundPainter::create(m_scrollbar.get(), m_painter.get(), m_geometry.get( ), WebKit::WebScrollbar::ForwardTrackPart).PassAs<LayerPainter>());
243 if (!m_foreTrack) 249 if (!m_foreTrack)
244 m_foreTrack = m_foreTrackUpdater->createResource(layerTreeHost()->co ntentsTextureManager()); 250 m_foreTrack = m_foreTrackUpdater->createResource(layerTreeHost()->co ntentsTextureManager());
245 } 251 }
246 252
247 if (!m_thumbUpdater) 253 if (!m_thumbUpdater)
248 m_thumbUpdater = CachingBitmapContentLayerUpdater::Create(ScrollbarThumb Painter::create(m_scrollbar.get(), m_painter.get(), m_geometry.get()).PassAs<Lay erPainter>()); 254 m_thumbUpdater = CachingBitmapContentLayerUpdater::Create(ScrollbarThumb Painter::create(m_scrollbar.get(), m_painter.get(), m_geometry.get()).PassAs<Lay erPainter>());
249 if (!m_thumb) 255 if (!m_thumb)
250 m_thumb = m_thumbUpdater->createResource(layerTreeHost()->contentsTextur eManager()); 256 m_thumb = m_thumbUpdater->createResource(layerTreeHost()->contentsTextur eManager());
251 } 257 }
252 258
253 void ScrollbarLayer::updatePart(CachingBitmapContentLayerUpdater* painter, Layer Updater::Resource* resource, const gfx::Rect& rect, ResourceUpdateQueue& queue, RenderingStats* stats) 259 void ScrollbarLayer::updatePart(CachingBitmapContentLayerUpdater* painter, Layer Updater::Resource* resource, const gfx::Rect& rect, ResourceUpdateQueue& queue, RenderingStats* stats)
254 { 260 {
261 if (layerTreeHost()->settings().solidColorScrollbars)
262 return;
263
255 // Skip painting and uploading if there are no invalidations and 264 // Skip painting and uploading if there are no invalidations and
256 // we already have valid texture data. 265 // we already have valid texture data.
257 if (resource->texture()->haveBackingTexture() && 266 if (resource->texture()->haveBackingTexture() &&
258 resource->texture()->size() == rect.size() && 267 resource->texture()->size() == rect.size() &&
259 !isDirty()) 268 !isDirty())
260 return; 269 return;
261 270
262 // We should always have enough memory for UI. 271 // We should always have enough memory for UI.
263 DCHECK(resource->texture()->canAcquireBackingTexture()); 272 DCHECK(resource->texture()->canAcquireBackingTexture());
264 if (!resource->texture()->canAcquireBackingTexture()) 273 if (!resource->texture()->canAcquireBackingTexture())
(...skipping 18 matching lines...) Expand all
283 gfx::Rect ScrollbarLayer::scrollbarLayerRectToContentRect(const gfx::Rect& layer Rect) const 292 gfx::Rect ScrollbarLayer::scrollbarLayerRectToContentRect(const gfx::Rect& layer Rect) const
284 { 293 {
285 // Don't intersect with the bounds as in layerRectToContentRect() because 294 // Don't intersect with the bounds as in layerRectToContentRect() because
286 // layerRect here might be in coordinates of the containing layer. 295 // layerRect here might be in coordinates of the containing layer.
287 gfx::RectF contentRect = gfx::ScaleRect(layerRect, contentsScaleX(), content sScaleY()); 296 gfx::RectF contentRect = gfx::ScaleRect(layerRect, contentsScaleX(), content sScaleY());
288 return gfx::ToEnclosingRect(contentRect); 297 return gfx::ToEnclosingRect(contentRect);
289 } 298 }
290 299
291 void ScrollbarLayer::setTexturePriorities(const PriorityCalculator&) 300 void ScrollbarLayer::setTexturePriorities(const PriorityCalculator&)
292 { 301 {
302 if (layerTreeHost()->settings().solidColorScrollbars)
303 return;
304
293 if (contentBounds().IsEmpty()) 305 if (contentBounds().IsEmpty())
294 return; 306 return;
295 DCHECK_LE(contentBounds().width(), maxTextureSize()); 307 DCHECK_LE(contentBounds().width(), maxTextureSize());
296 DCHECK_LE(contentBounds().height(), maxTextureSize()); 308 DCHECK_LE(contentBounds().height(), maxTextureSize());
297 309
298 createUpdaterIfNeeded(); 310 createUpdaterIfNeeded();
299 311
300 bool drawsToRoot = !renderTarget()->parent(); 312 bool drawsToRoot = !renderTarget()->parent();
301 if (m_backTrack) { 313 if (m_backTrack) {
302 m_backTrack->texture()->setDimensions(contentBounds(), m_textureFormat); 314 m_backTrack->texture()->setDimensions(contentBounds(), m_textureFormat);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 gfx::Rect thumbRect = m_geometry->thumbRect(m_scrollbar.get()); 346 gfx::Rect thumbRect = m_geometry->thumbRect(m_scrollbar.get());
335 m_thumbSize = thumbRect.size(); 347 m_thumbSize = thumbRect.size();
336 gfx::Rect originThumbRect = scrollbarLayerRectToContentRect(gfx::Rect(thumbR ect.size())); 348 gfx::Rect originThumbRect = scrollbarLayerRectToContentRect(gfx::Rect(thumbR ect.size()));
337 if (!originThumbRect.IsEmpty()) 349 if (!originThumbRect.IsEmpty())
338 updatePart(m_thumbUpdater.get(), m_thumb.get(), originThumbRect, queue, stats); 350 updatePart(m_thumbUpdater.get(), m_thumb.get(), originThumbRect, queue, stats);
339 351
340 m_dirtyRect = gfx::RectF(); 352 m_dirtyRect = gfx::RectF();
341 } 353 }
342 354
343 } // namespace cc 355 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layer_tree_settings.cc ('k') | cc/scrollbar_layer_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698