Chromium Code Reviews| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 background_blur_radius_(0), | 58 background_blur_radius_(0), |
| 59 layer_saturation_(0.0f), | 59 layer_saturation_(0.0f), |
| 60 layer_brightness_(0.0f), | 60 layer_brightness_(0.0f), |
| 61 layer_grayscale_(0.0f), | 61 layer_grayscale_(0.0f), |
| 62 layer_inverted_(false), | 62 layer_inverted_(false), |
| 63 layer_mask_(NULL), | 63 layer_mask_(NULL), |
| 64 layer_mask_back_link_(NULL), | 64 layer_mask_back_link_(NULL), |
| 65 delegate_(NULL), | 65 delegate_(NULL), |
| 66 web_layer_(NULL), | 66 web_layer_(NULL), |
| 67 scale_content_(true), | 67 scale_content_(true), |
| 68 device_scale_factor_(1.0f) { | 68 device_scale_factor_(1.0f), |
| 69 device_scale_factor_for_texture_(1.0f) { | |
| 69 CreateWebLayer(); | 70 CreateWebLayer(); |
| 70 } | 71 } |
| 71 | 72 |
| 72 Layer::Layer(LayerType type) | 73 Layer::Layer(LayerType type) |
| 73 : type_(type), | 74 : type_(type), |
| 74 compositor_(NULL), | 75 compositor_(NULL), |
| 75 parent_(NULL), | 76 parent_(NULL), |
| 76 visible_(true), | 77 visible_(true), |
| 77 force_render_surface_(false), | 78 force_render_surface_(false), |
| 78 fills_bounds_opaquely_(true), | 79 fills_bounds_opaquely_(true), |
| 79 layer_updated_externally_(false), | 80 layer_updated_externally_(false), |
| 80 opacity_(1.0f), | 81 opacity_(1.0f), |
| 81 background_blur_radius_(0), | 82 background_blur_radius_(0), |
| 82 layer_saturation_(0.0f), | 83 layer_saturation_(0.0f), |
| 83 layer_brightness_(0.0f), | 84 layer_brightness_(0.0f), |
| 84 layer_grayscale_(0.0f), | 85 layer_grayscale_(0.0f), |
| 85 layer_inverted_(false), | 86 layer_inverted_(false), |
| 86 layer_mask_(NULL), | 87 layer_mask_(NULL), |
| 87 layer_mask_back_link_(NULL), | 88 layer_mask_back_link_(NULL), |
| 88 delegate_(NULL), | 89 delegate_(NULL), |
| 89 scale_content_(true), | 90 scale_content_(true), |
| 90 device_scale_factor_(1.0f) { | 91 device_scale_factor_(1.0f), |
| 92 device_scale_factor_for_texture_(1.0f) { | |
| 91 CreateWebLayer(); | 93 CreateWebLayer(); |
| 92 } | 94 } |
| 93 | 95 |
| 94 Layer::~Layer() { | 96 Layer::~Layer() { |
| 95 // Destroying the animator may cause observers to use the layer (and | 97 // Destroying the animator may cause observers to use the layer (and |
| 96 // indirectly the WebLayer). Destroy the animator first so that the WebLayer | 98 // indirectly the WebLayer). Destroy the animator first so that the WebLayer |
| 97 // is still around. | 99 // is still around. |
| 98 animator_.reset(); | 100 animator_.reset(); |
| 99 if (compositor_) | 101 if (compositor_) |
| 100 compositor_->SetRootLayer(NULL); | 102 compositor_->SetRootLayer(NULL); |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 371 fills_bounds_opaquely_ = fills_bounds_opaquely; | 373 fills_bounds_opaquely_ = fills_bounds_opaquely; |
| 372 | 374 |
| 373 web_layer_->setOpaque(fills_bounds_opaquely); | 375 web_layer_->setOpaque(fills_bounds_opaquely); |
| 374 RecomputeDebugBorderColor(); | 376 RecomputeDebugBorderColor(); |
| 375 } | 377 } |
| 376 | 378 |
| 377 void Layer::SetExternalTexture(Texture* texture) { | 379 void Layer::SetExternalTexture(Texture* texture) { |
| 378 DCHECK_EQ(type_, LAYER_TEXTURED); | 380 DCHECK_EQ(type_, LAYER_TEXTURED); |
| 379 layer_updated_externally_ = !!texture; | 381 layer_updated_externally_ = !!texture; |
| 380 texture_ = texture; | 382 texture_ = texture; |
| 383 device_scale_factor_for_texture_ = device_scale_factor_; | |
|
piman
2012/09/20 23:20:07
mmh, that may solve the problem in a given case, b
Jun Mukai
2012/09/21 00:53:55
hmm, then added the device_scale_factor to ui::Tex
| |
| 381 if (web_layer_is_accelerated_ != layer_updated_externally_) { | 384 if (web_layer_is_accelerated_ != layer_updated_externally_) { |
| 382 // Switch to a different type of layer. | 385 // Switch to a different type of layer. |
| 383 web_layer_->removeAllChildren(); | 386 web_layer_->removeAllChildren(); |
| 384 scoped_ptr<WebKit::WebContentLayer> old_content_layer( | 387 scoped_ptr<WebKit::WebContentLayer> old_content_layer( |
| 385 content_layer_.release()); | 388 content_layer_.release()); |
| 386 scoped_ptr<WebKit::WebSolidColorLayer> old_solid_layer( | 389 scoped_ptr<WebKit::WebSolidColorLayer> old_solid_layer( |
| 387 solid_color_layer_.release()); | 390 solid_color_layer_.release()); |
| 388 scoped_ptr<WebKit::WebExternalTextureLayer> old_texture_layer( | 391 scoped_ptr<WebKit::WebExternalTextureLayer> old_texture_layer( |
| 389 texture_layer_.release()); | 392 texture_layer_.release()); |
| 390 WebKit::WebLayer* new_layer = NULL; | 393 WebKit::WebLayer* new_layer = NULL; |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 742 bool should_draw = type_ != LAYER_NOT_DRAWN; | 745 bool should_draw = type_ != LAYER_NOT_DRAWN; |
| 743 if (!web_layer_is_accelerated_) { | 746 if (!web_layer_is_accelerated_) { |
| 744 if (type_ != LAYER_SOLID_COLOR) { | 747 if (type_ != LAYER_SOLID_COLOR) { |
| 745 web_layer_->setDrawsContent(should_draw); | 748 web_layer_->setDrawsContent(should_draw); |
| 746 } | 749 } |
| 747 web_layer_->setBounds(ConvertSizeToPixel(this, bounds_.size())); | 750 web_layer_->setBounds(ConvertSizeToPixel(this, bounds_.size())); |
| 748 } else { | 751 } else { |
| 749 DCHECK(texture_); | 752 DCHECK(texture_); |
| 750 | 753 |
| 751 gfx::Size texture_size; | 754 gfx::Size texture_size; |
| 752 if (scale_content_) | 755 if (scale_content_) { |
| 753 texture_size = texture_->size(); | 756 texture_size = texture_->size(); |
| 754 else | 757 } else { |
| 755 texture_size = ConvertSizeToDIP(this, texture_->size()); | 758 texture_size = |
| 759 texture_->size().Scale(1.0f / device_scale_factor_for_texture_); | |
| 760 } | |
| 756 | 761 |
| 757 gfx::Size size(std::min(bounds().width(), texture_size.width()), | 762 gfx::Size size(std::min(bounds().width(), texture_size.width()), |
| 758 std::min(bounds().height(), texture_size.height())); | 763 std::min(bounds().height(), texture_size.height())); |
| 759 WebKit::WebFloatRect rect( | 764 WebKit::WebFloatRect rect( |
| 760 0, | 765 0, |
| 761 0, | 766 0, |
| 762 static_cast<float>(size.width())/texture_size.width(), | 767 static_cast<float>(size.width())/texture_size.width(), |
| 763 static_cast<float>(size.height())/texture_size.height()); | 768 static_cast<float>(size.height())/texture_size.height()); |
| 764 texture_layer_->setUVRect(rect); | 769 texture_layer_->setUVRect(rect); |
| 765 | 770 |
| 766 gfx::Size size_in_pixel = ConvertSizeToPixel(this, size); | 771 gfx::Size size_in_pixel = ConvertSizeToPixel(this, size); |
| 767 web_layer_->setBounds(size_in_pixel); | 772 web_layer_->setBounds(size_in_pixel); |
| 768 } | 773 } |
| 769 } | 774 } |
| 770 | 775 |
| 771 void Layer::RecomputeDebugBorderColor() { | 776 void Layer::RecomputeDebugBorderColor() { |
| 772 if (!show_debug_borders_) | 777 if (!show_debug_borders_) |
| 773 return; | 778 return; |
| 774 unsigned int color = 0xFF000000; | 779 unsigned int color = 0xFF000000; |
| 775 color |= web_layer_is_accelerated_ ? 0x0000FF00 : 0x00FF0000; | 780 color |= web_layer_is_accelerated_ ? 0x0000FF00 : 0x00FF0000; |
| 776 bool opaque = fills_bounds_opaquely_ && (GetCombinedOpacity() == 1.f); | 781 bool opaque = fills_bounds_opaquely_ && (GetCombinedOpacity() == 1.f); |
| 777 if (!opaque) | 782 if (!opaque) |
| 778 color |= 0xFF; | 783 color |= 0xFF; |
| 779 web_layer_->setDebugBorderColor(color); | 784 web_layer_->setDebugBorderColor(color); |
| 780 } | 785 } |
| 781 | 786 |
| 782 } // namespace ui | 787 } // namespace ui |
| OLD | NEW |