*
* Contact:
* Kitae Kim <kt920.kim@samsung.com>
+ * SangHo Park <sangho1206.park@samsung.com>
* YeongKyoon Lee <yeongkyoon.lee@samsung.com>
*
* This program is free software; you can redistribute it and/or
*/
#include <png.h>
-#ifdef CONFIG_WEBP
-#include <webp/types.h>
-#include <webp/encode.h>
-#endif
#include "emulator_common.h"
#include "emul_state.h"
+
+#ifdef CONFIG_SDL
+#include "display/maru_sdl.h"
+#endif
+#ifdef CONFIG_USE_SHM
+#include "display/maru_shm.h"
+#endif
+
#include "skin/maruskin_operation.h"
#include "encode_fb.h"
+
+#if defined(CONFIG_LINUX) && defined(ENCODE_DEBUG)
+#include <time.h>
+#endif
+#ifdef CONFIG_WEBP
+#include <webp/types.h>
+#include <webp/encode.h>
+#endif
+
#include "util/new_debug_ch.h"
DECLARE_DEBUG_CHANNEL(app_tethering);
*/
int bit_depth = 8;
struct encode_mem *container = NULL;
+ uint8_t *surface = NULL;
+ uint32_t surface_size = 0;
png_structp png_ptr = NULL;
png_infop info_ptr = NULL;
png_bytepp row_pointers = NULL;
- Framebuffer *surface = NULL;
-
- surface = request_screenshot();
- if (!surface) {
- LOG_SEVERE("failed to get framebuffer\n");
- return NULL;
- }
-
width = get_emul_resolution_width();
height = get_emul_resolution_height();
LOG_TRACE("width %d, height %d, stride %d, raw image %d\n",
width, height, image_stride, (image_stride * height));
+ surface_size = width * height * 4;
+
+ surface = g_malloc0(surface_size);
+ if (!surface) {
+ LOG_SEVERE("failed to allocate framebuffer\n");
+ return NULL;
+ }
+
+ if (!maru_extract_framebuffer(surface)) {
+ LOG_SEVERE("failed to extract framebuffer\n");
+ g_free(surface);
+ return NULL;
+ }
+
LOG_TRACE("png_create_write_struct\n");
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr) {
LOG_SEVERE("png_create_write_struct failure\n");
- g_free(surface->data);
g_free(surface);
return NULL;
}
info_ptr = png_create_info_struct(png_ptr);
if (!png_ptr) {
LOG_SEVERE("png_create_info_struct failure\n");
- g_free(surface->data);
g_free(surface);
png_destroy_write_struct(&png_ptr, &info_ptr);
return NULL;
LOG_TRACE("try png_jmpbuf\n");
if (setjmp(png_jmpbuf(png_ptr))) {
LOG_SEVERE("png_jmpbuf failure\n");
- g_free(surface->data);
g_free(surface);
png_destroy_write_struct(&png_ptr, &info_ptr);
png_destroy_info_struct(png_ptr, &info_ptr);
container = g_malloc(sizeof(struct encode_mem));
if (!container) {
LOG_SEVERE("failed to allocate encode_mem\n");
- g_free(surface->data);
g_free(surface);
png_destroy_write_struct(&png_ptr, &info_ptr);
png_destroy_info_struct(png_ptr, &info_ptr);
row_pointers = png_malloc(png_ptr, sizeof(png_bytep) * height);
if (row_pointers == NULL) {
LOG_SEVERE("failed to allocate png memory\n");
- g_free(surface->data);
g_free(surface);
png_destroy_write_struct(&png_ptr, &info_ptr);
png_destroy_info_struct(png_ptr, &info_ptr);
}
for (row_index = 0; row_index < height; row_index++) {
- row_pointers[row_index] = surface->data + (row_index * image_stride);
+ row_pointers[row_index] = surface + (row_index * image_stride);
}
LOG_TRACE("png_write_image\n");
LOG_TRACE("png_write_end\n");
png_write_end(png_ptr, info_ptr);
- g_free(surface->data);
g_free(surface);
LOG_TRACE("png image size %d\n", container->length);
static void *encode_webp(void)
{
int width = 0, height = 0, image_stride = 0;
- // float quality = 0;
size_t ret = 0;
struct encode_mem *container = NULL;
- Framebuffer *surface = NULL;
+ uint8_t *surface = NULL;
+ uint32_t surface_size = 0;
container = g_malloc(sizeof(struct encode_mem));
if (!container) {
container->buffer = NULL;
container->length = 0;
- surface = request_screenshot();
- if (!surface) {
- LOG_SEVERE("failed to get framebuffer\n");
- g_free(container);
- return NULL;
- }
-
width = get_emul_resolution_width();
height = get_emul_resolution_height();
LOG_TRACE("width %d, height %d, stride %d, raw image %d\n",
width, height, image_stride, (image_stride * height));
- ret = WebPEncodeLosslessBGRA((const uint8_t *)surface->data, width,
+ surface_size = width * height * 4;
+
+ surface = g_malloc0(surface_size);
+ if (!surface) {
+ LOG_SEVERE("failed to allocate framebuffer\n");
+ return NULL;
+ }
+
+ if (!maru_extract_framebuffer(surface)) {
+ LOG_SEVERE("failed to extract framebuffer\n");
+ g_free(surface);
+ return NULL;
+ }
+
+ container = g_malloc(sizeof(struct encode_mem));
+ if (!container) {
+ LOG_SEVERE("failed to allocate encode_mem\n");
+ g_free(surface);
+ return NULL;
+ }
+
+ container->buffer = NULL;
+ container->length = 0;
+
+ ret = WebPEncodeLosslessBGRA((const uint8_t *)surface, width,
height, image_stride, &container->buffer);
LOG_TRACE("lossless encode framebuffer via webp. result %zu\n", ret);
container->length = (int)ret;
- g_free(surface->data);
g_free(surface);
return container;
#include "emul_state.h"
#include "common.h"
#include "touch.h"
+#include "encode_fb.h"
#include "genmsg/tethering.pb-c.h"
#include "ecs/ecs_tethering.h"
#include "util/new_debug_ch.h"
// static bool is_touch_event;
static int touch_device_status;
-#ifndef DISPLAY_FEATURE
-#include "encode_fb.h"
-
-enum {
- ENCODE_WEBP = 0,
- ENCODE_PNG,
-};
-
// static void set_touch_event_status(bool status);
static bool send_display_image_data(void);
-#endif
-
#if 0
touch_state *init_touch_state(void)
}
#endif
+static bool is_display_dirty = false;
+
+void set_display_dirty(bool dirty)
+{
+ LOG_TRACE("qemu display update: %d\n", is_display_dirty);
+ is_display_dirty = dirty;
+}
+
// bool msgproc_tethering_touch_msg(Tethering__TouchMsg *msg)
bool msgproc_tethering_touch_msg(void *message)
{
break;
case TETHERING__TOUCH_MSG__TYPE__DISPLAY_MSG:
- send_display_image_data();
+ if (is_display_dirty) {
+ send_display_image_data();
+ is_display_dirty = false;
+ }
break;
#if 0
send_tethering_touch_status_ecp();
}
+static void dump_display_image_data(struct encode_mem *image)
+{
+#ifdef IMAGE_DUMP
+ FILE *fp = NULL;
+
+ fp = fopen("display_image_dump.png", "wb");
+ if (fp != NULL) {
+ fwrite(image->buffer, 1, image->length, fp);
+ fclose(fp);
+ }
+#endif
+}
+
static bool send_display_image_data(void)
{
bool ret = false;
LOG_TRACE("enter: %s\n", __func__);
- image = (struct encode_mem *)encode_framebuffer(ENCODE_WEBP);
+ image = (struct encode_mem *)encode_framebuffer(ENCODE_PNG);
if (!image) {
LOG_SEVERE("failed to encode framebuffer\n");
return false;
}
+ dump_display_image_data(image);
+
LOG_TRACE("image data size %d\n", image->length);
display.has_imagedata = true;
display.imagedata.len = image->length;
display.imagedata.data = image->buffer;
-#ifdef IMAGE_DUMP
- {
- FILE *fp = NULL;
-
- fp = fopen("test2.png", "wb");
- if (fp != NULL) {
- fwrite(image->buffer, 1, image->length, fp);
- fclose(fp);
- }
- }
-#endif
-
touch.type = TETHERING__TOUCH_MSG__TYPE__DISPLAY_MSG;
touch.display = &display;
- // ret = build_display_msg(&display);
ret = build_touch_msg(&touch);
LOG_TRACE("send display message: %d\n", ret);