#include <dlog.h>
#include <widget_errno.h> /* For error code */
+#include <widget_service.h>
#include <widget_buffer.h>
#include "debug.h"
int errno;
-struct fb_info {
- char *id;
- int w;
- int h;
- int bufsz;
- void *buffer;
-
- int pixels;
- int handle;
-};
-
static struct {
} s_info = {
};
int fb_init(void *disp)
{
- return 0;
+ return WIDGET_ERROR_NONE;
}
int fb_fini(void)
{
- return 0;
+ return WIDGET_ERROR_NONE;
}
static inline void update_fb_size(struct fb_info *info)
info->bufsz = info->w * info->h * info->pixels;
}
-static inline int sync_for_file(struct fb_info *info)
+static inline int sync_for_file(struct fb_info *info, int x, int y, int w, int h)
{
int fd;
- struct buffer *buffer;
+ widget_fb_t buffer;
buffer = info->buffer;
return WIDGET_ERROR_NONE;
}
- if (buffer->state != CREATED) {
+ if (buffer->state != WIDGET_FB_STATE_CREATED) {
ErrPrint("Invalid state of a FB\n");
return WIDGET_ERROR_INVALID_PARAMETER;
}
- if (buffer->type != WIDGET_BUFFER_TYPE_FILE) {
+ if (buffer->type != WIDGET_FB_TYPE_FILE) {
ErrPrint("Invalid buffer\n");
return WIDGET_ERROR_NONE;
}
return WIDGET_ERROR_NONE;
}
- if (read(fd, buffer->data, info->bufsz) != info->bufsz) {
- ErrPrint("read: %s\n", strerror(errno));
- if (close(fd) < 0) {
- ErrPrint("close: %s\n", strerror(errno));
+ if (x != 0 || y != 0 || info->w != w || info->h != h) {
+ int iy;
+ register int index;
+ register int width;
+
+ for (iy = y; iy < h; iy++) {
+ index = iy * info->w + x;
+ width = w * info->pixels;
+
+ if (lseek(fd, index * info->pixels, SEEK_SET) != index * info->pixels) {
+ ErrPrint("lseek: %s\n", strerror(errno));
+ if (close(fd) < 0) {
+ ErrPrint("close: %s\n", strerror(errno));
+ }
+ /**
+ * @note
+ * But return ZERO, even if we couldn't get a buffer file,
+ * the viewer can draw empty screen.
+ *
+ * and then update it after it gots update events
+ */
+ return WIDGET_ERROR_NONE;
+ }
+
+ if (read(fd, ((unsigned int *)buffer->data) + index, width) != width) {
+ if (close(fd) < 0) {
+ ErrPrint("close: %s\n", strerror(errno));
+ }
+ /**
+ * @note
+ * But return ZERO, even if we couldn't get a buffer file,
+ * the viewer can draw empty screen.
+ *
+ * and then update it after it gots update events
+ */
+ return WIDGET_ERROR_NONE;
+ }
}
+ } else {
+ if (read(fd, buffer->data, info->bufsz) != info->bufsz) {
+ ErrPrint("read: %s\n", strerror(errno));
+ if (close(fd) < 0) {
+ ErrPrint("close: %s\n", strerror(errno));
+ }
- /*!
- * \note
- * But return ZERO, even if we couldn't get a buffer file,
- * the viewer can draw empty screen.
- *
- * and then update it after it gots update events
- */
- return WIDGET_ERROR_NONE;
+ /*!
+ * \note
+ * But return ZERO, even if we couldn't get a buffer file,
+ * the viewer can draw empty screen.
+ *
+ * and then update it after it gots update events
+ */
+ return WIDGET_ERROR_NONE;
+ }
}
if (close(fd) < 0) {
}
if (!strncasecmp(info->id, SCHEMA_FILE, strlen(SCHEMA_FILE))) {
- return sync_for_file(info);
+ return sync_for_file(info, x, y, w, h);
} else if (!strncasecmp(info->id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) {
+ /**
+ * @note
+ */
} else if (!strncasecmp(info->id, SCHEMA_SHM, strlen(SCHEMA_SHM))) {
/* No need to do sync */
return WIDGET_ERROR_NONE;
}
if (info->buffer) {
- struct buffer *buffer;
+ widget_fb_t buffer;
buffer = info->buffer;
buffer->info = NULL;
void *fb_acquire_buffer(struct fb_info *info)
{
- struct buffer *buffer;
+ widget_fb_t buffer;
if (!info) {
ErrPrint("info == NIL\n");
return NULL;
}
- buffer->type = WIDGET_BUFFER_TYPE_FILE;
+ buffer->type = WIDGET_FB_TYPE_FILE;
buffer->refcnt = 0;
- buffer->state = CREATED;
+ buffer->state = WIDGET_FB_STATE_CREATED;
buffer->info = info;
info->buffer = buffer;
- sync_for_file(info);
+ sync_for_file(info, 0, 0, info->w, info->h);
} else if (!strncasecmp(info->id, SCHEMA_SHM, strlen(SCHEMA_SHM))) {
buffer = shmat(info->handle, NULL, 0);
if (buffer == (void *)-1) {
buffer = info->buffer;
switch (buffer->type) {
- case WIDGET_BUFFER_TYPE_FILE:
+ case WIDGET_FB_TYPE_FILE:
buffer->refcnt++;
break;
case WIDGET_BUFFER_TYPE_PIXMAP:
int fb_release_buffer(void *data)
{
- struct buffer *buffer;
+ widget_fb_t buffer;
if (!data) {
ErrPrint("buffer data == NIL\n");
return WIDGET_ERROR_INVALID_PARAMETER;
}
- buffer = container_of(data, struct buffer, data);
+ buffer = container_of(data, struct widget_fb, data);
- if (buffer->state != CREATED) {
+ if (buffer->state != WIDGET_FB_STATE_CREATED) {
ErrPrint("Invalid handle\n");
set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
return WIDGET_ERROR_INVALID_PARAMETER;
info = buffer->info;
buffer->state = WIDGET_FB_STATE_DESTROYED;
- free(buffer);
if (info && info->buffer == buffer) {
info->buffer = NULL;
}
+
+ free(buffer);
}
break;
case WIDGET_BUFFER_TYPE_PIXMAP:
int fb_refcnt(void *data)
{
- struct buffer *buffer;
+ widget_fb_t buffer;
struct shmid_ds buf;
int ret;
buffer = container_of(data, struct buffer, data);
- if (buffer->state != CREATED) {
+ if (buffer->state != WIDGET_FB_STATE_CREATED) {
ErrPrint("Invalid handle\n");
set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
return WIDGET_ERROR_INVALID_PARAMETER;
}
switch (buffer->type) {
- case WIDGET_BUFFER_TYPE_SHM:
+ case WIDGET_FB_TYPE_SHM:
if (shmctl(buffer->refcnt, IPC_STAT, &buf) < 0) {
ErrPrint("Error: %s\n", strerror(errno));
set_last_result(WIDGET_ERROR_FAULT);
ret = buf.shm_nattch;
break;
- case WIDGET_BUFFER_TYPE_FILE:
+ case WIDGET_FB_TYPE_FILE:
ret = buffer->refcnt;
break;
case WIDGET_BUFFER_TYPE_PIXMAP:
int fb_type(struct fb_info *info)
{
- struct buffer *buffer;
+ widget_fb_t buffer;
if (!info) {
return WIDGET_BUFFER_TYPE_ERROR;
buffer = info->buffer;
if (!buffer) {
- int type = WIDGET_BUFFER_TYPE_ERROR;
+ int type = WIDGET_FB_TYPE_ERROR;
/*!
* \note
* Try to get this from SCHEMA