-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathRockchipRga.cpp
More file actions
executable file
·175 lines (147 loc) · 4.16 KB
/
Copy pathRockchipRga.cpp
File metadata and controls
executable file
·175 lines (147 loc) · 4.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
* Copyright (C) 2016 Rockchip Electronics Co.Ltd
* Authors:
* Zhiqin Wei <wzq@rock-chips.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
*/
#define LOG_NDEBUG 0
#ifdef LOG_TAG
#undef LOG_TAG
#define LOG_TAG "rockchiprga"
#endif
#include <stdint.h>
#include <sys/types.h>
#include <math.h>
#include <fcntl.h>
#include <signal.h>
#include <time.h>
#include "RockchipRga.h"
//#include "RgaApi.h"
#include "version.h"
#include "normal/NormalRga.h"
#include <drm.h>
#include "drm_mode.h"
#include "xf86drm.h"
// ---------------------------------------------------------------------------
RockchipRga::RockchipRga():
mSupportRga(false),
mLogOnce(0),
mLogAlways(0),
mContext(NULL)
{
RkRgaInit();
printf("Rga built version:%s \n", RK_GRAPHICS_VER);
}
RockchipRga::~RockchipRga()
{
RgaDeInit(mContext);
}
int RockchipRga::RkRgaInit()
{
int ret = 0;
ret = RgaInit(&mContext);
if(ret == 0)
mSupportRga = true;
else
mSupportRga = false;
return ret;
}
int RockchipRga::RkRgaGetAllocBuffer(bo_t *bo_info, int width, int height, int bpp)
{
struct drm_mode_create_dumb arg;
int ret;
memset(&arg, 0, sizeof(arg));
arg.bpp = bpp;
arg.width = width;
arg.height = height;
bo_info->fd = open("/dev/dri/card0", O_RDWR, 0);
ret = drmIoctl(bo_info->fd, DRM_IOCTL_MODE_CREATE_DUMB, &arg);
if (ret) {
fprintf(stderr, "failed to create dumb buffer: %s\n", strerror(errno));
return ret;
}
bo_info->handle = arg.handle;
bo_info->size = arg.size;
bo_info->pitch = arg.pitch;
return 0;
}
int RockchipRga::RkRgaGetMmap(bo_t *bo_info)
{
struct drm_mode_map_dumb arg;
void *map;
int ret;
memset(&arg, 0, sizeof(arg));
arg.handle = bo_info->handle;
ret = drmIoctl(bo_info->fd, DRM_IOCTL_MODE_MAP_DUMB, &arg);
if (ret)
return ret;
map = mmap64(0, bo_info->size, PROT_READ | PROT_WRITE, MAP_SHARED, bo_info->fd, arg.offset);
if (map == MAP_FAILED)
return -EINVAL;
bo_info->ptr = map;
return 0;
}
int RockchipRga::RkRgaUnmap(bo_t *bo_info)
{
munmap(bo_info->ptr, bo_info->size);
bo_info->ptr = NULL;
return 0;
}
int RockchipRga::RkRgaFree(bo_t *bo_info)
{
struct drm_mode_destroy_dumb arg;
int ret;
memset(&arg, 0, sizeof(arg));
arg.handle = bo_info->handle;
ret = drmIoctl(bo_info->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &arg);
if (ret){
fprintf(stderr, "failed to destroy dumb buffer: %s\n", strerror(errno));
return -EINVAL;
}
return 0;
}
int RockchipRga::RkRgaGetBufferFd(bo_t *bo_info, int *fd)
{
int ret = 0;
ret = drmPrimeHandleToFD(bo_info->fd, bo_info->handle, 0, fd);
return ret;
}
int RockchipRga::RkRgaBlit(rga_info *src, rga_info *dst, rga_info *src1)
{
int ret = 0;
ret = RgaBlit(src, dst, src1);
if (ret) {
RkRgaLogOutUserPara(src);
RkRgaLogOutUserPara(dst);
RkRgaLogOutUserPara(src1);
printf("This output the user patamaters when rga call blit fail \n");
}
return ret;
}
int RockchipRga::RkRgaCollorFill(rga_info *dst)
{
int ret = 0;
ret = RgaCollorFill(dst);
return ret;
}
int RockchipRga::RkRgaLogOutUserPara(rga_info *rgaInfo)
{
if (!rgaInfo)
return -EINVAL;
printf("fd-vir-phy-hnd-format[%d, %p, %p, %p, %d] \n", rgaInfo->fd,
rgaInfo->virAddr, rgaInfo->phyAddr, (void*)rgaInfo->hnd, rgaInfo->format);
printf("rect[%d, %d, %d, %d, %d, %d, %d, %d] \n",
rgaInfo->rect.xoffset, rgaInfo->rect.yoffset,
rgaInfo->rect.width, rgaInfo->rect.height, rgaInfo->rect.wstride,
rgaInfo->rect.hstride, rgaInfo->rect.format, rgaInfo->rect.size);
printf("f-blend-size-rotation-col-log-mmu[%d, %x, %d, %d, %d, %d, %d] \n",
rgaInfo->format, rgaInfo->blend, rgaInfo->bufferSize,
rgaInfo->rotation, rgaInfo->color, rgaInfo->testLog, rgaInfo->mmuFlag);
return 0;
}
// ---------------------------------------------------------------------------