@@ -188,24 +188,28 @@ static struct buffer *get_wl_buffer(struct waydroid_hwc_composer_device_1 *pdev,
188
188
189
189
auto it = pdev->display ->buffer_map .find (layer->handle );
190
190
if (it != pdev->display ->buffer_map .end ()) {
191
+ std::lock_guard (pdev->display ->buffers_mutex );
191
192
if (it->second ->isShm ) {
192
193
if (width != it->second ->width || height != it->second ->height ) {
193
- if ( it->second ->buffer )
194
- wl_buffer_destroy (it->second ->buffer );
195
- delete (it->second );
194
+ it->second ->refcount --;
195
+ if (it->second ->refcount == 0 )
196
+ destroy_buffer (it->second );
196
197
pdev->display ->buffer_map .erase (it);
197
198
} else {
199
+ it->second ->refcount ++;
198
200
update_shm_buffer (pdev->display , it->second );
199
201
return it->second ;
200
202
}
201
- } else
203
+ } else {
204
+ it->second ->refcount ++;
202
205
return it->second ;
206
+ }
203
207
}
204
208
205
209
struct buffer *buf;
206
210
int ret = 0 ;
207
211
208
- buf = new struct buffer ( );
212
+ buf = create_buffer (pdev-> display );
209
213
if (pdev->display ->gtype == GRALLOC_GBM) {
210
214
struct gralloc_handle_t *drm_handle = (struct gralloc_handle_t *)layer->handle ;
211
215
if (pdev->display ->dmabuf ) {
@@ -236,7 +240,7 @@ static struct buffer *get_wl_buffer(struct waydroid_hwc_composer_device_1 *pdev,
236
240
return NULL ;
237
241
}
238
242
pdev->display ->buffer_map [layer->handle ] = buf;
239
-
243
+ buf-> refcount ++;
240
244
return pdev->display ->buffer_map [layer->handle ];
241
245
}
242
246
@@ -414,14 +418,11 @@ static int hwc_set(struct hwc_composer_device_1* dev,size_t numDisplays,
414
418
int err = 0 ;
415
419
416
420
if (pdev->display ->geo_changed ) {
421
+ std::lock_guard (pdev->display ->buffers_mutex );
417
422
for (auto it = pdev->display ->buffer_map .begin (); it != pdev->display ->buffer_map .end (); it++) {
418
- if (it->second ) {
419
- if (it->second ->buffer )
420
- wl_buffer_destroy (it->second ->buffer );
421
- if (it->second ->isShm )
422
- munmap (it->second ->shm_data , it->second ->size );
423
- delete (it->second );
424
- }
423
+ it->second ->refcount --;
424
+ if (it->second ->refcount == 0 )
425
+ destroy_buffer (it->second );
425
426
}
426
427
pdev->display ->buffer_map .clear ();
427
428
}
@@ -769,12 +770,8 @@ static int hwc_set(struct hwc_composer_device_1* dev,size_t numDisplays,
769
770
if (fb_layer->compositionType != HWC_FRAMEBUFFER &&
770
771
fb_layer->compositionType != HWC_SIDEBAND)
771
772
{
772
- int timeline_fd = sw_sync_timeline_create ();
773
773
/* To be signaled when the compositor releases the buffer */
774
- fb_layer->releaseFenceFd = sw_sync_fence_create (timeline_fd, " wayland_release" , 1 );
775
- buf->timeline_fd = timeline_fd;
776
- } else {
777
- buf->timeline_fd = -1 ;
774
+ fb_layer->releaseFenceFd = sw_sync_fence_create (buf->timeline_fd , " wayland_release" , ++buf->sync_point );
778
775
}
779
776
780
777
struct wl_surface *surface = get_surface (pdev, fb_layer, window, pdev->use_subsurface );
0 commit comments