summaryrefslogtreecommitdiffstats
path: root/dynamic-layers/chromium-browser-layer/recipes-browser/chromium/chromium-ozone-wayland/0118-V4L2VDA-Use-dlopen-to-dynamically-use-g2d-api.patch
blob: 7cd0b8524d07cc128a999f150451486b28f5678b (plain)
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
From 59bf28174104b591088a08e2ed61644cc93101fd Mon Sep 17 00:00:00 2001
From: Hou Qi <qi.hou@nxp.com>
Date: Thu, 22 Sep 2022 11:10:46 +0800
Subject: [PATCH] V4L2VDA: Use dlopen to dynamically use g2d api

Upstream-Status: Inappropriate [NXP specific]
---
 media/gpu/v4l2/BUILD.gn       |   1 -
 media/gpu/v4l2/v4l2_device.cc | 205 ++++++++++++++++++++++++++++++++--
 2 files changed, 194 insertions(+), 12 deletions(-)

diff --git a/media/gpu/v4l2/BUILD.gn b/media/gpu/v4l2/BUILD.gn
index 273f6066de175..ebd0a4ad64646 100644
--- a/media/gpu/v4l2/BUILD.gn
+++ b/media/gpu/v4l2/BUILD.gn
@@ -86,7 +86,6 @@ source_set("v4l2") {
     "EGL",
     "GLESv2",
   ]
-  libs += [ "g2d" ]
 
   if (use_v4l2_codec_aml) {
     sources += [
diff --git a/media/gpu/v4l2/v4l2_device.cc b/media/gpu/v4l2/v4l2_device.cc
index 42cd8386f41cb..af71f54d141aa 100644
--- a/media/gpu/v4l2/v4l2_device.cc
+++ b/media/gpu/v4l2/v4l2_device.cc
@@ -40,10 +40,12 @@
 #include "media/gpu/v4l2/aml_v4l2_device.h"
 #endif
 
-#include "g2d.h"
-#include "g2dExt.h"
+// #include "g2d.h"
+// #include "g2dExt.h"
+
 #include <linux/dma-buf.h>
 #include <time.h>
+#include <dlfcn.h>
 
 namespace media {
 
@@ -142,6 +144,158 @@ void V4L2ProcessingTrace(const struct v4l2_buffer* v4l2_buffer, bool start) {
 
 }  // namespace
 
+/*  g2d.h  g2dExt.h  */
+enum g2d_format
+{
+//rgb formats
+     G2D_RGB565               = 0,    /* [0:4] Blue;  [5:10] Green; [11:15] Red                      */
+     G2D_RGBA8888             = 1,    /* [0:7] Red;   [8:15] Green; [16:23] Blue; [23:31] Alpha      */
+     G2D_RGBX8888             = 2,    /* [0:7] Red;   [8:15] Green; [16:23] Blue; [23:31] don't care */
+     G2D_BGRA8888             = 3,    /* [0:7] Blue;  [8:15] Green; [16:23] Red; [23:31] Alpha       */
+     G2D_BGRX8888             = 4,    /* [0:7] Blue;  [8:15] Green; [16:23] Red; [23:31] don't care  */
+     G2D_BGR565               = 5,    /* [0:4] Red;   [5:10] Green; [11:15] Blue                     */
+
+     G2D_ARGB8888             = 6,    /* [0:7] Alpha; [8:15] Red;   [16:23] Green; [23:31] Blue      */
+     G2D_ABGR8888             = 7,    /* [0:7] Alpha; [8:15] Blue;  [16:23] Green; [23:31] Red       */
+     G2D_XRGB8888             = 8,    /* [0:7] don't care; [8:15] Red;  [16:23] Green; [23:31] Blue  */
+     G2D_XBGR8888             = 9,    /* [0:7] don't care; [8:15] Blue; [16:23] Green; [23:31] Red   */
+     G2D_RGB888               = 10,   /* [0:7] Red;   [8:15] Green; [16:23] Blue                     */
+     G2D_BGR888               = 11,   /* [0:7] Blue;  [8:15] Green; [16:23] Red                      */
+
+     G2D_RGBA5551             = 12,    /* [0:4] Red;   [5:9] Green; [10:14] Blue; [15] Alpha      */
+     G2D_RGBX5551             = 13,    /* [0:4] Red;   [5:9] Green; [10:14] Blue; [15] don't care */
+     G2D_BGRA5551             = 14,    /* [0:4] Blue;  [5:9] Green; [10:14] Red;  [15] Alpha       */
+     G2D_BGRX5551             = 15,    /* [0:4] Blue;  [5:9] Green; [10:14] Red;  [15] don't care  */
+
+//yuv formats
+     G2D_NV12                 = 20,   /* 2 plane 420 format; plane 1: [0:7] Y ; plane 2: [0:7] U; [8:15] V */
+     G2D_I420                 = 21,   /* 3 plane 420 format; plane 1: [0:7] Y ; plane 2: [0:7] U; plane 3: [0:7] V */
+     G2D_YV12                 = 22,   /* 3 plane 420 format; plane 1: [0:7] Y ; plane 2: [0:7] V; plane 3: [0:7] U */
+     G2D_NV21                 = 23,   /* 2 plane 420 format; plane 1: [0:7] Y ; plane 2: [0:7] V; [8:15] U */
+     G2D_YUYV                 = 24,   /* 1 plane 422 format; [0:7] Y; [8:15; U; [16:23] Y; [24:31] V */
+     G2D_YVYU                 = 25,   /* 1 plane 422 format; [0:7] Y; [8:15; V; [16:23] Y; [24:31] U */
+     G2D_UYVY                 = 26,   /* 1 plane 422 format; [0:7] U; [8:15; Y; [16:23] V; [24:31] Y */
+     G2D_VYUY                 = 27,   /* 1 plane 422 format; [0:7] V; [8:15; Y; [16:23] U; [24:31] Y */
+     G2D_NV16                 = 28,   /* 2 plane 422 format; plane 1: [0:7] Y ; plane 2: [0:7] U; [8:15] V */
+     G2D_NV61                 = 29,   /* 2 plane 422 format; plane 1: [0:7] Y ; plane 2: [0:7] V; [8:15] U */
+};
+
+enum g2d_tiling
+{
+    G2D_LINEAR              = 0x1,
+    G2D_TILED               = 0x2,
+    G2D_SUPERTILED          = 0x4,
+    G2D_AMPHION_TILED       = 0x8,
+    G2D_AMPHION_INTERLACED  = 0x10,
+    G2D_TILED_STATUS        = 0x20,
+    G2D_AMPHION_TILED_10BIT = 0x40,
+};
+
+struct g2d_tile_status
+{
+    unsigned int ts_addr;
+
+    unsigned int fc_enabled;
+    unsigned int fc_value;
+    unsigned int fc_value_upper;
+};
+
+struct g2d_buf
+{
+    void *buf_handle;
+    void *buf_vaddr;
+    int  buf_paddr;
+    int  buf_size;
+};
+
+enum g2d_blend_func
+{
+//basic blend
+    G2D_ZERO                  = 0,
+    G2D_ONE                   = 1,
+    G2D_SRC_ALPHA             = 2,
+    G2D_ONE_MINUS_SRC_ALPHA   = 3,
+    G2D_DST_ALPHA             = 4,
+    G2D_ONE_MINUS_DST_ALPHA   = 5,
+
+// extensive blend is set with basic blend together,
+// such as, G2D_ONE | G2D_PRE_MULTIPLIED_ALPHA
+    G2D_PRE_MULTIPLIED_ALPHA  = 0x10,
+    G2D_DEMULTIPLY_OUT_ALPHA  = 0x20,
+};
+
+enum g2d_rotation
+{
+    G2D_ROTATION_0            = 0,
+    G2D_ROTATION_90           = 1,
+    G2D_ROTATION_180          = 2,
+    G2D_ROTATION_270          = 3,
+    G2D_FLIP_H                = 4,
+    G2D_FLIP_V                = 5,
+};
+
+struct g2d_surface
+{
+    enum g2d_format format;
+
+    int planes[3];//surface buffer addresses are set in physical planes separately
+                  //RGB:  planes[0] - RGB565/RGBA8888/RGBX8888/BGRA8888/BRGX8888
+                  //NV12: planes[0] - Y, planes[1] - packed UV
+                  //I420: planes[0] - Y, planes[1] - U, planes[2] - V
+                  //YV12: planes[0] - Y, planes[1] - V, planes[2] - U
+                  //NV21: planes[0] - Y, planes[1] - packed VU
+                  //YUYV: planes[0] - packed YUYV
+                  //YVYU: planes[0] - packed YVYU
+                  //UYVY: planes[0] - packed UYVY
+                  //VYUY: planes[0] - packed VYUY
+                  //NV16: planes[0] - Y, planes[1] - packed UV
+                  //NV61: planes[0] - Y, planes[1] - packed VU
+
+    //blit rectangle in surface
+    int left;
+    int top;
+    int right;
+    int bottom;
+    int stride;                     ///< buffer stride, in Pixels
+    int width;                      ///< surface width, in Pixels
+    int height;                     ///< surface height, in Pixels
+    enum g2d_blend_func blendfunc;  ///< alpha blending parameters
+    int global_alpha;               ///< value is 0 ~ 255
+    //clrcolor format is RGBA8888, used as dst for clear, as src for blend dim
+    int clrcolor;
+
+    //rotation degree
+    enum g2d_rotation rot;
+};
+
+struct g2d_surfaceEx
+{
+    struct g2d_surface base;
+    enum   g2d_tiling tiling;
+
+    struct g2d_tile_status ts;
+    int reserved[8];
+};
+
+void *dl_handle = NULL;
+
+typedef int (*g2d_api_open)(void **handle);
+typedef int (*g2d_api_close)(void *handle);
+typedef int (*g2d_api_free)(struct g2d_buf *buf);
+typedef struct g2d_buf* (*g2d_api_alloc)(int size, int cacheable);
+typedef int (*g2d_api_buf_export_fd)(struct g2d_buf *);
+typedef int (*g2d_api_blitEx)(void *handle, struct g2d_surfaceEx *srcEx, struct g2d_surfaceEx *dstEx);
+
+#define G2D_API_SYM(name) g2d_api_##name g2d_##name = nullptr
+G2D_API_SYM(open);
+G2D_API_SYM(close);
+G2D_API_SYM(free);
+G2D_API_SYM(alloc);
+G2D_API_SYM(buf_export_fd);
+G2D_API_SYM(blitEx);
+#undef G2D_API_SYM
+/*  g2d.h  g2dExt.h  */
+
 V4L2ExtCtrl::V4L2ExtCtrl(uint32_t id) {
   memset(&ctrl, 0, sizeof(ctrl));
   ctrl.id = id;
@@ -261,7 +415,7 @@ V4L2Buffer::~V4L2Buffer() {
       }
     }
   }
-  if(g2dbuf_p0 && g2dbuf_p1) {
+  if(g2d_free && g2dbuf_p0 && g2dbuf_p1) {
 	  g2d_free(g2dbuf_p0);
 	  g2d_free(g2dbuf_p1);
   }
@@ -399,14 +553,18 @@ scoped_refptr<VideoFrame> V4L2Buffer::CreateVideoFrame() {
     else
       phys_1 = query1.phys;
 
-    g2dbuf_p0 = g2d_alloc(format_.fmt.pix_mp.width * format_.fmt.pix_mp.height, 0);
-    g2dbuf_p1 = g2d_alloc(format_.fmt.pix_mp.width * format_.fmt.pix_mp.height / 2, 0);
+    if (g2d_alloc) {
+      g2dbuf_p0 = g2d_alloc(format_.fmt.pix_mp.width * format_.fmt.pix_mp.height, 0);
+      g2dbuf_p1 = g2d_alloc(format_.fmt.pix_mp.width * format_.fmt.pix_mp.height / 2, 0);
+    }
     if((!g2dbuf_p0) || (!g2dbuf_p1)){
       DLOG(ERROR)<<"g2d buf alloc failed";
       return nullptr;
     }
 
-    int tmpfd = g2d_buf_export_fd(g2dbuf_p0);
+    int tmpfd = -1;
+    if (g2d_buf_export_fd)
+      tmpfd = g2d_buf_export_fd(g2dbuf_p0);
     tmpfd = dup(tmpfd);
     if(tmpfd > 0)
       g2dbufs_fds.push_back(base::ScopedFD(tmpfd));
@@ -416,7 +574,8 @@ scoped_refptr<VideoFrame> V4L2Buffer::CreateVideoFrame() {
       return nullptr;
     }
 
-    tmpfd = g2d_buf_export_fd(g2dbuf_p1);
+    if (g2d_buf_export_fd)
+      tmpfd = g2d_buf_export_fd(g2dbuf_p1);
     tmpfd = dup(tmpfd);
     if(tmpfd>0)
       g2dbufs_fds.push_back(base::ScopedFD(tmpfd));
@@ -1152,7 +1311,7 @@ V4L2Queue::V4L2Queue(scoped_refptr<V4L2Device> dev,
 #endif
 
   g2d_handle = NULL;
-  if(g2d_open(&g2d_handle))
+  if(g2d_open && g2d_open(&g2d_handle))
     VLOGF(1) << "g2d_open fail";
 }
 
@@ -1172,7 +1331,7 @@ V4L2Queue::~V4L2Queue() {
     DeallocateBuffers();
   }
 
-  if(g2d_handle)
+  if(g2d_close && g2d_handle)
 	  g2d_close(g2d_handle);
 
   std::move(destroy_cb_).Run();
@@ -1573,7 +1732,8 @@ std::pair<bool, V4L2ReadableBufferRef> V4L2Queue::DequeueBuffer() {
 	  src->global_alpha = 0xff;
 	  src->blendfunc = G2D_ONE;
 
-	  g2d_blitEx(g2d_handle, &srcEx, &dstEx);
+    if (g2d_blitEx)
+	    g2d_blitEx(g2d_handle, &srcEx, &dstEx);
   }
 
   return std::make_pair(true, V4L2BufferRefFactory::CreateReadableRef(
@@ -1747,8 +1907,31 @@ scoped_refptr<V4L2Device> V4L2Device::Create() {
 #endif
 
   device = new GenericV4L2Device();
-  if (device->Initialize())
+  if (device->Initialize()) {
+    dl_handle = dlopen("/usr/lib/libg2d.so",
+                        RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE | RTLD_LAZY);
+    if (!dl_handle) {
+      VLOGF(1) << "Has no libg2d.so";
+      return device;
+    }
+
+#define G2D_API_DLSYM(lib, name)                                               \
+    do {                                                                       \
+      g2d_##name = reinterpret_cast<g2d_api_##name>(dlsym(lib, "g2d_" #name)); \
+      if (!(g2d_##name))                                                       \
+        VLOGF(1) << "Failed to dlsym g2d_" #name;                              \
+    } while (0)
+
+    G2D_API_DLSYM(dl_handle, open);
+    G2D_API_DLSYM(dl_handle, close);
+    G2D_API_DLSYM(dl_handle, free);
+    G2D_API_DLSYM(dl_handle, alloc);
+    G2D_API_DLSYM(dl_handle, buf_export_fd);
+    G2D_API_DLSYM(dl_handle, blitEx);
+
     return device;
+  }
+
 
   VLOGF(1) << "Failed to create a V4L2Device";
   return nullptr;
-- 
2.17.1