|
1 /* |
|
2 * Copyright (C) 2010 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 |
|
26 #if USE(ACCELERATED_COMPOSITING) |
|
27 |
|
28 #include "LayerBackedDrawingArea.h" |
|
29 |
|
30 #include "DrawingAreaMessageKinds.h" |
|
31 #include "DrawingAreaProxyMessageKinds.h" |
|
32 #include "MessageID.h" |
|
33 #include "WebCoreArgumentCoders.h" |
|
34 #include "WebPage.h" |
|
35 #include "WebProcess.h" |
|
36 #include <WebCore/GraphicsLayer.h> |
|
37 |
|
38 using namespace WebCore; |
|
39 |
|
40 namespace WebKit { |
|
41 |
|
42 LayerBackedDrawingArea::LayerBackedDrawingArea(WebPage* webPage) |
|
43 : DrawingArea(LayerBackedDrawingAreaType, webPage) |
|
44 , m_syncTimer(WebProcess::shared().runLoop(), this, &LayerBackedDrawingArea::syncCompositingLayers) |
|
45 #if PLATFORM(MAC) && HAVE(HOSTED_CORE_ANIMATION) |
|
46 , m_remoteLayerRef(0) |
|
47 #endif |
|
48 , m_attached(false) |
|
49 , m_shouldPaint(true) |
|
50 { |
|
51 m_backingLayer = GraphicsLayer::create(this); |
|
52 m_backingLayer->setDrawsContent(true); |
|
53 #ifndef NDEBUG |
|
54 m_backingLayer->setName("DrawingArea backing layer"); |
|
55 #endif |
|
56 m_backingLayer->syncCompositingStateForThisLayerOnly(); |
|
57 m_backingLayer->setContentsOrientation(GraphicsLayer::CompositingCoordinatesBottomUp); |
|
58 |
|
59 platformInit(); |
|
60 } |
|
61 |
|
62 LayerBackedDrawingArea::~LayerBackedDrawingArea() |
|
63 { |
|
64 platformClear(); |
|
65 } |
|
66 |
|
67 void LayerBackedDrawingArea::invalidateWindow(const IntRect& rect, bool immediate) |
|
68 { |
|
69 |
|
70 } |
|
71 |
|
72 void LayerBackedDrawingArea::invalidateContentsAndWindow(const IntRect& rect, bool immediate) |
|
73 { |
|
74 setNeedsDisplay(rect); |
|
75 } |
|
76 |
|
77 void LayerBackedDrawingArea::invalidateContentsForSlowScroll(const IntRect& rect, bool immediate) |
|
78 { |
|
79 setNeedsDisplay(rect); |
|
80 } |
|
81 |
|
82 void LayerBackedDrawingArea::scroll(const IntSize& scrollDelta, const IntRect& rectToScroll, const IntRect& clipRect) |
|
83 { |
|
84 // FIXME: Do something much smarter. |
|
85 setNeedsDisplay(rectToScroll); |
|
86 } |
|
87 |
|
88 void LayerBackedDrawingArea::setNeedsDisplay(const IntRect& rect) |
|
89 { |
|
90 m_backingLayer->setNeedsDisplayInRect(rect); |
|
91 m_backingLayer->syncCompositingStateForThisLayerOnly(); |
|
92 |
|
93 #if PLATFORM(MAC) |
|
94 scheduleUpdateLayoutRunLoopObserver(); |
|
95 #endif |
|
96 } |
|
97 |
|
98 void LayerBackedDrawingArea::display() |
|
99 { |
|
100 // Layout if necessary. |
|
101 m_webPage->layoutIfNeeded(); |
|
102 } |
|
103 |
|
104 void LayerBackedDrawingArea::scheduleDisplay() |
|
105 { |
|
106 } |
|
107 |
|
108 void LayerBackedDrawingArea::setSize(const IntSize& viewSize) |
|
109 { |
|
110 ASSERT(m_shouldPaint); |
|
111 ASSERT_ARG(viewSize, !viewSize.isEmpty()); |
|
112 |
|
113 m_backingLayer->setSize(viewSize); |
|
114 m_backingLayer->syncCompositingStateForThisLayerOnly(); |
|
115 |
|
116 m_webPage->setSize(viewSize); |
|
117 |
|
118 // Layout if necessary. |
|
119 m_webPage->layoutIfNeeded(); |
|
120 |
|
121 WebProcess::shared().connection()->send(DrawingAreaProxyMessage::DidSetSize, m_webPage->pageID(), CoreIPC::In()); |
|
122 } |
|
123 |
|
124 void LayerBackedDrawingArea::suspendPainting() |
|
125 { |
|
126 ASSERT(m_shouldPaint); |
|
127 |
|
128 m_shouldPaint = false; |
|
129 } |
|
130 |
|
131 void LayerBackedDrawingArea::resumePainting() |
|
132 { |
|
133 ASSERT(!m_shouldPaint); |
|
134 |
|
135 m_shouldPaint = true; |
|
136 |
|
137 // Display if needed. |
|
138 display(); |
|
139 } |
|
140 |
|
141 void LayerBackedDrawingArea::didUpdate() |
|
142 { |
|
143 // Display if needed. |
|
144 display(); |
|
145 } |
|
146 |
|
147 void LayerBackedDrawingArea::didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder& arguments) |
|
148 { |
|
149 switch (messageID.get<DrawingAreaMessage::Kind>()) { |
|
150 case DrawingAreaMessage::SetSize: { |
|
151 IntSize size; |
|
152 if (!arguments.decode(CoreIPC::Out(size))) |
|
153 return; |
|
154 |
|
155 setSize(size); |
|
156 break; |
|
157 } |
|
158 |
|
159 case DrawingAreaMessage::SuspendPainting: |
|
160 suspendPainting(); |
|
161 break; |
|
162 |
|
163 case DrawingAreaMessage::ResumePainting: |
|
164 resumePainting(); |
|
165 break; |
|
166 |
|
167 case DrawingAreaMessage::DidUpdate: |
|
168 didUpdate(); |
|
169 break; |
|
170 |
|
171 default: |
|
172 ASSERT_NOT_REACHED(); |
|
173 break; |
|
174 } |
|
175 } |
|
176 |
|
177 // GraphicsLayerClient methods |
|
178 void LayerBackedDrawingArea::paintContents(const GraphicsLayer*, GraphicsContext& graphicsContext, GraphicsLayerPaintingPhase, const IntRect& inClip) |
|
179 { |
|
180 m_webPage->drawRect(graphicsContext, inClip); |
|
181 } |
|
182 |
|
183 bool LayerBackedDrawingArea::showDebugBorders() const |
|
184 { |
|
185 // FIXME: get from settings; |
|
186 return false; |
|
187 } |
|
188 |
|
189 bool LayerBackedDrawingArea::showRepaintCounter() const |
|
190 { |
|
191 // FIXME: get from settings; |
|
192 return false; |
|
193 } |
|
194 |
|
195 #if !PLATFORM(MAC) |
|
196 void LayerBackedDrawingArea::attachCompositingContext(GraphicsLayer*) |
|
197 { |
|
198 } |
|
199 |
|
200 void LayerBackedDrawingArea::detachCompositingContext() |
|
201 { |
|
202 } |
|
203 |
|
204 #if !PLATFORM(MAC) |
|
205 void LayerBackedDrawingArea::setRootCompositingLayer(WebCore::GraphicsLayer*) |
|
206 { |
|
207 } |
|
208 #endif |
|
209 |
|
210 void LayerBackedDrawingArea::scheduleCompositingLayerSync() |
|
211 { |
|
212 } |
|
213 |
|
214 void LayerBackedDrawingArea::syncCompositingLayers() |
|
215 { |
|
216 } |
|
217 |
|
218 void LayerBackedDrawingArea::platformInit() |
|
219 { |
|
220 } |
|
221 |
|
222 void LayerBackedDrawingArea::platformClear() |
|
223 { |
|
224 } |
|
225 #endif |
|
226 |
|
227 } // namespace WebKit |
|
228 |
|
229 #endif // USE(ACCELERATED_COMPOSITING) |