blob: ba5437648cf3b391c22f966ea16357ebc7e5d216 [file] [log] [blame]
Dominik Behr83010f82016-03-18 18:43:08 -07001/*
2 * Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
5 */
6
7#ifndef FB_H
8#define FB_H
9
10#include "drm.h"
11
12typedef struct {
13 int32_t width;
14 int32_t height;
15 int32_t pitch;
16 int32_t scaling;
17 int32_t size;
Dominik Behrbb728f32019-09-03 17:52:13 -070018 int32_t rotation; // DRM_MODE_ROTATE_*
Dominik Behr83010f82016-03-18 18:43:08 -070019} buffer_properties_t;
20
21typedef struct {
22 int32_t count;
23 uint64_t map_offset;
24 uint32_t* map;
25} fb_lock_t;
26
27typedef struct {
28 drm_t *drm;
29 buffer_properties_t buffer_properties;
30 fb_lock_t lock;
31 uint32_t buffer_handle;
32 uint32_t fb_id;
33} fb_t;
34
Dominik Behrbb728f32019-09-03 17:52:13 -070035typedef struct {
36 fb_t *fb;
37 int32_t start_x, start_y;
38 uint32_t w, h;
39 uint32_t x, y;
40 int32_t max_x, max_y;
41 uint32_t pitch_div_4;
42 int32_t m[2][3];
43} fb_stepper_t;
44
Dominik Behr83010f82016-03-18 18:43:08 -070045fb_t* fb_init(void);
46void fb_close(fb_t* fb);
47int32_t fb_setmode(fb_t* fb);
48int fb_buffer_init(fb_t* fb);
49void fb_buffer_destroy(fb_t* fb);
50uint32_t* fb_lock(fb_t* fb);
51void fb_unlock(fb_t* fb);
52int32_t fb_getwidth(fb_t* fb);
53int32_t fb_getheight(fb_t* fb);
Dominik Behr83010f82016-03-18 18:43:08 -070054int32_t fb_getscaling(fb_t* fb);
Dominik Behrbb728f32019-09-03 17:52:13 -070055bool fb_stepper_init(fb_stepper_t *s, fb_t *fb, int32_t x, int32_t y, uint32_t width, uint32_t height);
56
Manoj Gupta98f42b32019-10-01 09:36:35 -070057bool static inline fb_stepper_step_x(fb_stepper_t *s, uint32_t rgba)
Dominik Behrbb728f32019-09-03 17:52:13 -070058{
59 int32_t x = s->start_x + s->x;
60 int32_t y = s->start_y + s->y;
61 int32_t p;
62
63 if (x >= 0 && x < s->max_x
64 && y >= 0 && y < s->max_y) {
65 p = (x * s->m[0][0] + y * s->m[0][1] + s->m[0][2])
66 + (x * s->m[1][0] + y * s->m[1][1] + s->m[1][2]) * s->pitch_div_4;
67 s->fb->lock.map[p] = rgba;
68 }
69
70 s->x++;
71 if (s->x >= s->w) {
72 s->x = 0;
73 return false;
74 }
75 return true;
76}
77
78bool inline fb_stepper_step_y(fb_stepper_t *s)
79{
80 s->y++;
81 return s->y < s->h;
82}
Dominik Behr83010f82016-03-18 18:43:08 -070083
84#endif