2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <unistd.h> /* access */
22 #include <Ecore_Evas.h>
27 #include "buffer_handler.h"
35 struct buffer_info *buffer;
38 HAPI int fb_init(void)
43 HAPI int fb_fini(void)
48 static void *alloc_fb(void *data, int size)
50 struct fb_info *info = data;
52 DbgPrint("FB size: %d\n", size);
54 if (buffer_handler_load(info->buffer) < 0) {
55 ErrPrint("Failed to load buffer handler\n");
59 return buffer_handler_fb(info->buffer);
62 static void free_fb(void *data, void *ptr)
64 struct fb_info *info = data;
67 ErrPrint("Buffer is not valid (maybe already released)\n");
71 if (buffer_handler_fb(info->buffer) != ptr)
72 ErrPrint("Buffer pointer is not matched\n");
74 (void)buffer_handler_unload(info->buffer);
77 HAPI struct fb_info *fb_create(struct inst_info *inst, int w, int h, enum buffer_type type)
81 info = calloc(1, sizeof(*info));
83 ErrPrint("Heap: %s\n", strerror(errno));
87 info->buffer = buffer_handler_create(inst, type, w, h, sizeof(int));
89 ErrPrint("Failed to create a buffer\n");
98 static void render_pre_cb(void *data, Evas *e, void *event_info)
100 fb_pixmap_render_pre(data);
103 static void render_post_cb(void *data, Evas *e, void *event_info)
105 fb_pixmap_render_post(data);
108 HAPI int fb_create_buffer(struct fb_info *info)
113 buffer_handler_get_size(info->buffer, &ow, &oh);
114 DbgPrint("Buffer handler size: %dx%d\n", ow, oh);
115 if (ow == 0 && oh == 0) {
116 DbgPrint("ZERO Size FB accessed\n");
124 ecore_evas_geometry_get(info->ee, NULL, NULL, &w, &h);
125 if (w != ow || h != oh) {
126 ErrPrint("EE exists, size mismatched requested (%dx%d) but (%dx%d)\n", ow, oh, w, h);
127 ecore_evas_resize(info->ee, ow, oh);
133 info->ee = ecore_evas_buffer_allocfunc_new(ow, oh, alloc_fb, free_fb, info);
135 ErrPrint("Failed to create a buffer\n");
139 if (buffer_handler_type(info->buffer) == BUFFER_TYPE_PIXMAP) {
141 e = ecore_evas_get(info->ee);
143 evas_event_callback_add(e, EVAS_CALLBACK_RENDER_PRE, render_pre_cb, info);
144 evas_event_callback_add(e, EVAS_CALLBACK_RENDER_POST, render_post_cb, info);
148 * ecore_evas_alpha_set tries to access the canvas buffer.
149 * Without any render_pre/render_post callback.
151 fb_pixmap_render_pre(info);
152 ecore_evas_alpha_set(info->ee, EINA_TRUE);
153 fb_pixmap_render_post(info);
156 ecore_evas_alpha_set(info->ee, EINA_TRUE);
162 HAPI int fb_destroy_buffer(struct fb_info *info)
165 ErrPrint("EE is not exists (Maybe ZERO byte ee?)\n");
169 if (buffer_handler_type(info->buffer) == BUFFER_TYPE_PIXMAP) {
171 e = ecore_evas_get(info->ee);
173 evas_event_callback_del(e, EVAS_CALLBACK_RENDER_POST, render_post_cb);
174 evas_event_callback_del(e, EVAS_CALLBACK_RENDER_PRE, render_pre_cb);
178 ecore_evas_free(info->ee);
183 HAPI int fb_destroy(struct fb_info *info)
185 fb_destroy_buffer(info);
190 HAPI Ecore_Evas * const fb_canvas(struct fb_info *info)
195 HAPI const char *fb_id(struct fb_info *fb)
197 return fb ? buffer_handler_id(fb->buffer) : "";
200 HAPI int fb_resize(struct fb_info *info, int w, int h)
202 buffer_handler_update_size(info->buffer, w, h);
205 ecore_evas_resize(info->ee, w, h);
206 } else if (!info->ee && !info->buffer) {
208 * This object has no size at the initial time.
209 * Create a new buffer and use it
216 HAPI int fb_get_size(struct fb_info *info, int *w, int *h)
218 return buffer_handler_get_size(info->buffer, w, h);
221 HAPI void fb_sync(struct fb_info *info)
223 buffer_handler_flush(info->buffer);
226 HAPI void *fb_pixmap_render_pre(struct fb_info *info)
229 canvas = buffer_handler_pixmap_acquire_buffer(info->buffer);
233 HAPI int fb_pixmap_render_post(struct fb_info *info)
239 * info->buffer == struct buffer_info
241 canvas = buffer_handler_pixmap_buffer(info->buffer);
242 return buffer_handler_pixmap_release_buffer(canvas);