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

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: Fix typo 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 1578 matching lines...) Expand 10 before | Expand all | Expand 10 after
1743 1744
1744 #ifndef NDEBUG 1745 #ifndef NDEBUG
1745 void RenderLayerBacking::verifyNotPainting() 1746 void RenderLayerBacking::verifyNotPainting()
1746 { 1747 {
1747 ASSERT(!renderer()->frame()->page() || !renderer()->frame()->page()->isPaint ing()); 1748 ASSERT(!renderer()->frame()->page() || !renderer()->frame()->page()->isPaint ing());
1748 } 1749 }
1749 #endif 1750 #endif
1750 1751
1751 bool RenderLayerBacking::startAnimation(double timeOffset, const CSSAnimationDat a* anim, const KeyframeList& keyframes) 1752 bool RenderLayerBacking::startAnimation(double timeOffset, const CSSAnimationDat a* anim, const KeyframeList& keyframes)
1752 { 1753 {
1753 bool hasOpacity = keyframes.containsProperty(CSSPropertyOpacity);
1754 bool hasTransform = renderer()->isBox() && keyframes.containsProperty(CSSPro pertyWebkitTransform); 1754 bool hasTransform = renderer()->isBox() && keyframes.containsProperty(CSSPro pertyWebkitTransform);
1755 bool hasFilter = keyframes.containsProperty(CSSPropertyWebkitFilter); 1755 IntSize boxSize;
1756 1756 if (hasTransform)
1757 if (!hasOpacity && !hasTransform && !hasFilter) 1757 boxSize = toRenderBox(renderer())->pixelSnappedBorderBoxRect().size();
1758 WebAnimations animations(m_animationProvider->startAnimation(timeOffset, ani m, keyframes, hasTransform, boxSize));
1759 if (animations.isEmpty())
1758 return false; 1760 return false;
1759 1761
1760 KeyframeValueList transformVector(AnimatedPropertyWebkitTransform);
1761 KeyframeValueList opacityVector(AnimatedPropertyOpacity);
1762 KeyframeValueList filterVector(AnimatedPropertyWebkitFilter);
1763
1764 size_t numKeyframes = keyframes.size();
1765 for (size_t i = 0; i < numKeyframes; ++i) {
1766 const KeyframeValue& currentKeyframe = keyframes[i];
1767 const RenderStyle* keyframeStyle = currentKeyframe.style();
1768 double key = currentKeyframe.key();
1769
1770 if (!keyframeStyle)
1771 continue;
1772
1773 // Get timing function.
1774 RefPtr<TimingFunction> tf = KeyframeValue::timingFunction(currentKeyfram e.style(), keyframes.animationName());
1775
1776 bool isFirstOrLastKeyframe = key == 0 || key == 1;
1777 if ((hasTransform && isFirstOrLastKeyframe) || currentKeyframe.containsP roperty(CSSPropertyWebkitTransform))
1778 transformVector.insert(adoptPtr(new TransformAnimationValue(key, &(k eyframeStyle->transform()), tf)));
1779
1780 if ((hasOpacity && isFirstOrLastKeyframe) || currentKeyframe.containsPro perty(CSSPropertyOpacity))
1781 opacityVector.insert(adoptPtr(new FloatAnimationValue(key, keyframeS tyle->opacity(), tf)));
1782
1783 if ((hasFilter && isFirstOrLastKeyframe) || currentKeyframe.containsProp erty(CSSPropertyWebkitFilter))
1784 filterVector.insert(adoptPtr(new FilterAnimationValue(key, &(keyfram eStyle->filter()), tf)));
1785 }
1786
1787 bool didAnimate = false; 1762 bool didAnimate = false;
1788 1763 if (animations.m_transformAnimation && m_graphicsLayer->addAnimation(animati ons.m_transformAnimation.get()))
1789 if (hasTransform && m_graphicsLayer->addAnimation(transformVector, toRenderB ox(renderer())->pixelSnappedBorderBoxRect().size(), anim, keyframes.animationNam e(), timeOffset))
1790 didAnimate = true; 1764 didAnimate = true;
1791 1765 if (animations.m_opacityAnimation && m_graphicsLayer->addAnimation(animation s.m_opacityAnimation.get()))
1792 if (hasOpacity && m_graphicsLayer->addAnimation(opacityVector, IntSize(), an im, keyframes.animationName(), timeOffset))
1793 didAnimate = true; 1766 didAnimate = true;
1794 1767 if (animations.m_filterAnimation && m_graphicsLayer->addAnimation(animations .m_filterAnimation.get()))
1795 if (hasFilter && m_graphicsLayer->addAnimation(filterVector, IntSize(), anim , keyframes.animationName(), timeOffset))
1796 didAnimate = true; 1768 didAnimate = true;
1797 1769
1798 return didAnimate; 1770 return didAnimate;
1799 } 1771 }
1800 1772
1801 void RenderLayerBacking::animationPaused(double timeOffset, const String& animat ionName) 1773 void RenderLayerBacking::animationPaused(double timeOffset, const String& animat ionName)
1802 { 1774 {
1803 m_graphicsLayer->pauseAnimation(animationName, timeOffset); 1775 int animationId = m_animationProvider->getWebAnimationId(animationName);
1776 if (animationId)
1777 m_graphicsLayer->pauseAnimation(animationId, timeOffset);
1804 } 1778 }
1805 1779
1806 void RenderLayerBacking::animationFinished(const String& animationName) 1780 void RenderLayerBacking::animationFinished(const String& animationName)
1807 { 1781 {
1808 m_graphicsLayer->removeAnimation(animationName); 1782 int animationId = m_animationProvider->getWebAnimationId(animationName);
1783 if (animationId)
1784 m_graphicsLayer->removeAnimation(animationId);
1809 } 1785 }
1810 1786
1811 bool RenderLayerBacking::startTransition(double timeOffset, CSSPropertyID proper ty, const RenderStyle* fromStyle, const RenderStyle* toStyle) 1787 bool RenderLayerBacking::startTransition(double timeOffset, CSSPropertyID proper ty, const RenderStyle* fromStyle, const RenderStyle* toStyle)
1812 { 1788 {
1789 ASSERT(property != CSSPropertyInvalid);
1790 IntSize boxSize;
1791 if (property == CSSPropertyWebkitTransform && m_owningLayer->hasTransform()) {
1792 ASSERT(renderer()->isBox());
1793 boxSize = toRenderBox(renderer())->pixelSnappedBorderBoxRect().size();
1794 }
1795 float fromOpacity = 0;
1796 float toOpacity = 0;
1797 if (property == CSSPropertyOpacity) {
1798 fromOpacity = compositingOpacity(fromStyle->opacity());
1799 toOpacity = compositingOpacity(toStyle->opacity());
1800 }
1801 WebAnimations animations(m_animationProvider->startTransition(timeOffset, pr operty, fromStyle,
1802 toStyle, m_owningLayer->hasTransform(), m_owningLayer->hasFilter(), boxS ize, fromOpacity, toOpacity));
1813 bool didAnimate = false; 1803 bool didAnimate = false;
1814 1804 if (animations.m_transformAnimation && m_graphicsLayer->addAnimation(animati ons.m_transformAnimation.get())) {
1815 ASSERT(property != CSSPropertyInvalid); 1805 // To ensure that the correct transform is visible when the animation en ds, also set the final transform.
1816 1806 updateTransform(toStyle);
1817 if (property == CSSPropertyOpacity) { 1807 didAnimate = true;
1818 const CSSAnimationData* opacityAnim = toStyle->transitionForProperty(CSS PropertyOpacity);
1819 if (opacityAnim && !opacityAnim->isEmptyOrZeroDuration()) {
1820 KeyframeValueList opacityVector(AnimatedPropertyOpacity);
1821 opacityVector.insert(adoptPtr(new FloatAnimationValue(0, compositing Opacity(fromStyle->opacity()))));
1822 opacityVector.insert(adoptPtr(new FloatAnimationValue(1, compositing Opacity(toStyle->opacity()))));
1823 // The boxSize param is only used for transform animations (which ca n only run on RenderBoxes), so we pass an empty size here.
1824 if (m_graphicsLayer->addAnimation(opacityVector, IntSize(), opacityA nim, GraphicsLayer::animationNameForTransition(AnimatedPropertyOpacity), timeOff set)) {
1825 // To ensure that the correct opacity is visible when the animat ion ends, also set the final opacity.
1826 updateOpacity(toStyle);
1827 didAnimate = true;
1828 }
1829 }
1830 } 1808 }
1831 1809 if (animations.m_opacityAnimation && m_graphicsLayer->addAnimation(animation s.m_opacityAnimation.get())) {
1832 if (property == CSSPropertyWebkitTransform && m_owningLayer->hasTransform()) { 1810 // To ensure that the correct opacity is visible when the animation ends , also set the final opacity.
1833 const CSSAnimationData* transformAnim = toStyle->transitionForProperty(C SSPropertyWebkitTransform); 1811 updateOpacity(toStyle);
1834 if (transformAnim && !transformAnim->isEmptyOrZeroDuration()) { 1812 didAnimate = true;
1835 KeyframeValueList transformVector(AnimatedPropertyWebkitTransform);
1836 transformVector.insert(adoptPtr(new TransformAnimationValue(0, &from Style->transform())));
1837 transformVector.insert(adoptPtr(new TransformAnimationValue(1, &toSt yle->transform())));
1838 if (m_graphicsLayer->addAnimation(transformVector, toRenderBox(rende rer())->pixelSnappedBorderBoxRect().size(), transformAnim, GraphicsLayer::animat ionNameForTransition(AnimatedPropertyWebkitTransform), timeOffset)) {
1839 // To ensure that the correct transform is visible when the anim ation ends, also set the final transform.
1840 updateTransform(toStyle);
1841 didAnimate = true;
1842 }
1843 }
1844 } 1813 }
1845 1814 if (animations.m_filterAnimation && m_graphicsLayer->addAnimation(animations .m_filterAnimation.get())) {
1846 if (property == CSSPropertyWebkitFilter && m_owningLayer->hasFilter()) { 1815 // To ensure that the correct filter is visible when the animation ends, also set the final filter.
1847 const CSSAnimationData* filterAnim = toStyle->transitionForProperty(CSSP ropertyWebkitFilter); 1816 updateFilters(toStyle);
1848 if (filterAnim && !filterAnim->isEmptyOrZeroDuration()) { 1817 didAnimate = true;
1849 KeyframeValueList filterVector(AnimatedPropertyWebkitFilter);
1850 filterVector.insert(adoptPtr(new FilterAnimationValue(0, &fromStyle- >filter())));
1851 filterVector.insert(adoptPtr(new FilterAnimationValue(1, &toStyle->f ilter())));
1852 if (m_graphicsLayer->addAnimation(filterVector, IntSize(), filterAni m, GraphicsLayer::animationNameForTransition(AnimatedPropertyWebkitFilter), time Offset)) {
1853 // To ensure that the correct filter is visible when the animati on ends, also set the final filter.
1854 updateFilters(toStyle);
1855 didAnimate = true;
1856 }
1857 }
1858 } 1818 }
1859 1819
1860 return didAnimate; 1820 return didAnimate;
1861 } 1821 }
1862 1822
1863 void RenderLayerBacking::transitionPaused(double timeOffset, CSSPropertyID prope rty) 1823 void RenderLayerBacking::transitionPaused(double timeOffset, CSSPropertyID prope rty)
1864 { 1824 {
1865 AnimatedPropertyID animatedProperty = cssToGraphicsLayerProperty(property); 1825 int animationId = m_animationProvider->getWebAnimationId(property);
1866 if (animatedProperty != AnimatedPropertyInvalid) 1826 if (animationId)
1867 m_graphicsLayer->pauseAnimation(GraphicsLayer::animationNameForTransitio n(animatedProperty), timeOffset); 1827 m_graphicsLayer->pauseAnimation(animationId, timeOffset);
1868 } 1828 }
1869 1829
1870 void RenderLayerBacking::transitionFinished(CSSPropertyID property) 1830 void RenderLayerBacking::transitionFinished(CSSPropertyID property)
1871 { 1831 {
1872 AnimatedPropertyID animatedProperty = cssToGraphicsLayerProperty(property); 1832 int animationId = m_animationProvider->getWebAnimationId(property);
1873 if (animatedProperty != AnimatedPropertyInvalid) 1833 if (animationId)
1874 m_graphicsLayer->removeAnimation(GraphicsLayer::animationNameForTransiti on(animatedProperty)); 1834 m_graphicsLayer->removeAnimation(animationId);
1875 } 1835 }
1876 1836
1877 void RenderLayerBacking::notifyAnimationStarted(const GraphicsLayer*, double tim e) 1837 void RenderLayerBacking::notifyAnimationStarted(const GraphicsLayer*, double tim e)
1878 { 1838 {
1879 renderer()->animation()->notifyAnimationStarted(renderer(), time); 1839 renderer()->animation()->notifyAnimationStarted(renderer(), time);
1880 } 1840 }
1881 1841
1882 // This is used for the 'freeze' API, for testing only. 1842 // This is used for the 'freeze' API, for testing only.
1883 void RenderLayerBacking::suspendAnimations(double time) 1843 void RenderLayerBacking::suspendAnimations(double time)
1884 { 1844 {
1885 m_graphicsLayer->suspendAnimations(time); 1845 m_graphicsLayer->suspendAnimations(time);
1886 } 1846 }
1887 1847
1888 void RenderLayerBacking::resumeAnimations() 1848 void RenderLayerBacking::resumeAnimations()
1889 { 1849 {
1890 m_graphicsLayer->resumeAnimations(); 1850 m_graphicsLayer->resumeAnimations();
1891 } 1851 }
1892 1852
1893 IntRect RenderLayerBacking::compositedBounds() const 1853 IntRect RenderLayerBacking::compositedBounds() const
1894 { 1854 {
1895 return m_compositedBounds; 1855 return m_compositedBounds;
1896 } 1856 }
1897 1857
1898 void RenderLayerBacking::setCompositedBounds(const IntRect& bounds) 1858 void RenderLayerBacking::setCompositedBounds(const IntRect& bounds)
1899 { 1859 {
1900 m_compositedBounds = bounds; 1860 m_compositedBounds = bounds;
1901 } 1861 }
1902 1862
1903 CSSPropertyID RenderLayerBacking::graphicsLayerToCSSProperty(AnimatedPropertyID property)
1904 {
1905 CSSPropertyID cssProperty = CSSPropertyInvalid;
1906 switch (property) {
1907 case AnimatedPropertyWebkitTransform:
1908 cssProperty = CSSPropertyWebkitTransform;
1909 break;
1910 case AnimatedPropertyOpacity:
1911 cssProperty = CSSPropertyOpacity;
1912 break;
1913 case AnimatedPropertyBackgroundColor:
1914 cssProperty = CSSPropertyBackgroundColor;
1915 break;
1916 case AnimatedPropertyWebkitFilter:
1917 cssProperty = CSSPropertyWebkitFilter;
1918 break;
1919 case AnimatedPropertyInvalid:
1920 ASSERT_NOT_REACHED();
1921 }
1922 return cssProperty;
1923 }
1924
1925 AnimatedPropertyID RenderLayerBacking::cssToGraphicsLayerProperty(CSSPropertyID cssProperty)
1926 {
1927 switch (cssProperty) {
1928 case CSSPropertyWebkitTransform:
1929 return AnimatedPropertyWebkitTransform;
1930 case CSSPropertyOpacity:
1931 return AnimatedPropertyOpacity;
1932 case CSSPropertyBackgroundColor:
1933 return AnimatedPropertyBackgroundColor;
1934 case CSSPropertyWebkitFilter:
1935 return AnimatedPropertyWebkitFilter;
1936 default:
1937 // It's fine if we see other css properties here; they are just not accelerated.
1938 break;
1939 }
1940 return AnimatedPropertyInvalid;
1941 }
1942
1943 CompositingLayerType RenderLayerBacking::compositingLayerType() const 1863 CompositingLayerType RenderLayerBacking::compositingLayerType() const
1944 { 1864 {
1945 if (m_graphicsLayer->hasContentsLayer()) 1865 if (m_graphicsLayer->hasContentsLayer())
1946 return MediaCompositingLayer; 1866 return MediaCompositingLayer;
1947 1867
1948 if (m_graphicsLayer->drawsContent()) 1868 if (m_graphicsLayer->drawsContent())
1949 return NormalCompositingLayer; 1869 return NormalCompositingLayer;
1950 1870
1951 return ContainerCompositingLayer; 1871 return ContainerCompositingLayer;
1952 } 1872 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
2007 } else if (graphicsLayer == m_scrollingContentsLayer.get()) { 1927 } else if (graphicsLayer == m_scrollingContentsLayer.get()) {
2008 name = "Scrolling Contents Layer"; 1928 name = "Scrolling Contents Layer";
2009 } else { 1929 } else {
2010 ASSERT_NOT_REACHED(); 1930 ASSERT_NOT_REACHED();
2011 } 1931 }
2012 1932
2013 return name; 1933 return name;
2014 } 1934 }
2015 1935
2016 } // namespace WebCore 1936 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/rendering/RenderLayerBacking.h ('k') | Source/core/rendering/animation/WebAnimationProvider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698