2 * Copyright (C) 2009 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef WKCACFLayerRenderer_h
27 #define WKCACFLayerRenderer_h
29 #if USE(ACCELERATED_COMPOSITING)
33 #include "WKCACFLayer.h"
35 #include <wtf/Noncopyable.h>
37 #include <wtf/PassRefPtr.h>
38 #include <wtf/RefPtr.h>
39 #include <wtf/RetainPtr.h>
41 #include <CoreGraphics/CGGeometry.h>
43 interface IDirect3DDevice9;
48 class WKCACFRootLayer;
50 class WKCACFLayerRendererClient {
52 virtual ~WKCACFLayerRendererClient() { }
53 virtual bool shouldRender() const = 0;
56 // FIXME: Currently there is a WKCACFLayerRenderer for each WebView and each
57 // has its own CARenderOGLContext and Direct3DDevice9, which is inefficient.
58 // (https://bugs.webkit.org/show_bug.cgi?id=31855)
59 class WKCACFLayerRenderer : public Noncopyable {
61 static PassOwnPtr<WKCACFLayerRenderer> create(WKCACFLayerRendererClient*);
62 ~WKCACFLayerRenderer();
64 static bool acceleratedCompositingAvailable();
65 static void didFlushContext(WKCACFContext*);
67 void setRootContents(CGImageRef);
68 void setRootContentsAndDisplay(CGImageRef);
69 void setRootChildLayer(WKCACFLayer* layer);
70 void layerTreeDidChange();
71 void setNeedsDisplay();
72 void setHostWindow(HWND window) { m_hostWindow = window; }
73 void setBackingStoreDirty(bool dirty) { m_backingStoreDirty = dirty; }
74 bool createRenderer();
75 void destroyRenderer();
80 WKCACFLayer* rootLayer() const;
83 WKCACFLayerRenderer(WKCACFLayerRendererClient*);
85 void renderTimerFired(Timer<WKCACFLayerRenderer>*);
87 CGRect bounds() const;
89 void initD3DGeometry();
91 // Call this when the device window has changed size or when IDirect3DDevice9::Present returns
92 // D3DERR_DEVICELOST. Returns true if the device was recovered, false if rendering must be
93 // aborted and reattempted soon.
94 enum ResetReason { ChangedWindowSize, LostDevice };
95 bool resetDevice(ResetReason);
97 void render(const Vector<CGRect>& dirtyRects = Vector<CGRect>());
100 WKCACFLayerRendererClient* m_client;
101 bool m_mightBeAbleToCreateDeviceLater;
102 COMPtr<IDirect3DDevice9> m_d3dDevice;
103 RefPtr<WKCACFRootLayer> m_rootLayer;
104 RefPtr<WKCACFLayer> m_rootChildLayer;
105 WKCACFContext* m_context;
107 Timer<WKCACFLayerRenderer> m_renderTimer;
108 bool m_backingStoreDirty;
109 bool m_mustResetLostDeviceBeforeRendering;
117 #endif // USE(ACCELERATED_COMPOSITING)
119 #endif // WKCACFLayerRenderer_h