OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "ui/compositor/layer.h" | 5 #include "ui/compositor/layer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 void Layer::SetExternalTexture(Texture* texture) { | 304 void Layer::SetExternalTexture(Texture* texture) { |
305 DCHECK_EQ(type_, LAYER_TEXTURED); | 305 DCHECK_EQ(type_, LAYER_TEXTURED); |
306 layer_updated_externally_ = !!texture; | 306 layer_updated_externally_ = !!texture; |
307 texture_ = texture; | 307 texture_ = texture; |
308 if (web_layer_is_accelerated_ != layer_updated_externally_) { | 308 if (web_layer_is_accelerated_ != layer_updated_externally_) { |
309 // Switch to a different type of layer. | 309 // Switch to a different type of layer. |
310 web_layer_.removeAllChildren(); | 310 web_layer_.removeAllChildren(); |
311 WebKit::WebLayer new_layer; | 311 WebKit::WebLayer new_layer; |
312 if (layer_updated_externally_) { | 312 if (layer_updated_externally_) { |
313 WebKit::WebExternalTextureLayer texture_layer = | 313 WebKit::WebExternalTextureLayer texture_layer = |
314 WebKit::WebExternalTextureLayer::create(); | 314 WebKit::WebExternalTextureLayer::create(this); |
315 texture_layer.setFlipped(texture_->flipped()); | 315 texture_layer.setFlipped(texture_->flipped()); |
316 new_layer = texture_layer; | 316 new_layer = texture_layer; |
317 } else { | 317 } else { |
| 318 // Tell the compositor to clear references to the old texture. |
| 319 WebKit::WebExternalTextureLayer texture_layer = |
| 320 web_layer_.to<WebKit::WebExternalTextureLayer>(); |
| 321 texture_layer.willModifyTexture(); |
318 new_layer = WebKit::WebContentLayer::create(this); | 322 new_layer = WebKit::WebContentLayer::create(this); |
319 } | 323 } |
320 if (parent_) { | 324 if (parent_) { |
321 DCHECK(!parent_->web_layer_.isNull()); | 325 DCHECK(!parent_->web_layer_.isNull()); |
322 parent_->web_layer_.replaceChild(web_layer_, new_layer); | 326 parent_->web_layer_.replaceChild(web_layer_, new_layer); |
323 } | 327 } |
324 web_layer_ = new_layer; | 328 web_layer_ = new_layer; |
325 web_layer_is_accelerated_ = layer_updated_externally_; | 329 web_layer_is_accelerated_ = layer_updated_externally_; |
326 for (size_t i = 0; i < children_.size(); ++i) { | 330 for (size_t i = 0; i < children_.size(); ++i) { |
327 DCHECK(!children_[i]->web_layer_.isNull()); | 331 DCHECK(!children_[i]->web_layer_.isNull()); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 WebKit::WebRect& opaque) { | 432 WebKit::WebRect& opaque) { |
429 #endif | 433 #endif |
430 TRACE_EVENT0("ui", "Layer::paintContents"); | 434 TRACE_EVENT0("ui", "Layer::paintContents"); |
431 gfx::Canvas canvas(web_canvas, | 435 gfx::Canvas canvas(web_canvas, |
432 ui::GetScaleFactorFromScale(device_scale_factor_), scale_content_); | 436 ui::GetScaleFactorFromScale(device_scale_factor_), scale_content_); |
433 | 437 |
434 if (delegate_) | 438 if (delegate_) |
435 delegate_->OnPaintLayer(&canvas); | 439 delegate_->OnPaintLayer(&canvas); |
436 } | 440 } |
437 | 441 |
| 442 unsigned Layer::prepareTexture(WebKit::WebTextureUpdater& /* updater */) { |
| 443 DCHECK(layer_updated_externally_); |
| 444 return texture_->texture_id(); |
| 445 } |
| 446 |
| 447 WebKit::WebGraphicsContext3D* Layer::context() { |
| 448 DCHECK(layer_updated_externally_); |
| 449 return texture_->HostContext3D(); |
| 450 } |
| 451 |
438 void Layer::SetForceRenderSurface(bool force) { | 452 void Layer::SetForceRenderSurface(bool force) { |
439 if (force_render_surface_ == force) | 453 if (force_render_surface_ == force) |
440 return; | 454 return; |
441 | 455 |
442 force_render_surface_ = force; | 456 force_render_surface_ = force; |
443 web_layer_.setForceRenderSurface(force_render_surface_); | 457 web_layer_.setForceRenderSurface(force_render_surface_); |
444 } | 458 } |
445 | 459 |
446 float Layer::GetCombinedOpacity() const { | 460 float Layer::GetCombinedOpacity() const { |
447 float opacity = opacity_; | 461 float opacity = opacity_; |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 | 641 |
628 void Layer::RecomputeDrawsContentAndUVRect() { | 642 void Layer::RecomputeDrawsContentAndUVRect() { |
629 DCHECK(!web_layer_.isNull()); | 643 DCHECK(!web_layer_.isNull()); |
630 bool should_draw = type_ != LAYER_NOT_DRAWN; | 644 bool should_draw = type_ != LAYER_NOT_DRAWN; |
631 if (!web_layer_is_accelerated_) { | 645 if (!web_layer_is_accelerated_) { |
632 if (type_ != LAYER_SOLID_COLOR) | 646 if (type_ != LAYER_SOLID_COLOR) |
633 web_layer_.to<WebKit::WebContentLayer>().setDrawsContent(should_draw); | 647 web_layer_.to<WebKit::WebContentLayer>().setDrawsContent(should_draw); |
634 web_layer_.setBounds(ConvertSizeToPixel(this, bounds_.size())); | 648 web_layer_.setBounds(ConvertSizeToPixel(this, bounds_.size())); |
635 } else { | 649 } else { |
636 DCHECK(texture_); | 650 DCHECK(texture_); |
637 unsigned int texture_id = texture_->texture_id(); | |
638 WebKit::WebExternalTextureLayer texture_layer = | 651 WebKit::WebExternalTextureLayer texture_layer = |
639 web_layer_.to<WebKit::WebExternalTextureLayer>(); | 652 web_layer_.to<WebKit::WebExternalTextureLayer>(); |
640 texture_layer.setTextureId(should_draw ? texture_id : 0); | |
641 | 653 |
642 gfx::Size texture_size; | 654 gfx::Size texture_size; |
643 if (scale_content_) | 655 if (scale_content_) |
644 texture_size = texture_->size(); | 656 texture_size = texture_->size(); |
645 else | 657 else |
646 texture_size = ConvertSizeToDIP(this, texture_->size()); | 658 texture_size = ConvertSizeToDIP(this, texture_->size()); |
647 | 659 |
648 gfx::Size size(std::min(bounds().width(), texture_size.width()), | 660 gfx::Size size(std::min(bounds().width(), texture_size.width()), |
649 std::min(bounds().height(), texture_size.height())); | 661 std::min(bounds().height(), texture_size.height())); |
650 WebKit::WebFloatRect rect( | 662 WebKit::WebFloatRect rect( |
(...skipping 13 matching lines...) Expand all Loading... |
664 return; | 676 return; |
665 unsigned int color = 0xFF000000; | 677 unsigned int color = 0xFF000000; |
666 color |= web_layer_is_accelerated_ ? 0x0000FF00 : 0x00FF0000; | 678 color |= web_layer_is_accelerated_ ? 0x0000FF00 : 0x00FF0000; |
667 bool opaque = fills_bounds_opaquely_ && (GetCombinedOpacity() == 1.f); | 679 bool opaque = fills_bounds_opaquely_ && (GetCombinedOpacity() == 1.f); |
668 if (!opaque) | 680 if (!opaque) |
669 color |= 0xFF; | 681 color |= 0xFF; |
670 web_layer_.setDebugBorderColor(color); | 682 web_layer_.setDebugBorderColor(color); |
671 } | 683 } |
672 | 684 |
673 } // namespace ui | 685 } // namespace ui |
OLD | NEW |