Subversion Repositories Kolibri OS

Rev

Rev 881 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 881 Rev 885
1
int CreatePixmap(pixmap_t *io)
1
int CreatePixmap(pixmap_t *io)
2
{
2
{
3
     local_pixmap_t *pixmap;
3
     local_pixmap_t *pixmap;
4
 
4
 
5
     unsigned pitch;
5
     unsigned pitch;
6
     size_t size;
6
     size_t size;
7
 
7
 
8
     void *local;
8
     void *local;
9
 
9
 
10
     if( (io->width == 0) || (io->width > 2048)||
10
     if( (io->width == 0) || (io->width > 2048)||
11
         (io->height == 0)|| (io->height > 2048))
11
         (io->height == 0)|| (io->height > 2048))
12
     {
12
     {
13
        dbgprintf("Invalid pixmap size w:%d h:%d\n", io->width,io->height);
13
        dbgprintf("Invalid pixmap size w:%d h:%d\n", io->width,io->height);
14
        return ERR_PARAM;
14
        return ERR_PARAM;
15
     };
15
     };
16
 
16
 
17
     pitch = ((io->width+15)&~15)*4;
17
     pitch = ((io->width+15)&~15)*4;
18
     size = pitch*io->height;
18
     size = pitch*io->height;
19
 
19
 
20
     dbgprintf("pitch = %d\n", pitch);
20
     dbgprintf("pitch = %d\n", pitch);
21
 
21
 
22
     local = rhd_mem_alloc(&rhd,RHD_MEM_FB,size) ;
22
     local = rhd_mem_alloc(&rhd,RHD_MEM_FB,size) ;
23
     if ( !local)
23
     if ( !local)
24
     {
24
     {
25
        dbgprintf("Not enough memory for pixmap\n");
25
        dbgprintf("Not enough memory for pixmap\n");
26
        return ERR_PARAM;
26
        return ERR_PARAM;
27
     };
27
     };
28
 
28
 
29
     pixmap = malloc(sizeof(local_pixmap_t));
29
     pixmap = malloc(sizeof(local_pixmap_t));
30
     if(!pixmap)
30
     if(!pixmap)
31
     {
31
     {
32
        rhd_mem_free(&rhd, RHD_MEM_FB,local);
32
        rhd_mem_free(&rhd, RHD_MEM_FB,local);
33
        return ERR_PARAM;
33
        return ERR_PARAM;
34
     }
34
     }
35
     else
35
     else
36
     {
36
     {
37
        void *mapped;
37
        void *mapped;
38
 
38
 
39
        size = (size+4095) & ~ 4095;
39
        size = (size+4095) & ~ 4095;
40
 
40
 
41
        if (mapped = UserAlloc(size))
41
        if (mapped = UserAlloc(size))
42
        {
42
        {
43
           CommitPages(mapped, ((u32_t)local+rhd.LinearAddr)|7|(1<<9), size);
43
           CommitPages(mapped, ((u32_t)local+rhd.LinearAddr)|7|(1<<9), size);
44
 
44
 
45
           io->mapped = mapped;
45
           io->mapped = mapped;
46
           io->pitch   = pitch;
46
           io->pitch   = pitch;
47
           io->handle  = (u32_t)pixmap;
47
           io->handle  = (u32_t)pixmap;
48
 
48
 
49
           pixmap->width   = io->width;
49
           pixmap->width   = io->width;
50
           pixmap->height  = io->height;
50
           pixmap->height  = io->height;
51
           pixmap->format  = PICT_a8r8g8b8;
51
           pixmap->format  = PICT_a8r8g8b8;
52
           pixmap->flags   = io->flags;
52
           pixmap->flags   = io->flags;
53
           pixmap->pitch   = pitch;
53
           pixmap->pitch   = pitch;
54
           pixmap->mapped  = mapped;
54
           pixmap->mapped  = mapped;
55
           pixmap->pitch_offset =  ((pitch/64)<<22)| (((u32_t)local+rhd.fbLocation)>>10);
55
           pixmap->pitch_offset =  ((pitch/64)<<22)| (((u32_t)local+rhd.fbLocation)>>10);
56
           pixmap->local   = local;
56
           pixmap->local   = local+rhd.fbLocation;
57
 
57
 
58
           dbgprintf("pixmap.pitch_offset: %x\n", pixmap->pitch_offset);
58
           dbgprintf("pixmap.pitch_offset: %x\n", pixmap->pitch_offset);
59
           dbgprintf("width: %d height: %d\n",pixmap->width,pixmap->height );
59
           dbgprintf("width: %d height: %d\n",pixmap->width,pixmap->height );
60
           dbgprintf("map at %x\n", pixmap->mapped);
60
           dbgprintf("map at %x\n", pixmap->mapped);
61
 
61
 
62
           return ERR_OK;
62
           return ERR_OK;
63
        };
63
        };
64
        rhd_mem_free(&rhd, RHD_MEM_FB,local);
64
        rhd_mem_free(&rhd, RHD_MEM_FB,local);
65
        free(pixmap);
65
        free(pixmap);
66
     };
66
     };
67
     return ERR_PARAM;
67
     return ERR_PARAM;
68
};
68
};
69
 
69
 
70
 
70
 
71
int DestroyPixmap( pixmap_t *io )
71
int DestroyPixmap( pixmap_t *io )
72
{
72
{
73
     local_pixmap_t *pixmap;
73
     local_pixmap_t *pixmap;
74
     size_t size;
74
     size_t size;
75
 
75
 
76
     dbgprintf("Destroy pixmap %x\n", io->handle);
76
     dbgprintf("Destroy pixmap %x\n", io->handle);
77
 
77
 
78
     if(io->handle == -1)
78
     if(io->handle == -1)
79
        return ERR_PARAM;
79
        return ERR_PARAM;
80
     else
80
     else
81
        pixmap = (local_pixmap_t*)io->handle;
81
        pixmap = (local_pixmap_t*)io->handle;
82
 
82
 
83
     size = (pixmap->pitch*pixmap->height+4095) & ~ 4095;
83
     size = (pixmap->pitch*pixmap->height+4095) & ~ 4095;
84
 
84
 
85
     UnmapPages(pixmap->mapped, size);
85
     UnmapPages(pixmap->mapped, size);
86
     UserFree(pixmap->mapped);
86
     UserFree(pixmap->mapped);
87
 
87
 
88
     rhd_mem_free(&rhd,RHD_MEM_FB,pixmap->local);
88
     rhd_mem_free(&rhd,RHD_MEM_FB,pixmap->local-rhd.fbLocation);
89
     free(pixmap);
89
     free(pixmap);
90
 
90
 
91
     io->format  = 0;
91
     io->format  = 0;
92
     io->pitch   = 0;
92
     io->pitch   = 0;
93
     io->mapped  = NULL;
93
     io->mapped  = NULL;
94
     io->handle  = 0;
94
     io->handle  = 0;
95
 
95
 
96
     return ERR_OK;
96
     return ERR_OK;
97
};
97
};