Skip to content

Commit 7e76e08

Browse files
committed
add dummy_render_surface
Simple render surface that just doesn't do anything on fill, queue_present, present_kms, present_fbdev. Mostly useful for debugging platform views. Right now this is used instead when flutter presents a platform view that's not registered to flutter-pi.
1 parent adb56c9 commit 7e76e08

File tree

4 files changed

+190
-1
lines changed

4 files changed

+190
-1
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ add_library(
111111
src/dmabuf_surface.c
112112
src/frame_scheduler.c
113113
src/window.c
114+
src/dummy_render_surface.c
114115
src/plugins/services.c
115116
)
116117

src/compositor_ng.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "util/dynarray.h"
3434
#include "window.h"
3535
#include "cursor.h"
36+
#include "dummy_render_surface.h"
3637

3738
#include "config.h"
3839

@@ -342,7 +343,10 @@ static int compositor_push_fl_layers(struct compositor *compositor, size_t n_fl_
342343
// if we're in debug mode, we actually check if the ID is a valid,
343344
// registered ID.
344345
/// TODO: Implement
345-
layer->surface = surface_ref(compositor_get_view_by_id_locked(compositor, fl_layer->platform_view->identifier));
346+
layer->surface = compositor_get_view_by_id_locked(compositor, fl_layer->platform_view->identifier);
347+
if (layer->surface == NULL) {
348+
layer->surface = CAST_SURFACE(dummy_render_surface_new(compositor->tracer, VEC2I(fl_layer->size.width, fl_layer->size.height)));
349+
}
346350
#else
347351
// in release mode, we just assume the id is valid.
348352
// Since the surface constructs the ID by just casting the surface pointer to an int64_t,

src/dummy_render_surface.c

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
// SPDX-License-Identifier: MIT
2+
/*
3+
* Vulkan GBM Backing Store
4+
*
5+
* - a render surface that can be used for filling flutter vulkan backing stores
6+
* - and for scanout using KMS
7+
*
8+
* Copyright (c) 2022, Hannes Winkler <[email protected]>
9+
*/
10+
11+
#include "dummy_render_surface.h"
12+
13+
#include <stdatomic.h>
14+
#include <stdlib.h>
15+
16+
#include <unistd.h>
17+
18+
#include "render_surface.h"
19+
#include "render_surface_private.h"
20+
#include "surface.h"
21+
#include "surface_private.h"
22+
23+
#include "tracer.h"
24+
#include "util/geometry.h"
25+
#include "util/uuid.h"
26+
27+
struct dummy_render_surface {
28+
union {
29+
struct surface surface;
30+
struct render_surface render_surface;
31+
};
32+
33+
#ifdef DEBUG
34+
uuid_t uuid;
35+
#endif
36+
};
37+
38+
COMPILE_ASSERT(offsetof(struct dummy_render_surface, surface) == 0);
39+
COMPILE_ASSERT(offsetof(struct dummy_render_surface, render_surface.surface) == 0);
40+
41+
#ifdef DEBUG
42+
static const uuid_t uuid = CONST_UUID(0x26, 0xfe, 0x91, 0x53, 0x75, 0xf2, 0x41, 0x90, 0xa1, 0xf5, 0xba, 0xe1, 0x1b, 0x28, 0xd5, 0xe5);
43+
#endif
44+
45+
#define CAST_THIS(ptr) CAST_DUMMY_RENDER_SURFACE(ptr)
46+
#define CAST_THIS_UNCHECKED(ptr) CAST_DUMMY_RENDER_SURFACE_UNCHECKED(ptr)
47+
48+
#ifdef DEBUG
49+
ATTR_PURE struct dummy_render_surface *__checked_cast_dummy_render_surface(void *ptr) {
50+
struct dummy_render_surface *surface;
51+
52+
surface = CAST_DUMMY_RENDER_SURFACE_UNCHECKED(ptr);
53+
ASSERT(uuid_equals(surface->uuid, uuid));
54+
return surface;
55+
}
56+
#endif
57+
58+
void dummy_render_surface_deinit(struct surface *s);
59+
static int dummy_render_surface_present_kms(struct surface *s, const struct fl_layer_props *props, struct kms_req_builder *builder);
60+
static int dummy_render_surface_present_fbdev(struct surface *s, const struct fl_layer_props *props, struct fbdev_commit_builder *builder);
61+
static int dummy_render_surface_fill(struct render_surface *surface, FlutterBackingStore *fl_store);
62+
static int dummy_render_surface_queue_present(struct render_surface *surface, const FlutterBackingStore *fl_store);
63+
64+
int dummy_render_surface_init(
65+
struct dummy_render_surface *surface,
66+
struct tracer *tracer,
67+
struct vec2i size
68+
) {
69+
int ok;
70+
71+
ok = render_surface_init(CAST_RENDER_SURFACE_UNCHECKED(surface), tracer, size);
72+
if (ok != 0) {
73+
return EIO;
74+
}
75+
76+
surface->surface.present_kms = dummy_render_surface_present_kms;
77+
surface->surface.present_fbdev = dummy_render_surface_present_fbdev;
78+
surface->surface.deinit = dummy_render_surface_deinit;
79+
surface->render_surface.fill = dummy_render_surface_fill;
80+
surface->render_surface.queue_present = dummy_render_surface_queue_present;
81+
82+
#ifdef DEBUG
83+
uuid_copy(&surface->uuid, uuid);
84+
#endif
85+
return 0;
86+
}
87+
88+
struct dummy_render_surface *dummy_render_surface_new(
89+
struct tracer *tracer,
90+
struct vec2i size
91+
) {
92+
struct dummy_render_surface *surface;
93+
int ok;
94+
95+
surface = malloc(sizeof *surface);
96+
if (surface == NULL) {
97+
goto fail_return_null;
98+
}
99+
100+
ok = dummy_render_surface_init(surface, tracer, size);
101+
if (ok != 0) {
102+
goto fail_free_surface;
103+
}
104+
105+
return surface;
106+
107+
fail_free_surface:
108+
free(surface);
109+
110+
fail_return_null:
111+
return NULL;
112+
}
113+
114+
void dummy_render_surface_deinit(struct surface *s) {
115+
render_surface_deinit(s);
116+
}
117+
118+
static int dummy_render_surface_present_kms(struct surface *s, UNUSED const struct fl_layer_props *props, UNUSED struct kms_req_builder *builder) {
119+
(void) props;
120+
(void) builder;
121+
122+
TRACER_INSTANT(s->tracer, "dummy_render_surface_present_kms");
123+
124+
return 0;
125+
}
126+
127+
static int
128+
dummy_render_surface_present_fbdev(struct surface *s, const struct fl_layer_props *props, struct fbdev_commit_builder *builder) {
129+
(void) s;
130+
(void) props;
131+
(void) builder;
132+
133+
TRACER_INSTANT(s->tracer, "dummy_render_surface_present_fbdev");
134+
135+
return 0;
136+
}
137+
138+
static int dummy_render_surface_fill(struct render_surface *s, FlutterBackingStore *fl_store) {
139+
(void) fl_store;
140+
141+
TRACER_INSTANT(s->surface.tracer, "dummy_render_surface_fill");
142+
143+
return 0;
144+
}
145+
146+
static int dummy_render_surface_queue_present(struct render_surface *s, const FlutterBackingStore *fl_store) {
147+
(void) fl_store;
148+
149+
TRACER_INSTANT(s->surface.tracer, "dummy_render_surface_queue_present");
150+
151+
return 0;
152+
}

src/dummy_render_surface.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// SPDX-License-Identifier: MIT
2+
/*
3+
* Vulkan GBM render surface
4+
*
5+
* - used as a render target for flutter vulkan rendering
6+
* - can be scanned out using KMS
7+
*
8+
* Copyright (c) 2022, Hannes Winkler <[email protected]>
9+
*/
10+
11+
#ifndef _FLUTTERPI_INCLUDE_DUMMY_RENDER_SURFACE_H
12+
#define _FLUTTERPI_INCLUDE_DUMMY_RENDER_SURFACE_H
13+
14+
#include "util/geometry.h"
15+
16+
struct tracer;
17+
struct dummy_render_surface;
18+
19+
#define CAST_DUMMY_RENDER_SURFACE_UNCHECKED(ptr) ((struct dummy_render_surface *) (ptr))
20+
#ifdef DEBUG
21+
#define CAST_DUMMY_RENDER_SURFACE(ptr) __checked_cast_dummy_render_surface(ptr)
22+
ATTR_PURE struct dummy_render_surface *__checked_cast_dummy_render_surface(void *ptr);
23+
#else
24+
#define CAST_DUMMY_RENDER_SURFACE(ptr) CAST_DUMMY_RENDER_SURFACE_UNCHECKED(ptr)
25+
#endif
26+
27+
struct dummy_render_surface *dummy_render_surface_new(
28+
struct tracer *tracer,
29+
struct vec2i size
30+
);
31+
32+
#endif // _FLUTTERPI_INCLUDE_DUMMY_RENDER_SURFACE_H

0 commit comments

Comments
 (0)