Skip to content

Commit

Permalink
clang-format
Browse files Browse the repository at this point in the history
Signed-off-by: Joel Winarske <[email protected]>
  • Loading branch information
jwinarske committed May 7, 2024
1 parent 91c0e39 commit 7c4bb58
Show file tree
Hide file tree
Showing 64 changed files with 8,402 additions and 7,890 deletions.
12 changes: 12 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Defines the Chromium style for automatic reformatting.
# http://clang.llvm.org/docs/ClangFormatStyleOptions.html
BasedOnStyle: Chromium
# This defaults to 'Auto'. Explicitly set it for a while, so that
# 'vector<vector<int> >' in existing files gets formatted to
# 'vector<vector<int>>'. ('Auto' means that clang-format will only use
# 'int>>' if the file already contains at least one such instance.)
Standard: c++17
SortIncludes: CaseSensitive
---
Language: ObjC
ColumnLimit: 100
309 changes: 158 additions & 151 deletions examples/agl-capture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,175 +29,182 @@
#include "window_manager/agl_shell.h"
#include "window_manager/weston-capture.h"


struct Configuration {
bool write_back;
bool frame_buffer;
bool full_frame_buffer;
bool blending;
std::string output;
bool list;
bool all;
bool write_back;
bool frame_buffer;
bool full_frame_buffer;
bool blending;
std::string output;
bool list;
bool all;
};

static volatile bool gRunning = true;

class App : public WestonCaptureObserver {
public:
explicit App(const Configuration &config) : logging_(std::make_unique<Logging>()), weston_capture_v1_(nullptr) {

display_ = wl_display_connect(nullptr);
if (!display_) {
spdlog::critical("Unable to connect to Wayland socket.");
exit(EXIT_FAILURE);
}

agl_shell_ = std::make_unique<AglShell>(display_, false);
auto d = agl_shell_->get_display();

// required when not creating a window
wl_display_roundtrip(d);

if (config.list) {
auto &outputs = agl_shell_->get_outputs();
for (const auto &output: outputs) {
spdlog::info("Output: {}", output.second->get_name());
}
exit(EXIT_SUCCESS);
}

/// Weston Capture
weston_capture_v1_ = agl_shell_->get_weston_capture_v1();
if (!weston_capture_v1_) {
spdlog::critical("weston_capture_v1 interface not found.");
exit(EXIT_FAILURE);
}

/// Source
enum weston_capture_v1_source source = WESTON_CAPTURE_V1_SOURCE_FULL_FRAMEBUFFER;
if (config.write_back) {
source = WESTON_CAPTURE_V1_SOURCE_WRITEBACK;
} else if (config.frame_buffer) {
source = WESTON_CAPTURE_V1_SOURCE_FRAMEBUFFER;
} else if (config.full_frame_buffer) {
source = WESTON_CAPTURE_V1_SOURCE_FULL_FRAMEBUFFER;
} else if (config.blending) {
source = WESTON_CAPTURE_V1_SOURCE_BLENDING;
}

/// Output
if (!config.all) {
struct wl_output *output{};

if (!config.output.empty()) {
output = agl_shell_->find_output_by_name(config.output);
} else {
output = agl_shell_->get_primary_output();
}

if (!output) {
spdlog::critical("Output not available.");
exit(EXIT_FAILURE);
}

weston_capture_list_.push_back(
std::make_unique<WestonCapture>(weston_capture_v1_, output, source, this, this));
} else {
for (auto &output: agl_shell_->get_outputs()) {
weston_capture_list_.push_back(
std::make_unique<WestonCapture>(weston_capture_v1_, output.first, source, this, this));
}
}

spdlog::info("AGL Capture");
public:
explicit App(const Configuration& config)
: logging_(std::make_unique<Logging>()), weston_capture_v1_(nullptr) {
display_ = wl_display_connect(nullptr);
if (!display_) {
spdlog::critical("Unable to connect to Wayland socket.");
exit(EXIT_FAILURE);
}

void notify_weston_capture_format(void *user_data,
struct weston_capture_source_v1 * /* weston_capture_source_v1 */,
uint32_t drm_format) override {
auto obj = static_cast<App *>(user_data);
obj->buffer_.drm_format = drm_format;
spdlog::debug("drm_format: 0x{:X}", drm_format);
}
agl_shell_ = std::make_unique<AglShell>(display_, false);
auto d = agl_shell_->get_display();

void notify_weston_capture_size(void *user_data,
struct weston_capture_source_v1 * /* weston_capture_source_v1 */,
int32_t width,
int32_t height) override {
auto obj = static_cast<App *>(user_data);
obj->buffer_.width = width;
obj->buffer_.height = height;
spdlog::debug("width: {}, height: {}", width, height);
}
// required when not creating a window
wl_display_roundtrip(d);

void notify_weston_capture_complete(void * /* user_data */,
struct weston_capture_source_v1 * /* weston_capture_source_v1 */) override {
gRunning = false;
spdlog::debug("complete");
if (config.list) {
auto& outputs = agl_shell_->get_outputs();
for (const auto& output : outputs) {
spdlog::info("Output: {}", output.second->get_name());
}
exit(EXIT_SUCCESS);
}

void notify_weston_capture_retry(void * /* user_data */,
struct weston_capture_source_v1 * /* weston_capture_source_v1 */) override {
spdlog::debug("retry");
/// Weston Capture
weston_capture_v1_ = agl_shell_->get_weston_capture_v1();
if (!weston_capture_v1_) {
spdlog::critical("weston_capture_v1 interface not found.");
exit(EXIT_FAILURE);
}

void notify_weston_capture_failed(void * /* user_data */,
struct weston_capture_source_v1 * /* weston_capture_source_v1 */,
const char *msg) override {
spdlog::debug("failed: {}", msg);
/// Source
enum weston_capture_v1_source source =
WESTON_CAPTURE_V1_SOURCE_FULL_FRAMEBUFFER;
if (config.write_back) {
source = WESTON_CAPTURE_V1_SOURCE_WRITEBACK;
} else if (config.frame_buffer) {
source = WESTON_CAPTURE_V1_SOURCE_FRAMEBUFFER;
} else if (config.full_frame_buffer) {
source = WESTON_CAPTURE_V1_SOURCE_FULL_FRAMEBUFFER;
} else if (config.blending) {
source = WESTON_CAPTURE_V1_SOURCE_BLENDING;
}

~App() override {
if (display_) {
wl_display_flush(display_);
wl_display_disconnect(display_);
}
};

bool run() {
/// display_dispatch is blocking
return (gRunning && agl_shell_->display_dispatch() != -1);
/// Output
if (!config.all) {
struct wl_output* output{};

if (!config.output.empty()) {
output = agl_shell_->find_output_by_name(config.output);
} else {
output = agl_shell_->get_primary_output();
}

if (!output) {
spdlog::critical("Output not available.");
exit(EXIT_FAILURE);
}

weston_capture_list_.push_back(std::make_unique<WestonCapture>(
weston_capture_v1_, output, source, this, this));
} else {
for (auto& output : agl_shell_->get_outputs()) {
weston_capture_list_.push_back(std::make_unique<WestonCapture>(
weston_capture_v1_, output.first, source, this, this));
}
}

private:
struct wl_display *display_;
std::unique_ptr<Logging> logging_;
std::unique_ptr<AglShell> agl_shell_;
std::list<std::unique_ptr<WestonCapture>> weston_capture_list_;
struct weston_capture_v1 *weston_capture_v1_;

struct {
uint32_t drm_format;
int32_t width;
int32_t height;
} buffer_{};
spdlog::info("AGL Capture");
}

void notify_weston_capture_format(
void* user_data,
struct weston_capture_source_v1* /* weston_capture_source_v1 */,
uint32_t drm_format) override {
auto obj = static_cast<App*>(user_data);
obj->buffer_.drm_format = drm_format;
spdlog::debug("drm_format: 0x{:X}", drm_format);
}

void notify_weston_capture_size(
void* user_data,
struct weston_capture_source_v1* /* weston_capture_source_v1 */,
int32_t width,
int32_t height) override {
auto obj = static_cast<App*>(user_data);
obj->buffer_.width = width;
obj->buffer_.height = height;
spdlog::debug("width: {}, height: {}", width, height);
}

void notify_weston_capture_complete(
void* /* user_data */,
struct weston_capture_source_v1* /* weston_capture_source_v1 */)
override {
gRunning = false;
spdlog::debug("complete");
}

void notify_weston_capture_retry(
void* /* user_data */,
struct weston_capture_source_v1* /* weston_capture_source_v1 */)
override {
spdlog::debug("retry");
}

void notify_weston_capture_failed(
void* /* user_data */,
struct weston_capture_source_v1* /* weston_capture_source_v1 */,
const char* msg) override {
spdlog::debug("failed: {}", msg);
}

~App() override {
if (display_) {
wl_display_flush(display_);
wl_display_disconnect(display_);
}
};

bool run() {
/// display_dispatch is blocking
return (gRunning && agl_shell_->display_dispatch() != -1);
}

private:
struct wl_display* display_;
std::unique_ptr<Logging> logging_;
std::unique_ptr<AglShell> agl_shell_;
std::list<std::unique_ptr<WestonCapture>> weston_capture_list_;
struct weston_capture_v1* weston_capture_v1_;

struct {
uint32_t drm_format;
int32_t width;
int32_t height;
} buffer_{};
};

int main(int argc, char **argv) {

cxxopts::Options options("agl-capture", "AGL Output Capture Utility");
options.add_options()
("w,writeback", "Use hardware writeback")
("d,framebuffer", "Copy from framebuffer, desktop area")
("f,full-framebuffer", "Copy whole framebuffer, including borders")
("b,blending", "Copy from blending space")
("o,output", "take a screenshot of the output specified by OUTPUT_NAME", cxxopts::value<std::string>())
("l,list", "list all the outputs found")
("a,all", "take a screenshot of all the outputs found");

auto result = options.parse(argc, argv);

App app({
.write_back = result["writeback"].as<bool>(),
.frame_buffer = result["framebuffer"].as<bool>(),
.full_frame_buffer = result["full-framebuffer"].as<bool>(),
.blending = result["blending"].as<bool>(),
.output = result.count("output") ? result["output"].as<std::string>() : "",
.list = result["list"].as<bool>(),
.all = result["all"].as<bool>(),
});

while (app.run()) {}

return EXIT_SUCCESS;
int main(int argc, char** argv) {
cxxopts::Options options("agl-capture", "AGL Output Capture Utility");
options.add_options()("w,writeback", "Use hardware writeback")(
"d,framebuffer", "Copy from framebuffer, desktop area")(
"f,full-framebuffer", "Copy whole framebuffer, including borders")(
"b,blending", "Copy from blending space")(
"o,output", "take a screenshot of the output specified by OUTPUT_NAME",
cxxopts::value<std::string>())("l,list", "list all the outputs found")(
"a,all", "take a screenshot of all the outputs found");

auto result = options.parse(argc, argv);

App app({
.write_back = result["writeback"].as<bool>(),
.frame_buffer = result["framebuffer"].as<bool>(),
.full_frame_buffer = result["full-framebuffer"].as<bool>(),
.blending = result["blending"].as<bool>(),
.output =
result.count("output") ? result["output"].as<std::string>() : "",
.list = result["list"].as<bool>(),
.all = result["all"].as<bool>(),
});

while (app.run()) {
}

return EXIT_SUCCESS;
}
Loading

0 comments on commit 7c4bb58

Please sign in to comment.