|
| 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 | +} |
0 commit comments