AcagiLayer.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /*
  2. Copyright (C) 2010 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. #ifndef AcagiLayer_h
  18. #define AcagiLayer_h
  19. #if USE(ACCELERATED_COMPOSITING) && USE(ACAGI)
  20. #include "AcagiBackingStore.h"
  21. #include "AcagiCompositor.h"
  22. #include "FilterOperations.h"
  23. #include "FloatRect.h"
  24. #include "GraphicsLayerAnimation.h"
  25. #include "GraphicsLayerTransform.h"
  26. namespace WebCore {
  27. class Region;
  28. class AcagiPaintOptions;
  29. class PlatformLayerAcagi;
  30. class AcagiLayer : public GraphicsLayerAnimation::Client {
  31. WTF_MAKE_NONCOPYABLE(AcagiLayer);
  32. WTF_MAKE_FAST_ALLOCATED;
  33. public:
  34. class ScrollingClient {
  35. public:
  36. virtual ~ScrollingClient() { }
  37. virtual void commitScrollOffset(uint32_t layerID, const IntSize& offset) = 0;
  38. };
  39. AcagiLayer()
  40. : m_parent(0)
  41. , m_effectTarget(0)
  42. , m_contentsLayer(0)
  43. , m_currentOpacity(1)
  44. , m_centerZ(0)
  45. , m_compositor(0)
  46. , m_fixedToViewport(false)
  47. , m_id(0)
  48. , m_scrollClient(0)
  49. , m_isScrollable(false)
  50. , m_patternTransformDirty(false)
  51. { }
  52. virtual ~AcagiLayer();
  53. void setID(uint32_t id) { m_id = id; }
  54. uint32_t id() { return m_id; }
  55. const Vector<AcagiLayer*>& children() const { return m_children; }
  56. AcagiLayer* findScrollableContentsLayerAt(const FloatPoint& pos);
  57. void setScrollClient(ScrollingClient* scrollClient) { m_scrollClient = scrollClient; }
  58. void scrollBy(const WebCore::FloatSize&);
  59. void didCommitScrollOffset(const IntSize&);
  60. void setIsScrollable(bool isScrollable) { m_isScrollable = isScrollable; }
  61. bool isScrollable() const { return m_isScrollable; }
  62. AcagiCompositor* compositor() const;
  63. void setCompositor(AcagiCompositor* compositor) { m_compositor = compositor; }
  64. void setChildren(const Vector<AcagiLayer*>&);
  65. void setMaskLayer(AcagiLayer*);
  66. void setReplicaLayer(AcagiLayer*);
  67. void setPosition(const FloatPoint&);
  68. void setSize(const FloatSize&);
  69. void setAnchorPoint(const FloatPoint3D&);
  70. void setPreserves3D(bool);
  71. void setTransform(const TransformationMatrix&);
  72. void setChildrenTransform(const TransformationMatrix&);
  73. void setContentsRect(const IntRect&);
  74. void setMasksToBounds(bool);
  75. void setDrawsContent(bool);
  76. bool drawsContent() const { return m_state.drawsContent; }
  77. bool contentsAreVisible() const { return m_state.contentsVisible; }
  78. FloatSize size() const { return m_state.size; }
  79. float opacity() const { return m_state.opacity; }
  80. TransformationMatrix transform() const { return m_state.transform; }
  81. void setContentsVisible(bool);
  82. void setContentsOpaque(bool);
  83. void setBackfaceVisibility(bool);
  84. void setOpacity(float);
  85. void setSolidColor(const Color&);
  86. void setContentsTileSize(const IntSize&);
  87. void setContentsTilePhase(const IntPoint&);
  88. bool hasFilters() const
  89. {
  90. return false;
  91. }
  92. void setDebugVisuals(bool showDebugBorders, const Color& debugBorderColor, float debugBorderWidth, bool showRepaintCounter);
  93. bool isShowingRepaintCounter() const { return m_state.showRepaintCounter; }
  94. void setRepaintCount(int);
  95. void setContentsLayer(PlatformLayerAcagi*);
  96. void setAnimations(const GraphicsLayerAnimations&);
  97. void setFixedToViewport(bool);
  98. bool fixedToViewport() const { return m_fixedToViewport; }
  99. void setBackingStore(PassRefPtr<AcagiBackingStore>);
  100. void syncAnimations();
  101. bool descendantsOrSelfHaveRunningAnimations() const;
  102. void paint();
  103. void setScrollPositionDeltaIfNeeded(const FloatSize&);
  104. void applyAnimationsRecursively();
  105. void addChild(AcagiLayer*);
  106. void computeTransformsRecursive();
  107. TransformationMatrix combinedTransform() { return m_currentTransform.combined(); }
  108. private:
  109. const AcagiLayer* rootLayer() const;
  110. static int compareGraphicsLayersZValue(const void* a, const void* b);
  111. static void sortByZOrder(Vector<AcagiLayer* >& array);
  112. PassRefPtr<AcagiBitmapTexture> texture() { return m_backingStore ? m_backingStore->texture() : 0; }
  113. FloatPoint adjustedPosition() const { return m_state.pos + m_scrollPositionDelta - m_userScrollOffset; }
  114. bool isAncestorFixedToViewport() const;
  115. TransformationMatrix replicaTransform();
  116. void removeFromParent();
  117. void removeAllChildren();
  118. enum ResolveSelfOverlapMode {
  119. ResolveSelfOverlapAlways = 0,
  120. ResolveSelfOverlapIfNeeded
  121. };
  122. void computeOverlapRegions(Region& overlapRegion, Region& nonOverlapRegion, ResolveSelfOverlapMode);
  123. void paintRecursive(const AcagiPaintOptions&);
  124. void paintUsingOverlapRegions(const AcagiPaintOptions&);
  125. PassRefPtr<AcagiBitmapTexture> paintIntoSurface(const AcagiPaintOptions&, const IntSize&);
  126. void paintWithIntermediateSurface(const AcagiPaintOptions&, const IntRect&);
  127. void paintSelf(const AcagiPaintOptions&);
  128. void paintSelfAndChildren(const AcagiPaintOptions&);
  129. void paintSelfAndChildrenWithReplica(const AcagiPaintOptions&);
  130. void applyMask(const AcagiPaintOptions&);
  131. void computePatternTransformIfNeeded();
  132. // GraphicsLayerAnimation::Client
  133. virtual void setAnimatedTransform(const TransformationMatrix&) OVERRIDE;
  134. virtual void setAnimatedOpacity(float) OVERRIDE;
  135. bool isVisible() const;
  136. enum ContentsLayerCount {
  137. NoLayersWithContent,
  138. SingleLayerWithContents,
  139. MultipleLayersWithContents
  140. };
  141. bool shouldBlend() const;
  142. inline FloatRect layerRect() const
  143. {
  144. return FloatRect(FloatPoint::zero(), m_state.size);
  145. }
  146. Vector<AcagiLayer*> m_children;
  147. AcagiLayer* m_parent;
  148. AcagiLayer* m_effectTarget;
  149. RefPtr<AcagiBackingStore> m_backingStore;
  150. PlatformLayerAcagi* m_contentsLayer;
  151. GraphicsLayerTransform m_currentTransform;
  152. float m_currentOpacity;
  153. float m_centerZ;
  154. template<class HitTestCondition> AcagiLayer* hitTest(const FloatPoint&, HitTestCondition);
  155. static bool scrollableLayerHitTestCondition(AcagiLayer*, const FloatPoint&);
  156. FloatSize mapScrollOffset(const FloatSize&);
  157. void commitScrollOffset(const FloatSize&);
  158. struct State {
  159. FloatPoint pos;
  160. FloatPoint3D anchorPoint;
  161. FloatSize size;
  162. TransformationMatrix transform;
  163. TransformationMatrix childrenTransform;
  164. float opacity;
  165. FloatRect contentsRect;
  166. IntSize contentsTileSize;
  167. IntPoint contentsTilePhase;
  168. AcagiLayer* maskLayer;
  169. AcagiLayer* replicaLayer;
  170. Color solidColor;
  171. Color debugBorderColor;
  172. float debugBorderWidth;
  173. int repaintCount;
  174. bool preserves3D : 1;
  175. bool masksToBounds : 1;
  176. bool drawsContent : 1;
  177. bool contentsVisible : 1;
  178. bool contentsOpaque : 1;
  179. bool backfaceVisibility : 1;
  180. bool visible : 1;
  181. bool showDebugBorders : 1;
  182. bool showRepaintCounter : 1;
  183. State()
  184. : opacity(1)
  185. , maskLayer(0)
  186. , replicaLayer(0)
  187. , debugBorderWidth(0)
  188. , repaintCount(0)
  189. , preserves3D(false)
  190. , masksToBounds(false)
  191. , drawsContent(false)
  192. , contentsVisible(true)
  193. , contentsOpaque(false)
  194. , backfaceVisibility(true)
  195. , visible(true)
  196. , showDebugBorders(false)
  197. , showRepaintCounter(false)
  198. {
  199. }
  200. };
  201. State m_state;
  202. AcagiCompositor* m_compositor;
  203. GraphicsLayerAnimations m_animations;
  204. FloatSize m_scrollPositionDelta;
  205. bool m_fixedToViewport;
  206. uint32_t m_id;
  207. ScrollingClient* m_scrollClient;
  208. bool m_isScrollable;
  209. FloatSize m_userScrollOffset;
  210. FloatSize m_accumulatedScrollOffsetFractionalPart;
  211. TransformationMatrix m_patternTransform;
  212. bool m_patternTransformDirty;
  213. };
  214. }
  215. #endif
  216. #endif // AcagiLayer_h