2 Copyright 2010-2017, The AROS Development Team. All rights reserved.
6 #include "nouveau_intern.h"
8 #include <aros/debug.h>
10 #include <proto/oop.h>
11 #include <proto/utility.h>
13 #include "util/u_memory.h"
14 #include "util/u_inlines.h"
15 #include "nouveau/nouveau_winsys.h"
16 #include "nv50/nv50_resource.h"
17 #include "nvfx/nvfx_resource.h"
18 #include "nvc0/nvc0_resource.h"
20 #undef HiddGalliumAttrBase
21 #define HiddGalliumAttrBase (SD(cl)->galliumAttrBase)
23 struct HiddNouveauWinSys
25 struct HIDDT_WinSys base
;
26 struct pipe_screen
*pscreen
;
29 static INLINE
struct HiddNouveauWinSys
*
30 HiddNouveauWinSys(struct pipe_winsys
*ws
)
32 return (struct HiddNouveauWinSys
*)ws
;
36 HIDDNouveauFlushFrontBuffer( struct pipe_screen
*screen
,
37 struct pipe_resource
*resource
,
38 unsigned level
, unsigned layer
,
39 void *winsys_drawable_handle
)
45 HIDDNouveauDestroyWinSys(struct pipe_winsys
*ws
)
47 struct HiddNouveauWinSys
*nvws
= HiddNouveauWinSys(ws
);
52 /* Wraps the nouveau_bo from resource into 2D bitmap class data */
54 HIDDNouveauWrapResource(struct CardData
* carddata
, struct pipe_resource
* resource
,
55 struct HIDDNouveauBitMapData
* bmdata
)
57 struct nouveau_bo
* bo
= NULL
;
58 ULONG pitch
= 0; ULONG depth
= 0;
60 /* Get buffer object and pitch */
61 switch(carddata
->architecture
)
65 bo
= nvfx_resource(resource
)->bo
;
66 pitch
= ((struct nvfx_miptree
*)resource
)->linear_pitch
;
69 bo
= nv50_miptree(resource
)->base
.bo
;
70 pitch
= nv50_miptree(resource
)->level
[0].pitch
;
73 bo
= nvc0_miptree(resource
)->base
.bo
;
74 pitch
= nvc0_miptree(resource
)->level
[0].pitch
;
78 if ((bo
== NULL
) || (pitch
== 0))
81 switch(resource
->format
)
83 case PIPE_FORMAT_B8G8R8A8_UNORM
:
84 case PIPE_FORMAT_A8R8G8B8_UNORM
:
85 /* For purpose of blitting render buffer to screen, 32-bit render
86 buffer is treated as 24-bit surface. This is needed so that checks
87 (src->depth == dst->depth) pass. */
88 case PIPE_FORMAT_B8G8R8X8_UNORM
:
89 case PIPE_FORMAT_X8R8G8B8_UNORM
:
92 case PIPE_FORMAT_B5G5R5A1_UNORM
:
93 case PIPE_FORMAT_B4G4R4A4_UNORM
:
94 case PIPE_FORMAT_B5G6R5_UNORM
:
107 bmdata
->width
= resource
->width0
;
108 bmdata
->height
= resource
->height0
;
109 bmdata
->depth
= depth
;
110 if (bmdata
->depth
== 16)
111 bmdata
->bytesperpixel
= 2;
113 bmdata
->bytesperpixel
= 4;
114 bmdata
->pitch
= pitch
;
115 bmdata
->fbid
= 0; /* Default value */
116 InitSemaphore(&bmdata
->semaphore
);
123 OOP_Object
*METHOD(NouveauGallium
, Root
, New
)
127 interfaceVers
= GetTagData(aHidd_Gallium_InterfaceVersion
, -1, msg
->attrList
);
128 if (interfaceVers
!= GALLIUM_INTERFACE_VERSION
)
131 o
= (OOP_Object
*)OOP_DoSuperMethod(cl
, o
, (OOP_Msg
) msg
);
134 /* Check if chipset support hardware 3D via gallium */
135 if ((SD(cl
)->carddata
.dev
== NULL
) || (SD(cl
)->carddata
.dev
->chipset
< 0x30))
137 OOP_MethodID dispose_mid
;
138 dispose_mid
= OOP_GetMethodID(IID_Root
, moRoot_Dispose
);
139 OOP_CoerceMethod(cl
, o
, (OOP_Msg
) & dispose_mid
);
147 VOID
METHOD(NouveauGallium
, Root
, Get
)
151 if (IS_GALLIUM_ATTR(msg
->attrID
, idx
))
155 /* Overload the property */
156 case aoHidd_Gallium_InterfaceVersion
:
157 *msg
->storage
= GALLIUM_INTERFACE_VERSION
;
162 /* Use parent class for all other properties */
163 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
166 APTR
METHOD(NouveauGallium
, Hidd_Gallium
, CreatePipeScreen
)
168 struct HiddNouveauWinSys
*nvws
;
169 struct pipe_winsys
*ws
;
170 struct nouveau_device
*dev
= SD(cl
)->carddata
.dev
;
171 struct pipe_screen
*(*init
)(struct pipe_winsys
*,
172 struct nouveau_device
*);
174 switch (dev
->chipset
& 0xf0)
179 init
= nvfx_screen_create
;
185 init
= nv50_screen_create
;
188 init
= nvc0_screen_create
;
191 D(bug("%s: unknown chipset nv%02x\n", __func__
,
198 nvws
= CALLOC_STRUCT(HiddNouveauWinSys
);
203 ws
= &nvws
->base
.base
;
204 ws
->destroy
= HIDDNouveauDestroyWinSys
;
206 nvws
->pscreen
= init(ws
, dev
);
207 if (!nvws
->pscreen
) {
213 nvws
->pscreen
->flush_frontbuffer
= HIDDNouveauFlushFrontBuffer
;
215 /* Preserve pointer to HIDD driver */
216 nvws
->base
.driver
= o
;
220 return nvws
->pscreen
;
223 VOID
METHOD(NouveauGallium
, Hidd_Gallium
, DisplayResource
)
225 struct CardData
* carddata
= &(SD(cl
)->carddata
);
226 struct HIDDNouveauBitMapData srcdata
;
227 OOP_Object
* bm
= HIDD_BM_OBJ(msg
->bitmap
);
228 struct HIDDNouveauBitMapData
* dstdata
;
230 if (!IS_NOUVEAU_BM_CLASS(OOP_OCLASS(bm
))) /* Check if bitmap is really nouveau bitmap */
233 dstdata
= OOP_INST_DATA(OOP_OCLASS(bm
), bm
);
235 if (!HIDDNouveauWrapResource(carddata
, msg
->resource
, &srcdata
))
240 /* srcdata does not require a lock, because it's a local object that is
241 access only by one task at a time */
242 LOCK_BITMAP_BM(dstdata
)
244 /* HACK: there seems to something wrong with blitting method. Without this
245 mapping, the blitting is jittering with high frame frames. Probably some
246 flush is missing somewhere and doing a mapping executes this missing flush
248 MAP_BUFFER_BM(dstdata
)
250 UNMAP_BUFFER_BM(dstdata
)
252 switch(carddata
->architecture
)
256 HIDDNouveauNV04CopySameFormat(carddata
, &srcdata
, dstdata
,
257 msg
->srcx
, msg
->srcy
, msg
->dstx
, msg
->dsty
, msg
->width
, msg
->height
,
258 0x03 /* vHidd_GC_DrawMode_Copy */);
261 HIDDNouveauNV50CopySameFormat(carddata
, &srcdata
, dstdata
,
262 msg
->srcx
, msg
->srcy
, msg
->dstx
, msg
->dsty
, msg
->width
, msg
->height
,
263 0x03 /* vHidd_GC_DrawMode_Copy */);
266 HIDDNouveauNVC0CopySameFormat(carddata
, &srcdata
, dstdata
,
267 msg
->srcx
, msg
->srcy
, msg
->dstx
, msg
->dsty
, msg
->width
, msg
->height
,
268 0x03 /* vHidd_GC_DrawMode_Copy */);
270 /* TODO: Report error */
275 UNLOCK_BITMAP_BM(dstdata
)