1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2  *
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 #ifndef _MOZILLA_WIDGET_GTK_WINDOW_SURFACE_PROVIDER_H
8 #define _MOZILLA_WIDGET_GTK_WINDOW_SURFACE_PROVIDER_H
9 
10 #include <gdk/gdk.h>
11 
12 #include "mozilla/gfx/2D.h"
13 #include "mozilla/gfx/Types.h"
14 #include "mozilla/layers/LayersTypes.h"
15 #include "mozilla/widget/WindowSurface.h"
16 #include "Units.h"
17 
18 #ifdef MOZ_X11
19 #  include <X11/Xlib.h>  // for Window, Display, Visual, etc.
20 #  include "X11UndefineNone.h"
21 #endif
22 
23 class nsWindow;
24 
25 namespace mozilla {
26 namespace widget {
27 
28 /*
29  * Holds the logic for creating WindowSurface's for a GTK nsWindow.
30  * The main purpose of this class is to allow sharing of logic between
31  * nsWindow and GtkCompositorWidget, for when OMTC is enabled or disabled.
32  */
33 class WindowSurfaceProvider final {
34  public:
35   WindowSurfaceProvider();
36 
37   /**
38    * Initializes the WindowSurfaceProvider by giving it the window
39    * handle and display to attach to. WindowSurfaceProvider doesn't
40    * own the Display, Window, etc, and they must continue to exist
41    * while WindowSurfaceProvider is used.
42    */
43 #ifdef MOZ_WAYLAND
44   void Initialize(nsWindow* aWidget);
45 #endif
46 #ifdef MOZ_X11
47   void Initialize(Window aWindow, Visual* aVisual, int aDepth, bool aIsShaped);
48 #endif
49 
50   /**
51    * Releases any surfaces created by this provider.
52    * This is used by GtkCompositorWidget to get rid
53    * of resources.
54    */
55   void CleanupResources();
56 
57   already_AddRefed<gfx::DrawTarget> StartRemoteDrawingInRegion(
58       const LayoutDeviceIntRegion& aInvalidRegion,
59       layers::BufferMode* aBufferMode);
60   void EndRemoteDrawingInRegion(gfx::DrawTarget* aDrawTarget,
61                                 const LayoutDeviceIntRegion& aInvalidRegion);
62 
63  private:
64   RefPtr<WindowSurface> CreateWindowSurface();
65 
66   RefPtr<WindowSurface> mWindowSurface;
67 #ifdef MOZ_WAYLAND
68   nsWindow* mWidget;
69 #endif
70 #ifdef MOZ_X11
71   bool mIsShaped;
72   int mXDepth;
73   Window mXWindow;
74   Visual* mXVisual;
75 #endif
76 };
77 
78 }  // namespace widget
79 }  // namespace mozilla
80 
81 #endif  // _MOZILLA_WIDGET_GTK_WINDOW_SURFACE_PROVIDER_H
82