11#include " interface/gui_custom_bitmap_storage.hpp"
22
3+ #include " bitmaps/bitmaps.hpp"
4+ #include " cseries/cseries_events.hpp"
35#include " interface/user_interface_memory.hpp"
46#include " memory/module.hpp"
57#include " multithreading/synchronization.hpp"
6- #include " networking/online/online_error.hpp"
7- #include " rasterizer/rasterizer.hpp"
8- #include " rasterizer/rasterizer_d3d_allocations.hpp"
9- #include " rasterizer/rasterizer_textures_xenon_formats.hpp"
10- #include " xbox/xgraphics.hpp"
118
12- #include < stdio.h>
139
1410#include < d3d9.h>
1511#include < d3dx9.h>
@@ -34,48 +30,26 @@ void __thiscall c_gui_custom_bitmap_storage_item::dispose()
3430 ASSERT (!m_bitmap_ready);
3531 ASSERT (!m_hardware_format_bitmap.valid ());
3632
37- if (m_bitmap_pixel_buffer )
33+ if (m_bitmap_pixel_buffer_allocation )
3834 {
39- user_interface_free (m_bitmap_pixel_buffer );
40- m_bitmap_pixel_buffer = nullptr ;
35+ user_interface_free (m_bitmap_pixel_buffer_allocation );
36+ m_bitmap_pixel_buffer_allocation = NULL ;
4137 }
4238
4339 m_allocated = false ;
4440}
4541
46- const uns32 bitmap_pixel_buffer_alignment_bits = 12 ;
4742void __thiscall c_gui_custom_bitmap_storage_item::initialize (int32 width, int32 height, bool use_compressed_format)
4843{
4944 m_use_compressed_format = use_compressed_format;
5045 e_bitmap_format bitmap_format = m_use_compressed_format ? _bitmap_format_dxt5 : _bitmap_format_a8r8g8b8;
51- D3DFORMAT d3d_format = m_use_compressed_format ? D3DFMT_DXT5 : D3DFMT_A8R8G8B8;
52- uns16 flags = FLAG (_bitmap_free_on_delete_bit) | FLAG (_bitmap_use_base_address_for_hardware_format_bit );
46+ D3DFORMAT hardware_format = m_use_compressed_format ? D3DFMT_DXT5 : D3DFMT_A8R8G8B8;
47+ uns16 flags = FLAG (_bitmap_free_on_delete_bit) | FLAG (_bitmap_hardware_only_bit );
5348
54- bitmap_2d_initialize (&m_bitmap, static_cast <int16>(width), static_cast <int16>(height) , 0 , bitmap_format, flags, false , false );
55- m_bitmap .curve = 3 ;
49+ bitmap_2d_initialize (&m_bitmap_data, (int16)width, (int16)height , 0 , bitmap_format, flags, false , false );
50+ m_bitmap_data .curve = 3 ;
5651
57- c_rasterizer_texture_ref::allocate (m_hardware_format_bitmap, width, height, 1 , d3d_format, D3DPOOL_DEFAULT, false , 0 , 0 );
58- texture_header = new D3DBaseTexture ();
59-
60- uns32 base_size = 0 ;
61- uns32 mip_size = 0 ;
62- uns32 resource_bytes = XGSetTextureHeader (m_bitmap.width , m_bitmap.height , 1 , 4 , d3d_format, 0 , 0 , -1 , 0 , texture_header, &base_size, &mip_size);
63- if (resource_bytes)
64- {
65- int32 allocate_bytes = resource_bytes + FLAG (bitmap_pixel_buffer_alignment_bits);
66- m_bitmap_pixel_buffer = (char *)user_interface_malloc_tracked (allocate_bytes, __FILE__, __LINE__);
67- if (m_bitmap_pixel_buffer)
68- {
69- m_width = width;
70- m_height = height;
71- m_bitmap_pixel_buffer_base = (char *)ALIGN ((int32)m_bitmap_pixel_buffer, bitmap_pixel_buffer_alignment_bits);
72- m_bitmap_pixel_buffer_length = allocate_bytes - (m_bitmap_pixel_buffer_base - m_bitmap_pixel_buffer);
73- ASSERT (m_bitmap_pixel_buffer_length <= allocate_bytes);
74-
75- XGOffsetResourceAddress (texture_header, m_bitmap_pixel_buffer_base);
76- m_allocated = true ;
77- }
78- }
52+ c_rasterizer_texture_ref::allocate (m_hardware_format_bitmap, width, height, 1 , hardware_format, D3DPOOL_DEFAULT, false , 0 , 0 );
7953}
8054
8155bool __thiscall c_gui_custom_bitmap_storage_item::initialize_raw (int32 width, int32 height, char * buffer, int32 buffer_length, bool cpu_cached)
@@ -88,13 +62,15 @@ bool __thiscall c_gui_custom_bitmap_storage_item::load_from_buffer(char const* b
8862 ASSERT (buffer);
8963 ASSERT (!m_bitmap_ready);
9064
91- bool result = false ;
92-
93- if (!m_allocated)
94- return false ;
65+ // if (!m_allocated)
66+ // {
67+ // return false;
68+ // }
9569
9670 if (!m_hardware_format_bitmap.valid ())
71+ {
9772 return false ;
73+ }
9874
9975 IDirect3DTexture9* d3d_texture = m_hardware_format_bitmap.get_d3d_texture ();
10076 if (d3d_texture == NULL )
@@ -106,22 +82,20 @@ bool __thiscall c_gui_custom_bitmap_storage_item::load_from_buffer(char const* b
10682 IDirect3DSurface9* d3d_surface = NULL ;
10783 HRESULT get_surface_level_result = d3d_texture->GetSurfaceLevel (0 , &d3d_surface);
10884 if (FAILED (get_surface_level_result))
85+ {
10986 return false ;
87+ }
11088
111- HRESULT load_surface_result = D3DXLoadSurfaceFromFileInMemory (d3d_surface, NULL , NULL , buffer, buffer_length, NULL , D3DX_DEFAULT, 0 , NULL );
89+ D3DXIMAGE_INFO d3dximage_info{};
90+ HRESULT load_surface_result = D3DXLoadSurfaceFromFileInMemory (d3d_surface, NULL , NULL , buffer, buffer_length, NULL , D3DX_DEFAULT, 0 , &d3dximage_info);
11291 d3d_surface->Release ();
113-
92+
11493 if (FAILED (load_surface_result))
11594 {
11695 event (_event_error, " ui:custom_bitmaps: D3DXLoadSurfaceFromFile failed with error code 0x%08X" , load_surface_result);
11796 return false ;
11897 }
11998
120- uns32 bytes = XGSetTextureHeader (m_bitmap.width , m_bitmap.height , 1 , 4 , m_use_compressed_format ? D3DFMT_DXT5 : D3DFMT_A8R8G8B8, 1 , 0 , -1 , 0 , texture_header, 0 , 0 );
121- ASSERT (bytes > 0 );
122-
123- XGOffsetResourceAddress (texture_header, m_bitmap_pixel_buffer_base);
124-
12599 m_bitmap_ready = true ;
126100 return true ;
127101}
@@ -157,35 +131,44 @@ c_gui_custom_bitmap_storage_item const* c_gui_custom_bitmap_storage_manager::get
157131
158132 internal_critical_section_enter (k_crit_section_ui_custom_bitmaps_lock);
159133
160- s_bitmap_storage_handle_datum* bitmap_storage_handle = DATUM_TRY_AND_GET (m_bitmap_storage_items, s_bitmap_storage_handle_datum, bitmap_storage_index);
161- if (bitmap_storage_handle && bitmap_storage_handle ->reference_count > 0 && bitmap_storage_handle ->state == 2 )
134+ s_bitmap_storage_handle_datum* bitmap_storage_handle_datum = DATUM_TRY_AND_GET (m_bitmap_storage_items, s_bitmap_storage_handle_datum, bitmap_storage_index);
135+ if (bitmap_storage_handle_datum && bitmap_storage_handle_datum ->reference_count > 0 && bitmap_storage_handle_datum ->state == _bitmap_storage_state_ready )
162136 {
163- storage_item = &bitmap_storage_handle ->storage_item ;
137+ storage_item = &bitmap_storage_handle_datum ->storage_item ;
164138 }
165139
166140 internal_critical_section_leave (k_crit_section_ui_custom_bitmaps_lock);
167141
168142 return storage_item;
169143}
170144
171- bool __cdecl c_gui_custom_bitmap_storage_manager::load_bitmap_from_buffer (int32 storage_item_index , char const * buffer, int32 buffer_size, int32 aspect_ratio)
145+ bool __cdecl c_gui_custom_bitmap_storage_manager::load_bitmap_from_buffer (int32 bitmap_storage_index , char const * buffer, int32 buffer_size, int32 aspect_ratio)
172146{
173- s_bitmap_storage_handle_datum* storage_item = NULL ;
147+ s_bitmap_storage_handle_datum* bitmap_storage_handle_datum = NULL ;
174148 {
175149 c_critical_section_scope section_scope (k_crit_section_ui_custom_bitmaps_lock);
176- if (storage_item = DATUM_TRY_AND_GET (m_bitmap_storage_items, s_bitmap_storage_handle_datum, storage_item_index ))
177- storage_item ->state = 1 ;
150+ if (bitmap_storage_handle_datum = DATUM_TRY_AND_GET (m_bitmap_storage_items, s_bitmap_storage_handle_datum, bitmap_storage_index ))
151+ bitmap_storage_handle_datum ->state = _bitmap_storage_state_loading ;
178152 }
179153
180- if (!storage_item)
154+ if (!bitmap_storage_handle_datum)
155+ {
181156 return false ;
157+ }
182158
183- bool result = storage_item->storage_item .load_from_buffer (buffer, buffer_size, m_buffer, m_buffer_size, aspect_ratio);
159+ event (_event_message, " ui:custom_bitmaps: load_bitmap_from_buffer starting %d" ,
160+ bitmap_storage_index);
161+
162+ bool bitmap_ready = bitmap_storage_handle_datum->storage_item .load_from_buffer (buffer, buffer_size, m_buffer, m_buffer_size, aspect_ratio);
184163
185164 {
186165 c_critical_section_scope section_scope (k_crit_section_ui_custom_bitmaps_lock);
187- storage_item->state = result ? 2 : 0 ;
166+ ASSERT (bitmap_storage_handle_datum->state == _bitmap_storage_state_loading);
167+ bitmap_storage_handle_datum->state = bitmap_ready ? _bitmap_storage_state_ready : _bitmap_storage_state_none;
188168 }
189169
190- return result;
170+ event (_event_message, " ui:custom_bitmaps: load_bitmap_from_buffer ending %d" ,
171+ bitmap_storage_index);
172+
173+ return bitmap_ready;
191174}
0 commit comments