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 if (!web_layer_.isNull()) { | |
piman
2012/07/12 00:18:09
I don't think web_layer_.isNull() is ever true (we
jonathan.backer
2012/07/12 13:53:22
Thanks. Done.
| |
319 // Tell the compositor to clear references to the old texture. | |
320 WebKit::WebExternalTextureLayer texture_layer = | |
321 web_layer_.to<WebKit::WebExternalTextureLayer>(); | |
322 texture_layer.willModifyTexture(); | |
323 } | |
318 new_layer = WebKit::WebContentLayer::create(this); | 324 new_layer = WebKit::WebContentLayer::create(this); |
319 } | 325 } |
320 if (parent_) { | 326 if (parent_) { |
321 DCHECK(!parent_->web_layer_.isNull()); | 327 DCHECK(!parent_->web_layer_.isNull()); |
322 parent_->web_layer_.replaceChild(web_layer_, new_layer); | 328 parent_->web_layer_.replaceChild(web_layer_, new_layer); |
323 } | 329 } |
324 web_layer_ = new_layer; | 330 web_layer_ = new_layer; |
325 web_layer_is_accelerated_ = layer_updated_externally_; | 331 web_layer_is_accelerated_ = layer_updated_externally_; |
326 for (size_t i = 0; i < children_.size(); ++i) { | 332 for (size_t i = 0; i < children_.size(); ++i) { |
327 DCHECK(!children_[i]->web_layer_.isNull()); | 333 DCHECK(!children_[i]->web_layer_.isNull()); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
428 WebKit::WebRect& opaque) { | 434 WebKit::WebRect& opaque) { |
429 #endif | 435 #endif |
430 TRACE_EVENT0("ui", "Layer::paintContents"); | 436 TRACE_EVENT0("ui", "Layer::paintContents"); |
431 gfx::Canvas canvas(web_canvas, | 437 gfx::Canvas canvas(web_canvas, |
432 ui::GetScaleFactorFromScale(device_scale_factor_), scale_content_); | 438 ui::GetScaleFactorFromScale(device_scale_factor_), scale_content_); |
433 | 439 |
434 if (delegate_) | 440 if (delegate_) |
435 delegate_->OnPaintLayer(&canvas); | 441 delegate_->OnPaintLayer(&canvas); |
436 } | 442 } |
437 | 443 |
444 unsigned Layer::prepareTexture(WebKit::WebTextureUpdater& /* updater */) { | |
445 DCHECK(layer_updated_externally_); | |
446 return texture_->texture_id(); | |
447 } | |
448 | |
449 WebKit::WebGraphicsContext3D* Layer::context() { | |
450 DCHECK(layer_updated_externally_); | |
451 return texture_->hostContext3D(); | |
452 } | |
453 | |
438 void Layer::SetForceRenderSurface(bool force) { | 454 void Layer::SetForceRenderSurface(bool force) { |
439 if (force_render_surface_ == force) | 455 if (force_render_surface_ == force) |
440 return; | 456 return; |
441 | 457 |
442 force_render_surface_ = force; | 458 force_render_surface_ = force; |
443 web_layer_.setForceRenderSurface(force_render_surface_); | 459 web_layer_.setForceRenderSurface(force_render_surface_); |
444 } | 460 } |
445 | 461 |
446 float Layer::GetCombinedOpacity() const { | 462 float Layer::GetCombinedOpacity() const { |
447 float opacity = opacity_; | 463 float opacity = opacity_; |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
627 | 643 |
628 void Layer::RecomputeDrawsContentAndUVRect() { | 644 void Layer::RecomputeDrawsContentAndUVRect() { |
629 DCHECK(!web_layer_.isNull()); | 645 DCHECK(!web_layer_.isNull()); |
630 bool should_draw = type_ != LAYER_NOT_DRAWN; | 646 bool should_draw = type_ != LAYER_NOT_DRAWN; |
631 if (!web_layer_is_accelerated_) { | 647 if (!web_layer_is_accelerated_) { |
632 if (type_ != LAYER_SOLID_COLOR) | 648 if (type_ != LAYER_SOLID_COLOR) |
633 web_layer_.to<WebKit::WebContentLayer>().setDrawsContent(should_draw); | 649 web_layer_.to<WebKit::WebContentLayer>().setDrawsContent(should_draw); |
634 web_layer_.setBounds(ConvertSizeToPixel(this, bounds_.size())); | 650 web_layer_.setBounds(ConvertSizeToPixel(this, bounds_.size())); |
635 } else { | 651 } else { |
636 DCHECK(texture_); | 652 DCHECK(texture_); |
637 unsigned int texture_id = texture_->texture_id(); | |
638 WebKit::WebExternalTextureLayer texture_layer = | 653 WebKit::WebExternalTextureLayer texture_layer = |
639 web_layer_.to<WebKit::WebExternalTextureLayer>(); | 654 web_layer_.to<WebKit::WebExternalTextureLayer>(); |
640 texture_layer.setTextureId(should_draw ? texture_id : 0); | |
641 | 655 |
642 gfx::Size texture_size; | 656 gfx::Size texture_size; |
643 if (scale_content_) | 657 if (scale_content_) |
644 texture_size = texture_->size(); | 658 texture_size = texture_->size(); |
645 else | 659 else |
646 texture_size = ConvertSizeToDIP(this, texture_->size()); | 660 texture_size = ConvertSizeToDIP(this, texture_->size()); |
647 | 661 |
648 gfx::Size size(std::min(bounds().width(), texture_size.width()), | 662 gfx::Size size(std::min(bounds().width(), texture_size.width()), |
649 std::min(bounds().height(), texture_size.height())); | 663 std::min(bounds().height(), texture_size.height())); |
650 WebKit::WebFloatRect rect( | 664 WebKit::WebFloatRect rect( |
(...skipping 13 matching lines...) Expand all Loading... | |
664 return; | 678 return; |
665 unsigned int color = 0xFF000000; | 679 unsigned int color = 0xFF000000; |
666 color |= web_layer_is_accelerated_ ? 0x0000FF00 : 0x00FF0000; | 680 color |= web_layer_is_accelerated_ ? 0x0000FF00 : 0x00FF0000; |
667 bool opaque = fills_bounds_opaquely_ && (GetCombinedOpacity() == 1.f); | 681 bool opaque = fills_bounds_opaquely_ && (GetCombinedOpacity() == 1.f); |
668 if (!opaque) | 682 if (!opaque) |
669 color |= 0xFF; | 683 color |= 0xFF; |
670 web_layer_.setDebugBorderColor(color); | 684 web_layer_.setDebugBorderColor(color); |
671 } | 685 } |
672 | 686 |
673 } // namespace ui | 687 } // namespace ui |
OLD | NEW |