diff options
Diffstat (limited to 'xbmc/utils/GBMBufferObject.cpp')
| -rw-r--r-- | xbmc/utils/GBMBufferObject.cpp | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/xbmc/utils/GBMBufferObject.cpp b/xbmc/utils/GBMBufferObject.cpp new file mode 100644 index 0000000..88b7575 --- /dev/null +++ b/xbmc/utils/GBMBufferObject.cpp | |||
| @@ -0,0 +1,98 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2005-2018 Team Kodi | ||
| 3 | * This file is part of Kodi - https://kodi.tv | ||
| 4 | * | ||
| 5 | * SPDX-License-Identifier: GPL-2.0-or-later | ||
| 6 | * See LICENSES/README.md for more information. | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include "GBMBufferObject.h" | ||
| 10 | |||
| 11 | #include "BufferObjectFactory.h" | ||
| 12 | #include "ServiceBroker.h" | ||
| 13 | #include "windowing/gbm/WinSystemGbmEGLContext.h" | ||
| 14 | |||
| 15 | #include <gbm.h> | ||
| 16 | |||
| 17 | using namespace KODI::WINDOWING::GBM; | ||
| 18 | |||
| 19 | std::unique_ptr<CBufferObject> CGBMBufferObject::Create() | ||
| 20 | { | ||
| 21 | return std::make_unique<CGBMBufferObject>(); | ||
| 22 | } | ||
| 23 | |||
| 24 | void CGBMBufferObject::Register() | ||
| 25 | { | ||
| 26 | CBufferObjectFactory::RegisterBufferObject(CGBMBufferObject::Create); | ||
| 27 | } | ||
| 28 | |||
| 29 | CGBMBufferObject::CGBMBufferObject() | ||
| 30 | { | ||
| 31 | m_device = static_cast<CWinSystemGbmEGLContext*>(CServiceBroker::GetWinSystem())->GetGBMDevice(); | ||
| 32 | } | ||
| 33 | |||
| 34 | CGBMBufferObject::~CGBMBufferObject() | ||
| 35 | { | ||
| 36 | ReleaseMemory(); | ||
| 37 | DestroyBufferObject(); | ||
| 38 | } | ||
| 39 | |||
| 40 | bool CGBMBufferObject::CreateBufferObject(uint32_t format, uint32_t width, uint32_t height) | ||
| 41 | { | ||
| 42 | if (m_fd >= 0) | ||
| 43 | return true; | ||
| 44 | |||
| 45 | m_width = width; | ||
| 46 | m_height = height; | ||
| 47 | |||
| 48 | m_bo = gbm_bo_create(m_device, m_width, m_height, format, GBM_BO_USE_LINEAR); | ||
| 49 | |||
| 50 | if (!m_bo) | ||
| 51 | return false; | ||
| 52 | |||
| 53 | m_fd = gbm_bo_get_fd(m_bo); | ||
| 54 | |||
| 55 | return true; | ||
| 56 | } | ||
| 57 | |||
| 58 | void CGBMBufferObject::DestroyBufferObject() | ||
| 59 | { | ||
| 60 | close(m_fd); | ||
| 61 | |||
| 62 | if (m_bo) | ||
| 63 | gbm_bo_destroy(m_bo); | ||
| 64 | |||
| 65 | m_bo = nullptr; | ||
| 66 | m_fd = -1; | ||
| 67 | } | ||
| 68 | |||
| 69 | uint8_t* CGBMBufferObject::GetMemory() | ||
| 70 | { | ||
| 71 | if (m_bo) | ||
| 72 | { | ||
| 73 | m_map = static_cast<uint8_t*>(gbm_bo_map(m_bo, 0, 0, m_width, m_height, GBM_BO_TRANSFER_WRITE, &m_stride, &m_map_data)); | ||
| 74 | if (m_map) | ||
| 75 | return m_map; | ||
| 76 | } | ||
| 77 | |||
| 78 | return nullptr; | ||
| 79 | } | ||
| 80 | |||
| 81 | void CGBMBufferObject::ReleaseMemory() | ||
| 82 | { | ||
| 83 | if (m_bo && m_map) | ||
| 84 | { | ||
| 85 | gbm_bo_unmap(m_bo, m_map_data); | ||
| 86 | m_map_data = nullptr; | ||
| 87 | m_map = nullptr; | ||
| 88 | } | ||
| 89 | } | ||
| 90 | |||
| 91 | uint64_t CGBMBufferObject::GetModifier() | ||
| 92 | { | ||
| 93 | #if defined(HAS_GBM_MODIFIERS) | ||
| 94 | return gbm_bo_get_modifier(m_bo); | ||
| 95 | #else | ||
| 96 | return 0; | ||
| 97 | #endif | ||
| 98 | } | ||
