summaryrefslogtreecommitdiff
path: root/Source/DirectFB/gfxdrivers/unichrome/uc_spic.c
blob: b7665b38c2870b95ea8902628121c9ef35ac2a6a (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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*
   Copyright (c) 2003 Andreas Robinson, All rights reserved.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.
*/

#include <config.h>

#include "unichrome.h"
#include "vidregs.h"
#include "mmio.h"

#include <core/system.h>
#include <core/palette.h>

#define UC_SPIC_OPTIONS DLOP_OPACITY

typedef struct _UcSubpictureData {
} UcSubpictureData;

static int uc_spic_datasize( void )
{
    return sizeof(UcSubpictureData);
}

static void
uc_spic_set_palette( volatile u8* hwregs, CorePalette *palette )
{
    int i;

    if (palette) {
        for (i = 0; i < 16; i++) {
            /* TODO: Check r-g-b order. */
            VIDEO_OUT(hwregs, RAM_TABLE_CONTROL,
                (palette->entries[i].r << 24) |
                (palette->entries[i].g << 16) |
                (palette->entries[i].b <<  8) |
                (i << 4) | RAM_TABLE_RGB_ENABLE);
        }
    }
}

static void uc_spic_enable( volatile u8 *hwregs, bool enable )
{
    VIDEO_OUT(hwregs, SUBP_CONTROL_STRIDE,
        (VIDEO_IN(hwregs, SUBP_CONTROL_STRIDE) & ~SUBP_HQV_ENABLE) |
        (enable ? SUBP_HQV_ENABLE : 0));
}

static void
uc_spic_set_buffer( volatile u8 *hwregs, CoreSurfaceBufferLock *lock )
{
    if (lock) {
        VIDEO_OUT(hwregs, SUBP_STARTADDR,
            lock->offset);
        VIDEO_OUT(hwregs, SUBP_CONTROL_STRIDE,
            (VIDEO_IN(hwregs, SUBP_CONTROL_STRIDE) & ~SUBP_STRIDE_MASK) |
            (lock->pitch & SUBP_STRIDE_MASK) |
            SUBP_AI44 );
    }
}

static DFBResult
uc_spic_init_layer( CoreLayer                   *layer,
                    void                        *driver_data,
                    void                        *layer_data,
                    DFBDisplayLayerDescription  *description,
                    DFBDisplayLayerConfig       *config,
                    DFBColorAdjustment          *adjustment )
{
    /* Set layer type, capabilities and name */

    description->caps = DLCAPS_SURFACE | DLCAPS_OPACITY;
    description->type = DLTF_GRAPHICS | DLTF_VIDEO | DLTF_STILL_PICTURE;
    snprintf(description->name,
        DFB_DISPLAY_LAYER_DESC_NAME_LENGTH, "VIA Unichrome DVD Subpicture");

    adjustment->flags = DCAF_NONE;

    /* Fill out the default configuration */

    config->flags  = DLCONF_WIDTH | DLCONF_HEIGHT |
                     DLCONF_PIXELFORMAT | DLCONF_BUFFERMODE | DLCONF_OPTIONS;

    config->width  = 720;
    config->height = 576;

    config->pixelformat = DSPF_ALUT44;
    config->buffermode  = DLBM_FRONTONLY;
    config->options     = DLOP_NONE;

    return DFB_OK;
}

static DFBResult
uc_spic_test_region( CoreLayer                  *layer,
                     void                       *driver_data,
                     void                       *layer_data,
                     CoreLayerRegionConfig      *config,
                     CoreLayerRegionConfigFlags *failed)
{
    CoreLayerRegionConfigFlags fail = 0;

    /* Check layer options */

    if (config->options & ~UC_SPIC_OPTIONS)
        fail |= CLRCF_OPTIONS;

    /* Check pixelformats */

    switch (config->format) {
          case DSPF_ALUT44:
              break;
          //case DSPF_LUTA44:
              // IA44 does not exist in DirectFB, but hw supports it.
          default:
              fail |= CLRCF_FORMAT;
    }

    /* Check width and height */

    if (config->width > 8195 || config->width < 1)
        fail |= CLRCF_WIDTH;

    if (config->height > 4096 || config->height < 1)
        fail |= CLRCF_HEIGHT;

    if (failed) *failed = fail;
    if (fail) return DFB_UNSUPPORTED;

    return DFB_OK;
}

static DFBResult
uc_spic_set_region( CoreLayer                  *layer,
                    void                       *driver_data,
                    void                       *layer_data,
                    void                       *region_data,
                    CoreLayerRegionConfig      *config,
                    CoreLayerRegionConfigFlags  updated,
                    CoreSurface                *surface,
                    CorePalette                *palette,
                    CoreSurfaceBufferLock      *lock )
{
    UcDriverData*  ucdrv = (UcDriverData*) driver_data;

    uc_spic_set_palette(ucdrv->hwregs, palette);
    uc_spic_set_buffer(ucdrv->hwregs, lock);
    uc_spic_enable(ucdrv->hwregs, (config->opacity > 0));

    return DFB_OK;
}

static DFBResult
uc_spic_remove( CoreLayer *layer,
                void      *driver_data,
                void      *layer_data,
                void      *region_data )
{
    UcDriverData*  ucdrv = (UcDriverData*) driver_data;

    uc_spic_enable(ucdrv->hwregs, false);
    return DFB_OK;
}

static DFBResult
uc_spic_flip_region( CoreLayer             *layer,
                     void                  *driver_data,
                     void                  *layer_data,
                     void                  *region_data,
                     CoreSurface           *surface,
                     DFBSurfaceFlipFlags    flags,
                     CoreSurfaceBufferLock *lock )
{
    UcDriverData*  ucdrv = (UcDriverData*) driver_data;

    dfb_surface_flip(surface, false);
    uc_spic_set_buffer(ucdrv->hwregs, lock);

    return DFB_OK;
}

DisplayLayerFuncs ucSubpictureFuncs = {
     .LayerDataSize = uc_spic_datasize,
     .InitLayer     = uc_spic_init_layer,
     .SetRegion     = uc_spic_set_region,
     .RemoveRegion  = uc_spic_remove,
     .TestRegion    = uc_spic_test_region,
     .FlipRegion    = uc_spic_flip_region,
};