2 * Copyright (C) 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 "CoordinatedTile.h"
29 #if USE(TILED_BACKING_STORE)
31 #include "GraphicsContext.h"
32 #include "ImageBuffer.h"
33 #include "SurfaceUpdateInfo.h"
34 #include "TiledBackingStoreClient.h"
38 static const uint32_t InvalidCoordinatedTileID = 0;
40 CoordinatedTile::CoordinatedTile(CoordinatedTileClient* client, TiledBackingStore* tiledBackingStore, const Coordinate& tileCoordinate)
42 , m_tiledBackingStore(tiledBackingStore)
43 , m_coordinate(tileCoordinate)
44 , m_rect(tiledBackingStore->tileRectForCoordinate(tileCoordinate))
45 , m_ID(InvalidCoordinatedTileID)
50 CoordinatedTile::~CoordinatedTile()
52 if (m_ID != InvalidCoordinatedTileID)
53 m_client->removeTile(m_ID);
56 bool CoordinatedTile::isDirty() const
58 return !m_dirtyRect.isEmpty();
61 void CoordinatedTile::invalidate(const IntRect& dirtyRect)
63 IntRect tileDirtyRect = intersection(dirtyRect, m_rect);
64 if (tileDirtyRect.isEmpty())
67 m_dirtyRect.unite(tileDirtyRect);
70 Vector<IntRect> CoordinatedTile::updateBackBuffer()
73 return Vector<IntRect>();
75 SurfaceUpdateInfo updateInfo;
77 if (!m_client->paintToSurface(m_dirtyRect.size(), updateInfo.atlasID, updateInfo.surfaceOffset, this))
78 return Vector<IntRect>();
80 updateInfo.updateRect = m_dirtyRect;
81 updateInfo.updateRect.move(-m_rect.x(), -m_rect.y());
82 updateInfo.scaleFactor = m_tiledBackingStore->contentsScale();
84 static uint32_t id = 1;
85 if (m_ID == InvalidCoordinatedTileID) {
87 // We may get an invalid ID due to wrap-around on overflow.
88 if (m_ID == InvalidCoordinatedTileID)
90 m_client->createTile(m_ID, updateInfo, m_rect);
92 m_client->updateTile(m_ID, updateInfo, m_rect);
94 Vector<IntRect> updatedRects;
95 updatedRects.append(m_dirtyRect);
96 m_dirtyRect = IntRect();
100 void CoordinatedTile::paintToSurfaceContext(GraphicsContext* context)
102 context->translate(-m_dirtyRect.x(), -m_dirtyRect.y());
103 context->scale(FloatSize(m_tiledBackingStore->contentsScale(), m_tiledBackingStore->contentsScale()));
104 m_tiledBackingStore->client()->tiledBackingStorePaint(context, m_tiledBackingStore->mapToContents(m_dirtyRect));
107 void CoordinatedTile::swapBackBufferToFront()
109 // Handled by tiledBackingStorePaintEnd.
112 bool CoordinatedTile::isReadyToPaint() const
114 return m_ID != InvalidCoordinatedTileID;
117 void CoordinatedTile::paint(GraphicsContext*, const IntRect&)
119 ASSERT_NOT_REACHED();
122 void CoordinatedTile::resize(const IntSize& newSize)
124 m_rect = IntRect(m_rect.location(), newSize);
125 m_dirtyRect = m_rect;
128 CoordinatedTileBackend::CoordinatedTileBackend(CoordinatedTileClient* client)
133 PassRefPtr<Tile> CoordinatedTileBackend::createTile(TiledBackingStore* tiledBackingStore, const Tile::Coordinate& tileCoordinate)
135 return CoordinatedTile::create(m_client, tiledBackingStore, tileCoordinate);
138 void CoordinatedTileBackend::paintCheckerPattern(GraphicsContext*, const FloatRect&)
142 } // namespace WebCore
144 #endif // USE(TILED_BACKING_STORE)