2 * Copyright (C) 2010, 2011 Nokia Corporation and/or its subsidiary(-ies)
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #include "TiledDrawingArea.h"
29 #if ENABLE(TILED_BACKING_STORE)
31 #include "DrawingAreaProxyMessages.h"
32 #include "MessageID.h"
33 #include "UpdateInfo.h"
34 #include "WebCoreArgumentCoders.h"
36 #include "WebProcess.h"
38 using namespace WebCore;
42 TiledDrawingArea::TiledDrawingArea(WebPage* webPage)
43 : DrawingArea(DrawingAreaTypeTiled, webPage)
45 , m_isWaitingForUIProcess(false)
46 , m_didSendTileUpdate(false)
47 , m_mainBackingStore(adoptPtr(new TiledBackingStore(this, TiledBackingStoreRemoteTileBackend::create(this))))
51 TiledDrawingArea::~TiledDrawingArea()
55 void TiledDrawingArea::scroll(const IntRect& scrollRect, const IntSize& scrollDelta)
57 // FIXME: Do something much smarter.
58 setNeedsDisplay(scrollRect);
61 void TiledDrawingArea::setNeedsDisplay(const IntRect& rect)
63 m_mainBackingStore->invalidate(rect);
66 void TiledDrawingArea::setSize(const IntSize& viewSize)
69 ASSERT_ARG(viewSize, !viewSize.isEmpty());
71 m_webPage->setSize(viewSize);
74 void TiledDrawingArea::setVisibleContentRectAndScale(const WebCore::IntRect& visibleContentsRect, float scale)
76 m_visibleContentRect = visibleContentsRect;
78 if (scale != m_mainBackingStore->contentsScale()) {
79 // Keep the tiles for the previous scale until enough content is available to be shown on the screen for the new scale.
80 // If we already have a previous set of tiles it means that two scale changed happened successively.
81 // In that case, make sure that our current main tiles have more content to show than the "previous previous"
82 // within the visible rect before replacing it.
83 if (!m_previousBackingStore || m_mainBackingStore->coverageRatio(m_visibleContentRect) > m_previousBackingStore->coverageRatio(m_visibleContentRect))
84 m_previousBackingStore = m_mainBackingStore.release();
86 m_mainBackingStore = adoptPtr(new TiledBackingStore(this, TiledBackingStoreRemoteTileBackend::create(this)));
87 m_mainBackingStore->setContentsScale(scale);
89 m_mainBackingStore->adjustVisibleRect();
92 void TiledDrawingArea::setVisibleContentRectTrajectoryVector(const WebCore::FloatPoint& trajectoryVector)
94 m_mainBackingStore->setVisibleRectTrajectoryVector(trajectoryVector);
97 void TiledDrawingArea::renderNextFrame()
99 m_isWaitingForUIProcess = false;
100 m_mainBackingStore->updateTileBuffers();
103 void TiledDrawingArea::suspendPainting()
105 ASSERT(!m_suspended);
110 void TiledDrawingArea::resumePainting()
115 m_mainBackingStore->updateTileBuffers();
118 void TiledDrawingArea::tiledBackingStorePaintBegin()
120 m_webPage->layoutIfNeeded();
123 void TiledDrawingArea::tiledBackingStorePaint(GraphicsContext* graphicsContext, const IntRect& contentRect)
125 m_webPage->drawRect(*graphicsContext, contentRect);
128 void TiledDrawingArea::tiledBackingStorePaintEnd(const Vector<IntRect>& paintedArea)
130 if (m_didSendTileUpdate) {
131 // Since we know that all tile updates following a page invalidate will all be rendered
132 // in one paint pass for all the tiles, we can send the swap tile message here.
133 m_webPage->send(Messages::DrawingAreaProxy::DidRenderFrame());
134 m_isWaitingForUIProcess = true;
135 m_didSendTileUpdate = false;
137 // Make sure that we destroy the previous backing store and remove its tiles only after DidRenderFrame
138 // was sent to swap recently created tiles' buffer. Else a frame could be rendered after the previous
139 // tiles were removed and before the new tile have their first back buffer swapped.
140 if (m_previousBackingStore && m_mainBackingStore->coverageRatio(m_visibleContentRect) >= 1.0f)
141 m_previousBackingStore.clear();
145 bool TiledDrawingArea::tiledBackingStoreUpdatesAllowed() const
147 return !m_suspended && !m_isWaitingForUIProcess;
150 IntRect TiledDrawingArea::tiledBackingStoreContentsRect()
152 return IntRect(IntPoint::zero(), m_webPage->size());
155 IntRect TiledDrawingArea::tiledBackingStoreVisibleRect()
157 return m_visibleContentRect;
160 Color TiledDrawingArea::tiledBackingStoreBackgroundColor() const
162 return Color::transparent;
165 void TiledDrawingArea::createTile(int tileID, const UpdateInfo& updateInfo)
167 m_webPage->send(Messages::DrawingAreaProxy::CreateTile(tileID, updateInfo));
168 m_didSendTileUpdate = true;
170 void TiledDrawingArea::updateTile(int tileID, const UpdateInfo& updateInfo)
172 m_webPage->send(Messages::DrawingAreaProxy::UpdateTile(tileID, updateInfo));
173 m_didSendTileUpdate = true;
175 void TiledDrawingArea::removeTile(int tileID)
177 m_webPage->send(Messages::DrawingAreaProxy::RemoveTile(tileID));
180 } // namespace WebKit
182 #endif // TILED_BACKING_STORE