[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 04/13] sm501: Introduce variable for commonly used value for bette
From: |
Gerd Hoffmann |
Subject: |
[PULL 04/13] sm501: Introduce variable for commonly used value for better readability |
Date: |
Wed, 1 Jul 2020 17:04:16 +0200 |
From: BALATON Zoltan <balaton@eik.bme.hu>
The bytes per pixel value can be calculated from format but it's used
freqently enough (and will be used more in subseqent patches) so store
it in a variable for better readabilty. Also drop some unneded 0x
prefix around where new variable is defined.
Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-id:
b9ea5ef2d68583db9f3fb73a2b859abbd7c044a8.1592686588.git.balaton@eik.bme.hu
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
hw/display/sm501.c | 41 +++++++++++++++++++++--------------------
1 file changed, 21 insertions(+), 20 deletions(-)
diff --git a/hw/display/sm501.c b/hw/display/sm501.c
index ad5a62bfab1b..3ced2c42db3a 100644
--- a/hw/display/sm501.c
+++ b/hw/display/sm501.c
@@ -684,10 +684,11 @@ static void sm501_2d_operation(SM501State *s)
{
int cmd = (s->twoD_control >> 16) & 0x1F;
int rtl = s->twoD_control & BIT(27);
- int format = (s->twoD_stretch >> 20) & 0x3;
- int rop_mode = (s->twoD_control >> 15) & 0x1; /* 1 for rop2, else rop3 */
+ int format = (s->twoD_stretch >> 20) & 3;
+ int bypp = 1 << format; /* bytes per pixel */
+ int rop_mode = (s->twoD_control >> 15) & 1; /* 1 for rop2, else rop3 */
/* 1 if rop2 source is the pattern, otherwise the source is the bitmap */
- int rop2_source_is_pattern = (s->twoD_control >> 14) & 0x1;
+ int rop2_source_is_pattern = (s->twoD_control >> 14) & 1;
int rop = s->twoD_control & 0xFF;
unsigned int dst_x = (s->twoD_destination >> 16) & 0x01FFF;
unsigned int dst_y = s->twoD_destination & 0xFFFF;
@@ -724,8 +725,8 @@ static void sm501_2d_operation(SM501State *s)
}
if (dst_base >= get_local_mem_size(s) ||
- dst_base + (dst_x + width + (dst_y + height) * dst_pitch) *
- (1 << format) >= get_local_mem_size(s)) {
+ dst_base + (dst_x + width + (dst_y + height) * dst_pitch) * bypp >=
+ get_local_mem_size(s)) {
qemu_log_mask(LOG_GUEST_ERROR, "sm501: 2D op dest is outside vram.\n");
return;
}
@@ -750,8 +751,8 @@ static void sm501_2d_operation(SM501State *s)
}
if (src_base >= get_local_mem_size(s) ||
- src_base + (src_x + width + (src_y + height) * src_pitch) *
- (1 << format) >= get_local_mem_size(s)) {
+ src_base + (src_x + width + (src_y + height) * src_pitch) * bypp >=
+ get_local_mem_size(s)) {
qemu_log_mask(LOG_GUEST_ERROR,
"sm501: 2D op src is outside vram.\n");
return;
@@ -763,8 +764,8 @@ static void sm501_2d_operation(SM501State *s)
uint8_t *d = s->local_mem + dst_base;
for (y = 0; y < height; y++) {
- i = (dst_x + (dst_y + y) * dst_pitch) * (1 << format);
- for (x = 0; x < width; x++, i += (1 << format)) {
+ i = (dst_x + (dst_y + y) * dst_pitch) * bypp;
+ for (x = 0; x < width; x++, i += bypp) {
switch (format) {
case 0:
d[i] = ~d[i];
@@ -801,7 +802,7 @@ static void sm501_2d_operation(SM501State *s)
de = db + width + height * (width + dst_pitch);
if (rtl && ((db >= sb && db <= se) || (de >= sb && de <= se))) {
/* regions may overlap: copy via temporary */
- int llb = width * (1 << format);
+ int llb = width * bypp;
int tmp_stride = DIV_ROUND_UP(llb, sizeof(uint32_t));
uint32_t *tmp = tmp_buf;
@@ -809,13 +810,13 @@ static void sm501_2d_operation(SM501State *s)
tmp = g_malloc(tmp_stride * sizeof(uint32_t) * height);
}
pixman_blt((uint32_t *)&s->local_mem[src_base], tmp,
- src_pitch * (1 << format) / sizeof(uint32_t),
- tmp_stride, 8 * (1 << format), 8 * (1 << format),
+ src_pitch * bypp / sizeof(uint32_t),
+ tmp_stride, 8 * bypp, 8 * bypp,
src_x, src_y, 0, 0, width, height);
pixman_blt(tmp, (uint32_t *)&s->local_mem[dst_base],
tmp_stride,
- dst_pitch * (1 << format) / sizeof(uint32_t),
- 8 * (1 << format), 8 * (1 << format),
+ dst_pitch * bypp / sizeof(uint32_t),
+ 8 * bypp, 8 * bypp,
0, 0, dst_x, dst_y, width, height);
if (tmp != tmp_buf) {
g_free(tmp);
@@ -823,9 +824,9 @@ static void sm501_2d_operation(SM501State *s)
} else {
pixman_blt((uint32_t *)&s->local_mem[src_base],
(uint32_t *)&s->local_mem[dst_base],
- src_pitch * (1 << format) / sizeof(uint32_t),
- dst_pitch * (1 << format) / sizeof(uint32_t),
- 8 * (1 << format), 8 * (1 << format),
+ src_pitch * bypp / sizeof(uint32_t),
+ dst_pitch * bypp / sizeof(uint32_t),
+ 8 * bypp, 8 * bypp,
src_x, src_y, dst_x, dst_y, width, height);
}
}
@@ -842,8 +843,8 @@ static void sm501_2d_operation(SM501State *s)
}
pixman_fill((uint32_t *)&s->local_mem[dst_base],
- dst_pitch * (1 << format) / sizeof(uint32_t),
- 8 * (1 << format), dst_x, dst_y, width, height, color);
+ dst_pitch * bypp / sizeof(uint32_t),
+ 8 * bypp, dst_x, dst_y, width, height, color);
break;
}
default:
@@ -855,7 +856,7 @@ static void sm501_2d_operation(SM501State *s)
if (dst_base >= get_fb_addr(s, crt) &&
dst_base <= get_fb_addr(s, crt) + fb_len) {
int dst_len = MIN(fb_len, ((dst_y + height - 1) * dst_pitch +
- dst_x + width) * (1 << format));
+ dst_x + width) * bypp);
if (dst_len) {
memory_region_set_dirty(&s->local_mem_region, dst_base, dst_len);
}
--
2.18.4
- [PULL 00/13] Vga 20200701 patches, Gerd Hoffmann, 2020/07/01
- [PULL 03/13] sm501: Ignore no-op blits, Gerd Hoffmann, 2020/07/01
- [PULL 01/13] sm501: Fix bounds checks, Gerd Hoffmann, 2020/07/01
- [PULL 06/13] sm501: Use stn_he_p/ldn_he_p instead of switch/case, Gerd Hoffmann, 2020/07/01
- [PULL 13/13] configure: vgabios cleanups, Gerd Hoffmann, 2020/07/01
- [PULL 09/13] sm501: Fix and optimize overlap check, Gerd Hoffmann, 2020/07/01
- [PULL 07/13] sm501: Do not allow guest to set invalid format, Gerd Hoffmann, 2020/07/01
- [PULL 02/13] sm501: Drop unneded variable, Gerd Hoffmann, 2020/07/01
- [PULL 05/13] sm501: Optimise 1 pixel 2d ops, Gerd Hoffmann, 2020/07/01
- [PULL 04/13] sm501: Introduce variable for commonly used value for better readability,
Gerd Hoffmann <=
- [PULL 08/13] sm501: Convert debug printfs to traces, Gerd Hoffmann, 2020/07/01
- [PULL 11/13] ati-vga: Do not assert on error, Gerd Hoffmann, 2020/07/01
- [PULL 12/13] ati-vga: Add dummy MEM_SDRAM_MODE_REG, Gerd Hoffmann, 2020/07/01
- [PULL 10/13] ati-vga: Support unaligned access to hardware cursor registers, Gerd Hoffmann, 2020/07/01
- Re: [PULL 00/13] Vga 20200701 patches, Peter Maydell, 2020/07/02