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

Unified Diff: cc/layers/scrollbar_layer.cc

Issue 21917004: Change ScrollbarLayer to use UI resource (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and merge Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/layers/scrollbar_layer.h ('k') | cc/layers/scrollbar_layer_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/layers/scrollbar_layer.cc
diff --git a/cc/layers/scrollbar_layer.cc b/cc/layers/scrollbar_layer.cc
index 4a6383504fc5750bb706b694764e664fff59309a..14d038fcd624c43702b0cbb10f166e082602eecf 100644
--- a/cc/layers/scrollbar_layer.cc
+++ b/cc/layers/scrollbar_layer.cc
@@ -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.
@@ -9,12 +8,15 @@
#include "base/basictypes.h"
#include "base/debug/trace_event.h"
#include "cc/layers/scrollbar_layer_impl.h"
-#include "cc/resources/caching_bitmap_content_layer_updater.h"
-#include "cc/resources/layer_painter.h"
-#include "cc/resources/prioritized_resource.h"
-#include "cc/resources/resource_update_queue.h"
+#include "cc/resources/ui_resource_bitmap.h"
#include "cc/trees/layer_tree_host.h"
-#include "ui/gfx/rect_conversions.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/SkBitmap.h"
+#include "third_party/skia/include/core/SkCanvas.h"
+#include "third_party/skia/include/core/SkSize.h"
+#include "ui/gfx/skia_util.h"
namespace cc {
@@ -27,16 +29,15 @@ scoped_ptr<LayerImpl> ScrollbarLayer::CreateLayerImpl(
scoped_refptr<ScrollbarLayer> ScrollbarLayer::Create(
scoped_ptr<Scrollbar> scrollbar,
int scroll_layer_id) {
- return make_scoped_refptr(new ScrollbarLayer(scrollbar.Pass(),
- scroll_layer_id));
+ return make_scoped_refptr(
+ new ScrollbarLayer(scrollbar.Pass(), scroll_layer_id));
}
ScrollbarLayer::ScrollbarLayer(
scoped_ptr<Scrollbar> scrollbar,
int scroll_layer_id)
: scrollbar_(scrollbar.Pass()),
- scroll_layer_id_(scroll_layer_id),
- texture_format_(GL_INVALID_ENUM) {
+ scroll_layer_id_(scroll_layer_id) {
if (!scrollbar_->IsOverlay())
SetShouldScrollOnMainThread(true);
}
@@ -128,15 +129,10 @@ void ScrollbarLayer::PushPropertiesTo(LayerImpl* layer) {
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);
+ if (track_resource_.get())
+ scrollbar_layer->set_track_ui_resource_id(track_resource_->id());
+ if (thumb_resource_.get())
+ scrollbar_layer->set_thumb_ui_resource_id(thumb_resource_->id());
scrollbar_layer->set_is_overlay_scrollbar(scrollbar_->IsOverlay());
@@ -149,113 +145,16 @@ ScrollbarLayer* ScrollbarLayer::ToScrollbarLayer() {
}
void ScrollbarLayer::SetLayerTreeHost(LayerTreeHost* host) {
+ // When the LTH is set to null or has changed, then this layer should remove
+ // all of its associated resources.
if (!host || host != layer_tree_host()) {
- track_updater_ = NULL;
- track_.reset();
- thumb_updater_ = NULL;
- thumb_.reset();
+ track_resource_.reset();
+ thumb_resource_.reset();
}
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());
- }
-}
-
-bool ScrollbarLayer::UpdatePart(CachingBitmapContentLayerUpdater* painter,
- LayerUpdater::Resource* resource,
- gfx::Rect rect,
- ResourceUpdateQueue* queue) {
- if (layer_tree_host()->settings().solid_color_scrollbars)
- return false;
-
- // 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 false;
-
- // We should always have enough memory for UI.
- DCHECK(resource->texture()->can_acquire_backing_texture());
- if (!resource->texture()->can_acquire_backing_texture())
- return false;
-
- // 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 false;
- }
-
- 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);
- return true;
-}
-
gfx::Rect ScrollbarLayer::ScrollbarLayerRectToContentRect(
gfx::Rect layer_rect) const {
// Don't intersect with the bounds as in LayerRectToContentRect() because
@@ -269,84 +168,80 @@ gfx::Rect ScrollbarLayer::ScrollbarLayerRectToContentRect(
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));
+gfx::Rect ScrollbarLayer::OriginThumbRect() const {
+ gfx::Size thumb_size;
+ if (Orientation() == HORIZONTAL) {
+ thumb_size =
+ gfx::Size(scrollbar_->ThumbLength(), scrollbar_->ThumbThickness());
+ } else {
+ thumb_size =
+ gfx::Size(scrollbar_->ThumbThickness(), scrollbar_->ThumbLength());
}
+ return ScrollbarLayerRectToContentRect(gfx::Rect(thumb_size));
}
bool ScrollbarLayer::Update(ResourceUpdateQueue* queue,
const OcclusionTracker* occlusion) {
track_rect_ = scrollbar_->TrackRect();
+ gfx::Rect scaled_track_rect = ScrollbarLayerRectToContentRect(
+ gfx::Rect(scrollbar_->Location(), bounds()));
- if (layer_tree_host()->settings().solid_color_scrollbars)
+ if (layer_tree_host()->settings().solid_color_scrollbars ||
+ track_rect_.IsEmpty() || scaled_track_rect.IsEmpty())
return false;
- bool updated = false;
-
{
base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_,
true);
- updated = ContentsScalingLayer::Update(queue, occlusion);
+ ContentsScalingLayer::Update(queue, occlusion);
}
- dirty_rect_.Union(update_rect_);
- if (content_bounds().IsEmpty())
- return false;
- if (visible_content_rect().IsEmpty())
- return false;
-
- CreateUpdaterIfNeeded();
+ track_resource_ = ScopedUIResource::Create(
+ layer_tree_host(), RasterizeScrollbarPart(scaled_track_rect, TRACK));
+ gfx::Rect thumb_rect = OriginThumbRect();
- gfx::Rect content_rect = ScrollbarLayerRectToContentRect(
- gfx::Rect(scrollbar_->Location(), bounds()));
- updated |= UpdatePart(track_updater_.get(), track_.get(), content_rect,
- queue);
-
- if (scrollbar_->HasThumb()) {
+ if (scrollbar_->HasThumb() && !thumb_rect.IsEmpty()) {
thumb_thickness_ = scrollbar_->ThumbThickness();
thumb_length_ = scrollbar_->ThumbLength();
- gfx::Rect origin_thumb_rect = OriginThumbRect();
- if (!origin_thumb_rect.IsEmpty()) {
- updated |= UpdatePart(thumb_updater_.get(), thumb_.get(),
- origin_thumb_rect, queue);
- }
+ thumb_resource_ = ScopedUIResource::Create(
+ layer_tree_host(), RasterizeScrollbarPart(thumb_rect, THUMB));
}
- dirty_rect_ = gfx::RectF();
- return updated;
+ return true;
}
-gfx::Rect ScrollbarLayer::OriginThumbRect() const {
- gfx::Size thumb_size;
- if (Orientation() == HORIZONTAL) {
- thumb_size = gfx::Size(scrollbar_->ThumbLength(),
- scrollbar_->ThumbThickness());
- } else {
- thumb_size = gfx::Size(scrollbar_->ThumbThickness(),
- scrollbar_->ThumbLength());
- }
- return ScrollbarLayerRectToContentRect(gfx::Rect(thumb_size));
+scoped_refptr<UIResourceBitmap> ScrollbarLayer::RasterizeScrollbarPart(
+ gfx::Rect rect,
+ ScrollbarPart part) {
+ DCHECK(!layer_tree_host()->settings().solid_color_scrollbars);
+ DCHECK(!rect.size().IsEmpty());
+
+ scoped_refptr<UIResourceBitmap> bitmap =
+ UIResourceBitmap::Create(new uint8_t[rect.width() * rect.height() * 4],
+ UIResourceBitmap::RGBA8,
+ rect.size());
+
+ SkBitmap skbitmap;
+ skbitmap.setConfig(SkBitmap::kARGB_8888_Config, rect.width(), rect.height());
+ skbitmap.setPixels(bitmap->GetPixels());
+
+ SkCanvas skcanvas(skbitmap);
+ skcanvas.translate(SkFloatToScalar(-rect.x()), SkFloatToScalar(-rect.y()));
+ skcanvas.scale(SkFloatToScalar(contents_scale_x()),
+ SkFloatToScalar(contents_scale_y()));
+
+ gfx::Rect layer_rect = gfx::ScaleToEnclosingRect(
+ rect, 1.f / contents_scale_x(), 1.f / contents_scale_y());
+ SkRect layer_skrect = RectToSkRect(layer_rect);
+ SkPaint paint;
+ paint.setAntiAlias(false);
+ paint.setXfermodeMode(SkXfermode::kClear_Mode);
+ skcanvas.drawRect(layer_skrect, paint);
+ skcanvas.clipRect(layer_skrect);
+
+ scrollbar_->PaintPart(&skcanvas, part, layer_rect);
+
+ return bitmap;
}
} // namespace cc
« no previous file with comments | « cc/layers/scrollbar_layer.h ('k') | cc/layers/scrollbar_layer_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698