| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 "webkit/renderer/compositor_bindings/web_layer_impl.h" | 5 #include "webkit/renderer/compositor_bindings/web_layer_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "cc/animation/animation.h" | 9 #include "cc/animation/animation.h" |
| 10 #include "cc/base/region.h" | 10 #include "cc/base/region.h" |
| 11 #include "cc/layers/layer.h" | 11 #include "cc/layers/layer.h" |
| 12 #include "cc/layers/layer_position_constraint.h" | 12 #include "cc/layers/layer_position_constraint.h" |
| 13 #include "third_party/WebKit/public/platform/WebCompositingReasons.h" | 13 #include "third_party/WebKit/public/platform/WebCompositingReasons.h" |
| 14 #include "third_party/WebKit/public/platform/WebFloatPoint.h" | 14 #include "third_party/WebKit/public/platform/WebFloatPoint.h" |
| 15 #include "third_party/WebKit/public/platform/WebFloatRect.h" | 15 #include "third_party/WebKit/public/platform/WebFloatRect.h" |
| 16 #include "third_party/WebKit/public/platform/WebLayerClient.h" | 16 #include "third_party/WebKit/public/platform/WebLayerClient.h" |
| 17 #include "third_party/WebKit/public/platform/WebLayerPositionConstraint.h" | 17 #include "third_party/WebKit/public/platform/WebLayerPositionConstraint.h" |
| 18 #include "third_party/WebKit/public/platform/WebLayerScrollClient.h" | 18 #include "third_party/WebKit/public/platform/WebLayerScrollClient.h" |
| 19 #include "third_party/WebKit/public/platform/WebSize.h" | 19 #include "third_party/WebKit/public/platform/WebSize.h" |
| 20 #include "third_party/skia/include/utils/SkMatrix44.h" | 20 #include "third_party/skia/include/utils/SkMatrix44.h" |
| 21 #include "webkit/renderer/compositor_bindings/web_animation_impl.h" | 21 #include "webkit/renderer/compositor_bindings/web_animation_impl.h" |
| 22 #include "webkit/renderer/compositor_bindings/web_filter_operations_impl.h" | 22 #include "webkit/renderer/compositor_bindings/web_filter_operations_impl.h" |
| 23 #include "webkit/renderer/compositor_bindings/web_to_cc_animation_delegate_adapt
er.h" | 23 #include "webkit/renderer/compositor_bindings/web_to_cc_animation_delegate_adapt
er.h" |
| 24 | 24 |
| 25 using cc::Animation; | 25 using cc::Animation; |
| 26 using cc::Layer; | 26 using cc::Layer; |
| 27 using WebKit::WebLayer; | 27 using blink::WebLayer; |
| 28 using WebKit::WebFloatPoint; | 28 using blink::WebFloatPoint; |
| 29 using WebKit::WebVector; | 29 using blink::WebVector; |
| 30 using WebKit::WebRect; | 30 using blink::WebRect; |
| 31 using WebKit::WebSize; | 31 using blink::WebSize; |
| 32 using WebKit::WebColor; | 32 using blink::WebColor; |
| 33 using WebKit::WebFilterOperations; | 33 using blink::WebFilterOperations; |
| 34 | 34 |
| 35 namespace webkit { | 35 namespace webkit { |
| 36 | 36 |
| 37 WebLayerImpl::WebLayerImpl() : layer_(Layer::Create()) { | 37 WebLayerImpl::WebLayerImpl() : layer_(Layer::Create()) { |
| 38 web_layer_client_ = NULL; | 38 web_layer_client_ = NULL; |
| 39 layer_->SetLayerClient(this); | 39 layer_->SetLayerClient(this); |
| 40 } | 40 } |
| 41 | 41 |
| 42 WebLayerImpl::WebLayerImpl(scoped_refptr<Layer> layer) : layer_(layer) { | 42 WebLayerImpl::WebLayerImpl(scoped_refptr<Layer> layer) : layer_(layer) { |
| 43 web_layer_client_ = NULL; | 43 web_layer_client_ = NULL; |
| 44 layer_->SetLayerClient(this); | 44 layer_->SetLayerClient(this); |
| 45 } | 45 } |
| 46 | 46 |
| 47 WebLayerImpl::~WebLayerImpl() { | 47 WebLayerImpl::~WebLayerImpl() { |
| 48 layer_->ClearRenderSurface(); | 48 layer_->ClearRenderSurface(); |
| 49 layer_->set_layer_animation_delegate(NULL); | 49 layer_->set_layer_animation_delegate(NULL); |
| 50 web_layer_client_ = NULL; | 50 web_layer_client_ = NULL; |
| 51 } | 51 } |
| 52 | 52 |
| 53 int WebLayerImpl::id() const { return layer_->id(); } | 53 int WebLayerImpl::id() const { return layer_->id(); } |
| 54 | 54 |
| 55 void WebLayerImpl::invalidateRect(const WebKit::WebFloatRect& rect) { | 55 void WebLayerImpl::invalidateRect(const blink::WebFloatRect& rect) { |
| 56 layer_->SetNeedsDisplayRect(rect); | 56 layer_->SetNeedsDisplayRect(rect); |
| 57 } | 57 } |
| 58 | 58 |
| 59 void WebLayerImpl::invalidate() { layer_->SetNeedsDisplay(); } | 59 void WebLayerImpl::invalidate() { layer_->SetNeedsDisplay(); } |
| 60 | 60 |
| 61 void WebLayerImpl::addChild(WebLayer* child) { | 61 void WebLayerImpl::addChild(WebLayer* child) { |
| 62 layer_->AddChild(static_cast<WebLayerImpl*>(child)->layer()); | 62 layer_->AddChild(static_cast<WebLayerImpl*>(child)->layer()); |
| 63 } | 63 } |
| 64 | 64 |
| 65 void WebLayerImpl::insertChild(WebLayer* child, size_t index) { | 65 void WebLayerImpl::insertChild(WebLayer* child, size_t index) { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 layer_->SetFilters(filters_impl.AsFilterOperations()); | 172 layer_->SetFilters(filters_impl.AsFilterOperations()); |
| 173 } | 173 } |
| 174 | 174 |
| 175 void WebLayerImpl::setBackgroundFilters(const WebFilterOperations& filters) { | 175 void WebLayerImpl::setBackgroundFilters(const WebFilterOperations& filters) { |
| 176 const WebFilterOperationsImpl& filters_impl = | 176 const WebFilterOperationsImpl& filters_impl = |
| 177 static_cast<const WebFilterOperationsImpl&>(filters); | 177 static_cast<const WebFilterOperationsImpl&>(filters); |
| 178 layer_->SetBackgroundFilters(filters_impl.AsFilterOperations()); | 178 layer_->SetBackgroundFilters(filters_impl.AsFilterOperations()); |
| 179 } | 179 } |
| 180 | 180 |
| 181 void WebLayerImpl::setCompositingReasons( | 181 void WebLayerImpl::setCompositingReasons( |
| 182 WebKit::WebCompositingReasons reasons) { | 182 blink::WebCompositingReasons reasons) { |
| 183 layer_->SetCompositingReasons(reasons); | 183 layer_->SetCompositingReasons(reasons); |
| 184 } | 184 } |
| 185 | 185 |
| 186 void WebLayerImpl::setAnimationDelegate( | 186 void WebLayerImpl::setAnimationDelegate( |
| 187 WebKit::WebAnimationDelegate* delegate) { | 187 blink::WebAnimationDelegate* delegate) { |
| 188 animation_delegate_adapter_.reset( | 188 animation_delegate_adapter_.reset( |
| 189 new WebToCCAnimationDelegateAdapter(delegate)); | 189 new WebToCCAnimationDelegateAdapter(delegate)); |
| 190 layer_->set_layer_animation_delegate(animation_delegate_adapter_.get()); | 190 layer_->set_layer_animation_delegate(animation_delegate_adapter_.get()); |
| 191 } | 191 } |
| 192 | 192 |
| 193 bool WebLayerImpl::addAnimation(WebKit::WebAnimation* animation) { | 193 bool WebLayerImpl::addAnimation(blink::WebAnimation* animation) { |
| 194 bool result = layer_->AddAnimation( | 194 bool result = layer_->AddAnimation( |
| 195 static_cast<WebAnimationImpl*>(animation)->PassAnimation()); | 195 static_cast<WebAnimationImpl*>(animation)->PassAnimation()); |
| 196 delete animation; | 196 delete animation; |
| 197 return result; | 197 return result; |
| 198 } | 198 } |
| 199 | 199 |
| 200 void WebLayerImpl::removeAnimation(int animation_id) { | 200 void WebLayerImpl::removeAnimation(int animation_id) { |
| 201 layer_->RemoveAnimation(animation_id); | 201 layer_->RemoveAnimation(animation_id); |
| 202 } | 202 } |
| 203 | 203 |
| 204 void WebLayerImpl::removeAnimation( | 204 void WebLayerImpl::removeAnimation( |
| 205 int animation_id, | 205 int animation_id, |
| 206 WebKit::WebAnimation::TargetProperty target_property) { | 206 blink::WebAnimation::TargetProperty target_property) { |
| 207 layer_->layer_animation_controller()->RemoveAnimation( | 207 layer_->layer_animation_controller()->RemoveAnimation( |
| 208 animation_id, | 208 animation_id, |
| 209 static_cast<Animation::TargetProperty>(target_property)); | 209 static_cast<Animation::TargetProperty>(target_property)); |
| 210 } | 210 } |
| 211 | 211 |
| 212 void WebLayerImpl::pauseAnimation(int animation_id, double time_offset) { | 212 void WebLayerImpl::pauseAnimation(int animation_id, double time_offset) { |
| 213 layer_->PauseAnimation(animation_id, time_offset); | 213 layer_->PauseAnimation(animation_id, time_offset); |
| 214 } | 214 } |
| 215 | 215 |
| 216 bool WebLayerImpl::hasActiveAnimation() { return layer_->HasActiveAnimation(); } | 216 bool WebLayerImpl::hasActiveAnimation() { return layer_->HasActiveAnimation(); } |
| 217 | 217 |
| 218 void WebLayerImpl::setForceRenderSurface(bool force_render_surface) { | 218 void WebLayerImpl::setForceRenderSurface(bool force_render_surface) { |
| 219 layer_->SetForceRenderSurface(force_render_surface); | 219 layer_->SetForceRenderSurface(force_render_surface); |
| 220 } | 220 } |
| 221 | 221 |
| 222 void WebLayerImpl::setScrollPosition(WebKit::WebPoint position) { | 222 void WebLayerImpl::setScrollPosition(blink::WebPoint position) { |
| 223 layer_->SetScrollOffset(gfx::Point(position).OffsetFromOrigin()); | 223 layer_->SetScrollOffset(gfx::Point(position).OffsetFromOrigin()); |
| 224 } | 224 } |
| 225 | 225 |
| 226 WebKit::WebPoint WebLayerImpl::scrollPosition() const { | 226 blink::WebPoint WebLayerImpl::scrollPosition() const { |
| 227 return gfx::PointAtOffsetFromOrigin(layer_->scroll_offset()); | 227 return gfx::PointAtOffsetFromOrigin(layer_->scroll_offset()); |
| 228 } | 228 } |
| 229 | 229 |
| 230 void WebLayerImpl::setMaxScrollPosition(WebSize max_scroll_position) { | 230 void WebLayerImpl::setMaxScrollPosition(WebSize max_scroll_position) { |
| 231 layer_->SetMaxScrollOffset(max_scroll_position); | 231 layer_->SetMaxScrollOffset(max_scroll_position); |
| 232 } | 232 } |
| 233 | 233 |
| 234 WebSize WebLayerImpl::maxScrollPosition() const { | 234 WebSize WebLayerImpl::maxScrollPosition() const { |
| 235 return layer_->max_scroll_offset(); | 235 return layer_->max_scroll_offset(); |
| 236 } | 236 } |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 } | 321 } |
| 322 | 322 |
| 323 void WebLayerImpl::setIsContainerForFixedPositionLayers(bool enable) { | 323 void WebLayerImpl::setIsContainerForFixedPositionLayers(bool enable) { |
| 324 layer_->SetIsContainerForFixedPositionLayers(enable); | 324 layer_->SetIsContainerForFixedPositionLayers(enable); |
| 325 } | 325 } |
| 326 | 326 |
| 327 bool WebLayerImpl::isContainerForFixedPositionLayers() const { | 327 bool WebLayerImpl::isContainerForFixedPositionLayers() const { |
| 328 return layer_->IsContainerForFixedPositionLayers(); | 328 return layer_->IsContainerForFixedPositionLayers(); |
| 329 } | 329 } |
| 330 | 330 |
| 331 static WebKit::WebLayerPositionConstraint ToWebLayerPositionConstraint( | 331 static blink::WebLayerPositionConstraint ToWebLayerPositionConstraint( |
| 332 const cc::LayerPositionConstraint& constraint) { | 332 const cc::LayerPositionConstraint& constraint) { |
| 333 WebKit::WebLayerPositionConstraint web_constraint; | 333 blink::WebLayerPositionConstraint web_constraint; |
| 334 web_constraint.isFixedPosition = constraint.is_fixed_position(); | 334 web_constraint.isFixedPosition = constraint.is_fixed_position(); |
| 335 web_constraint.isFixedToRightEdge = constraint.is_fixed_to_right_edge(); | 335 web_constraint.isFixedToRightEdge = constraint.is_fixed_to_right_edge(); |
| 336 web_constraint.isFixedToBottomEdge = constraint.is_fixed_to_bottom_edge(); | 336 web_constraint.isFixedToBottomEdge = constraint.is_fixed_to_bottom_edge(); |
| 337 return web_constraint; | 337 return web_constraint; |
| 338 } | 338 } |
| 339 | 339 |
| 340 static cc::LayerPositionConstraint ToLayerPositionConstraint( | 340 static cc::LayerPositionConstraint ToLayerPositionConstraint( |
| 341 const WebKit::WebLayerPositionConstraint& web_constraint) { | 341 const blink::WebLayerPositionConstraint& web_constraint) { |
| 342 cc::LayerPositionConstraint constraint; | 342 cc::LayerPositionConstraint constraint; |
| 343 constraint.set_is_fixed_position(web_constraint.isFixedPosition); | 343 constraint.set_is_fixed_position(web_constraint.isFixedPosition); |
| 344 constraint.set_is_fixed_to_right_edge(web_constraint.isFixedToRightEdge); | 344 constraint.set_is_fixed_to_right_edge(web_constraint.isFixedToRightEdge); |
| 345 constraint.set_is_fixed_to_bottom_edge(web_constraint.isFixedToBottomEdge); | 345 constraint.set_is_fixed_to_bottom_edge(web_constraint.isFixedToBottomEdge); |
| 346 return constraint; | 346 return constraint; |
| 347 } | 347 } |
| 348 | 348 |
| 349 void WebLayerImpl::setPositionConstraint( | 349 void WebLayerImpl::setPositionConstraint( |
| 350 const WebKit::WebLayerPositionConstraint& constraint) { | 350 const blink::WebLayerPositionConstraint& constraint) { |
| 351 layer_->SetPositionConstraint(ToLayerPositionConstraint(constraint)); | 351 layer_->SetPositionConstraint(ToLayerPositionConstraint(constraint)); |
| 352 } | 352 } |
| 353 | 353 |
| 354 WebKit::WebLayerPositionConstraint WebLayerImpl::positionConstraint() const { | 354 blink::WebLayerPositionConstraint WebLayerImpl::positionConstraint() const { |
| 355 return ToWebLayerPositionConstraint(layer_->position_constraint()); | 355 return ToWebLayerPositionConstraint(layer_->position_constraint()); |
| 356 } | 356 } |
| 357 | 357 |
| 358 void WebLayerImpl::setScrollClient( | 358 void WebLayerImpl::setScrollClient( |
| 359 WebKit::WebLayerScrollClient* scroll_client) { | 359 blink::WebLayerScrollClient* scroll_client) { |
| 360 if (scroll_client) { | 360 if (scroll_client) { |
| 361 layer_->set_did_scroll_callback( | 361 layer_->set_did_scroll_callback( |
| 362 base::Bind(&WebKit::WebLayerScrollClient::didScroll, | 362 base::Bind(&blink::WebLayerScrollClient::didScroll, |
| 363 base::Unretained(scroll_client))); | 363 base::Unretained(scroll_client))); |
| 364 } else { | 364 } else { |
| 365 layer_->set_did_scroll_callback(base::Closure()); | 365 layer_->set_did_scroll_callback(base::Closure()); |
| 366 } | 366 } |
| 367 } | 367 } |
| 368 | 368 |
| 369 bool WebLayerImpl::isOrphan() const { return !layer_->layer_tree_host(); } | 369 bool WebLayerImpl::isOrphan() const { return !layer_->layer_tree_host(); } |
| 370 | 370 |
| 371 void WebLayerImpl::setWebLayerClient(WebKit::WebLayerClient* client) { | 371 void WebLayerImpl::setWebLayerClient(blink::WebLayerClient* client) { |
| 372 web_layer_client_ = client; | 372 web_layer_client_ = client; |
| 373 } | 373 } |
| 374 | 374 |
| 375 std::string WebLayerImpl::DebugName() { | 375 std::string WebLayerImpl::DebugName() { |
| 376 if (!web_layer_client_) | 376 if (!web_layer_client_) |
| 377 return std::string(); | 377 return std::string(); |
| 378 | 378 |
| 379 std::string name = web_layer_client_->debugName(this).utf8(); | 379 std::string name = web_layer_client_->debugName(this).utf8(); |
| 380 DCHECK(IsStringASCII(name)); | 380 DCHECK(IsStringASCII(name)); |
| 381 return name; | 381 return name; |
| 382 } | 382 } |
| 383 | 383 |
| 384 void WebLayerImpl::setScrollParent(WebKit::WebLayer* parent) { | 384 void WebLayerImpl::setScrollParent(blink::WebLayer* parent) { |
| 385 cc::Layer* scroll_parent = NULL; | 385 cc::Layer* scroll_parent = NULL; |
| 386 if (parent) | 386 if (parent) |
| 387 scroll_parent = static_cast<WebLayerImpl*>(parent)->layer(); | 387 scroll_parent = static_cast<WebLayerImpl*>(parent)->layer(); |
| 388 layer_->SetScrollParent(scroll_parent); | 388 layer_->SetScrollParent(scroll_parent); |
| 389 } | 389 } |
| 390 | 390 |
| 391 void WebLayerImpl::setClipParent(WebKit::WebLayer* parent) { | 391 void WebLayerImpl::setClipParent(blink::WebLayer* parent) { |
| 392 cc::Layer* clip_parent = NULL; | 392 cc::Layer* clip_parent = NULL; |
| 393 if (parent) | 393 if (parent) |
| 394 clip_parent = static_cast<WebLayerImpl*>(parent)->layer(); | 394 clip_parent = static_cast<WebLayerImpl*>(parent)->layer(); |
| 395 layer_->SetClipParent(clip_parent); | 395 layer_->SetClipParent(clip_parent); |
| 396 } | 396 } |
| 397 | 397 |
| 398 Layer* WebLayerImpl::layer() const { return layer_.get(); } | 398 Layer* WebLayerImpl::layer() const { return layer_.get(); } |
| 399 | 399 |
| 400 } // namespace webkit | 400 } // namespace webkit |
| OLD | NEW |