2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 4; -*- */
|
2015-07-30 19:40:56 +03:00
|
|
|
/* 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 "SharedSurfaceGLX.h"
|
|
|
|
#include "gfxXlibSurface.h"
|
|
|
|
#include "GLXLibrary.h"
|
|
|
|
#include "GLContextProvider.h"
|
|
|
|
#include "GLContextGLX.h"
|
|
|
|
#include "GLScreenBuffer.h"
|
2020-06-15 21:25:55 +03:00
|
|
|
#include "MozFramebuffer.h"
|
2015-10-12 06:21:03 +03:00
|
|
|
#include "mozilla/gfx/SourceSurfaceCairo.h"
|
2015-07-30 19:40:56 +03:00
|
|
|
#include "mozilla/layers/LayersSurfaces.h"
|
|
|
|
#include "mozilla/layers/ShadowLayerUtilsX11.h"
|
|
|
|
#include "mozilla/layers/ISurfaceAllocator.h"
|
2016-09-27 06:22:20 +03:00
|
|
|
#include "mozilla/layers/TextureForwarder.h"
|
2015-07-30 19:40:56 +03:00
|
|
|
#include "mozilla/X11Util.h"
|
|
|
|
|
2020-01-18 16:48:34 +03:00
|
|
|
namespace mozilla::gl {
|
2015-07-30 19:40:56 +03:00
|
|
|
|
2020-06-15 21:25:55 +03:00
|
|
|
UniquePtr<SharedSurface> SurfaceFactory_GLXDrawable::CreateSharedImpl(
|
|
|
|
const SharedSurfaceDesc& desc) {
|
|
|
|
return SharedSurface_GLXDrawable::Create(desc);
|
|
|
|
}
|
|
|
|
|
2015-07-30 19:40:56 +03:00
|
|
|
/* static */
|
|
|
|
UniquePtr<SharedSurface_GLXDrawable> SharedSurface_GLXDrawable::Create(
|
2020-06-15 21:25:55 +03:00
|
|
|
const SharedSurfaceDesc& desc) {
|
2015-07-30 19:40:56 +03:00
|
|
|
Display* display = DefaultXDisplay();
|
|
|
|
Screen* screen = XDefaultScreenOfDisplay(display);
|
2016-01-08 07:57:38 +03:00
|
|
|
Visual* visual =
|
|
|
|
gfxXlibSurface::FindVisual(screen, gfx::SurfaceFormat::A8R8G8B8_UINT32);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-06-15 21:25:55 +03:00
|
|
|
const RefPtr<gfxXlibSurface> surf =
|
|
|
|
gfxXlibSurface::Create(screen, visual, desc.size);
|
|
|
|
surf->ReleasePixmap();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-06-15 21:25:55 +03:00
|
|
|
return AsUnique(new SharedSurface_GLXDrawable(desc, surf));
|
2015-07-30 19:40:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
SharedSurface_GLXDrawable::SharedSurface_GLXDrawable(
|
2020-06-15 21:25:55 +03:00
|
|
|
const SharedSurfaceDesc& desc, const RefPtr<gfxXlibSurface>& xlibSurface)
|
|
|
|
: SharedSurface(desc, nullptr), mXlibSurface(xlibSurface) {}
|
|
|
|
|
|
|
|
SharedSurface_GLXDrawable::~SharedSurface_GLXDrawable() = default;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-01-06 02:57:44 +03:00
|
|
|
void SharedSurface_GLXDrawable::ProducerReleaseImpl() {
|
2020-06-15 21:25:55 +03:00
|
|
|
mDesc.gl->MakeCurrent();
|
|
|
|
mDesc.gl->fFlush();
|
2015-07-30 19:40:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void SharedSurface_GLXDrawable::LockProdImpl() {
|
2020-06-15 21:25:55 +03:00
|
|
|
GLContextGLX::Cast(mDesc.gl)->OverrideDrawable(mXlibSurface->GetGLXPixmap());
|
2015-07-30 19:40:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void SharedSurface_GLXDrawable::UnlockProdImpl() {
|
2020-06-15 21:25:55 +03:00
|
|
|
GLContextGLX::Cast(mDesc.gl)->RestoreDrawable();
|
2015-07-30 19:40:56 +03:00
|
|
|
}
|
|
|
|
|
2020-06-15 21:25:55 +03:00
|
|
|
Maybe<layers::SurfaceDescriptor>
|
|
|
|
SharedSurface_GLXDrawable::ToSurfaceDescriptor() {
|
|
|
|
if (!mXlibSurface) return {};
|
|
|
|
const bool sameProcess = false;
|
|
|
|
return Some(layers::SurfaceDescriptorX11(mXlibSurface, sameProcess));
|
2015-07-30 19:40:56 +03:00
|
|
|
}
|
|
|
|
|
2015-10-12 06:21:03 +03:00
|
|
|
bool SharedSurface_GLXDrawable::ReadbackBySharedHandle(
|
|
|
|
gfx::DataSourceSurface* out_surface) {
|
|
|
|
MOZ_ASSERT(out_surface);
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfx::DataSourceSurface> dataSurf =
|
2015-10-12 06:21:03 +03:00
|
|
|
new gfx::DataSourceSurfaceCairo(mXlibSurface->CairoSurface());
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-10-12 06:21:03 +03:00
|
|
|
gfx::DataSourceSurface::ScopedMap mapSrc(dataSurf,
|
|
|
|
gfx::DataSourceSurface::READ);
|
|
|
|
if (!mapSrc.IsMapped()) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-10-12 06:21:03 +03:00
|
|
|
gfx::DataSourceSurface::ScopedMap mapDest(out_surface,
|
|
|
|
gfx::DataSourceSurface::WRITE);
|
|
|
|
if (!mapDest.IsMapped()) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-10-12 06:21:03 +03:00
|
|
|
if (mapDest.GetStride() == mapSrc.GetStride()) {
|
|
|
|
memcpy(mapDest.GetData(), mapSrc.GetData(),
|
|
|
|
out_surface->GetSize().height * mapDest.GetStride());
|
|
|
|
} else {
|
|
|
|
for (int32_t i = 0; i < dataSurf->GetSize().height; i++) {
|
|
|
|
memcpy(mapDest.GetData() + i * mapDest.GetStride(),
|
|
|
|
mapSrc.GetData() + i * mapSrc.GetStride(),
|
|
|
|
std::min(mapSrc.GetStride(), mapDest.GetStride()));
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-10-12 06:21:03 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-06-15 21:25:55 +03:00
|
|
|
SurfaceFactory_GLXDrawable::SurfaceFactory_GLXDrawable(GLContext& gl)
|
|
|
|
: SurfaceFactory({&gl, SharedSurfaceType::GLXDrawable,
|
|
|
|
layers::TextureType::X11, true}) {}
|
2015-07-30 19:40:56 +03:00
|
|
|
|
2020-01-18 16:48:34 +03:00
|
|
|
} // namespace mozilla::gl
|