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/WebKit/chromium/public/platform/WebContentLa
yer.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebContentLa
yer.h" |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebExternalT
extureLayer.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebExternalT
extureLayer.h" |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFloatPoin
t.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFloatPoin
t.h" |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFloatRect
.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFloatRect
.h" |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSolidColo
rLayer.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSolidColo
rLayer.h" |
19 #include "ui/base/animation/animation.h" | 19 #include "ui/base/animation/animation.h" |
20 #include "ui/gfx/canvas_skia.h" | 20 #include "ui/gfx/canvas_skia.h" |
21 #include "ui/gfx/compositor/compositor_switches.h" | 21 #include "ui/gfx/compositor/compositor_switches.h" |
22 #include "ui/gfx/compositor/layer_animator.h" | 22 #include "ui/gfx/compositor/layer_animator.h" |
23 #include "ui/gfx/interpolated_transform.h" | 23 #include "ui/gfx/interpolated_transform.h" |
24 #include "ui/gfx/point3.h" | 24 #include "ui/gfx/point3.h" |
25 | 25 |
26 #include "ui/gfx/compositor/compositor_cc.h" | |
27 | |
28 namespace { | 26 namespace { |
29 | 27 |
30 const float EPSILON = 1e-3f; | 28 const float EPSILON = 1e-3f; |
31 | 29 |
32 bool IsApproximateMultipleOf(float value, float base) { | 30 bool IsApproximateMultipleOf(float value, float base) { |
33 float remainder = fmod(fabs(value), base); | 31 float remainder = fmod(fabs(value), base); |
34 return remainder < EPSILON || base - remainder < EPSILON; | 32 return remainder < EPSILON || base - remainder < EPSILON; |
35 } | 33 } |
36 | 34 |
37 const ui::Layer* GetRoot(const ui::Layer* layer) { | 35 const ui::Layer* GetRoot(const ui::Layer* layer) { |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 void Layer::SetFillsBoundsOpaquely(bool fills_bounds_opaquely) { | 214 void Layer::SetFillsBoundsOpaquely(bool fills_bounds_opaquely) { |
217 if (fills_bounds_opaquely_ == fills_bounds_opaquely) | 215 if (fills_bounds_opaquely_ == fills_bounds_opaquely) |
218 return; | 216 return; |
219 | 217 |
220 fills_bounds_opaquely_ = fills_bounds_opaquely; | 218 fills_bounds_opaquely_ = fills_bounds_opaquely; |
221 | 219 |
222 web_layer_.setOpaque(fills_bounds_opaquely); | 220 web_layer_.setOpaque(fills_bounds_opaquely); |
223 RecomputeDebugBorderColor(); | 221 RecomputeDebugBorderColor(); |
224 } | 222 } |
225 | 223 |
226 void Layer::SetExternalTexture(ui::Texture* texture) { | 224 void Layer::SetExternalTexture(Texture* texture) { |
227 DCHECK_EQ(type_, LAYER_TEXTURED); | 225 DCHECK_EQ(type_, LAYER_TEXTURED); |
228 layer_updated_externally_ = !!texture; | 226 layer_updated_externally_ = !!texture; |
229 texture_ = texture; | 227 texture_ = texture; |
230 if (web_layer_is_accelerated_ != layer_updated_externally_) { | 228 if (web_layer_is_accelerated_ != layer_updated_externally_) { |
231 // Switch to a different type of layer. | 229 // Switch to a different type of layer. |
232 web_layer_.removeAllChildren(); | 230 web_layer_.removeAllChildren(); |
233 WebKit::WebLayer new_layer; | 231 WebKit::WebLayer new_layer; |
234 if (layer_updated_externally_) | 232 if (layer_updated_externally_) { |
235 new_layer = WebKit::WebExternalTextureLayer::create(); | 233 WebKit::WebExternalTextureLayer texture_layer = |
236 else | 234 WebKit::WebExternalTextureLayer::create(); |
| 235 texture_layer.setFlipped(texture_->flipped()); |
| 236 new_layer = texture_layer; |
| 237 } else { |
237 new_layer = WebKit::WebContentLayer::create(this); | 238 new_layer = WebKit::WebContentLayer::create(this); |
| 239 } |
238 if (parent_) { | 240 if (parent_) { |
239 DCHECK(!parent_->web_layer_.isNull()); | 241 DCHECK(!parent_->web_layer_.isNull()); |
240 parent_->web_layer_.replaceChild(web_layer_, new_layer); | 242 parent_->web_layer_.replaceChild(web_layer_, new_layer); |
241 } | 243 } |
242 web_layer_ = new_layer; | 244 web_layer_ = new_layer; |
243 web_layer_is_accelerated_ = layer_updated_externally_; | 245 web_layer_is_accelerated_ = layer_updated_externally_; |
244 for (size_t i = 0; i < children_.size(); ++i) { | 246 for (size_t i = 0; i < children_.size(); ++i) { |
245 DCHECK(!children_[i]->web_layer_.isNull()); | 247 DCHECK(!children_[i]->web_layer_.isNull()); |
246 web_layer_.addChild(children_[i]->web_layer_); | 248 web_layer_.addChild(children_[i]->web_layer_); |
247 } | 249 } |
248 web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); | 250 web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); |
249 web_layer_.setOpaque(fills_bounds_opaquely_); | 251 web_layer_.setOpaque(fills_bounds_opaquely_); |
250 web_layer_.setOpacity(visible_ ? opacity_ : 0.f); | 252 web_layer_.setOpacity(visible_ ? opacity_ : 0.f); |
251 web_layer_.setDebugBorderWidth(show_debug_borders_ ? 2 : 0); | 253 web_layer_.setDebugBorderWidth(show_debug_borders_ ? 2 : 0); |
252 RecomputeTransform(); | 254 RecomputeTransform(); |
253 RecomputeDebugBorderColor(); | 255 RecomputeDebugBorderColor(); |
254 } | 256 } |
255 if (texture) { | |
256 TextureCC* texture_cc = static_cast<TextureCC*>(texture); | |
257 texture_cc->Update(); | |
258 WebKit::WebExternalTextureLayer texture_layer = | |
259 web_layer_.to<WebKit::WebExternalTextureLayer>(); | |
260 texture_layer.setFlipped(texture_cc->flipped()); | |
261 } | |
262 RecomputeDrawsContentAndUVRect(); | 257 RecomputeDrawsContentAndUVRect(); |
263 } | 258 } |
264 | 259 |
265 void Layer::SetCanvas(const SkCanvas& canvas, const gfx::Point& origin) { | |
266 NOTREACHED(); | |
267 } | |
268 | |
269 void Layer::SetColor(SkColor color) { | 260 void Layer::SetColor(SkColor color) { |
270 DCHECK_EQ(type_, LAYER_SOLID_COLOR); | 261 DCHECK_EQ(type_, LAYER_SOLID_COLOR); |
271 // WebColor is equivalent to SkColor, per WebColor.h. | 262 // WebColor is equivalent to SkColor, per WebColor.h. |
272 web_layer_.to<WebKit::WebSolidColorLayer>().setBackgroundColor( | 263 web_layer_.to<WebKit::WebSolidColorLayer>().setBackgroundColor( |
273 static_cast<WebKit::WebColor>(color)); | 264 static_cast<WebKit::WebColor>(color)); |
274 SetFillsBoundsOpaquely(SkColorGetA(color) == 0xFF); | 265 SetFillsBoundsOpaquely(SkColorGetA(color) == 0xFF); |
275 } | 266 } |
276 | 267 |
277 void Layer::SchedulePaint(const gfx::Rect& invalid_rect) { | 268 void Layer::SchedulePaint(const gfx::Rect& invalid_rect) { |
278 if (type_ == LAYER_SOLID_COLOR) | 269 if (type_ == LAYER_SOLID_COLOR) |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 | 468 |
478 void Layer::RecomputeDrawsContentAndUVRect() { | 469 void Layer::RecomputeDrawsContentAndUVRect() { |
479 DCHECK(!web_layer_.isNull()); | 470 DCHECK(!web_layer_.isNull()); |
480 bool should_draw = type_ != LAYER_NOT_DRAWN; | 471 bool should_draw = type_ != LAYER_NOT_DRAWN; |
481 if (!web_layer_is_accelerated_) { | 472 if (!web_layer_is_accelerated_) { |
482 if (type_ != LAYER_SOLID_COLOR) | 473 if (type_ != LAYER_SOLID_COLOR) |
483 web_layer_.to<WebKit::WebContentLayer>().setDrawsContent(should_draw); | 474 web_layer_.to<WebKit::WebContentLayer>().setDrawsContent(should_draw); |
484 web_layer_.setBounds(bounds_.size()); | 475 web_layer_.setBounds(bounds_.size()); |
485 } else { | 476 } else { |
486 DCHECK(texture_); | 477 DCHECK(texture_); |
487 TextureCC* texture_cc = static_cast<TextureCC*>(texture_.get()); | 478 unsigned int texture_id = texture_->texture_id(); |
488 unsigned int texture_id = texture_cc->texture_id(); | |
489 WebKit::WebExternalTextureLayer texture_layer = | 479 WebKit::WebExternalTextureLayer texture_layer = |
490 web_layer_.to<WebKit::WebExternalTextureLayer>(); | 480 web_layer_.to<WebKit::WebExternalTextureLayer>(); |
491 texture_layer.setTextureId(should_draw ? texture_id : 0); | 481 texture_layer.setTextureId(should_draw ? texture_id : 0); |
492 gfx::Size size(std::min(bounds_.width(), texture_cc->size().width()), | 482 gfx::Size texture_size = texture_->size(); |
493 std::min(bounds_.height(), texture_cc->size().height())); | 483 gfx::Size size(std::min(bounds_.width(), texture_size.width()), |
| 484 std::min(bounds_.height(), texture_size.height())); |
494 WebKit::WebFloatRect rect( | 485 WebKit::WebFloatRect rect( |
495 0, | 486 0, |
496 0, | 487 0, |
497 static_cast<float>(size.width())/texture_cc->size().width(), | 488 static_cast<float>(size.width())/texture_size.width(), |
498 static_cast<float>(size.height())/texture_cc->size().height()); | 489 static_cast<float>(size.height())/texture_size.height()); |
499 texture_layer.setUVRect(rect); | 490 texture_layer.setUVRect(rect); |
500 web_layer_.setBounds(size); | 491 web_layer_.setBounds(size); |
501 } | 492 } |
502 } | 493 } |
503 | 494 |
504 void Layer::RecomputeDebugBorderColor() { | 495 void Layer::RecomputeDebugBorderColor() { |
505 if (!show_debug_borders_) | 496 if (!show_debug_borders_) |
506 return; | 497 return; |
507 unsigned int color = 0xFF000000; | 498 unsigned int color = 0xFF000000; |
508 color |= web_layer_is_accelerated_ ? 0x0000FF00 : 0x00FF0000; | 499 color |= web_layer_is_accelerated_ ? 0x0000FF00 : 0x00FF0000; |
509 bool opaque = fills_bounds_opaquely_ && (GetCombinedOpacity() == 1.f); | 500 bool opaque = fills_bounds_opaquely_ && (GetCombinedOpacity() == 1.f); |
510 if (!opaque) | 501 if (!opaque) |
511 color |= 0xFF; | 502 color |= 0xFF; |
512 web_layer_.setDebugBorderColor(color); | 503 web_layer_.setDebugBorderColor(color); |
513 } | 504 } |
514 | 505 |
515 } // namespace ui | 506 } // namespace ui |
OLD | NEW |