TiledCoreAnimationDrawingArea.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * Copyright (C) 2011 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. #ifndef TiledCoreAnimationDrawingArea_h
  26. #define TiledCoreAnimationDrawingArea_h
  27. #if ENABLE(THREADED_SCROLLING)
  28. #include "DrawingArea.h"
  29. #include "LayerTreeContext.h"
  30. #include <WebCore/FloatRect.h>
  31. #include <WebCore/GraphicsLayerClient.h>
  32. #include <WebCore/LayerFlushScheduler.h>
  33. #include <WebCore/LayerFlushSchedulerClient.h>
  34. #include <WebCore/Timer.h>
  35. #include <wtf/HashMap.h>
  36. #include <wtf/RetainPtr.h>
  37. OBJC_CLASS CALayer;
  38. OBJC_CLASS WKContentLayer;
  39. namespace WebCore {
  40. class TiledBacking;
  41. }
  42. namespace WebKit {
  43. class LayerHostingContext;
  44. class TiledCoreAnimationDrawingArea : public DrawingArea, WebCore::GraphicsLayerClient, WebCore::LayerFlushSchedulerClient {
  45. public:
  46. static PassOwnPtr<TiledCoreAnimationDrawingArea> create(WebPage*, const WebPageCreationParameters&);
  47. virtual ~TiledCoreAnimationDrawingArea();
  48. private:
  49. TiledCoreAnimationDrawingArea(WebPage*, const WebPageCreationParameters&);
  50. // DrawingArea
  51. virtual void setNeedsDisplay() OVERRIDE;
  52. virtual void setNeedsDisplayInRect(const WebCore::IntRect&) OVERRIDE;
  53. virtual void scroll(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollDelta) OVERRIDE;
  54. virtual void forceRepaint() OVERRIDE;
  55. virtual bool forceRepaintAsync(uint64_t callbackID) OVERRIDE;
  56. virtual void setLayerTreeStateIsFrozen(bool) OVERRIDE;
  57. virtual bool layerTreeStateIsFrozen() const OVERRIDE;
  58. virtual void setRootCompositingLayer(WebCore::GraphicsLayer*) OVERRIDE;
  59. virtual void scheduleCompositingLayerFlush() OVERRIDE;
  60. virtual void didInstallPageOverlay(PageOverlay*) OVERRIDE;
  61. virtual void didUninstallPageOverlay(PageOverlay*) OVERRIDE;
  62. virtual void setPageOverlayNeedsDisplay(PageOverlay*, const WebCore::IntRect&) OVERRIDE;
  63. virtual void updatePreferences(const WebPreferencesStore&) OVERRIDE;
  64. virtual void mainFrameContentSizeChanged(const WebCore::IntSize&) OVERRIDE;
  65. virtual void setExposedRect(const WebCore::FloatRect&) OVERRIDE;
  66. virtual void setClipsToExposedRect(bool) OVERRIDE;
  67. virtual void didChangeScrollOffsetForAnyFrame() OVERRIDE;
  68. virtual void dispatchAfterEnsuringUpdatedScrollPosition(const Function<void ()>&) OVERRIDE;
  69. // WebCore::GraphicsLayerClient
  70. virtual void notifyAnimationStarted(const WebCore::GraphicsLayer*, double time) OVERRIDE;
  71. virtual void notifyFlushRequired(const WebCore::GraphicsLayer*) OVERRIDE;
  72. virtual void paintContents(const WebCore::GraphicsLayer*, WebCore::GraphicsContext&, WebCore::GraphicsLayerPaintingPhase, const WebCore::IntRect& clipRect) OVERRIDE;
  73. virtual float deviceScaleFactor() const OVERRIDE;
  74. virtual void didCommitChangesForLayer(const WebCore::GraphicsLayer*) const OVERRIDE;
  75. // WebCore::LayerFlushSchedulerClient
  76. virtual bool flushLayers() OVERRIDE;
  77. // Message handlers.
  78. virtual void suspendPainting() OVERRIDE;
  79. virtual void resumePainting() OVERRIDE;
  80. virtual void updateGeometry(const WebCore::IntSize& viewSize, const WebCore::IntSize& layerPosition) OVERRIDE;
  81. virtual void setDeviceScaleFactor(float) OVERRIDE;
  82. virtual void setLayerHostingMode(uint32_t) OVERRIDE;
  83. virtual void setColorSpace(const ColorSpaceData&) OVERRIDE;
  84. void updateLayerHostingContext();
  85. void setRootCompositingLayer(CALayer *);
  86. void createPageOverlayLayer(PageOverlay*);
  87. void destroyPageOverlayLayer(PageOverlay*);
  88. WebCore::TiledBacking* mainFrameTiledBacking() const;
  89. void updateDebugInfoLayer(bool showLayer);
  90. void updateIntrinsicContentSizeTimerFired(WebCore::Timer<TiledCoreAnimationDrawingArea>*);
  91. void updateMainFrameClipsToExposedRect();
  92. void updateScrolledExposedRect();
  93. void invalidateAllPageOverlays();
  94. bool m_layerTreeStateIsFrozen;
  95. WebCore::LayerFlushScheduler m_layerFlushScheduler;
  96. OwnPtr<LayerHostingContext> m_layerHostingContext;
  97. RetainPtr<CALayer> m_rootLayer;
  98. RetainPtr<CALayer> m_pendingRootCompositingLayer;
  99. RetainPtr<CALayer> m_debugInfoLayer;
  100. typedef HashMap<PageOverlay*, OwnPtr<WebCore::GraphicsLayer>> PageOverlayLayerMap;
  101. PageOverlayLayerMap m_pageOverlayLayers;
  102. mutable HashMap<const WebCore::GraphicsLayer*, RetainPtr<CALayer>> m_pageOverlayPlatformLayers;
  103. bool m_isPaintingSuspended;
  104. bool m_hasRootCompositingLayer;
  105. WebCore::FloatRect m_exposedRect;
  106. WebCore::FloatRect m_scrolledExposedRect;
  107. bool m_clipsToExposedRect;
  108. WebCore::IntSize m_lastSentIntrinsicContentSize;
  109. WebCore::Timer<TiledCoreAnimationDrawingArea> m_updateIntrinsicContentSizeTimer;
  110. bool m_inUpdateGeometry;
  111. };
  112. } // namespace WebKit
  113. #endif // ENABLE(THREADED_SCROLLING)
  114. #endif // TiledCoreAnimationDrawingArea_h