Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 12 | typedef struct { |
| 13 | int32_t width; |
| 14 | int32_t height; |
| 15 | int32_t pitch; |
| 16 | int32_t scaling; |
| 17 | int32_t size; |
Dominik Behr | bb728f3 | 2019-09-03 17:52:13 -0700 | [diff] [blame] | 18 | int32_t rotation; // DRM_MODE_ROTATE_* |
Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 19 | } buffer_properties_t; |
| 20 | |
| 21 | typedef struct { |
| 22 | int32_t count; |
| 23 | uint64_t map_offset; |
| 24 | uint32_t* map; |
| 25 | } fb_lock_t; |
| 26 | |
| 27 | typedef 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 Behr | bb728f3 | 2019-09-03 17:52:13 -0700 | [diff] [blame] | 35 | typedef 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 Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 45 | fb_t* fb_init(void); |
| 46 | void fb_close(fb_t* fb); |
| 47 | int32_t fb_setmode(fb_t* fb); |
| 48 | int fb_buffer_init(fb_t* fb); |
| 49 | void fb_buffer_destroy(fb_t* fb); |
| 50 | uint32_t* fb_lock(fb_t* fb); |
| 51 | void fb_unlock(fb_t* fb); |
| 52 | int32_t fb_getwidth(fb_t* fb); |
| 53 | int32_t fb_getheight(fb_t* fb); |
Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 54 | int32_t fb_getscaling(fb_t* fb); |
Dominik Behr | bb728f3 | 2019-09-03 17:52:13 -0700 | [diff] [blame] | 55 | bool fb_stepper_init(fb_stepper_t *s, fb_t *fb, int32_t x, int32_t y, uint32_t width, uint32_t height); |
| 56 | |
Manoj Gupta | 98f42b3 | 2019-10-01 09:36:35 -0700 | [diff] [blame] | 57 | bool static inline fb_stepper_step_x(fb_stepper_t *s, uint32_t rgba) |
Dominik Behr | bb728f3 | 2019-09-03 17:52:13 -0700 | [diff] [blame] | 58 | { |
| 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 | |
| 78 | bool inline fb_stepper_step_y(fb_stepper_t *s) |
| 79 | { |
| 80 | s->y++; |
| 81 | return s->y < s->h; |
| 82 | } |
Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 83 | |
| 84 | #endif |