diff options
-rw-r--r-- | android/console.c | 8 | ||||
-rw-r--r-- | android/display-core.c | 5 | ||||
-rw-r--r-- | android/display-core.h | 7 | ||||
-rw-r--r-- | android/framebuffer-common.h | 3 | ||||
-rw-r--r-- | android/framebuffer-core.c | 18 | ||||
-rw-r--r-- | android/framebuffer-core.h | 12 | ||||
-rw-r--r-- | android/framebuffer-ui.c | 37 |
7 files changed, 76 insertions, 14 deletions
diff --git a/android/console.c b/android/console.c index 398218a..a89d0e1 100644 --- a/android/console.c +++ b/android/console.c @@ -2518,10 +2518,14 @@ do_create_framebuffer_service( ControlClient client, char* args ) return -1; } - core_fb = corefb_create(client->sock, protocol); + core_fb = corefb_create(client->sock, protocol, coredisplay_get_framebuffer()); if (!coredisplay_attach_fb_service(core_fb)) { + char reply_buf[4096]; framebuffer_client = client; - control_write( client, "OK\r\n"); + // Reply "OK" with the framebuffer's bits per pixel + snprintf(reply_buf, sizeof(reply_buf), "OK: -bitsperpixel=%d\r\n", + corefb_get_bits_per_pixel(core_fb)); + control_write( client, reply_buf); } else { control_write( client, "KO\r\n" ); control_client_destroy(client); diff --git a/android/display-core.c b/android/display-core.c index 70e7b14..1efb4a2 100644 --- a/android/display-core.c +++ b/android/display-core.c @@ -117,3 +117,8 @@ coredisplay_detach_fb_service(void) return ret; } +QFrameBuffer* +coredisplay_get_framebuffer(void) +{ + return core_display.fb; +} diff --git a/android/display-core.h b/android/display-core.h index 02301c5..4e1d07f 100644 --- a/android/display-core.h +++ b/android/display-core.h @@ -49,4 +49,11 @@ extern int coredisplay_attach_fb_service(CoreFramebuffer* core_fb); */ extern CoreFramebuffer* coredisplay_detach_fb_service(void); +/* + * Get framebuffer descriptor for core display. + * Return: + * Framebuffer descriptor for core display. + */ +extern QFrameBuffer* coredisplay_get_framebuffer(void); + #endif /* _ANDROID_DISPLAY_CORE_H */ diff --git a/android/framebuffer-common.h b/android/framebuffer-common.h index 7ca654c..95f65b6 100644 --- a/android/framebuffer-common.h +++ b/android/framebuffer-common.h @@ -27,9 +27,6 @@ typedef struct FBUpdateMessage { uint16_t w; uint16_t h; - /* Number of bits used to encode a single pixel. */ - uint8_t bits_per_pixel; - /* Contains updating rectangle copied over from the framebuffer's pixels. */ uint8_t rect[0]; } FBUpdateMessage; diff --git a/android/framebuffer-core.c b/android/framebuffer-core.c index a473415..62e979a 100644 --- a/android/framebuffer-core.c +++ b/android/framebuffer-core.c @@ -28,10 +28,13 @@ /* Core framebuffer descriptor. */ struct CoreFramebuffer { /* Writer used to send FB update notification messages. */ - AsyncWriter fb_update_writer; + AsyncWriter fb_update_writer; /* I/O associated with this descriptor. */ - LoopIo io; + LoopIo io; + + /* Framebuffer used for this service. */ + QFrameBuffer* fb; /* Looper used to communicate framebuffer updates. */ Looper* looper; @@ -116,7 +119,6 @@ fbupdatenotify_create(CoreFramebuffer* core_fb, const QFrameBuffer* fb, ret->message.y = y; ret->message.w = w; ret->message.h = h; - ret->message.bits_per_pixel = fb->bits_per_pixel; _copy_fb_rect(ret->message.rect, fb, x, y, w, h); return ret; } @@ -182,7 +184,7 @@ corefb_io_func(void* opaque, int fd, unsigned events) } CoreFramebuffer* -corefb_create(int sock, const char* protocol) +corefb_create(int sock, const char* protocol, QFrameBuffer* fb) { // At this point we're implementing the -raw protocol only. CoreFramebuffer* ret; @@ -190,6 +192,7 @@ corefb_create(int sock, const char* protocol) ret->sock = sock; ret->looper = looper_newCore(); loopIo_init(&ret->io, ret->looper, sock, corefb_io_func, ret); + ret->fb = fb; ret->fb_update_head = NULL; ret->fb_update_tail = NULL; return ret; @@ -256,3 +259,10 @@ corefb_update(CoreFramebuffer* core_fb, struct DisplayState* ds, return; } } + +int +corefb_get_bits_per_pixel(CoreFramebuffer* core_fb) +{ + return (core_fb != NULL && core_fb->fb != NULL) ? + core_fb->fb->bits_per_pixel : -1; +} diff --git a/android/framebuffer-core.h b/android/framebuffer-core.h index 6738d0e..fd4af52 100644 --- a/android/framebuffer-core.h +++ b/android/framebuffer-core.h @@ -29,10 +29,11 @@ typedef struct CoreFramebuffer CoreFramebuffer; * supported values ar: * -raw Transfers the updating rectangle buffer over the socket. * -shared Used a shared memory to transfer the updating rectangle buffer. + * fb - Framebuffer descriptor for this service. * Return: * Framebuffer service descriptor. */ -CoreFramebuffer* corefb_create(int sock, const char* protocol); +CoreFramebuffer* corefb_create(int sock, const char* protocol, struct QFrameBuffer* fb); /* * Destroys framebuffer service created with corefb_create. @@ -52,4 +53,13 @@ void corefb_destroy(CoreFramebuffer* core_fb); void corefb_update(CoreFramebuffer* core_fb, struct DisplayState* ds, struct QFrameBuffer* fb, int x, int y, int w, int h); +/* + * Gets number of bits used to encode a single pixel. + * Param: + * core_fb - Framebuffer service descriptor created with corefb_create + * Return: + * Number of bits used to encode a single pixel. + */ +int corefb_get_bits_per_pixel(CoreFramebuffer* core_fb); + #endif /* _ANDROID_FRAMEBUFFER_CORE_H */ diff --git a/android/framebuffer-ui.c b/android/framebuffer-ui.c index 0402df0..47c0d8a 100644 --- a/android/framebuffer-ui.c +++ b/android/framebuffer-ui.c @@ -59,6 +59,9 @@ struct ClientFramebuffer { /* Socket descriptor for the framebuffer client. */ int sock; + + /* Number of bits used to encode single pixel. */ + int bits_per_pixel; }; /* The only instance of framebuffer client. */ @@ -127,7 +130,7 @@ _clientfb_read_cb(void* opaque) fb_client->reader_offset = 0; fb_client->reader_bytes = fb_client->update_header.w * fb_client->update_header.h * - (fb_client->update_header.bits_per_pixel / 8); + (fb_client->bits_per_pixel / 8); fb_client->reader_buffer = malloc(fb_client->reader_bytes); if (fb_client->reader_buffer == NULL) { PANIC("Unable to allocate memory for framebuffer update\n"); @@ -144,7 +147,7 @@ _clientfb_read_cb(void* opaque) // Perform the update. Note that pixels buffer must be freed there. update_rect(fb_client->update_header.x, fb_client->update_header.y, fb_client->update_header.w, fb_client->update_header.h, - fb_client->update_header.bits_per_pixel, pixels); + fb_client->bits_per_pixel, pixels); } } } @@ -165,7 +168,7 @@ clientfb_create(SockAddress* console_socket, const char* protocol) if (core_connection_open(_client_fb.core_connection)) { core_connection_free(_client_fb.core_connection); _client_fb.core_connection = NULL; - derror("Framebuffer client is unable to ioen the console: %s\n", + derror("Framebuffer client is unable to open the console: %s\n", errno_str); return NULL; } @@ -182,8 +185,30 @@ clientfb_create(SockAddress* console_socket, const char* protocol) _client_fb.core_connection = NULL; return NULL; } + + // We expect core framebuffer to return us bits per pixel property in + // the handshake message. + _client_fb.bits_per_pixel = 0; if (connect_message != NULL) { - free(connect_message); + char* bpp = strstr(connect_message, "bitsperpixel="); + if (bpp != NULL) { + char* end; + bpp += strlen("bitsperpixel="); + end = strchr(bpp, ' '); + if (end == NULL) { + end = bpp + strlen(bpp); + } + _client_fb.bits_per_pixel = strtol(bpp, &end, 0); + } + } + + if (!_client_fb.bits_per_pixel) { + derror("Unexpected core framebuffer reply: %s\n" + "Bits per pixel property is not there, or is invalid\n", connect_message); + core_connection_close(_client_fb.core_connection); + core_connection_free(_client_fb.core_connection); + _client_fb.core_connection = NULL; + return NULL; } // Now that we're connected lets initialize the descriptor. @@ -193,6 +218,10 @@ clientfb_create(SockAddress* console_socket, const char* protocol) _client_fb.reader_offset = 0; _client_fb.reader_bytes = sizeof(FBUpdateMessage); + if (connect_message != NULL) { + free(connect_message); + } + // At last setup read callback, and start receiving the updates. if (qemu_set_fd_handler(_client_fb.sock, _clientfb_read_cb, NULL, &_client_fb)) { derror("Unable to set up framebuffer read callback\n"); |