@@ -34,11 +34,24 @@ wf::auxilliary_buffer_t::~auxilliary_buffer_t()
3434 free ();
3535}
3636
37+ static wf::dimensions_t sanitize_buffer_size (wf::dimensions_t size)
38+ {
39+ const float MAX_BUFFER_SIZE = 4096 .0f ;
40+ if ((size.width > MAX_BUFFER_SIZE ) || (size.height > MAX_BUFFER_SIZE ))
41+ {
42+ LOGW (" Attempting to allocate a buffer which is too large " , size, " !" );
43+ float scale = std::min (MAX_BUFFER_SIZE / size.width , MAX_BUFFER_SIZE / size.height );
44+ size.width = std::ceil (size.width * scale);
45+ size.height = std::ceil (size.height * scale);
46+ }
47+
48+ return size;
49+ }
50+
3751bool wf::auxilliary_buffer_t::allocate (wf::dimensions_t size, float scale, buffer_allocation_hints_t hints)
3852{
3953 size.width = std::max (1 .0f , std::ceil (size.width * scale));
4054 size.height = std::max (1 .0f , std::ceil (size.height * scale));
41-
4255 if (buffer.get_size () == size)
4356 {
4457 return false ;
@@ -63,7 +76,16 @@ bool wf::auxilliary_buffer_t::allocate(wf::dimensions_t size, float scale, buffe
6376
6477 if (!buffer.buffer )
6578 {
66- LOGE (" Failed to allocate auxilliary buffer!" );
79+ // On some systems, we may not be able to allocate very big buffers, so try to allocate a smaller
80+ // size instead.
81+ size = sanitize_buffer_size (size);
82+ buffer.buffer = wlr_allocator_create_buffer (wf::get_core_impl ().allocator , size.width ,
83+ size.height , format);
84+ }
85+
86+ if (!buffer.buffer )
87+ {
88+ LOGE (" Failed to allocate auxilliary buffer! Size " , size, " format " , drm_fmt);
6789 return false ;
6890 }
6991
0 commit comments