2 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #if USE(ACCELERATED_COMPOSITING)
31 #include "cc/CCLayerTilingData.h"
37 PassOwnPtr<CCLayerTilingData> CCLayerTilingData::create(const IntSize& tileSize, BorderTexelOption border)
39 return adoptPtr(new CCLayerTilingData(tileSize, border));
42 CCLayerTilingData::CCLayerTilingData(const IntSize& tileSize, BorderTexelOption border)
43 : m_tilingData(max(tileSize.width(), tileSize.height()), 0, 0, border == HasBorderTexels)
45 setTileSize(tileSize);
48 void CCLayerTilingData::setTileSize(const IntSize& size)
50 if (m_tileSize == size)
56 m_tilingData.setMaxTextureSize(max(size.width(), size.height()));
59 const CCLayerTilingData& CCLayerTilingData::operator=(const CCLayerTilingData& tiler)
61 m_tileSize = tiler.m_tileSize;
62 m_layerPosition = tiler.m_layerPosition;
63 m_tilingData = tiler.m_tilingData;
68 void CCLayerTilingData::addTile(PassRefPtr<Tile> tile, int i, int j)
70 ASSERT(!tileAt(i, j));
72 m_tiles.add(make_pair(i, j), tile);
75 PassRefPtr<CCLayerTilingData::Tile> CCLayerTilingData::takeTile(int i, int j)
77 return m_tiles.take(make_pair(i, j));
80 CCLayerTilingData::Tile* CCLayerTilingData::tileAt(int i, int j) const
82 Tile* tile = m_tiles.get(make_pair(i, j)).get();
83 ASSERT(!tile || tile->refCount() == 1);
87 void CCLayerTilingData::reset()
90 m_tilingData.setTotalSize(0, 0);
93 void CCLayerTilingData::contentRectToTileIndices(const IntRect& contentRect, int& left, int& top, int& right, int& bottom) const
95 const IntRect layerRect = contentRectToLayerRect(contentRect);
97 left = m_tilingData.tileXIndexFromSrcCoord(layerRect.x());
98 top = m_tilingData.tileYIndexFromSrcCoord(layerRect.y());
99 right = m_tilingData.tileXIndexFromSrcCoord(layerRect.maxX() - 1);
100 bottom = m_tilingData.tileYIndexFromSrcCoord(layerRect.maxY() - 1);
103 IntRect CCLayerTilingData::contentRectToLayerRect(const IntRect& contentRect) const
105 IntPoint pos(contentRect.x() - m_layerPosition.x(), contentRect.y() - m_layerPosition.y());
106 IntRect layerRect(pos, contentRect.size());
108 // Clip to the position.
109 if (pos.x() < 0 || pos.y() < 0)
110 layerRect = IntRect(IntPoint(0, 0), IntSize(contentRect.width() + pos.x(), contentRect.height() + pos.y()));
114 IntRect CCLayerTilingData::layerRectToContentRect(const IntRect& layerRect) const
116 IntRect contentRect = layerRect;
117 contentRect.move(m_layerPosition.x(), m_layerPosition.y());
121 IntRect CCLayerTilingData::tileContentRect(const Tile* tile) const
123 IntRect contentRect = tileLayerRect(tile);
124 contentRect.move(m_layerPosition.x(), m_layerPosition.y());
128 IntRect CCLayerTilingData::tileLayerRect(const Tile* tile) const
130 const int index = m_tilingData.tileIndex(tile->i(), tile->j());
131 IntRect layerRect = m_tilingData.tileBoundsWithBorder(index);
132 layerRect.setSize(m_tileSize);
136 void CCLayerTilingData::setLayerPosition(const IntPoint& layerPosition)
138 m_layerPosition = layerPosition;
141 void CCLayerTilingData::growLayerToContain(const IntRect& contentRect)
143 // Grow the tile array to contain this content rect.
144 IntRect layerRect = contentRectToLayerRect(contentRect);
145 IntSize rectSize = IntSize(layerRect.maxX(), layerRect.maxY());
147 IntSize oldLayerSize(m_tilingData.totalSizeX(), m_tilingData.totalSizeY());
148 IntSize newSize = rectSize.expandedTo(oldLayerSize);
149 m_tilingData.setTotalSize(newSize.width(), newSize.height());
152 } // namespace WebCore
154 #endif // USE(ACCELERATED_COMPOSITING)