PageRenderTime 73ms CodeModel.GetById 40ms app.highlight 16ms RepoModel.GetById 14ms app.codeStats 0ms

/src/backend/directfb/ftk_display_dfb.c

http://ftk.googlecode.com/
C | 219 lines | 150 code | 40 blank | 29 comment | 19 complexity | a2fc588ac1a410c255742f6c2301f3cc MD5 | raw file
  1/*
  2 * File: ftk_display_dfb.h    
  3 * Author:  Li XianJing <xianjimli@hotmail.com>
  4 * Brief:   display directfb implementation.
  5 *
  6 * Copyright (c) 2009 - 2010  Li XianJing <xianjimli@hotmail.com>
  7 *
  8 * Licensed under the Academic Free License version 2.1
  9 *
 10 * This program is free software; you can redistribute it and/or modify
 11 * it under the terms of the GNU General Public License as published by
 12 * the Free Software Foundation; either version 2 of the License, or
 13 * (at your option) any later version.
 14 *
 15 * This program is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 18 * GNU General Public License for more details.
 19 *
 20 * You should have received a copy of the GNU General Public License
 21 * along with this program; if not, write to the Free Software
 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 23 */
 24
 25/*
 26 * History:
 27 * ================================================================
 28 * 2009-11-28 Li XianJing <xianjimli@hotmail.com> created
 29 *
 30 */
 31
 32#include <directfb.h>
 33#include "ftk_globals.h"
 34#include "ftk_source_dfb.h"
 35#include "ftk_display_dfb.h"
 36
 37#define DFBCHECK(x) x
 38
 39typedef struct _PrivInfo
 40{
 41	int width;
 42	int height;
 43	IDirectFB* dfb;
 44	IDirectFBWindow* window;
 45	IDirectFBSurface* window_surface;
 46	IDirectFBEventBuffer* event_buffer;
 47	IDirectFBDisplayLayer* layer;
 48}PrivInfo;
 49
 50static Ret ftk_display_dfb_update(FtkDisplay* thiz, FtkBitmap* bitmap, FtkRect* rect, int xoffset, int yoffset)
 51{
 52	Ret ret = RET_OK;
 53	DECL_PRIV(thiz, priv);
 54	DFBRectangle r = {0};
 55	int display_width  = ftk_display_width(thiz);
 56	int display_height = ftk_display_height(thiz);
 57	
 58	IDirectFBSurface* surface = (IDirectFBSurface*)ftk_bitmap_get_native(bitmap);
 59
 60	r.w = display_width;
 61	r.h = display_height;
 62	
 63	priv->window_surface->Blit(priv->window_surface, surface, &r, 0, 0);
 64	priv->window_surface->Flip(priv->window_surface, NULL, 0);
 65
 66	return ret;
 67}
 68
 69static int ftk_display_dfb_width(FtkDisplay* thiz)
 70{
 71	DECL_PRIV(thiz, priv);
 72	return_val_if_fail(priv != NULL, 0);	
 73
 74	return priv->width;
 75}
 76
 77static int ftk_display_dfb_height(FtkDisplay* thiz)
 78{
 79	DECL_PRIV(thiz, priv);
 80	return_val_if_fail(priv != NULL, 0);	
 81
 82	return priv->height;
 83}
 84
 85static Ret ftk_display_dfb_snap(FtkDisplay* thiz, FtkRect* r, FtkBitmap* bitmap)
 86{
 87	int pitch = 0;
 88	void *data = NULL;
 89	FtkRect rect = {0};
 90	DECL_PRIV(thiz, priv);
 91	int w = ftk_display_width(thiz);
 92	int h = ftk_display_height(thiz);
 93	int bw = ftk_bitmap_width(bitmap);
 94	int bh = ftk_bitmap_height(bitmap);
 95
 96	IDirectFBSurface* surface = priv->window_surface;
 97	surface->Lock(surface, DSLF_READ | DSLF_WRITE, &data, &pitch);
 98	
 99	rect.x = r->x;
100	rect.y = r->y;
101	rect.width = FTK_MIN(bw, r->width);
102	rect.height = FTK_MIN(bh, r->height);
103	ftk_bitmap_copy_from_data_bgra32(bitmap, data, w, h, &rect);
104
105	surface->Unlock(surface);
106
107	return RET_OK;
108}
109
110static void ftk_display_dfb_destroy(FtkDisplay* thiz)
111{
112	if(thiz != NULL)
113	{
114		DECL_PRIV(thiz, priv);
115		
116		if(priv->event_buffer != NULL)
117		{
118			priv->event_buffer->Release(priv->event_buffer);
119			priv->event_buffer = NULL;
120		}
121
122		if(priv->window_surface != NULL)
123		{
124			priv->window_surface->Release(priv->window_surface);
125			priv->window_surface = NULL;
126		}
127
128		if(priv->window != NULL)
129		{
130			priv->window->Release(priv->window);
131			priv->window= NULL;
132		}
133		
134		if(priv->layer != NULL)
135		{
136			priv->layer->Release(priv->layer);
137			priv->layer= NULL;
138		}
139		
140		if(priv->dfb != NULL)
141		{
142			priv->dfb->Release( priv->dfb );
143			priv->dfb = NULL;
144		}
145
146		FTK_ZFREE(thiz, sizeof(FtkDisplay) + sizeof(PrivInfo));
147	}
148
149	return;
150}
151
152static Ret ftk_display_dfb_init(FtkDisplay* thiz, IDirectFB* dfb)
153{	
154	DECL_PRIV(thiz, priv);
155	int display_height = 0;
156	int display_width  = 0;
157	FtkSource* source = NULL;
158	DFBWindowDescription win_desc;
159	IDirectFBWindow* window = NULL;
160	IDirectFBDisplayLayer* layer = NULL;
161	IDirectFBSurface* window_surface = NULL;
162	IDirectFBEventBuffer* event_buffer = NULL;
163	DFBDisplayLayerConfig         layer_config;
164
165	DFBCHECK(dfb->GetDisplayLayer( dfb, DLID_PRIMARY, &layer ));
166	layer->SetCooperativeLevel( layer, DLSCL_ADMINISTRATIVE );
167	layer->GetConfiguration( layer, &layer_config );
168
169	display_width = layer_config.width;
170	display_height = layer_config.height;
171
172	win_desc.posx   = 0;
173	win_desc.posy   = 0;
174	win_desc.width  = display_width;
175	win_desc.height = display_height;
176	win_desc.flags  = ( DWDESC_POSX | DWDESC_POSY | DWDESC_WIDTH | DWDESC_HEIGHT);
177
178	DFBCHECK(layer->CreateWindow( layer, &win_desc, &window ));
179    window->GetSurface( window, &window_surface );
180	window->CreateEventBuffer( window, &event_buffer );
181
182	priv->dfb     = dfb;
183	priv->layer   = layer;
184	priv->width   = display_width;
185	priv->height  = display_height;
186	priv->window = window;
187	priv->event_buffer = event_buffer;
188	priv->window_surface = window_surface;
189
190	window->SetOpacity( window, 0xFF );
191	if((source = ftk_source_dfb_create(dfb, event_buffer)) != NULL)
192	{
193		ftk_sources_manager_add(ftk_default_sources_manager(), source);
194	}
195
196	return RET_OK;
197}
198
199FtkDisplay* ftk_display_dfb_create(IDirectFB* dfb)
200{
201	FtkDisplay* thiz = NULL;
202	return_val_if_fail(dfb != NULL, NULL);
203
204	thiz = FTK_ZALLOC(sizeof(FtkDisplay)+sizeof(PrivInfo));
205	if(thiz != NULL)
206	{
207		thiz->update  = ftk_display_dfb_update;
208		thiz->width   = ftk_display_dfb_width;
209		thiz->height  = ftk_display_dfb_height;
210		thiz->snap    = ftk_display_dfb_snap;
211		thiz->destroy = ftk_display_dfb_destroy;
212
213		ftk_display_dfb_init(thiz, dfb);
214	}
215	
216	return thiz;
217}
218
219