2016-07-22 20:23:07 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "WindowSurfaceProvider.h"
|
|
|
|
|
|
|
|
#include "gfxPlatformGtk.h"
|
|
|
|
#include "mozilla/layers/LayersTypes.h"
|
|
|
|
#include "WindowSurfaceX11Image.h"
|
|
|
|
#include "WindowSurfaceX11SHM.h"
|
|
|
|
#include "WindowSurfaceXRender.h"
|
2017-12-18 22:20:02 +03:00
|
|
|
#ifdef MOZ_WAYLAND
|
|
|
|
#include "WindowSurfaceWayland.h"
|
|
|
|
#endif
|
2016-07-22 20:23:07 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace widget {
|
|
|
|
|
|
|
|
using namespace mozilla::gfx;
|
|
|
|
using namespace mozilla::layers;
|
|
|
|
|
|
|
|
WindowSurfaceProvider::WindowSurfaceProvider()
|
2017-12-18 22:20:02 +03:00
|
|
|
: mIsX11Display(false)
|
|
|
|
, mXDisplay(nullptr)
|
2016-07-22 20:23:07 +03:00
|
|
|
, mXWindow(0)
|
|
|
|
, mXVisual(nullptr)
|
|
|
|
, mXDepth(0)
|
|
|
|
, mWindowSurface(nullptr)
|
2017-12-18 22:20:02 +03:00
|
|
|
#ifdef MOZ_WAYLAND
|
|
|
|
, mWidget(nullptr)
|
|
|
|
#endif
|
2018-07-24 17:07:04 +03:00
|
|
|
, mIsShaped(false)
|
2016-07-22 20:23:07 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void WindowSurfaceProvider::Initialize(
|
|
|
|
Display* aDisplay,
|
|
|
|
Window aWindow,
|
|
|
|
Visual* aVisual,
|
2018-07-24 17:07:04 +03:00
|
|
|
int aDepth,
|
|
|
|
bool aIsShaped)
|
2016-07-22 20:23:07 +03:00
|
|
|
{
|
|
|
|
// We should not be initialized
|
|
|
|
MOZ_ASSERT(!mXDisplay);
|
|
|
|
|
|
|
|
// This should also be a valid initialization
|
|
|
|
MOZ_ASSERT(aDisplay && aWindow != X11None && aVisual);
|
|
|
|
|
|
|
|
mXDisplay = aDisplay;
|
|
|
|
mXWindow = aWindow;
|
|
|
|
mXVisual = aVisual;
|
|
|
|
mXDepth = aDepth;
|
2018-07-24 17:07:04 +03:00
|
|
|
mIsShaped = aIsShaped;
|
2017-12-18 22:20:02 +03:00
|
|
|
mIsX11Display = true;
|
2016-07-22 20:23:07 +03:00
|
|
|
}
|
2017-12-18 22:20:02 +03:00
|
|
|
|
|
|
|
#ifdef MOZ_WAYLAND
|
|
|
|
void WindowSurfaceProvider::Initialize(nsWindow *aWidget)
|
|
|
|
{
|
2018-01-12 12:30:38 +03:00
|
|
|
MOZ_ASSERT(aWidget->GetWaylandDisplay(),
|
2017-12-18 22:20:02 +03:00
|
|
|
"We are supposed to have a Wayland display!");
|
|
|
|
|
|
|
|
mWidget = aWidget;
|
|
|
|
mIsX11Display = false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-07-22 20:23:07 +03:00
|
|
|
void WindowSurfaceProvider::CleanupResources()
|
|
|
|
{
|
|
|
|
mWindowSurface = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
UniquePtr<WindowSurface>
|
|
|
|
WindowSurfaceProvider::CreateWindowSurface()
|
|
|
|
{
|
2017-12-18 22:20:02 +03:00
|
|
|
#ifdef MOZ_WAYLAND
|
|
|
|
if (!mIsX11Display) {
|
|
|
|
LOGDRAW(("Drawing to nsWindow %p using wl_surface\n", (void*)this));
|
|
|
|
return MakeUnique<WindowSurfaceWayland>(mWidget);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-07-22 20:23:07 +03:00
|
|
|
// We should be initialized
|
|
|
|
MOZ_ASSERT(mXDisplay);
|
|
|
|
|
|
|
|
// Blit to the window with the following priority:
|
|
|
|
// 1. XRender (iff XRender is enabled && we are in-process)
|
|
|
|
// 2. MIT-SHM
|
|
|
|
// 3. XPutImage
|
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_GTK
|
2018-07-24 17:07:04 +03:00
|
|
|
if (!mIsShaped && gfxVars::UseXRender()) {
|
2016-07-22 20:23:07 +03:00
|
|
|
LOGDRAW(("Drawing to nsWindow %p using XRender\n", (void*)this));
|
|
|
|
return MakeUnique<WindowSurfaceXRender>(mXDisplay, mXWindow, mXVisual, mXDepth);
|
|
|
|
}
|
|
|
|
#endif // MOZ_WIDGET_GTK
|
|
|
|
|
|
|
|
#ifdef MOZ_HAVE_SHMIMAGE
|
2018-07-24 17:07:04 +03:00
|
|
|
if (!mIsShaped && nsShmImage::UseShm()) {
|
2016-07-22 20:23:07 +03:00
|
|
|
LOGDRAW(("Drawing to nsWindow %p using MIT-SHM\n", (void*)this));
|
|
|
|
return MakeUnique<WindowSurfaceX11SHM>(mXDisplay, mXWindow, mXVisual, mXDepth);
|
|
|
|
}
|
|
|
|
#endif // MOZ_HAVE_SHMIMAGE
|
|
|
|
|
|
|
|
LOGDRAW(("Drawing to nsWindow %p using XPutImage\n", (void*)this));
|
2018-07-24 17:07:04 +03:00
|
|
|
return MakeUnique<WindowSurfaceX11Image>(mXDisplay, mXWindow, mXVisual,
|
|
|
|
mXDepth, mIsShaped);
|
2016-07-22 20:23:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<gfx::DrawTarget>
|
|
|
|
WindowSurfaceProvider::StartRemoteDrawingInRegion(LayoutDeviceIntRegion& aInvalidRegion,
|
|
|
|
layers::BufferMode* aBufferMode)
|
|
|
|
{
|
|
|
|
if (aInvalidRegion.IsEmpty())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
if (!mWindowSurface) {
|
|
|
|
mWindowSurface = CreateWindowSurface();
|
|
|
|
if (!mWindowSurface)
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aBufferMode = BufferMode::BUFFER_NONE;
|
|
|
|
RefPtr<DrawTarget> dt = nullptr;
|
2016-12-01 20:15:58 +03:00
|
|
|
if (!(dt = mWindowSurface->Lock(aInvalidRegion)) &&
|
2017-12-18 22:20:02 +03:00
|
|
|
mIsX11Display && !mWindowSurface->IsFallback()) {
|
|
|
|
// We can't use WindowSurfaceX11Image fallback on Wayland but
|
|
|
|
// Lock() call on WindowSurfaceWayland should never fail.
|
2016-07-22 20:23:07 +03:00
|
|
|
gfxWarningOnce() << "Failed to lock WindowSurface, falling back to XPutImage backend.";
|
2018-07-24 17:07:04 +03:00
|
|
|
mWindowSurface = MakeUnique<WindowSurfaceX11Image>(mXDisplay, mXWindow, mXVisual, mXDepth, mIsShaped);
|
2016-12-01 20:15:58 +03:00
|
|
|
dt = mWindowSurface->Lock(aInvalidRegion);
|
2016-07-22 20:23:07 +03:00
|
|
|
}
|
|
|
|
return dt.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WindowSurfaceProvider::EndRemoteDrawingInRegion(gfx::DrawTarget* aDrawTarget,
|
|
|
|
LayoutDeviceIntRegion& aInvalidRegion)
|
|
|
|
{
|
|
|
|
if (mWindowSurface)
|
|
|
|
mWindowSurface->Commit(aInvalidRegion);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
} // namespace widget
|