[chromium] Make CCThreadProxy draw
[WebKit-https.git] / Source / WebCore / platform / graphics / chromium / cc / CCLayerTreeHost.h
1 /*
2  * Copyright (C) 2011 Google 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'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16  * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
17  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  */
24
25 #ifndef CCLayerTreeHost_h
26 #define CCLayerTreeHost_h
27
28 #include "GraphicsTypes3D.h"
29 #include "IntRect.h"
30 #include "cc/CCProxy.h"
31
32 #include <wtf/PassOwnPtr.h>
33 #include <wtf/PassRefPtr.h>
34 #include <wtf/RefCounted.h>
35
36 #if USE(SKIA)
37 class GrContext;
38 #endif
39
40 namespace WebCore {
41
42 class CCLayerTreeHostImpl;
43 class CCThread;
44 class GraphicsContext3D;
45 class LayerChromium;
46 class LayerPainterChromium;
47 class TextureManager;
48
49 class CCLayerTreeHostClient {
50 public:
51     virtual void animateAndLayout(double frameBeginTime) = 0;
52     virtual PassOwnPtr<CCThread> createCompositorThread() = 0;
53     virtual PassRefPtr<GraphicsContext3D> createLayerTreeHostContext3D() = 0;
54     virtual PassOwnPtr<LayerPainterChromium> createRootLayerPainter() = 0;
55     virtual void didRecreateGraphicsContext(bool success) = 0;
56 #if !USE(THREADED_COMPOSITING)
57     virtual void scheduleComposite() = 0;
58 #endif
59 protected:
60     virtual ~CCLayerTreeHostClient() { }
61 };
62
63 struct CCSettings {
64     CCSettings()
65             : acceleratePainting(false)
66             , compositeOffscreen(false)
67             , enableCompositorThread(false)
68             , showFPSCounter(false)
69             , showPlatformLayerTree(false) { }
70     CCSettings(bool acceleratePainting, bool compositeOffscreen, bool enableCompositorThread, bool showFPSCounter, bool showPlatformLayerTree)
71             : acceleratePainting(acceleratePainting)
72             , compositeOffscreen(compositeOffscreen)
73             , enableCompositorThread(enableCompositorThread)
74             , showFPSCounter(showFPSCounter)
75             , showPlatformLayerTree(showPlatformLayerTree) { }
76
77     bool acceleratePainting;
78     bool compositeOffscreen;
79     bool enableCompositorThread;
80     bool showFPSCounter;
81     bool showPlatformLayerTree;
82 };
83
84 // Provides information on an Impl's rendering capabilities back to the CCLayerTreeHost
85 struct LayerRendererCapabilities {
86     LayerRendererCapabilities()
87         : bestTextureFormat(0)
88         , usingMapSub(false)
89         , usingAcceleratedPainting(false)
90         , maxTextureSize(0) { }
91
92     GC3Denum bestTextureFormat;
93     bool usingMapSub;
94     bool usingAcceleratedPainting;
95     int maxTextureSize;
96 };
97
98 class CCLayerTreeHost : public RefCounted<CCLayerTreeHost> {
99 public:
100     static PassRefPtr<CCLayerTreeHost> create(CCLayerTreeHostClient*, PassRefPtr<LayerChromium> rootLayer, const CCSettings&);
101     virtual ~CCLayerTreeHost();
102
103     // CCLayerTreeHost interface to CCProxy.
104     void animateAndLayout(double frameBeginTime);
105     void commitComplete();
106     void commitTo(CCLayerTreeHostImpl*);
107     PassOwnPtr<CCThread> createCompositorThread();
108     PassRefPtr<GraphicsContext3D> createLayerTreeHostContext3D();
109     virtual PassOwnPtr<CCLayerTreeHostImpl> createLayerTreeHostImpl();
110     void didRecreateGraphicsContext(bool success);
111 #if !USE(THREADED_COMPOSITING)
112     void scheduleComposite();
113 #endif
114
115     // CCLayerTreeHost interface to WebView.
116     bool animating() const { return m_animating; }
117     void setAnimating(bool animating) { m_animating = animating; } // Can be removed when non-threaded scheduling moves inside.
118
119     CCLayerTreeHostClient* client() { return m_client; }
120
121 #if !USE(THREADED_COMPOSITING)
122     void composite();
123 #endif
124
125     GraphicsContext3D* context();
126
127     // Composites and attempts to read back the result into the provided
128     // buffer. If it wasn't possible, e.g. due to context lost, will return
129     // false.
130     bool compositeAndReadback(void *pixels, const IntRect&);
131
132     void finishAllRendering();
133
134     int frameNumber() const { return m_frameNumber; }
135
136     void setZoomAnimatorScale(double);
137
138     const LayerRendererCapabilities& layerRendererCapabilities() const;
139
140     // Test-only hook
141     void loseCompositorContext(int numTimes);
142
143     void setNeedsCommitAndRedraw();
144     void setNeedsRedraw();
145
146     LayerChromium* rootLayer() { return m_rootLayer.get(); }
147     const LayerChromium* rootLayer() const { return m_rootLayer.get(); }
148
149     const CCSettings& settings() const { return m_settings; }
150
151     void setViewport(const IntSize& viewportSize);
152
153     const IntSize& viewportSize() const { return m_viewportSize; }
154     TextureManager* contentsTextureManager() const;
155
156     void setVisible(bool);
157
158     void updateLayers();
159
160     void deleteContentsTextures(GraphicsContext3D*);
161
162 protected:
163     CCLayerTreeHost(CCLayerTreeHostClient*, PassRefPtr<LayerChromium> rootLayer, const CCSettings&);
164     bool initialize();
165
166 private:
167     typedef Vector<RefPtr<LayerChromium> > LayerList;
168
169     void paintLayerContents(const LayerList&);
170     void updateLayers(LayerChromium*);
171     void updateCompositorResources(const LayerList&, GraphicsContext3D*);
172     void updateCompositorResources(LayerChromium*, GraphicsContext3D*);
173     void clearPendingUpdate();
174
175     bool m_animating;
176
177     CCLayerTreeHostClient* m_client;
178
179     int m_frameNumber;
180
181     OwnPtr<CCProxy> m_proxy;
182
183     RefPtr<LayerChromium> m_rootLayer;
184     OwnPtr<TextureManager> m_contentsTextureManager;
185
186     LayerList m_updateList;
187
188     CCSettings m_settings;
189
190     IntSize m_viewportSize;
191     double m_zoomAnimatorScale;
192     bool m_visible;
193 };
194
195 }
196
197 #endif