RemoteGraphicsLayer.mm 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * Copyright (C) 2012 Apple Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  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.
  12. *
  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.
  24. */
  25. #include "config.h"
  26. #include "RemoteGraphicsLayer.h"
  27. #include "RemoteLayerTreeContext.h"
  28. #include "RemoteLayerTreeTransaction.h"
  29. #include <WebCore/FloatRect.h>
  30. #include <wtf/text/CString.h>
  31. using namespace WebCore;
  32. namespace WebKit {
  33. static uint64_t generateLayerID()
  34. {
  35. static uint64_t layerID;
  36. return ++layerID;
  37. }
  38. PassOwnPtr<GraphicsLayer> RemoteGraphicsLayer::create(GraphicsLayerClient* client, RemoteLayerTreeContext* context)
  39. {
  40. return adoptPtr(new RemoteGraphicsLayer(client, context));
  41. }
  42. RemoteGraphicsLayer::RemoteGraphicsLayer(GraphicsLayerClient* client, RemoteLayerTreeContext* context)
  43. : GraphicsLayer(client)
  44. , m_layerID(generateLayerID())
  45. , m_context(context)
  46. , m_uncommittedLayerChanges(RemoteLayerTreeTransaction::NoChange)
  47. {
  48. }
  49. RemoteGraphicsLayer::~RemoteGraphicsLayer()
  50. {
  51. willBeDestroyed();
  52. }
  53. void RemoteGraphicsLayer::setName(const String& name)
  54. {
  55. String longName = String::format("RemoteGraphicsLayer(%p) ", this) + name;
  56. GraphicsLayer::setName(longName);
  57. noteLayerPropertiesChanged(RemoteLayerTreeTransaction::NameChanged);
  58. }
  59. bool RemoteGraphicsLayer::setChildren(const Vector<GraphicsLayer*>& children)
  60. {
  61. if (GraphicsLayer::setChildren(children)) {
  62. noteSublayersChanged();
  63. return true;
  64. }
  65. return false;
  66. }
  67. void RemoteGraphicsLayer::addChild(GraphicsLayer* childLayer)
  68. {
  69. GraphicsLayer::addChild(childLayer);
  70. noteSublayersChanged();
  71. }
  72. void RemoteGraphicsLayer::addChildAtIndex(GraphicsLayer* childLayer, int index)
  73. {
  74. GraphicsLayer::addChildAtIndex(childLayer, index);
  75. noteSublayersChanged();
  76. }
  77. void RemoteGraphicsLayer::addChildAbove(GraphicsLayer* childLayer, GraphicsLayer* sibling)
  78. {
  79. GraphicsLayer::addChildAbove(childLayer, sibling);
  80. noteSublayersChanged();
  81. }
  82. void RemoteGraphicsLayer::addChildBelow(GraphicsLayer* childLayer, GraphicsLayer* sibling)
  83. {
  84. GraphicsLayer::addChildBelow(childLayer, sibling);
  85. noteSublayersChanged();
  86. }
  87. bool RemoteGraphicsLayer::replaceChild(GraphicsLayer* oldChild, GraphicsLayer* newChild)
  88. {
  89. if (GraphicsLayer::replaceChild(oldChild, newChild)) {
  90. noteSublayersChanged();
  91. return true;
  92. }
  93. return false;
  94. }
  95. void RemoteGraphicsLayer::removeFromParent()
  96. {
  97. if (m_parent)
  98. static_cast<RemoteGraphicsLayer*>(m_parent)->noteSublayersChanged();
  99. GraphicsLayer::removeFromParent();
  100. }
  101. void RemoteGraphicsLayer::setPosition(const FloatPoint& position)
  102. {
  103. if (position == m_position)
  104. return;
  105. GraphicsLayer::setPosition(position);
  106. noteLayerPropertiesChanged(RemoteLayerTreeTransaction::PositionChanged);
  107. }
  108. void RemoteGraphicsLayer::setSize(const FloatSize& size)
  109. {
  110. if (size == m_size)
  111. return;
  112. GraphicsLayer::setSize(size);
  113. noteLayerPropertiesChanged(RemoteLayerTreeTransaction::SizeChanged);
  114. }
  115. void RemoteGraphicsLayer::setNeedsDisplay()
  116. {
  117. FloatRect hugeRect(-std::numeric_limits<float>::max() / 2, -std::numeric_limits<float>::max() / 2,
  118. std::numeric_limits<float>::max(), std::numeric_limits<float>::max());
  119. setNeedsDisplayInRect(hugeRect);
  120. }
  121. void RemoteGraphicsLayer::setNeedsDisplayInRect(const FloatRect&)
  122. {
  123. // FIXME: Implement this.
  124. }
  125. void RemoteGraphicsLayer::flushCompositingState(const FloatRect&)
  126. {
  127. recursiveCommitChanges();
  128. }
  129. void RemoteGraphicsLayer::flushCompositingStateForThisLayerOnly()
  130. {
  131. if (!m_uncommittedLayerChanges)
  132. return;
  133. m_context->currentTransaction().layerPropertiesChanged(this, m_uncommittedLayerChanges);
  134. m_uncommittedLayerChanges = RemoteLayerTreeTransaction::NoChange;
  135. }
  136. void RemoteGraphicsLayer::willBeDestroyed()
  137. {
  138. m_context->layerWillBeDestroyed(this);
  139. GraphicsLayer::willBeDestroyed();
  140. }
  141. void RemoteGraphicsLayer::noteLayerPropertiesChanged(unsigned layerChanges)
  142. {
  143. if (!m_uncommittedLayerChanges && m_client)
  144. m_client->notifyFlushRequired(this);
  145. m_uncommittedLayerChanges |= layerChanges;
  146. }
  147. void RemoteGraphicsLayer::noteSublayersChanged()
  148. {
  149. noteLayerPropertiesChanged(RemoteLayerTreeTransaction::ChildrenChanged);
  150. // FIXME: Handle replica layers.
  151. }
  152. void RemoteGraphicsLayer::recursiveCommitChanges()
  153. {
  154. flushCompositingStateForThisLayerOnly();
  155. for (size_t i = 0; i < children().size(); ++i) {
  156. RemoteGraphicsLayer* graphicsLayer = static_cast<RemoteGraphicsLayer*>(children()[i]);
  157. graphicsLayer->recursiveCommitChanges();
  158. }
  159. }
  160. } // namespace WebKit