Index: cc/layers/scrollbar_layer.cc |
=================================================================== |
--- cc/layers/scrollbar_layer.cc (revision 210393) |
+++ cc/layers/scrollbar_layer.cc (working copy) |
@@ -1,4 +1,3 @@ |
- |
// Copyright 2012 The Chromium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
@@ -11,15 +10,20 @@ |
#include "cc/layers/scrollbar_layer_impl.h" |
#include "cc/resources/caching_bitmap_content_layer_updater.h" |
aelias_OOO_until_Jul13
2013/07/10 23:07:22
Three more includes to delete here.
powei
2013/07/11 23:54:44
Done.
|
#include "cc/resources/layer_painter.h" |
-#include "cc/resources/prioritized_resource.h" |
#include "cc/resources/resource_update_queue.h" |
+#include "cc/resources/ui_resource_manager.h" |
#include "cc/trees/layer_tree_host.h" |
+#include "cc/trees/layer_tree_impl.h" |
+#include "skia/ext/platform_canvas.h" |
+#include "skia/ext/refptr.h" |
+#include "third_party/skia/include/core/SkSize.h" |
#include "ui/gfx/rect_conversions.h" |
namespace cc { |
scoped_ptr<LayerImpl> ScrollbarLayer::CreateLayerImpl( |
LayerTreeImpl* tree_impl) { |
+ |
aelias_OOO_until_Jul13
2013/07/10 23:07:22
nit: accidental spacing change
powei
2013/07/11 23:54:44
Done.
|
return ScrollbarLayerImpl::Create( |
tree_impl, id(), scrollbar_->Orientation()).PassAs<LayerImpl>(); |
} |
@@ -36,7 +40,9 @@ |
int scroll_layer_id) |
: scrollbar_(scrollbar.Pass()), |
scroll_layer_id_(scroll_layer_id), |
- texture_format_(GL_INVALID_ENUM) { |
+ track_ui_resource_id_(0), |
+ thumb_ui_resource_id_(0), |
+ skip_update_(false) { |
if (!scrollbar_->IsOverlay()) |
SetShouldScrollOnMainThread(true); |
} |
@@ -107,7 +113,7 @@ |
if (layer_tree_host() && |
layer_tree_host()->settings().solid_color_scrollbars) { |
int thickness_override = |
- layer_tree_host()->settings().solid_color_scrollbar_thickness_dip; |
+ layer_tree_host()->settings().solid_color_scrollbar_thickness_dip; |
aelias_OOO_until_Jul13
2013/07/10 23:07:22
nit: accidental spacing change
powei
2013/07/11 23:54:44
Done.
|
if (thickness_override != -1) { |
scrollbar_layer->set_thumb_thickness(thickness_override); |
} else { |
@@ -120,6 +126,7 @@ |
scrollbar_layer->set_thumb_thickness(thumb_thickness_); |
} |
scrollbar_layer->set_thumb_length(thumb_length_); |
+ |
aelias_OOO_until_Jul13
2013/07/10 23:07:22
nit: accidental spacing change
powei
2013/07/11 23:54:44
Done.
|
if (Orientation() == HORIZONTAL) { |
scrollbar_layer->set_track_start(track_rect_.x()); |
scrollbar_layer->set_track_length(track_rect_.width()); |
@@ -128,15 +135,8 @@ |
scrollbar_layer->set_track_length(track_rect_.height()); |
} |
- if (track_ && track_->texture()->have_backing_texture()) |
- scrollbar_layer->set_track_resource_id(track_->texture()->resource_id()); |
- else |
- scrollbar_layer->set_track_resource_id(0); |
- |
- if (thumb_ && thumb_->texture()->have_backing_texture()) |
- scrollbar_layer->set_thumb_resource_id(thumb_->texture()->resource_id()); |
- else |
- scrollbar_layer->set_thumb_resource_id(0); |
+ scrollbar_layer->set_track_ui_resource_id(track_ui_resource_id_); |
+ scrollbar_layer->set_thumb_ui_resource_id(thumb_ui_resource_id_); |
} |
ScrollbarLayer* ScrollbarLayer::ToScrollbarLayer() { |
@@ -144,112 +144,22 @@ |
} |
void ScrollbarLayer::SetLayerTreeHost(LayerTreeHost* host) { |
- if (!host || host != layer_tree_host()) { |
- track_updater_ = NULL; |
- track_.reset(); |
- thumb_updater_ = NULL; |
- thumb_.reset(); |
- } |
+ // When the LTH is set to null, then this layer should remove all of |
+ // its associated textures. |
+ if (host != layer_tree_host() && host == NULL) { |
aelias_OOO_until_Jul13
2013/07/10 23:07:22
You changed the behavior here by changing this lin
powei
2013/07/11 23:54:44
Done.
|
+ if (track_ui_resource_id_) { |
+ layer_tree_host()->DeleteUIResource(track_ui_resource_id_); |
aelias_OOO_until_Jul13
2013/07/10 23:07:22
Also throw out the UIResourceBitmaps here.
powei
2013/07/11 23:54:44
Done.
|
+ track_ui_resource_id_ = 0; |
+ } |
+ if (thumb_ui_resource_id_) { |
+ layer_tree_host()->DeleteUIResource(thumb_ui_resource_id_); |
+ thumb_ui_resource_id_ = 0; |
+ } |
+ } |
ContentsScalingLayer::SetLayerTreeHost(host); |
} |
-class ScrollbarPartPainter : public LayerPainter { |
- public: |
- ScrollbarPartPainter(Scrollbar* scrollbar, ScrollbarPart part) |
- : scrollbar_(scrollbar), |
- part_(part) {} |
- virtual ~ScrollbarPartPainter() {} |
- |
- // LayerPainter implementation |
- virtual void Paint(SkCanvas* canvas, |
- gfx::Rect content_rect, |
- gfx::RectF* opaque) OVERRIDE { |
- scrollbar_->PaintPart(canvas, part_, content_rect); |
- } |
- |
- private: |
- Scrollbar* scrollbar_; |
- ScrollbarPart part_; |
-}; |
- |
-void ScrollbarLayer::CreateUpdaterIfNeeded() { |
- if (layer_tree_host()->settings().solid_color_scrollbars) |
- return; |
- |
- texture_format_ = |
- layer_tree_host()->GetRendererCapabilities().best_texture_format; |
- |
- if (!track_updater_.get()) { |
- track_updater_ = CachingBitmapContentLayerUpdater::Create( |
- scoped_ptr<LayerPainter>( |
- new ScrollbarPartPainter(scrollbar_.get(), TRACK)) |
- .Pass(), |
- rendering_stats_instrumentation(), |
- id()); |
- } |
- if (!track_) { |
- track_ = track_updater_->CreateResource( |
- layer_tree_host()->contents_texture_manager()); |
- } |
- |
- if (!thumb_updater_.get()) { |
- thumb_updater_ = CachingBitmapContentLayerUpdater::Create( |
- scoped_ptr<LayerPainter>( |
- new ScrollbarPartPainter(scrollbar_.get(), THUMB)) |
- .Pass(), |
- rendering_stats_instrumentation(), |
- id()); |
- } |
- if (!thumb_ && scrollbar_->HasThumb()) { |
- thumb_ = thumb_updater_->CreateResource( |
- layer_tree_host()->contents_texture_manager()); |
- } |
-} |
- |
-void ScrollbarLayer::UpdatePart(CachingBitmapContentLayerUpdater* painter, |
- LayerUpdater::Resource* resource, |
- gfx::Rect rect, |
- ResourceUpdateQueue* queue) { |
- if (layer_tree_host()->settings().solid_color_scrollbars) |
- return; |
- |
- // Skip painting and uploading if there are no invalidations and |
- // we already have valid texture data. |
- if (resource->texture()->have_backing_texture() && |
- resource->texture()->size() == rect.size() && |
- !is_dirty()) |
- return; |
- |
- // We should always have enough memory for UI. |
- DCHECK(resource->texture()->can_acquire_backing_texture()); |
- if (!resource->texture()->can_acquire_backing_texture()) |
- return; |
- |
- // Paint and upload the entire part. |
- gfx::Rect painted_opaque_rect; |
- painter->PrepareToUpdate(rect, |
- rect.size(), |
- contents_scale_x(), |
- contents_scale_y(), |
- &painted_opaque_rect); |
- if (!painter->pixels_did_change() && |
- resource->texture()->have_backing_texture()) { |
- TRACE_EVENT_INSTANT0("cc", |
- "ScrollbarLayer::UpdatePart no texture upload needed", |
- TRACE_EVENT_SCOPE_THREAD); |
- return; |
- } |
- |
- bool partial_updates_allowed = |
- layer_tree_host()->settings().max_partial_texture_updates > 0; |
- if (!partial_updates_allowed) |
- resource->texture()->ReturnBackingTexture(); |
- |
- gfx::Vector2d dest_offset(0, 0); |
- resource->Update(queue, rect, dest_offset, partial_updates_allowed); |
-} |
- |
gfx::Rect ScrollbarLayer::ScrollbarLayerRectToContentRect( |
gfx::Rect layer_rect) const { |
// Don't intersect with the bounds as in LayerRectToContentRect() because |
@@ -263,32 +173,6 @@ |
return expanded_rect; |
} |
-void ScrollbarLayer::SetTexturePriorities( |
- const PriorityCalculator& priority_calc) { |
- if (layer_tree_host()->settings().solid_color_scrollbars) |
- return; |
- |
- if (content_bounds().IsEmpty()) |
- return; |
- DCHECK_LE(content_bounds().width(), MaxTextureSize()); |
- DCHECK_LE(content_bounds().height(), MaxTextureSize()); |
- |
- CreateUpdaterIfNeeded(); |
- |
- bool draws_to_root = !render_target()->parent(); |
- if (track_) { |
- track_->texture()->SetDimensions(content_bounds(), texture_format_); |
- track_->texture()->set_request_priority( |
- PriorityCalculator::UIPriority(draws_to_root)); |
- } |
- if (thumb_) { |
- gfx::Size thumb_size = OriginThumbRect().size(); |
- thumb_->texture()->SetDimensions(thumb_size, texture_format_); |
- thumb_->texture()->set_request_priority( |
- PriorityCalculator::UIPriority(draws_to_root)); |
- } |
-} |
- |
void ScrollbarLayer::Update(ResourceUpdateQueue* queue, |
const OcclusionTracker* occlusion) { |
track_rect_ = scrollbar_->TrackRect(); |
@@ -296,40 +180,87 @@ |
if (layer_tree_host()->settings().solid_color_scrollbars) |
return; |
- { |
- base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_, |
- true); |
- ContentsScalingLayer::Update(queue, occlusion); |
- } |
+ base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_, |
+ true); |
+ ContentsScalingLayer::Update(queue, occlusion); |
- dirty_rect_.Union(update_rect_); |
- if (content_bounds().IsEmpty()) |
+ if (skip_update_) { |
+ skip_update_ = false; |
return; |
- if (visible_content_rect().IsEmpty()) |
- return; |
+ } |
- CreateUpdaterIfNeeded(); |
- |
- gfx::Rect content_rect = ScrollbarLayerRectToContentRect( |
- gfx::Rect(scrollbar_->Location(), bounds())); |
- UpdatePart(track_updater_.get(), |
- track_.get(), |
- content_rect, |
- queue); |
- |
if (scrollbar_->HasThumb()) { |
thumb_thickness_ = scrollbar_->ThumbThickness(); |
thumb_length_ = scrollbar_->ThumbLength(); |
gfx::Rect origin_thumb_rect = OriginThumbRect(); |
- if (!origin_thumb_rect.IsEmpty()) { |
- UpdatePart(thumb_updater_.get(), |
- thumb_.get(), |
- origin_thumb_rect, |
- queue); |
- } |
} |
- dirty_rect_ = gfx::RectF(); |
+ |
+ gfx::Rect track_rect = ScrollbarLayerRectToContentRect( |
+ gfx::Rect(scrollbar_->Location(), bounds())); |
+ gfx::Rect thumb_rect = OriginThumbRect(); |
+ |
+ { |
+ track_bitmap_ = UIResourceBitmap::Create( |
+ new uint8_t[track_rect.width()*track_rect.height()*4], |
aelias_OOO_until_Jul13
2013/07/10 23:07:22
nit: spaces around *
powei
2013/07/11 23:54:44
Done.
|
+ UIResourceBitmap::RGBA8, |
+ track_rect.size()); |
+ |
+ // raster track |
+ skia::RefPtr<SkCanvas> track_canvas = skia::AdoptRef( |
+ skia::CreatePlatformCanvas(track_rect.width(), |
+ track_rect.height(), |
+ false, |
+ reinterpret_cast<uint8_t*>( |
+ track_bitmap_->GetPixels()), |
+ skia::CRASH_ON_FAILURE)); |
+ |
+ track_canvas->save(); |
+ track_canvas->translate(SkFloatToScalar(-track_rect.x()), |
+ SkFloatToScalar(-track_rect.y())); |
+ SkPaint paint; |
+ paint.setAntiAlias(false); |
+ paint.setXfermodeMode(SkXfermode::kClear_Mode); |
+ SkRect layer_sk_rect = SkRect::MakeXYWH(track_rect.x(), |
+ track_rect.y(), |
+ track_rect.width(), |
+ track_rect.height()); |
+ |
+ track_canvas->drawRect(layer_sk_rect, paint); |
+ track_canvas->clipRect(layer_sk_rect); |
+ scrollbar_->PaintPart(track_canvas.get(), TRACK, track_rect); |
+ track_canvas->restore(); |
+ |
+ if (track_ui_resource_id_) |
+ layer_tree_host()->DeleteUIResource(track_ui_resource_id_); |
+ track_ui_resource_id_ = layer_tree_host()->CreateUIResource(track_bitmap_, |
+ this); |
+ } |
+ |
+ if (scrollbar_->HasThumb()) { |
+ thumb_bitmap_ = UIResourceBitmap::Create( |
+ new uint8_t[thumb_rect.width()*thumb_rect.height()*4], |
aelias_OOO_until_Jul13
2013/07/10 23:07:22
nit: spaces around *
powei
2013/07/11 23:54:44
Done.
|
+ UIResourceBitmap::RGBA8, |
+ thumb_rect.size()); |
+ |
+ // raster thumb |
+ skia::RefPtr<SkCanvas> thumb_canvas = skia::AdoptRef( |
+ skia::CreatePlatformCanvas(thumb_rect.width(), |
+ thumb_rect.height(), |
+ false, |
+ reinterpret_cast<uint8_t*>( |
+ thumb_bitmap_->GetPixels()), |
+ skia::CRASH_ON_FAILURE)); |
+ |
+ scrollbar_->PaintPart(thumb_canvas.get(), |
+ THUMB, |
+ thumb_rect); |
+ |
+ if (thumb_ui_resource_id_) |
+ layer_tree_host()->DeleteUIResource(thumb_ui_resource_id_); |
+ thumb_ui_resource_id_ = layer_tree_host()->CreateUIResource(thumb_bitmap_, |
+ this); |
+ } |
} |
gfx::Rect ScrollbarLayer::OriginThumbRect() const { |
@@ -344,4 +275,19 @@ |
return ScrollbarLayerRectToContentRect(gfx::Rect(thumb_size)); |
} |
+void ScrollbarLayer::UIResourceReady(UIResourceId id) { |
aelias_OOO_until_Jul13
2013/07/10 23:07:22
This code is unnecessary, please delete it. It's
powei
2013/07/11 23:54:44
Done.
|
+ if (thumb_ui_resource_id_ == id) { |
+ // Need to push the ui resource id to the impl thread. |
+ SetNeedsCommit(); |
+ // If we do not have this flag, we will always have a |
+ // SetNeedsCommimt request in the scheduler |
+ skip_update_ = true; |
+ } |
+ |
+ if (track_ui_resource_id_ == id) { |
+ SetNeedsCommit(); |
+ skip_update_ = true; |
+ } |
+} |
+ |
} // namespace cc |