gceSTATUS gcoOS_DisplayBufferRegions( IN HALNativeDisplayType Display, IN HALNativeWindowType Window, IN gctINT NumRects, IN gctINT_PTR Rects ) { screen_buffer_t buf[gcdDISPLAY_BACK_BUFFERS]; int rc; gceSTATUS status = gcvSTATUS_OK; gcmHEADER_ARG("Display=0x%x Window=0x%x NumRects=%d", Display, Window, NumRects); rc = screen_get_window_property_pv((screen_window_t)Window, SCREEN_PROPERTY_RENDER_BUFFERS, (void**)buf); if (rc) { goto OnError; } rc = screen_post_window((screen_window_t)Window, buf[0], NumRects, Rects, 0); if (rc) { goto OnError; } gcmFOOTER_NO(); return status; OnError: status = gcvSTATUS_INVALID_ARGUMENT; gcmFOOTER(); return status; }
bool_e qnxscreen_post(struct qnxscreen_api *q, uint32_t index) { int clipRect[4]; if (!q) { DVP_PRINT(DVP_ZONE_ERROR, "(%s) OOPS: Invalid struct qnxscreen_api pointer." " Something is seriously wrong!\n", __func__); return false_e; } if (index > q->count || index > QNXSCREEN_MAX_INDEX) { DVP_PRINT(DVP_ZONE_ERROR, "Invalid index %d\n", index); return false_e; } clipRect[0] = q->metrics.left; clipRect[1] = q->metrics.top; clipRect[2] = q->metrics.left + q->metrics.width; clipRect[3] = q->metrics.top + q->metrics.height; /* Just flush out the only buffer we have */ if (screen_post_window(q->win, q->buf[index], 1, clipRect, 0)) { DVP_PRINT(DVP_ZONE_ERROR, "(%s): Failure on screen_post_window (%d)\n", __func__, errno); return false_e; } return true_e; }
screen_window_t create_bg_window(const char *group, int dims[2]) { /* Start by creating the application window and window group. */ screen_window_t screen_win; screen_create_window(&screen_win, screen_ctx); screen_create_window_group(screen_win, group); int vis = 1; screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_VISIBLE, &vis); int color = 0xffffff00; screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_COLOR, &color); int zorder = 0; screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_ZORDER, &zorder); int rect[4] = { 0, 0, 1, 1 }; screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, rect+2); screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_SOURCE_SIZE, dims); screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_SIZE, dims); int pos[2] = { -dims[0], -dims[1] }; screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_SOURCE_POSITION, pos); screen_buffer_t screen_buf; screen_create_window_buffers(screen_win, 1); screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)&screen_buf); screen_post_window(screen_win, screen_buf, 1, rect, 0); return screen_win; }
screen_window_t create_bar_window(const char *group, const char *id, int dims[2]) { screen_window_t screen_win; screen_create_window_type(&screen_win, screen_ctx, SCREEN_CHILD_WINDOW); screen_join_window_group(screen_win, group); screen_set_window_property_cv(screen_win, SCREEN_PROPERTY_ID_STRING, strlen(id), id); int vis = 1; screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_VISIBLE, &vis); int zorder = 1; screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_ZORDER, &zorder); int color = 0xff0000ff; screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_COLOR, &color); int rect[4] = { 0, 0, 1, 1 }; screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, rect+2); int pos[2] = { -rect[2], -rect[3] }; screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_SOURCE_POSITION, pos); pos[0] = pos[1] = 0; screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_POSITION, pos); int size[2] = {barwidth,dims[1]}; screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_SIZE, size); screen_buffer_t screen_buf; screen_create_window_buffers(screen_win, 1); screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)&screen_buf); screen_post_window(screen_win, screen_buf, 1, rect, 0); return screen_win; }
void QQnxWindow::post(const QRegion &dirty) { // How double-buffering works // -------------------------- // // The are two buffers, the previous one and the current one. // The previous buffer always contains the complete, full image of the whole window when it // was last posted. // The current buffer starts with the complete, full image of the second to last posting // of the window. // // During painting, Qt paints on the current buffer. Thus, when Qt has finished painting, the // current buffer contains the second to last image plus the newly painted regions. // Since the second to last image is too old, we copy over the image from the previous buffer, but // only for those regions that Qt didn't paint (because that would overwrite what Qt has just // painted). This is the copyPreviousToCurrent() call below. // // After the call to copyPreviousToCurrent(), the current buffer contains the complete, full image of the // whole window in its current state, and we call screen_post_window() to make the new buffer // available to libscreen (called "posting"). There, only the regions that Qt painted on are // posted, as nothing else has changed. // // After that, the previous and the current buffers are swapped, and the whole cycle starts anew. // Check if render buffer exists and something was rendered if (m_currentBufferIndex != -1 && !dirty.isEmpty()) { qWindowDebug() << Q_FUNC_INFO << "window =" << window(); QQnxBuffer ¤tBuffer = m_buffers[m_currentBufferIndex]; // Copy unmodified region from old render buffer to new render buffer; // required to allow partial updates QRegion preserve = m_previousDirty - dirty - m_scrolled; blitPreviousToCurrent(preserve, 0, 0); // Calculate region that changed QRegion modified = preserve + dirty + m_scrolled; QRect rect = modified.boundingRect(); int dirtyRect[4] = { rect.x(), rect.y(), rect.x() + rect.width(), rect.y() + rect.height() }; // Update the display with contents of render buffer errno = 0; int result = screen_post_window(m_window, currentBuffer.nativeBuffer(), 1, dirtyRect, 0); if (result != 0) qFatal("QQnxWindow: failed to post window buffer, errno=%d", errno); // Advance to next nender buffer m_previousBufferIndex = m_currentBufferIndex++; if (m_currentBufferIndex >= MAX_BUFFER_COUNT) m_currentBufferIndex = 0; // Save modified region and clear scrolled region m_previousDirty = dirty; m_scrolled = QRegion(); // Notify screen that window posted if (m_screen != 0) m_screen->onWindowPost(this); } }
ButtonMap::ButtonMap(screen_context_t screen_ctx, QString groupId, int coid) { this->screen_cxt = screen_ctx; this->groupId = groupId; this->coid = coid; const int usage = SCREEN_USAGE_NATIVE | SCREEN_USAGE_WRITE | SCREEN_USAGE_READ; int rc; if(screen_create_window_type(&screen_win, screen_cxt, SCREEN_CHILD_WINDOW)) { RARCH_ERR("ButtonMap: screen_create_window_type failed.\n"); } screen_join_window_group(screen_win, (const char *)groupId.toAscii().constData()); int format = SCREEN_FORMAT_RGBA8888; screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_FORMAT, &format); screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_USAGE, &usage); screen_display_t screen_disp; if (screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_DISPLAY, (void **)&screen_disp)) { RARCH_ERR("screen_get_window_property_pv [SCREEN_PROPERTY_DISPLAY] failed.\n"); } if (screen_get_display_property_iv(screen_disp, SCREEN_PROPERTY_SIZE, screen_resolution)) { RARCH_ERR("screen_get_window_property_iv [SCREEN_PROPERTY_SIZE] failed.\n"); } rc = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, screen_resolution); if (rc) { perror("screen_set_window_property_iv"); } int z = -10; if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_ZORDER, &z) != 0) { return; } rc = screen_create_window_buffers(screen_win, 1); if (rc) { perror("screen_create_window_buffers"); } screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)&screen_buf); int bg[] = { SCREEN_BLIT_COLOR, 0x00000000, SCREEN_BLIT_GLOBAL_ALPHA, 0x80, SCREEN_BLIT_END }; screen_fill(screen_cxt, screen_buf, bg); screen_post_window(screen_win, screen_buf, 1, screen_resolution, 0); buttonDataModel = new ArrayDataModel(); refreshButtonMap(0); }
void ScreenWindow::flip() { int rect[4] = {0, 0, 1024, 600}; screen_buffer_t windowBuffer[1]; screen_get_window_property_pv(m_window, SCREEN_PROPERTY_RENDER_BUFFERS, (void**)&windowBuffer); screen_post_window(m_window, windowBuffer[0], 1, rect, 0); }
void display_frame(ffdec_context *ffd_context, AVFrame *frame) { ffdec_reserved *ffd_reserved = (ffdec_reserved*) ffd_context->reserved; ffdec_view *view = ffd_reserved->view; if (!view) return; screen_window_t screen_window = view->screen_window; screen_buffer_t screen_pixel_buffer = view->screen_pixel_buffer; screen_context_t screen_context = view->screen_context; int stride = view->stride; unsigned char *ptr = NULL; screen_get_buffer_property_pv(screen_pixel_buffer, SCREEN_PROPERTY_POINTER, (void**) &ptr); int width = frame->width; int height = frame->height; uint8_t *srcy = frame->data[0]; uint8_t *srcu = frame->data[1]; uint8_t *srcv = frame->data[2]; unsigned char *y = ptr; unsigned char *u = y + (height * stride); unsigned char *v = u + (height * stride) / 4; for (int i = 0; i < height; i++) { int doff = i * stride; int soff = i * frame->linesize[0]; memcpy(&y[doff], &srcy[soff], frame->width); } for (int i = 0; i < height / 2; i++) { int doff = i * stride / 2; int soff = i * frame->linesize[1]; memcpy(&u[doff], &srcu[soff], frame->width / 2); } for (int i = 0; i < height / 2; i++) { int doff = i * stride / 2; int soff = i * frame->linesize[2]; memcpy(&v[doff], &srcv[soff], frame->width / 2); } screen_buffer_t screen_buffer; screen_get_window_property_pv(screen_window, SCREEN_PROPERTY_RENDER_BUFFERS, (void**) &screen_buffer); int attribs[] = { SCREEN_BLIT_SOURCE_WIDTH, width, SCREEN_BLIT_SOURCE_HEIGHT, height, SCREEN_BLIT_END }; screen_blit(screen_context, screen_buffer, screen_pixel_buffer, attribs); int dirty_rects[] = { 0, 0, width, height }; screen_post_window(screen_window, screen_buffer, 1, dirty_rects, 0); }
screen_window_t create_hg_window(const char *group, const char *id, int dims[2]) { int i, j; screen_window_t screen_win; screen_create_window_type(&screen_win, screen_ctx, SCREEN_CHILD_WINDOW); screen_join_window_group(screen_win, group); screen_set_window_property_cv(screen_win, SCREEN_PROPERTY_ID_STRING, strlen(id), id); int flag = 1; screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_STATIC, &flag); int vis = 1; screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_VISIBLE, &vis); int zorder = 2; screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_ZORDER, &zorder); int format = SCREEN_FORMAT_RGBA8888; screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_FORMAT, &format); int usage = SCREEN_USAGE_WRITE; screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_USAGE, &usage); int transparency = SCREEN_TRANSPARENCY_SOURCE_OVER; screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_TRANSPARENCY, &transparency); int rect[4] = { 0, 0, 100, 100 }; screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, rect+2); screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_SIZE, &rect[2]); screen_buffer_t screen_buf; screen_create_window_buffers(screen_win, 1); screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)&screen_buf); char *ptr = NULL; screen_get_buffer_property_pv(screen_buf, SCREEN_PROPERTY_POINTER, (void **)&ptr); int stride = 0; screen_get_buffer_property_iv(screen_buf, SCREEN_PROPERTY_STRIDE, &stride); for (i = 0; i < rect[3]; i++, ptr += stride) { for (j = 0; j < rect[2]; j++) { ptr[j*4] = 0xa0; ptr[j*4+1] = 0xa0; ptr[j*4+2] = 0xa0; ptr[j*4+3] = ((j >= i && j <= rect[3]-i) || (j <= i && j >= rect[3]-i)) ? 0xff : 0; } } screen_post_window(screen_win, screen_buf, 1, rect, 0); return screen_win; }
int main(int argc, char **argv) { const int usage = SCREEN_USAGE_NATIVE; screen_window_t screen_win; screen_buffer_t screen_buf = NULL; int rect[4] = { 0, 0, 0, 0 }; // create an application window which will just act as a background screen_create_context(&screen_ctx, 0); screen_create_window(&screen_win, screen_ctx); screen_create_window_group(screen_win, vf_group); screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_USAGE, &usage); screen_create_window_buffers(screen_win, 1); screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)&screen_buf); screen_get_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, rect+2); // fill the window with black int attribs[] = { SCREEN_BLIT_COLOR, 0x00000000, SCREEN_BLIT_END }; screen_fill(screen_ctx, screen_buf, attribs); screen_post_window(screen_win, screen_buf, 1, rect, 0); // position the window at an arbitrary z-order int i = APP_ZORDER; screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_ZORDER, &i); // Signal bps library that navigator and screen events will be requested bps_initialize(); screen_request_events(screen_ctx); navigator_request_events(0); // open camera and configure viewfinder if (init_camera() == EOK) { // our main loop just runs a state machine and handles input while (!shutdown) { run_state_machine(); // Handle user input handle_event(); } if (state == STATE_VIEWFINDER) { // clean up camera camera_stop_photo_viewfinder(handle); camera_close(handle); } } // Clean up screen_stop_events(screen_ctx); bps_shutdown(); screen_destroy_window(screen_win); screen_destroy_context(screen_ctx); return 0; }
void QQnxRootWindow::post() const { qRootWindowDebug() << Q_FUNC_INFO; errno = 0; screen_buffer_t buffer; int result = screen_get_window_property_pv(m_window, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)&buffer); if (result != 0) qFatal("QQnxRootWindow: failed to query window buffer, errno=%d", errno); errno = 0; int dirtyRect[] = {0, 0, 1, 1}; result = screen_post_window(m_window, buffer, 1, dirtyRect, 0); if (result != 0) qFatal("QQNX: failed to post window buffer, errno=%d", errno); }
gceSTATUS gcoOS_SetDisplayVirtual( IN HALNativeDisplayType Display, IN HALNativeWindowType Window, IN gctUINT Offset, IN gctINT X, IN gctINT Y ) { screen_buffer_t buf[gcdDISPLAY_BACK_BUFFERS]; int rc; int rects[4]; gceSTATUS status = gcvSTATUS_OK; gcmHEADER_ARG("Display=0x%x Window=0x%x Offset=%u X=%d Y=%d", Display, Window, Offset, X, Y); rects[0] = 0; rects[1] = 0; rc = screen_get_window_property_pv((screen_window_t)Window, SCREEN_PROPERTY_RENDER_BUFFERS, (void**)buf); if (rc) { goto OnError; } rc = screen_get_window_property_iv((screen_window_t)Window, SCREEN_PROPERTY_BUFFER_SIZE, &rects[2]); if (rc) { goto OnError; } rc = screen_post_window((screen_window_t)Window, buf[0], 1, rects, 0); if (rc) { goto OnError; } _ReleaseWindowInfoNode(Window); gcmFOOTER_NO(); return status; OnError: status = gcvSTATUS_INVALID_ARGUMENT; gcmFOOTER(); return status; }
int setup_screen() { /* * Create the window. */ if (screen_create_context(&screen_context, SCREEN_APPLICATION_CONTEXT) != 0) return EXIT_FAILURE; if (screen_create_window(&screen_window, screen_context) != 0) { screen_destroy_context(screen_context); return EXIT_FAILURE; } if (screen_create_window_group(screen_window, WINDOW_GROUP_NAME) != 0) return EXIT_FAILURE; int format = SCREEN_FORMAT_RGBA8888; if (screen_set_window_property_iv(screen_window, SCREEN_PROPERTY_FORMAT, &format) != 0) return EXIT_FAILURE; int usage = SCREEN_USAGE_NATIVE; if (screen_set_window_property_iv(screen_window, SCREEN_PROPERTY_USAGE, &usage) != 0) return EXIT_FAILURE; if (screen_create_window_buffers(screen_window, 1) != 0) return EXIT_FAILURE; // Get the render buffer screen_buffer_t temp_buffer[1]; if (screen_get_window_property_pv( screen_window, SCREEN_PROPERTY_RENDER_BUFFERS, (void**)temp_buffer) != 0) return EXIT_FAILURE; // Fill the buffer with a solid color (green) int fill_attributes[3] = {SCREEN_BLIT_COLOR, 0x00C000, SCREEN_BLIT_END}; if (screen_fill(screen_context, temp_buffer[0], fill_attributes) != 0) return EXIT_FAILURE; // Make the window visible if (screen_get_window_property_iv(screen_window, SCREEN_PROPERTY_SIZE, screen_size) != 0) return EXIT_FAILURE; int temp_rectangle[4] = {0,0,screen_size[0],screen_size[1]}; if (screen_post_window(screen_window, temp_buffer[0], 1, temp_rectangle, 0) != 0) return EXIT_FAILURE; return EXIT_SUCCESS; }
static void bb10display_fillWindowBuffer(BB10Display *d, MSPicture *yuvbuf) { uint8_t *ptr = NULL; screen_get_buffer_property_pv(d->pixmap_buffer, SCREEN_PROPERTY_POINTER, (void **)&ptr); if (ptr) { uint8_t *dest_planes[3]; int dest_strides[3]; MSVideoSize roi = {0}; uint8_t *y = ptr; uint8_t *u = y + (d->vsize.height * d->stride); uint8_t *v = u + (d->vsize.height * d->stride) / 4; dest_planes[0] = y; dest_planes[1] = u; dest_planes[2] = v; dest_strides[0] = d->stride; dest_strides[1] = d->stride / 2; dest_strides[2] = d->stride / 2; roi.width = yuvbuf->w; roi.height = yuvbuf->h; ms_yuv_buf_copy(yuvbuf->planes, yuvbuf->strides, dest_planes, dest_strides, roi); screen_buffer_t buffer; screen_get_window_property_pv(d->window, SCREEN_PROPERTY_RENDER_BUFFERS, (void**) &buffer); MSRect rect; ms_layout_center_rectangle(d->wsize, d->vsize, &rect); int attributes[] = { SCREEN_BLIT_SOURCE_WIDTH, d->vsize.width, SCREEN_BLIT_SOURCE_HEIGHT, d->vsize.height, SCREEN_BLIT_DESTINATION_X, rect.x, SCREEN_BLIT_DESTINATION_Y, rect.y, SCREEN_BLIT_DESTINATION_WIDTH, rect.w, SCREEN_BLIT_DESTINATION_HEIGHT, rect.h, SCREEN_BLIT_END }; screen_blit(d->context, buffer, d->pixmap_buffer, attributes); int dirty_rect[4] = { 0, 0, d->wsize.width, d->wsize.height }; screen_post_window(d->window, buffer, 1, dirty_rect, 0); } }
gceSTATUS gcoOS_GetNextDisplayInfoEx( IN HALNativeDisplayType Display, IN HALNativeWindowType Window, IN gctUINT DisplayInfoSize, OUT halDISPLAY_INFO * DisplayInfo ) { int rc; gceSTATUS status = gcvSTATUS_OK; screen_buffer_t buf[gcdDISPLAY_BACK_BUFFERS]; gcmHEADER_ARG("Display=0x%x Window=0x%x DisplayInfoSize=%u", Display, Window, DisplayInfoSize); if ((Window == gcvNULL) || (DisplayInfoSize != sizeof(halDISPLAY_INFO))) { goto OnError; } rc = screen_get_window_property_pv((screen_window_t)Window, SCREEN_PROPERTY_RENDER_BUFFERS, (void**)buf); if (rc) { goto OnError; } rc = screen_post_window((screen_window_t)Window, buf[0], 0, NULL, 0); if (rc) { goto OnError; } status = gcoOS_GetDisplayInfoEx(Display, Window, DisplayInfoSize, DisplayInfo); gcmFOOTER_ARG("*DisplayInfo=0x%x", *DisplayInfo); return status; OnError: status = gcvSTATUS_INVALID_ARGUMENT; gcmFOOTER(); return status; }
/** * Set up a basic screen, so that the navigator will * send window state events when the window state changes. * * @return @c EXIT_SUCCESS or @c EXIT_FAILURE */ int setup_screen() { if (screen_create_context(&screen_ctx, SCREEN_APPLICATION_CONTEXT) != 0) { return EXIT_FAILURE; } if (screen_create_window(&screen_win, screen_ctx) != 0) { screen_destroy_context(screen_ctx); return EXIT_FAILURE; } int usage = SCREEN_USAGE_NATIVE; if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_USAGE, &usage) != 0) goto fail; if (screen_create_window_buffers(screen_win, 1) != 0) goto fail; if (screen_create_window_group(screen_win, get_window_group_id()) != 0) goto fail; screen_buffer_t buff; if (screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_RENDER_BUFFERS, (void*)&buff) != 0) goto fail; int buffer_size[2]; if (screen_get_buffer_property_iv(buff, SCREEN_PROPERTY_BUFFER_SIZE, buffer_size) != 0) goto fail; int attribs[1] = {SCREEN_BLIT_END}; if (screen_fill(screen_ctx, buff, attribs) != 0) goto fail; int dirty_rects[4] = {0, 0, buffer_size[0], buffer_size[1]}; if (screen_post_window(screen_win, buff, 1, (const int*)dirty_rects, 0) != 0) goto fail; return EXIT_SUCCESS; fail: screen_destroy_window(screen_win); screen_destroy_context(screen_ctx); return EXIT_FAILURE; }
int PLAYBOOK_FlipHWSurface(SDL_VideoDevice *device, SDL_Surface *surface) { // FIXME: device doesn't work properly yet. It flashes black, I think the new render buffers are wrong. static int fullRect[] = {0, 0, 1024, 600}; //screen_flush_blits(device->hidden->screenContext, 0); int result = screen_post_window(device->hidden->screenWindow, surface->hwdata->front, 1, fullRect, 0); screen_buffer_t windowBuffer[2]; int rc = screen_get_window_property_pv(device->hidden->screenWindow, SCREEN_PROPERTY_RENDER_BUFFERS, (void**)&windowBuffer); if (rc) { SDL_SetError("Cannot get window render buffers: %s", strerror(errno)); return NULL; } rc = screen_get_buffer_property_pv(windowBuffer[0], SCREEN_PROPERTY_POINTER, &device->hidden->pixels); if (rc) { SDL_SetError("Cannot get buffer pointer: %s", strerror(errno)); return NULL; } surface->hwdata->front = windowBuffer[0]; surface->pixels = device->hidden->pixels; return 0; }
int ButtonMap::mapNextButtonPressed() { bps_event_t *event = NULL; int sym; //use in frontend run loop, get key pressed back, and map int z = 10; if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_ZORDER, &z) != 0) { return -1; } screen_post_window(screen_win, screen_buf, 1, screen_resolution, 0); while(1) { if (BPS_SUCCESS != bps_get_event(&event, -1)) { fprintf(stderr, "bps_get_event failed\n"); break; } if (event) { int domain = bps_event_get_domain(event); int events = bps_event_get_code(event); if (events == NAVIGATOR_SWIPE_DOWN) { if(overlayDisplay) { *g_settings.input.overlay = '\1'; } else { *g_settings.input.overlay = '\1'; } overlayDisplay = !overlayDisplay; } if (domain == screen_get_domain()) { screen_event_t screen_event = screen_event_get_event(event); int screen_val; screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &screen_val); //TODO: Should we only let the buttons through that we are trying to map? if(screen_val == SCREEN_EVENT_MTOUCH_TOUCH) { //This is touch screen event sym = NO_BTN; break; } else if(screen_val == SCREEN_EVENT_KEYBOARD) { screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_KEY_SYM, &sym); sym &= 0xFF; break; } else if( (screen_val == SCREEN_EVENT_GAMEPAD) || (screen_val == SCREEN_EVENT_JOYSTICK) ) { screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_BUTTONS, &sym); break; } } } } z = -10; if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_ZORDER, &z) != 0) { return -1; } screen_post_window(screen_win, screen_buf, 1, screen_resolution, 0); return (g_settings.input.binds[player][button].joykey = sym); }
void ScreenWindow::init() { int rc; rc = screen_create_context(&m_context, 0); // if (rc) fprintf(stderr, "Fail at %d: %s\n", __LINE__, strerror(errno)); rc = screen_create_window(&m_appWindow, m_context); char groupName[256]; snprintf(groupName, 256, "screen-%d", getpid()); rc = screen_create_window_group(m_appWindow, groupName); int sizeOfWindow[2] = {1024, 600}; rc = screen_set_window_property_iv(m_appWindow, SCREEN_PROPERTY_SIZE, sizeOfWindow); int sizeOfBuffer[2] = {1024, 600}; rc = screen_set_window_property_iv(m_appWindow, SCREEN_PROPERTY_BUFFER_SIZE, sizeOfBuffer); int format = SCREEN_FORMAT_RGBX8888; rc = screen_set_window_property_iv(m_appWindow, SCREEN_PROPERTY_FORMAT, &format); int usage = SCREEN_USAGE_NATIVE | SCREEN_USAGE_READ | SCREEN_USAGE_WRITE; rc = screen_set_window_property_iv(m_appWindow, SCREEN_PROPERTY_USAGE, &usage); int angle = 0; char *orientation = getenv("ORIENTATION"); if (orientation) { angle = atoi(orientation); } rc = screen_set_window_property_iv(m_appWindow, SCREEN_PROPERTY_ROTATION, &angle); rc = screen_create_window_buffers(m_appWindow, 1); screen_buffer_t windowBuffer[1]; rc = screen_get_window_property_pv(m_appWindow, SCREEN_PROPERTY_RENDER_BUFFERS, (void**)&windowBuffer); int attribs[] = {SCREEN_BLIT_DESTINATION_X, 0, SCREEN_BLIT_DESTINATION_Y, 0, SCREEN_BLIT_DESTINATION_WIDTH, 1024, SCREEN_BLIT_DESTINATION_HEIGHT, 600, SCREEN_BLIT_COLOR, 0xff30ffff, SCREEN_BLIT_END}; rc = screen_fill(m_context, windowBuffer[0], attribs); rc = screen_get_window_property_pv(m_appWindow, SCREEN_PROPERTY_RENDER_BUFFERS, (void**)&windowBuffer); int rect[4] = {0, 0, 1024, 600}; rc = screen_post_window(m_appWindow, windowBuffer[0], 1, rect, 0); screen_request_events(m_context); navigator_request_events(0); }
int main (int argc, char **argv) { int card = -1; int dev = 0; snd_pcm_t *pcm_handle; FILE *file; wave_hdr wav_header; int samples; int sample_rate; int sample_channels; int sample_bits; char *sample_buffer; int fragsize = -1; int verbose = 0; int rtn; int final_return_code = -1; snd_pcm_channel_info_t pi; snd_mixer_t *mixer_handle; snd_mixer_group_t group; snd_pcm_channel_params_t pp; snd_pcm_channel_setup_t setup; int bsize, bytes_read, total_written = 0; fd_set rfds, wfds; uint32_t voice_mask[] = { 0, 0, 0, 0 }; snd_pcm_voice_conversion_t voice_conversion; int voice_override = 0; int num_frags = -1; char input_file[PATH_MAX]; char cwd[PATH_MAX]; screen_context_t screen_cxt; screen_window_t screen_win; screen_buffer_t screen_buf; int screen_fill_attribs[] = { SCREEN_BLIT_COLOR, COLOR_PURPLE, SCREEN_BLIT_END }; int screen_dirty[4] = { 0, 0, 1024, 600 }; //start with sane default values int idle_mode = SCREEN_IDLE_MODE_KEEP_AWAKE; int usage = SCREEN_USAGE_NATIVE; if (screen_create_context(&screen_cxt, 0) != 0) { return err("failed to create context"); } if (screen_create_window(&screen_win, screen_cxt) != 0) { err("failed to create window"); goto fail1; } if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_USAGE, &usage) != 0) { err("failed to set native usage mode"); goto fail2; } if (screen_create_window_buffers(screen_win, 1) != 0) { err("failed to set native usage mode"); goto fail2; } if(screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)&screen_buf) != 0) { err("failed to get screen buffer"); goto fail2; } if (screen_fill(screen_cxt, screen_buf, screen_fill_attribs) != 0) { err("failed to fill the screen"); goto fail3; } if (screen_get_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, screen_dirty+2) != 0) { err("failed to get window size"); goto fail3; } if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_IDLE_MODE, &idle_mode) != 0) { err("failed to set idle mode"); goto fail3; } if (screen_post_window(screen_win, screen_buf, 1, screen_dirty, 0) != 0) { err("failed to post the window"); goto fail3; } if ((rtn = snd_pcm_open_preferred (&pcm_handle, &card, &dev, SND_PCM_OPEN_PLAYBACK)) < 0) { err ("device open"); goto fail3; } getcwd(cwd, PATH_MAX); rtn = snprintf(input_file, PATH_MAX, "%s%s", cwd, WAV_RELATIVE_PATH); if (rtn > PATH_MAX - 1) { err ("File name and path too long"); goto fail4; } if ((file = fopen (input_file, "r")) == 0) { err ("File open failed"); goto fail4; } if (check_hdr (file) == -1) { err ("check_hdr failed"); goto fail5; } samples = find_tag (file, "fmt "); fread (&wav_header, sizeof (wav_header), 1, file); fseek (file, (samples - sizeof (wave_hdr)), SEEK_CUR); sample_rate = ENDIAN_LE32 (wav_header.samples_per_sec); sample_channels = ENDIAN_LE16 (wav_header.channels); sample_bits = ENDIAN_LE16 (wav_header.bits_per_sample); printf ("SampleRate = %d, channels = %d, SampleBits = %d\n", sample_rate, sample_channels, sample_bits); /* disabling mmap is not actually required in this example but it is included to * demonstrate how it is used when it is required. */ if ((rtn = snd_pcm_plugin_set_disable (pcm_handle, PLUGIN_DISABLE_MMAP)) < 0) { fprintf (stderr, "snd_pcm_plugin_set_disable failed: %s\n", snd_strerror (rtn)); goto fail5; } memset (&pi, 0, sizeof (pi)); pi.channel = SND_PCM_CHANNEL_PLAYBACK; if ((rtn = snd_pcm_plugin_info (pcm_handle, &pi)) < 0) { fprintf (stderr, "snd_pcm_plugin_info failed: %s\n", snd_strerror (rtn)); goto fail5; } memset (&pp, 0, sizeof (pp)); pp.mode = SND_PCM_MODE_BLOCK; pp.channel = SND_PCM_CHANNEL_PLAYBACK; pp.start_mode = SND_PCM_START_FULL; pp.stop_mode = SND_PCM_STOP_STOP; pp.buf.block.frag_size = pi.max_fragment_size; if (fragsize != -1) { pp.buf.block.frag_size = fragsize; } pp.buf.block.frags_max = num_frags; pp.buf.block.frags_min = 1; pp.format.interleave = 1; pp.format.rate = sample_rate; pp.format.voices = sample_channels; if (ENDIAN_LE16 (wav_header.format_tag) == 6) pp.format.format = SND_PCM_SFMT_A_LAW; else if (ENDIAN_LE16 (wav_header.format_tag) == 7) pp.format.format = SND_PCM_SFMT_MU_LAW; else if (sample_bits == 8) pp.format.format = SND_PCM_SFMT_U8; else if (sample_bits == 24) pp.format.format = SND_PCM_SFMT_S24; else pp.format.format = SND_PCM_SFMT_S16_LE; strcpy (pp.sw_mixer_subchn_name, "Wave playback channel"); if ((rtn = snd_pcm_plugin_params (pcm_handle, &pp)) < 0) { fprintf (stderr, "snd_pcm_plugin_params failed: %s\n", snd_strerror (rtn)); goto fail5; } if ((rtn = snd_pcm_plugin_prepare (pcm_handle, SND_PCM_CHANNEL_PLAYBACK)) < 0) { fprintf (stderr, "snd_pcm_plugin_prepare failed: %s\n", snd_strerror (rtn)); goto fail5; } if (voice_override) { snd_pcm_plugin_get_voice_conversion (pcm_handle, SND_PCM_CHANNEL_PLAYBACK, &voice_conversion); voice_conversion.matrix[0] = voice_mask[0]; voice_conversion.matrix[1] = voice_mask[1]; voice_conversion.matrix[2] = voice_mask[2]; voice_conversion.matrix[3] = voice_mask[3]; snd_pcm_plugin_set_voice_conversion (pcm_handle, SND_PCM_CHANNEL_PLAYBACK, &voice_conversion); } memset (&setup, 0, sizeof (setup)); memset (&group, 0, sizeof (group)); setup.channel = SND_PCM_CHANNEL_PLAYBACK; setup.mixer_gid = &group.gid; if ((rtn = snd_pcm_plugin_setup (pcm_handle, &setup)) < 0) { fprintf (stderr, "snd_pcm_plugin_setup failed: %s\n", snd_strerror (rtn)); goto fail5; } printf ("Format %s \n", snd_pcm_get_format_name (setup.format.format)); printf ("Frag Size %d \n", setup.buf.block.frag_size); printf ("Total Frags %d \n", setup.buf.block.frags); printf ("Rate %d \n", setup.format.rate); printf ("Voices %d \n", setup.format.voices); bsize = setup.buf.block.frag_size; if (group.gid.name[0] == 0) { fprintf (stderr, "Mixer Pcm Group [%s] Not Set \n", group.gid.name); goto fail5; } printf ("Mixer Pcm Group [%s]\n", group.gid.name); if ((rtn = snd_mixer_open (&mixer_handle, card, setup.mixer_device)) < 0) { fprintf (stderr, "snd_mixer_open failed: %s\n", snd_strerror (rtn)); goto fail5; } samples = find_tag (file, "data"); sample_buffer = malloc (bsize); FD_ZERO (&rfds); FD_ZERO (&wfds); bytes_read = 1; while (total_written < samples && bytes_read > 0) { if (tcgetpgrp (0) == getpid ()) FD_SET (STDIN_FILENO, &rfds); FD_SET (snd_mixer_file_descriptor (mixer_handle), &rfds); FD_SET (snd_pcm_file_descriptor (pcm_handle, SND_PCM_CHANNEL_PLAYBACK), &wfds); rtn = max (snd_mixer_file_descriptor (mixer_handle), snd_pcm_file_descriptor (pcm_handle, SND_PCM_CHANNEL_PLAYBACK)); if (select (rtn + 1, &rfds, &wfds, NULL, NULL) == -1) { err ("select"); goto fail6; } if (FD_ISSET (snd_pcm_file_descriptor (pcm_handle, SND_PCM_CHANNEL_PLAYBACK), &wfds)) { snd_pcm_channel_status_t status; int written = 0; if ((bytes_read = fread (sample_buffer, 1, min (samples - total_written, bsize), file)) <= 0) continue; written = snd_pcm_plugin_write (pcm_handle, sample_buffer, bytes_read); if (verbose) printf ("bytes written = %d \n", written); if (written < bytes_read) { memset (&status, 0, sizeof (status)); status.channel = SND_PCM_CHANNEL_PLAYBACK; if (snd_pcm_plugin_status (pcm_handle, &status) < 0) { fprintf (stderr, "underrun: playback channel status error\n"); goto fail6; } if (status.status == SND_PCM_STATUS_READY || status.status == SND_PCM_STATUS_UNDERRUN) { if (snd_pcm_plugin_prepare (pcm_handle, SND_PCM_CHANNEL_PLAYBACK) < 0) { fprintf (stderr, "underrun: playback channel prepare error\n"); goto fail6; } } if (written < 0) written = 0; written += snd_pcm_plugin_write (pcm_handle, sample_buffer + written, bytes_read - written); } total_written += written; } } bytes_read = snd_pcm_plugin_flush (pcm_handle, SND_PCM_CHANNEL_PLAYBACK); final_return_code = 0; fail6: rtn = snd_mixer_close (mixer_handle); fail5: fclose (file); fail4: rtn = snd_pcm_close (pcm_handle); fail3: screen_destroy_buffer(screen_buf); fail2: screen_destroy_window(screen_win); fail1: screen_destroy_context(screen_cxt); return final_return_code; }
int ShowVideo(void) { Image *Output; int SX,SY; /* Must have active video image, X11 display */ if(!VideoImg||!VideoImg->Data) return(0); /* Allocate image buffer if none */ if(!OutImg.Data&&!NewImage(&OutImg,XSize,YSize)) return(0); /* Count framerate */ if((Effects&EFF_SHOWFPS)&&(++FrameCount>=120)) { struct timeval NewTS; int Time; gettimeofday(&NewTS,0); Time = (NewTS.tv_sec-TimeStamp.tv_sec)*1000 + (NewTS.tv_usec-TimeStamp.tv_usec)/1000; FrameRate = 1000*FrameCount/(Time>0? Time:1); TimeStamp = NewTS; FrameCount = 0; FrameRate = FrameRate>999? 999:FrameRate; } /* If not scaling or post-processing image, avoid extra work */ if(!(Effects&(EFF_SOFTEN|EFF_SCALE|EFF_TVLINES))) { /* Show framerate if requested */ if((Effects&EFF_SHOWFPS)&&(FrameRate>0)) { char S[8]; sprintf(S,"%02dfps",FrameRate); PrintXY(VideoImg,S, 8,8, FPS_COLOR,PIXEL(255,255,255) ); } screen_buffer_t screen_buf[1]; screen_get_window_property_pv(window, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)screen_buf); int bg[] = { SCREEN_BLIT_END }; screen_blit(ctxt, screen_buf[0], VideoImg->pbuf, bg); screen_post_window(window, screen_buf[0], 1, rect, 0); return 1; } /* By default, we will be showing OutImg */ Output = &OutImg; SX = 0; SY = 0; if(Effects&EFF_SOFTEN) { /* Apply softening */ SoftenImage(&OutImg,VideoImg,VideoX,VideoY,VideoW,VideoH); /* Apply TV scanlines, if needed */ if(Effects&EFF_TVLINES) TelevizeImage(&OutImg,0,0,OutImg.W,OutImg.H); } else if(Effects&EFF_TVLINES) { if(Effects&EFF_SCALE) { /* Scale VideoImg into OutImg */ ScaleImage(&OutImg,VideoImg,VideoX,VideoY,VideoW,VideoH); /* Apply TV scanlines */ TelevizeImage(&OutImg,0,0,OutImg.W,OutImg.H); } else { /* Center VideoImg in OutImg */ IMGCopy(&OutImg,(OutImg.W-VideoW)>>1,(OutImg.H-VideoH)>>1,VideoImg,VideoX,VideoY,VideoW,VideoH,-1); /* Apply TV scanlines */ TelevizeImage(&OutImg,(OutImg.W-VideoW)>>1,(OutImg.H-VideoH)>>1,VideoW,VideoH); } } else if((OutImg.W==VideoW)&&(OutImg.H==VideoH))
int create_gles_window(const char *group, const char *id, int dims[2]) { int i, j; screen_window_t screen_win; screen_create_window_type(&screen_win, screen_ctx, SCREEN_CHILD_WINDOW); screen_join_window_group(screen_win, group); screen_set_window_property_cv(screen_win, SCREEN_PROPERTY_ID_STRING, strlen(id), id); int flag = 1; screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_STATIC, &flag); int vis = 1; screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_VISIBLE, &vis); int zorder = 3; screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_ZORDER, &zorder); int format = SCREEN_FORMAT_RGBA8888; screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_FORMAT, &format); int usage = SCREEN_USAGE_OPENGL_ES2; screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_USAGE, &usage); int transparency = SCREEN_TRANSPARENCY_SOURCE_OVER; screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_TRANSPARENCY, &transparency); screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, dims); screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_SIZE, dims); screen_buffer_t screen_buf; screen_create_window_buffers(screen_win, 1); screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)&screen_buf); int rect[4] = { 0, 0, dims[0], dims[1] }; // OpenGL window covers all display screen_post_window(screen_win, screen_buf, 1, rect, 0); // EGL initialization stuff starts here EGLint surface_width, surface_height; GLuint rendering_program; EGLConfig egl_conf; EGLint interval = 1; int rc, num_configs; EGLint attrib_list[]= { EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_NONE}; EGLint attributes[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; //EGL initialization egl_disp = eglGetDisplay(EGL_DEFAULT_DISPLAY); if (egl_disp == EGL_NO_DISPLAY) { egl_perror("bbutil_init_egl: eglGetDisplay"); gl_terminate(&screen_win); return EXIT_FAILURE; } rc = eglInitialize(egl_disp, NULL, NULL); if (rc != EGL_TRUE) { egl_perror("bbutil_init_egl: eglInitialize"); gl_terminate(&screen_win); return EXIT_FAILURE; } rc = eglBindAPI(EGL_OPENGL_ES_API); if (rc != EGL_TRUE) { egl_perror("bbutil_init_egl: eglBindApi"); gl_terminate(&screen_win); return EXIT_FAILURE; } if(!eglChooseConfig(egl_disp, attrib_list, &egl_conf, 1, &num_configs)) { gl_terminate(&screen_win); return EXIT_FAILURE; } egl_ctx = eglCreateContext(egl_disp, egl_conf, EGL_NO_CONTEXT, attributes); if (egl_ctx == EGL_NO_CONTEXT) { egl_perror("bbutil_init_egl: eglCreateContext"); gl_terminate(&screen_win); return EXIT_FAILURE; } // Bound EGL serface to our Native Window egl_surf = eglCreateWindowSurface(egl_disp, egl_conf, screen_win, NULL); if (egl_surf == EGL_NO_SURFACE) { egl_perror("eglCreateWindowSurface"); gl_terminate(&screen_win); return 1; } rc = eglMakeCurrent(egl_disp, egl_surf, egl_surf, egl_ctx); if (rc != EGL_TRUE) { egl_perror("eglMakeCurrent"); gl_terminate(&screen_win); return 1; } rc = eglSwapInterval(egl_disp, interval); if (rc != EGL_TRUE) { egl_perror("eglSwapInterval"); gl_terminate(&screen_win); return 1; } glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Last byte is 'transparency', it's important to have it 0.0f glEnable(GL_CULL_FACE); // Enable 2d eglQuerySurface(egl_disp, egl_surf, EGL_WIDTH, &surface_width); eglQuerySurface(egl_disp, egl_surf, EGL_HEIGHT, &surface_height); EGLint err = eglGetError(); if (err != 0x3000) { fprintf(stderr, "Unable to query EGL surface dimensions\n"); return EXIT_FAILURE; } glViewport(0, 0, surface_width, surface_height); // Create shaders const char *v_source = "attribute vec4 vPosition;\n" "void main()\n" "{\n" "gl_Position = vPosition;\n" "}"; const char *f_source = "precision mediump float; \n" "void main()\n" "{\n" "gl_FragColor = vec4(1.0, 0.0, 0.0, 0.7); \n" // 0.7 means we make it 'a bit' transparent "} \n"; // Compile the vertex shader GLint status; GLuint vs = glCreateShader(GL_VERTEX_SHADER); if (!vs) { fprintf(stderr, "Failed to create vertex shader: %d\n", glGetError()); return EXIT_FAILURE; } else { glShaderSource(vs, 1, &v_source, 0); glCompileShader(vs); glGetShaderiv(vs, GL_COMPILE_STATUS, &status); if (GL_FALSE == status) { GLchar log[256]; glGetShaderInfoLog(vs, 256, NULL, log); fprintf(stderr, "Failed to compile vertex shader: %s\n", log); glDeleteShader(vs); return EXIT_FAILURE; } } // Compile the fragment shader GLuint fs = glCreateShader(GL_FRAGMENT_SHADER); if (!fs) { fprintf(stderr, "Failed to create fragment shader: %d\n", glGetError()); return EXIT_FAILURE; } else { glShaderSource(fs, 1, &f_source, 0); glCompileShader(fs); glGetShaderiv(fs, GL_COMPILE_STATUS, &status); if (GL_FALSE == status) { GLchar log[256]; glGetShaderInfoLog(fs, 256, NULL, log); fprintf(stderr, "Failed to compile fragment shader: %s\n", log); glDeleteShader(vs); glDeleteShader(fs); return EXIT_FAILURE; } } // Create and link the program rendering_program = glCreateProgram(); if (rendering_program) { glAttachShader(rendering_program, vs); glAttachShader(rendering_program, fs); glLinkProgram(rendering_program); glGetProgramiv(rendering_program, GL_LINK_STATUS, &status); if (status == GL_FALSE){ GLchar log[256]; glGetProgramInfoLog(fs, 256, NULL, log); fprintf(stderr, "Failed to link text rendering shader program: %s\n", log); glDeleteProgram(rendering_program); rendering_program = 0; return EXIT_FAILURE; } } else { fprintf(stderr, "Failed to create a shader program\n"); glDeleteShader(vs); glDeleteShader(fs); return EXIT_FAILURE; } // We don't need the shaders anymore - the program is enough glDeleteShader(fs); glDeleteShader(vs); glUseProgram(rendering_program); // In this example we use only one rendering program, so we can call this function once screen_gles_win = screen_win; return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { int rc; int exit_application = 0; // Screen variables screen_context_t screen_context = 0; screen_window_t screen_window = 0; int screen_size[2] = {0,0}; // Renderer variables mmr_connection_t* mmr_connection = 0; mmr_context_t* mmr_context = 0; strm_dict_t* dict = NULL; // I/O variables int video_device_output_id = -1; int audio_device_output_id = -1; bps_initialize(); /* * Create the window used for video output. */ if (screen_create_context(&screen_context, SCREEN_APPLICATION_CONTEXT) != 0) { return EXIT_FAILURE; } if (screen_create_window(&screen_window, screen_context) != 0) { screen_destroy_context(screen_context); return EXIT_FAILURE; } if (screen_create_window_group(screen_window, window_group_name) != 0) { return EXIT_FAILURE; } int format = SCREEN_FORMAT_RGBA8888; if (screen_set_window_property_iv(screen_window, SCREEN_PROPERTY_FORMAT, &format) != 0) { return EXIT_FAILURE; } int usage = SCREEN_USAGE_NATIVE; if (screen_set_window_property_iv(screen_window, SCREEN_PROPERTY_USAGE, &usage) != 0) { return EXIT_FAILURE; } if (screen_create_window_buffers(screen_window, 1) != 0) { return EXIT_FAILURE; } /* * Configure mm-renderer. */ mmr_connection = mmr_connect(NULL); if (mmr_connection == NULL) { return EXIT_FAILURE; } mmr_context = mmr_context_create(mmr_connection, video_context_name, 0, S_IRWXU|S_IRWXG|S_IRWXO); if (mmr_context == NULL) { return EXIT_FAILURE; } /* * Configure video and audio output. */ video_device_output_id = mmr_output_attach(mmr_context, video_device_url, "video"); if (video_device_output_id == -1) { return EXIT_FAILURE; } audio_device_output_id = mmr_output_attach(mmr_context, audio_device_url, "audio"); if (audio_device_output_id == -1) { return EXIT_FAILURE; } // Get the render buffer screen_buffer_t temp_buffer[1]; if (screen_get_window_property_pv( screen_window, SCREEN_PROPERTY_RENDER_BUFFERS, (void**)temp_buffer) != 0) { return EXIT_FAILURE; } // Fill the buffer with a solid color (black) int fill_attributes[3] = {SCREEN_BLIT_COLOR, 0x0, SCREEN_BLIT_END}; if (screen_fill(screen_context, temp_buffer[0], fill_attributes) != 0) { return EXIT_FAILURE; } // Make the window visible if (screen_get_window_property_iv(screen_window, SCREEN_PROPERTY_SIZE, screen_size) != 0) { return EXIT_FAILURE; } int temp_rectangle[4] = {0, 0, screen_size[0], screen_size[1]}; if (screen_post_window(screen_window, temp_buffer[0], 1, temp_rectangle, 0) != 0) { return EXIT_FAILURE; } // Prevent the backlight from going off int idle_mode = SCREEN_IDLE_MODE_KEEP_AWAKE; if (screen_set_window_property_iv(screen_window, SCREEN_PROPERTY_IDLE_MODE, &idle_mode) != 0) { return EXIT_FAILURE; } // Build up the path where our bundled resource is. char cwd[PATH_MAX]; char media_file[PATH_MAX]; getcwd(cwd,PATH_MAX); rc = snprintf(media_file, PATH_MAX, "file://%s/app/native/pb_sample.mp4", cwd); if ((rc == -1) || (rc >= PATH_MAX)) { return EXIT_FAILURE; } /* * Start the playback. */ if (mmr_input_attach(mmr_context, media_file, "track") != 0) { return EXIT_FAILURE; } if (mmr_play(mmr_context) != 0) { return EXIT_FAILURE; } /* Do some work to make the aspect ratio correct. */ dict = calculate_rect(screen_size[0], screen_size[1]); if (NULL == dict) { return EXIT_FAILURE; } if (mmr_output_parameters(mmr_context, video_device_output_id, dict) != 0) { return EXIT_FAILURE; } /* Note that we allocated memory for the dictionary, but the call to * mmr_output_parameters() deallocates that memory even on failure. */ dict = NULL; screen_request_events(screen_context); navigator_request_events(0); /* * Handle keyboard events and stop playback upon user request. */ for (;;) { bps_event_t *event = NULL; if (bps_get_event(&event, -1) != BPS_SUCCESS) { return EXIT_FAILURE; } if (event) { if (bps_event_get_domain(event) == navigator_get_domain() && bps_event_get_code(event) == NAVIGATOR_EXIT) { exit_application = 1; } if (exit_application) { break; } } } screen_stop_events(screen_context); if (mmr_stop(mmr_context) != 0) { return EXIT_FAILURE; } if (mmr_output_detach(mmr_context, audio_device_output_id) != 0) { return EXIT_FAILURE; } if (mmr_output_detach(mmr_context, video_device_output_id) != 0) { return EXIT_FAILURE; } if (mmr_context_destroy(mmr_context) != 0) { return EXIT_FAILURE; } mmr_context = 0; video_device_output_id = -1; audio_device_output_id = -1; mmr_disconnect(mmr_connection); mmr_connection = 0; bps_shutdown(); if (screen_destroy_window(screen_window) != 0) { return EXIT_FAILURE; } if (screen_destroy_context(screen_context) != 0) { return EXIT_FAILURE; } screen_context = 0; screen_window = 0; return EXIT_SUCCESS; }
int setup_screen() { if (screen_create_context(&screen_ctx, SCREEN_APPLICATION_CONTEXT) != 0) { return EXIT_FAILURE; } //Signal BPS library that navigator orientation is to be locked if (BPS_SUCCESS != navigator_rotation_lock(true)) { screen_destroy_context(screen_ctx); return EXIT_FAILURE; } if (screen_create_window(&screen_win, screen_ctx) != 0) { screen_destroy_context(screen_ctx); return EXIT_FAILURE; } if (screen_create_window_group(screen_win, get_window_group_id()) != 0) goto fail; int usage = SCREEN_USAGE_NATIVE; if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_USAGE, &usage) != 0) goto fail; int size[2]; if (screen_get_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, size) != 0) goto fail; screen_display_t screen_disp; screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_DISPLAY, (void **)&screen_disp); screen_display_mode_t screen_mode; if (screen_get_display_property_pv(screen_disp, SCREEN_PROPERTY_MODE, (void**)&screen_mode) != 0) goto fail; int buffer_size[2] = {size[0], size[1]}; int angle = atoi(getenv("ORIENTATION")); if ((angle == 0) || (angle == 180)) { if (((screen_mode.width > screen_mode.height) && (size[0] < size[1])) || ((screen_mode.width < screen_mode.height) && (size[0] > size[1]))) { buffer_size[1] = size[0]; buffer_size[0] = size[1]; } } else if ((angle == 90) || (angle == 270)){ if (((screen_mode.width > screen_mode.height) && (size[0] > size[1])) || ((screen_mode.width < screen_mode.height && size[0] < size[1]))) { buffer_size[1] = size[0]; buffer_size[0] = size[1]; } } else { goto fail; } if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, buffer_size) != 0) goto fail; if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_ROTATION, &angle) != 0) goto fail; if (screen_create_window_buffers(screen_win, 1) != 0) goto fail; screen_buffer_t buff; if (screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_RENDER_BUFFERS, (void*)&buff) != 0) goto fail; int attribs[1] = {SCREEN_BLIT_END}; if (screen_fill(screen_ctx, buff, attribs) != 0) goto fail; int dirty_rects[4] = {0, 0, buffer_size[0], buffer_size[1]}; if (screen_post_window(screen_win, buff, 1, (const int*)dirty_rects, 0) != 0) goto fail; return EXIT_SUCCESS; fail: perror(NULL); cleanup_screen(); return EXIT_FAILURE; }