Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(391)

Side by Side Diff: WebCore/platform/graphics/skia/LayerSkia.cpp

Issue 650002: Implementing ACCELERATED_COMPOSITING via Skia Base URL: http://svn.webkit.org/repository/webkit/trunk/
Patch Set: '' Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « WebCore/platform/graphics/skia/LayerSkia.h ('k') | WebKit/chromium/src/ChromeClientImpl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2010, 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 are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31
32 #include "config.h"
33
34 #if USE(ACCELERATED_COMPOSITING)
35
36 #include "LayerSkia.h"
37 #include "PlatformContextSkia.h"
38 #include "RenderLayerBacking.h"
39
40 #include "skia/ext/platform_canvas.h"
41
42 namespace WebCore {
43
44 using namespace std;
45
46
47 PassRefPtr<LayerSkia> LayerSkia::create(LayerType type, GraphicsLayerSkia* owner )
48 {
49 return adoptRef(new LayerSkia(type, owner));
50 }
51
52 LayerSkia::LayerSkia(LayerType type, GraphicsLayerSkia* owner)
53 : m_needsDisplayOnBoundsChange(false)
54 , m_owner(owner)
55 , m_layerType(type)
56 , m_superlayer(0)
57 , m_borderWidth(0)
58 , m_borderColor(0, 0, 0, 0)
59 , m_backgroundColor(0, 0, 0, 0)
60 , m_anchorPointZ(0)
61 , m_clearsContext(false)
62 , m_doubleSided(false)
63 , m_edgeAntialiasingMask(0)
64 , m_hidden(false)
65 , m_masksToBounds(false)
66 , m_contentsGravity(Bottom)
67 , m_opacity(1.0)
68 , m_opaque(true)
69 , m_zPosition(0.0)
70 , m_canvas(0)
71 , m_skiaContext(0)
72 , m_graphicsContext(0)
73 , m_geometryFlipped(false)
74 {
75 m_bounds.setEmpty();
76 m_backingStoreRect.setEmpty();
77 m_frame.setEmpty();
78 m_position.set(0, 0);
79 m_anchorPoint.set(0, 0);
80 m_transform.reset();
81 m_sublayerTransform.reset();
82
83 updateGraphicsContext(m_backingStoreRect);
84 }
85
86 LayerSkia::~LayerSkia()
87 {
88 // Our superlayer should be holding a reference to us, so there should be no way for us to be destroyed while we still have a superlayer.
89 ASSERT(!superlayer());
90
91 delete m_graphicsContext;
92 delete m_skiaContext;
93 delete m_canvas;
94 }
95
96 void LayerSkia::updateGraphicsContext(const SkIRect& rect)
97 {
98 if (m_graphicsContext)
99 delete m_graphicsContext;
100 if (m_skiaContext)
101 delete m_skiaContext;
102 if (m_canvas)
103 delete m_canvas;
104
105 m_canvas = new skia::PlatformCanvas(rect.width(), rect.height(), false);
106 m_skiaContext = new PlatformContextSkia(m_canvas);
107
108 // This is needed to get text to show up correctly. Without it,
109 // GDI renders with zero alpha and the text becomes invisible.
110 // Unfortunately, setting this to true disables cleartype.
111 m_skiaContext->setDrawingToImageBuffer(true);
112
113 m_graphicsContext = new GraphicsContext(reinterpret_cast<PlatformGraphicsCon text*>(m_skiaContext));
114
115 // Backing store a layer could be different than then layer's bounds.
116 // This is mostly true for the root layer that's sized based on the view
117 // size rather than the actual layer size.
118 m_backingStoreRect = rect;
119 }
120
121 void LayerSkia::updateContents()
122 {
123 RenderLayerBacking* backing = static_cast<RenderLayerBacking*>(m_owner->clie nt());
124
125 if (backing && !backing->paintingGoesToWindow()) {
126 m_owner->paintGraphicsLayerContents(*m_graphicsContext, IntRect(0, 0, m_ bounds.width(), m_bounds.height()));
127 }
128
129 // Paint the debug border.
130 // TODO(vangelis): Add a flag to check if debug borders are used.
131 m_graphicsContext->setStrokeColor(m_borderColor, DeviceColorSpace);
132 m_graphicsContext->setStrokeThickness(m_borderWidth);
133 m_graphicsContext->drawLine(IntPoint(0, 0), IntPoint(m_bounds.width(), 0));
134 m_graphicsContext->drawLine(IntPoint(0, 0), IntPoint(0, m_bounds.height()));
135 m_graphicsContext->drawLine(IntPoint(m_bounds.width(), 0), IntPoint(m_bounds .width(), m_bounds.height()));
136 m_graphicsContext->drawLine(IntPoint(0, m_bounds.height()), IntPoint(m_bound s.width(), m_bounds.height()));
137 }
138
139
140 void LayerSkia::setNeedsCommit()
141 {
142 // Call notifySyncRequired(), which in this implementation plumbs through to
143 // call setRootLayerNeedsDisplay() on the WebView, which causes the CACFRend erer
144 // to render a frame.
145 if (m_owner)
146 m_owner->notifySyncRequired();
147 }
148
149 void LayerSkia::addSublayer(PassRefPtr<LayerSkia> sublayer)
150 {
151 insertSublayer(sublayer, numSublayers());
152 }
153
154 void LayerSkia::insertSublayer(PassRefPtr<LayerSkia> sublayer, size_t index)
155 {
156 index = min(index, m_sublayers.size());
157 m_sublayers.insert(index, sublayer);
158 sublayer->setSuperlayer(this);
159 setNeedsCommit();
160 }
161
162 void LayerSkia::replaceSublayer(LayerSkia* reference, PassRefPtr<LayerSkia> newL ayer)
163 {
164 ASSERT_ARG(reference, reference);
165 ASSERT_ARG(reference, reference->superlayer() == this);
166
167 if (reference == newLayer)
168 return;
169
170 if (!newLayer) {
171 removeSublayer(reference);
172 return;
173 }
174
175 newLayer->removeFromSuperlayer();
176
177 int referenceIndex = indexOfSublayer(reference);
178 ASSERT(referenceIndex != -1);
179 if (referenceIndex == -1)
180 return;
181
182 reference->removeFromSuperlayer();
183 insertSublayer(newLayer, referenceIndex);
184 }
185
186 void LayerSkia::removeFromSuperlayer()
187 {
188 LayerSkia* superlayer = this->superlayer();
189 if (!superlayer)
190 return;
191
192 superlayer->removeSublayer(this);
193 superlayer->setNeedsCommit();
194 }
195
196 void LayerSkia::removeSublayer(LayerSkia* sublayer)
197 {
198 int foundIndex = indexOfSublayer(sublayer);
199 if (foundIndex == -1)
200 return;
201
202 m_sublayers.remove(foundIndex);
203 sublayer->setSuperlayer(0);
204 setNeedsCommit();
205 }
206
207 int LayerSkia::indexOfSublayer(const LayerSkia* reference)
208 {
209 for (size_t i = 0; i < m_sublayers.size(); i++) {
210 if (m_sublayers[i] == reference)
211 return i;
212 }
213 return -1;
214 }
215
216 LayerSkia* LayerSkia::ancestorOrSelfWithSuperlayer(LayerSkia* superlayer) const
217 {
218 LayerSkia* layer = const_cast<LayerSkia*>(this);
219 for (LayerSkia* ancestor = this->superlayer(); ancestor; layer = ancestor, a ncestor = ancestor->superlayer()) {
220 if (ancestor == superlayer)
221 return layer;
222 }
223 return 0;
224 }
225
226 void LayerSkia::setBackingStoreRect(const SkIRect& rect)
227 {
228 if (m_backingStoreRect == rect)
229 return;
230
231 updateGraphicsContext(rect);
232 }
233
234
235 void LayerSkia::setBounds(const SkIRect& rect)
236 {
237 if (rect == m_bounds)
238 return;
239
240 m_bounds = rect;
241
242 // Re-create the canvas and associated contexts.
243 updateGraphicsContext(m_bounds);
244
245 setNeedsCommit();
246 }
247
248 void LayerSkia::setFrame(const SkRect& rect)
249 {
250 m_frame = rect;
251 setNeedsCommit();
252 }
253
254
255 LayerSkia* LayerSkia::rootLayer() const
256 {
257 LayerSkia* layer = const_cast<LayerSkia*>(this);
258 for (LayerSkia* superlayer = layer->superlayer(); superlayer; layer = superl ayer, superlayer = superlayer->superlayer()) { }
259 return layer;
260 }
261
262 void LayerSkia::removeAllSublayers()
263 {
264 m_sublayers.clear();
265 setNeedsCommit();
266 }
267
268 void LayerSkia::setSublayers(const Vector<RefPtr<LayerSkia> >& sublayers)
269 {
270 m_sublayers = sublayers;
271 }
272
273 void LayerSkia::setSuperlayer(LayerSkia* superlayer)
274 {
275 m_superlayer = superlayer;
276 }
277
278 LayerSkia* LayerSkia::superlayer() const
279 {
280 return m_superlayer;
281 }
282
283 void LayerSkia::setNeedsDisplay(const SkRect& dirtyRect)
284 {
285 // TODO(vangelis): implement
286 setNeedsCommit();
287 }
288
289 void LayerSkia::setNeedsDisplay()
290 {
291 // TODO(vangelis): implement
292 }
293
294
295 }
296
297 #endif // USE(ACCELERATED_COMPOSITING)
OLDNEW
« no previous file with comments | « WebCore/platform/graphics/skia/LayerSkia.h ('k') | WebKit/chromium/src/ChromeClientImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698