• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 WKCACFLayerRenderer_h
27 #define WKCACFLayerRenderer_h
28 
29 #if USE(ACCELERATED_COMPOSITING)
30 
31 #include "COMPtr.h"
32 #include "Timer.h"
33 #include "WKCACFLayer.h"
34 
35 #include <wtf/Noncopyable.h>
36 
37 #include <wtf/PassRefPtr.h>
38 #include <wtf/RefPtr.h>
39 #include <wtf/RetainPtr.h>
40 
41 #include <CoreGraphics/CGGeometry.h>
42 
43 interface IDirect3DDevice9;
44 typedef struct _CACFContext* CACFContextRef;
45 typedef struct _CARenderContext CARenderContext;
46 typedef struct _CARenderOGLContext CARenderOGLContext;
47 
48 namespace WebCore {
49 
50 // FIXME: Currently there is a WKCACFLayerRenderer for each WebView and each
51 // has its own CARenderOGLContext and Direct3DDevice9, which is inefficient.
52 // (https://bugs.webkit.org/show_bug.cgi?id=31855)
53 class WKCACFLayerRenderer : public Noncopyable {
54 public:
55     static PassOwnPtr<WKCACFLayerRenderer> create();
56     ~WKCACFLayerRenderer();
57 
58     static bool acceleratedCompositingAvailable();
59     static void didFlushContext(CACFContextRef);
60 
61     void setScrollFrame(const IntRect&);
62     void setRootContents(CGImageRef);
63     void setRootChildLayer(WebCore::PlatformLayer* layer);
64     void setNeedsDisplay();
setHostWindow(HWND window)65     void setHostWindow(HWND window) { m_hostWindow = window; createRenderer(); }
66 
67     void createRenderer();
68     void destroyRenderer();
69     void resize();
70     void renderSoon();
71 
72 protected:
rootLayer()73     WKCACFLayer* rootLayer() const { return m_rootLayer.get(); }
74 
75 private:
76     WKCACFLayerRenderer();
77 
78     void renderTimerFired(Timer<WKCACFLayerRenderer>*);
79 
80     CGRect bounds() const;
81 
82     void initD3DGeometry();
83     void resetDevice();
84 
85     void render(const Vector<CGRect>& dirtyRects = Vector<CGRect>());
86     void paint();
87 
88     bool m_triedToCreateD3DRenderer;
89     COMPtr<IDirect3DDevice9> m_d3dDevice;
90     RefPtr<WKCACFLayer> m_rootLayer;
91     RefPtr<WKCACFLayer> m_viewLayer;
92     RefPtr<WKCACFLayer> m_scrollLayer;
93     RefPtr<WKCACFLayer> m_rootChildLayer;
94     RetainPtr<CACFContextRef> m_context;
95     CARenderContext* m_renderContext;
96     CARenderOGLContext* m_renderer;
97     HWND m_hostWindow;
98     Timer<WKCACFLayerRenderer> m_renderTimer;
99     IntRect m_scrollFrame;
100 
101 #ifndef NDEBUG
102     bool m_printTree;
103 #endif
104 };
105 
106 }
107 
108 #endif // USE(ACCELERATED_COMPOSITING)
109 
110 #endif // WKCACFLayerRenderer_h
111