Bug 1758698 [wpt PR 33120] - Add more referrer policy WPTs for Early Hints, a=testonly
[gecko.git] / widget / InProcessCompositorWidget.cpp
blob1c25e9d9a101233f71e92288a0f93125b81ac1c5
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 namespace mozilla {
11 namespace widget {
13 // Platforms with no OOP compositor process support use
14 // InProcessCompositorWidget by default.
15 #if !defined(MOZ_WIDGET_SUPPORTS_OOP_COMPOSITING)
16 /* static */
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);
28 #endif
30 InProcessCompositorWidget::InProcessCompositorWidget(
31 const layers::CompositorOptions& aOptions, nsBaseWidget* aWidget)
32 : CompositorWidget(aOptions),
33 mWidget(aWidget),
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
41 // a crash.
42 MOZ_RELEASE_ASSERT(mWidget);
45 bool InProcessCompositorWidget::PreRender(WidgetRenderingContext* aContext) {
46 CheckWidgetSanity();
47 return mWidget->PreRender(aContext);
50 void InProcessCompositorWidget::PostRender(WidgetRenderingContext* aContext) {
51 CheckWidgetSanity();
52 mWidget->PostRender(aContext);
55 RefPtr<layers::NativeLayerRoot>
56 InProcessCompositorWidget::GetNativeLayerRoot() {
57 CheckWidgetSanity();
58 return mWidget->GetNativeLayerRoot();
61 already_AddRefed<gfx::DrawTarget>
62 InProcessCompositorWidget::StartRemoteDrawing() {
63 CheckWidgetSanity();
64 return mWidget->StartRemoteDrawing();
67 already_AddRefed<gfx::DrawTarget>
68 InProcessCompositorWidget::StartRemoteDrawingInRegion(
69 const LayoutDeviceIntRegion& aInvalidRegion,
70 layers::BufferMode* aBufferMode) {
71 CheckWidgetSanity();
72 return mWidget->StartRemoteDrawingInRegion(aInvalidRegion, aBufferMode);
75 void InProcessCompositorWidget::EndRemoteDrawing() {
76 CheckWidgetSanity();
77 mWidget->EndRemoteDrawing();
80 void InProcessCompositorWidget::EndRemoteDrawingInRegion(
81 gfx::DrawTarget* aDrawTarget, const LayoutDeviceIntRegion& aInvalidRegion) {
82 CheckWidgetSanity();
83 mWidget->EndRemoteDrawingInRegion(aDrawTarget, aInvalidRegion);
86 void InProcessCompositorWidget::CleanupRemoteDrawing() {
87 CheckWidgetSanity();
88 mWidget->CleanupRemoteDrawing();
91 void InProcessCompositorWidget::CleanupWindowEffects() {
92 CheckWidgetSanity();
93 mWidget->CleanupWindowEffects();
96 bool InProcessCompositorWidget::InitCompositor(
97 layers::Compositor* aCompositor) {
98 CheckWidgetSanity();
99 return mWidget->InitCompositor(aCompositor);
102 LayoutDeviceIntSize InProcessCompositorWidget::GetClientSize() {
103 CheckWidgetSanity();
104 return mWidget->GetClientSize();
107 uint32_t InProcessCompositorWidget::GetGLFrameBufferFormat() {
108 CheckWidgetSanity();
109 return mWidget->GetGLFrameBufferFormat();
112 uintptr_t InProcessCompositorWidget::GetWidgetKey() {
113 CheckWidgetSanity();
114 return reinterpret_cast<uintptr_t>(mWidget);
117 nsIWidget* InProcessCompositorWidget::RealWidget() { return mWidget; }
119 void InProcessCompositorWidget::ObserveVsync(VsyncObserver* aObserver) {
120 CheckWidgetSanity();
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