diff options
author | Dave Chapman <dave@dchapman.com> | 2008-03-22 00:31:22 +0000 |
---|---|---|
committer | Dave Chapman <dave@dchapman.com> | 2008-03-22 00:31:22 +0000 |
commit | 45b2d8802d1e8fcc47fd1148adb7b1173ad5b311 (patch) | |
tree | 849eea4153daaf7dfafd571ca6b93b6f985b1ff9 /apps/gui/gwps-common.c | |
parent | 7ee63e22c58f4a7017136871e7b55dd702c5f460 (diff) | |
download | rockbox-45b2d8802d1e8fcc47fd1148adb7b1173ad5b311.tar.gz rockbox-45b2d8802d1e8fcc47fd1148adb7b1173ad5b311.zip |
Reduce the shocking amount of RAM my viewports implementation was using. The first version stored an array of lines for each of the 16 possible viewports (MAX_VIEWPORTS * the number of lines on the LCD with a 5-pixel high font). This version reverts back to a single global array of lines, with each viewport specifying the first and last lines as indexes into that array. This also turns out to be simpler, reducing binsize a little as well.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16735 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/gui/gwps-common.c')
-rw-r--r-- | apps/gui/gwps-common.c | 70 |
1 files changed, 34 insertions, 36 deletions
diff --git a/apps/gui/gwps-common.c b/apps/gui/gwps-common.c index ae5492a66c..3c3bad3056 100644 --- a/apps/gui/gwps-common.c +++ b/apps/gui/gwps-common.c | |||
@@ -1466,7 +1466,7 @@ static bool evaluate_conditional(struct gui_wps *gwps, int *token_index) | |||
1466 | The return value indicates whether the line needs to be updated. | 1466 | The return value indicates whether the line needs to be updated. |
1467 | */ | 1467 | */ |
1468 | static bool get_line(struct gui_wps *gwps, | 1468 | static bool get_line(struct gui_wps *gwps, |
1469 | int v, int line, int subline, | 1469 | int line, int subline, |
1470 | struct align_pos *align, | 1470 | struct align_pos *align, |
1471 | char *linebuf, | 1471 | char *linebuf, |
1472 | int linebuf_size) | 1472 | int linebuf_size) |
@@ -1494,8 +1494,8 @@ static bool get_line(struct gui_wps *gwps, | |||
1494 | #endif | 1494 | #endif |
1495 | 1495 | ||
1496 | /* Process all tokens of the desired subline */ | 1496 | /* Process all tokens of the desired subline */ |
1497 | last_token_idx = wps_last_token_index(data, v, line, subline); | 1497 | last_token_idx = wps_last_token_index(data, line, subline); |
1498 | for (i = wps_first_token_index(data, v, line, subline); | 1498 | for (i = wps_first_token_index(data, line, subline); |
1499 | i <= last_token_idx; i++) | 1499 | i <= last_token_idx; i++) |
1500 | { | 1500 | { |
1501 | switch(data->tokens[i].type) | 1501 | switch(data->tokens[i].type) |
@@ -1594,16 +1594,16 @@ static bool get_line(struct gui_wps *gwps, | |||
1594 | return update; | 1594 | return update; |
1595 | } | 1595 | } |
1596 | 1596 | ||
1597 | static void get_subline_timeout(struct gui_wps *gwps, int v, int line, int subline) | 1597 | static void get_subline_timeout(struct gui_wps *gwps, int line, int subline) |
1598 | { | 1598 | { |
1599 | struct wps_data *data = gwps->data; | 1599 | struct wps_data *data = gwps->data; |
1600 | int i; | 1600 | int i; |
1601 | int subline_idx = wps_subline_index(data, v, line, subline); | 1601 | int subline_idx = wps_subline_index(data, line, subline); |
1602 | int last_token_idx = wps_last_token_index(data, v, line, subline); | 1602 | int last_token_idx = wps_last_token_index(data, line, subline); |
1603 | 1603 | ||
1604 | data->sublines[subline_idx].time_mult = DEFAULT_SUBLINE_TIME_MULTIPLIER; | 1604 | data->sublines[subline_idx].time_mult = DEFAULT_SUBLINE_TIME_MULTIPLIER; |
1605 | 1605 | ||
1606 | for (i = wps_first_token_index(data, v, line, subline); | 1606 | for (i = wps_first_token_index(data, line, subline); |
1607 | i <= last_token_idx; i++) | 1607 | i <= last_token_idx; i++) |
1608 | { | 1608 | { |
1609 | switch(data->tokens[i].type) | 1609 | switch(data->tokens[i].type) |
@@ -1631,7 +1631,7 @@ static void get_subline_timeout(struct gui_wps *gwps, int v, int line, int subli | |||
1631 | 1631 | ||
1632 | /* Calculates which subline should be displayed for the specified line | 1632 | /* Calculates which subline should be displayed for the specified line |
1633 | Returns true iff the subline must be refreshed */ | 1633 | Returns true iff the subline must be refreshed */ |
1634 | static bool update_curr_subline(struct gui_wps *gwps, int v, int line) | 1634 | static bool update_curr_subline(struct gui_wps *gwps, int line) |
1635 | { | 1635 | { |
1636 | struct wps_data *data = gwps->data; | 1636 | struct wps_data *data = gwps->data; |
1637 | 1637 | ||
@@ -1640,13 +1640,13 @@ static bool update_curr_subline(struct gui_wps *gwps, int v, int line) | |||
1640 | bool new_subline_refresh; | 1640 | bool new_subline_refresh; |
1641 | bool only_one_subline; | 1641 | bool only_one_subline; |
1642 | 1642 | ||
1643 | num_sublines = data->viewports[v].lines[line].num_sublines; | 1643 | num_sublines = data->lines[line].num_sublines; |
1644 | reset_subline = (data->viewports[v].lines[line].curr_subline == SUBLINE_RESET); | 1644 | reset_subline = (data->lines[line].curr_subline == SUBLINE_RESET); |
1645 | new_subline_refresh = false; | 1645 | new_subline_refresh = false; |
1646 | only_one_subline = false; | 1646 | only_one_subline = false; |
1647 | 1647 | ||
1648 | /* if time to advance to next sub-line */ | 1648 | /* if time to advance to next sub-line */ |
1649 | if (TIME_AFTER(current_tick, data->viewports[v].lines[line].subline_expire_time - 1) || | 1649 | if (TIME_AFTER(current_tick, data->lines[line].subline_expire_time - 1) || |
1650 | reset_subline) | 1650 | reset_subline) |
1651 | { | 1651 | { |
1652 | /* search all sublines until the next subline with time > 0 | 1652 | /* search all sublines until the next subline with time > 0 |
@@ -1654,46 +1654,46 @@ static bool update_curr_subline(struct gui_wps *gwps, int v, int line) | |||
1654 | if (reset_subline) | 1654 | if (reset_subline) |
1655 | search_start = 0; | 1655 | search_start = 0; |
1656 | else | 1656 | else |
1657 | search_start = data->viewports[v].lines[line].curr_subline; | 1657 | search_start = data->lines[line].curr_subline; |
1658 | 1658 | ||
1659 | for (search = 0; search < num_sublines; search++) | 1659 | for (search = 0; search < num_sublines; search++) |
1660 | { | 1660 | { |
1661 | data->viewports[v].lines[line].curr_subline++; | 1661 | data->lines[line].curr_subline++; |
1662 | 1662 | ||
1663 | /* wrap around if beyond last defined subline or WPS_MAX_SUBLINES */ | 1663 | /* wrap around if beyond last defined subline or WPS_MAX_SUBLINES */ |
1664 | if (data->viewports[v].lines[line].curr_subline == num_sublines) | 1664 | if (data->lines[line].curr_subline == num_sublines) |
1665 | { | 1665 | { |
1666 | if (data->viewports[v].lines[line].curr_subline == 1) | 1666 | if (data->lines[line].curr_subline == 1) |
1667 | only_one_subline = true; | 1667 | only_one_subline = true; |
1668 | data->viewports[v].lines[line].curr_subline = 0; | 1668 | data->lines[line].curr_subline = 0; |
1669 | } | 1669 | } |
1670 | 1670 | ||
1671 | /* if back where we started after search or | 1671 | /* if back where we started after search or |
1672 | only one subline is defined on the line */ | 1672 | only one subline is defined on the line */ |
1673 | if (((search > 0) && | 1673 | if (((search > 0) && |
1674 | (data->viewports[v].lines[line].curr_subline == search_start)) || | 1674 | (data->lines[line].curr_subline == search_start)) || |
1675 | only_one_subline) | 1675 | only_one_subline) |
1676 | { | 1676 | { |
1677 | /* no other subline with a time > 0 exists */ | 1677 | /* no other subline with a time > 0 exists */ |
1678 | data->viewports[v].lines[line].subline_expire_time = (reset_subline ? | 1678 | data->lines[line].subline_expire_time = (reset_subline ? |
1679 | current_tick : | 1679 | current_tick : |
1680 | data->viewports[v].lines[line].subline_expire_time) + 100 * HZ; | 1680 | data->lines[line].subline_expire_time) + 100 * HZ; |
1681 | break; | 1681 | break; |
1682 | } | 1682 | } |
1683 | else | 1683 | else |
1684 | { | 1684 | { |
1685 | /* get initial time multiplier for this subline */ | 1685 | /* get initial time multiplier for this subline */ |
1686 | get_subline_timeout(gwps, v, line, data->viewports[v].lines[line].curr_subline); | 1686 | get_subline_timeout(gwps, line, data->lines[line].curr_subline); |
1687 | 1687 | ||
1688 | int subline_idx = wps_subline_index(data, v, line, | 1688 | int subline_idx = wps_subline_index(data, line, |
1689 | data->viewports[v].lines[line].curr_subline); | 1689 | data->lines[line].curr_subline); |
1690 | 1690 | ||
1691 | /* only use this subline if subline time > 0 */ | 1691 | /* only use this subline if subline time > 0 */ |
1692 | if (data->sublines[subline_idx].time_mult > 0) | 1692 | if (data->sublines[subline_idx].time_mult > 0) |
1693 | { | 1693 | { |
1694 | new_subline_refresh = true; | 1694 | new_subline_refresh = true; |
1695 | data->viewports[v].lines[line].subline_expire_time = (reset_subline ? | 1695 | data->lines[line].subline_expire_time = (reset_subline ? |
1696 | current_tick : data->viewports[v].lines[line].subline_expire_time) + | 1696 | current_tick : data->lines[line].subline_expire_time) + |
1697 | BASE_SUBLINE_TIME*data->sublines[subline_idx].time_mult; | 1697 | BASE_SUBLINE_TIME*data->sublines[subline_idx].time_mult; |
1698 | break; | 1698 | break; |
1699 | } | 1699 | } |
@@ -1909,12 +1909,9 @@ bool gui_wps_refresh(struct gui_wps *gwps, | |||
1909 | { | 1909 | { |
1910 | display->clear_display(); | 1910 | display->clear_display(); |
1911 | 1911 | ||
1912 | for (v = 0; v < data->num_viewports; v++) | 1912 | for (i = 0; i <= data->num_lines; i++) |
1913 | { | 1913 | { |
1914 | for (i = 0; i < data->viewports[v].num_lines; i++) | 1914 | data->lines[i].curr_subline = SUBLINE_RESET; |
1915 | { | ||
1916 | data->viewports[v].lines[i].curr_subline = SUBLINE_RESET; | ||
1917 | } | ||
1918 | } | 1915 | } |
1919 | } | 1916 | } |
1920 | 1917 | ||
@@ -1951,23 +1948,24 @@ bool gui_wps_refresh(struct gui_wps *gwps, | |||
1951 | } | 1948 | } |
1952 | #endif | 1949 | #endif |
1953 | 1950 | ||
1954 | for (line = 0; line < data->viewports[v].num_lines; line++) | 1951 | for (line = data->viewports[v].first_line; |
1952 | line <= data->viewports[v].last_line; line++) | ||
1955 | { | 1953 | { |
1956 | memset(linebuf, 0, sizeof(linebuf)); | 1954 | memset(linebuf, 0, sizeof(linebuf)); |
1957 | update_line = false; | 1955 | update_line = false; |
1958 | 1956 | ||
1959 | /* get current subline for the line */ | 1957 | /* get current subline for the line */ |
1960 | new_subline_refresh = update_curr_subline(gwps, v, line); | 1958 | new_subline_refresh = update_curr_subline(gwps, line); |
1961 | 1959 | ||
1962 | subline_idx = wps_subline_index(data, v, line, | 1960 | subline_idx = wps_subline_index(data, line, |
1963 | data->viewports[v].lines[line].curr_subline); | 1961 | data->lines[line].curr_subline); |
1964 | flags = data->sublines[subline_idx].line_type; | 1962 | flags = data->sublines[subline_idx].line_type; |
1965 | 1963 | ||
1966 | if (refresh_mode == WPS_REFRESH_ALL || (flags & refresh_mode) | 1964 | if (refresh_mode == WPS_REFRESH_ALL || (flags & refresh_mode) |
1967 | || new_subline_refresh) | 1965 | || new_subline_refresh) |
1968 | { | 1966 | { |
1969 | /* get_line tells us if we need to update the line */ | 1967 | /* get_line tells us if we need to update the line */ |
1970 | update_line = get_line(gwps, v, line, data->viewports[v].lines[line].curr_subline, | 1968 | update_line = get_line(gwps, line, data->lines[line].curr_subline, |
1971 | &align, linebuf, sizeof(linebuf)); | 1969 | &align, linebuf, sizeof(linebuf)); |
1972 | } | 1970 | } |
1973 | 1971 | ||
@@ -2021,10 +2019,10 @@ bool gui_wps_refresh(struct gui_wps *gwps, | |||
2021 | /* if the line is a scrolling one we don't want to update | 2019 | /* if the line is a scrolling one we don't want to update |
2022 | too often, so that it has the time to scroll */ | 2020 | too often, so that it has the time to scroll */ |
2023 | if ((refresh_mode & WPS_REFRESH_SCROLL) || new_subline_refresh) | 2021 | if ((refresh_mode & WPS_REFRESH_SCROLL) || new_subline_refresh) |
2024 | write_line(display, &align, line, true); | 2022 | write_line(display, &align, line - data->viewports[v].first_line, true); |
2025 | } | 2023 | } |
2026 | else | 2024 | else |
2027 | write_line(display, &align, line, false); | 2025 | write_line(display, &align, line - data->viewports[v].first_line, false); |
2028 | } | 2026 | } |
2029 | 2027 | ||
2030 | } | 2028 | } |