mirror of
				https://github.com/DreamMaoMao/maomaowm.git
				synced 2025-11-03 09:01:47 -05:00 
			
		
		
		
	opt: optimize rendermon
This commit is contained in:
		
							parent
							
								
									13f4ade7bf
								
							
						
					
					
						commit
						aed93721c0
					
				
					 1 changed files with 29 additions and 29 deletions
				
			
		
							
								
								
									
										58
									
								
								maomao.c
									
										
									
									
									
								
							
							
						
						
									
										58
									
								
								maomao.c
									
										
									
									
									
								
							| 
						 | 
					@ -3630,17 +3630,17 @@ void client_handle_opacity(Client *c) {
 | 
				
			||||||
                                 scene_buffer_apply_opacity, &opacity);
 | 
					                                 scene_buffer_apply_opacity, &opacity);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void // 0.5
 | 
					void rendermon(struct wl_listener *listener, void *data) {
 | 
				
			||||||
rendermon(struct wl_listener *listener, void *data) {
 | 
					 | 
				
			||||||
  /* This function is called every time an output is ready to display a frame,
 | 
					 | 
				
			||||||
   * generally at the output's refresh rate (e.g. 60Hz). */
 | 
					 | 
				
			||||||
  Monitor *m = wl_container_of(listener, m, frame);
 | 
					  Monitor *m = wl_container_of(listener, m, frame);
 | 
				
			||||||
  Client *c;
 | 
					  Client *c;
 | 
				
			||||||
  struct wlr_output_state pending = {0};
 | 
					  struct wlr_output_state pending = {0};
 | 
				
			||||||
  struct wlr_gamma_control_v1 *gamma_control;
 | 
					  struct wlr_gamma_control_v1 *gamma_control = NULL;
 | 
				
			||||||
  struct timespec now;
 | 
					  struct timespec now;
 | 
				
			||||||
  bool need_more_frames = false;
 | 
					  bool need_more_frames = false;
 | 
				
			||||||
 | 
					  bool has_commit = false;
 | 
				
			||||||
 | 
					  bool is_commit_pending = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Draw frames for all clients
 | 
				
			||||||
  wl_list_for_each(c, &clients, link) {
 | 
					  wl_list_for_each(c, &clients, link) {
 | 
				
			||||||
    need_more_frames = client_draw_frame(c);
 | 
					    need_more_frames = client_draw_frame(c);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					@ -3649,50 +3649,50 @@ rendermon(struct wl_listener *listener, void *data) {
 | 
				
			||||||
    wlr_output_schedule_frame(m->wlr_output);
 | 
					    wlr_output_schedule_frame(m->wlr_output);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /* Render if no XDG clients have an outstanding resize and are visible on
 | 
					  // Check if we should skip rendering
 | 
				
			||||||
   * this monitor. */
 | 
					 | 
				
			||||||
  wl_list_for_each(c, &clients, link) {
 | 
					  wl_list_for_each(c, &clients, link) {
 | 
				
			||||||
  	if (c->configure_serial && !c->isfloating && client_is_rendered_on_mon(c, m) &&
 | 
					    if (c->configure_serial && !c->isfloating && client_is_rendered_on_mon(c, m) &&
 | 
				
			||||||
  !client_is_stopped(c)) 		
 | 
					        !client_is_stopped(c)) {
 | 
				
			||||||
    goto skip;
 | 
					      goto skip;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Handle Gamma LUT changes
 | 
				
			||||||
  /*
 | 
					 | 
				
			||||||
   * HACK: The "correct" way to set the gamma is to commit it together with
 | 
					 | 
				
			||||||
   * the rest of the state in one go, but to do that we would need to rewrite
 | 
					 | 
				
			||||||
   * wlr_scene_output_commit() in order to add the gamma to the pending
 | 
					 | 
				
			||||||
   * state before committing, instead try to commit the gamma in one frame,
 | 
					 | 
				
			||||||
   * and commit the rest of the state in the next one (or in the same frame if
 | 
					 | 
				
			||||||
   * the gamma can not be committed).
 | 
					 | 
				
			||||||
   */
 | 
					 | 
				
			||||||
  if (m->gamma_lut_changed) {
 | 
					  if (m->gamma_lut_changed) {
 | 
				
			||||||
    gamma_control = wlr_gamma_control_manager_v1_get_control(gamma_control_mgr,
 | 
					    gamma_control = wlr_gamma_control_manager_v1_get_control(gamma_control_mgr, m->wlr_output);
 | 
				
			||||||
                                                             m->wlr_output);
 | 
					 | 
				
			||||||
    m->gamma_lut_changed = 0;
 | 
					    m->gamma_lut_changed = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!wlr_gamma_control_v1_apply(gamma_control, &pending))
 | 
					    if (!wlr_gamma_control_v1_apply(gamma_control, &pending)) {
 | 
				
			||||||
      goto commit;
 | 
					      goto commit;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!wlr_output_test_state(m->wlr_output, &pending)) {
 | 
					    if (!wlr_output_test_state(m->wlr_output, &pending)) {
 | 
				
			||||||
      wlr_gamma_control_v1_send_failed_and_destroy(gamma_control);
 | 
					      wlr_gamma_control_v1_send_failed_and_destroy(gamma_control);
 | 
				
			||||||
      goto commit;
 | 
					      goto commit;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    wlr_output_commit_state(m->wlr_output, &pending);
 | 
					    wlr_output_commit_state(m->wlr_output, &pending);
 | 
				
			||||||
    wlr_output_schedule_frame(m->wlr_output);
 | 
					    wlr_output_schedule_frame(m->wlr_output);
 | 
				
			||||||
  } else {
 | 
					    is_commit_pending = true;
 | 
				
			||||||
  commit:
 | 
					    has_commit = true; // Gamma commit succeeded
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					commit:
 | 
				
			||||||
 | 
					  if (!has_commit) {
 | 
				
			||||||
    wlr_scene_output_commit(m->scene_output, NULL);
 | 
					    wlr_scene_output_commit(m->scene_output, NULL);
 | 
				
			||||||
 | 
					    has_commit = true;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
skip:
 | 
					skip:
 | 
				
			||||||
 | 
					  if (!has_commit && !is_commit_pending) {
 | 
				
			||||||
 | 
					    wlr_scene_output_commit(m->scene_output, NULL);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  struct wlr_scene_output *scene_output =
 | 
					  // Send frame done notification
 | 
				
			||||||
  wlr_scene_get_scene_output(scene, m->wlr_output);
 | 
					 | 
				
			||||||
  wlr_scene_output_commit(scene_output, NULL);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  clock_gettime(CLOCK_MONOTONIC, &now);
 | 
					  clock_gettime(CLOCK_MONOTONIC, &now);
 | 
				
			||||||
  wlr_scene_output_send_frame_done(scene_output, &now);
 | 
					  wlr_scene_output_send_frame_done(m->scene_output, &now);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Clean up pending state
 | 
				
			||||||
  wlr_output_state_finish(&pending);
 | 
					  wlr_output_state_finish(&pending);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue