1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /* vim: set sw=2 ts=2 et tw=80 : */
3 : /* ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
6 : * The contents of this file are subject to the Mozilla Public License Version
7 : * 1.1 (the "License"); you may not use this file except in compliance with
8 : * the License. You may obtain a copy of the License at
9 : * http://www.mozilla.org/MPL/
10 : *
11 : * Software distributed under the License is distributed on an "AS IS" basis,
12 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 : * for the specific language governing rights and limitations under the
14 : * License.
15 : *
16 : * The Original Code is Mozilla Content App.
17 : *
18 : * The Initial Developer of the Original Code is
19 : * The Mozilla Foundation.
20 : * Portions created by the Initial Developer are Copyright (C) 2011
21 : * the Initial Developer. All Rights Reserved.
22 : *
23 : * Contributor(s):
24 : * Benoit Girard <bgirard@mozilla.com>
25 : * Ali Juma <ajuma@mozilla.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 "CompositorParent.h"
42 : #include "RenderTrace.h"
43 : #include "ShadowLayersParent.h"
44 : #include "LayerManagerOGL.h"
45 : #include "nsIWidget.h"
46 :
47 : namespace mozilla {
48 : namespace layers {
49 :
50 0 : CompositorParent::CompositorParent(nsIWidget* aWidget)
51 0 : : mStopped(false), mWidget(aWidget)
52 : {
53 0 : MOZ_COUNT_CTOR(CompositorParent);
54 0 : }
55 :
56 0 : CompositorParent::~CompositorParent()
57 : {
58 0 : MOZ_COUNT_DTOR(CompositorParent);
59 0 : }
60 :
61 : void
62 0 : CompositorParent::Destroy()
63 : {
64 0 : NS_ABORT_IF_FALSE(ManagedPLayersParent().Length() == 0,
65 : "CompositorParent destroyed before managed PLayersParent");
66 :
67 : // Ensure that the layer manager is destroyed on the compositor thread.
68 0 : mLayerManager = NULL;
69 0 : }
70 :
71 : bool
72 0 : CompositorParent::RecvStop()
73 : {
74 0 : mStopped = true;
75 0 : Destroy();
76 0 : return true;
77 : }
78 :
79 : void
80 0 : CompositorParent::ScheduleComposition()
81 : {
82 0 : CancelableTask *composeTask = NewRunnableMethod(this, &CompositorParent::Composite);
83 0 : MessageLoop::current()->PostTask(FROM_HERE, composeTask);
84 :
85 : #ifdef MOZ_RENDERTRACE
86 : Layer* aLayer = mLayerManager->GetRoot();
87 : mozilla::layers::RenderTraceLayers(aLayer, "0000");
88 : #endif
89 :
90 0 : }
91 :
92 : void
93 0 : CompositorParent::Composite()
94 : {
95 0 : if (mStopped || !mLayerManager) {
96 0 : return;
97 : }
98 :
99 0 : mLayerManager->EndEmptyTransaction();
100 : }
101 :
102 : // Go down shadow layer tree, setting properties to match their non-shadow
103 : // counterparts.
104 : static void
105 0 : SetShadowProperties(Layer* aLayer)
106 : {
107 : // FIXME: Bug 717688 -- Do these updates in ShadowLayersParent::RecvUpdate.
108 0 : ShadowLayer* shadow = aLayer->AsShadowLayer();
109 0 : shadow->SetShadowTransform(aLayer->GetTransform());
110 0 : shadow->SetShadowVisibleRegion(aLayer->GetVisibleRegion());
111 0 : shadow->SetShadowClipRect(aLayer->GetClipRect());
112 :
113 0 : for (Layer* child = aLayer->GetFirstChild();
114 : child; child = child->GetNextSibling()) {
115 0 : SetShadowProperties(child);
116 : }
117 0 : }
118 :
119 : void
120 0 : CompositorParent::ShadowLayersUpdated()
121 : {
122 0 : const nsTArray<PLayersParent*>& shadowParents = ManagedPLayersParent();
123 0 : NS_ABORT_IF_FALSE(shadowParents.Length() <= 1,
124 : "can only support at most 1 ShadowLayersParent");
125 0 : if (shadowParents.Length()) {
126 0 : Layer* root = static_cast<ShadowLayersParent*>(shadowParents[0])->GetRoot();
127 0 : mLayerManager->SetRoot(root);
128 0 : SetShadowProperties(root);
129 : }
130 0 : ScheduleComposition();
131 0 : }
132 :
133 : PLayersParent*
134 0 : CompositorParent::AllocPLayers(const LayersBackend &backendType)
135 : {
136 0 : if (backendType == LayerManager::LAYERS_OPENGL) {
137 0 : nsRefPtr<LayerManagerOGL> layerManager = new LayerManagerOGL(mWidget);
138 0 : mWidget = NULL;
139 0 : mLayerManager = layerManager;
140 :
141 0 : if (!layerManager->Initialize()) {
142 0 : NS_ERROR("Failed to init OGL Layers");
143 0 : return NULL;
144 : }
145 :
146 0 : ShadowLayerManager* slm = layerManager->AsShadowManager();
147 0 : if (!slm) {
148 0 : return NULL;
149 : }
150 0 : return new ShadowLayersParent(slm, this);
151 : } else {
152 0 : NS_ERROR("Unsupported backend selected for Async Compositor");
153 0 : return NULL;
154 : }
155 : }
156 :
157 : bool
158 0 : CompositorParent::DeallocPLayers(PLayersParent* actor)
159 : {
160 0 : delete actor;
161 0 : return true;
162 : }
163 :
164 : } // namespace layers
165 : } // namespace mozilla
166 :
|