| 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/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 web_layer_.addChild(children_[i]->web_layer_); | 272 web_layer_.addChild(children_[i]->web_layer_); |
| 273 } | 273 } |
| 274 web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); | 274 web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); |
| 275 web_layer_.setOpaque(fills_bounds_opaquely_); | 275 web_layer_.setOpaque(fills_bounds_opaquely_); |
| 276 web_layer_.setOpacity(visible_ ? opacity_ : 0.f); | 276 web_layer_.setOpacity(visible_ ? opacity_ : 0.f); |
| 277 web_layer_.setBounds(bounds_.size()); | 277 web_layer_.setBounds(bounds_.size()); |
| 278 RecomputeTransform(); | 278 RecomputeTransform(); |
| 279 } | 279 } |
| 280 TextureCC* texture_cc = static_cast<TextureCC*>(texture); | 280 TextureCC* texture_cc = static_cast<TextureCC*>(texture); |
| 281 texture_cc->Update(); | 281 texture_cc->Update(); |
| 282 web_layer_.to<WebKit::WebExternalTextureLayer>().setFlipped( | 282 WebKit::WebExternalTextureLayer texture_layer = |
| 283 texture_cc->flipped()); | 283 web_layer_.to<WebKit::WebExternalTextureLayer>(); |
| 284 RecomputeDrawsContent(); | 284 texture_layer.setFlipped(texture_cc->flipped()); |
| 285 RecomputeDrawsContentAndUVRect(); |
| 285 #endif | 286 #endif |
| 286 } | 287 } |
| 287 | 288 |
| 288 void Layer::SetCanvas(const SkCanvas& canvas, const gfx::Point& origin) { | 289 void Layer::SetCanvas(const SkCanvas& canvas, const gfx::Point& origin) { |
| 289 #if defined(USE_WEBKIT_COMPOSITOR) | 290 #if defined(USE_WEBKIT_COMPOSITOR) |
| 290 NOTREACHED(); | 291 NOTREACHED(); |
| 291 #else | 292 #else |
| 292 DCHECK_EQ(type_, LAYER_HAS_TEXTURE); | 293 DCHECK_EQ(type_, LAYER_HAS_TEXTURE); |
| 293 | 294 |
| 294 if (!texture_.get()) | 295 if (!texture_.get()) |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 // Ensure we have the largest hole. | 471 // Ensure we have the largest hole. |
| 471 if (candidate_hole.size().GetArea() > hole_rect_.size().GetArea()) | 472 if (candidate_hole.size().GetArea() > hole_rect_.size().GetArea()) |
| 472 hole_rect_ = candidate_hole; | 473 hole_rect_ = candidate_hole; |
| 473 } | 474 } |
| 474 | 475 |
| 475 // Free up texture memory if the hole fills bounds of layer. | 476 // Free up texture memory if the hole fills bounds of layer. |
| 476 if (!ShouldDraw() && !layer_updated_externally_) | 477 if (!ShouldDraw() && !layer_updated_externally_) |
| 477 texture_ = NULL; | 478 texture_ = NULL; |
| 478 | 479 |
| 479 #if defined(USE_WEBKIT_COMPOSITOR) | 480 #if defined(USE_WEBKIT_COMPOSITOR) |
| 480 RecomputeDrawsContent(); | 481 RecomputeDrawsContentAndUVRect(); |
| 481 #endif | 482 #endif |
| 482 } | 483 } |
| 483 | 484 |
| 484 bool Layer::IsCompletelyOpaque() const { | 485 bool Layer::IsCompletelyOpaque() const { |
| 485 return fills_bounds_opaquely() && GetCombinedOpacity() == 1.0f; | 486 return fills_bounds_opaquely() && GetCombinedOpacity() == 1.0f; |
| 486 } | 487 } |
| 487 | 488 |
| 488 // static | 489 // static |
| 489 void Layer::PunchHole(const gfx::Rect& rect, | 490 void Layer::PunchHole(const gfx::Rect& rect, |
| 490 const gfx::Rect& region_to_punch_out, | 491 const gfx::Rect& region_to_punch_out, |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 ScheduleDraw(); | 572 ScheduleDraw(); |
| 572 else | 573 else |
| 573 SchedulePaint(gfx::Rect(bounds.size())); | 574 SchedulePaint(gfx::Rect(bounds.size())); |
| 574 } | 575 } |
| 575 | 576 |
| 576 if (parent()) | 577 if (parent()) |
| 577 parent()->RecomputeHole(); | 578 parent()->RecomputeHole(); |
| 578 #if defined(USE_WEBKIT_COMPOSITOR) | 579 #if defined(USE_WEBKIT_COMPOSITOR) |
| 579 web_layer_.setBounds(bounds.size()); | 580 web_layer_.setBounds(bounds.size()); |
| 580 RecomputeTransform(); | 581 RecomputeTransform(); |
| 581 RecomputeDrawsContent(); | 582 RecomputeDrawsContentAndUVRect(); |
| 582 #endif | 583 #endif |
| 583 } | 584 } |
| 584 | 585 |
| 585 void Layer::SetTransformImmediately(const ui::Transform& transform) { | 586 void Layer::SetTransformImmediately(const ui::Transform& transform) { |
| 586 transform_ = transform; | 587 transform_ = transform; |
| 587 | 588 |
| 588 if (parent()) | 589 if (parent()) |
| 589 parent()->RecomputeHole(); | 590 parent()->RecomputeHole(); |
| 590 #if defined(USE_WEBKIT_COMPOSITOR) | 591 #if defined(USE_WEBKIT_COMPOSITOR) |
| 591 RecomputeTransform(); | 592 RecomputeTransform(); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 float Layer::GetOpacityForAnimation() const { | 649 float Layer::GetOpacityForAnimation() const { |
| 649 return opacity(); | 650 return opacity(); |
| 650 } | 651 } |
| 651 | 652 |
| 652 #if defined(USE_WEBKIT_COMPOSITOR) | 653 #if defined(USE_WEBKIT_COMPOSITOR) |
| 653 void Layer::CreateWebLayer() { | 654 void Layer::CreateWebLayer() { |
| 654 web_layer_ = WebKit::WebContentLayer::create(this, this); | 655 web_layer_ = WebKit::WebContentLayer::create(this, this); |
| 655 web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); | 656 web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); |
| 656 web_layer_.setOpaque(true); | 657 web_layer_.setOpaque(true); |
| 657 web_layer_is_accelerated_ = false; | 658 web_layer_is_accelerated_ = false; |
| 658 RecomputeDrawsContent(); | 659 RecomputeDrawsContentAndUVRect(); |
| 659 } | 660 } |
| 660 | 661 |
| 661 void Layer::RecomputeTransform() { | 662 void Layer::RecomputeTransform() { |
| 662 ui::Transform transform = transform_; | 663 ui::Transform transform = transform_; |
| 663 transform.ConcatTranslate(bounds_.x(), bounds_.y()); | 664 transform.ConcatTranslate(bounds_.x(), bounds_.y()); |
| 664 web_layer_.setTransform(transform.matrix()); | 665 web_layer_.setTransform(transform.matrix()); |
| 665 } | 666 } |
| 666 | 667 |
| 667 void Layer::RecomputeDrawsContent() { | 668 void Layer::RecomputeDrawsContentAndUVRect() { |
| 668 DCHECK(!web_layer_.isNull()); | 669 DCHECK(!web_layer_.isNull()); |
| 669 bool should_draw = type_ == LAYER_HAS_TEXTURE && | 670 bool should_draw = type_ == LAYER_HAS_TEXTURE && |
| 670 !hole_rect_.Contains(gfx::Rect(gfx::Point(0, 0), bounds_.size())); | 671 !hole_rect_.Contains(gfx::Rect(gfx::Point(0, 0), bounds_.size())); |
| 671 if (!web_layer_is_accelerated_) { | 672 if (!web_layer_is_accelerated_) { |
| 672 web_layer_.to<WebKit::WebContentLayer>().setDrawsContent(should_draw); | 673 web_layer_.to<WebKit::WebContentLayer>().setDrawsContent(should_draw); |
| 673 } else { | 674 } else { |
| 674 DCHECK(texture_); | 675 DCHECK(texture_); |
| 675 #if defined(USE_WEBKIT_COMPOSITOR) | 676 TextureCC* texture_cc = static_cast<TextureCC*>(texture_.get()); |
| 676 unsigned int texture_id = | 677 unsigned int texture_id = texture_cc->texture_id(); |
| 677 static_cast<TextureCC*>(texture_.get())->texture_id(); | 678 WebKit::WebExternalTextureLayer texture_layer = |
| 678 #else | 679 web_layer_.to<WebKit::WebExternalTextureLayer>(); |
| 679 unsigned int texture_id = 0; | 680 texture_layer.setTextureId(should_draw ? texture_id : 0); |
| 680 #endif | 681 WebKit::WebFloatRect rect( |
| 681 web_layer_.to<WebKit::WebExternalTextureLayer>().setTextureId( | 682 0, |
| 682 should_draw ? texture_id : 0); | 683 0, |
| 684 static_cast<float>(bounds_.width())/texture_cc->size().width(), |
| 685 static_cast<float>(bounds_.height())/texture_cc->size().height()); |
| 686 texture_layer.setUVRect(rect); |
| 683 } | 687 } |
| 684 } | 688 } |
| 685 #endif | 689 #endif |
| 686 | 690 |
| 687 } // namespace ui | 691 } // namespace ui |
| OLD | NEW |