diff options
author | Rosen Penev <rosenp@gmail.com> | 2021-05-09 16:11:32 -0700 |
---|---|---|
committer | Frediano Ziglio <freddy77@gmail.com> | 2021-08-23 10:41:11 +0100 |
commit | 24f67439e4050235f8fac926557780b18eed70b3 (patch) | |
tree | 2458bfb2d224ffd2dbbfd8e99c370dc23dd3c801 | |
parent | 258fda6290e61b79ce99a8aabb70ecb22c322168 (diff) |
several conversions to std::array
These conversions allowed extra conversions to for range loops in
addition to replacing macro usage with .size().
Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
-rw-r--r-- | server/dcc-private.h | 10 | ||||
-rw-r--r-- | server/dcc.h | 10 | ||||
-rw-r--r-- | server/display-channel-private.h | 26 | ||||
-rw-r--r-- | server/display-channel.cpp | 4 | ||||
-rw-r--r-- | server/display-channel.h | 8 | ||||
-rw-r--r-- | server/video-stream.cpp | 18 |
6 files changed, 32 insertions, 44 deletions
diff --git a/server/dcc-private.h b/server/dcc-private.h index 7b1643d1..842c14b2 100644 --- a/server/dcc-private.h +++ b/server/dcc-private.h @@ -44,13 +44,13 @@ struct DisplayChannelClientPrivate uint32_t pixmap_cache_generation = 0; int pending_pixmaps_sync = 0; - RedCacheItem *palette_cache[PALETTE_CACHE_HASH_SIZE]; + std::array<RedCacheItem *, PALETTE_CACHE_HASH_SIZE> palette_cache; Ring palette_cache_lru = { nullptr, nullptr }; long palette_cache_available = CLIENT_PALETTE_CACHE_SIZE; struct { FreeList free_list; - uint64_t pixmap_cache_items[MAX_DRAWABLE_PIXMAP_CACHE_ITEMS]; + std::array<uint64_t, MAX_DRAWABLE_PIXMAP_CACHE_ITEMS> pixmap_cache_items; int num_pixmap_cache_items; } send_data; @@ -60,10 +60,10 @@ struct DisplayChannelClientPrivate * preference order (index) as value */ GArray *client_preferred_video_codecs; - uint8_t surface_client_created[NUM_SURFACES]; - QRegion surface_client_lossy_region[NUM_SURFACES]; + std::array<bool, NUM_SURFACES> surface_client_created; + std::array<QRegion, NUM_SURFACES> surface_client_lossy_region; - VideoStreamAgent stream_agents[NUM_STREAMS]; + std::array<VideoStreamAgent, NUM_STREAMS> stream_agents; uint32_t streams_max_latency; uint64_t streams_max_bit_rate; bool gl_draw_ongoing; diff --git a/server/dcc.h b/server/dcc.h index 89f26233..47f83a5e 100644 --- a/server/dcc.h +++ b/server/dcc.h @@ -83,17 +83,17 @@ struct VideoStream; struct VideoStreamAgent; struct RedSurface; -typedef struct WaitForChannels { +struct WaitForChannels { SpiceMsgWaitForChannels header; - SpiceWaitForChannel buf[MAX_CACHE_CLIENTS]; -} WaitForChannels; + std::array<SpiceWaitForChannel, MAX_CACHE_CLIENTS> buf; +}; -typedef struct FreeList { +struct FreeList { int res_size; SpiceResourceList *res; uint64_t sync[MAX_CACHE_CLIENTS]; WaitForChannels wait; -} FreeList; +}; #define DCC_TO_DC(dcc) ((DisplayChannel*) dcc->get_channel()) diff --git a/server/display-channel-private.h b/server/display-channel-private.h index 650b4782..04ac2c0d 100644 --- a/server/display-channel-private.h +++ b/server/display-channel-private.h @@ -24,7 +24,7 @@ #define NUM_TRACE_ITEMS (1 << TRACE_ITEMS_SHIFT) #define ITEMS_TRACE_MASK (NUM_TRACE_ITEMS - 1) -typedef struct DrawContext { +struct DrawContext { SpiceCanvas *canvas; int canvas_draws_on_surface; int top_down; @@ -33,7 +33,7 @@ typedef struct DrawContext { int32_t stride; uint32_t format; void *line_0; -} DrawContext; +}; struct RedSurface { SPICE_CXX_GLIB_ALLOCATOR @@ -63,15 +63,14 @@ struct RedSurface { red::shared_ptr<const RedSurfaceCmd> destroy_cmd; }; -typedef struct MonitorsConfig { +struct MonitorsConfig { int refs; int count; int max_allowed; QXLHead heads[0]; -} MonitorsConfig; +}; #define NUM_DRAWABLES 1000 -typedef struct _Drawable _Drawable; struct _Drawable { union { alignas(Drawable) char raw_drawable[sizeof(Drawable)]; @@ -103,20 +102,20 @@ struct DisplayChannelPrivate Ring current_list; uint32_t drawable_count; - _Drawable drawables[NUM_DRAWABLES]; + std::array<_Drawable, NUM_DRAWABLES> drawables; _Drawable *free_drawables; int stream_video; GArray *video_codecs; uint32_t stream_count; - VideoStream streams_buf[NUM_STREAMS]; + std::array<VideoStream, NUM_STREAMS> streams_buf; VideoStream *free_streams; Ring streams; - ItemTrace items_trace[NUM_TRACE_ITEMS]; + std::array<ItemTrace, NUM_TRACE_ITEMS> items_trace; uint32_t next_item_trace; uint64_t streams_size_total; - RedSurface *surfaces[NUM_SURFACES]; + std::array<RedSurface *, NUM_SURFACES> surfaces; uint32_t n_surfaces; SpiceImageSurfaces image_surfaces; @@ -325,15 +324,10 @@ static inline int is_same_drawable(Drawable *d1, Drawable *d2) static inline bool is_drawable_independent_from_surfaces(const Drawable *drawable) { - for (const auto& surface : drawable->surface_deps) { - if (surface) { - return false; - } - } - return true; + return std::all_of(drawable->surface_deps.begin(), drawable->surface_deps.end(), std::logical_not<RedSurface *>()); } -static inline int has_shadow(RedDrawable *drawable) +static inline bool has_shadow(const RedDrawable *drawable) { return drawable->type == QXL_COPY_BITS; } diff --git a/server/display-channel.cpp b/server/display-channel.cpp index 1e6228af..f56db9d6 100644 --- a/server/display-channel.cpp +++ b/server/display-channel.cpp @@ -224,7 +224,7 @@ static void stop_streams(DisplayChannel *display) } display->priv->next_item_trace = 0; - memset(display->priv->items_trace, 0, sizeof(display->priv->items_trace)); + display->priv->items_trace = {}; } static void display_channel_surface_unref(DisplayChannel *display, RedSurface *surface) @@ -2334,7 +2334,7 @@ void display_channel_gl_draw_done(DisplayChannel *display) int display_channel_get_video_stream_id(DisplayChannel *display, VideoStream *stream) { - return (int)(stream - display->priv->streams_buf); + return static_cast<int>(stream - display->priv->streams_buf.data()); } VideoStream *display_channel_get_nth_video_stream(DisplayChannel *display, gint i) diff --git a/server/display-channel.h b/server/display-channel.h index 3319cf22..c54df25c 100644 --- a/server/display-channel.h +++ b/server/display-channel.h @@ -54,10 +54,10 @@ struct DisplayChannel final: public CommonGraphicsChannel red::unique_link<DisplayChannelPrivate> priv; }; -typedef struct DependItem { +struct DependItem { Drawable *drawable; RingItem ring_item; -} DependItem; +}; struct Drawable { uint32_t refs; @@ -77,12 +77,12 @@ struct Drawable { VideoStream *stream; int streamable; BitmapGradualType copy_bitmap_graduality; - DependItem depend_items[3]; + std::array<DependItem, 3> depend_items; /* destination surface. This pointer is not NULL. A reference is hold */ RedSurface *surface; /* dependency surfaces. They can be NULL. A reference is hold. */ - RedSurface *surface_deps[3]; + std::array<RedSurface *, 3> surface_deps; uint32_t process_commands_generation; DisplayChannel *display; diff --git a/server/video-stream.cpp b/server/video-stream.cpp index 667d2713..4de92b63 100644 --- a/server/video-stream.cpp +++ b/server/video-stream.cpp @@ -486,8 +486,6 @@ GArray *video_stream_parse_preferred_codecs(SpiceMsgcDisplayPreferredVideoCodecT /* TODO: document the difference between the 2 functions below */ void video_stream_trace_update(DisplayChannel *display, Drawable *drawable) { - ItemTrace *trace; - ItemTrace *trace_end; RingItem *item; if (drawable->stream || !drawable->streamable || drawable->frames_count) { @@ -514,16 +512,12 @@ void video_stream_trace_update(DisplayChannel *display, Drawable *drawable) } } - trace = display->priv->items_trace; - trace_end = trace + NUM_TRACE_ITEMS; - for (; trace < trace_end; trace++) { - if (is_next_stream_frame(drawable, trace->width, trace->height, - &trace->dest_area, trace->time, nullptr, FALSE)) { - if (video_stream_add_frame(display, drawable, - trace->first_frame_time, - trace->frames_count, - trace->gradual_frames_count, - trace->last_gradual_frame)) { + for (auto &&trace : display->priv->items_trace) { + if (is_next_stream_frame(drawable, trace.width, trace.height, &trace.dest_area, trace.time, + nullptr, false)) { + if (video_stream_add_frame(display, drawable, trace.first_frame_time, + trace.frames_count, trace.gradual_frames_count, + trace.last_gradual_frame)) { return; } } |