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 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 void Layer::SetExternalTexture(Texture* texture) { | 364 void Layer::SetExternalTexture(Texture* texture) { |
365 DCHECK_EQ(type_, LAYER_TEXTURED); | 365 DCHECK_EQ(type_, LAYER_TEXTURED); |
366 layer_updated_externally_ = !!texture; | 366 layer_updated_externally_ = !!texture; |
367 texture_ = texture; | 367 texture_ = texture; |
368 if (web_layer_is_accelerated_ != layer_updated_externally_) { | 368 if (web_layer_is_accelerated_ != layer_updated_externally_) { |
369 // Switch to a different type of layer. | 369 // Switch to a different type of layer. |
370 web_layer_.removeAllChildren(); | 370 web_layer_.removeAllChildren(); |
371 WebKit::WebLayer new_layer; | 371 WebKit::WebLayer new_layer; |
372 if (layer_updated_externally_) { | 372 if (layer_updated_externally_) { |
373 WebKit::WebExternalTextureLayer texture_layer = | 373 WebKit::WebExternalTextureLayer texture_layer = |
374 WebKit::WebExternalTextureLayer::create(this); | 374 WebKit::WebExternalTextureLayer::create(); |
375 texture_layer.setFlipped(texture_->flipped()); | 375 texture_layer.setFlipped(texture_->flipped()); |
376 new_layer = texture_layer; | 376 new_layer = texture_layer; |
377 } else { | 377 } else { |
378 // Tell the compositor to clear references to the old texture. | |
379 WebKit::WebExternalTextureLayer texture_layer = | |
380 web_layer_.to<WebKit::WebExternalTextureLayer>(); | |
381 texture_layer.willModifyTexture(); | |
382 new_layer = WebKit::WebContentLayer::create(this); | 378 new_layer = WebKit::WebContentLayer::create(this); |
383 } | 379 } |
384 if (parent_) { | 380 if (parent_) { |
385 DCHECK(!parent_->web_layer_.isNull()); | 381 DCHECK(!parent_->web_layer_.isNull()); |
386 parent_->web_layer_.replaceChild(web_layer_, new_layer); | 382 parent_->web_layer_.replaceChild(web_layer_, new_layer); |
387 } | 383 } |
388 web_layer_ = new_layer; | 384 web_layer_ = new_layer; |
389 web_layer_is_accelerated_ = layer_updated_externally_; | 385 web_layer_is_accelerated_ = layer_updated_externally_; |
390 for (size_t i = 0; i < children_.size(); ++i) { | 386 for (size_t i = 0; i < children_.size(); ++i) { |
391 DCHECK(!children_[i]->web_layer_.isNull()); | 387 DCHECK(!children_[i]->web_layer_.isNull()); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 canvas->sk_canvas()->scale(SkFloatToScalar(device_scale_factor_), | 496 canvas->sk_canvas()->scale(SkFloatToScalar(device_scale_factor_), |
501 SkFloatToScalar(device_scale_factor_)); | 497 SkFloatToScalar(device_scale_factor_)); |
502 } | 498 } |
503 | 499 |
504 if (delegate_) | 500 if (delegate_) |
505 delegate_->OnPaintLayer(canvas.get()); | 501 delegate_->OnPaintLayer(canvas.get()); |
506 if (scale_content_) | 502 if (scale_content_) |
507 canvas->Restore(); | 503 canvas->Restore(); |
508 } | 504 } |
509 | 505 |
510 unsigned Layer::prepareTexture(WebKit::WebTextureUpdater& /* updater */) { | |
511 DCHECK(layer_updated_externally_); | |
512 return texture_->texture_id(); | |
513 } | |
514 | |
515 WebKit::WebGraphicsContext3D* Layer::context() { | |
516 DCHECK(layer_updated_externally_); | |
517 return texture_->HostContext3D(); | |
518 } | |
519 | |
520 void Layer::SetForceRenderSurface(bool force) { | 506 void Layer::SetForceRenderSurface(bool force) { |
521 if (force_render_surface_ == force) | 507 if (force_render_surface_ == force) |
522 return; | 508 return; |
523 | 509 |
524 force_render_surface_ = force; | 510 force_render_surface_ = force; |
525 web_layer_.setForceRenderSurface(force_render_surface_); | 511 web_layer_.setForceRenderSurface(force_render_surface_); |
526 } | 512 } |
527 | 513 |
528 float Layer::GetCombinedOpacity() const { | 514 float Layer::GetCombinedOpacity() const { |
529 float opacity = opacity_; | 515 float opacity = opacity_; |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 | 720 |
735 void Layer::RecomputeDrawsContentAndUVRect() { | 721 void Layer::RecomputeDrawsContentAndUVRect() { |
736 DCHECK(!web_layer_.isNull()); | 722 DCHECK(!web_layer_.isNull()); |
737 bool should_draw = type_ != LAYER_NOT_DRAWN; | 723 bool should_draw = type_ != LAYER_NOT_DRAWN; |
738 if (!web_layer_is_accelerated_) { | 724 if (!web_layer_is_accelerated_) { |
739 if (type_ != LAYER_SOLID_COLOR) | 725 if (type_ != LAYER_SOLID_COLOR) |
740 web_layer_.to<WebKit::WebContentLayer>().setDrawsContent(should_draw); | 726 web_layer_.to<WebKit::WebContentLayer>().setDrawsContent(should_draw); |
741 web_layer_.setBounds(ConvertSizeToPixel(this, bounds_.size())); | 727 web_layer_.setBounds(ConvertSizeToPixel(this, bounds_.size())); |
742 } else { | 728 } else { |
743 DCHECK(texture_); | 729 DCHECK(texture_); |
| 730 unsigned int texture_id = texture_->texture_id(); |
744 WebKit::WebExternalTextureLayer texture_layer = | 731 WebKit::WebExternalTextureLayer texture_layer = |
745 web_layer_.to<WebKit::WebExternalTextureLayer>(); | 732 web_layer_.to<WebKit::WebExternalTextureLayer>(); |
| 733 texture_layer.setTextureId(should_draw ? texture_id : 0); |
746 | 734 |
747 gfx::Size texture_size; | 735 gfx::Size texture_size; |
748 if (scale_content_) | 736 if (scale_content_) |
749 texture_size = texture_->size(); | 737 texture_size = texture_->size(); |
750 else | 738 else |
751 texture_size = ConvertSizeToDIP(this, texture_->size()); | 739 texture_size = ConvertSizeToDIP(this, texture_->size()); |
752 | 740 |
753 gfx::Size size(std::min(bounds().width(), texture_size.width()), | 741 gfx::Size size(std::min(bounds().width(), texture_size.width()), |
754 std::min(bounds().height(), texture_size.height())); | 742 std::min(bounds().height(), texture_size.height())); |
755 WebKit::WebFloatRect rect( | 743 WebKit::WebFloatRect rect( |
(...skipping 13 matching lines...) Expand all Loading... |
769 return; | 757 return; |
770 unsigned int color = 0xFF000000; | 758 unsigned int color = 0xFF000000; |
771 color |= web_layer_is_accelerated_ ? 0x0000FF00 : 0x00FF0000; | 759 color |= web_layer_is_accelerated_ ? 0x0000FF00 : 0x00FF0000; |
772 bool opaque = fills_bounds_opaquely_ && (GetCombinedOpacity() == 1.f); | 760 bool opaque = fills_bounds_opaquely_ && (GetCombinedOpacity() == 1.f); |
773 if (!opaque) | 761 if (!opaque) |
774 color |= 0xFF; | 762 color |= 0xFF; |
775 web_layer_.setDebugBorderColor(color); | 763 web_layer_.setDebugBorderColor(color); |
776 } | 764 } |
777 | 765 |
778 } // namespace ui | 766 } // namespace ui |
OLD | NEW |