Move CACFLayerTreeHostClient to its own header file
[WebKit-https.git] / Source / WebCore / platform / graphics / ca / win / CACFLayerTreeHost.h
1 /*
2  * Copyright (C) 2009 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. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
24  */
25
26 #ifndef CACFLayerTreeHost_h
27 #define CACFLayerTreeHost_h
28
29 #if USE(ACCELERATED_COMPOSITING)
30
31 #include "COMPtr.h"
32 #include "Timer.h"
33
34 #include <wtf/HashSet.h>
35 #include <wtf/PassRefPtr.h>
36 #include <wtf/RefCounted.h>
37 #include <wtf/RefPtr.h>
38 #include <wtf/RetainPtr.h>
39 #include <wtf/Vector.h>
40
41 #include <CoreGraphics/CGGeometry.h>
42
43 interface IDirect3DDevice9;
44 struct WKCACFContext;
45
46 typedef struct CGImage* CGImageRef;
47
48 namespace WebCore {
49
50 class CACFLayerTreeHostClient;
51 class PlatformCALayer;
52
53 // FIXME: Currently there is a CACFLayerTreeHost for each WebView and each
54 // has its own CARenderOGLContext and Direct3DDevice9, which is inefficient.
55 // (https://bugs.webkit.org/show_bug.cgi?id=31855)
56 class CACFLayerTreeHost : public RefCounted<CACFLayerTreeHost> {
57     friend PlatformCALayer;
58
59 public:
60     static PassRefPtr<CACFLayerTreeHost> create();
61     ~CACFLayerTreeHost();
62
63     static bool acceleratedCompositingAvailable();
64
65     void setClient(CACFLayerTreeHostClient* client) { m_client = client; }
66
67     void setRootChildLayer(PlatformCALayer*);
68     void layerTreeDidChange();
69     void setWindow(HWND);
70     void paint();
71     void resize();
72     void flushPendingGraphicsLayerChangesSoon();
73     void flushPendingLayerChangesNow();
74
75 protected:
76     PlatformCALayer* rootLayer() const;
77     void addPendingAnimatedLayer(PassRefPtr<PlatformCALayer>);
78
79 private:
80     CACFLayerTreeHost();
81
82     bool createRenderer();
83     void destroyRenderer();
84     void renderSoon();
85     void renderTimerFired(Timer<CACFLayerTreeHost>*);
86     void notifyAnimationsStarted();
87
88     CGRect bounds() const;
89
90     void initD3DGeometry();
91
92     // Call this when the device window has changed size or when IDirect3DDevice9::Present returns
93     // D3DERR_DEVICELOST. Returns true if the device was recovered, false if rendering must be
94     // aborted and reattempted soon.
95     enum ResetReason { ChangedWindowSize, LostDevice };
96     bool resetDevice(ResetReason);
97
98     void render(const Vector<CGRect>& dirtyRects = Vector<CGRect>());
99
100     CACFLayerTreeHostClient* m_client;
101     bool m_mightBeAbleToCreateDeviceLater;
102     COMPtr<IDirect3DDevice9> m_d3dDevice;
103     RefPtr<PlatformCALayer> m_rootLayer;
104     RefPtr<PlatformCALayer> m_rootChildLayer;
105     WKCACFContext* m_context;
106     HWND m_window;
107     Timer<CACFLayerTreeHost> m_renderTimer;
108     bool m_mustResetLostDeviceBeforeRendering;
109     bool m_shouldFlushPendingGraphicsLayerChanges;
110     bool m_isFlushingLayerChanges;
111     HashSet<RefPtr<PlatformCALayer> > m_pendingAnimatedLayers;
112
113 #ifndef NDEBUG
114     bool m_printTree;
115 #endif
116 #if !ASSERT_DISABLED
117     enum { WindowNotSet, WindowSet, WindowCleared } m_state;
118 #endif
119 };
120
121 }
122
123 #endif // USE(ACCELERATED_COMPOSITING)
124
125 #endif // CACFLayerTreeHost_h