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/gfx/compositor/layer.h" | 5 #include "ui/gfx/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" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "third_party/WebKit/Source/Platform/chromium/public/WebContentLayer.h" | 13 #include "third_party/WebKit/Source/Platform/chromium/public/WebContentLayer.h" |
14 #include "third_party/WebKit/Source/Platform/chromium/public/WebExternalTextureL
ayer.h" | 14 #include "third_party/WebKit/Source/Platform/chromium/public/WebExternalTextureL
ayer.h" |
15 #include "third_party/WebKit/Source/Platform/chromium/public/WebFilterOperation.
h" | 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebFilterOperation.
h" |
16 #include "third_party/WebKit/Source/Platform/chromium/public/WebFilterOperations
.h" | 16 #include "third_party/WebKit/Source/Platform/chromium/public/WebFilterOperations
.h" |
17 #include "third_party/WebKit/Source/Platform/chromium/public/WebFloatPoint.h" | 17 #include "third_party/WebKit/Source/Platform/chromium/public/WebFloatPoint.h" |
18 #include "third_party/WebKit/Source/Platform/chromium/public/WebFloatRect.h" | 18 #include "third_party/WebKit/Source/Platform/chromium/public/WebFloatRect.h" |
19 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" | 19 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" |
20 #include "third_party/WebKit/Source/Platform/chromium/public/WebSolidColorLayer.
h" | 20 #include "third_party/WebKit/Source/Platform/chromium/public/WebSolidColorLayer.
h" |
21 #include "ui/base/animation/animation.h" | 21 #include "ui/base/animation/animation.h" |
22 #include "ui/gfx/canvas.h" | 22 #include "ui/gfx/canvas.h" |
23 #include "ui/gfx/compositor/compositor_switches.h" | 23 #include "ui/gfx/compositor/compositor_switches.h" |
| 24 #include "ui/gfx/compositor/dip_util.h" |
24 #include "ui/gfx/compositor/layer_animator.h" | 25 #include "ui/gfx/compositor/layer_animator.h" |
25 #include "ui/gfx/interpolated_transform.h" | 26 #include "ui/gfx/interpolated_transform.h" |
26 #include "ui/gfx/point3.h" | 27 #include "ui/gfx/point3.h" |
27 | 28 |
28 namespace { | 29 namespace { |
29 | 30 |
30 const float EPSILON = 1e-3f; | 31 const float EPSILON = 1e-3f; |
31 | 32 |
32 bool IsApproximateMultipleOf(float value, float base) { | 33 bool IsApproximateMultipleOf(float value, float base) { |
33 float remainder = fmod(fabs(value), base); | 34 float remainder = fmod(fabs(value), base); |
34 return remainder < EPSILON || base - remainder < EPSILON; | 35 return remainder < EPSILON || base - remainder < EPSILON; |
35 } | 36 } |
36 | 37 |
37 const ui::Layer* GetRoot(const ui::Layer* layer) { | 38 const ui::Layer* GetRoot(const ui::Layer* layer) { |
38 return layer->parent() ? GetRoot(layer->parent()) : layer; | 39 return layer->parent() ? GetRoot(layer->parent()) : layer; |
39 } | 40 } |
40 | 41 |
| 42 float GetScale(const ui::Compositor* compositor) { |
| 43 if (!ui::IsDIPEnabled()) |
| 44 return 1.0f; |
| 45 return compositor ? compositor->device_scale_factor() : 1.0f; |
| 46 } |
| 47 |
41 } // namespace | 48 } // namespace |
42 | 49 |
43 namespace ui { | 50 namespace ui { |
44 | 51 |
45 Layer::Layer() | 52 Layer::Layer() |
46 : type_(LAYER_TEXTURED), | 53 : type_(LAYER_TEXTURED), |
47 compositor_(NULL), | 54 compositor_(NULL), |
48 parent_(NULL), | 55 parent_(NULL), |
49 visible_(true), | 56 visible_(true), |
50 fills_bounds_opaquely_(true), | 57 fills_bounds_opaquely_(true), |
51 layer_updated_externally_(false), | 58 layer_updated_externally_(false), |
52 opacity_(1.0f), | 59 opacity_(1.0f), |
53 delegate_(NULL) { | 60 delegate_(NULL), |
| 61 scale_canvas_(true) { |
54 CreateWebLayer(); | 62 CreateWebLayer(); |
55 } | 63 } |
56 | 64 |
57 Layer::Layer(LayerType type) | 65 Layer::Layer(LayerType type) |
58 : type_(type), | 66 : type_(type), |
59 compositor_(NULL), | 67 compositor_(NULL), |
60 parent_(NULL), | 68 parent_(NULL), |
61 visible_(true), | 69 visible_(true), |
62 fills_bounds_opaquely_(true), | 70 fills_bounds_opaquely_(true), |
63 layer_updated_externally_(false), | 71 layer_updated_externally_(false), |
64 opacity_(1.0f), | 72 opacity_(1.0f), |
65 delegate_(NULL) { | 73 delegate_(NULL), |
| 74 scale_canvas_(true) { |
66 CreateWebLayer(); | 75 CreateWebLayer(); |
67 } | 76 } |
68 | 77 |
69 Layer::~Layer() { | 78 Layer::~Layer() { |
70 // Destroying the animator may cause observers to use the layer (and | 79 // Destroying the animator may cause observers to use the layer (and |
71 // indirectly the WebLayer). Destroy the animator first so that the WebLayer | 80 // indirectly the WebLayer). Destroy the animator first so that the WebLayer |
72 // is still around. | 81 // is still around. |
73 animator_.reset(); | 82 animator_.reset(); |
74 if (compositor_) | 83 if (compositor_) |
75 compositor_->SetRootLayer(NULL); | 84 compositor_->SetRootLayer(NULL); |
(...skipping 17 matching lines...) Expand all Loading... |
93 compositor_ = compositor; | 102 compositor_ = compositor; |
94 } | 103 } |
95 | 104 |
96 void Layer::Add(Layer* child) { | 105 void Layer::Add(Layer* child) { |
97 DCHECK(!child->compositor_); | 106 DCHECK(!child->compositor_); |
98 if (child->parent_) | 107 if (child->parent_) |
99 child->parent_->Remove(child); | 108 child->parent_->Remove(child); |
100 child->parent_ = this; | 109 child->parent_ = this; |
101 children_.push_back(child); | 110 children_.push_back(child); |
102 web_layer_.addChild(child->web_layer_); | 111 web_layer_.addChild(child->web_layer_); |
| 112 child->UpdateLayerSize(GetCompositor()); |
103 } | 113 } |
104 | 114 |
105 void Layer::Remove(Layer* child) { | 115 void Layer::Remove(Layer* child) { |
106 std::vector<Layer*>::iterator i = | 116 std::vector<Layer*>::iterator i = |
107 std::find(children_.begin(), children_.end(), child); | 117 std::find(children_.begin(), children_.end(), child); |
108 DCHECK(i != children_.end()); | 118 DCHECK(i != children_.end()); |
109 children_.erase(i); | 119 children_.erase(i); |
110 child->parent_ = NULL; | 120 child->parent_ = NULL; |
111 child->web_layer_.removeFromParent(); | 121 child->web_layer_.removeFromParent(); |
112 } | 122 } |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 // static | 237 // static |
228 void Layer::ConvertPointToLayer(const Layer* source, | 238 void Layer::ConvertPointToLayer(const Layer* source, |
229 const Layer* target, | 239 const Layer* target, |
230 gfx::Point* point) { | 240 gfx::Point* point) { |
231 if (source == target) | 241 if (source == target) |
232 return; | 242 return; |
233 | 243 |
234 const Layer* root_layer = GetRoot(source); | 244 const Layer* root_layer = GetRoot(source); |
235 CHECK_EQ(root_layer, GetRoot(target)); | 245 CHECK_EQ(root_layer, GetRoot(target)); |
236 | 246 |
| 247 // TODO(oshima): We probably need to handle source's root != target's root |
| 248 // case under multi monitor environment. |
237 if (source != root_layer) | 249 if (source != root_layer) |
238 source->ConvertPointForAncestor(root_layer, point); | 250 source->ConvertPointForAncestor(root_layer, point); |
239 if (target != root_layer) | 251 if (target != root_layer) |
240 target->ConvertPointFromAncestor(root_layer, point); | 252 target->ConvertPointFromAncestor(root_layer, point); |
241 } | 253 } |
242 | 254 |
243 void Layer::SetFillsBoundsOpaquely(bool fills_bounds_opaquely) { | 255 void Layer::SetFillsBoundsOpaquely(bool fills_bounds_opaquely) { |
244 if (fills_bounds_opaquely_ == fills_bounds_opaquely) | 256 if (fills_bounds_opaquely_ == fills_bounds_opaquely) |
245 return; | 257 return; |
246 | 258 |
247 fills_bounds_opaquely_ = fills_bounds_opaquely; | 259 fills_bounds_opaquely_ = fills_bounds_opaquely; |
248 | 260 |
249 web_layer_.setOpaque(fills_bounds_opaquely); | 261 web_layer_.setOpaque(fills_bounds_opaquely); |
250 RecomputeDebugBorderColor(); | 262 RecomputeDebugBorderColor(); |
251 } | 263 } |
252 | 264 |
253 void Layer::SetExternalTexture(Texture* texture) { | 265 void Layer::SetExternalTexture(Texture* texture) { |
254 DCHECK_EQ(type_, LAYER_TEXTURED); | 266 DCHECK_EQ(type_, LAYER_TEXTURED); |
255 layer_updated_externally_ = !!texture; | 267 layer_updated_externally_ = !!texture; |
256 texture_ = texture; | 268 texture_ = texture; |
| 269 const Compositor* compositor = GetCompositor(); |
257 if (web_layer_is_accelerated_ != layer_updated_externally_) { | 270 if (web_layer_is_accelerated_ != layer_updated_externally_) { |
258 // Switch to a different type of layer. | 271 // Switch to a different type of layer. |
259 web_layer_.removeAllChildren(); | 272 web_layer_.removeAllChildren(); |
260 WebKit::WebLayer new_layer; | 273 WebKit::WebLayer new_layer; |
261 if (layer_updated_externally_) { | 274 if (layer_updated_externally_) { |
262 WebKit::WebExternalTextureLayer texture_layer = | 275 WebKit::WebExternalTextureLayer texture_layer = |
263 WebKit::WebExternalTextureLayer::create(); | 276 WebKit::WebExternalTextureLayer::create(); |
264 texture_layer.setFlipped(texture_->flipped()); | 277 texture_layer.setFlipped(texture_->flipped()); |
265 new_layer = texture_layer; | 278 new_layer = texture_layer; |
266 } else { | 279 } else { |
267 new_layer = WebKit::WebContentLayer::create(this); | 280 new_layer = WebKit::WebContentLayer::create(this); |
268 } | 281 } |
269 if (parent_) { | 282 if (parent_) { |
270 DCHECK(!parent_->web_layer_.isNull()); | 283 DCHECK(!parent_->web_layer_.isNull()); |
271 parent_->web_layer_.replaceChild(web_layer_, new_layer); | 284 parent_->web_layer_.replaceChild(web_layer_, new_layer); |
272 } | 285 } |
273 web_layer_ = new_layer; | 286 web_layer_ = new_layer; |
274 web_layer_is_accelerated_ = layer_updated_externally_; | 287 web_layer_is_accelerated_ = layer_updated_externally_; |
275 for (size_t i = 0; i < children_.size(); ++i) { | 288 for (size_t i = 0; i < children_.size(); ++i) { |
276 DCHECK(!children_[i]->web_layer_.isNull()); | 289 DCHECK(!children_[i]->web_layer_.isNull()); |
277 web_layer_.addChild(children_[i]->web_layer_); | 290 web_layer_.addChild(children_[i]->web_layer_); |
278 } | 291 } |
279 web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); | 292 web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); |
280 web_layer_.setOpaque(fills_bounds_opaquely_); | 293 web_layer_.setOpaque(fills_bounds_opaquely_); |
281 web_layer_.setOpacity(visible_ ? opacity_ : 0.f); | 294 web_layer_.setOpacity(visible_ ? opacity_ : 0.f); |
282 web_layer_.setDebugBorderWidth(show_debug_borders_ ? 2 : 0); | 295 web_layer_.setDebugBorderWidth(show_debug_borders_ ? 2 : 0); |
283 RecomputeTransform(); | 296 RecomputeTransform(compositor); |
284 RecomputeDebugBorderColor(); | 297 RecomputeDebugBorderColor(); |
285 } | 298 } |
286 RecomputeDrawsContentAndUVRect(); | 299 RecomputeDrawsContentAndUVRect(compositor); |
287 } | 300 } |
288 | 301 |
289 void Layer::SetColor(SkColor color) { | 302 void Layer::SetColor(SkColor color) { |
290 DCHECK_EQ(type_, LAYER_SOLID_COLOR); | 303 DCHECK_EQ(type_, LAYER_SOLID_COLOR); |
291 // WebColor is equivalent to SkColor, per WebColor.h. | 304 // WebColor is equivalent to SkColor, per WebColor.h. |
292 web_layer_.to<WebKit::WebSolidColorLayer>().setBackgroundColor( | 305 web_layer_.to<WebKit::WebSolidColorLayer>().setBackgroundColor( |
293 static_cast<WebKit::WebColor>(color)); | 306 static_cast<WebKit::WebColor>(color)); |
294 SetFillsBoundsOpaquely(SkColorGetA(color) == 0xFF); | 307 SetFillsBoundsOpaquely(SkColorGetA(color) == 0xFF); |
295 } | 308 } |
296 | 309 |
297 bool Layer::SchedulePaint(const gfx::Rect& invalid_rect) { | 310 bool Layer::SchedulePaint(const gfx::Rect& invalid_rect) { |
298 if (type_ == LAYER_SOLID_COLOR || !delegate_) | 311 if (type_ == LAYER_SOLID_COLOR || !delegate_) |
299 return false; | 312 return false; |
300 damaged_region_.op(invalid_rect.x(), | 313 gfx::Rect invalid_rect_in_pixel = ConvertRectToPixel(this, invalid_rect); |
301 invalid_rect.y(), | 314 damaged_region_.op(invalid_rect_in_pixel.x(), |
302 invalid_rect.right(), | 315 invalid_rect_in_pixel.y(), |
303 invalid_rect.bottom(), | 316 invalid_rect_in_pixel.right(), |
| 317 invalid_rect_in_pixel.bottom(), |
304 SkRegion::kUnion_Op); | 318 SkRegion::kUnion_Op); |
305 ScheduleDraw(); | 319 ScheduleDraw(); |
306 return true; | 320 return true; |
307 } | 321 } |
308 | 322 |
309 void Layer::ScheduleDraw() { | 323 void Layer::ScheduleDraw() { |
310 Compositor* compositor = GetCompositor(); | 324 Compositor* compositor = GetCompositor(); |
311 if (compositor) | 325 if (compositor) |
312 compositor->ScheduleDraw(); | 326 compositor->ScheduleDraw(); |
313 } | 327 } |
(...skipping 21 matching lines...) Expand all Loading... |
335 } | 349 } |
336 | 350 |
337 void Layer::SuppressPaint() { | 351 void Layer::SuppressPaint() { |
338 if (!delegate_) | 352 if (!delegate_) |
339 return; | 353 return; |
340 delegate_ = NULL; | 354 delegate_ = NULL; |
341 for (size_t i = 0; i < children_.size(); ++i) | 355 for (size_t i = 0; i < children_.size(); ++i) |
342 children_[i]->SuppressPaint(); | 356 children_[i]->SuppressPaint(); |
343 } | 357 } |
344 | 358 |
| 359 void Layer::UpdateLayerSize(const Compositor* compositor) { |
| 360 RecomputeTransform(compositor); |
| 361 RecomputeDrawsContentAndUVRect(compositor); |
| 362 for (size_t i = 0; i < children_.size(); ++i) |
| 363 children_[i]->UpdateLayerSize(compositor); |
| 364 } |
| 365 |
345 void Layer::paintContents(WebKit::WebCanvas* web_canvas, | 366 void Layer::paintContents(WebKit::WebCanvas* web_canvas, |
346 const WebKit::WebRect& clip) { | 367 const WebKit::WebRect& clip) { |
347 TRACE_EVENT0("ui", "Layer::paintContents"); | 368 TRACE_EVENT0("ui", "Layer::paintContents"); |
348 gfx::Canvas canvas(web_canvas); | 369 gfx::Canvas canvas(web_canvas); |
| 370 bool scale_canvas = IsDIPEnabled() && scale_canvas_; |
| 371 if (scale_canvas) { |
| 372 float scale = GetDeviceScaleFactor(this); |
| 373 canvas.sk_canvas()->scale(SkFloatToScalar(scale), SkFloatToScalar(scale)); |
| 374 } |
349 if (delegate_) | 375 if (delegate_) |
350 delegate_->OnPaintLayer(&canvas); | 376 delegate_->OnPaintLayer(&canvas); |
| 377 if (scale_canvas) |
| 378 canvas.Restore(); |
351 } | 379 } |
352 | 380 |
353 float Layer::GetCombinedOpacity() const { | 381 float Layer::GetCombinedOpacity() const { |
354 float opacity = opacity_; | 382 float opacity = opacity_; |
355 Layer* current = this->parent_; | 383 Layer* current = this->parent_; |
356 while (current) { | 384 while (current) { |
357 opacity *= current->opacity_; | 385 opacity *= current->opacity_; |
358 current = current->parent_; | 386 current = current->parent_; |
359 } | 387 } |
360 return opacity; | 388 return opacity; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 transform->ConcatTransform(p->transform()); | 439 transform->ConcatTransform(p->transform()); |
412 transform->ConcatTranslate(static_cast<float>(p->bounds().x()), | 440 transform->ConcatTranslate(static_cast<float>(p->bounds().x()), |
413 static_cast<float>(p->bounds().y())); | 441 static_cast<float>(p->bounds().y())); |
414 } | 442 } |
415 return p == ancestor; | 443 return p == ancestor; |
416 } | 444 } |
417 | 445 |
418 void Layer::SetBoundsImmediately(const gfx::Rect& bounds) { | 446 void Layer::SetBoundsImmediately(const gfx::Rect& bounds) { |
419 if (bounds == bounds_) | 447 if (bounds == bounds_) |
420 return; | 448 return; |
| 449 Compositor* compositor = GetCompositor(); |
421 | 450 |
422 bool was_move = bounds_.size() == bounds.size(); | 451 bool was_move = bounds_.size() == bounds.size(); |
423 bounds_ = bounds; | 452 bounds_ = bounds; |
424 if (IsDrawn()) { | 453 if (IsDrawn()) { |
425 if (was_move) | 454 if (was_move) |
426 ScheduleDraw(); | 455 ScheduleDraw(compositor); |
427 else | 456 else |
428 SchedulePaint(gfx::Rect(bounds.size())); | 457 SchedulePaint(compositor, gfx::Rect(bounds.size())); |
429 } | 458 } |
430 | 459 RecomputeTransform(compositor); |
431 RecomputeTransform(); | 460 RecomputeDrawsContentAndUVRect(compositor); |
432 RecomputeDrawsContentAndUVRect(); | |
433 } | 461 } |
434 | 462 |
435 void Layer::SetTransformImmediately(const ui::Transform& transform) { | 463 void Layer::SetTransformImmediately(const ui::Transform& transform) { |
436 transform_ = transform; | 464 transform_ = transform; |
437 | 465 |
438 RecomputeTransform(); | 466 RecomputeTransform(GetCompositor()); |
439 } | 467 } |
440 | 468 |
441 void Layer::SetOpacityImmediately(float opacity) { | 469 void Layer::SetOpacityImmediately(float opacity) { |
442 bool schedule_draw = (opacity != opacity_ && IsDrawn()); | 470 bool schedule_draw = (opacity != opacity_ && IsDrawn()); |
443 opacity_ = opacity; | 471 opacity_ = opacity; |
444 | 472 |
445 if (visible_) | 473 if (visible_) |
446 web_layer_.setOpacity(opacity); | 474 web_layer_.setOpacity(opacity); |
447 RecomputeDebugBorderColor(); | 475 RecomputeDebugBorderColor(); |
448 if (schedule_draw) | 476 if (schedule_draw) |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 if (type_ == LAYER_SOLID_COLOR) | 526 if (type_ == LAYER_SOLID_COLOR) |
499 web_layer_ = WebKit::WebSolidColorLayer::create(); | 527 web_layer_ = WebKit::WebSolidColorLayer::create(); |
500 else | 528 else |
501 web_layer_ = WebKit::WebContentLayer::create(this); | 529 web_layer_ = WebKit::WebContentLayer::create(this); |
502 web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); | 530 web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); |
503 web_layer_.setOpaque(true); | 531 web_layer_.setOpaque(true); |
504 web_layer_is_accelerated_ = false; | 532 web_layer_is_accelerated_ = false; |
505 show_debug_borders_ = CommandLine::ForCurrentProcess()->HasSwitch( | 533 show_debug_borders_ = CommandLine::ForCurrentProcess()->HasSwitch( |
506 switches::kUIShowLayerBorders); | 534 switches::kUIShowLayerBorders); |
507 web_layer_.setDebugBorderWidth(show_debug_borders_ ? 2 : 0); | 535 web_layer_.setDebugBorderWidth(show_debug_borders_ ? 2 : 0); |
508 RecomputeDrawsContentAndUVRect(); | |
509 RecomputeDebugBorderColor(); | |
510 } | 536 } |
511 | 537 |
512 void Layer::RecomputeTransform() { | 538 void Layer::RecomputeTransform(const Compositor* compositor) { |
513 ui::Transform transform = transform_; | 539 Transform t; |
514 transform.ConcatTranslate(bounds_.x(), bounds_.y()); | 540 if (compositor && IsDIPEnabled()) { |
515 web_layer_.setTransform(transform.matrix()); | 541 t = compositor->GetTranslateTransform(transform_, bounds_.origin()); |
| 542 } else { |
| 543 t = transform_; |
| 544 t.ConcatTranslate(bounds_.x(), bounds_.y()); |
| 545 } |
| 546 web_layer_.setTransform(t.matrix()); |
516 } | 547 } |
517 | 548 |
518 void Layer::RecomputeDrawsContentAndUVRect() { | 549 void Layer::RecomputeDrawsContentAndUVRect(const Compositor* compositor) { |
519 DCHECK(!web_layer_.isNull()); | 550 DCHECK(!web_layer_.isNull()); |
| 551 float device_scale_factor = GetScale(compositor); |
520 bool should_draw = type_ != LAYER_NOT_DRAWN; | 552 bool should_draw = type_ != LAYER_NOT_DRAWN; |
521 if (!web_layer_is_accelerated_) { | 553 if (!web_layer_is_accelerated_) { |
522 if (type_ != LAYER_SOLID_COLOR) | 554 if (type_ != LAYER_SOLID_COLOR) |
523 web_layer_.to<WebKit::WebContentLayer>().setDrawsContent(should_draw); | 555 web_layer_.to<WebKit::WebContentLayer>().setDrawsContent(should_draw); |
524 web_layer_.setBounds(bounds_.size()); | 556 web_layer_.setBounds(bounds_.size().Scale(device_scale_factor)); |
525 } else { | 557 } else { |
526 DCHECK(texture_); | 558 DCHECK(texture_); |
527 unsigned int texture_id = texture_->texture_id(); | 559 unsigned int texture_id = texture_->texture_id(); |
528 WebKit::WebExternalTextureLayer texture_layer = | 560 WebKit::WebExternalTextureLayer texture_layer = |
529 web_layer_.to<WebKit::WebExternalTextureLayer>(); | 561 web_layer_.to<WebKit::WebExternalTextureLayer>(); |
530 texture_layer.setTextureId(should_draw ? texture_id : 0); | 562 texture_layer.setTextureId(should_draw ? texture_id : 0); |
| 563 gfx::Rect bounds_in_pixel = bounds().Scale(device_scale_factor); |
531 gfx::Size texture_size = texture_->size(); | 564 gfx::Size texture_size = texture_->size(); |
532 gfx::Size size(std::min(bounds_.width(), texture_size.width()), | 565 gfx::Size size(std::min(bounds_in_pixel.width(), texture_size.width()), |
533 std::min(bounds_.height(), texture_size.height())); | 566 std::min(bounds_in_pixel.height(), texture_size.height())); |
534 WebKit::WebFloatRect rect( | 567 WebKit::WebFloatRect rect( |
535 0, | 568 0, |
536 0, | 569 0, |
537 static_cast<float>(size.width())/texture_size.width(), | 570 static_cast<float>(size.width())/texture_size.width(), |
538 static_cast<float>(size.height())/texture_size.height()); | 571 static_cast<float>(size.height())/texture_size.height()); |
539 texture_layer.setUVRect(rect); | 572 texture_layer.setUVRect(rect); |
540 web_layer_.setBounds(size); | 573 web_layer_.setBounds(size); |
541 } | 574 } |
542 } | 575 } |
543 | 576 |
544 void Layer::RecomputeDebugBorderColor() { | 577 void Layer::RecomputeDebugBorderColor() { |
545 if (!show_debug_borders_) | 578 if (!show_debug_borders_) |
546 return; | 579 return; |
547 unsigned int color = 0xFF000000; | 580 unsigned int color = 0xFF000000; |
548 color |= web_layer_is_accelerated_ ? 0x0000FF00 : 0x00FF0000; | 581 color |= web_layer_is_accelerated_ ? 0x0000FF00 : 0x00FF0000; |
549 bool opaque = fills_bounds_opaquely_ && (GetCombinedOpacity() == 1.f); | 582 bool opaque = fills_bounds_opaquely_ && (GetCombinedOpacity() == 1.f); |
550 if (!opaque) | 583 if (!opaque) |
551 color |= 0xFF; | 584 color |= 0xFF; |
552 web_layer_.setDebugBorderColor(color); | 585 web_layer_.setDebugBorderColor(color); |
553 } | 586 } |
554 | 587 |
| 588 void Layer::ScheduleDraw(Compositor* compositor) { |
| 589 if (compositor) |
| 590 compositor->ScheduleDraw(); |
| 591 } |
| 592 |
| 593 bool Layer::SchedulePaint(Compositor* compositor, |
| 594 const gfx::Rect& invalid_rect) { |
| 595 if (type_ == LAYER_SOLID_COLOR || !delegate_) |
| 596 return false; |
| 597 gfx::Rect invalid_rect_in_pixel = |
| 598 invalid_rect.Scale(GetScale(compositor)); |
| 599 damaged_region_.op(invalid_rect_in_pixel.x(), |
| 600 invalid_rect_in_pixel.y(), |
| 601 invalid_rect_in_pixel.right(), |
| 602 invalid_rect_in_pixel.bottom(), |
| 603 SkRegion::kUnion_Op); |
| 604 ScheduleDraw(compositor); |
| 605 return true; |
| 606 } |
| 607 |
| 608 |
555 } // namespace ui | 609 } // namespace ui |
OLD | NEW |