1 /*
2    (c) Copyright 2001-2011  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 #include <config.h>
30 
31 #include <core/CoreDFB.h>
32 #include <core/CoreGraphicsState.h>
33 
34 #include <media/ImageProvider_includes.h>
35 
36 #include <directfb.h>
37 
38 #include <direct/debug.h>
39 #include <direct/messages.h>
40 
41 #include <fusion/conf.h>
42 
43 #include <core/core.h>
44 
45 #include <media/idirectfbdatabuffer_client.h>
46 
47 D_DEBUG_DOMAIN( DirectFB_CoreDFB, "DirectFB/Core", "DirectFB Core" );
48 
49 /*********************************************************************************************************************/
50 
51 
52 DFBResult
ICore_Real__Register(CoreDFB * obj,u32 slave_call)53 ICore_Real__Register( CoreDFB                  *obj,
54                       u32                       slave_call
55 )
56 {
57     D_DEBUG_AT( DirectFB_CoreDFB, "%s()\n", __FUNCTION__ );
58 
59     D_MAGIC_ASSERT( obj, CoreDFB );
60 
61     return Core_Resource_AddIdentity( Core_GetIdentity(), slave_call );
62 }
63 
64 DFBResult
ICore_Real__CreateSurface(CoreDFB * obj,const CoreSurfaceConfig * config,CoreSurfaceTypeFlags type,u64 resource_id,CorePalette * palette,CoreSurface ** ret_surface)65 ICore_Real__CreateSurface( CoreDFB                  *obj,
66                            const CoreSurfaceConfig  *config,
67                            CoreSurfaceTypeFlags      type,
68                            u64                       resource_id,
69                            CorePalette              *palette,
70                            CoreSurface             **ret_surface )
71 {
72      DFBResult    ret;
73      CoreSurface *surface;
74 
75      D_DEBUG_AT( DirectFB_CoreDFB, "%s( %p )\n", __FUNCTION__, core_dfb );
76 
77      D_MAGIC_ASSERT( obj, CoreDFB );
78      D_ASSERT( config != NULL );
79      D_ASSERT( ret_surface != NULL );
80 
81      ret = Core_Resource_CheckSurface( config, type, resource_id, palette );
82      if (ret)
83           return ret;
84 
85      ret = dfb_surface_create( obj, config, type, resource_id, palette, &surface );
86      if (ret)
87           return ret;
88 
89      Core_Resource_AddSurface( surface );
90 
91      *ret_surface = surface;
92 
93      return DFB_OK;
94 }
95 
96 DFBResult
ICore_Real__CreatePalette(CoreDFB * obj,u32 size,CorePalette ** ret_palette)97 ICore_Real__CreatePalette( CoreDFB      *obj,
98                            u32           size,
99                            CorePalette **ret_palette )
100 {
101      D_DEBUG_AT( DirectFB_CoreDFB, "%s()\n", __FUNCTION__ );
102 
103      D_MAGIC_ASSERT( obj, CoreDFB );
104      D_ASSERT( ret_palette != NULL );
105 
106      return dfb_palette_create( obj, size, ret_palette );
107 }
108 
109 DFBResult
ICore_Real__CreateState(CoreDFB * obj,CoreGraphicsState ** ret_state)110 ICore_Real__CreateState( CoreDFB                              *obj,
111                     CoreGraphicsState                        **ret_state
112 )
113 {
114     D_DEBUG_AT( DirectFB_CoreDFB, "%s()\n", __FUNCTION__ );
115 
116     D_MAGIC_ASSERT( obj, CoreDFB );
117     D_ASSERT( ret_state != NULL );
118 
119     return dfb_graphics_state_create( core_dfb, ret_state );
120 }
121 
122 DFBResult
ICore_Real__WaitIdle(CoreDFB * obj)123 ICore_Real__WaitIdle( CoreDFB                                 *obj
124 
125 )
126 {
127     D_DEBUG_AT( DirectFB_CoreDFB, "%s()\n", __FUNCTION__ );
128 
129     D_MAGIC_ASSERT( obj, CoreDFB );
130 
131     return dfb_gfxcard_sync();
132 }
133 
134 DFBResult
ICore_Real__CreateImageProvider(CoreDFB * obj,u32 buffer_call,u32 * ret_call)135 ICore_Real__CreateImageProvider( CoreDFB                                 *obj,
136                     u32                                        buffer_call,
137                     u32                                       *ret_call
138 )
139 {
140      DFBResult               ret;
141      IDirectFBDataBuffer    *buffer;
142      IDirectFBImageProvider *provider;
143      ImageProviderDispatch  *dispatch;
144 
145      D_DEBUG_AT( DirectFB_CoreDFB, "ICore_Real::%s()\n", __FUNCTION__ );
146 
147      D_MAGIC_ASSERT( obj, CoreDFB );
148      D_ASSERT( ret_call != NULL );
149 
150      DIRECT_ALLOCATE_INTERFACE( buffer, IDirectFBDataBuffer );
151      if (!buffer)
152           return (DFBResult) D_OOM();
153 
154      /* Construct data buffer client */
155      ret = IDirectFBDataBuffer_Client_Construct( buffer, core_dfb, buffer_call );
156      if (ret)
157           return ret;
158 
159      /* Create image provider */
160      ret = buffer->CreateImageProvider( buffer, &provider );
161      if (ret) {
162           buffer->Release( buffer );
163           return ret;
164      }
165 
166      /* Create dispatch object */
167      ret = ImageProviderDispatch_Create( buffer, provider, &dispatch );
168      if (ret) {
169           provider->Release( provider );
170           buffer->Release( buffer );
171           return ret;
172      }
173 
174      *ret_call = dispatch->call.call_id;
175 
176      return DFB_OK;
177 }
178 
179 
180