From 84a8ba4f86c2dbbb34a765d3f99ea0fa35ca3211 Mon Sep 17 00:00:00 2001 From: idea4good Date: Tue, 28 Mar 2023 16:09:19 +0800 Subject: [PATCH] code optimization --- GuiLite.h | 17 ++++++++--------- src/core/display.h | 19 +++++++++---------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/GuiLite.h b/GuiLite.h index 1b8b6ac..ff34885 100644 --- a/GuiLite.h +++ b/GuiLite.h @@ -602,13 +602,15 @@ public: c_rect low_active_rect = m_layers[low_z_order].active_rect; void* fb = m_layers[low_z_order].fb; int width = low_layer_rect.width(); - for (int y = current_active_rect.m_top; (y <= current_active_rect.m_bottom && y <= low_active_rect.m_bottom); y++) + for (int y = current_active_rect.m_top; y <= current_active_rect.m_bottom; y++) { - for (int x = current_active_rect.m_left; (x <= current_active_rect.m_right && x <= low_active_rect.m_right); x++) + for (int x = current_active_rect.m_left; x <= current_active_rect.m_right; x++) { - if (!low_layer_rect.pt_in_rect(x, y)) continue; - unsigned int rgb = (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)fb)[(x - low_layer_rect.m_left) + (y - low_layer_rect.m_top) * width]) : ((unsigned int*)fb)[(x - low_layer_rect.m_left) + (y - low_layer_rect.m_top) * width]; - draw_pixel_low_level(x, y, rgb); + if (low_active_rect.pt_in_rect(x, y) && low_layer_rect.pt_in_rect(x, y))//active rect maybe is bigger than layer rect + { + unsigned int rgb = (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)fb)[(x - low_layer_rect.m_left) + (y - low_layer_rect.m_top) * width]) : ((unsigned int*)fb)[(x - low_layer_rect.m_left) + (y - low_layer_rect.m_top) * width]; + draw_pixel_low_level(x, y, rgb); + } } } } @@ -677,11 +679,8 @@ protected: {//Top layber fb always be 0 ASSERT(m_layers[i].fb = calloc(layer_rect.width() * layer_rect.height(), m_color_bytes)); m_layers[i].rect = layer_rect; - if(i == Z_ORDER_LEVEL_0) - { - m_layers[i].active_rect = layer_rect; - } } + m_layers[Z_ORDER_LEVEL_0].active_rect = layer_rect; } int m_width; //in pixels int m_height; //in pixels diff --git a/src/core/display.h b/src/core/display.h index 21d8607..dd6c751 100644 --- a/src/core/display.h +++ b/src/core/display.h @@ -437,16 +437,17 @@ public: { c_rect low_layer_rect = m_layers[low_z_order].rect; c_rect low_active_rect = m_layers[low_z_order].active_rect; - void* fb = m_layers[low_z_order].fb; int width = low_layer_rect.width(); - for (int y = current_active_rect.m_top; (y <= current_active_rect.m_bottom && y <= low_active_rect.m_bottom); y++) + for (int y = current_active_rect.m_top; y <= current_active_rect.m_bottom; y++) { - for (int x = current_active_rect.m_left; (x <= current_active_rect.m_right && x <= low_active_rect.m_right); x++) + for (int x = current_active_rect.m_left; x <= current_active_rect.m_right; x++) { - if (!low_layer_rect.pt_in_rect(x, y)) continue; - unsigned int rgb = (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)fb)[(x - low_layer_rect.m_left) + (y - low_layer_rect.m_top) * width]) : ((unsigned int*)fb)[(x - low_layer_rect.m_left) + (y - low_layer_rect.m_top) * width]; - draw_pixel_low_level(x, y, rgb); + if (low_active_rect.pt_in_rect(x, y) && low_layer_rect.pt_in_rect(x, y))//active rect maybe is bigger than layer rect + { + unsigned int rgb = (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)fb)[(x - low_layer_rect.m_left) + (y - low_layer_rect.m_top) * width]) : ((unsigned int*)fb)[(x - low_layer_rect.m_left) + (y - low_layer_rect.m_top) * width]; + draw_pixel_low_level(x, y, rgb); + } } } } @@ -521,11 +522,9 @@ protected: {//Top layber fb always be 0 ASSERT(m_layers[i].fb = calloc(layer_rect.width() * layer_rect.height(), m_color_bytes)); m_layers[i].rect = layer_rect; - if(i == Z_ORDER_LEVEL_0) - { - m_layers[i].active_rect = layer_rect; - } } + + m_layers[Z_ORDER_LEVEL_0].active_rect = layer_rect; } int m_width; //in pixels