FrameLayers.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Copyright (C) 2010, 2011, 2012 Research In Motion Limited. All rights reserved.
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser 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. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "config.h"
  19. #if USE(ACCELERATED_COMPOSITING)
  20. #include "FrameLayers.h"
  21. #include "Frame.h"
  22. #include "FrameView.h"
  23. #include "LayerWebKitThread.h"
  24. #include "Page.h"
  25. #include "RenderPart.h"
  26. #include "WebPage_p.h"
  27. #include <wtf/Assertions.h>
  28. using namespace WebCore;
  29. namespace BlackBerry {
  30. namespace WebKit {
  31. static FloatSize frameLayerAbsoluteOffset(Frame* frame)
  32. {
  33. ASSERT(frame);
  34. if (!frame->view() || !frame->page() || !frame->page()->mainFrame() || !frame->page()->mainFrame()->view())
  35. return FloatSize();
  36. IntPoint offset = frame->page()->mainFrame()->view()->windowToContents(frame->view()->contentsToWindow(IntPoint::zero()));
  37. return FloatSize(offset.x(), offset.y());
  38. }
  39. FrameLayers::FrameLayers(WebPagePrivate* page)
  40. : m_pagePrivate(page)
  41. , m_rootGraphicsLayer()
  42. , m_rootLayer(0)
  43. {
  44. }
  45. FrameLayers::~FrameLayers()
  46. {
  47. m_frameLayers.clear();
  48. }
  49. bool FrameLayers::containsLayerForFrame(Frame* frame)
  50. {
  51. ASSERT(frame);
  52. return m_frameLayers.contains(frame);
  53. }
  54. void FrameLayers::addLayer(Frame* frame, LayerWebKitThread* layer)
  55. {
  56. // If we have main frame layer we don't accept other layers.
  57. // This should not happen actually.
  58. ASSERT(frame != m_pagePrivate->m_mainFrame || !isRootLayerMainFrameLayer());
  59. if (frame == m_pagePrivate->m_mainFrame && isRootLayerMainFrameLayer())
  60. return;
  61. ASSERT(frame && layer && !m_frameLayers.contains(frame));
  62. m_frameLayers.add(frame, layer);
  63. calculateRootLayer();
  64. if (!m_rootLayer) {
  65. ASSERT(!m_rootGraphicsLayer);
  66. m_rootGraphicsLayer = GraphicsLayer::create(0);
  67. m_rootLayer = m_rootGraphicsLayer->platformLayer();
  68. }
  69. if (m_rootLayer != layer)
  70. m_rootLayer->addSublayer(layer);
  71. }
  72. void FrameLayers::removeLayerByFrame(Frame* frame)
  73. {
  74. ASSERT(frame);
  75. FrameLayerMap::iterator it = m_frameLayers.find(frame);
  76. if (it != m_frameLayers.end()) {
  77. LayerWebKitThread* layer = it->value;
  78. if (layer->superlayer())
  79. layer->removeFromSuperlayer();
  80. m_frameLayers.remove(it);
  81. calculateRootLayer();
  82. }
  83. }
  84. void FrameLayers::commitOnWebKitThread(double scale)
  85. {
  86. ASSERT(m_rootLayer);
  87. if (!isRootLayerMainFrameLayer()) {
  88. for (FrameLayerMap::iterator it = m_frameLayers.begin(); it != m_frameLayers.end(); ++it)
  89. it->value->setAbsoluteOffset(frameLayerAbsoluteOffset(it->key));
  90. }
  91. m_rootLayer->commitOnWebKitThread(scale);
  92. }
  93. void FrameLayers::notifyAnimationsStarted(double animationStartTime)
  94. {
  95. m_rootLayer->notifyAnimationsStarted(animationStartTime);
  96. }
  97. void FrameLayers::calculateRootLayer()
  98. {
  99. if (m_frameLayers.size() == 1 && m_frameLayers.begin()->key == m_pagePrivate->m_mainFrame)
  100. m_rootLayer = m_frameLayers.begin()->value;
  101. else if (m_rootGraphicsLayer)
  102. m_rootLayer = m_rootGraphicsLayer->platformLayer();
  103. else
  104. m_rootLayer = 0;
  105. }
  106. void FrameLayers::releaseLayerResources()
  107. {
  108. if (m_rootLayer)
  109. m_rootLayer->releaseLayerResources();
  110. }
  111. } // namespace BlackBerry
  112. } // namespace WebKit
  113. #endif // USE(ACCELERATED_COMPOSITING)