Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gamma control API #216

Merged
merged 1 commit into from
Jan 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/wlc/wlc.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,12 @@ bool wlc_output_get_sleep(wlc_handle output);
/** Wake up / sleep. */
void wlc_output_set_sleep(wlc_handle output, bool sleep);

/** Set gamma. R, G, and B are color ramp arrays of size elements. */
void wlc_output_set_gamma(wlc_handle output, uint16_t size, uint16_t *r, uint16_t *g, uint16_t *b);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering why the rgb are pointers? Arrays?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe document the units or something, or just refer to drm documentation since this API models it I guess.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I dunno how gamma works, I just gave an interface on top of drm. Will mention that in the docs.


/** Get gamma size */
uint16_t wlc_output_get_gamma_size(wlc_handle output);

/**
* Get real resolution.
* Resolution applied by either wlc_output_set_resolution call or initially.
Expand Down
27 changes: 27 additions & 0 deletions src/compositor/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,16 @@ wlc_output_set_sleep_ptr(struct wlc_output *output, bool sleep)
}
}

void
wlc_output_set_gamma_ptr(struct wlc_output *output, uint16_t size, uint16_t *r, uint16_t *g, uint16_t *b)
{
if (!output)
return;

if (output->bsurface.api.set_gamma)
output->bsurface.api.set_gamma(&output->bsurface, size, r, g, b);
}

void
wlc_output_set_mask_ptr(struct wlc_output *output, uint32_t mask)
{
Expand Down Expand Up @@ -913,6 +923,23 @@ wlc_output_set_sleep(wlc_handle output, bool sleep)
wlc_output_set_sleep_ptr(convert_from_wlc_handle(output, "output"), sleep);
}

WLC_API void
wlc_output_set_gamma(wlc_handle output, uint16_t size, uint16_t *r, uint16_t *g, uint16_t *b)
{
wlc_output_set_gamma_ptr(convert_from_wlc_handle(output, "output"), size, r, g, b);
}

WLC_API uint16_t
wlc_output_get_gamma_size(wlc_handle output)
{
struct wlc_output *_output = convert_from_wlc_handle(output, "output");

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

precondition here if (!_output || !_output->bsurface.api.get_gamma_size) return 0;

if (!_output || _output->bsurface.api.get_gamma_size)
return 0;

return _output->bsurface.api.get_gamma_size(&_output->bsurface);
}

WLC_API uint32_t
wlc_output_get_mask(wlc_handle output)
{
Expand Down
1 change: 1 addition & 0 deletions src/compositor/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ WLC_NONULL bool wlc_output(struct wlc_output *output);

void wlc_output_focus_ptr(struct wlc_output *output);
void wlc_output_set_sleep_ptr(struct wlc_output *output, bool sleep);
void wlc_output_set_gamma_ptr(struct wlc_output *output, uint16_t size, uint16_t *r, uint16_t *g, uint16_t *b);
WLC_NONULLV(2) bool wlc_output_set_resolution_ptr(struct wlc_output *output, const struct wlc_size *resolution, uint32_t scale);
void wlc_output_set_mask_ptr(struct wlc_output *output, uint32_t mask);
WLC_NONULLV(2) void wlc_output_get_pixels_ptr(struct wlc_output *output, bool (*pixels)(const struct wlc_size *size, uint8_t *rgba, void *arg), void *arg);
Expand Down
2 changes: 2 additions & 0 deletions src/platform/backend/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ struct wlc_backend_surface {
WLC_NONULL void (*terminate)(struct wlc_backend_surface *surface);
WLC_NONULL void (*sleep)(struct wlc_backend_surface *surface, bool sleep);
WLC_NONULL bool (*page_flip)(struct wlc_backend_surface *surface);
WLC_NONULL void (*set_gamma)(struct wlc_backend_surface *bsurface, uint16_t size, uint16_t *r, uint16_t *g, uint16_t *b);
WLC_NONULL uint16_t (*get_gamma_size)(struct wlc_backend_surface *bsurface);
} api;
};

Expand Down
16 changes: 16 additions & 0 deletions src/platform/backend/drm.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,20 @@ surface_sleep(struct wlc_backend_surface *bsurface, bool sleep)
}
}

static void
set_gamma(struct wlc_backend_surface *bsurface, uint16_t size, uint16_t *r, uint16_t *g, uint16_t *b)
{
struct drm_surface *dsurface = bsurface->internal;
drmModeCrtcSetGamma(drm.fd, dsurface->crtc->crtc_id, size, r, g, b);
}

static uint16_t
get_gamma_size(struct wlc_backend_surface *bsurface)
{
struct drm_surface *dsurface = bsurface->internal;
return dsurface->crtc->gamma_size;
}

static void
surface_release(struct wlc_backend_surface *bsurface)
{
Expand Down Expand Up @@ -232,6 +246,8 @@ add_output(struct gbm_device *device, struct gbm_surface *surface, struct drm_ou
bsurface.window = (EGLNativeWindowType)surface;
bsurface.api.sleep = surface_sleep;
bsurface.api.page_flip = page_flip;
bsurface.api.set_gamma = set_gamma;
bsurface.api.get_gamma_size = get_gamma_size;

struct wlc_output_event ev = { .add = { &bsurface, &info->info }, .type = WLC_OUTPUT_EVENT_ADD };
wl_signal_emit(&wlc_system_signals()->output, &ev);
Expand Down