1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "InProcessCompositorWidget.h"
7 #include "mozilla/VsyncDispatcher.h"
8 #include "nsBaseWidget.h"
10 #if defined(MOZ_WIDGET_ANDROID) && !defined(MOZ_WIDGET_SUPPORTS_OOP_COMPOSITING)
11 # include "mozilla/widget/AndroidCompositorWidget.h"
17 // Platforms with no OOP compositor process support use
18 // InProcessCompositorWidget by default.
19 #if !defined(MOZ_WIDGET_SUPPORTS_OOP_COMPOSITING)
21 RefPtr
<CompositorWidget
> CompositorWidget::CreateLocal(
22 const CompositorWidgetInitData
& aInitData
,
23 const layers::CompositorOptions
& aOptions
, nsIWidget
* aWidget
) {
24 // We're getting crashes from storing a NULL mWidget, and this is the
25 // only remaining explanation that doesn't involve memory corruption,
26 // so placing a release assert here. For even more sanity-checking, we
27 // do it after the static_cast.
28 nsBaseWidget
* widget
= static_cast<nsBaseWidget
*>(aWidget
);
29 MOZ_RELEASE_ASSERT(widget
);
30 # ifdef MOZ_WIDGET_ANDROID
31 return new AndroidCompositorWidget(aOptions
, widget
);
33 return new InProcessCompositorWidget(aOptions
, widget
);
38 InProcessCompositorWidget::InProcessCompositorWidget(
39 const layers::CompositorOptions
& aOptions
, nsBaseWidget
* aWidget
)
40 : CompositorWidget(aOptions
),
42 mCanary(CANARY_VALUE
),
43 mWidgetSanity(aWidget
) {
44 // The only method of construction that is used outside of unit tests is
45 // ::CreateLocal, above. That method of construction asserts that mWidget
46 // is not assigned a NULL value. And yet mWidget is NULL in some crash
47 // reports that involve other class methods. Adding a release assert here
48 // will give us the earliest possible notification that we're headed for
50 MOZ_RELEASE_ASSERT(mWidget
);
53 bool InProcessCompositorWidget::PreRender(WidgetRenderingContext
* aContext
) {
55 return mWidget
->PreRender(aContext
);
58 void InProcessCompositorWidget::PostRender(WidgetRenderingContext
* aContext
) {
60 mWidget
->PostRender(aContext
);
63 RefPtr
<layers::NativeLayerRoot
>
64 InProcessCompositorWidget::GetNativeLayerRoot() {
66 return mWidget
->GetNativeLayerRoot();
69 already_AddRefed
<gfx::DrawTarget
>
70 InProcessCompositorWidget::StartRemoteDrawing() {
72 return mWidget
->StartRemoteDrawing();
75 already_AddRefed
<gfx::DrawTarget
>
76 InProcessCompositorWidget::StartRemoteDrawingInRegion(
77 const LayoutDeviceIntRegion
& aInvalidRegion
,
78 layers::BufferMode
* aBufferMode
) {
80 return mWidget
->StartRemoteDrawingInRegion(aInvalidRegion
, aBufferMode
);
83 void InProcessCompositorWidget::EndRemoteDrawing() {
85 mWidget
->EndRemoteDrawing();
88 void InProcessCompositorWidget::EndRemoteDrawingInRegion(
89 gfx::DrawTarget
* aDrawTarget
, const LayoutDeviceIntRegion
& aInvalidRegion
) {
91 mWidget
->EndRemoteDrawingInRegion(aDrawTarget
, aInvalidRegion
);
94 void InProcessCompositorWidget::CleanupRemoteDrawing() {
96 mWidget
->CleanupRemoteDrawing();
99 void InProcessCompositorWidget::CleanupWindowEffects() {
101 mWidget
->CleanupWindowEffects();
104 bool InProcessCompositorWidget::InitCompositor(
105 layers::Compositor
* aCompositor
) {
107 return mWidget
->InitCompositor(aCompositor
);
110 LayoutDeviceIntSize
InProcessCompositorWidget::GetClientSize() {
112 return mWidget
->GetClientSize();
115 uint32_t InProcessCompositorWidget::GetGLFrameBufferFormat() {
117 return mWidget
->GetGLFrameBufferFormat();
120 uintptr_t InProcessCompositorWidget::GetWidgetKey() {
122 return reinterpret_cast<uintptr_t>(mWidget
);
125 nsIWidget
* InProcessCompositorWidget::RealWidget() { return mWidget
; }
127 void InProcessCompositorWidget::ObserveVsync(VsyncObserver
* aObserver
) {
129 if (RefPtr
<CompositorVsyncDispatcher
> cvd
=
130 mWidget
->GetCompositorVsyncDispatcher()) {
131 cvd
->SetCompositorVsyncObserver(aObserver
);
135 const char* InProcessCompositorWidget::CANARY_VALUE
=
136 reinterpret_cast<char*>(0x1a1a1a1a);
138 void InProcessCompositorWidget::CheckWidgetSanity() {
139 MOZ_RELEASE_ASSERT(mWidgetSanity
== mWidget
);
140 MOZ_RELEASE_ASSERT(mCanary
== CANARY_VALUE
);
143 } // namespace widget
144 } // namespace mozilla