Skip to content

Commit

Permalink
Merge pull request #3067 from MirServer/platform-API-merge-fix-eglstr…
Browse files Browse the repository at this point in the history
…eams

Sharing CpuAdressableDisplayProvider between eglstreams and gbm platforms
  • Loading branch information
AlanGriffiths authored Oct 26, 2023
2 parents 60a5409 + 1705d00 commit deca1ba
Show file tree
Hide file tree
Showing 27 changed files with 486 additions and 189 deletions.
5 changes: 5 additions & 0 deletions src/platforms/common/server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ add_library(server_platform_common STATIC
one_shot_device_observer.cpp
cpu_copy_output_surface.cpp
cpu_copy_output_surface.h
kms_cpu_addressable_display_provider.cpp
kms_cpu_addressable_display_provider.h
cpu_addressable_fb.cpp
cpu_addressable_fb.h
kms_framebuffer.h
options_parsing_helpers.h
options_parsing_helpers.cpp
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#include "cpu_addressable_fb.h"

#include "mir/geometry/forward.h"
#include "mir/log.h"
#include "mir_toolkit/common.h"

Expand All @@ -26,9 +25,8 @@
#include <drm_fourcc.h>

namespace mg = mir::graphics;
namespace mgg = mg::gbm;

class mgg::CPUAddressableFB::Buffer : public mir::renderer::software::RWMappableBuffer
class mg::CPUAddressableFB::Buffer : public mir::renderer::software::RWMappableBuffer
{
template<typename T>
class Mapping : public mir::renderer::software::Mapping<T>
Expand All @@ -53,7 +51,7 @@ class mgg::CPUAddressableFB::Buffer : public mir::renderer::software::RWMappable
if (::munmap(const_cast<typename std::remove_const<T>::type *>(data_), len_) == -1)
{
// It's unclear how this could happen, but tell *someone* about it if it does!
mir::log_error("Failed to unmap CPU buffer: %s (%i)", strerror(errno), errno);
log_error("Failed to unmap CPU buffer: %s (%i)", strerror(errno), errno);
}
}

Expand Down Expand Up @@ -102,7 +100,7 @@ class mgg::CPUAddressableFB::Buffer : public mir::renderer::software::RWMappable

if (auto const err = drmIoctl(drm_fd, DRM_IOCTL_MODE_DESTROY_DUMB, &params))
{
mir::log_error("Failed destroy CPU-accessible buffer: %s (%i)", strerror(-err), -err);
log_error("Failed destroy CPU-accessible buffer: %s (%i)", strerror(-err), -err);
}
}

Expand Down Expand Up @@ -248,7 +246,7 @@ class mgg::CPUAddressableFB::Buffer : public mir::renderer::software::RWMappable
size_t const size_;
};

mgg::CPUAddressableFB::CPUAddressableFB(
mg::CPUAddressableFB::CPUAddressableFB(
mir::Fd const& drm_fd,
bool supports_modifiers,
DRMFormat format,
Expand All @@ -257,12 +255,12 @@ mgg::CPUAddressableFB::CPUAddressableFB(
{
}

mgg::CPUAddressableFB::~CPUAddressableFB()
mg::CPUAddressableFB::~CPUAddressableFB()
{
drmModeRmFB(drm_fd, fb_id);
}

mgg::CPUAddressableFB::CPUAddressableFB(
mg::CPUAddressableFB::CPUAddressableFB(
mir::Fd drm_fd,
bool supports_modifiers,
DRMFormat format,
Expand All @@ -273,32 +271,32 @@ mgg::CPUAddressableFB::CPUAddressableFB(
{
}

auto mgg::CPUAddressableFB::map_writeable() -> std::unique_ptr<mir::renderer::software::Mapping<unsigned char>>
auto mg::CPUAddressableFB::map_writeable() -> std::unique_ptr<mir::renderer::software::Mapping<unsigned char>>
{
return buffer->map_writeable();
}

auto mgg::CPUAddressableFB::format() const -> MirPixelFormat
auto mg::CPUAddressableFB::format() const -> MirPixelFormat
{
return buffer->format();
}

auto mgg::CPUAddressableFB::stride() const -> geometry::Stride
auto mg::CPUAddressableFB::stride() const -> geometry::Stride
{
return buffer->stride();
}

auto mgg::CPUAddressableFB::size() const -> geometry::Size
auto mg::CPUAddressableFB::size() const -> geometry::Size
{
return buffer->size();
}

mgg::CPUAddressableFB::operator uint32_t() const
mg::CPUAddressableFB::operator uint32_t() const
{
return fb_id;
}

auto mgg::CPUAddressableFB::fb_id_for_buffer(
auto mg::CPUAddressableFB::fb_id_for_buffer(
mir::Fd const &drm_fd,
bool supports_modifiers,
DRMFormat format,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef MIR_GRAPHICS_GBM_FB_H_
#define MIR_GRAPHICS_GBM_FB_H_
#ifndef MIR_GRAPHICS_CPU_ADDRESSABLE_FB_H_
#define MIR_GRAPHICS_CPU_ADDRESSABLE_FB_H_

#include "mir/fd.h"
#include "mir/graphics/platform.h"

#include "kms_framebuffer.h"

namespace mir::graphics::gbm
namespace mir::graphics
{
class CPUAddressableFB : public FBHandle, public CPUAddressableDisplayProvider::MappableFB
{
Expand Down Expand Up @@ -65,4 +65,4 @@ class CPUAddressableFB : public FBHandle, public CPUAddressableDisplayProvider::

}

#endif //MIR_GRAPHICS_GBM_FB_H_
#endif //MIR_GRAPHICS_CPU_ADDRESSABLE_FB_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright © Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 2 or 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "kms_cpu_addressable_display_provider.h"
#include "cpu_addressable_fb.h"
#include <drm_fourcc.h>
#include <xf86drm.h>

namespace
{
auto drm_get_cap_checked(mir::Fd const& drm_fd, uint64_t cap) -> uint64_t
{
uint64_t value;
if (drmGetCap(drm_fd, cap, &value))
{
BOOST_THROW_EXCEPTION((
std::system_error{
errno,
std::system_category(),
"Failed to query DRM capabilities"}));
}
return value;
}
}

namespace mg = mir::graphics;
namespace geom = mir::geometry;

mg::kms::CPUAddressableDisplayProvider::CPUAddressableDisplayProvider(mir::Fd drm_fd)
: drm_fd{std::move(drm_fd)},
supports_modifiers{drm_get_cap_checked(this->drm_fd, DRM_CAP_ADDFB2_MODIFIERS) == 1}
{
}

auto mg::kms::CPUAddressableDisplayProvider::supported_formats() const
-> std::vector<mg::DRMFormat>
{
// TODO: Pull out of DRM info
return {mg::DRMFormat{DRM_FORMAT_XRGB8888}, mg::DRMFormat{DRM_FORMAT_ARGB8888}};
}

auto mg::kms::CPUAddressableDisplayProvider::alloc_fb(
geom::Size size, DRMFormat format) -> std::unique_ptr<MappableFB>
{
return std::make_unique<mg::CPUAddressableFB>(drm_fd, supports_modifiers, format, size);
}

auto mir::graphics::kms::CPUAddressableDisplayProvider::create_if_supported(mir::Fd const& drm_fd)
-> std::shared_ptr<CPUAddressableDisplayProvider>
{
if (drm_get_cap_checked(drm_fd, DRM_CAP_DUMB_BUFFER))
{
return std::shared_ptr<CPUAddressableDisplayProvider>(new CPUAddressableDisplayProvider{drm_fd});
}
else
{
return {};
}
}
52 changes: 52 additions & 0 deletions src/platforms/common/server/kms_cpu_addressable_display_provider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright © Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 2 or 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef MIR_GRAPHICS_BASIC_CPU_ADDRESSABLE_DISPLAY_PROVIDER_H
#define MIR_GRAPHICS_BASIC_CPU_ADDRESSABLE_DISPLAY_PROVIDER_H

#include "mir/graphics/platform.h"
#include <mir/fd.h>

namespace mir
{
namespace graphics
{
namespace kms
{
class CPUAddressableDisplayProvider : public graphics::CPUAddressableDisplayProvider
{
public:
/// Create an CPUAddressableDisplayProvider if and only if supported by the device
/// \return the provider, or an empty pointer
static auto create_if_supported(mir::Fd const& drm_fd) -> std::shared_ptr<CPUAddressableDisplayProvider>;

auto supported_formats() const
-> std::vector<DRMFormat> override;

auto alloc_fb(geometry::Size pixel_size, DRMFormat format)
-> std::unique_ptr<MappableFB> override;

private:
explicit CPUAddressableDisplayProvider(mir::Fd drm_fd);

mir::Fd const drm_fd;
bool const supports_modifiers;
};
}
}
}

#endif //MIR_GRAPHICS_BASIC_CPU_ADDRESSABLE_DISPLAY_PROVIDER_H
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ namespace mir
{
namespace graphics
{
namespace gbm
{
class FBHandle : public Framebuffer
{
public:
Expand All @@ -35,7 +33,6 @@ class FBHandle : public Framebuffer

}
}
}


#endif //MIR_GRAPHICS_GBM_KMS_FRAMEBUFFER_H_
Loading

0 comments on commit deca1ba

Please sign in to comment.