| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ui/gfx/compositor/layer.h" | 5 #include "ui/gfx/compositor/layer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebExternalTextureLay
er.h" |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContentLayer.h" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFloatPoint.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFloatPoint.h" |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFloatRect.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFloatRect.h" |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h" |
| 14 #include "ui/base/animation/animation.h" | 16 #include "ui/base/animation/animation.h" |
| 17 #if defined(USE_WEBKIT_COMPOSITOR) |
| 18 #include "ui/gfx/compositor/compositor_cc.h" |
| 19 #endif |
| 15 #include "ui/gfx/compositor/layer_animation_manager.h" | 20 #include "ui/gfx/compositor/layer_animation_manager.h" |
| 16 #include "ui/gfx/canvas_skia.h" | 21 #include "ui/gfx/canvas_skia.h" |
| 17 #include "ui/gfx/interpolated_transform.h" | 22 #include "ui/gfx/interpolated_transform.h" |
| 18 #include "ui/gfx/point3.h" | 23 #include "ui/gfx/point3.h" |
| 19 | 24 |
| 20 namespace { | 25 namespace { |
| 21 | 26 |
| 22 const float EPSILON = 1e-3f; | 27 const float EPSILON = 1e-3f; |
| 23 | 28 |
| 24 bool IsApproximateMultilpleOf(float value, float base) { | 29 bool IsApproximateMultilpleOf(float value, float base) { |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 parent()->RecomputeHole(); | 239 parent()->RecomputeHole(); |
| 235 #if defined(USE_WEBKIT_COMPOSITOR) | 240 #if defined(USE_WEBKIT_COMPOSITOR) |
| 236 web_layer_.setOpaque(fills_bounds_opaquely); | 241 web_layer_.setOpaque(fills_bounds_opaquely); |
| 237 #endif | 242 #endif |
| 238 } | 243 } |
| 239 | 244 |
| 240 void Layer::SetExternalTexture(ui::Texture* texture) { | 245 void Layer::SetExternalTexture(ui::Texture* texture) { |
| 241 DCHECK(texture); | 246 DCHECK(texture); |
| 242 layer_updated_externally_ = true; | 247 layer_updated_externally_ = true; |
| 243 texture_ = texture; | 248 texture_ = texture; |
| 249 #if defined(USE_WEBKIT_COMPOSITOR) |
| 250 if (!web_layer_is_accelerated_) { |
| 251 web_layer_.removeAllChildren(); |
| 252 WebKit::WebLayer new_layer = |
| 253 WebKit::WebExternalTextureLayer::create(this); |
| 254 if (parent_) { |
| 255 DCHECK(!parent_->web_layer_.isNull()); |
| 256 parent_->web_layer_.replaceChild(web_layer_, new_layer); |
| 257 } |
| 258 web_layer_ = new_layer; |
| 259 web_layer_is_accelerated_ = true; |
| 260 for (size_t i = 0; i < children_.size(); ++i) { |
| 261 DCHECK(!children_[i]->web_layer_.isNull()); |
| 262 web_layer_.addChild(children_[i]->web_layer_); |
| 263 } |
| 264 web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); |
| 265 web_layer_.setOpaque(fills_bounds_opaquely_); |
| 266 web_layer_.setOpacity(visible_ ? opacity_ : 0.f); |
| 267 web_layer_.setBounds(bounds_.size()); |
| 268 RecomputeTransform(); |
| 269 } |
| 270 TextureCC* texture_cc = static_cast<TextureCC*>(texture); |
| 271 texture_cc->Update(); |
| 272 web_layer_.to<WebKit::WebExternalTextureLayer>().setFlipped( |
| 273 texture_cc->flipped()); |
| 274 RecomputeDrawsContent(); |
| 275 #endif |
| 244 } | 276 } |
| 245 | 277 |
| 246 void Layer::SetCanvas(const SkCanvas& canvas, const gfx::Point& origin) { | 278 void Layer::SetCanvas(const SkCanvas& canvas, const gfx::Point& origin) { |
| 247 #if defined(USE_WEBKIT_COMPOSITOR) | 279 #if defined(USE_WEBKIT_COMPOSITOR) |
| 248 NOTREACHED(); | 280 NOTREACHED(); |
| 249 #else | 281 #else |
| 250 DCHECK_EQ(type_, LAYER_HAS_TEXTURE); | 282 DCHECK_EQ(type_, LAYER_HAS_TEXTURE); |
| 251 | 283 |
| 252 if (!texture_.get()) | 284 if (!texture_.get()) |
| 253 texture_ = GetCompositor()->CreateTexture(); | 285 texture_ = GetCompositor()->CreateTexture(); |
| 254 | 286 |
| 255 texture_->SetCanvas(canvas, origin, bounds_.size()); | 287 texture_->SetCanvas(canvas, origin, bounds_.size()); |
| 256 invalid_rect_ = gfx::Rect(); | 288 invalid_rect_ = gfx::Rect(); |
| 257 #endif | 289 #endif |
| 258 } | 290 } |
| 259 | 291 |
| 260 void Layer::SchedulePaint(const gfx::Rect& invalid_rect) { | 292 void Layer::SchedulePaint(const gfx::Rect& invalid_rect) { |
| 261 #if defined(USE_WEBKIT_COMPOSITOR) | 293 #if defined(USE_WEBKIT_COMPOSITOR) |
| 262 WebKit::WebFloatRect web_rect(invalid_rect.x(), | 294 WebKit::WebFloatRect web_rect(invalid_rect.x(), |
| 263 invalid_rect.y(), | 295 invalid_rect.y(), |
| 264 invalid_rect.width(), | 296 invalid_rect.width(), |
| 265 invalid_rect.height()); | 297 invalid_rect.height()); |
| 266 web_layer_.invalidateRect(web_rect); | 298 if (!web_layer_is_accelerated_) |
| 299 web_layer_.to<WebKit::WebContentLayer>().invalidateRect(web_rect); |
| 267 #else | 300 #else |
| 268 invalid_rect_ = invalid_rect_.Union(invalid_rect); | 301 invalid_rect_ = invalid_rect_.Union(invalid_rect); |
| 269 ScheduleDraw(); | 302 ScheduleDraw(); |
| 270 #endif | 303 #endif |
| 271 } | 304 } |
| 272 | 305 |
| 273 void Layer::ScheduleDraw() { | 306 void Layer::ScheduleDraw() { |
| 274 Compositor* compositor = GetCompositor(); | 307 Compositor* compositor = GetCompositor(); |
| 275 if (compositor) | 308 if (compositor) |
| 276 compositor->ScheduleDraw(); | 309 compositor->ScheduleDraw(); |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 Layer* current = to_process.front(); | 608 Layer* current = to_process.front(); |
| 576 to_process.pop(); | 609 to_process.pop(); |
| 577 current->RecomputeHole(); | 610 current->RecomputeHole(); |
| 578 for (size_t i = 0; i < current->children_.size(); ++i) | 611 for (size_t i = 0; i < current->children_.size(); ++i) |
| 579 to_process.push(current->children_.at(i)); | 612 to_process.push(current->children_.at(i)); |
| 580 } | 613 } |
| 581 } | 614 } |
| 582 #if defined(USE_WEBKIT_COMPOSITOR) | 615 #if defined(USE_WEBKIT_COMPOSITOR) |
| 583 if (visible_) | 616 if (visible_) |
| 584 web_layer_.setOpacity(opacity); | 617 web_layer_.setOpacity(opacity); |
| 585 RecomputeDrawsContent(); | |
| 586 #endif | 618 #endif |
| 587 } | 619 } |
| 588 | 620 |
| 589 void Layer::SetBoundsFromAnimator(const gfx::Rect& bounds) { | 621 void Layer::SetBoundsFromAnimator(const gfx::Rect& bounds) { |
| 590 SetBoundsImmediately(bounds); | 622 SetBoundsImmediately(bounds); |
| 591 } | 623 } |
| 592 | 624 |
| 593 void Layer::SetTransformFromAnimator(const Transform& transform) { | 625 void Layer::SetTransformFromAnimator(const Transform& transform) { |
| 594 SetTransformImmediately(transform); | 626 SetTransformImmediately(transform); |
| 595 } | 627 } |
| 596 | 628 |
| 597 void Layer::SetOpacityFromAnimator(float opacity) { | 629 void Layer::SetOpacityFromAnimator(float opacity) { |
| 598 SetOpacityImmediately(opacity); | 630 SetOpacityImmediately(opacity); |
| 599 } | 631 } |
| 600 | 632 |
| 601 #if defined(USE_WEBKIT_COMPOSITOR) | 633 #if defined(USE_WEBKIT_COMPOSITOR) |
| 602 void Layer::CreateWebLayer() { | 634 void Layer::CreateWebLayer() { |
| 603 web_layer_ = WebKit::WebContentLayer::create(this, this); | 635 web_layer_ = WebKit::WebContentLayer::create(this, this); |
| 604 web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); | 636 web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); |
| 605 web_layer_.setOpaque(true); | 637 web_layer_.setOpaque(true); |
| 638 web_layer_is_accelerated_ = false; |
| 606 RecomputeDrawsContent(); | 639 RecomputeDrawsContent(); |
| 607 } | 640 } |
| 608 | 641 |
| 609 void Layer::RecomputeTransform() { | 642 void Layer::RecomputeTransform() { |
| 610 ui::Transform transform = transform_; | 643 ui::Transform transform = transform_; |
| 611 transform.ConcatTranslate(bounds_.x(), bounds_.y()); | 644 transform.ConcatTranslate(bounds_.x(), bounds_.y()); |
| 612 web_layer_.setTransform(transform.matrix()); | 645 web_layer_.setTransform(transform.matrix()); |
| 613 } | 646 } |
| 614 | 647 |
| 615 void Layer::RecomputeDrawsContent() { | 648 void Layer::RecomputeDrawsContent() { |
| 616 web_layer_.setDrawsContent(ShouldDraw()); | 649 DCHECK(!web_layer_.isNull()); |
| 650 bool should_draw = type_ == LAYER_HAS_TEXTURE && |
| 651 !hole_rect_.Contains(gfx::Rect(gfx::Point(0, 0), bounds_.size())); |
| 652 if (!web_layer_is_accelerated_) { |
| 653 web_layer_.to<WebKit::WebContentLayer>().setDrawsContent(should_draw); |
| 654 } else { |
| 655 DCHECK(texture_); |
| 656 #if defined(USE_WEBKIT_COMPOSITOR) |
| 657 unsigned int texture_id = |
| 658 static_cast<TextureCC*>(texture_.get())->texture_id(); |
| 659 #else |
| 660 unsigned int texture_id = 0; |
| 661 #endif |
| 662 web_layer_.to<WebKit::WebExternalTextureLayer>().setTextureId( |
| 663 should_draw ? texture_id : 0); |
| 664 } |
| 617 } | 665 } |
| 618 #endif | 666 #endif |
| 619 | 667 |
| 620 } // namespace ui | 668 } // namespace ui |
| OLD | NEW |