|
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 #include "ChunkedUpdateDrawingArea.h" |
|
27 |
|
28 #include "DrawingAreaMessageKinds.h" |
|
29 #include "DrawingAreaProxyMessageKinds.h" |
|
30 #include "MessageID.h" |
|
31 #include "UpdateChunk.h" |
|
32 #include "WebCoreArgumentCoders.h" |
|
33 #include "WebPage.h" |
|
34 #include "WebProcess.h" |
|
35 |
|
36 using namespace WebCore; |
|
37 |
|
38 namespace WebKit { |
|
39 |
|
40 ChunkedUpdateDrawingArea::ChunkedUpdateDrawingArea(WebPage* webPage) |
|
41 : DrawingArea(ChunkedUpdateDrawingAreaType, webPage) |
|
42 , m_isWaitingForUpdate(false) |
|
43 , m_paintingIsSuspended(false) |
|
44 , m_displayTimer(WebProcess::shared().runLoop(), this, &ChunkedUpdateDrawingArea::display) |
|
45 { |
|
46 } |
|
47 |
|
48 ChunkedUpdateDrawingArea::~ChunkedUpdateDrawingArea() |
|
49 { |
|
50 } |
|
51 |
|
52 void ChunkedUpdateDrawingArea::invalidateWindow(const IntRect& rect, bool immediate) |
|
53 { |
|
54 } |
|
55 |
|
56 void ChunkedUpdateDrawingArea::invalidateContentsAndWindow(const IntRect& rect, bool immediate) |
|
57 { |
|
58 setNeedsDisplay(rect); |
|
59 } |
|
60 |
|
61 void ChunkedUpdateDrawingArea::invalidateContentsForSlowScroll(const IntRect& rect, bool immediate) |
|
62 { |
|
63 setNeedsDisplay(rect); |
|
64 } |
|
65 |
|
66 void ChunkedUpdateDrawingArea::scroll(const IntSize& scrollDelta, const IntRect& rectToScroll, const IntRect& clipRect) |
|
67 { |
|
68 // FIXME: Do something much smarter. |
|
69 setNeedsDisplay(rectToScroll); |
|
70 } |
|
71 |
|
72 void ChunkedUpdateDrawingArea::setNeedsDisplay(const IntRect& rect) |
|
73 { |
|
74 // FIXME: Collect a set of rects/region instead of just the union |
|
75 // of all rects. |
|
76 m_dirtyRect.unite(rect); |
|
77 scheduleDisplay(); |
|
78 } |
|
79 |
|
80 void ChunkedUpdateDrawingArea::display() |
|
81 { |
|
82 ASSERT(!m_isWaitingForUpdate); |
|
83 |
|
84 if (m_paintingIsSuspended) |
|
85 return; |
|
86 |
|
87 if (m_dirtyRect.isEmpty()) |
|
88 return; |
|
89 |
|
90 // Layout if necessary. |
|
91 m_webPage->layoutIfNeeded(); |
|
92 |
|
93 IntRect dirtyRect = m_dirtyRect; |
|
94 m_dirtyRect = IntRect(); |
|
95 |
|
96 // Create a new UpdateChunk and paint into it. |
|
97 UpdateChunk updateChunk(dirtyRect); |
|
98 paintIntoUpdateChunk(&updateChunk); |
|
99 |
|
100 WebProcess::shared().connection()->send(DrawingAreaProxyMessage::Update, m_webPage->pageID(), CoreIPC::In(updateChunk)); |
|
101 |
|
102 m_isWaitingForUpdate = true; |
|
103 m_displayTimer.stop(); |
|
104 } |
|
105 |
|
106 void ChunkedUpdateDrawingArea::scheduleDisplay() |
|
107 { |
|
108 if (m_paintingIsSuspended) |
|
109 return; |
|
110 |
|
111 if (m_isWaitingForUpdate) |
|
112 return; |
|
113 |
|
114 if (m_dirtyRect.isEmpty()) |
|
115 return; |
|
116 |
|
117 if (m_displayTimer.isActive()) |
|
118 return; |
|
119 |
|
120 m_displayTimer.startOneShot(0); |
|
121 } |
|
122 |
|
123 void ChunkedUpdateDrawingArea::setSize(const IntSize& viewSize) |
|
124 { |
|
125 ASSERT_ARG(viewSize, !viewSize.isEmpty()); |
|
126 |
|
127 // We don't want to wait for an update until we display. |
|
128 m_isWaitingForUpdate = false; |
|
129 |
|
130 m_webPage->setSize(viewSize); |
|
131 |
|
132 // Layout if necessary. |
|
133 m_webPage->layoutIfNeeded(); |
|
134 |
|
135 if (m_paintingIsSuspended) { |
|
136 ASSERT(!m_displayTimer.isActive()); |
|
137 |
|
138 // Painting is suspended, just send back an empty update chunk. |
|
139 WebProcess::shared().connection()->send(DrawingAreaProxyMessage::DidSetSize, m_webPage->pageID(), CoreIPC::In(UpdateChunk())); |
|
140 return; |
|
141 } |
|
142 |
|
143 // Create a new UpdateChunk and paint into it. |
|
144 UpdateChunk updateChunk(IntRect(0, 0, viewSize.width(), viewSize.height())); |
|
145 paintIntoUpdateChunk(&updateChunk); |
|
146 |
|
147 m_displayTimer.stop(); |
|
148 |
|
149 WebProcess::shared().connection()->send(DrawingAreaProxyMessage::DidSetSize, m_webPage->pageID(), CoreIPC::In(updateChunk)); |
|
150 } |
|
151 |
|
152 void ChunkedUpdateDrawingArea::suspendPainting() |
|
153 { |
|
154 ASSERT(!m_paintingIsSuspended); |
|
155 |
|
156 m_paintingIsSuspended = true; |
|
157 m_displayTimer.stop(); |
|
158 } |
|
159 |
|
160 void ChunkedUpdateDrawingArea::resumePainting(bool forceRepaint) |
|
161 { |
|
162 ASSERT(m_paintingIsSuspended); |
|
163 |
|
164 m_paintingIsSuspended = false; |
|
165 |
|
166 if (forceRepaint) { |
|
167 // Just set the dirty rect to the entire page size. |
|
168 m_dirtyRect = IntRect(IntPoint(0, 0), m_webPage->size()); |
|
169 } |
|
170 |
|
171 // Schedule a display. |
|
172 scheduleDisplay(); |
|
173 } |
|
174 |
|
175 void ChunkedUpdateDrawingArea::didUpdate() |
|
176 { |
|
177 m_isWaitingForUpdate = false; |
|
178 |
|
179 // Display if needed. |
|
180 display(); |
|
181 } |
|
182 |
|
183 void ChunkedUpdateDrawingArea::didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder& arguments) |
|
184 { |
|
185 switch (messageID.get<DrawingAreaMessage::Kind>()) { |
|
186 case DrawingAreaMessage::SetSize: { |
|
187 IntSize size; |
|
188 if (!arguments.decode(CoreIPC::Out(size))) |
|
189 return; |
|
190 |
|
191 setSize(size); |
|
192 break; |
|
193 } |
|
194 |
|
195 case DrawingAreaMessage::SuspendPainting: |
|
196 suspendPainting(); |
|
197 break; |
|
198 |
|
199 case DrawingAreaMessage::ResumePainting: { |
|
200 bool forceRepaint; |
|
201 if (!arguments.decode(CoreIPC::Out(forceRepaint))) |
|
202 return; |
|
203 |
|
204 resumePainting(forceRepaint); |
|
205 break; |
|
206 } |
|
207 case DrawingAreaMessage::DidUpdate: |
|
208 didUpdate(); |
|
209 break; |
|
210 |
|
211 default: |
|
212 ASSERT_NOT_REACHED(); |
|
213 break; |
|
214 } |
|
215 } |
|
216 |
|
217 } // namespace WebKit |