2 #include <lib/base/init.h>
3 #include <lib/base/init_num.h>
4 #include <lib/gdi/accel.h>
5 #include <lib/base/eerror.h>
6 #include <lib/gdi/esize.h>
7 #include <lib/gdi/epoint.h>
8 #include <lib/gdi/erect.h>
9 #include <lib/gdi/gpixmap.h>
11 gAccel *gAccel::instance;
15 extern int ati_accel_init(void);
16 extern void ati_accel_close(void);
17 extern void ati_accel_blit(
18 int src_addr, int src_width, int src_height, int src_stride,
19 int dst_addr, int dst_width, int dst_height, int dst_stride,
20 int src_x, int src_y, int width, int height,
21 int dst_x, int dst_y);
22 extern void ati_accel_fill(
23 int dst_addr, int dst_width, int dst_height, int dst_stride,
24 int x, int y, int width, int height,
28 extern int bcm_accel_init(void);
29 extern void bcm_accel_close(void);
30 extern void bcm_accel_blit(
31 int src_addr, int src_width, int src_height, int src_stride, int src_format,
32 int dst_addr, int dst_width, int dst_height, int dst_stride,
33 int src_x, int src_y, int width, int height,
34 int dst_x, int dst_y, int dwidth, int dheight,
35 int pal_addr, int flags);
36 extern void bcm_accel_fill(
37 int dst_addr, int dst_width, int dst_height, int dst_stride,
38 int x, int y, int width, int height,
45 m_accel_phys_addr = 0;
47 m_accel_allocation = 0;
54 m_bcm_accel_state = bcm_accel_init();
69 gAccel *gAccel::getInstance()
74 void gAccel::setAccelMemorySpace(void *addr, int phys_addr, int size)
76 if (m_accel_allocation)
77 delete[] m_accel_allocation;
79 m_accel_size = size >> 12;
81 m_accel_allocation = new int[m_accel_size];
82 memset(m_accel_allocation, 0, sizeof(int)*m_accel_size);
85 m_accel_phys_addr = phys_addr;
88 int gAccel::blit(gSurface *dst, const gSurface *src, const eRect &p, const eRect &area, int flags)
92 src->data_phys, src->x, src->y, src->stride,
93 dst->data_phys, dst->x, dst->y, dst->stride,
94 area.left(), area.top(), area.width(), area.height(),
99 if (!m_bcm_accel_state)
101 if (flags & (gPixmap::blitAlphaTest|gPixmap::blitAlphaBlend)) /* unsupported flags */
103 unsigned long pal_addr = 0;
107 else if ((src->bpp == 8) && src->clut.data)
112 pal_addr = src->stride * src->y;
113 unsigned long *pal = (unsigned long*)(((unsigned char*)src->data) + pal_addr);
114 pal_addr += src->data_phys;
115 for (i = 0; i < src->clut.colors; ++i)
116 *pal++ = src->clut.data[i].argb() ^ 0xFF000000;
118 return -1; /* unsupported source format */
121 src->data_phys, src->x, src->y, src->stride, src_format,
122 dst->data_phys, dst->x, dst->y, dst->stride,
123 area.left(), area.top(), area.width(), area.height(),
124 p.x(), p.y(), p.width(), p.height(),
132 int gAccel::fill(gSurface *dst, const eRect &area, unsigned long col)
136 dst->data_phys, dst->x, dst->y, dst->stride,
137 area.left(), area.top(), area.width(), area.height(),
142 if (!m_bcm_accel_state) {
144 dst->data_phys, dst->x, dst->y, dst->stride,
145 area.left(), area.top(), area.width(), area.height(),
153 int gAccel::accelAlloc(void *&addr, int &phys_addr, int size)
155 eDebug("accel %d bytes", size);
156 if ((!size) || (!m_accel_allocation))
158 eDebug("size: %d, alloc %p", size, m_accel_allocation);
164 size += 4095; size >>= 12;
167 int used = 0, free = 0, s = 0;
168 for (i=0; i < m_accel_size; ++i)
170 if (m_accel_allocation[i] == 0)
172 else if (m_accel_allocation[i] == -1)
177 s += m_accel_allocation[i];
180 eDebug("accel memstat: used=%d kB, free %d kB, s %d kB", used * 4, free * 4, s * 4);
182 for (i=0; i < m_accel_size - size; ++i)
185 for (a=0; a<size; ++a)
186 if (m_accel_allocation[i+a])
190 m_accel_allocation[i] = size;
191 for (a=1; a<size; ++a)
192 m_accel_allocation[i+a] = -1;
193 addr = ((unsigned char*)m_accel_addr) + (i << 12);
194 phys_addr = m_accel_phys_addr + (i << 12);
198 eDebug("accel alloc failed\n");
202 void gAccel::accelFree(int phys_addr)
204 phys_addr -= m_accel_phys_addr;
207 int size = m_accel_allocation[phys_addr];
212 m_accel_allocation[phys_addr++] = 0;
215 eAutoInitP0<gAccel> init_gAccel(eAutoInitNumbers::graphic-2, "graphics acceleration manager");