diff --git a/definitions/CMakeLists.txt b/definitions/CMakeLists.txt index 9a549df4..ea163809 100644 --- a/definitions/CMakeLists.txt +++ b/definitions/CMakeLists.txt @@ -26,7 +26,6 @@ project_version(1.0.0) find_package(CompileSettingsDebug REQUIRED) find_package(JsonGenerator REQUIRED) find_package(${NAMESPACE}Core REQUIRED) -find_package(${NAMESPACE}PrivilegedRequest QUIET) set(Target ${NAMESPACE}${PROJECT_NAME}) @@ -40,11 +39,6 @@ file(GLOB INTERFACE_FILE ${INTERFACES_PATTERNS}) set(PUBLIC_HEADERS "definitions.h" "ValuePoint.h") -if (${NAMESPACE}PrivilegedRequest_FOUND) - message(STATUS "Found Privileged request, so adding CompositionBuffer.h") - list(APPEND PUBLIC_HEADERS "CompositionBuffer.h") -endif() - if(NOT GENERATOR_SEARCH_PATH) set(GENERATOR_SEARCH_PATH ${CMAKE_SYSROOT}${CMAKE_INSTALL_PREFIX}/include/${NAMESPACE}) endif() diff --git a/definitions/CompositionBuffer.h b/definitions/CompositionBuffer.h deleted file mode 100644 index 2e8e0829..00000000 --- a/definitions/CompositionBuffer.h +++ /dev/null @@ -1,487 +0,0 @@ -/* - * If not stated otherwise in this file or this component's LICENSE file the - * following copyright and licenses apply: - * - * Copyright 2022 Metrological B.V. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include - -namespace WPEFramework { - -namespace Exchange { - - template - class CompositionBufferType : public ICompositionBuffer, public Core::IResource { - private: - // We need to test this on a 32 bit platform. On 64 bits platforms we do need - // the data to be written into the eventfd to be 64 bits otherwise it does not - // respond! - using EventFrame = uintptr_t; - - // We need some shared space for data to exchange, and to create a lock.. - class SharedStorage { - private: - struct PlaneStorage { - uint32_t _stride; - uint32_t _offset; - }; - - public: - void* operator new(size_t stAllocateBlock, int fd) - { - void* result = ::mmap(nullptr, stAllocateBlock, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - return (result != MAP_FAILED ? result : nullptr); - } - // Somehow Purify gets lost if we do not delete it, overide the delete operator - void operator delete(void* stAllocateBlock) - { - ::munmap(stAllocateBlock, sizeof(struct SharedStorage)); - } - - public: - SharedStorage(SharedStorage&&) = delete; - SharedStorage(const SharedStorage&) = delete; - SharedStorage& operator=(const SharedStorage&) = delete; - - SharedStorage() - : _width(0) - , _height(0) - , _format(0) - , _modifier(0) - , _dirty() - , _copyOfDirty() - { - } - SharedStorage(const uint32_t width, const uint32_t height, const uint32_t format, const uint64_t modifier) - : _width(width) - , _height(height) - , _format(format) - , _modifier(modifier) - , _dirty() - , _copyOfDirty(false) - { - if (::pthread_mutex_init(&_mutex, nullptr) != 0) { - // That will be the day, if this fails... - ASSERT(false); - } - } - ~SharedStorage() - { - ::pthread_mutex_destroy(&(_mutex)); - } - - public: - uint32_t Width() const - { - return (_width); - } - uint32_t Height() const - { - return (_height); - } - uint32_t Format() const - { - return (_format); - } - uint32_t Modifier() const - { - return (_modifier); - } - uint32_t Stride(const uint8_t index) const - { // Bytes per row for a plane [(bit-per-pixel/8) * width] - return (_planes[index]._stride); - } - uint32_t Offset(const uint8_t index) const - { // Offset of the plane from where the pixel data starts in the buffer. - return (_planes[index]._offset); - } - void Add(uint8_t index, const uint32_t stride, const uint32_t offset) - { - _planes[index]._stride = stride; - _planes[index]._offset = offset; - } - bool Dirty() - { - _copyOfDirty = false; - return (_dirty.test_and_set() == false); - } - bool IsDirty() - { - return (_copyOfDirty); - } - void Set() - { - _dirty.clear(); - _copyOfDirty = true; - } - uint32_t Lock(uint32_t timeout) - { - timespec structTime; - - clock_gettime(CLOCK_MONOTONIC, &structTime); - structTime.tv_nsec += ((timeout % 1000) * 1000 * 1000); /* remainder, milliseconds to nanoseconds */ - structTime.tv_sec += (timeout / 1000) + (structTime.tv_nsec / 1000000000); /* milliseconds to seconds */ - structTime.tv_nsec = structTime.tv_nsec % 1000000000; - int result = pthread_mutex_timedlock(&_mutex, &structTime); - return (result == 0 ? Core::ERROR_NONE : Core::ERROR_TIMEDOUT); - } - uint32_t Unlock() - { - pthread_mutex_unlock(&_mutex); - return (Core::ERROR_NONE); - } - - private: - uint32_t _width; - uint32_t _height; - uint32_t _format; - uint64_t _modifier; - PlaneStorage _planes[PLANES]; - pthread_mutex_t _mutex; - std::atomic_flag _dirty; - bool _copyOfDirty; - }; - - class Iterator : public ICompositionBuffer::IIterator { - private: - class PlaneImplementation : public ::Compositor::Interfaces::IBuffer::IPlane { - public: - PlaneImplementation(PlaneImplementation&&) = delete; - PlaneImplementation(const PlaneImplementation&) = delete; - PlaneImplementation& operator=(const PlaneImplementation&) = delete; - - PlaneImplementation() - : _parent(nullptr) - , _index(-1) - { - } - ~PlaneImplementation() override = default; - - public: - void Define(CompositionBufferType& parent, const uint8_t index) - { - _parent = &parent; - _index = index; - } - buffer_id Accessor() const override - { // Access to the actual data. - ASSERT(_parent != nullptr); - return (_parent->Accessor(_index)); - } - uint32_t Stride() const override - { // Bytes per row for a plane [(bit-per-pixel/8) * width] - ASSERT(_parent != nullptr); - ASSERT(_parent->_storage != nullptr); - return (_parent->_storage->Stride(_index)); - } - uint32_t Offset() const override - { // Offset of the plane from where the pixel data starts in the buffer. - ASSERT(_parent != nullptr); - ASSERT(_parent->_storage != nullptr); - return (_parent->_storage->Offset(_index)); - } - - private: - CompositionBufferType* _parent; - uint8_t _index; - }; - - public: - Iterator() = delete; - Iterator(Iterator&&) = delete; - Iterator(const Iterator&) = delete; - Iterator& operator=(const Iterator&) = delete; - - Iterator(CompositionBufferType& parent) - : _parent(parent) - { - // Fill our elements - for (uint8_t index = 0; index < PLANES; index++) { - _planes[index].Define(_parent, index); - } - - Reset(); - } - ~Iterator() override = default; - - public: - bool IsValid() const override - { - return ((_position > 0) && (_position <= _parent.Planes())); - } - void Reset() override - { - _position = 0; - } - bool Next() override - { - if (_position <= _parent.Planes()) { - _position++; - } - return (IsValid()); - } - IPlane* Plane() override - { - ASSERT(IsValid() == true); - return (&(_planes[_position - 1])); - } - - private: - CompositionBufferType& _parent; - PlaneImplementation _planes[PLANES]; - uint8_t _position; - }; - - public: - CompositionBufferType() = delete; - CompositionBufferType(CompositionBufferType&&) = delete; - CompositionBufferType(const CompositionBufferType&) = delete; - CompositionBufferType& operator=(const CompositionBufferType&) = delete; - - CompositionBufferType(const string& callsign, const uint32_t id, const uint32_t width, const uint32_t height, const uint32_t format, const uint64_t modifier) - : _id(id) - , _planeCount(0) - , _iterator(*this) - , _virtualFd(-1) - , _eventFd(-1) - , _storage(nullptr) - { - string definition = _T("NotifiableBuffer") + callsign; - _virtualFd = ::memfd_create(definition.c_str(), MFD_ALLOW_SEALING | MFD_CLOEXEC); - if (_virtualFd != -1) { - int length = sizeof(struct SharedStorage); - - /* Size the file as specified by our struct. */ - if (::ftruncate(_virtualFd, length) != -1) { - /* map that file to a memory area we can directly access as a memory mapped file */ - _storage = new (_virtualFd) SharedStorage(width, height, format, modifier); - if (_storage != nullptr) { - _eventFd = ::eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK | EFD_SEMAPHORE); - } - } - } - } - CompositionBufferType(const uint32_t id, Core::PrivilegedRequest::Container& descriptors) - : _id(id) - , _planeCount(0) - , _iterator(*this) - , _virtualFd(-1) - , _eventFd(-1) - , _storage(nullptr) - { - ASSERT(descriptors.size() >= 3); - - if (descriptors.size() >= 3) { - Core::PrivilegedRequest::Container::iterator index(descriptors.begin()); - - _virtualFd = index->Move(); - index++; - - ASSERT(_virtualFd != -1); - - _storage = new (_virtualFd) SharedStorage(); - if (_storage == nullptr) { - ::close(_virtualFd); - } else { - _eventFd = index->Move(); - index++; - - ASSERT(_eventFd != -1); - - while ((index != descriptors.end()) && (_planeCount < PLANES)) { - _planes[_planeCount] = index->Move(); - index++; - _planeCount++; - } - } - } - } - ~CompositionBufferType() override - { - if (_eventFd != -1) { - ::close(_eventFd); - _eventFd = -1; - - ASSERT(_storage != nullptr); - } - if (_storage != nullptr) { - delete _storage; - _storage = nullptr; - } - if (_virtualFd != -1) { - ::close(_virtualFd); - _virtualFd = -1; - } - - // Close all the FileDescriptors handedn over to us for the planes. - for (uint8_t index = 0; index < _planeCount; index++) { - ::close(_planes[index]); - } - } - - public: - bool IsValid() const - { - return (_eventFd != -1); - } - uint8_t Descriptors(const uint8_t maxSize, int container[]) const - { - ASSERT(IsValid() == true); - ASSERT(maxSize > 2); - uint8_t result = 0; - - if (maxSize > 2) { - container[0] = _virtualFd; - container[1] = _eventFd; - uint8_t count = std::min(_planeCount, static_cast(maxSize - 2)); - for (uint8_t index = 0; (index < count); index++) { - container[index + 2] = _planes[index]; - } - result = 2 + count; - } - return (result); - } - - // - // Implementation of Core::IResource - // ----------------------------------------------------------------- - handle Descriptor() const override - { - return (_eventFd); - } - uint16_t Events() override - { - return (POLLIN); - } - void Handle(const uint16_t events) override - { - EventFrame value; - - if (((events & POLLIN) != 0) && (::read(_eventFd, &value, sizeof(EventFrame)) == sizeof(EventFrame))) { - if (_storage->Dirty() == true) { - Render(); - } - } - } - - // - // Implementation of Exchange::ICompositionBuffer - // ----------------------------------------------------------------- - // Wait time in milliseconds. - IIterator* Planes(const uint32_t waitTimeInMs) override - { // Access to the buffer planes. - if (Lock(waitTimeInMs) == Core::ERROR_NONE) { - _iterator.Reset(); - return (&_iterator); - } - return (nullptr); - } - virtual uint32_t Completed(const bool dirty) - { - Unlock(); - if (dirty == true) { - EventFrame value = 1; - _storage->Set(); - size_t result = ::write(_eventFd, &value, sizeof(value)); - return (result != sizeof(value) ? Core::ERROR_ILLEGAL_STATE : Core::ERROR_NONE); - } - return (Core::ERROR_NONE); - } - - uint32_t Identifier() const override - { - return (_id); - } - uint32_t Width() const override - { // Width of the allocated buffer in pixels - ASSERT(_storage != nullptr); - return (_storage->Width()); - } - uint32_t Height() const override - { // Height of the allocated buffer in pixels - ASSERT(_storage != nullptr); - return (_storage->Height()); - } - uint32_t Format() const override - { // Layout of a pixel according the fourcc format - ASSERT(_storage != nullptr); - return (_storage->Format()); - } - uint64_t Modifier() const override - { // Pixel arrangement in the buffer, used to optimize for hardware - ASSERT(_storage != nullptr); - return (_storage->Modifier()); - } - uint8_t Planes() const - { - return (_planeCount); - } - bool IsDirty() const - { - ASSERT(_storage != nullptr); - return (_storage->IsDirty()); - } - - protected: - void Add(int fd, const uint32_t stride, const uint32_t offset) - { - ASSERT(fd > 0); - ASSERT((_planeCount + 1) <= PLANES); - _storage->Add(_planeCount, stride, offset); - _planes[_planeCount] = ::dup(fd); - _planeCount++; - } - - private: - buffer_id Accessor(const uint8_t index) const - { // Access to the actual data. - ASSERT(index < _planeCount); - return (_planes[index]); - } - uint32_t Lock(const uint32_t timeout) - { - return (_storage->Lock(timeout)); - } - uint32_t Unlock() - { - return (_storage->Unlock()); - } - - private: - uint32_t _id; - uint8_t _planeCount; - Iterator _iterator; - - // We need a descriptor that is pointing to the virtual memory (shared memory) - int _virtualFd; - - // We need a descriptor we can wait for and that can be signalled - int _eventFd; - - // From the virtual memory we can map the shared data to a memory area in "our" process. - SharedStorage* _storage; - - int _planes[PLANES]; - }; - -} -} diff --git a/definitions/Definitions.cpp b/definitions/Definitions.cpp index 662207e7..b7d0bf0f 100644 --- a/definitions/Definitions.cpp +++ b/definitions/Definitions.cpp @@ -323,7 +323,6 @@ namespace Exchange return ((static_cast(resolution) < sizeof(resolutionWidthHeightTable) / sizeof(ScreenResolutionWidthHeight)) ? resolutionWidthHeightTable[static_cast(resolution)].refresh: 0); } - // ------------------------------------------------------------------------ // Convenience methods to extract interesting information from the Type() // ------------------------------------------------------------------------