Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/widget/gtk/WindowSurfaceProvider.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
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
#include "WindowSurfaceProvider.h"
8
9
#include "gfxPlatformGtk.h"
10
#include "mozilla/layers/LayersTypes.h"
11
#include "WindowSurfaceX11Image.h"
12
#include "WindowSurfaceX11SHM.h"
13
#include "WindowSurfaceXRender.h"
14
#ifdef MOZ_WAYLAND
15
#include "WindowSurfaceWayland.h"
16
#endif
17
18
namespace mozilla {
19
namespace widget {
20
21
using namespace mozilla::gfx;
22
using namespace mozilla::layers;
23
24
WindowSurfaceProvider::WindowSurfaceProvider()
25
    : mIsX11Display(false)
26
    , mXDisplay(nullptr)
27
    , mXWindow(0)
28
    , mXVisual(nullptr)
29
    , mXDepth(0)
30
    , mWindowSurface(nullptr)
31
#ifdef MOZ_WAYLAND
32
    , mWidget(nullptr)
33
#endif
34
    , mIsShaped(false)
35
0
{
36
0
}
37
38
void WindowSurfaceProvider::Initialize(
39
      Display* aDisplay,
40
      Window aWindow,
41
      Visual* aVisual,
42
      int aDepth,
43
      bool aIsShaped)
44
0
{
45
0
  // We should not be initialized
46
0
  MOZ_ASSERT(!mXDisplay);
47
0
48
0
  // This should also be a valid initialization
49
0
  MOZ_ASSERT(aDisplay && aWindow != X11None && aVisual);
50
0
51
0
  mXDisplay = aDisplay;
52
0
  mXWindow = aWindow;
53
0
  mXVisual = aVisual;
54
0
  mXDepth = aDepth;
55
0
  mIsShaped = aIsShaped;
56
0
  mIsX11Display = true;
57
0
}
58
59
#ifdef MOZ_WAYLAND
60
void WindowSurfaceProvider::Initialize(nsWindow *aWidget)
61
{
62
  MOZ_ASSERT(aWidget->GetWaylandDisplay(),
63
             "We are supposed to have a Wayland display!");
64
65
  mWidget = aWidget;
66
  mIsX11Display = false;
67
}
68
#endif
69
70
void WindowSurfaceProvider::CleanupResources()
71
0
{
72
0
  mWindowSurface = nullptr;
73
0
}
74
75
UniquePtr<WindowSurface>
76
WindowSurfaceProvider::CreateWindowSurface()
77
0
{
78
#ifdef MOZ_WAYLAND
79
  if (!mIsX11Display) {
80
    LOGDRAW(("Drawing to nsWindow %p using wl_surface\n", (void*)this));
81
    return MakeUnique<WindowSurfaceWayland>(mWidget);
82
  }
83
#endif
84
85
0
  // We should be initialized
86
0
  MOZ_ASSERT(mXDisplay);
87
0
88
0
  // Blit to the window with the following priority:
89
0
  // 1. XRender (iff XRender is enabled && we are in-process)
90
0
  // 2. MIT-SHM
91
0
  // 3. XPutImage
92
0
93
0
#ifdef MOZ_WIDGET_GTK
94
0
  if (!mIsShaped && gfxVars::UseXRender()) {
95
0
    LOGDRAW(("Drawing to nsWindow %p using XRender\n", (void*)this));
96
0
    return MakeUnique<WindowSurfaceXRender>(mXDisplay, mXWindow, mXVisual, mXDepth);
97
0
  }
98
0
#endif // MOZ_WIDGET_GTK
99
0
100
0
#ifdef MOZ_HAVE_SHMIMAGE
101
0
  if (!mIsShaped && nsShmImage::UseShm()) {
102
0
    LOGDRAW(("Drawing to nsWindow %p using MIT-SHM\n", (void*)this));
103
0
    return MakeUnique<WindowSurfaceX11SHM>(mXDisplay, mXWindow, mXVisual, mXDepth);
104
0
  }
105
0
#endif // MOZ_HAVE_SHMIMAGE
106
0
107
0
  LOGDRAW(("Drawing to nsWindow %p using XPutImage\n", (void*)this));
108
0
  return MakeUnique<WindowSurfaceX11Image>(mXDisplay, mXWindow, mXVisual,
109
0
    mXDepth, mIsShaped);
110
0
}
111
112
already_AddRefed<gfx::DrawTarget>
113
WindowSurfaceProvider::StartRemoteDrawingInRegion(LayoutDeviceIntRegion& aInvalidRegion,
114
                                                layers::BufferMode* aBufferMode)
115
0
{
116
0
  if (aInvalidRegion.IsEmpty())
117
0
    return nullptr;
118
0
119
0
  if (!mWindowSurface) {
120
0
    mWindowSurface = CreateWindowSurface();
121
0
    if (!mWindowSurface)
122
0
      return nullptr;
123
0
  }
124
0
125
0
  *aBufferMode = BufferMode::BUFFER_NONE;
126
0
  RefPtr<DrawTarget> dt = nullptr;
127
0
  if (!(dt = mWindowSurface->Lock(aInvalidRegion)) &&
128
0
      mIsX11Display && !mWindowSurface->IsFallback()) {
129
0
    // We can't use WindowSurfaceX11Image fallback on Wayland but
130
0
    // Lock() call on WindowSurfaceWayland should never fail.
131
0
    gfxWarningOnce() << "Failed to lock WindowSurface, falling back to XPutImage backend.";
132
0
    mWindowSurface = MakeUnique<WindowSurfaceX11Image>(mXDisplay, mXWindow, mXVisual, mXDepth, mIsShaped);
133
0
    dt = mWindowSurface->Lock(aInvalidRegion);
134
0
  }
135
0
  return dt.forget();
136
0
}
137
138
void
139
WindowSurfaceProvider::EndRemoteDrawingInRegion(gfx::DrawTarget* aDrawTarget,
140
                                              LayoutDeviceIntRegion& aInvalidRegion)
141
0
{
142
0
  if (mWindowSurface)
143
0
    mWindowSurface->Commit(aInvalidRegion);
144
0
}
145
146
} // namespace mozilla
147
} // namespace widget