summaryrefslogtreecommitdiff
path: root/display/surface.h
blob: 0b7edb3da7614d4e934b33847e8243508e79d96f (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#ifndef SURFACE_H
#define SURFACE_H

#include "qxldd.h"

/* Hooks supported by our surfaces. */
#ifdef CALL_TEST
#define QXL_SURFACE_HOOKS_CALL_TEST \
    (HOOK_PLGBLT | HOOK_FILLPATH | HOOK_STROKEANDFILLPATH | HOOK_LINETO |  \
    HOOK_GRADIENTFILL)
#else
#define QXL_SURFACE_HOOKS_CALL_TEST (0)
#endif

#define QXL_SURFACE_HOOKS \
    (HOOK_SYNCHRONIZE | HOOK_COPYBITS |                                 \
    HOOK_BITBLT | HOOK_TEXTOUT | HOOK_STROKEPATH | HOOK_STRETCHBLT |    \
    HOOK_STRETCHBLTROP | HOOK_TRANSPARENTBLT | HOOK_ALPHABLEND | QXL_SURFACE_HOOKS_CALL_TEST)


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

  pdev = info->u.pdev;
  if (info == &pdev->surface0_info) {
    return 0;
  }
  return (UINT32)(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;

    if (!surf || !surf->dhsurf) {
        return (UINT32)-1;
    }
    surface = (SurfaceInfo *)surf->dhsurf;
    return GetSurfaceIdFromInfo(surface);
}

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

    if (surface_id == 0) {
        return;
    }
    EngAcquireSemaphore(pdev->Res->surface_sem);

    DEBUG_PRINT((pdev, 9, "%s: %p: %d\n", __FUNCTION__, pdev, surface_id));
    surface = &pdev->Res->surfaces_info[surface_id];
    if (surface->draw_area.base_mem == NULL) {
        DEBUG_PRINT((pdev, 9, "%s: %p: %d: double free. safely ignored\n", __FUNCTION__,
            pdev, surface_id));
        EngReleaseSemaphore(pdev->Res->surface_sem);
        return;
    }
    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 = (UINT32)(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,
};

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