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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 | 46 |
47 Layer::Layer() | 47 Layer::Layer() |
48 : type_(LAYER_TEXTURED), | 48 : type_(LAYER_TEXTURED), |
49 compositor_(NULL), | 49 compositor_(NULL), |
50 parent_(NULL), | 50 parent_(NULL), |
51 visible_(true), | 51 visible_(true), |
52 fills_bounds_opaquely_(true), | 52 fills_bounds_opaquely_(true), |
53 layer_updated_externally_(false), | 53 layer_updated_externally_(false), |
54 opacity_(1.0f), | 54 opacity_(1.0f), |
55 delegate_(NULL), | 55 delegate_(NULL), |
56 scale_content_(true), | 56 scale_canvas_(true), |
57 device_scale_factor_(1.0f) { | 57 device_scale_factor_(1.0f) { |
58 CreateWebLayer(); | 58 CreateWebLayer(); |
59 } | 59 } |
60 | 60 |
61 Layer::Layer(LayerType type) | 61 Layer::Layer(LayerType type) |
62 : type_(type), | 62 : type_(type), |
63 compositor_(NULL), | 63 compositor_(NULL), |
64 parent_(NULL), | 64 parent_(NULL), |
65 visible_(true), | 65 visible_(true), |
66 fills_bounds_opaquely_(true), | 66 fills_bounds_opaquely_(true), |
67 layer_updated_externally_(false), | 67 layer_updated_externally_(false), |
68 opacity_(1.0f), | 68 opacity_(1.0f), |
69 delegate_(NULL), | 69 delegate_(NULL), |
70 scale_content_(true), | 70 scale_canvas_(true), |
71 device_scale_factor_(1.0f) { | 71 device_scale_factor_(1.0f) { |
72 CreateWebLayer(); | 72 CreateWebLayer(); |
73 } | 73 } |
74 | 74 |
75 Layer::~Layer() { | 75 Layer::~Layer() { |
76 // Destroying the animator may cause observers to use the layer (and | 76 // Destroying the animator may cause observers to use the layer (and |
77 // indirectly the WebLayer). Destroy the animator first so that the WebLayer | 77 // indirectly the WebLayer). Destroy the animator first so that the WebLayer |
78 // is still around. | 78 // is still around. |
79 animator_.reset(); | 79 animator_.reset(); |
80 if (compositor_) | 80 if (compositor_) |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 if (delegate_ && !damaged_region_.isEmpty()) { | 333 if (delegate_ && !damaged_region_.isEmpty()) { |
334 for (SkRegion::Iterator iter(damaged_region_); | 334 for (SkRegion::Iterator iter(damaged_region_); |
335 !iter.done(); iter.next()) { | 335 !iter.done(); iter.next()) { |
336 const SkIRect& sk_damaged = iter.rect(); | 336 const SkIRect& sk_damaged = iter.rect(); |
337 gfx::Rect damaged( | 337 gfx::Rect damaged( |
338 sk_damaged.x(), | 338 sk_damaged.x(), |
339 sk_damaged.y(), | 339 sk_damaged.y(), |
340 sk_damaged.width(), | 340 sk_damaged.width(), |
341 sk_damaged.height()); | 341 sk_damaged.height()); |
342 | 342 |
343 if (scale_content_ && web_layer_is_accelerated_) { | 343 // TODO(pkotwicz): Remove this once we are no longer linearly upscaling |
| 344 // web contents when DIP is enabled (crbug.com/127455). |
| 345 if (web_layer_is_accelerated_) { |
344 damaged.Inset(-1, -1); | 346 damaged.Inset(-1, -1); |
345 damaged = damaged.Intersect(bounds_); | 347 damaged = damaged.Intersect(bounds_); |
346 } | 348 } |
347 | 349 |
348 gfx::Rect damaged_in_pixel = ConvertRectToPixel(this, damaged); | 350 gfx::Rect damaged_in_pixel = ConvertRectToPixel(this, damaged); |
349 WebKit::WebFloatRect web_rect( | 351 WebKit::WebFloatRect web_rect( |
350 damaged_in_pixel.x(), | 352 damaged_in_pixel.x(), |
351 damaged_in_pixel.y(), | 353 damaged_in_pixel.y(), |
352 damaged_in_pixel.width(), | 354 damaged_in_pixel.width(), |
353 damaged_in_pixel.height()); | 355 damaged_in_pixel.height()); |
(...skipping 27 matching lines...) Expand all Loading... |
381 if (delegate_) | 383 if (delegate_) |
382 delegate_->OnDeviceScaleFactorChanged(device_scale_factor); | 384 delegate_->OnDeviceScaleFactorChanged(device_scale_factor); |
383 for (size_t i = 0; i < children_.size(); ++i) | 385 for (size_t i = 0; i < children_.size(); ++i) |
384 children_[i]->OnDeviceScaleFactorChanged(device_scale_factor); | 386 children_[i]->OnDeviceScaleFactorChanged(device_scale_factor); |
385 } | 387 } |
386 | 388 |
387 void Layer::paintContents(WebKit::WebCanvas* web_canvas, | 389 void Layer::paintContents(WebKit::WebCanvas* web_canvas, |
388 const WebKit::WebRect& clip) { | 390 const WebKit::WebRect& clip) { |
389 TRACE_EVENT0("ui", "Layer::paintContents"); | 391 TRACE_EVENT0("ui", "Layer::paintContents"); |
390 gfx::Canvas canvas(web_canvas); | 392 gfx::Canvas canvas(web_canvas); |
391 bool scale_content = scale_content_; | 393 bool scale_canvas = scale_canvas_; |
392 if (scale_content) { | 394 if (scale_canvas) { |
393 canvas.sk_canvas()->scale(SkFloatToScalar(device_scale_factor_), | 395 canvas.sk_canvas()->scale(SkFloatToScalar(device_scale_factor_), |
394 SkFloatToScalar(device_scale_factor_)); | 396 SkFloatToScalar(device_scale_factor_)); |
395 } | 397 } |
396 if (delegate_) | 398 if (delegate_) |
397 delegate_->OnPaintLayer(&canvas); | 399 delegate_->OnPaintLayer(&canvas); |
398 if (scale_content) | 400 if (scale_canvas) |
399 canvas.Restore(); | 401 canvas.Restore(); |
400 } | 402 } |
401 | 403 |
402 float Layer::GetCombinedOpacity() const { | 404 float Layer::GetCombinedOpacity() const { |
403 float opacity = opacity_; | 405 float opacity = opacity_; |
404 Layer* current = this->parent_; | 406 Layer* current = this->parent_; |
405 while (current) { | 407 while (current) { |
406 opacity *= current->opacity_; | 408 opacity *= current->opacity_; |
407 current = current->parent_; | 409 current = current->parent_; |
408 } | 410 } |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 if (!web_layer_is_accelerated_) { | 584 if (!web_layer_is_accelerated_) { |
583 if (type_ != LAYER_SOLID_COLOR) | 585 if (type_ != LAYER_SOLID_COLOR) |
584 web_layer_.to<WebKit::WebContentLayer>().setDrawsContent(should_draw); | 586 web_layer_.to<WebKit::WebContentLayer>().setDrawsContent(should_draw); |
585 web_layer_.setBounds(ConvertSizeToPixel(this, bounds_.size())); | 587 web_layer_.setBounds(ConvertSizeToPixel(this, bounds_.size())); |
586 } else { | 588 } else { |
587 DCHECK(texture_); | 589 DCHECK(texture_); |
588 unsigned int texture_id = texture_->texture_id(); | 590 unsigned int texture_id = texture_->texture_id(); |
589 WebKit::WebExternalTextureLayer texture_layer = | 591 WebKit::WebExternalTextureLayer texture_layer = |
590 web_layer_.to<WebKit::WebExternalTextureLayer>(); | 592 web_layer_.to<WebKit::WebExternalTextureLayer>(); |
591 texture_layer.setTextureId(should_draw ? texture_id : 0); | 593 texture_layer.setTextureId(should_draw ? texture_id : 0); |
| 594 gfx::Size texture_size = texture_->size(); |
592 | 595 |
593 gfx::Size texture_size; | 596 // As WebKit does not support DIP, WebKit is told of coordinates in DIP |
594 if (scale_content_) | 597 // as if they were pixel coordinates. The texture is scaled here via |
595 texture_size = texture_->size(); | 598 // the setBounds call. |
596 else | 599 // TODO(pkotwicz): Fix this code to take in account textures with pixel |
597 texture_size = ConvertSizeToDIP(this, texture_->size()); | 600 // sizes once WebKit understands DIP. http://crbug.com/127455 |
598 | |
599 gfx::Size size(std::min(bounds().width(), texture_size.width()), | 601 gfx::Size size(std::min(bounds().width(), texture_size.width()), |
600 std::min(bounds().height(), texture_size.height())); | 602 std::min(bounds().height(), texture_size.height())); |
601 WebKit::WebFloatRect rect( | 603 WebKit::WebFloatRect rect( |
602 0, | 604 0, |
603 0, | 605 0, |
604 static_cast<float>(size.width())/texture_size.width(), | 606 static_cast<float>(size.width())/texture_size.width(), |
605 static_cast<float>(size.height())/texture_size.height()); | 607 static_cast<float>(size.height())/texture_size.height()); |
606 texture_layer.setUVRect(rect); | 608 texture_layer.setUVRect(rect); |
607 | 609 |
608 gfx::Size size_in_pixel = ConvertSizeToPixel(this, size); | 610 gfx::Size size_in_pixel = ConvertSizeToPixel(this, size); |
609 web_layer_.setBounds(size_in_pixel); | 611 web_layer_.setBounds(size_in_pixel); |
610 } | 612 } |
611 } | 613 } |
612 | 614 |
613 void Layer::RecomputeDebugBorderColor() { | 615 void Layer::RecomputeDebugBorderColor() { |
614 if (!show_debug_borders_) | 616 if (!show_debug_borders_) |
615 return; | 617 return; |
616 unsigned int color = 0xFF000000; | 618 unsigned int color = 0xFF000000; |
617 color |= web_layer_is_accelerated_ ? 0x0000FF00 : 0x00FF0000; | 619 color |= web_layer_is_accelerated_ ? 0x0000FF00 : 0x00FF0000; |
618 bool opaque = fills_bounds_opaquely_ && (GetCombinedOpacity() == 1.f); | 620 bool opaque = fills_bounds_opaquely_ && (GetCombinedOpacity() == 1.f); |
619 if (!opaque) | 621 if (!opaque) |
620 color |= 0xFF; | 622 color |= 0xFF; |
621 web_layer_.setDebugBorderColor(color); | 623 web_layer_.setDebugBorderColor(color); |
622 } | 624 } |
623 | 625 |
624 } // namespace ui | 626 } // namespace ui |
OLD | NEW |