1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 : * vim: sw=2 ts=8 et :
3 : */
4 : /* ***** BEGIN LICENSE BLOCK *****
5 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 : *
7 : * The contents of this file are subject to the Mozilla Public License Version
8 : * 1.1 (the "License"); you may not use this file except in compliance with
9 : * the License. You may obtain a copy of the License at:
10 : * http://www.mozilla.org/MPL/
11 : *
12 : * Software distributed under the License is distributed on an "AS IS" basis,
13 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 : * for the specific language governing rights and limitations under the
15 : * License.
16 : *
17 : * The Original Code is Mozilla Code.
18 : *
19 : * The Initial Developer of the Original Code is
20 : * The Mozilla Foundation
21 : * Portions created by the Initial Developer are Copyright (C) 2010
22 : * the Initial Developer. All Rights Reserved.
23 : *
24 : * Contributor(s):
25 : * Chris Jones <jones.chris.g@gmail.com>
26 : *
27 : * Alternatively, the contents of this file may be used under the terms of
28 : * either the GNU General Public License Version 2 or later (the "GPL"), or
29 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 : * in which case the provisions of the GPL or the LGPL are applicable instead
31 : * of those above. If you wish to allow use of your version of this file only
32 : * under the terms of either the GPL or the LGPL, and not to allow others to
33 : * use your version of this file under the terms of the MPL, indicate your
34 : * decision by deleting the provisions above and replace them with the notice
35 : * and other provisions required by the GPL or the LGPL. If you do not delete
36 : * the provisions above, a recipient may use your version of this file under
37 : * the terms of any one of the MPL, the GPL or the LGPL.
38 : *
39 : * ***** END LICENSE BLOCK ***** */
40 :
41 : #include <vector>
42 :
43 : #include "ShadowLayersParent.h"
44 : #include "ShadowLayerParent.h"
45 : #include "ShadowLayers.h"
46 : #include "RenderTrace.h"
47 :
48 : #include "mozilla/unused.h"
49 :
50 : #include "mozilla/layout/RenderFrameParent.h"
51 : #include "CompositorParent.h"
52 :
53 : #include "gfxSharedImageSurface.h"
54 :
55 : #include "ImageLayers.h"
56 :
57 : typedef std::vector<mozilla::layers::EditReply> EditReplyVector;
58 :
59 : using mozilla::layout::RenderFrameParent;
60 :
61 : namespace mozilla {
62 : namespace layers {
63 :
64 : //--------------------------------------------------
65 : // Convenience accessors
66 : static ShadowLayerParent*
67 0 : cast(const PLayerParent* in)
68 : {
69 : return const_cast<ShadowLayerParent*>(
70 0 : static_cast<const ShadowLayerParent*>(in));
71 : }
72 :
73 : template<class OpCreateT>
74 : static ShadowLayerParent*
75 0 : AsShadowLayer(const OpCreateT& op)
76 : {
77 0 : return cast(op.layerParent());
78 : }
79 :
80 : static ShadowLayerParent*
81 0 : AsShadowLayer(const OpSetRoot& op)
82 : {
83 0 : return cast(op.rootParent());
84 : }
85 :
86 : static ShadowLayerParent*
87 0 : ShadowContainer(const OpInsertAfter& op)
88 : {
89 0 : return cast(op.containerParent());
90 : }
91 : static ShadowLayerParent*
92 0 : ShadowChild(const OpInsertAfter& op)
93 : {
94 0 : return cast(op.childLayerParent());
95 : }
96 : static ShadowLayerParent*
97 0 : ShadowAfter(const OpInsertAfter& op)
98 : {
99 0 : return cast(op.afterParent());
100 : }
101 :
102 : static ShadowLayerParent*
103 0 : ShadowContainer(const OpAppendChild& op)
104 : {
105 0 : return cast(op.containerParent());
106 : }
107 : static ShadowLayerParent*
108 0 : ShadowChild(const OpAppendChild& op)
109 : {
110 0 : return cast(op.childLayerParent());
111 : }
112 :
113 : static ShadowLayerParent*
114 0 : ShadowContainer(const OpRemoveChild& op)
115 : {
116 0 : return cast(op.containerParent());
117 : }
118 : static ShadowLayerParent*
119 0 : ShadowChild(const OpRemoveChild& op)
120 : {
121 0 : return cast(op.childLayerParent());
122 : }
123 :
124 : //--------------------------------------------------
125 : // ShadowLayersParent
126 0 : ShadowLayersParent::ShadowLayersParent(ShadowLayerManager* aManager,
127 : ShadowLayersManager* aLayersManager)
128 0 : : mLayerManager(aManager), mShadowLayersManager(aLayersManager), mDestroyed(false)
129 : {
130 0 : MOZ_COUNT_CTOR(ShadowLayersParent);
131 0 : }
132 :
133 0 : ShadowLayersParent::~ShadowLayersParent()
134 : {
135 0 : MOZ_COUNT_DTOR(ShadowLayersParent);
136 0 : }
137 :
138 : void
139 0 : ShadowLayersParent::Destroy()
140 : {
141 0 : mDestroyed = true;
142 0 : for (size_t i = 0; i < ManagedPLayerParent().Length(); ++i) {
143 : ShadowLayerParent* slp =
144 0 : static_cast<ShadowLayerParent*>(ManagedPLayerParent()[i]);
145 0 : slp->Destroy();
146 : }
147 0 : }
148 :
149 : bool
150 0 : ShadowLayersParent::RecvUpdate(const InfallibleTArray<Edit>& cset,
151 : InfallibleTArray<EditReply>* reply)
152 : {
153 0 : MOZ_LAYERS_LOG(("[ParentSide] received txn with %d edits", cset.Length()));
154 :
155 0 : if (mDestroyed || layer_manager()->IsDestroyed()) {
156 0 : return true;
157 : }
158 :
159 0 : EditReplyVector replyv;
160 :
161 0 : layer_manager()->BeginTransactionWithTarget(NULL);
162 :
163 0 : for (EditArray::index_type i = 0; i < cset.Length(); ++i) {
164 0 : const Edit& edit = cset[i];
165 :
166 0 : switch (edit.type()) {
167 : // Create* ops
168 : case Edit::TOpCreateThebesLayer: {
169 0 : MOZ_LAYERS_LOG(("[ParentSide] CreateThebesLayer"));
170 :
171 : nsRefPtr<ShadowThebesLayer> layer =
172 0 : layer_manager()->CreateShadowThebesLayer();
173 0 : layer->SetAllocator(this);
174 0 : AsShadowLayer(edit.get_OpCreateThebesLayer())->Bind(layer);
175 : break;
176 : }
177 : case Edit::TOpCreateContainerLayer: {
178 0 : MOZ_LAYERS_LOG(("[ParentSide] CreateContainerLayer"));
179 :
180 0 : nsRefPtr<ContainerLayer> layer = layer_manager()->CreateShadowContainerLayer();
181 0 : AsShadowLayer(edit.get_OpCreateContainerLayer())->Bind(layer);
182 : break;
183 : }
184 : case Edit::TOpCreateImageLayer: {
185 0 : MOZ_LAYERS_LOG(("[ParentSide] CreateImageLayer"));
186 :
187 : nsRefPtr<ShadowImageLayer> layer =
188 0 : layer_manager()->CreateShadowImageLayer();
189 0 : AsShadowLayer(edit.get_OpCreateImageLayer())->Bind(layer);
190 : break;
191 : }
192 : case Edit::TOpCreateColorLayer: {
193 0 : MOZ_LAYERS_LOG(("[ParentSide] CreateColorLayer"));
194 :
195 0 : nsRefPtr<ShadowColorLayer> layer = layer_manager()->CreateShadowColorLayer();
196 0 : AsShadowLayer(edit.get_OpCreateColorLayer())->Bind(layer);
197 : break;
198 : }
199 : case Edit::TOpCreateCanvasLayer: {
200 0 : MOZ_LAYERS_LOG(("[ParentSide] CreateCanvasLayer"));
201 :
202 : nsRefPtr<ShadowCanvasLayer> layer =
203 0 : layer_manager()->CreateShadowCanvasLayer();
204 0 : layer->SetAllocator(this);
205 0 : AsShadowLayer(edit.get_OpCreateCanvasLayer())->Bind(layer);
206 : break;
207 : }
208 :
209 : // Attributes
210 : case Edit::TOpSetLayerAttributes: {
211 0 : MOZ_LAYERS_LOG(("[ParentSide] SetLayerAttributes"));
212 :
213 0 : const OpSetLayerAttributes& osla = edit.get_OpSetLayerAttributes();
214 0 : Layer* layer = AsShadowLayer(osla)->AsLayer();
215 0 : const LayerAttributes& attrs = osla.attrs();
216 :
217 0 : const CommonLayerAttributes& common = attrs.common();
218 0 : layer->SetVisibleRegion(common.visibleRegion());
219 0 : layer->SetContentFlags(common.contentFlags());
220 0 : layer->SetOpacity(common.opacity());
221 0 : layer->SetClipRect(common.useClipRect() ? &common.clipRect() : NULL);
222 0 : layer->SetTransform(common.transform());
223 0 : layer->SetTileSourceRect(common.useTileSourceRect() ? &common.tileSourceRect() : NULL);
224 0 : static bool fixedPositionLayersEnabled = getenv("MOZ_ENABLE_FIXED_POSITION_LAYERS") != 0;
225 0 : if (fixedPositionLayersEnabled) {
226 0 : layer->SetIsFixedPosition(common.isFixedPosition());
227 : }
228 :
229 : typedef SpecificLayerAttributes Specific;
230 0 : const SpecificLayerAttributes& specific = attrs.specific();
231 0 : switch (specific.type()) {
232 : case Specific::Tnull_t:
233 0 : break;
234 :
235 : case Specific::TThebesLayerAttributes: {
236 0 : MOZ_LAYERS_LOG(("[ParentSide] thebes layer"));
237 :
238 : ShadowThebesLayer* thebesLayer =
239 0 : static_cast<ShadowThebesLayer*>(layer);
240 : const ThebesLayerAttributes& attrs =
241 0 : specific.get_ThebesLayerAttributes();
242 :
243 0 : thebesLayer->SetValidRegion(attrs.validRegion());
244 :
245 0 : break;
246 : }
247 : case Specific::TContainerLayerAttributes:
248 0 : MOZ_LAYERS_LOG(("[ParentSide] container layer"));
249 :
250 : static_cast<ContainerLayer*>(layer)->SetFrameMetrics(
251 0 : specific.get_ContainerLayerAttributes().metrics());
252 0 : break;
253 :
254 : case Specific::TColorLayerAttributes:
255 0 : MOZ_LAYERS_LOG(("[ParentSide] color layer"));
256 :
257 : static_cast<ColorLayer*>(layer)->SetColor(
258 0 : specific.get_ColorLayerAttributes().color());
259 0 : break;
260 :
261 : case Specific::TCanvasLayerAttributes:
262 0 : MOZ_LAYERS_LOG(("[ParentSide] canvas layer"));
263 :
264 : static_cast<CanvasLayer*>(layer)->SetFilter(
265 0 : specific.get_CanvasLayerAttributes().filter());
266 0 : break;
267 :
268 : case Specific::TImageLayerAttributes:
269 0 : MOZ_LAYERS_LOG(("[ParentSide] image layer"));
270 :
271 : static_cast<ImageLayer*>(layer)->SetFilter(
272 0 : specific.get_ImageLayerAttributes().filter());
273 0 : break;
274 :
275 : default:
276 0 : NS_RUNTIMEABORT("not reached");
277 : }
278 0 : break;
279 : }
280 :
281 : // Tree ops
282 : case Edit::TOpSetRoot: {
283 0 : MOZ_LAYERS_LOG(("[ParentSide] SetRoot"));
284 :
285 0 : mRoot = AsShadowLayer(edit.get_OpSetRoot())->AsContainer();
286 0 : break;
287 : }
288 : case Edit::TOpInsertAfter: {
289 0 : MOZ_LAYERS_LOG(("[ParentSide] InsertAfter"));
290 :
291 0 : const OpInsertAfter& oia = edit.get_OpInsertAfter();
292 0 : ShadowContainer(oia)->AsContainer()->InsertAfter(
293 0 : ShadowChild(oia)->AsLayer(), ShadowAfter(oia)->AsLayer());
294 0 : break;
295 : }
296 : case Edit::TOpAppendChild: {
297 0 : MOZ_LAYERS_LOG(("[ParentSide] AppendChild"));
298 :
299 0 : const OpAppendChild& oac = edit.get_OpAppendChild();
300 0 : ShadowContainer(oac)->AsContainer()->InsertAfter(
301 0 : ShadowChild(oac)->AsLayer(), NULL);
302 0 : break;
303 : }
304 : case Edit::TOpRemoveChild: {
305 0 : MOZ_LAYERS_LOG(("[ParentSide] RemoveChild"));
306 :
307 0 : const OpRemoveChild& orc = edit.get_OpRemoveChild();
308 0 : Layer* childLayer = ShadowChild(orc)->AsLayer();
309 0 : ShadowContainer(orc)->AsContainer()->RemoveChild(childLayer);
310 0 : break;
311 : }
312 :
313 : case Edit::TOpPaintThebesBuffer: {
314 0 : MOZ_LAYERS_LOG(("[ParentSide] Paint ThebesLayer"));
315 :
316 0 : const OpPaintThebesBuffer& op = edit.get_OpPaintThebesBuffer();
317 0 : ShadowLayerParent* shadow = AsShadowLayer(op);
318 : ShadowThebesLayer* thebes =
319 0 : static_cast<ShadowThebesLayer*>(shadow->AsLayer());
320 0 : const ThebesBuffer& newFront = op.newFrontBuffer();
321 :
322 : #ifdef MOZ_RENDERTRACE
323 : RenderTraceInvalidateStart(thebes, "FF00FF", op.updatedRegion().GetBounds());
324 : #endif
325 :
326 0 : OptionalThebesBuffer newBack;
327 0 : nsIntRegion newValidRegion;
328 0 : OptionalThebesBuffer readonlyFront;
329 0 : nsIntRegion frontUpdatedRegion;
330 0 : thebes->Swap(newFront, op.updatedRegion(),
331 : &newBack, &newValidRegion,
332 0 : &readonlyFront, &frontUpdatedRegion);
333 : replyv.push_back(
334 : OpThebesBufferSwap(
335 : shadow, NULL,
336 : newBack, newValidRegion,
337 0 : readonlyFront, frontUpdatedRegion));
338 :
339 : #ifdef MOZ_RENDERTRACE
340 : RenderTraceInvalidateEnd(thebes, "FF00FF");
341 : #endif
342 : break;
343 : }
344 : case Edit::TOpPaintCanvas: {
345 0 : MOZ_LAYERS_LOG(("[ParentSide] Paint CanvasLayer"));
346 :
347 0 : const OpPaintCanvas& op = edit.get_OpPaintCanvas();
348 0 : ShadowLayerParent* shadow = AsShadowLayer(op);
349 : ShadowCanvasLayer* canvas =
350 0 : static_cast<ShadowCanvasLayer*>(shadow->AsLayer());
351 :
352 : #ifdef MOZ_RENDERTRACE
353 : RenderTraceInvalidateStart(canvas, "FF00FF", canvas->GetVisibleRegion().GetBounds());
354 : #endif
355 :
356 0 : canvas->SetAllocator(this);
357 0 : CanvasSurface newBack;
358 0 : canvas->Swap(op.newFrontBuffer(), op.needYFlip(), &newBack);
359 0 : canvas->Updated();
360 : replyv.push_back(OpBufferSwap(shadow, NULL,
361 0 : newBack));
362 :
363 : #ifdef MOZ_RENDERTRACE
364 : RenderTraceInvalidateEnd(canvas, "FF00FF");
365 : #endif
366 : break;
367 : }
368 : case Edit::TOpPaintImage: {
369 0 : MOZ_LAYERS_LOG(("[ParentSide] Paint ImageLayer"));
370 :
371 0 : const OpPaintImage& op = edit.get_OpPaintImage();
372 0 : ShadowLayerParent* shadow = AsShadowLayer(op);
373 : ShadowImageLayer* image =
374 0 : static_cast<ShadowImageLayer*>(shadow->AsLayer());
375 :
376 : #ifdef MOZ_RENDERTRACE
377 : RenderTraceInvalidateStart(image, "FF00FF", image->GetVisibleRegion().GetBounds());
378 : #endif
379 :
380 0 : image->SetAllocator(this);
381 0 : SharedImage newBack;
382 0 : image->Swap(op.newFrontBuffer(), &newBack);
383 : replyv.push_back(OpImageSwap(shadow, NULL,
384 0 : newBack));
385 :
386 : #ifdef MOZ_RENDERTRACE
387 : RenderTraceInvalidateEnd(image, "FF00FF");
388 : #endif
389 : break;
390 : }
391 :
392 : default:
393 0 : NS_RUNTIMEABORT("not reached");
394 : }
395 : }
396 :
397 0 : layer_manager()->EndTransaction(NULL, NULL, LayerManager::END_NO_IMMEDIATE_REDRAW);
398 :
399 0 : reply->SetCapacity(replyv.size());
400 0 : if (replyv.size() > 0) {
401 0 : reply->AppendElements(&replyv.front(), replyv.size());
402 : }
403 :
404 : // Ensure that any pending operations involving back and front
405 : // buffers have completed, so that neither process stomps on the
406 : // other's buffer contents.
407 0 : ShadowLayerManager::PlatformSyncBeforeReplyUpdate();
408 :
409 0 : mShadowLayersManager->ShadowLayersUpdated();
410 :
411 0 : return true;
412 : }
413 :
414 : PLayerParent*
415 0 : ShadowLayersParent::AllocPLayer()
416 : {
417 0 : return new ShadowLayerParent();
418 : }
419 :
420 : bool
421 0 : ShadowLayersParent::DeallocPLayer(PLayerParent* actor)
422 : {
423 0 : delete actor;
424 0 : return true;
425 : }
426 :
427 : void
428 0 : ShadowLayersParent::DestroySharedSurface(gfxSharedImageSurface* aSurface)
429 : {
430 0 : layer_manager()->DestroySharedSurface(aSurface, this);
431 0 : }
432 :
433 : void
434 0 : ShadowLayersParent::DestroySharedSurface(SurfaceDescriptor* aSurface)
435 : {
436 0 : layer_manager()->DestroySharedSurface(aSurface, this);
437 0 : }
438 :
439 : } // namespace layers
440 : } // namespace mozilla
|