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"
13 // Platforms with no OOP compositor process support use
14 // InProcessCompositorWidget by default.
15 #if !defined(MOZ_WIDGET_SUPPORTS_OOP_COMPOSITING)
17 RefPtr
<CompositorWidget
> CompositorWidget::CreateLocal(
18 const CompositorWidgetInitData
& aInitData
,
19 const layers::CompositorOptions
& aOptions
, nsIWidget
* aWidget
) {
20 // We're getting crashes from storing a NULL mWidget, and this is the
21 // only remaining explanation that doesn't involve memory corruption,
22 // so placing a release assert here. For even more sanity-checking, we
23 // do it after the static_cast.
24 nsBaseWidget
* widget
= static_cast<nsBaseWidget
*>(aWidget
);
25 MOZ_RELEASE_ASSERT(widget
);
26 return new InProcessCompositorWidget(aOptions
, widget
);
30 InProcessCompositorWidget::InProcessCompositorWidget(
31 const layers::CompositorOptions
& aOptions
, nsBaseWidget
* aWidget
)
32 : CompositorWidget(aOptions
),
34 mCanary(CANARY_VALUE
),
35 mWidgetSanity(aWidget
) {
36 // The only method of construction that is used outside of unit tests is
37 // ::CreateLocal, above. That method of construction asserts that mWidget
38 // is not assigned a NULL value. And yet mWidget is NULL in some crash
39 // reports that involve other class methods. Adding a release assert here
40 // will give us the earliest possible notification that we're headed for
42 MOZ_RELEASE_ASSERT(mWidget
);
45 bool InProcessCompositorWidget::PreRender(WidgetRenderingContext
* aContext
) {
47 return mWidget
->PreRender(aContext
);
50 void InProcessCompositorWidget::PostRender(WidgetRenderingContext
* aContext
) {
52 mWidget
->PostRender(aContext
);
55 RefPtr
<layers::NativeLayerRoot
>
56 InProcessCompositorWidget::GetNativeLayerRoot() {
58 return mWidget
->GetNativeLayerRoot();
61 already_AddRefed
<gfx::DrawTarget
>
62 InProcessCompositorWidget::StartRemoteDrawing() {
64 return mWidget
->StartRemoteDrawing();
67 already_AddRefed
<gfx::DrawTarget
>
68 InProcessCompositorWidget::StartRemoteDrawingInRegion(
69 const LayoutDeviceIntRegion
& aInvalidRegion
,
70 layers::BufferMode
* aBufferMode
) {
72 return mWidget
->StartRemoteDrawingInRegion(aInvalidRegion
, aBufferMode
);
75 void InProcessCompositorWidget::EndRemoteDrawing() {
77 mWidget
->EndRemoteDrawing();
80 void InProcessCompositorWidget::EndRemoteDrawingInRegion(
81 gfx::DrawTarget
* aDrawTarget
, const LayoutDeviceIntRegion
& aInvalidRegion
) {
83 mWidget
->EndRemoteDrawingInRegion(aDrawTarget
, aInvalidRegion
);
86 void InProcessCompositorWidget::CleanupRemoteDrawing() {
88 mWidget
->CleanupRemoteDrawing();
91 void InProcessCompositorWidget::CleanupWindowEffects() {
93 mWidget
->CleanupWindowEffects();
96 bool InProcessCompositorWidget::InitCompositor(
97 layers::Compositor
* aCompositor
) {
99 return mWidget
->InitCompositor(aCompositor
);
102 LayoutDeviceIntSize
InProcessCompositorWidget::GetClientSize() {
104 return mWidget
->GetClientSize();
107 uint32_t InProcessCompositorWidget::GetGLFrameBufferFormat() {
109 return mWidget
->GetGLFrameBufferFormat();
112 uintptr_t InProcessCompositorWidget::GetWidgetKey() {
114 return reinterpret_cast<uintptr_t>(mWidget
);
117 nsIWidget
* InProcessCompositorWidget::RealWidget() { return mWidget
; }
119 void InProcessCompositorWidget::ObserveVsync(VsyncObserver
* aObserver
) {
121 if (RefPtr
<CompositorVsyncDispatcher
> cvd
=
122 mWidget
->GetCompositorVsyncDispatcher()) {
123 cvd
->SetCompositorVsyncObserver(aObserver
);
127 const char* InProcessCompositorWidget::CANARY_VALUE
=
128 reinterpret_cast<char*>(0x1a1a1a1a);
130 void InProcessCompositorWidget::CheckWidgetSanity() {
131 MOZ_RELEASE_ASSERT(mWidgetSanity
== mWidget
);
132 MOZ_RELEASE_ASSERT(mCanary
== CANARY_VALUE
);
135 } // namespace widget
136 } // namespace mozilla