AcagiTile.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies)
  3. Copyright (C) 2014 Sony Computer Entertainment Inc.
  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. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public License
  13. along with this library; see the file COPYING.LIB. If not, write to
  14. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  15. Boston, MA 02110-1301, USA.
  16. */
  17. #include "config.h"
  18. #include "AcagiTile.h"
  19. #if USE(ACCELERATED_COMPOSITING) && USE(ACAGI)
  20. #include "AcagiCompositor.h"
  21. #include "Image.h"
  22. #include <wtf/RefPtr.h>
  23. namespace WebCore {
  24. class GraphicsLayer;
  25. void AcagiTile::updateContents(AcagiCompositor* compositor, Image* image, const IntRect& dirtyRect, AcagiBitmapTexture::UpdateContentsFlag updateContentsFlag)
  26. {
  27. IntRect targetRect = enclosingIntRect(m_tileRect);
  28. targetRect.intersect(dirtyRect);
  29. if (targetRect.isEmpty())
  30. return;
  31. IntPoint sourceOffset = targetRect.location();
  32. // Normalize sourceRect to the buffer's coordinates.
  33. sourceOffset.move(-dirtyRect.x(), -dirtyRect.y());
  34. // Normalize targetRect to the texture's coordinates.
  35. targetRect.move(-m_tileRect.x(), -m_tileRect.y());
  36. if (!m_texture) {
  37. m_texture = compositor->createTexture();
  38. m_texture->reset(m_tileRect.size(), image->currentFrameKnownToBeOpaque() ? 0 : AcagiBitmapTexture::SupportsAlpha);
  39. }
  40. m_texture->updateContents(image, targetRect, sourceOffset, updateContentsFlag);
  41. }
  42. void AcagiTile::updateContents(AcagiCompositor* compositor, GraphicsLayer* sourceLayer, const IntRect& dirtyRect, AcagiBitmapTexture::UpdateContentsFlag updateContentsFlag)
  43. {
  44. // Source rect in the contents coordinates.
  45. FloatRect sourceRect = dirtyRect;
  46. sourceRect.unite(m_dirtyRect);
  47. sourceRect.intersect(scaledTileRect());
  48. m_dirtyRect = IntRect();
  49. if (sourceRect.isEmpty())
  50. return;
  51. // Reset texture.
  52. if (!m_texture) {
  53. m_texture = compositor->createTexture();
  54. m_texture->reset(m_tileRect.size(), AcagiBitmapTexture::SupportsAlpha);
  55. sourceRect = scaledTileRect();
  56. } else
  57. m_texture = compositor->duplicateTexture(m_texture);
  58. // Calculate dirty rect in the buffer's coordinate.
  59. FloatRect enclosedTargetRect = sourceRect;
  60. enclosedTargetRect.scale(1 / m_contentsScale);
  61. IntRect targetRect = enclosingIntRect(enclosedTargetRect);
  62. // Update sourceRect by scaling targetRect.
  63. sourceRect = targetRect;
  64. sourceRect.scale(1 / m_contentsScale);
  65. IntPoint targetOffset = m_tileRect.location();
  66. targetRect.moveBy(-targetOffset);
  67. m_texture->updateContents(compositor, sourceLayer, targetRect, targetOffset, sourceRect, updateContentsFlag);
  68. }
  69. void AcagiTile::paint(AcagiCompositor* compositor, const TransformationMatrix& transform, float opacity, const unsigned exposedEdges)
  70. {
  71. FloatRect rect = m_tileRect;
  72. rect.scale(1 / m_contentsScale);
  73. if (texture().get())
  74. compositor->drawTexture(*texture().get(), rect, transform, opacity, exposedEdges);
  75. }
  76. } // namespace WebCore
  77. #endif