Skip to content

Commit

Permalink
[Cloud]Don't use stb_image_write_to_mem
Browse files Browse the repository at this point in the history
  • Loading branch information
OFFTKP committed Dec 16, 2023
1 parent da0e228 commit 2ada500
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ endif ()
set(LINK_LIBS ${LINK_LIBS} sokol ${ALSA_LIBRARIES})

if(NOT EMSCRIPTEN AND NOT ANDROID AND NOT IOS)
target_include_directories(${PROJECT_NAME} PRIVATE src/openssl/include)
target_include_directories(${PROJECT_NAME} PRIVATE src/curl/include)
set(LINK_LIBS ${LINK_LIBS} curl)
endif()

Expand Down
24 changes: 13 additions & 11 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2804,7 +2804,16 @@ void se_capture_cloud_callback(void* userdata, void* data){
cloud_state.save_states_busy_swap[slot] = false;
mutex_unlock(cloud_state.save_states_mutex[slot]);
}
void se_capture_state_slot_cloud(int slot){
void se_write_png_cloud(void* context, void* data, int size){
char file[SB_FILE_PATH_SIZE];
size_t slot = (size_t)context;
snprintf(file,SB_FILE_PATH_SIZE,"%016llx.slot%zu.state.png",emu_state.game_checksum,slot);
// data is freed after this function returns, so we need to copy it
void* data_copy = malloc(size);
memcpy(data_copy,data,size);
cloud_drive_upload(cloud_state.drive, file, "image/png", data_copy, (size_t)size, se_capture_cloud_callback, (void*)slot);
}
void se_capture_state_slot_cloud(size_t slot){
if(emu_state.rom_loaded==false)return;
se_save_state_t* save_state = cloud_state.save_states+slot;
se_capture_state(&core, save_state);
Expand All @@ -2813,17 +2822,10 @@ void se_capture_state_slot_cloud(int slot){
uint32_t width=0, height=0;
uint8_t* imdata = se_save_state_to_image(save_state, &width,&height);
int len;
void* data = stbi_write_png_to_mem(imdata, 0, width, height, 4, &len); // Freed in cloud_drive_upload callback
stbi_write_png_to_func(se_write_png_cloud, (void*)slot, width, height, 4, imdata, 0);
free(imdata);
if (data) {
char file[SB_FILE_PATH_SIZE];
snprintf(file,SB_FILE_PATH_SIZE,"%016llx.slot%d.state.png",emu_state.game_checksum,slot);
cloud_drive_upload(cloud_state.drive, file, "image/png", data, (size_t)len, se_capture_cloud_callback, (void*)(size_t)slot);
} else {
printf("Failed to write png to memory\n");
}
}
void se_restore_state_slot_cloud(int slot){
void se_restore_state_slot_cloud(size_t slot){
se_restore_state(&core, cloud_state.save_states+slot);
}
static void se_drive_ready_callback(cloud_drive_t* drive){
Expand Down Expand Up @@ -5614,7 +5616,7 @@ void se_draw_save_states(bool cloud){
int win_w = igGetWindowContentRegionWidth();
ImDrawList*dl= igGetWindowDrawList();
if(!emu_state.rom_loaded)se_push_disabled();
for(int i=0;i<SE_NUM_SAVE_STATES;++i){
for(size_t i=0;i<SE_NUM_SAVE_STATES;++i){
mutex_lock(cloud_state.save_states_mutex[i]);
se_save_state_t* states = cloud?cloud_state.save_states:save_states;
int slot_x = 0;
Expand Down
2 changes: 0 additions & 2 deletions src/stb_image_write.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,6 @@ STBIWDEF int stbi_write_jpg_to_func(stbi_write_func *func, void *context, int x,

STBIWDEF void stbi_flip_vertically_on_write(int flip_boolean);

STBIWDEF unsigned char *stbi_write_png_to_mem(const unsigned char *pixels, int stride_bytes, int x, int y, int n, int *out_len);

#endif//INCLUDE_STB_IMAGE_WRITE_H

#ifdef STB_IMAGE_WRITE_IMPLEMENTATION
Expand Down

0 comments on commit 2ada500

Please sign in to comment.