2 Copyright 2010-2011, The AROS Development Team. All rights reserved.
6 #include "nouveau_intern.h"
8 #include <aros/debug.h>
11 #include "util/u_memory.h"
12 #include "util/u_inlines.h"
13 #include "nouveau/nouveau_winsys.h"
14 #include "nv50/nv50_resource.h"
15 #include "nvfx/nvfx_resource.h"
16 #include "nvc0/nvc0_resource.h"
18 #undef HiddGalliumAttrBase
19 #define HiddGalliumAttrBase (SD(cl)->galliumAttrBase)
21 struct HiddNouveauWinSys
23 struct HIDDT_WinSys base
;
24 struct pipe_screen
*pscreen
;
27 static INLINE
struct HiddNouveauWinSys
*
28 HiddNouveauWinSys(struct pipe_winsys
*ws
)
30 return (struct HiddNouveauWinSys
*)ws
;
34 HIDDNouveauFlushFrontBuffer( struct pipe_screen
*screen
,
35 struct pipe_resource
*resource
,
36 unsigned level
, unsigned layer
,
37 void *winsys_drawable_handle
)
43 HIDDNouveauDestroyWinSys(struct pipe_winsys
*ws
)
45 struct HiddNouveauWinSys
*nvws
= HiddNouveauWinSys(ws
);
50 /* Wraps the nouveau_bo from resource into 2D bitmap class data */
52 HIDDNouveauWrapResource(struct CardData
* carddata
, struct pipe_resource
* resource
,
53 struct HIDDNouveauBitMapData
* bmdata
)
55 struct nouveau_bo
* bo
= NULL
;
56 ULONG pitch
= 0; ULONG depth
= 0;
58 /* Get buffer object and pitch */
59 switch(carddata
->architecture
)
63 bo
= nvfx_resource(resource
)->bo
;
64 pitch
= ((struct nvfx_miptree
*)resource
)->linear_pitch
;
67 bo
= nv50_miptree(resource
)->base
.bo
;
68 pitch
= nv50_miptree(resource
)->level
[0].pitch
;
71 bo
= nvc0_miptree(resource
)->base
.bo
;
72 pitch
= nvc0_miptree(resource
)->level
[0].pitch
;
76 if ((bo
== NULL
) || (pitch
== 0))
79 switch(resource
->format
)
81 case PIPE_FORMAT_B8G8R8A8_UNORM
:
82 case PIPE_FORMAT_A8R8G8B8_UNORM
:
83 /* For purpose of blitting render buffer to screen, 32-bit render
84 buffer is treated as 24-bit surface. This is needed so that checks
85 (src->depth == dst->depth) pass. */
86 case PIPE_FORMAT_B8G8R8X8_UNORM
:
87 case PIPE_FORMAT_X8R8G8B8_UNORM
:
90 case PIPE_FORMAT_B5G5R5A1_UNORM
:
91 case PIPE_FORMAT_B4G4R4A4_UNORM
:
92 case PIPE_FORMAT_B5G6R5_UNORM
:
105 bmdata
->width
= resource
->width0
;
106 bmdata
->height
= resource
->height0
;
107 bmdata
->depth
= depth
;
108 if (bmdata
->depth
== 16)
109 bmdata
->bytesperpixel
= 2;
111 bmdata
->bytesperpixel
= 4;
112 bmdata
->pitch
= pitch
;
113 bmdata
->fbid
= 0; /* Default value */
114 InitSemaphore(&bmdata
->semaphore
);
121 OOP_Object
*METHOD(NouveauGallium
, Root
, New
)
123 o
= (OOP_Object
*)OOP_DoSuperMethod(cl
, o
, (OOP_Msg
) msg
);
127 /* Check if chipset support hardware 3D via gallium */
128 if ((SD(cl
)->carddata
.dev
== NULL
) || (SD(cl
)->carddata
.dev
->chipset
< 0x30))
130 OOP_MethodID dispose_mid
;
131 dispose_mid
= OOP_GetMethodID(IID_Root
, moRoot_Dispose
);
132 OOP_CoerceMethod(cl
, o
, (OOP_Msg
) & dispose_mid
);
140 VOID
METHOD(NouveauGallium
, Root
, Get
)
144 if (IS_GALLIUM_ATTR(msg
->attrID
, idx
))
148 /* Overload the property */
149 case aoHidd_Gallium_GalliumInterfaceVersion
:
150 *msg
->storage
= GALLIUM_INTERFACE_VERSION
;
155 /* Use parent class for all other properties */
156 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
159 APTR
METHOD(NouveauGallium
, Hidd_Gallium
, CreatePipeScreen
)
161 struct HiddNouveauWinSys
*nvws
;
162 struct pipe_winsys
*ws
;
163 struct nouveau_device
*dev
= SD(cl
)->carddata
.dev
;
164 struct pipe_screen
*(*init
)(struct pipe_winsys
*,
165 struct nouveau_device
*);
167 switch (dev
->chipset
& 0xf0)
172 init
= nvfx_screen_create
;
178 init
= nv50_screen_create
;
181 init
= nvc0_screen_create
;
184 D(bug("%s: unknown chipset nv%02x\n", __func__
,
190 nvws
= CALLOC_STRUCT(HiddNouveauWinSys
);
194 ws
= &nvws
->base
.base
;
195 ws
->destroy
= HIDDNouveauDestroyWinSys
;
197 nvws
->pscreen
= init(ws
, dev
);
198 if (!nvws
->pscreen
) {
203 nvws
->pscreen
->flush_frontbuffer
= HIDDNouveauFlushFrontBuffer
;
205 /* Preserve pointer to HIDD driver */
206 nvws
->base
.driver
= o
;
208 return nvws
->pscreen
;
211 VOID
METHOD(NouveauGallium
, Hidd_Gallium
, DisplayResource
)
213 struct CardData
* carddata
= &(SD(cl
)->carddata
);
214 struct HIDDNouveauBitMapData srcdata
;
215 OOP_Object
* bm
= HIDD_BM_OBJ(msg
->bitmap
);
216 struct HIDDNouveauBitMapData
* dstdata
;
218 if (!IS_NOUVEAU_BM_CLASS(OOP_OCLASS(bm
))) /* Check if bitmap is really nouveau bitmap */
221 dstdata
= OOP_INST_DATA(OOP_OCLASS(bm
), bm
);
223 if (!HIDDNouveauWrapResource(carddata
, msg
->resource
, &srcdata
))
226 /* srcdata does not require a lock, because it's a local object that is
227 access only by one task at a time */
228 LOCK_BITMAP_BM(dstdata
)
230 /* HACK: there seems to something wrong with blitting method. Without this
231 mapping, the blitting is jittering with high frame frames. Probably some
232 flush is missing somewhere and doing a mapping executes this missing flush
234 MAP_BUFFER_BM(dstdata
)
236 UNMAP_BUFFER_BM(dstdata
)
238 switch(carddata
->architecture
)
242 HIDDNouveauNV04CopySameFormat(carddata
, &srcdata
, dstdata
,
243 msg
->srcx
, msg
->srcy
, msg
->dstx
, msg
->dsty
, msg
->width
, msg
->height
,
244 0x03 /* vHidd_GC_DrawMode_Copy */);
247 HIDDNouveauNV50CopySameFormat(carddata
, &srcdata
, dstdata
,
248 msg
->srcx
, msg
->srcy
, msg
->dstx
, msg
->dsty
, msg
->width
, msg
->height
,
249 0x03 /* vHidd_GC_DrawMode_Copy */);
252 HIDDNouveauNVC0CopySameFormat(carddata
, &srcdata
, dstdata
,
253 msg
->srcx
, msg
->srcy
, msg
->dstx
, msg
->dsty
, msg
->width
, msg
->height
,
254 0x03 /* vHidd_GC_DrawMode_Copy */);
256 /* TODO: Report error */
261 UNLOCK_BITMAP_BM(dstdata
)