1/* 2 * Copyright (C) 2011 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 23 * THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26#import "config.h" 27#import "TiledCoreAnimationDrawingAreaProxy.h" 28 29#if ENABLE(THREADED_SCROLLING) 30 31#import "ColorSpaceData.h" 32#import "DrawingAreaMessages.h" 33#import "DrawingAreaProxyMessages.h" 34#import "LayerTreeContext.h" 35#import "WebPageProxy.h" 36#import "WebProcessProxy.h" 37 38using namespace WebCore; 39 40namespace WebKit { 41 42PassOwnPtr<TiledCoreAnimationDrawingAreaProxy> TiledCoreAnimationDrawingAreaProxy::create(WebPageProxy* webPageProxy) 43{ 44 return adoptPtr(new TiledCoreAnimationDrawingAreaProxy(webPageProxy)); 45} 46 47TiledCoreAnimationDrawingAreaProxy::TiledCoreAnimationDrawingAreaProxy(WebPageProxy* webPageProxy) 48 : DrawingAreaProxy(DrawingAreaTypeTiledCoreAnimation, webPageProxy) 49 , m_isWaitingForDidUpdateGeometry(false) 50{ 51} 52 53TiledCoreAnimationDrawingAreaProxy::~TiledCoreAnimationDrawingAreaProxy() 54{ 55} 56 57void TiledCoreAnimationDrawingAreaProxy::deviceScaleFactorDidChange() 58{ 59 m_webPageProxy->process()->send(Messages::DrawingArea::SetDeviceScaleFactor(m_webPageProxy->deviceScaleFactor()), m_webPageProxy->pageID()); 60} 61 62void TiledCoreAnimationDrawingAreaProxy::visibilityDidChange() 63{ 64 if (!m_webPageProxy->isViewVisible()) 65 m_webPageProxy->process()->send(Messages::DrawingArea::SuspendPainting(), m_webPageProxy->pageID()); 66 else 67 m_webPageProxy->process()->send(Messages::DrawingArea::ResumePainting(), m_webPageProxy->pageID()); 68} 69 70void TiledCoreAnimationDrawingAreaProxy::layerHostingModeDidChange() 71{ 72 m_webPageProxy->process()->send(Messages::DrawingArea::SetLayerHostingMode(m_webPageProxy->layerHostingMode()), m_webPageProxy->pageID()); 73} 74 75void TiledCoreAnimationDrawingAreaProxy::sizeDidChange() 76{ 77 if (!m_webPageProxy->isValid()) 78 return; 79 80 // We only want one UpdateGeometry message in flight at once, so if we've already sent one but 81 // haven't yet received the reply we'll just return early here. 82 if (m_isWaitingForDidUpdateGeometry) 83 return; 84 85 sendUpdateGeometry(); 86} 87 88void TiledCoreAnimationDrawingAreaProxy::waitForPossibleGeometryUpdate(double timeout) 89{ 90 if (!m_isWaitingForDidUpdateGeometry) 91 return; 92 93 if (m_webPageProxy->process()->isLaunching()) 94 return; 95 96 m_webPageProxy->process()->connection()->waitForAndDispatchImmediately<Messages::DrawingAreaProxy::DidUpdateGeometry>(m_webPageProxy->pageID(), timeout); 97} 98 99void TiledCoreAnimationDrawingAreaProxy::colorSpaceDidChange() 100{ 101 m_webPageProxy->process()->send(Messages::DrawingArea::SetColorSpace(m_webPageProxy->colorSpace()), m_webPageProxy->pageID()); 102} 103 104void TiledCoreAnimationDrawingAreaProxy::minimumLayoutSizeDidChange() 105{ 106 if (!m_webPageProxy->isValid()) 107 return; 108 109 // We only want one UpdateGeometry message in flight at once, so if we've already sent one but 110 // haven't yet received the reply we'll just return early here. 111 if (m_isWaitingForDidUpdateGeometry) 112 return; 113 114 sendUpdateGeometry(); 115} 116 117void TiledCoreAnimationDrawingAreaProxy::enterAcceleratedCompositingMode(uint64_t backingStoreStateID, const LayerTreeContext& layerTreeContext) 118{ 119 m_webPageProxy->enterAcceleratedCompositingMode(layerTreeContext); 120} 121 122void TiledCoreAnimationDrawingAreaProxy::exitAcceleratedCompositingMode(uint64_t backingStoreStateID, const UpdateInfo&) 123{ 124 // This should never be called. 125 ASSERT_NOT_REACHED(); 126} 127 128void TiledCoreAnimationDrawingAreaProxy::updateAcceleratedCompositingMode(uint64_t backingStoreStateID, const LayerTreeContext& layerTreeContext) 129{ 130 m_webPageProxy->updateAcceleratedCompositingMode(layerTreeContext); 131} 132 133void TiledCoreAnimationDrawingAreaProxy::didUpdateGeometry() 134{ 135 ASSERT(m_isWaitingForDidUpdateGeometry); 136 137 m_isWaitingForDidUpdateGeometry = false; 138 139 IntSize minimumLayoutSize = m_webPageProxy->minimumLayoutSize(); 140 141 // If the WKView was resized while we were waiting for a DidUpdateGeometry reply from the web process, 142 // we need to resend the new size here. 143 if (m_lastSentSize != m_size || m_lastSentLayerPosition != m_layerPosition || m_lastSentMinimumLayoutSize != minimumLayoutSize) 144 sendUpdateGeometry(); 145} 146 147void TiledCoreAnimationDrawingAreaProxy::intrinsicContentSizeDidChange(const IntSize& newIntrinsicContentSize) 148{ 149 if (m_webPageProxy->minimumLayoutSize().width() > 0) 150 m_webPageProxy->intrinsicContentSizeDidChange(newIntrinsicContentSize); 151} 152 153void TiledCoreAnimationDrawingAreaProxy::sendUpdateGeometry() 154{ 155 ASSERT(!m_isWaitingForDidUpdateGeometry); 156 157 m_lastSentMinimumLayoutSize = m_webPageProxy->minimumLayoutSize(); 158 m_lastSentSize = m_size; 159 m_lastSentLayerPosition = m_layerPosition; 160 m_webPageProxy->process()->send(Messages::DrawingArea::UpdateGeometry(m_size, m_layerPosition), m_webPageProxy->pageID()); 161 m_isWaitingForDidUpdateGeometry = true; 162} 163 164} // namespace WebKit 165 166#endif // ENABLE(THREADED_SCROLLING) 167