1 /*
2    (c) Copyright 2001-2009  The world wide DirectFB Open Source Community (directfb.org)
3    (c) Copyright 2000-2004  Convergence (integrated media) GmbH
4 
5    All rights reserved.
6 
7    Written by Denis Oliver Kropp <dok@directfb.org>,
8               Andreas Hundt <andi@fischlustig.de>,
9               Sven Neumann <neo@directfb.org>,
10               Ville Syrjälä <syrjala@sci.fi> and
11               Claudio Ciccani <klan@users.sf.net>.
12 
13    This library is free software; you can redistribute it and/or
14    modify it under the terms of the GNU Lesser General Public
15    License as published by the Free Software Foundation; either
16    version 2 of the License, or (at your option) any later version.
17 
18    This library is distributed in the hope that it will be useful,
19    but WITHOUT ANY WARRANTY; without even the implied warranty of
20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21    Lesser General Public License for more details.
22 
23    You should have received a copy of the GNU Lesser General Public
24    License along with this library; if not, write to the
25    Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26    Boston, MA 02111-1307, USA.
27 */
28 
29 #ifndef __CORE__LAYERS_H__
30 #define __CORE__LAYERS_H__
31 
32 #include <directfb.h>
33 
34 #include <core/coretypes.h>
35 
36 #include <core/gfxcard.h>
37 #include <core/surface_buffer.h>
38 
39 
40 struct __DFB_CoreLayerRegionConfig {
41      int                        width;            /* width of the source in pixels */
42      int                        height;           /* height of the source in pixels */
43      DFBSurfacePixelFormat      format;           /* pixel format of the source surface */
44      DFBSurfaceCapabilities     surface_caps;     /* capabilities of the source surface */
45      DFBDisplayLayerBufferMode  buffermode;       /* surface buffer configuration */
46 
47      DFBDisplayLayerOptions     options;          /* various configuration options */
48 
49      DFBDisplayLayerSourceID    source_id;        /* selected source */
50 
51      DFBRectangle               source;           /* viewport within source (input) */
52      DFBRectangle               dest;             /* viewport on screen (output) */
53 
54      u8                         opacity;          /* global region alpha */
55 
56      DFBColorKey                src_key;          /* source color key */
57      DFBColorKey                dst_key;          /* destination color key */
58 
59      int                        parity;           /* field parity (for interlaced) */
60 
61      u8                         alpha_ramp[4];    /* alpha values for 1 or 2 bit lookup */
62 
63      DFBRegion                 *clips;            /* clip regions */
64      int                        num_clips;        /* number of clip regions */
65      DFBBoolean                 positive;         /* show or cut out regions */
66 
67      bool                       keep_buffers;
68 };
69 
70 #if D_DEBUG_ENABLED
71 #define DFB_CORE_LAYER_REGION_CONFIG_DEBUG_AT( domain, config )                                                    \
72      do {                                                                                                          \
73           const CoreLayerRegionConfig *_config = config;                                                           \
74                                                                                                                    \
75           D_DEBUG_AT( domain, "  -> size       %dx%d\n", _config->width, _config->height );                        \
76           D_DEBUG_AT( domain, "  -> format     %s\n", dfb_pixelformat_name( _config->format ) );                   \
77           D_DEBUG_AT( domain, "  -> surf caps  0x%08x\n", _config->surface_caps );                                 \
78           D_DEBUG_AT( domain, "  -> buffermode %d\n", _config->buffermode );                                       \
79           D_DEBUG_AT( domain, "  -> options    0x%08x\n", _config->options );                                      \
80           D_DEBUG_AT( domain, "  -> source     %d,%d-%dx%d\n", DFB_RECTANGLE_VALS(&_config->source) );             \
81           D_DEBUG_AT( domain, "  -> dest       %d,%d-%dx%d\n", DFB_RECTANGLE_VALS(&_config->dest) );               \
82           D_DEBUG_AT( domain, "  -> opacity    %d\n", _config->opacity );                                          \
83           D_DEBUG_AT( domain, "  -> src_key    %02x%02x%02x (index %d)\n", DFB_COLORKEY_VALS(&_config->src_key) ); \
84           D_DEBUG_AT( domain, "  -> dst_key    %02x%02x%02x (index %d)\n", DFB_COLORKEY_VALS(&_config->dst_key) ); \
85      } while (0)
86 #else
87 #define DFB_CORE_LAYER_REGION_CONFIG_DEBUG_AT( domain, config )                                                    \
88      do {                                                                                                          \
89      } while (0)
90 #endif
91 
92 typedef enum {
93      CLRCF_NONE         = 0x00000000,
94 
95      CLRCF_WIDTH        = 0x00000001,
96      CLRCF_HEIGHT       = 0x00000002,
97      CLRCF_FORMAT       = 0x00000004,
98      CLRCF_SURFACE_CAPS = 0x00000008,
99 
100      CLRCF_BUFFERMODE   = 0x00000010,
101      CLRCF_OPTIONS      = 0x00000020,
102      CLRCF_SOURCE_ID    = 0x00000040,
103 
104      CLRCF_SOURCE       = 0x00000100,
105      CLRCF_DEST         = 0x00000200,
106      CLRCF_CLIPS        = 0x00000400,
107 
108      CLRCF_OPACITY      = 0x00001000,
109      CLRCF_ALPHA_RAMP   = 0x00002000,
110 
111      CLRCF_SRCKEY       = 0x00010000,
112      CLRCF_DSTKEY       = 0x00020000,
113 
114      CLRCF_PARITY       = 0x00100000,
115 
116      CLRCF_SURFACE      = 0x10000000,
117      CLRCF_PALETTE      = 0x20000000,
118 
119      CLRCF_FREEZE       = 0x80000000,
120 
121      CLRCF_ALL          = 0xB013377F
122 } CoreLayerRegionConfigFlags;
123 
124 typedef struct {
125    /** Driver Control **/
126 
127      /*
128       * Return size of layer data (shared memory).
129       */
130      int       (*LayerDataSize) ( void );
131 
132      /*
133       * Return size of region data (shared memory).
134       */
135      int       (*RegionDataSize)( void );
136 
137      /*
138       * Called once by the master to initialize layer data and reset hardware.
139       * Return layer description, default configuration and color adjustment.
140       */
141      DFBResult (*InitLayer)     ( CoreLayer                  *layer,
142                                   void                       *driver_data,
143                                   void                       *layer_data,
144                                   DFBDisplayLayerDescription *description,
145                                   DFBDisplayLayerConfig      *config,
146                                   DFBColorAdjustment         *adjustment );
147 
148      /*
149       * Called once by the master to shutdown the layer.
150       * Use this function to free any resources that were taken during init.
151       */
152      DFBResult (*ShutdownLayer) ( CoreLayer                  *layer,
153                                   void                       *driver_data,
154                                   void                       *layer_data );
155 
156      /*
157       * Called once by the master for each source.
158       * Driver fills description.
159       */
160      DFBResult (*InitSource)    ( CoreLayer                         *layer,
161                                   void                              *driver_data,
162                                   void                              *layer_data,
163                                   int                                source,
164                                   DFBDisplayLayerSourceDescription  *description );
165 
166 
167    /** Layer Control **/
168 
169      /*
170       * Return the currently displayed field (interlaced only).
171       */
172      DFBResult (*GetCurrentOutputField)( CoreLayer              *layer,
173                                          void                   *driver_data,
174                                          void                   *layer_data,
175                                          int                    *field );
176 
177      /*
178       * Return the z position of the layer.
179       */
180      DFBResult (*GetLevel)             ( CoreLayer              *layer,
181                                          void                   *driver_data,
182                                          void                   *layer_data,
183                                          int                    *level );
184 
185      /*
186       * Move the layer below or on top of others (z position).
187       */
188      DFBResult (*SetLevel)             ( CoreLayer              *layer,
189                                          void                   *driver_data,
190                                          void                   *layer_data,
191                                          int                     level );
192 
193 
194    /** Configuration **/
195 
196      /*
197       * Adjust brightness, contrast, saturation etc.
198       */
199      DFBResult (*SetColorAdjustment)   ( CoreLayer              *layer,
200                                          void                   *driver_data,
201                                          void                   *layer_data,
202                                          DFBColorAdjustment     *adjustment );
203 
204 
205    /** Region Control **/
206 
207      /*
208       * Check all parameters and return if this region is supported.
209       */
210      DFBResult (*TestRegion)   ( CoreLayer                  *layer,
211                                  void                       *driver_data,
212                                  void                       *layer_data,
213                                  CoreLayerRegionConfig      *config,
214                                  CoreLayerRegionConfigFlags *failed );
215 
216      /*
217       * Add a new region to the layer, but don't program hardware, yet.
218       */
219      DFBResult (*AddRegion)    ( CoreLayer                  *layer,
220                                  void                       *driver_data,
221                                  void                       *layer_data,
222                                  void                       *region_data,
223                                  CoreLayerRegionConfig      *config );
224 
225      /*
226       * Setup hardware, called once after AddRegion() or when parameters
227       * have changed. Surface and palette are only set if updated or new.
228       */
229      DFBResult (*SetRegion)    ( CoreLayer                  *layer,
230                                  void                       *driver_data,
231                                  void                       *layer_data,
232                                  void                       *region_data,
233                                  CoreLayerRegionConfig      *config,
234                                  CoreLayerRegionConfigFlags  updated,
235                                  CoreSurface                *surface,
236                                  CorePalette                *palette,
237                                  CoreSurfaceBufferLock      *lock );
238 
239      /*
240       * Remove a region from the layer.
241       */
242      DFBResult (*RemoveRegion) ( CoreLayer                  *layer,
243                                  void                       *driver_data,
244                                  void                       *layer_data,
245                                  void                       *region_data );
246 
247      /*
248       * Flip the surface of the region.
249       */
250      DFBResult (*FlipRegion)   ( CoreLayer                  *layer,
251                                  void                       *driver_data,
252                                  void                       *layer_data,
253                                  void                       *region_data,
254                                  CoreSurface                *surface,
255                                  DFBSurfaceFlipFlags         flags,
256                                  CoreSurfaceBufferLock      *lock );
257 
258      /*
259       * Indicate updates to the front buffer content.
260       */
261      DFBResult (*UpdateRegion) ( CoreLayer                  *layer,
262                                  void                       *driver_data,
263                                  void                       *layer_data,
264                                  void                       *region_data,
265                                  CoreSurface                *surface,
266                                  const DFBRegion            *update,
267                                  CoreSurfaceBufferLock      *lock );
268 
269      /*
270       * Control hardware deinterlacing.
271       */
272      DFBResult (*SetInputField)( CoreLayer                  *layer,
273                                  void                       *driver_data,
274                                  void                       *layer_data,
275                                  void                       *region_data,
276                                  int                         field );
277 
278 
279    /** Override defaults. Subject to change. **/
280 
281      /*
282       * Allocate the surface of the region.
283       */
284      DFBResult (*AllocateSurface)  ( CoreLayer              *layer,
285                                      void                   *driver_data,
286                                      void                   *layer_data,
287                                      void                   *region_data,
288                                      CoreLayerRegionConfig  *config,
289                                      CoreSurface           **ret_surface );
290 
291      /*
292       * Reallocate the surface of the region.
293       */
294      DFBResult (*ReallocateSurface)( CoreLayer              *layer,
295                                      void                   *driver_data,
296                                      void                   *layer_data,
297                                      void                   *region_data,
298                                      CoreLayerRegionConfig  *config,
299                                      CoreSurface            *surface );
300 
301      /*
302       * Deallocate the surface of the region.
303       */
304      DFBResult (*DeallocateSurface)( CoreLayer              *layer,
305                                      void                   *driver_data,
306                                      void                   *layer_data,
307                                      void                   *region_data,
308                                      CoreSurface            *surface );
309 } DisplayLayerFuncs;
310 
311 
312 /*
313  * Add a layer to a graphics device by pointing to a table
314  * containing driver functions. The supplied driver data
315  * will be passed to these functions.
316  */
317 CoreLayer *dfb_layers_register( CoreScreen              *screen,
318                                 void                    *driver_data,
319                                 const DisplayLayerFuncs *funcs );
320 
321 /*
322  * Replace functions of the primary layer implementation by passing
323  * an alternative driver function table. All non-NULL functions in the new
324  * table replace the functions in the original function table.
325  * The original function table is written to 'primary_funcs' before to allow
326  * drivers to use existing functionality from the original implementation.
327  */
328 CoreLayer *dfb_layers_hook_primary( CoreGraphicsDevice *device,
329                                     void               *driver_data,
330                                     DisplayLayerFuncs  *funcs,
331                                     DisplayLayerFuncs  *primary_funcs,
332                                     void              **primary_driver_data );
333 
334 /*
335  * Replace functions of the primary layer implementation completely by passing
336  * an alternative driver function table.
337  */
338 CoreLayer *dfb_layers_replace_primary( CoreGraphicsDevice *device,
339                                        void               *driver_data,
340                                        DisplayLayerFuncs  *funcs );
341 
342 typedef DFBEnumerationResult (*DisplayLayerCallback) (CoreLayer *layer,
343                                                       void      *ctx);
344 
345 void dfb_layers_enumerate( DisplayLayerCallback  callback,
346                            void                 *ctx );
347 
348 
349 int        dfb_layer_num( void );
350 
351 CoreLayer *dfb_layer_at( DFBDisplayLayerID id );
352 
353 CoreLayer *dfb_layer_at_translated( DFBDisplayLayerID id );
354 
355 
356 void dfb_layer_get_description( const CoreLayer            *layer,
357                                 DFBDisplayLayerDescription *desc );
358 
359 CoreScreen *dfb_layer_screen( const CoreLayer *layer );
360 
361 CardState  *dfb_layer_state( CoreLayer *layer );
362 
363 DFBDisplayLayerID dfb_layer_id( const CoreLayer *layer );
364 
365 DFBDisplayLayerID dfb_layer_id_translated( const CoreLayer *layer );
366 
367 DFBDisplayLayerID dfb_layer_id_translate( DFBDisplayLayerID layer_id );
368 
369 DFBSurfacePixelFormat dfb_primary_layer_pixelformat( void );
370 
371 #endif
372