Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=99: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #include "InProcessCompositorSession.h"
8 :
9 : // so we can cast an APZCTreeManager to an IAPZCTreeManager
10 : #include "mozilla/layers/APZCTreeManager.h"
11 : #include "mozilla/layers/IAPZCTreeManager.h"
12 : #include "nsBaseWidget.h"
13 :
14 : namespace mozilla {
15 : namespace layers {
16 :
17 1 : InProcessCompositorSession::InProcessCompositorSession(widget::CompositorWidget* aWidget,
18 : nsBaseWidget* baseWidget,
19 : CompositorBridgeChild* aChild,
20 1 : CompositorBridgeParent* aParent)
21 2 : : CompositorSession(aWidget->AsDelegate(), aChild, aParent->RootLayerTreeId()),
22 : mWidget(baseWidget),
23 : mCompositorBridgeParent(aParent),
24 2 : mCompositorWidget(aWidget)
25 : {
26 1 : GPUProcessManager::Get()->RegisterInProcessSession(this);
27 1 : }
28 :
29 : /* static */ RefPtr<InProcessCompositorSession>
30 1 : InProcessCompositorSession::Create(nsBaseWidget* aWidget,
31 : LayerManager* aLayerManager,
32 : const uint64_t& aRootLayerTreeId,
33 : CSSToLayoutDeviceScale aScale,
34 : const CompositorOptions& aOptions,
35 : bool aUseExternalSurfaceSize,
36 : const gfx::IntSize& aSurfaceSize,
37 : uint32_t aNamespace)
38 : {
39 2 : CompositorWidgetInitData initData;
40 1 : aWidget->GetCompositorWidgetInitData(&initData);
41 :
42 2 : RefPtr<CompositorWidget> widget = CompositorWidget::CreateLocal(initData, aOptions, aWidget);
43 : RefPtr<CompositorBridgeParent> parent =
44 3 : CompositorManagerParent::CreateSameProcessWidgetCompositorBridge(aScale, aOptions,
45 : aUseExternalSurfaceSize,
46 3 : aSurfaceSize);
47 1 : MOZ_ASSERT(parent);
48 1 : parent->InitSameProcess(widget, aRootLayerTreeId);
49 :
50 : RefPtr<CompositorBridgeChild> child =
51 2 : CompositorManagerChild::CreateSameProcessWidgetCompositorBridge(aLayerManager,
52 2 : aNamespace);
53 1 : MOZ_ASSERT(child);
54 :
55 3 : return new InProcessCompositorSession(widget, aWidget, child, parent);
56 : }
57 :
58 : void
59 0 : InProcessCompositorSession::NotifySessionLost()
60 : {
61 0 : mWidget->NotifyCompositorSessionLost(this);
62 0 : }
63 :
64 : CompositorBridgeParent*
65 0 : InProcessCompositorSession::GetInProcessBridge() const
66 : {
67 0 : return mCompositorBridgeParent;
68 : }
69 :
70 : void
71 1 : InProcessCompositorSession::SetContentController(GeckoContentController* aController)
72 : {
73 1 : mCompositorBridgeParent->SetControllerForLayerTree(mRootLayerTreeId, aController);
74 1 : }
75 :
76 : RefPtr<IAPZCTreeManager>
77 1 : InProcessCompositorSession::GetAPZCTreeManager() const
78 : {
79 1 : return mCompositorBridgeParent->GetAPZCTreeManager(mRootLayerTreeId);
80 : }
81 :
82 : nsIWidget*
83 0 : InProcessCompositorSession::GetWidget() const
84 : {
85 0 : return mWidget;
86 : }
87 :
88 : void
89 0 : InProcessCompositorSession::Shutdown()
90 : {
91 : // Destroy will synchronously wait for the parent to acknowledge shutdown,
92 : // at which point CBP will defer a Release on the compositor thread. We
93 : // can safely release our reference now, and let the destructor run on either
94 : // thread.
95 0 : mCompositorBridgeChild->Destroy();
96 0 : mCompositorBridgeChild = nullptr;
97 0 : mCompositorBridgeParent = nullptr;
98 0 : mCompositorWidget = nullptr;
99 : #if defined(MOZ_WIDGET_ANDROID)
100 : if (mUiCompositorControllerChild) {
101 : mUiCompositorControllerChild->Destroy();
102 : mUiCompositorControllerChild = nullptr;
103 : }
104 : #endif //defined(MOZ_WIDGET_ANDROID)
105 0 : GPUProcessManager::Get()->UnregisterInProcessSession(this);
106 0 : }
107 :
108 : } // namespace layers
109 : } // namespace mozilla
|