| 1 | /* |
| 2 | Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies) |
| 3 | |
| 4 | This library is free software; you can redistribute it and/or |
| 5 | modify it under the terms of the GNU Library General Public |
| 6 | License as published by the Free Software Foundation; either |
| 7 | version 2 of the License, or (at your option) any later version. |
| 8 | |
| 9 | This library is distributed in the hope that it will be useful, |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | Library General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU Library General Public License |
| 15 | along with this library; see the file COPYING.LIB. If not, write to |
| 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 17 | Boston, MA 02110-1301, USA. |
| 18 | */ |
| 19 | #include "config.h" |
| 20 | |
| 21 | #include "TextureMapperTile.h" |
| 22 | |
| 23 | #include "Image.h" |
| 24 | #include "TextureMapper.h" |
| 25 | |
| 26 | namespace WebCore { |
| 27 | |
| 28 | class GraphicsLayer; |
| 29 | |
| 30 | void TextureMapperTile::updateContents(TextureMapper& textureMapper, Image* image, const IntRect& dirtyRect) |
| 31 | { |
| 32 | IntRect targetRect = enclosingIntRect(m_rect); |
| 33 | targetRect.intersect(dirtyRect); |
| 34 | if (targetRect.isEmpty()) |
| 35 | return; |
| 36 | IntPoint sourceOffset = targetRect.location(); |
| 37 | |
| 38 | // Normalize sourceRect to the buffer's coordinates. |
| 39 | sourceOffset.move(-dirtyRect.x(), -dirtyRect.y()); |
| 40 | |
| 41 | // Normalize targetRect to the texture's coordinates. |
| 42 | targetRect.move(-m_rect.x(), -m_rect.y()); |
| 43 | if (!m_texture) { |
| 44 | m_texture = textureMapper.createTexture(); |
| 45 | m_texture->reset(targetRect.size(), image->currentFrameKnownToBeOpaque() ? 0 : BitmapTexture::SupportsAlpha); |
| 46 | } |
| 47 | |
| 48 | m_texture->updateContents(image, targetRect, sourceOffset); |
| 49 | } |
| 50 | |
| 51 | void TextureMapperTile::updateContents(TextureMapper& textureMapper, GraphicsLayer* sourceLayer, const IntRect& dirtyRect, float scale) |
| 52 | { |
| 53 | IntRect targetRect = enclosingIntRect(m_rect); |
| 54 | targetRect.intersect(dirtyRect); |
| 55 | if (targetRect.isEmpty()) |
| 56 | return; |
| 57 | IntPoint sourceOffset = targetRect.location(); |
| 58 | |
| 59 | // Normalize targetRect to the texture's coordinates. |
| 60 | targetRect.move(-m_rect.x(), -m_rect.y()); |
| 61 | |
| 62 | if (!m_texture) { |
| 63 | m_texture = textureMapper.createTexture(); |
| 64 | m_texture->reset(targetRect.size(), BitmapTexture::SupportsAlpha); |
| 65 | } |
| 66 | |
| 67 | m_texture->updateContents(textureMapper, sourceLayer, targetRect, sourceOffset, scale); |
| 68 | } |
| 69 | |
| 70 | void TextureMapperTile::paint(TextureMapper& textureMapper, const TransformationMatrix& transform, float opacity, const unsigned exposedEdges) |
| 71 | { |
| 72 | if (texture().get()) |
| 73 | textureMapper.drawTexture(*texture().get(), rect(), transform, opacity, exposedEdges); |
| 74 | } |
| 75 | |
| 76 | } // namespace WebCore |
| 77 | |