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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
54 layer_updated_externally_(false), | 54 layer_updated_externally_(false), |
55 opacity_(1.0f), | 55 opacity_(1.0f), |
56 background_blur_radius_(0), | 56 background_blur_radius_(0), |
57 layer_saturation_(0.0f), | 57 layer_saturation_(0.0f), |
58 layer_brightness_(0.0f), | 58 layer_brightness_(0.0f), |
59 layer_grayscale_(0.0f), | 59 layer_grayscale_(0.0f), |
60 layer_inverted_(false), | 60 layer_inverted_(false), |
61 layer_mask_(NULL), | 61 layer_mask_(NULL), |
62 layer_mask_back_link_(NULL), | 62 layer_mask_back_link_(NULL), |
63 delegate_(NULL), | 63 delegate_(NULL), |
64 #if defined(WEBLAYER_IS_PURE_VIRTUAL) | |
65 web_layer_(NULL), | |
66 #endif | |
64 scale_content_(true), | 67 scale_content_(true), |
65 device_scale_factor_(1.0f) { | 68 device_scale_factor_(1.0f) { |
66 CreateWebLayer(); | 69 CreateWebLayer(); |
67 } | 70 } |
68 | 71 |
69 Layer::Layer(LayerType type) | 72 Layer::Layer(LayerType type) |
70 : type_(type), | 73 : type_(type), |
71 compositor_(NULL), | 74 compositor_(NULL), |
72 parent_(NULL), | 75 parent_(NULL), |
73 visible_(true), | 76 visible_(true), |
(...skipping 22 matching lines...) Expand all Loading... | |
96 if (compositor_) | 99 if (compositor_) |
97 compositor_->SetRootLayer(NULL); | 100 compositor_->SetRootLayer(NULL); |
98 if (parent_) | 101 if (parent_) |
99 parent_->Remove(this); | 102 parent_->Remove(this); |
100 if (layer_mask_) | 103 if (layer_mask_) |
101 SetMaskLayer(NULL); | 104 SetMaskLayer(NULL); |
102 if (layer_mask_back_link_) | 105 if (layer_mask_back_link_) |
103 layer_mask_back_link_->SetMaskLayer(NULL); | 106 layer_mask_back_link_->SetMaskLayer(NULL); |
104 for (size_t i = 0; i < children_.size(); ++i) | 107 for (size_t i = 0; i < children_.size(); ++i) |
105 children_[i]->parent_ = NULL; | 108 children_[i]->parent_ = NULL; |
109 #if defined(WEBLAYER_IS_PURE_VIRTUAL) | |
110 web_layer_->removeFromParent(); | |
111 #else | |
106 web_layer_.removeFromParent(); | 112 web_layer_.removeFromParent(); |
113 #endif | |
107 } | 114 } |
108 | 115 |
109 Compositor* Layer::GetCompositor() { | 116 Compositor* Layer::GetCompositor() { |
110 return GetRoot(this)->compositor_; | 117 return GetRoot(this)->compositor_; |
111 } | 118 } |
112 | 119 |
113 void Layer::SetCompositor(Compositor* compositor) { | 120 void Layer::SetCompositor(Compositor* compositor) { |
114 // This function must only be called to set the compositor on the root layer, | 121 // This function must only be called to set the compositor on the root layer, |
115 // or to reset it. | 122 // or to reset it. |
116 DCHECK(!compositor || !compositor_); | 123 DCHECK(!compositor || !compositor_); |
117 DCHECK(!compositor || compositor->root_layer() == this); | 124 DCHECK(!compositor || compositor->root_layer() == this); |
118 DCHECK(!parent_); | 125 DCHECK(!parent_); |
119 compositor_ = compositor; | 126 compositor_ = compositor; |
120 if (compositor) | 127 if (compositor) |
121 OnDeviceScaleFactorChanged(compositor->device_scale_factor()); | 128 OnDeviceScaleFactorChanged(compositor->device_scale_factor()); |
122 } | 129 } |
123 | 130 |
124 void Layer::Add(Layer* child) { | 131 void Layer::Add(Layer* child) { |
125 DCHECK(!child->compositor_); | 132 DCHECK(!child->compositor_); |
126 if (child->parent_) | 133 if (child->parent_) |
127 child->parent_->Remove(child); | 134 child->parent_->Remove(child); |
128 child->parent_ = this; | 135 child->parent_ = this; |
129 children_.push_back(child); | 136 children_.push_back(child); |
137 #if defined(WEBLAYER_IS_PURE_VIRTUAL) | |
138 web_layer_->addChild(child->web_layer_); | |
139 #else | |
130 web_layer_.addChild(child->web_layer_); | 140 web_layer_.addChild(child->web_layer_); |
141 #endif | |
131 child->OnDeviceScaleFactorChanged(device_scale_factor_); | 142 child->OnDeviceScaleFactorChanged(device_scale_factor_); |
132 } | 143 } |
133 | 144 |
134 void Layer::Remove(Layer* child) { | 145 void Layer::Remove(Layer* child) { |
135 std::vector<Layer*>::iterator i = | 146 std::vector<Layer*>::iterator i = |
136 std::find(children_.begin(), children_.end(), child); | 147 std::find(children_.begin(), children_.end(), child); |
137 DCHECK(i != children_.end()); | 148 DCHECK(i != children_.end()); |
138 children_.erase(i); | 149 children_.erase(i); |
139 child->parent_ = NULL; | 150 child->parent_ = NULL; |
151 #if defined(WEBLAYER_IS_PURE_VIRTUAL) | |
152 child->web_layer_->removeFromParent(); | |
153 #else | |
140 child->web_layer_.removeFromParent(); | 154 child->web_layer_.removeFromParent(); |
155 #endif | |
141 } | 156 } |
142 | 157 |
143 void Layer::StackAtTop(Layer* child) { | 158 void Layer::StackAtTop(Layer* child) { |
144 if (children_.size() <= 1 || child == children_.back()) | 159 if (children_.size() <= 1 || child == children_.back()) |
145 return; // Already in front. | 160 return; // Already in front. |
146 StackAbove(child, children_.back()); | 161 StackAbove(child, children_.back()); |
147 } | 162 } |
148 | 163 |
149 void Layer::StackAbove(Layer* child, Layer* other) { | 164 void Layer::StackAbove(Layer* child, Layer* other) { |
150 StackRelativeTo(child, other, true); | 165 StackRelativeTo(child, other, true); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
198 | 213 |
199 gfx::Rect Layer::GetTargetBounds() const { | 214 gfx::Rect Layer::GetTargetBounds() const { |
200 if (animator_.get() && animator_->IsAnimatingProperty( | 215 if (animator_.get() && animator_->IsAnimatingProperty( |
201 LayerAnimationElement::BOUNDS)) { | 216 LayerAnimationElement::BOUNDS)) { |
202 return animator_->GetTargetBounds(); | 217 return animator_->GetTargetBounds(); |
203 } | 218 } |
204 return bounds_; | 219 return bounds_; |
205 } | 220 } |
206 | 221 |
207 void Layer::SetMasksToBounds(bool masks_to_bounds) { | 222 void Layer::SetMasksToBounds(bool masks_to_bounds) { |
223 #if defined(WEBLAYER_IS_PURE_VIRTUAL) | |
224 web_layer_->setMasksToBounds(masks_to_bounds); | |
225 #else | |
208 web_layer_.setMasksToBounds(masks_to_bounds); | 226 web_layer_.setMasksToBounds(masks_to_bounds); |
227 #endif | |
209 } | 228 } |
210 | 229 |
211 bool Layer::GetMasksToBounds() const { | 230 bool Layer::GetMasksToBounds() const { |
231 #if defined(WEBLAYER_IS_PURE_VIRTUAL) | |
232 return web_layer_->masksToBounds(); | |
233 #else | |
212 return web_layer_.masksToBounds(); | 234 return web_layer_.masksToBounds(); |
235 #endif | |
213 } | 236 } |
214 | 237 |
215 void Layer::SetOpacity(float opacity) { | 238 void Layer::SetOpacity(float opacity) { |
216 GetAnimator()->SetOpacity(opacity); | 239 GetAnimator()->SetOpacity(opacity); |
217 } | 240 } |
218 | 241 |
219 void Layer::SetBackgroundBlur(int blur_radius) { | 242 void Layer::SetBackgroundBlur(int blur_radius) { |
220 background_blur_radius_ = blur_radius; | 243 background_blur_radius_ = blur_radius; |
221 | 244 |
222 WebKit::WebFilterOperations filters; | 245 WebKit::WebFilterOperations filters; |
223 if (background_blur_radius_) { | 246 if (background_blur_radius_) { |
224 filters.append(WebKit::WebFilterOperation::createBlurFilter( | 247 filters.append(WebKit::WebFilterOperation::createBlurFilter( |
225 background_blur_radius_)); | 248 background_blur_radius_)); |
226 } | 249 } |
250 #if defined(WEBLAYER_IS_PURE_VIRTUAL) | |
251 web_layer_->setBackgroundFilters(filters); | |
252 #else | |
227 web_layer_.setBackgroundFilters(filters); | 253 web_layer_.setBackgroundFilters(filters); |
254 #endif | |
228 } | 255 } |
229 | 256 |
230 void Layer::SetLayerSaturation(float saturation) { | 257 void Layer::SetLayerSaturation(float saturation) { |
231 layer_saturation_ = saturation; | 258 layer_saturation_ = saturation; |
232 SetLayerFilters(); | 259 SetLayerFilters(); |
233 } | 260 } |
234 | 261 |
235 void Layer::SetLayerBrightness(float brightness) { | 262 void Layer::SetLayerBrightness(float brightness) { |
236 GetAnimator()->SetBrightness(brightness); | 263 GetAnimator()->SetBrightness(brightness); |
237 } | 264 } |
(...skipping 30 matching lines...) Expand all Loading... | |
268 layer_mask->children().empty() && | 295 layer_mask->children().empty() && |
269 !layer_mask->layer_mask_back_link_)); | 296 !layer_mask->layer_mask_back_link_)); |
270 DCHECK(!layer_mask_back_link_); | 297 DCHECK(!layer_mask_back_link_); |
271 if (layer_mask_ == layer_mask) | 298 if (layer_mask_ == layer_mask) |
272 return; | 299 return; |
273 // We need to de-reference the currently linked object so that no problem | 300 // We need to de-reference the currently linked object so that no problem |
274 // arises if the mask layer gets deleted before this object. | 301 // arises if the mask layer gets deleted before this object. |
275 if (layer_mask_) | 302 if (layer_mask_) |
276 layer_mask_->layer_mask_back_link_ = NULL; | 303 layer_mask_->layer_mask_back_link_ = NULL; |
277 layer_mask_ = layer_mask; | 304 layer_mask_ = layer_mask; |
305 #if defined(WEBLAYER_IS_PURE_VIRTUAL) | |
306 web_layer_->setMaskLayer( | |
307 layer_mask ? layer_mask->web_layer() : NULL); | |
308 #else | |
278 web_layer_.setMaskLayer( | 309 web_layer_.setMaskLayer( |
279 layer_mask ? layer_mask->web_layer() : WebKit::WebLayer()); | 310 layer_mask ? layer_mask->web_layer() : WebKit::WebLayer()); |
311 #endif | |
280 // We need to reference the linked object so that it can properly break the | 312 // We need to reference the linked object so that it can properly break the |
281 // link to us when it gets deleted. | 313 // link to us when it gets deleted. |
282 if (layer_mask) | 314 if (layer_mask) |
283 layer_mask->layer_mask_back_link_ = this; | 315 layer_mask->layer_mask_back_link_ = this; |
284 } | 316 } |
285 | 317 |
286 void Layer::SetLayerFilters() { | 318 void Layer::SetLayerFilters() { |
287 WebKit::WebFilterOperations filters; | 319 WebKit::WebFilterOperations filters; |
288 if (layer_saturation_) { | 320 if (layer_saturation_) { |
289 filters.append(WebKit::WebFilterOperation::createSaturateFilter( | 321 filters.append(WebKit::WebFilterOperation::createSaturateFilter( |
290 layer_saturation_)); | 322 layer_saturation_)); |
291 } | 323 } |
292 if (layer_grayscale_) { | 324 if (layer_grayscale_) { |
293 filters.append(WebKit::WebFilterOperation::createGrayscaleFilter( | 325 filters.append(WebKit::WebFilterOperation::createGrayscaleFilter( |
294 layer_grayscale_)); | 326 layer_grayscale_)); |
295 } | 327 } |
296 if (layer_inverted_) | 328 if (layer_inverted_) |
297 filters.append(WebKit::WebFilterOperation::createInvertFilter(1.0)); | 329 filters.append(WebKit::WebFilterOperation::createInvertFilter(1.0)); |
298 // Brightness goes last, because the resulting colors neeed clamping, which | 330 // Brightness goes last, because the resulting colors neeed clamping, which |
299 // cause further color matrix filters to be applied separately. In this order, | 331 // cause further color matrix filters to be applied separately. In this order, |
300 // they all can be combined in a single pass. | 332 // they all can be combined in a single pass. |
301 if (layer_brightness_) { | 333 if (layer_brightness_) { |
302 filters.append(WebKit::WebFilterOperation::createBrightnessFilter( | 334 filters.append(WebKit::WebFilterOperation::createBrightnessFilter( |
303 layer_brightness_)); | 335 layer_brightness_)); |
304 } | 336 } |
305 | 337 |
338 #if defined(WEBLAYER_IS_PURE_VIRTUAL) | |
339 web_layer_->setFilters(filters); | |
340 #else | |
306 web_layer_.setFilters(filters); | 341 web_layer_.setFilters(filters); |
342 #endif | |
307 } | 343 } |
308 | 344 |
309 float Layer::GetTargetOpacity() const { | 345 float Layer::GetTargetOpacity() const { |
310 if (animator_.get() && animator_->IsAnimatingProperty( | 346 if (animator_.get() && animator_->IsAnimatingProperty( |
311 LayerAnimationElement::OPACITY)) | 347 LayerAnimationElement::OPACITY)) |
312 return animator_->GetTargetOpacity(); | 348 return animator_->GetTargetOpacity(); |
313 return opacity_; | 349 return opacity_; |
314 } | 350 } |
315 | 351 |
316 void Layer::SetVisible(bool visible) { | 352 void Layer::SetVisible(bool visible) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
350 if (target != root_layer) | 386 if (target != root_layer) |
351 target->ConvertPointFromAncestor(root_layer, point); | 387 target->ConvertPointFromAncestor(root_layer, point); |
352 } | 388 } |
353 | 389 |
354 void Layer::SetFillsBoundsOpaquely(bool fills_bounds_opaquely) { | 390 void Layer::SetFillsBoundsOpaquely(bool fills_bounds_opaquely) { |
355 if (fills_bounds_opaquely_ == fills_bounds_opaquely) | 391 if (fills_bounds_opaquely_ == fills_bounds_opaquely) |
356 return; | 392 return; |
357 | 393 |
358 fills_bounds_opaquely_ = fills_bounds_opaquely; | 394 fills_bounds_opaquely_ = fills_bounds_opaquely; |
359 | 395 |
396 #if defined(WEBLAYER_IS_PURE_VIRTUAL) | |
397 web_layer_->setOpaque(fills_bounds_opaquely); | |
398 #else | |
360 web_layer_.setOpaque(fills_bounds_opaquely); | 399 web_layer_.setOpaque(fills_bounds_opaquely); |
400 #endif | |
361 RecomputeDebugBorderColor(); | 401 RecomputeDebugBorderColor(); |
362 } | 402 } |
363 | 403 |
364 void Layer::SetExternalTexture(Texture* texture) { | 404 void Layer::SetExternalTexture(Texture* texture) { |
365 DCHECK_EQ(type_, LAYER_TEXTURED); | 405 DCHECK_EQ(type_, LAYER_TEXTURED); |
366 layer_updated_externally_ = !!texture; | 406 layer_updated_externally_ = !!texture; |
367 texture_ = texture; | 407 texture_ = texture; |
368 if (web_layer_is_accelerated_ != layer_updated_externally_) { | 408 if (web_layer_is_accelerated_ != layer_updated_externally_) { |
369 // Switch to a different type of layer. | 409 // Switch to a different type of layer. |
410 #if defined(WEBLAYER_IS_PURE_VIRTUAL) | |
411 web_layer_->removeAllChildren(); | |
412 content_layer_.reset(); | |
413 solid_color_layer_.reset(); | |
414 WebKit::WebLayer* new_layer = NULL; | |
415 #else | |
370 web_layer_.removeAllChildren(); | 416 web_layer_.removeAllChildren(); |
371 WebKit::WebLayer new_layer; | 417 WebKit::WebLayer new_layer; |
418 #endif | |
372 if (layer_updated_externally_) { | 419 if (layer_updated_externally_) { |
420 #if defined(WEBLAYER_IS_PURE_VIRTUAL) | |
421 texture_layer_.reset(WebKit::WebExternalTextureLayer::create()); | |
422 texture_layer_->setFlipped(texture_->flipped()); | |
423 new_layer = texture_layer_->layer(); | |
424 #else | |
373 WebKit::WebExternalTextureLayer texture_layer = | 425 WebKit::WebExternalTextureLayer texture_layer = |
374 WebKit::WebExternalTextureLayer::create(); | 426 WebKit::WebExternalTextureLayer::create(); |
375 texture_layer.setFlipped(texture_->flipped()); | 427 texture_layer.setFlipped(texture_->flipped()); |
376 new_layer = texture_layer; | 428 new_layer = texture_layer; |
429 #endif | |
377 } else { | 430 } else { |
431 #if defined(WEBLAYER_IS_PURE_VIRTUAL) | |
432 texture_layer_.reset(); | |
433 solid_color_layer_.reset(); | |
434 content_layer_.reset(WebKit::WebContentLayer::create(this)); | |
435 new_layer = content_layer_->layer(); | |
436 #else | |
378 new_layer = WebKit::WebContentLayer::create(this); | 437 new_layer = WebKit::WebContentLayer::create(this); |
438 #endif | |
379 } | 439 } |
380 if (parent_) { | 440 if (parent_) { |
441 #if defined(WEBLAYER_IS_PURE_VIRTUAL) | |
442 DCHECK(parent_->web_layer_); | |
443 parent_->web_layer_->replaceChild(web_layer_, new_layer); | |
444 #else | |
381 DCHECK(!parent_->web_layer_.isNull()); | 445 DCHECK(!parent_->web_layer_.isNull()); |
382 parent_->web_layer_.replaceChild(web_layer_, new_layer); | 446 parent_->web_layer_.replaceChild(web_layer_, new_layer); |
447 #endif | |
383 } | 448 } |
449 #if defined(WEBLAYER_IS_PURE_VIRTUAL) | |
450 web_layer_= new_layer; | |
451 #else | |
384 web_layer_ = new_layer; | 452 web_layer_ = new_layer; |
453 #endif | |
385 web_layer_is_accelerated_ = layer_updated_externally_; | 454 web_layer_is_accelerated_ = layer_updated_externally_; |
386 for (size_t i = 0; i < children_.size(); ++i) { | 455 for (size_t i = 0; i < children_.size(); ++i) { |
456 #if defined(WEBLAYER_IS_PURE_VIRTUAL) | |
457 DCHECK(children_[i]->web_layer_); | |
458 web_layer_->addChild(children_[i]->web_layer_); | |
459 #else | |
387 DCHECK(!children_[i]->web_layer_.isNull()); | 460 DCHECK(!children_[i]->web_layer_.isNull()); |
388 web_layer_.addChild(children_[i]->web_layer_); | 461 web_layer_.addChild(children_[i]->web_layer_); |
462 #endif | |
389 } | 463 } |
464 #if defined(WEBLAYER_IS_PURE_VIRTUAL) | |
465 web_layer_->setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); | |
466 web_layer_->setOpaque(fills_bounds_opaquely_); | |
467 web_layer_->setOpacity(visible_ ? opacity_ : 0.f); | |
468 web_layer_->setDebugBorderWidth(show_debug_borders_ ? 2 : 0); | |
469 web_layer_->setForceRenderSurface(force_render_surface_); | |
470 #else | |
390 web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); | 471 web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); |
391 web_layer_.setOpaque(fills_bounds_opaquely_); | 472 web_layer_.setOpaque(fills_bounds_opaquely_); |
392 web_layer_.setOpacity(visible_ ? opacity_ : 0.f); | 473 web_layer_.setOpacity(visible_ ? opacity_ : 0.f); |
393 web_layer_.setDebugBorderWidth(show_debug_borders_ ? 2 : 0); | 474 web_layer_.setDebugBorderWidth(show_debug_borders_ ? 2 : 0); |
394 web_layer_.setForceRenderSurface(force_render_surface_); | 475 web_layer_.setForceRenderSurface(force_render_surface_); |
476 #endif | |
395 RecomputeTransform(); | 477 RecomputeTransform(); |
396 RecomputeDebugBorderColor(); | 478 RecomputeDebugBorderColor(); |
397 } | 479 } |
398 RecomputeDrawsContentAndUVRect(); | 480 RecomputeDrawsContentAndUVRect(); |
399 } | 481 } |
400 | 482 |
401 void Layer::SetColor(SkColor color) { | 483 void Layer::SetColor(SkColor color) { |
402 DCHECK_EQ(type_, LAYER_SOLID_COLOR); | 484 DCHECK_EQ(type_, LAYER_SOLID_COLOR); |
403 // WebColor is equivalent to SkColor, per WebColor.h. | 485 // WebColor is equivalent to SkColor, per WebColor.h. |
486 #if defined(WEBLAYER_IS_PURE_VIRTUAL) | |
487 solid_color_layer_->setBackgroundColor(static_cast<WebKit::WebColor>(color)); | |
488 #else | |
404 web_layer_.to<WebKit::WebSolidColorLayer>().setBackgroundColor( | 489 web_layer_.to<WebKit::WebSolidColorLayer>().setBackgroundColor( |
405 static_cast<WebKit::WebColor>(color)); | 490 static_cast<WebKit::WebColor>(color)); |
491 #endif | |
406 SetFillsBoundsOpaquely(SkColorGetA(color) == 0xFF); | 492 SetFillsBoundsOpaquely(SkColorGetA(color) == 0xFF); |
407 } | 493 } |
408 | 494 |
409 bool Layer::SchedulePaint(const gfx::Rect& invalid_rect) { | 495 bool Layer::SchedulePaint(const gfx::Rect& invalid_rect) { |
410 if (type_ == LAYER_SOLID_COLOR || (!delegate_ && !texture_)) | 496 if (type_ == LAYER_SOLID_COLOR || (!delegate_ && !texture_)) |
411 return false; | 497 return false; |
412 | 498 |
413 damaged_region_.op(invalid_rect.x(), | 499 damaged_region_.op(invalid_rect.x(), |
414 invalid_rect.y(), | 500 invalid_rect.y(), |
415 invalid_rect.right(), | 501 invalid_rect.right(), |
(...skipping 24 matching lines...) Expand all Loading... | |
440 damaged.Inset(-1, -1); | 526 damaged.Inset(-1, -1); |
441 damaged = damaged.Intersect(gfx::Rect(bounds_.size())); | 527 damaged = damaged.Intersect(gfx::Rect(bounds_.size())); |
442 } | 528 } |
443 | 529 |
444 gfx::Rect damaged_in_pixel = ConvertRectToPixel(this, damaged); | 530 gfx::Rect damaged_in_pixel = ConvertRectToPixel(this, damaged); |
445 WebKit::WebFloatRect web_rect( | 531 WebKit::WebFloatRect web_rect( |
446 damaged_in_pixel.x(), | 532 damaged_in_pixel.x(), |
447 damaged_in_pixel.y(), | 533 damaged_in_pixel.y(), |
448 damaged_in_pixel.width(), | 534 damaged_in_pixel.width(), |
449 damaged_in_pixel.height()); | 535 damaged_in_pixel.height()); |
536 #if defined(WEBLAYER_IS_PURE_VIRTUAL) | |
537 web_layer_->invalidateRect(web_rect); | |
538 #else | |
450 if (!web_layer_is_accelerated_) | 539 if (!web_layer_is_accelerated_) |
451 web_layer_.to<WebKit::WebContentLayer>().invalidateRect(web_rect); | 540 web_layer_.to<WebKit::WebContentLayer>().invalidateRect(web_rect); |
452 else | 541 else |
453 web_layer_.to<WebKit::WebExternalTextureLayer>().invalidateRect( | 542 web_layer_.to<WebKit::WebExternalTextureLayer>().invalidateRect( |
454 web_rect); | 543 web_rect); |
544 #endif | |
455 } | 545 } |
456 damaged_region_.setEmpty(); | 546 damaged_region_.setEmpty(); |
457 } | 547 } |
458 for (size_t i = 0; i < children_.size(); ++i) | 548 for (size_t i = 0; i < children_.size(); ++i) |
459 children_[i]->SendDamagedRects(); | 549 children_[i]->SendDamagedRects(); |
460 } | 550 } |
461 | 551 |
462 void Layer::SuppressPaint() { | 552 void Layer::SuppressPaint() { |
463 if (!delegate_) | 553 if (!delegate_) |
464 return; | 554 return; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
501 delegate_->OnPaintLayer(canvas.get()); | 591 delegate_->OnPaintLayer(canvas.get()); |
502 if (scale_content_) | 592 if (scale_content_) |
503 canvas->Restore(); | 593 canvas->Restore(); |
504 } | 594 } |
505 | 595 |
506 void Layer::SetForceRenderSurface(bool force) { | 596 void Layer::SetForceRenderSurface(bool force) { |
507 if (force_render_surface_ == force) | 597 if (force_render_surface_ == force) |
508 return; | 598 return; |
509 | 599 |
510 force_render_surface_ = force; | 600 force_render_surface_ = force; |
601 #if defined(WEBLAYER_IS_PURE_VIRTUAL) | |
602 web_layer_->setForceRenderSurface(force_render_surface_); | |
603 #else | |
511 web_layer_.setForceRenderSurface(force_render_surface_); | 604 web_layer_.setForceRenderSurface(force_render_surface_); |
605 #endif | |
512 } | 606 } |
513 | 607 |
514 float Layer::GetCombinedOpacity() const { | 608 float Layer::GetCombinedOpacity() const { |
515 float opacity = opacity_; | 609 float opacity = opacity_; |
516 Layer* current = this->parent_; | 610 Layer* current = this->parent_; |
517 while (current) { | 611 while (current) { |
518 opacity *= current->opacity_; | 612 opacity *= current->opacity_; |
519 current = current->parent_; | 613 current = current->parent_; |
520 } | 614 } |
521 return opacity; | 615 return opacity; |
(...skipping 11 matching lines...) Expand all Loading... | |
533 if ((above && child_i == other_i + 1) || (!above && child_i + 1 == other_i)) | 627 if ((above && child_i == other_i + 1) || (!above && child_i + 1 == other_i)) |
534 return; | 628 return; |
535 | 629 |
536 const size_t dest_i = | 630 const size_t dest_i = |
537 above ? | 631 above ? |
538 (child_i < other_i ? other_i : other_i + 1) : | 632 (child_i < other_i ? other_i : other_i + 1) : |
539 (child_i < other_i ? other_i - 1 : other_i); | 633 (child_i < other_i ? other_i - 1 : other_i); |
540 children_.erase(children_.begin() + child_i); | 634 children_.erase(children_.begin() + child_i); |
541 children_.insert(children_.begin() + dest_i, child); | 635 children_.insert(children_.begin() + dest_i, child); |
542 | 636 |
637 #if defined(WEBLAYER_IS_PURE_VIRTUAL) | |
638 child->web_layer_->removeFromParent(); | |
639 web_layer_->insertChild(child->web_layer_, dest_i); | |
640 #else | |
543 child->web_layer_.removeFromParent(); | 641 child->web_layer_.removeFromParent(); |
544 web_layer_.insertChild(child->web_layer_, dest_i); | 642 web_layer_.insertChild(child->web_layer_, dest_i); |
643 #endif | |
545 } | 644 } |
546 | 645 |
547 bool Layer::ConvertPointForAncestor(const Layer* ancestor, | 646 bool Layer::ConvertPointForAncestor(const Layer* ancestor, |
548 gfx::Point* point) const { | 647 gfx::Point* point) const { |
549 ui::Transform transform; | 648 ui::Transform transform; |
550 bool result = GetTransformRelativeTo(ancestor, &transform); | 649 bool result = GetTransformRelativeTo(ancestor, &transform); |
551 gfx::Point3f p(*point); | 650 gfx::Point3f p(*point); |
552 transform.TransformPoint(p); | 651 transform.TransformPoint(p); |
553 *point = p.AsPoint(); | 652 *point = p.AsPoint(); |
554 return result; | 653 return result; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
606 transform_ = transform; | 705 transform_ = transform; |
607 | 706 |
608 RecomputeTransform(); | 707 RecomputeTransform(); |
609 } | 708 } |
610 | 709 |
611 void Layer::SetOpacityImmediately(float opacity) { | 710 void Layer::SetOpacityImmediately(float opacity) { |
612 bool schedule_draw = (opacity != opacity_ && IsDrawn()); | 711 bool schedule_draw = (opacity != opacity_ && IsDrawn()); |
613 opacity_ = opacity; | 712 opacity_ = opacity; |
614 | 713 |
615 if (visible_) | 714 if (visible_) |
715 #if defined(WEBLAYER_IS_PURE_VIRTUAL) | |
716 web_layer_->setOpacity(opacity); | |
717 #else | |
616 web_layer_.setOpacity(opacity); | 718 web_layer_.setOpacity(opacity); |
719 #endif | |
617 RecomputeDebugBorderColor(); | 720 RecomputeDebugBorderColor(); |
618 if (schedule_draw) | 721 if (schedule_draw) |
619 ScheduleDraw(); | 722 ScheduleDraw(); |
620 } | 723 } |
621 | 724 |
622 void Layer::SetVisibilityImmediately(bool visible) { | 725 void Layer::SetVisibilityImmediately(bool visible) { |
623 if (visible_ == visible) | 726 if (visible_ == visible) |
624 return; | 727 return; |
625 | 728 |
626 visible_ = visible; | 729 visible_ = visible; |
627 // TODO(piman): Expose a visibility flag on WebLayer. | 730 // TODO(piman): Expose a visibility flag on WebLayer. |
731 #if defined(WEBLAYER_IS_PURE_VIRTUAL) | |
732 web_layer_->setOpacity(visible_ ? opacity_ : 0.f); | |
733 #else | |
628 web_layer_.setOpacity(visible_ ? opacity_ : 0.f); | 734 web_layer_.setOpacity(visible_ ? opacity_ : 0.f); |
735 #endif | |
629 } | 736 } |
630 | 737 |
631 void Layer::SetBrightnessImmediately(float brightness) { | 738 void Layer::SetBrightnessImmediately(float brightness) { |
632 layer_brightness_ = brightness; | 739 layer_brightness_ = brightness; |
633 SetLayerFilters(); | 740 SetLayerFilters(); |
634 } | 741 } |
635 | 742 |
636 void Layer::SetGrayscaleImmediately(float grayscale) { | 743 void Layer::SetGrayscaleImmediately(float grayscale) { |
637 layer_grayscale_ = grayscale; | 744 layer_grayscale_ = grayscale; |
638 SetLayerFilters(); | 745 SetLayerFilters(); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
683 | 790 |
684 float Layer::GetBrightnessForAnimation() const { | 791 float Layer::GetBrightnessForAnimation() const { |
685 return layer_brightness(); | 792 return layer_brightness(); |
686 } | 793 } |
687 | 794 |
688 float Layer::GetGrayscaleForAnimation() const { | 795 float Layer::GetGrayscaleForAnimation() const { |
689 return layer_grayscale(); | 796 return layer_grayscale(); |
690 } | 797 } |
691 | 798 |
692 void Layer::CreateWebLayer() { | 799 void Layer::CreateWebLayer() { |
800 #if defined(WEBLAYER_IS_PURE_VIRTUAL) | |
801 if (type_ == LAYER_SOLID_COLOR) { | |
802 solid_color_layer_.reset(WebKit::WebSolidColorLayer::create()); | |
803 web_layer_ = solid_color_layer_->layer(); | |
804 } else { | |
805 solid_color_layer_.reset(); | |
806 texture_layer_.reset(); | |
piman
2012/08/18 00:34:18
nit: you can get rid of those 2 as well.
jamesr
2012/08/18 00:35:41
I see, I missed that this was private and just cal
| |
807 content_layer_.reset(WebKit::WebContentLayer::create(this)); | |
808 web_layer_ = content_layer_->layer(); | |
809 } | |
810 #else | |
693 if (type_ == LAYER_SOLID_COLOR) | 811 if (type_ == LAYER_SOLID_COLOR) |
694 web_layer_ = WebKit::WebSolidColorLayer::create(); | 812 web_layer_ = WebKit::WebSolidColorLayer::create(); |
695 else | 813 else |
696 web_layer_ = WebKit::WebContentLayer::create(this); | 814 web_layer_ = WebKit::WebContentLayer::create(this); |
697 web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); | 815 #endif |
698 web_layer_.setOpaque(true); | |
699 web_layer_is_accelerated_ = false; | 816 web_layer_is_accelerated_ = false; |
700 show_debug_borders_ = CommandLine::ForCurrentProcess()->HasSwitch( | 817 show_debug_borders_ = CommandLine::ForCurrentProcess()->HasSwitch( |
701 switches::kUIShowLayerBorders); | 818 switches::kUIShowLayerBorders); |
819 #if defined(WEBLAYER_IS_PURE_VIRTUAL) | |
820 web_layer_->setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); | |
821 web_layer_->setOpaque(true); | |
822 web_layer_->setDebugBorderWidth(show_debug_borders_ ? 2 : 0); | |
823 #else | |
824 web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); | |
825 web_layer_.setOpaque(true); | |
702 web_layer_.setDebugBorderWidth(show_debug_borders_ ? 2 : 0); | 826 web_layer_.setDebugBorderWidth(show_debug_borders_ ? 2 : 0); |
827 #endif | |
703 } | 828 } |
704 | 829 |
705 void Layer::RecomputeTransform() { | 830 void Layer::RecomputeTransform() { |
706 ui::Transform scale_translate; | 831 ui::Transform scale_translate; |
707 scale_translate.matrix().set3x3(device_scale_factor_, 0, 0, | 832 scale_translate.matrix().set3x3(device_scale_factor_, 0, 0, |
708 0, device_scale_factor_, 0, | 833 0, device_scale_factor_, 0, |
709 0, 0, 1); | 834 0, 0, 1); |
710 // Start with the inverse matrix of above. | 835 // Start with the inverse matrix of above. |
711 Transform transform; | 836 Transform transform; |
712 transform.matrix().set3x3(1.0f / device_scale_factor_, 0, 0, | 837 transform.matrix().set3x3(1.0f / device_scale_factor_, 0, 0, |
713 0, 1.0f / device_scale_factor_, 0, | 838 0, 1.0f / device_scale_factor_, 0, |
714 0, 0, 1); | 839 0, 0, 1); |
715 transform.ConcatTransform(transform_); | 840 transform.ConcatTransform(transform_); |
716 transform.ConcatTranslate(bounds_.x(), bounds_.y()); | 841 transform.ConcatTranslate(bounds_.x(), bounds_.y()); |
717 transform.ConcatTransform(scale_translate); | 842 transform.ConcatTransform(scale_translate); |
843 #if defined(WEBLAYER_IS_PURE_VIRTUAL) | |
844 web_layer_->setTransform(transform.matrix()); | |
845 #else | |
718 web_layer_.setTransform(transform.matrix()); | 846 web_layer_.setTransform(transform.matrix()); |
847 #endif | |
719 } | 848 } |
720 | 849 |
721 void Layer::RecomputeDrawsContentAndUVRect() { | 850 void Layer::RecomputeDrawsContentAndUVRect() { |
851 #if defined(WEBLAYER_IS_PURE_VIRTUAL) | |
852 DCHECK(web_layer_); | |
853 #else | |
722 DCHECK(!web_layer_.isNull()); | 854 DCHECK(!web_layer_.isNull()); |
855 #endif | |
723 bool should_draw = type_ != LAYER_NOT_DRAWN; | 856 bool should_draw = type_ != LAYER_NOT_DRAWN; |
724 if (!web_layer_is_accelerated_) { | 857 if (!web_layer_is_accelerated_) { |
725 if (type_ != LAYER_SOLID_COLOR) | 858 if (type_ != LAYER_SOLID_COLOR) { |
859 #if defined(WEBLAYER_IS_PURE_VIRTUAL) | |
860 web_layer_->setDrawsContent(should_draw); | |
861 #else | |
726 web_layer_.to<WebKit::WebContentLayer>().setDrawsContent(should_draw); | 862 web_layer_.to<WebKit::WebContentLayer>().setDrawsContent(should_draw); |
863 #endif | |
864 } | |
865 #if defined(WEBLAYER_IS_PURE_VIRTUAL) | |
866 web_layer_->setBounds(ConvertSizeToPixel(this, bounds_.size())); | |
867 #else | |
727 web_layer_.setBounds(ConvertSizeToPixel(this, bounds_.size())); | 868 web_layer_.setBounds(ConvertSizeToPixel(this, bounds_.size())); |
869 #endif | |
728 } else { | 870 } else { |
729 DCHECK(texture_); | 871 DCHECK(texture_); |
730 unsigned int texture_id = texture_->texture_id(); | 872 unsigned int texture_id = texture_->texture_id(); |
873 #if defined(WEBLAYER_IS_PURE_VIRTUAL) | |
874 texture_layer_->setTextureId(should_draw ? texture_id : 0); | |
875 #else | |
731 WebKit::WebExternalTextureLayer texture_layer = | 876 WebKit::WebExternalTextureLayer texture_layer = |
732 web_layer_.to<WebKit::WebExternalTextureLayer>(); | 877 web_layer_.to<WebKit::WebExternalTextureLayer>(); |
733 texture_layer.setTextureId(should_draw ? texture_id : 0); | 878 texture_layer.setTextureId(should_draw ? texture_id : 0); |
879 #endif | |
734 | 880 |
735 gfx::Size texture_size; | 881 gfx::Size texture_size; |
736 if (scale_content_) | 882 if (scale_content_) |
737 texture_size = texture_->size(); | 883 texture_size = texture_->size(); |
738 else | 884 else |
739 texture_size = ConvertSizeToDIP(this, texture_->size()); | 885 texture_size = ConvertSizeToDIP(this, texture_->size()); |
740 | 886 |
741 gfx::Size size(std::min(bounds().width(), texture_size.width()), | 887 gfx::Size size(std::min(bounds().width(), texture_size.width()), |
742 std::min(bounds().height(), texture_size.height())); | 888 std::min(bounds().height(), texture_size.height())); |
743 WebKit::WebFloatRect rect( | 889 WebKit::WebFloatRect rect( |
744 0, | 890 0, |
745 0, | 891 0, |
746 static_cast<float>(size.width())/texture_size.width(), | 892 static_cast<float>(size.width())/texture_size.width(), |
747 static_cast<float>(size.height())/texture_size.height()); | 893 static_cast<float>(size.height())/texture_size.height()); |
894 #if defined(WEBLAYER_IS_PURE_VIRTUAL) | |
895 texture_layer_->setUVRect(rect); | |
896 #else | |
748 texture_layer.setUVRect(rect); | 897 texture_layer.setUVRect(rect); |
898 #endif | |
749 | 899 |
750 gfx::Size size_in_pixel = ConvertSizeToPixel(this, size); | 900 gfx::Size size_in_pixel = ConvertSizeToPixel(this, size); |
901 #if defined(WEBLAYER_IS_PURE_VIRTUAL) | |
902 web_layer_->setBounds(size_in_pixel); | |
903 #else | |
751 web_layer_.setBounds(size_in_pixel); | 904 web_layer_.setBounds(size_in_pixel); |
905 #endif | |
752 } | 906 } |
753 } | 907 } |
754 | 908 |
755 void Layer::RecomputeDebugBorderColor() { | 909 void Layer::RecomputeDebugBorderColor() { |
756 if (!show_debug_borders_) | 910 if (!show_debug_borders_) |
757 return; | 911 return; |
758 unsigned int color = 0xFF000000; | 912 unsigned int color = 0xFF000000; |
759 color |= web_layer_is_accelerated_ ? 0x0000FF00 : 0x00FF0000; | 913 color |= web_layer_is_accelerated_ ? 0x0000FF00 : 0x00FF0000; |
760 bool opaque = fills_bounds_opaquely_ && (GetCombinedOpacity() == 1.f); | 914 bool opaque = fills_bounds_opaquely_ && (GetCombinedOpacity() == 1.f); |
761 if (!opaque) | 915 if (!opaque) |
762 color |= 0xFF; | 916 color |= 0xFF; |
917 #if defined(WEBLAYER_IS_PURE_VIRTUAL) | |
918 web_layer_->setDebugBorderColor(color); | |
919 #else | |
763 web_layer_.setDebugBorderColor(color); | 920 web_layer_.setDebugBorderColor(color); |
921 #endif | |
764 } | 922 } |
765 | 923 |
766 } // namespace ui | 924 } // namespace ui |
OLD | NEW |