-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3067 from MirServer/platform-API-merge-fix-eglstr…
…eams Sharing CpuAdressableDisplayProvider between eglstreams and gbm platforms
- Loading branch information
Showing
27 changed files
with
486 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/platforms/common/server/kms_cpu_addressable_display_provider.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
52
src/platforms/common/server/kms_cpu_addressable_display_provider.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.