aboutsummaryrefslogtreecommitdiffstats
path: root/src/gamma-drm.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gamma-drm.c')
-rw-r--r--src/gamma-drm.c75
1 files changed, 60 insertions, 15 deletions
diff --git a/src/gamma-drm.c b/src/gamma-drm.c
index 9fc6354..dec7074 100644
--- a/src/gamma-drm.c
+++ b/src/gamma-drm.c
@@ -14,9 +14,14 @@
You should have received a copy of the GNU General Public License
along with Redshift. If not, see <http://www.gnu.org/licenses/>.
- Copyright (c) 2014 Mattias Andrée <maandree@member.fsf.org>
+ Copyright (c) 2014 Mattias Andrée <m@maandree.se>
+ Copyright (c) 2017 Jon Lund Steffensen <jonlst@gmail.com>
*/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
@@ -37,24 +42,49 @@
#define O_CLOEXEC 02000000
#endif
+#include <xf86drm.h>
+#include <xf86drmMode.h>
+
#include "gamma-drm.h"
#include "colorramp.h"
-int
-drm_init(drm_state_t *state)
+typedef struct {
+ int crtc_num;
+ int crtc_id;
+ int gamma_size;
+ uint16_t* r_gamma;
+ uint16_t* g_gamma;
+ uint16_t* b_gamma;
+} drm_crtc_state_t;
+
+typedef struct {
+ int card_num;
+ int crtc_num;
+ int fd;
+ drmModeRes* res;
+ drm_crtc_state_t* crtcs;
+} drm_state_t;
+
+
+static int
+drm_init(drm_state_t **state)
{
/* Initialize state. */
- state->card_num = 0;
- state->crtc_num = -1;
- state->fd = -1;
- state->res = NULL;
- state->crtcs = NULL;
+ *state = malloc(sizeof(drm_state_t));
+ if (*state == NULL) return -1;
+
+ drm_state_t *s = *state;
+ s->card_num = 0;
+ s->crtc_num = -1;
+ s->fd = -1;
+ s->res = NULL;
+ s->crtcs = NULL;
return 0;
}
-int
+static int
drm_start(drm_state_t *state, program_mode_t mode)
{
/* Acquire access to a graphics card. */
@@ -172,7 +202,7 @@ drm_start(drm_state_t *state, program_mode_t mode)
return 0;
}
-void
+static void
drm_restore(drm_state_t *state)
{
drm_crtc_state_t *crtcs = state->crtcs;
@@ -185,7 +215,7 @@ drm_restore(drm_state_t *state)
}
}
-void
+static void
drm_free(drm_state_t *state)
{
if (state->crtcs != NULL) {
@@ -206,9 +236,11 @@ drm_free(drm_state_t *state)
close(state->fd);
state->fd = -1;
}
+
+ free(state);
}
-void
+static void
drm_print_help(FILE *f)
{
fputs(_("Adjust gamma ramps with Direct Rendering Manager.\n"), f);
@@ -221,7 +253,7 @@ drm_print_help(FILE *f)
fputs("\n", f);
}
-int
+static int
drm_set_option(drm_state_t *state, const char *key, const char *value)
{
if (strcasecmp(key, "card") == 0) {
@@ -240,8 +272,9 @@ drm_set_option(drm_state_t *state, const char *key, const char *value)
return 0;
}
-int
-drm_set_temperature(drm_state_t *state, const color_setting_t *setting)
+static int
+drm_set_temperature(
+ drm_state_t *state, const color_setting_t *setting, int preserve)
{
drm_crtc_state_t *crtcs = state->crtcs;
uint32_t last_gamma_size = 0;
@@ -288,3 +321,15 @@ drm_set_temperature(drm_state_t *state, const color_setting_t *setting)
return 0;
}
+
+
+const gamma_method_t drm_gamma_method = {
+ "drm", 0,
+ (gamma_method_init_func *)drm_init,
+ (gamma_method_start_func *)drm_start,
+ (gamma_method_free_func *)drm_free,
+ (gamma_method_print_help_func *)drm_print_help,
+ (gamma_method_set_option_func *)drm_set_option,
+ (gamma_method_restore_func *)drm_restore,
+ (gamma_method_set_temperature_func *)drm_set_temperature
+};