Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(860)

Side by Side Diff: Source/core/rendering/RenderLayerBacking.cpp

Issue 23431021: Refactoring animation code in accelerated path. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009, 2010, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2009, 2010, 2011 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 22 matching lines...) Expand all
33 #include "core/fetch/ImageResource.h" 33 #include "core/fetch/ImageResource.h"
34 #include "core/html/HTMLIFrameElement.h" 34 #include "core/html/HTMLIFrameElement.h"
35 #include "core/html/HTMLMediaElement.h" 35 #include "core/html/HTMLMediaElement.h"
36 #include "core/html/canvas/CanvasRenderingContext.h" 36 #include "core/html/canvas/CanvasRenderingContext.h"
37 #include "core/inspector/InspectorInstrumentation.h" 37 #include "core/inspector/InspectorInstrumentation.h"
38 #include "core/page/Chrome.h" 38 #include "core/page/Chrome.h"
39 #include "core/page/FrameView.h" 39 #include "core/page/FrameView.h"
40 #include "core/page/Settings.h" 40 #include "core/page/Settings.h"
41 #include "core/page/animation/AnimationController.h" 41 #include "core/page/animation/AnimationController.h"
42 #include "core/page/scrolling/ScrollingCoordinator.h" 42 #include "core/page/scrolling/ScrollingCoordinator.h"
43 #include "core/platform/animation/KeyframeValueList.h"
44 #include "core/platform/graphics/FontCache.h" 43 #include "core/platform/graphics/FontCache.h"
45 #include "core/platform/graphics/GraphicsContext.h" 44 #include "core/platform/graphics/GraphicsContext.h"
46 #include "core/platform/graphics/GraphicsLayer.h" 45 #include "core/platform/graphics/GraphicsLayer.h"
47 #include "core/plugins/PluginView.h" 46 #include "core/plugins/PluginView.h"
48 #include "core/rendering/RenderApplet.h" 47 #include "core/rendering/RenderApplet.h"
49 #include "core/rendering/RenderEmbeddedObject.h" 48 #include "core/rendering/RenderEmbeddedObject.h"
50 #include "core/rendering/RenderIFrame.h" 49 #include "core/rendering/RenderIFrame.h"
51 #include "core/rendering/RenderImage.h" 50 #include "core/rendering/RenderImage.h"
52 #include "core/rendering/RenderLayer.h" 51 #include "core/rendering/RenderLayer.h"
53 #include "core/rendering/RenderLayerCompositor.h" 52 #include "core/rendering/RenderLayerCompositor.h"
54 #include "core/rendering/RenderVideo.h" 53 #include "core/rendering/RenderVideo.h"
55 #include "core/rendering/RenderView.h" 54 #include "core/rendering/RenderView.h"
55 #include "core/rendering/animation/WebAnimationProvider.h"
56 #include "core/rendering/style/KeyframeList.h" 56 #include "core/rendering/style/KeyframeList.h"
57 #include "wtf/CurrentTime.h" 57 #include "wtf/CurrentTime.h"
58 #include "wtf/text/StringBuilder.h" 58 #include "wtf/text/StringBuilder.h"
59 59
60 #include "core/platform/graphics/filters/custom/CustomFilterOperation.h" 60 #include "core/platform/graphics/filters/custom/CustomFilterOperation.h"
61 #include "core/rendering/FilterEffectRenderer.h" 61 #include "core/rendering/FilterEffectRenderer.h"
62 62
63 #include "core/platform/graphics/GraphicsContext3D.h" 63 #include "core/platform/graphics/GraphicsContext3D.h"
64 64
65 using namespace std; 65 using namespace std;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 { 145 {
146 Page* page = layer->renderer()->frame()->page(); 146 Page* page = layer->renderer()->frame()->page();
147 if (!page) 147 if (!page)
148 return 0; 148 return 0;
149 149
150 return page->scrollingCoordinator(); 150 return page->scrollingCoordinator();
151 } 151 }
152 152
153 RenderLayerBacking::RenderLayerBacking(RenderLayer* layer) 153 RenderLayerBacking::RenderLayerBacking(RenderLayer* layer)
154 : m_owningLayer(layer) 154 : m_owningLayer(layer)
155 , m_animationProvider(adoptPtr(new WebAnimationProvider))
155 , m_artificiallyInflatedBounds(false) 156 , m_artificiallyInflatedBounds(false)
156 , m_boundsConstrainedByClipping(false) 157 , m_boundsConstrainedByClipping(false)
157 , m_isMainFrameRenderViewLayer(false) 158 , m_isMainFrameRenderViewLayer(false)
158 , m_requiresOwnBackingStore(true) 159 , m_requiresOwnBackingStore(true)
159 , m_canCompositeFilters(false) 160 , m_canCompositeFilters(false)
160 , m_backgroundLayerPaintsFixedRootBackground(false) 161 , m_backgroundLayerPaintsFixedRootBackground(false)
161 { 162 {
162 if (layer->isRootLayer()) { 163 if (layer->isRootLayer()) {
163 Frame& frame = toRenderView(renderer())->frameView()->frame(); 164 Frame& frame = toRenderView(renderer())->frameView()->frame();
164 Page* page = frame.page(); 165 Page* page = frame.page();
(...skipping 1502 matching lines...) Expand 10 before | Expand all | Expand 10 after
1667 1668
1668 #ifndef NDEBUG 1669 #ifndef NDEBUG
1669 void RenderLayerBacking::verifyNotPainting() 1670 void RenderLayerBacking::verifyNotPainting()
1670 { 1671 {
1671 ASSERT(!renderer()->frame()->page() || !renderer()->frame()->page()->isPaint ing()); 1672 ASSERT(!renderer()->frame()->page() || !renderer()->frame()->page()->isPaint ing());
1672 } 1673 }
1673 #endif 1674 #endif
1674 1675
1675 bool RenderLayerBacking::startAnimation(double timeOffset, const CSSAnimationDat a* anim, const KeyframeList& keyframes) 1676 bool RenderLayerBacking::startAnimation(double timeOffset, const CSSAnimationDat a* anim, const KeyframeList& keyframes)
1676 { 1677 {
1677 bool hasOpacity = keyframes.containsProperty(CSSPropertyOpacity);
1678 bool hasTransform = renderer()->isBox() && keyframes.containsProperty(CSSPro pertyWebkitTransform); 1678 bool hasTransform = renderer()->isBox() && keyframes.containsProperty(CSSPro pertyWebkitTransform);
1679 bool hasFilter = keyframes.containsProperty(CSSPropertyWebkitFilter); 1679 IntSize boxSize;
1680 1680 if (hasTransform)
1681 if (!hasOpacity && !hasTransform && !hasFilter) 1681 boxSize = toRenderBox(renderer())->pixelSnappedBorderBoxRect().size();
1682 WebAnimations animations(m_animationProvider->startAnimation(timeOffset, ani m, keyframes, hasTransform, boxSize));
1683 if (animations.isEmpty())
1682 return false; 1684 return false;
1683 1685
1684 KeyframeValueList transformVector(AnimatedPropertyWebkitTransform);
1685 KeyframeValueList opacityVector(AnimatedPropertyOpacity);
1686 KeyframeValueList filterVector(AnimatedPropertyWebkitFilter);
1687
1688 size_t numKeyframes = keyframes.size();
1689 for (size_t i = 0; i < numKeyframes; ++i) {
1690 const KeyframeValue& currentKeyframe = keyframes[i];
1691 const RenderStyle* keyframeStyle = currentKeyframe.style();
1692 double key = currentKeyframe.key();
1693
1694 if (!keyframeStyle)
1695 continue;
1696
1697 // Get timing function.
1698 RefPtr<TimingFunction> tf = currentKeyframe.timingFunction(keyframes.ani mationName());
1699
1700 bool isFirstOrLastKeyframe = key == 0 || key == 1;
1701 if ((hasTransform && isFirstOrLastKeyframe) || currentKeyframe.containsP roperty(CSSPropertyWebkitTransform))
1702 transformVector.insert(adoptPtr(new TransformAnimationValue(key, &(k eyframeStyle->transform()), tf)));
1703
1704 if ((hasOpacity && isFirstOrLastKeyframe) || currentKeyframe.containsPro perty(CSSPropertyOpacity))
1705 opacityVector.insert(adoptPtr(new FloatAnimationValue(key, keyframeS tyle->opacity(), tf)));
1706
1707 if ((hasFilter && isFirstOrLastKeyframe) || currentKeyframe.containsProp erty(CSSPropertyWebkitFilter))
1708 filterVector.insert(adoptPtr(new FilterAnimationValue(key, &(keyfram eStyle->filter()), tf)));
1709 }
1710
1711 bool didAnimate = false; 1686 bool didAnimate = false;
1712 1687 if (animations.m_transformAnimation && m_graphicsLayer->addAnimation(animati ons.m_transformAnimation.get()))
1713 if (hasTransform && m_graphicsLayer->addAnimation(transformVector, toRenderB ox(renderer())->pixelSnappedBorderBoxRect().size(), anim, keyframes.animationNam e(), timeOffset))
1714 didAnimate = true; 1688 didAnimate = true;
1715 1689 if (animations.m_opacityAnimation && m_graphicsLayer->addAnimation(animation s.m_opacityAnimation.get()))
1716 if (hasOpacity && m_graphicsLayer->addAnimation(opacityVector, IntSize(), an im, keyframes.animationName(), timeOffset))
1717 didAnimate = true; 1690 didAnimate = true;
1718 1691 if (animations.m_filterAnimation && m_graphicsLayer->addAnimation(animations .m_filterAnimation.get()))
1719 if (hasFilter && m_graphicsLayer->addAnimation(filterVector, IntSize(), anim , keyframes.animationName(), timeOffset))
1720 didAnimate = true; 1692 didAnimate = true;
1721 1693
1722 return didAnimate; 1694 return didAnimate;
1723 } 1695 }
1724 1696
1725 void RenderLayerBacking::animationPaused(double timeOffset, const String& animat ionName) 1697 void RenderLayerBacking::animationPaused(double timeOffset, const String& animat ionName)
1726 { 1698 {
1727 m_graphicsLayer->pauseAnimation(animationName, timeOffset); 1699 int animationId = m_animationProvider->getWebAnimationId(animationName);
1700 if (animationId)
1701 m_graphicsLayer->pauseAnimation(animationId, timeOffset);
1728 } 1702 }
1729 1703
1730 void RenderLayerBacking::animationFinished(const String& animationName) 1704 void RenderLayerBacking::animationFinished(const String& animationName)
1731 { 1705 {
1732 m_graphicsLayer->removeAnimation(animationName); 1706 int animationId = m_animationProvider->getWebAnimationId(animationName);
1707 if (animationId)
1708 m_graphicsLayer->removeAnimation(animationId);
1733 } 1709 }
1734 1710
1735 bool RenderLayerBacking::startTransition(double timeOffset, CSSPropertyID proper ty, const RenderStyle* fromStyle, const RenderStyle* toStyle) 1711 bool RenderLayerBacking::startTransition(double timeOffset, CSSPropertyID proper ty, const RenderStyle* fromStyle, const RenderStyle* toStyle)
1736 { 1712 {
1713 ASSERT(property != CSSPropertyInvalid);
1714 IntSize boxSize;
1715 if (property == CSSPropertyWebkitTransform && m_owningLayer->hasTransform()) {
1716 ASSERT(renderer()->isBox());
1717 boxSize = toRenderBox(renderer())->pixelSnappedBorderBoxRect().size();
1718 }
1719 float fromOpacity = 0;
1720 float toOpacity = 0;
1721 if (property == CSSPropertyOpacity) {
1722 fromOpacity = compositingOpacity(fromStyle->opacity());
1723 toOpacity = compositingOpacity(toStyle->opacity());
1724 }
1725 WebAnimations animations(m_animationProvider->startTransition(timeOffset, pr operty, fromStyle,
1726 toStyle, m_owningLayer->hasTransform(), m_owningLayer->hasFilter(), boxS ize, fromOpacity, toOpacity));
1737 bool didAnimate = false; 1727 bool didAnimate = false;
1738 1728 if (animations.m_transformAnimation && m_graphicsLayer->addAnimation(animati ons.m_transformAnimation.get())) {
1739 ASSERT(property != CSSPropertyInvalid); 1729 // To ensure that the correct transform is visible when the animation en ds, also set the final transform.
1740 1730 updateTransform(toStyle);
1741 if (property == CSSPropertyOpacity) { 1731 didAnimate = true;
1742 const CSSAnimationData* opacityAnim = toStyle->transitionForProperty(CSS PropertyOpacity);
1743 if (opacityAnim && !opacityAnim->isEmptyOrZeroDuration()) {
1744 KeyframeValueList opacityVector(AnimatedPropertyOpacity);
1745 opacityVector.insert(adoptPtr(new FloatAnimationValue(0, compositing Opacity(fromStyle->opacity()))));
1746 opacityVector.insert(adoptPtr(new FloatAnimationValue(1, compositing Opacity(toStyle->opacity()))));
1747 // The boxSize param is only used for transform animations (which ca n only run on RenderBoxes), so we pass an empty size here.
1748 if (m_graphicsLayer->addAnimation(opacityVector, IntSize(), opacityA nim, GraphicsLayer::animationNameForTransition(AnimatedPropertyOpacity), timeOff set)) {
1749 // To ensure that the correct opacity is visible when the animat ion ends, also set the final opacity.
1750 updateOpacity(toStyle);
1751 didAnimate = true;
1752 }
1753 }
1754 } 1732 }
1755 1733 if (animations.m_opacityAnimation && m_graphicsLayer->addAnimation(animation s.m_opacityAnimation.get())) {
1756 if (property == CSSPropertyWebkitTransform && m_owningLayer->hasTransform()) { 1734 // To ensure that the correct opacity is visible when the animation ends , also set the final opacity.
1757 const CSSAnimationData* transformAnim = toStyle->transitionForProperty(C SSPropertyWebkitTransform); 1735 updateOpacity(toStyle);
1758 if (transformAnim && !transformAnim->isEmptyOrZeroDuration()) { 1736 didAnimate = true;
1759 KeyframeValueList transformVector(AnimatedPropertyWebkitTransform);
1760 transformVector.insert(adoptPtr(new TransformAnimationValue(0, &from Style->transform())));
1761 transformVector.insert(adoptPtr(new TransformAnimationValue(1, &toSt yle->transform())));
1762 if (m_graphicsLayer->addAnimation(transformVector, toRenderBox(rende rer())->pixelSnappedBorderBoxRect().size(), transformAnim, GraphicsLayer::animat ionNameForTransition(AnimatedPropertyWebkitTransform), timeOffset)) {
1763 // To ensure that the correct transform is visible when the anim ation ends, also set the final transform.
1764 updateTransform(toStyle);
1765 didAnimate = true;
1766 }
1767 }
1768 } 1737 }
1769 1738 if (animations.m_filterAnimation && m_graphicsLayer->addAnimation(animations .m_filterAnimation.get())) {
1770 if (property == CSSPropertyWebkitFilter && m_owningLayer->hasFilter()) { 1739 // To ensure that the correct filter is visible when the animation ends, also set the final filter.
1771 const CSSAnimationData* filterAnim = toStyle->transitionForProperty(CSSP ropertyWebkitFilter); 1740 updateFilters(toStyle);
1772 if (filterAnim && !filterAnim->isEmptyOrZeroDuration()) { 1741 didAnimate = true;
1773 KeyframeValueList filterVector(AnimatedPropertyWebkitFilter);
1774 filterVector.insert(adoptPtr(new FilterAnimationValue(0, &fromStyle- >filter())));
1775 filterVector.insert(adoptPtr(new FilterAnimationValue(1, &toStyle->f ilter())));
1776 if (m_graphicsLayer->addAnimation(filterVector, IntSize(), filterAni m, GraphicsLayer::animationNameForTransition(AnimatedPropertyWebkitFilter), time Offset)) {
1777 // To ensure that the correct filter is visible when the animati on ends, also set the final filter.
1778 updateFilters(toStyle);
1779 didAnimate = true;
1780 }
1781 }
1782 } 1742 }
1783 1743
1784 return didAnimate; 1744 return didAnimate;
1785 } 1745 }
1786 1746
1787 void RenderLayerBacking::transitionPaused(double timeOffset, CSSPropertyID prope rty) 1747 void RenderLayerBacking::transitionPaused(double timeOffset, CSSPropertyID prope rty)
1788 { 1748 {
1789 AnimatedPropertyID animatedProperty = cssToGraphicsLayerProperty(property); 1749 int animationId = m_animationProvider->getWebAnimationId(property);
1790 if (animatedProperty != AnimatedPropertyInvalid) 1750 if (animationId)
1791 m_graphicsLayer->pauseAnimation(GraphicsLayer::animationNameForTransitio n(animatedProperty), timeOffset); 1751 m_graphicsLayer->pauseAnimation(animationId, timeOffset);
1792 } 1752 }
1793 1753
1794 void RenderLayerBacking::transitionFinished(CSSPropertyID property) 1754 void RenderLayerBacking::transitionFinished(CSSPropertyID property)
1795 { 1755 {
1796 AnimatedPropertyID animatedProperty = cssToGraphicsLayerProperty(property); 1756 int animationId = m_animationProvider->getWebAnimationId(property);
1797 if (animatedProperty != AnimatedPropertyInvalid) 1757 if (animationId)
1798 m_graphicsLayer->removeAnimation(GraphicsLayer::animationNameForTransiti on(animatedProperty)); 1758 m_graphicsLayer->removeAnimation(animationId);
1799 } 1759 }
1800 1760
1801 void RenderLayerBacking::notifyAnimationStarted(const GraphicsLayer*, double tim e) 1761 void RenderLayerBacking::notifyAnimationStarted(const GraphicsLayer*, double tim e)
1802 { 1762 {
1803 renderer()->animation()->notifyAnimationStarted(renderer(), time); 1763 renderer()->animation()->notifyAnimationStarted(renderer(), time);
1804 } 1764 }
1805 1765
1806 // This is used for the 'freeze' API, for testing only. 1766 // This is used for the 'freeze' API, for testing only.
1807 void RenderLayerBacking::suspendAnimations(double time) 1767 void RenderLayerBacking::suspendAnimations(double time)
1808 { 1768 {
1809 m_graphicsLayer->suspendAnimations(time); 1769 m_graphicsLayer->suspendAnimations(time);
1810 } 1770 }
1811 1771
1812 void RenderLayerBacking::resumeAnimations() 1772 void RenderLayerBacking::resumeAnimations()
1813 { 1773 {
1814 m_graphicsLayer->resumeAnimations(); 1774 m_graphicsLayer->resumeAnimations();
1815 } 1775 }
1816 1776
1817 IntRect RenderLayerBacking::compositedBounds() const 1777 IntRect RenderLayerBacking::compositedBounds() const
1818 { 1778 {
1819 return m_compositedBounds; 1779 return m_compositedBounds;
1820 } 1780 }
1821 1781
1822 void RenderLayerBacking::setCompositedBounds(const IntRect& bounds) 1782 void RenderLayerBacking::setCompositedBounds(const IntRect& bounds)
1823 { 1783 {
1824 m_compositedBounds = bounds; 1784 m_compositedBounds = bounds;
1825 } 1785 }
1826 1786
1827 CSSPropertyID RenderLayerBacking::graphicsLayerToCSSProperty(AnimatedPropertyID property)
1828 {
1829 CSSPropertyID cssProperty = CSSPropertyInvalid;
1830 switch (property) {
1831 case AnimatedPropertyWebkitTransform:
1832 cssProperty = CSSPropertyWebkitTransform;
1833 break;
1834 case AnimatedPropertyOpacity:
1835 cssProperty = CSSPropertyOpacity;
1836 break;
1837 case AnimatedPropertyBackgroundColor:
1838 cssProperty = CSSPropertyBackgroundColor;
1839 break;
1840 case AnimatedPropertyWebkitFilter:
1841 cssProperty = CSSPropertyWebkitFilter;
1842 break;
1843 case AnimatedPropertyInvalid:
1844 ASSERT_NOT_REACHED();
1845 }
1846 return cssProperty;
1847 }
1848
1849 AnimatedPropertyID RenderLayerBacking::cssToGraphicsLayerProperty(CSSPropertyID cssProperty)
1850 {
1851 switch (cssProperty) {
1852 case CSSPropertyWebkitTransform:
1853 return AnimatedPropertyWebkitTransform;
1854 case CSSPropertyOpacity:
1855 return AnimatedPropertyOpacity;
1856 case CSSPropertyBackgroundColor:
1857 return AnimatedPropertyBackgroundColor;
1858 case CSSPropertyWebkitFilter:
1859 return AnimatedPropertyWebkitFilter;
1860 default:
1861 // It's fine if we see other css properties here; they are just not accelerated.
1862 break;
1863 }
1864 return AnimatedPropertyInvalid;
1865 }
1866
1867 CompositingLayerType RenderLayerBacking::compositingLayerType() const 1787 CompositingLayerType RenderLayerBacking::compositingLayerType() const
1868 { 1788 {
1869 if (m_graphicsLayer->hasContentsLayer()) 1789 if (m_graphicsLayer->hasContentsLayer())
1870 return MediaCompositingLayer; 1790 return MediaCompositingLayer;
1871 1791
1872 if (m_graphicsLayer->drawsContent()) 1792 if (m_graphicsLayer->drawsContent())
1873 return NormalCompositingLayer; 1793 return NormalCompositingLayer;
1874 1794
1875 return ContainerCompositingLayer; 1795 return ContainerCompositingLayer;
1876 } 1796 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1929 } else if (graphicsLayer == m_scrollingContentsLayer.get()) { 1849 } else if (graphicsLayer == m_scrollingContentsLayer.get()) {
1930 name = "Scrolling Contents Layer"; 1850 name = "Scrolling Contents Layer";
1931 } else { 1851 } else {
1932 ASSERT_NOT_REACHED(); 1852 ASSERT_NOT_REACHED();
1933 } 1853 }
1934 1854
1935 return name; 1855 return name;
1936 } 1856 }
1937 1857
1938 } // namespace WebCore 1858 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698