-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disable Autoformat like the kernel guidelines suggest. Add instructions to generate `compile_commands.json`. Modernize cpp code. Fix incorrect version in test. Add instructions to build python module. Fix makefile to use virtual env if activated.
- Loading branch information
Showing
14 changed files
with
1,004 additions
and
229 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -20,3 +20,8 @@ tmp/ | |
checkpatch.pl | ||
const_structs.checkpatch | ||
spelling.txt | ||
|
||
__pycache__/ | ||
evdienv/ | ||
.cache/ | ||
compile_commands.json |
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,12 @@ | ||
{ | ||
"[cpp]": { | ||
"editor.formatOnType": false, | ||
"editor.formatOnPaste": false, | ||
"editor.formatOnSave": false | ||
}, | ||
"[c]": { | ||
"editor.formatOnType": false, | ||
"editor.formatOnPaste": false, | ||
"editor.formatOnSave": false | ||
} | ||
} |
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 |
---|---|---|
@@ -1,38 +1,45 @@ | ||
// Copyright (c) 2022 DisplayLink (UK) Ltd. | ||
#include "Buffer.h" | ||
#include "../library/evdi_lib.h" | ||
#include <cstdlib> | ||
#include <cstdio> | ||
|
||
#include "../library/evdi_lib.h" | ||
#include "Buffer.h" | ||
|
||
int Buffer::numerator = 0; | ||
|
||
Buffer::Buffer(evdi_mode mode, evdi_handle evdiHandle) | ||
{ | ||
int id = numerator++; | ||
int id = numerator++; | ||
|
||
this->evdiHandle = evdiHandle; | ||
int stride = mode.width; | ||
int pitch_mask = 63; | ||
this->evdiHandle = evdiHandle; | ||
int stride = mode.width; | ||
int pitch_mask = 63; | ||
|
||
stride += pitch_mask; | ||
stride &= ~pitch_mask; | ||
stride *= 4; | ||
|
||
buffer.id = id; | ||
buffer.width = mode.width; | ||
buffer.height = mode.height; | ||
buffer.stride = stride; | ||
buffer.rect_count = 16; | ||
buffer.rects = reinterpret_cast<evdi_rect*>( | ||
calloc(buffer.rect_count, sizeof(struct evdi_rect))); | ||
buffer.buffer = calloc(mode.width*mode.width, mode.bits_per_pixel/8); | ||
buffer.id = id; | ||
buffer.width = mode.width; | ||
buffer.height = mode.height; | ||
buffer.stride = stride; | ||
buffer.rect_count = 16; | ||
buffer.rects = reinterpret_cast<evdi_rect *>( | ||
calloc(buffer.rect_count, sizeof(struct evdi_rect))); | ||
rects_span = std::span<evdi_rect>(buffer.rects, buffer.rect_count); | ||
bytes_per_pixel = mode.bits_per_pixel / 8; | ||
buffer_size = mode.width * mode.height * bytes_per_pixel; | ||
buffer.buffer = calloc(1, buffer_size); | ||
buffer_span = | ||
std::span<uint32_t>(reinterpret_cast<uint32_t *>(buffer.buffer), | ||
buffer_size / sizeof(uint32_t)); | ||
|
||
evdi_register_buffer(evdiHandle, buffer); | ||
evdi_register_buffer(evdiHandle, buffer); | ||
} | ||
|
||
Buffer::~Buffer() | ||
{ | ||
evdi_unregister_buffer(evdiHandle, buffer.id); | ||
free(buffer.buffer); | ||
free(buffer.rects); | ||
evdi_unregister_buffer(evdiHandle, buffer.id); | ||
free(buffer.buffer); | ||
free(buffer.rects); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,167 +1,166 @@ | ||
// Copyright (c) 2022 DisplayLink (UK) Ltd. | ||
#include <format> | ||
|
||
#include "../library/evdi_lib.h" | ||
#include <pybind11/pybind11.h> | ||
#include "Card.h" | ||
#include "Buffer.h" | ||
|
||
namespace py = pybind11; | ||
|
||
|
||
void default_update_ready_handler(int buffer_to_be_updated, void *user_data) | ||
{ | ||
Card* card_ptr = reinterpret_cast<Card*>(user_data); | ||
assert(buffer_to_be_updated == card_ptr->buffer_requested->buffer.id); | ||
card_ptr->grab_pixels(); | ||
Card *card_ptr = reinterpret_cast<Card *>(user_data); | ||
assert(buffer_to_be_updated == card_ptr->buffer_requested->buffer.id); | ||
card_ptr->grab_pixels(); | ||
} | ||
|
||
void card_C_mode_handler(struct evdi_mode mode, void *user_data) | ||
{ | ||
py::module logging = py::module::import("logging"); | ||
logging.attr("info")("Got mode_changed signal."); | ||
Card* card = reinterpret_cast<Card*>(user_data); | ||
py::module logging = py::module::import("logging"); | ||
logging.attr("info")("Got mode_changed signal."); | ||
Card *card = reinterpret_cast<Card *>(user_data); | ||
|
||
assert(card); | ||
assert(card); | ||
|
||
card->setMode(mode); | ||
card->makeBuffers(2); | ||
card->setMode(mode); | ||
card->makeBuffers(2); | ||
|
||
if(card->m_modeHandler != nullptr){ | ||
card->m_modeHandler(mode); | ||
} | ||
if (!card->mode_handler_cb.is_none()) { | ||
card->mode_handler_cb(mode); | ||
} | ||
|
||
card->request_update(); | ||
card->request_update(); | ||
} | ||
|
||
void Card::setMode(struct evdi_mode mode) | ||
{ | ||
this->mode = mode; | ||
this->mode = mode; | ||
} | ||
|
||
void Card::makeBuffers(int count) | ||
{ | ||
clearBuffers(); | ||
for(int i=0; i<count; i++){ | ||
buffers.emplace_back(new Buffer(mode, evdiHandle)); | ||
} | ||
clearBuffers(); | ||
for (int i = 0; i < count; i++) { | ||
buffers.emplace_back(new Buffer(mode, evdiHandle)); | ||
} | ||
} | ||
|
||
void Card::clearBuffers() | ||
{ | ||
buffer_requested.reset(); | ||
buffers.clear(); | ||
buffer_requested.reset(); | ||
buffers.clear(); | ||
} | ||
|
||
void dpms_handler(int dpms_mode, void* /*user_data*/){ | ||
py::module logging = py::module::import("logging"); | ||
logging.attr("info")("Got dpms signal." + std::to_string(dpms_mode)); | ||
void dpms_handler(int dpms_mode, void * /*user_data*/) | ||
{ | ||
py::module logging = py::module::import("logging"); | ||
logging.attr("info")(std::format("Got dpms signal: \"{}\"", dpms_mode)); | ||
} | ||
|
||
Card::Card(int device) : | ||
evdiHandle(evdi_open(device)) | ||
Card::Card(int device) | ||
: evdiHandle(evdi_open(device)) | ||
{ | ||
if(evdiHandle==nullptr) | ||
{ | ||
throw py::value_error("Card /dev/dri/card" + std::to_string(device) + "does not exists!"); | ||
} | ||
|
||
memset(&eventContext, 0, sizeof(eventContext)); | ||
if (evdiHandle == nullptr) { | ||
throw py::value_error(std::format( | ||
"Failed to open card \"/dev/dri/card{}\"", device)); | ||
} | ||
|
||
m_modeHandler = nullptr; | ||
acquire_framebuffer_cb = nullptr; | ||
memset(&eventContext, 0, sizeof(eventContext)); | ||
|
||
eventContext.mode_changed_handler = &card_C_mode_handler; | ||
eventContext.update_ready_handler = &default_update_ready_handler; | ||
eventContext.dpms_handler=dpms_handler; | ||
eventContext.user_data = this; | ||
eventContext.mode_changed_handler = &card_C_mode_handler; | ||
eventContext.update_ready_handler = &default_update_ready_handler; | ||
eventContext.dpms_handler = dpms_handler; | ||
eventContext.user_data = this; | ||
|
||
memset(&mode, 0, sizeof(mode)); | ||
memset(&mode, 0, sizeof(mode)); | ||
} | ||
|
||
Card::~Card() | ||
{ | ||
close(); | ||
close(); | ||
} | ||
|
||
void Card::close() | ||
{ | ||
if(evdiHandle != nullptr) | ||
{ | ||
clearBuffers(); | ||
evdi_close(evdiHandle); | ||
} | ||
evdiHandle = nullptr; | ||
if (evdiHandle != nullptr) { | ||
clearBuffers(); | ||
evdi_close(evdiHandle); | ||
} | ||
evdiHandle = nullptr; | ||
} | ||
|
||
void Card::connect(const char *edid, const unsigned int edid_length, | ||
const uint32_t pixel_area_limit, const uint32_t pixel_per_second_limit) | ||
const uint32_t pixel_area_limit, | ||
const uint32_t pixel_per_second_limit) | ||
{ | ||
evdi_connect2(evdiHandle, reinterpret_cast<const unsigned char *>(edid), | ||
edid_length, pixel_area_limit, pixel_per_second_limit); | ||
evdi_connect2(evdiHandle, reinterpret_cast<const unsigned char *>(edid), | ||
edid_length, pixel_area_limit, pixel_per_second_limit); | ||
} | ||
|
||
void Card::disconnect() | ||
{ | ||
evdi_disconnect(evdiHandle); | ||
evdi_disconnect(evdiHandle); | ||
} | ||
|
||
struct evdi_mode Card::getMode() const | ||
{ | ||
return mode; | ||
return mode; | ||
} | ||
|
||
void Card::handle_events(int waiting_time) | ||
{ | ||
fd_set rfds; | ||
struct timeval tv; | ||
FD_ZERO(&rfds); | ||
int fd = evdi_get_event_ready(evdiHandle); | ||
FD_SET(fd, &rfds); | ||
tv.tv_sec = 0; | ||
tv.tv_usec = waiting_time*1000; | ||
|
||
request_update(); | ||
|
||
if(select(fd + 1, &rfds, NULL, NULL, &tv)){ | ||
evdi_handle_events(evdiHandle, &eventContext); | ||
} | ||
fd_set rfds; | ||
struct timeval tv; | ||
FD_ZERO(&rfds); | ||
int fd = evdi_get_event_ready(evdiHandle); | ||
FD_SET(fd, &rfds); | ||
tv.tv_sec = 0; | ||
tv.tv_usec = waiting_time * 1000; | ||
|
||
request_update(); | ||
|
||
if (select(fd + 1, &rfds, NULL, NULL, &tv)) { | ||
evdi_handle_events(evdiHandle, &eventContext); | ||
} | ||
} | ||
|
||
void Card::request_update() | ||
{ | ||
if(buffer_requested){ | ||
return; | ||
} | ||
|
||
for(auto &i : buffers){ | ||
if(i.use_count() == 1) | ||
{ | ||
buffer_requested = i; | ||
break; | ||
} | ||
} | ||
|
||
if(!buffer_requested){ | ||
return; | ||
} | ||
|
||
bool update_ready = evdi_request_update(evdiHandle, buffer_requested->buffer.id); | ||
|
||
if(update_ready){ | ||
grab_pixels(); | ||
} | ||
if (buffer_requested) { | ||
return; | ||
} | ||
|
||
for (auto &i : buffers) { | ||
if (i.use_count() == 1) { | ||
buffer_requested = i; | ||
break; | ||
} | ||
} | ||
|
||
if (!buffer_requested) { | ||
return; | ||
} | ||
|
||
bool update_ready = | ||
evdi_request_update(evdiHandle, buffer_requested->buffer.id); | ||
|
||
if (update_ready) { | ||
grab_pixels(); | ||
} | ||
} | ||
|
||
void Card::grab_pixels() | ||
{ | ||
if(!buffer_requested){ | ||
return; | ||
} | ||
if (!buffer_requested) { | ||
return; | ||
} | ||
|
||
evdi_grab_pixels(evdiHandle, buffer_requested->buffer.rects, &buffer_requested->buffer.rect_count); | ||
evdi_grab_pixels(evdiHandle, buffer_requested->buffer.rects, | ||
&buffer_requested->buffer.rect_count); | ||
|
||
if(acquire_framebuffer_cb) | ||
acquire_framebuffer_cb(std::move(buffer_requested)); | ||
buffer_requested = nullptr; | ||
if (acquire_framebuffer_cb) | ||
acquire_framebuffer_cb(std::move(buffer_requested)); | ||
buffer_requested = nullptr; | ||
|
||
request_update(); | ||
request_update(); | ||
} |
Oops, something went wrong.