summaryrefslogtreecommitdiff
path: root/display/surface.h
blob: 028f97eb6d2570e831014abac58ac8717258ae95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifndef SURFACE_H
#define SURFACE_H

#include "qxldd.h"

static _inline UINT32 GetSurfaceIdFromInfo(SurfaceInfo *info)
{
  PDev *pdev;

  pdev = info->u.pdev;
  if (info == &pdev->surface0_info) {
    return 0;
  }
  return info - pdev->Res->surfaces_info;
}

static _inline SurfaceInfo *GetSurfaceInfo(PDev *pdev, UINT32 id)
{
  if (id == 0) {
    return &pdev->surface0_info;
  }
  return &pdev->Res->surfaces_info[id];
}

static _inline UINT32 GetSurfaceId(SURFOBJ *surf)
{
    SurfaceInfo *surface;

    surface = (SurfaceInfo *)surf->dhsurf;
    return GetSurfaceIdFromInfo(surface);
}

static _inline void FreeSurface(PDev *pdev, UINT32 surface_id)
{
    SurfaceInfo *surface;

    if (surface_id == 0) {
        return;
    }

    EngAcquireSemaphore(pdev->Res->surface_sem);

    surface = &pdev->Res->surfaces_info[surface_id];
    surface->draw_area.base_mem = NULL; /* Mark as not used */
    surface->u.next_free = pdev->Res->free_surfaces;
    pdev->Res->free_surfaces = surface;

    EngReleaseSemaphore(pdev->Res->surface_sem);
}


static UINT32 GetFreeSurface(PDev *pdev)
{
    UINT32 x, id;
    SurfaceInfo *surface;

    EngAcquireSemaphore(pdev->Res->surface_sem);

    surface = pdev->Res->free_surfaces;
    if (surface == NULL) {
        id = 0;
    } else {
      pdev->Res->free_surfaces = surface->u.next_free;

      id = surface - pdev->Res->surfaces_info;
    }

    EngReleaseSemaphore(pdev->Res->surface_sem);

    return id;
}

enum {
    DEVICE_BITMAP_ALLOCATION_TYPE_SURF0,
    DEVICE_BITMAP_ALLOCATION_TYPE_DEVRAM,
    DEVICE_BITMAP_ALLOCATION_TYPE_VRAM,
};

BOOL CreateDrawArea(PDev *pdev, UINT8 *base_mem, ULONG format, UINT32 cx, UINT32 cy, UINT32 stride,
                    UINT32 surface_id);
VOID FreeDrawArea(DrawArea *drawarea);

HBITMAP CreateDeviceBitmap(PDev *pdev, SIZEL size, ULONG format, QXLPHYSICAL *phys_mem,
                           UINT8 **base_mem, UINT32 surface_id, UINT8 allocation_type);
VOID DeleteDeviceBitmap(PDev *pdev, UINT32 surface_id, UINT8 allocation_type);

#endif