display-core.c revision ac389ae4513263597dc02e4099867d5123faaa04
1/* Copyright (C) 2010 The Android Open Source Project 2** 3** This software is licensed under the terms of the GNU General Public 4** License version 2, as published by the Free Software Foundation, and 5** may be copied, distributed, and modified under those terms. 6** 7** This program is distributed in the hope that it will be useful, 8** but WITHOUT ANY WARRANTY; without even the implied warranty of 9** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10** GNU General Public License for more details. 11*/ 12 13/* 14 * Contains extension to android display (see android/display.h|c) that is used 15 * by the core to communicate display changes to the attached UI 16 */ 17 18#include "android/utils/system.h" 19#include "android/display-core.h" 20 21/* Core display descriptor. */ 22struct CoreDisplay { 23 /* Display state for this core display. */ 24 DisplayState* ds; 25 26 /* Framebuffer for this core display. */ 27 QFrameBuffer* fb; 28 29 /* Framebuffer service associated with this core display. */ 30 CoreFramebuffer* core_fb; 31}; 32 33/* One and only one core display instance. */ 34CoreDisplay core_display; 35 36/* 37 * Framebuffer calls this routine when it detects changes. This routine will 38 * initiate a "push" of the framebuffer changes to the UI. 39 * See QFrameBufferUpdateFunc in framebuffer.h for more info on this callback. 40 */ 41static void 42coredisplay_fb_update(void* opaque, int x, int y, int w, int h) 43{ 44 CoreDisplay* cd = (CoreDisplay*)opaque; 45 if (cd->core_fb) { 46 corefb_update(cd->core_fb, cd->fb, x, y, w, h); 47 } 48} 49 50/* 51 * Framebuffer callback. See QFrameBufferRotateFunc in framebuffer.h for more 52 * info on this callback. 53 */ 54static void 55coredisplay_fb_rotate(void* opaque, int rotation) 56{ 57} 58 59/* 60 * Framebuffer callback. See QFrameBufferPollFunc in framebuffer.h for more 61 * info on this callback. 62 */ 63static void 64coredisplay_fb_poll(void* opaque) 65{ 66 // This will eventually call core_display_fb_update. 67 qframebuffer_check_updates(); 68} 69 70/* 71 * Framebuffer callback. See QFrameBufferDoneFunc in framebuffer.h for more 72 * info on this callback. 73 */ 74static void 75coredisplay_fb_done(void* opaque) 76{ 77} 78 79void 80coredisplay_init(DisplayState* ds) 81{ 82 int format; 83 84 core_display.ds = ds; 85 /* Create and initialize framebuffer instance that will be used for core 86 * display. 87 */ 88 ANEW0(core_display.fb); 89 core_display.core_fb = NULL; 90 91 /* In the core, there is no skin to parse and the format of ds->surface 92 * is determined by the -android-gui option. 93 */ 94 format = QFRAME_BUFFER_RGB565; 95 if (ds->surface->pf.bytes_per_pixel == 4) 96 format = QFRAME_BUFFER_RGBX_8888; 97 98 qframebuffer_init(core_display.fb, ds->surface->width, ds->surface->height, 99 0, format); 100 qframebuffer_fifo_add(core_display.fb); 101 /* Register core display as the client for the framebuffer, so we can start 102 * receiving framebuffer notifications. Note that until UI connects to the 103 * core all framebuffer callbacks are essentially no-ops. 104 */ 105 qframebuffer_add_client(core_display.fb, &core_display, 106 coredisplay_fb_update, coredisplay_fb_rotate, 107 coredisplay_fb_poll, coredisplay_fb_done); 108 android_display_init(ds, core_display.fb); 109} 110 111int 112coredisplay_attach_fb_service(CoreFramebuffer* core_fb) 113{ 114 if (core_display.core_fb == NULL) { 115 core_display.core_fb = core_fb; 116 return 0; 117 } else { 118 return -1; 119 } 120} 121 122CoreFramebuffer* 123coredisplay_detach_fb_service(void) 124{ 125 CoreFramebuffer* ret = core_display.core_fb; 126 core_display.core_fb = NULL; 127 return ret; 128} 129 130QFrameBuffer* 131coredisplay_get_framebuffer(void) 132{ 133 return core_display.fb; 134} 135