static int DirectFB_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, Uint32 format, void * pixels, int pitch) { Uint32 sdl_format; unsigned char* laypixels; int laypitch; DFBSurfacePixelFormat dfb_format; DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; IDirectFBSurface *winsurf = data->target; DirectFB_ActivateRenderer(renderer); winsurf->GetPixelFormat(winsurf, &dfb_format); sdl_format = DirectFB_DFBToSDLPixelFormat(dfb_format); winsurf->Lock(winsurf, DSLF_READ, (void **) &laypixels, &laypitch); laypixels += (rect->y * laypitch + rect->x * SDL_BYTESPERPIXEL(sdl_format) ); SDL_ConvertPixels(rect->w, rect->h, sdl_format, laypixels, laypitch, format, pixels, pitch); winsurf->Unlock(winsurf); return 0; }
static void Display(vout_display_t *vd, picture_t *picture) { vout_display_sys_t *sys = vd->sys; IDirectFBSurface *primary = sys->primary; void *pixels; int pitch; if (primary->Lock(primary, DSLF_WRITE, &pixels, &pitch) == DFB_OK) { picture_resource_t rsc; memset(&rsc, 0, sizeof(rsc)); rsc.p[0].p_pixels = pixels; rsc.p[0].i_lines = sys->height; rsc.p[0].i_pitch = pitch; picture_t *direct = picture_NewFromResource(&vd->fmt, &rsc); if (direct) { picture_Copy(direct, picture); picture_Release(direct); } if (primary->Unlock(primary) == DFB_OK) primary->Flip(primary, NULL, 0); } picture_Release(picture); }
void DirectFB_UnlockYUVOverlay(_THIS, SDL_Overlay *overlay) { IDirectFBSurface *surface = overlay->hwdata->surface; overlay->pixels[0] = overlay->pixels[1] = overlay->pixels[2] = NULL; surface->Unlock (surface); }
static void directfb_commit_strip (struct bitmap *bmp, int top, int lines) { IDirectFBSurface *surface = bmp->flags; surface->Unlock (surface); bmp->data = NULL; }
static void directfb_register_bitmap (struct bitmap *bmp) { IDirectFBSurface *surface = bmp->flags; surface->Unlock (surface); bmp->data = NULL; }
static mrb_value surface_unlock(mrb_state *mrb, mrb_value self) { IDirectFBSurface* surface = mrb_directfb_surface(mrb, self); DFBResult ret = -1; if (surface != NULL) { ret = surface->Unlock(surface); } return mrb_fixnum_value(ret); }
static void * TestThread( DirectThread *thread, void *arg ) { DFBResult ret; IDirectFBSurface *surface = arg; DFBRectangle rect = { 0, 0, 500, 1 }; while (!quit) { void *data; int pitch; ret = surface->Lock( surface, DSLF_WRITE, &data, &pitch ); if (ret) { D_DERROR( ret, "DFBTest/Resize: Lock() failed!\n" ); return NULL; } if (!data) { D_DERROR( ret, "DFBTest/Resize:invalid pointer!\n" ); return NULL; } memset( data, 0, pitch * 400 ); surface->Unlock( surface ); data = malloc( pitch ); ret = surface->Read( surface, &rect, data, pitch ); if (ret) { D_DERROR( ret, "DFBTest/Resize: Read() failed!\n" ); free (data); return NULL; } ret = surface->Write( surface, &rect, data, pitch ); if (ret) { D_DERROR( ret, "DFBTest/Resize: Write() failed!\n" ); free(data); return NULL; } free(data); } return NULL; }
void QDirectFBPaintDevice::unlockSurface() { if (QDirectFBScreen::instance() && lockFlgs) { #ifdef QT_DIRECTFB_SUBSURFACE IDirectFBSurface *surface = subSurface; #else IDirectFBSurface *surface = dfbSurface; #endif if (surface) { surface->Unlock(surface); lockFlgs = static_cast<DFBSurfaceLockFlags>(0); mem = 0; } } }
//Hardcore translateion void glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels) { #ifdef DEBUG printf("%s:%s[%d]\n", __FILE__, __func__, __LINE__); #endif IDirectFBSurface * surface = NULL; EGLSurface egl_surface = NULL; DFBResult err = 0; DFBSurfaceDescription dsc; CoreSurfaceBufferLock lock; dsc.flags = (DFBSurfaceDescriptionFlags) (DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS); dsc.caps = DSCAPS_PREMULTIPLIED; dsc.width = width; dsc.height = height; dsc.pixelformat = DSPF_ARGB; m_dfb->CreateSurface( m_dfb, &dsc, &surface); #if 0 surface->Lock (surface, DSLF_WRITE, &lock.addr, &lock.pitch); memcpy(lock.addr, pixels, width*height*4); surface->Unlock (surface); #else DFBRectangle rect; rect.x = 0; rect.y = 0; rect.w = width; rect.h = height; surface->Write(surface, &rect, pixels, 4*width); #endif egl_textures[m_bound_texture].surface = surface; #ifdef DEBUG printf("%s:%s[%d] ---------------- texture=%d (%p)\n", __FILE__, __func__, __LINE__, texturesCurrent, egl_textures[texturesCurrent].surface); #endif }
GdkCursor * gdk_cursor_new_for_display (GdkDisplay *display, GdkCursorType cursor_type) { GdkCursor *cursor; GdkDisplayDFB *dfb_display = GDK_DISPLAY_DFB (display); if (cursor_type >= sizeof (stock_cursors) / sizeof (stock_cursors[0])) return NULL; cursor = stock_cursors[cursor_type].cursor; if (!cursor) { GdkCursorDirectFB *private; DFBResult ret; IDirectFBSurface *temp; IDirectFBSurface *temp2; IDirectFBSurface *shape; int width = stock_cursors[cursor_type+1].width; int height = stock_cursors[cursor_type+1].height; temp = gdk_display_dfb_create_surface (dfb_display, DSPF_ARGB, width, height); if (!temp) { return NULL; } else { u32 *dst; int pitch; ret = temp->Lock (temp, DSLF_WRITE, (void**)&dst, &pitch); if (ret) { DirectFBError ("gdkcursor-directfb.c (gdk_cursor_new): " "temp->Lock", ret); temp->Release (temp); return NULL; } else { gint x, y; gint mx, my; gint p = ((stock_cursors[cursor_type].width + 7) / 8) * 8; gint mp = ((stock_cursors[cursor_type + 1].width + 7) / 8) * 8; const guchar *src; const guchar *mask; pitch >>= 2; src = stock_cursors[cursor_type].bits; mask = stock_cursors[cursor_type+1].bits; mx = stock_cursors[cursor_type+1].hotx - stock_cursors[cursor_type].hotx; my = stock_cursors[cursor_type+1].hoty - stock_cursors[cursor_type].hoty; for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { gint bit = x-mx + (y-my) * p; gint mbit = x + y * mp; u32 color = ((x - mx) < 0 || (y - my) < 0 || (x - mx) >= stock_cursors[cursor_type].width || (y - my) >= stock_cursors[cursor_type].height) ? 0x00FFFFFF : (src[bit/8] & (1 << bit%8) ? 0 : 0x00FFFFFF); u8 a = color ? 0xE0 : 0xFF; u32 alpha = mask[mbit/8] & (1 << mbit%8) ? (a << 24) : 0; dst[x + y*pitch] = alpha | color; } } temp->Unlock (temp); } } width += 2; height += 2; temp2 = gdk_display_dfb_create_surface (dfb_display, DSPF_ARGB, width, height); if (!temp2) { temp->Release (temp); return NULL; } temp2->Clear (temp2, 0x80, 0x80, 0x80, 0); temp2->SetBlittingFlags (temp2, (DSBLIT_BLEND_COLORALPHA | DSBLIT_BLEND_ALPHACHANNEL)); temp2->SetColor (temp2, 0, 0, 0, 0x30); temp2->Blit (temp2, temp, NULL, 0, 0); temp2->Blit (temp2, temp, NULL, 0, 2); temp2->Blit (temp2, temp, NULL, 2, 0); temp2->Blit (temp2, temp, NULL, 2, 2); temp2->SetColor (temp2, 0, 0, 0, 0xA0); temp2->Blit (temp2, temp, NULL, 1, 0); temp2->Blit (temp2, temp, NULL, 0, 1); temp2->Blit (temp2, temp, NULL, 2, 1); temp2->Blit (temp2, temp, NULL, 1, 2); temp2->SetColor (temp2, 0, 0, 0, 0xE0); temp2->Blit (temp2, temp, NULL, 1, 1); temp->Release (temp); // creating stretch width = width * 2; height = height * 2; shape = gdk_display_dfb_create_surface (dfb_display, DSPF_ARGB, width, height); if (!shape) { temp2->Release (temp2); return NULL; } shape->StretchBlit(shape, temp2, NULL, NULL); temp2->Release (temp2); private = g_new0 (GdkCursorDirectFB, 1);
int main( int argc, char *argv[] ) { DFBResult ret; int i; DFBSurfaceDescription desc; IDirectFB *dfb; IDirectFBSurface *dest = NULL; DFBSurfacePixelFormat dest_format = DSPF_UNKNOWN; char pixel_buffer[100*100*4]; IDirectFBSurface *source = NULL; IDirectFBEventBuffer *keybuffer; DFBInputEvent evt; bool quit = false; /* Initialize DirectFB. */ ret = DirectFBInit( &argc, &argv ); if (ret) { D_DERROR( ret, "DFBTest/PreAlloc: DirectFBInit() failed!\n" ); return ret; } /* Parse arguments. */ for (i=1; i<argc; i++) { const char *arg = argv[i]; if (strcmp( arg, "-h" ) == 0 || strcmp (arg, "--help") == 0) return print_usage( argv[0] ); else if (strcmp (arg, "-v") == 0 || strcmp (arg, "--version") == 0) { fprintf (stderr, "dfbtest_blit version %s\n", DIRECTFB_VERSION); return false; } else if (strcmp (arg, "-d") == 0 || strcmp (arg, "--dest") == 0) { if (++i == argc) { print_usage (argv[0]); return false; } if (!parse_format( argv[i], &dest_format )) return false; } else if (strcmp (arg, "-s") == 0 || strcmp (arg, "--static") == 0) { static_caps = DSCAPS_STATIC_ALLOC; } else return print_usage( argv[0] ); } /* Create super interface. */ ret = DirectFBCreate( &dfb ); if (ret) { D_DERROR( ret, "DFBTest/PreAlloc: DirectFBCreate() failed!\n" ); return ret; } /* Fill description for a primary surface. */ desc.flags = DSDESC_CAPS; desc.caps = DSCAPS_PRIMARY | DSCAPS_FLIPPING; if (dest_format != DSPF_UNKNOWN) { desc.flags |= DSDESC_PIXELFORMAT; desc.pixelformat = dest_format; } dfb->SetCooperativeLevel( dfb, DFSCL_FULLSCREEN ); /* Create an input buffer for key events */ dfb->CreateInputEventBuffer( dfb, DICAPS_KEYS, DFB_TRUE, &keybuffer); /* Create a primary surface. */ ret = dfb->CreateSurface( dfb, &desc, &dest ); if (ret) { D_DERROR( ret, "DFBTest/PreAlloc: IDirectFB::CreateSurface() for the destination failed!\n" ); goto out; } dest->GetSize( dest, &desc.width, &desc.height ); dest->GetPixelFormat( dest, &desc.pixelformat ); D_INFO( "DFBTest/PreAlloc: Destination is %dx%d using %s\n", desc.width, desc.height, dfb_pixelformat_name(desc.pixelformat) ); /* Create a preallocated surface. */ desc.flags = DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS | DSDESC_PREALLOCATED; desc.width = 100; desc.height = 100; desc.pixelformat = DSPF_ARGB; desc.caps = static_caps; desc.preallocated[0].data = pixel_buffer; desc.preallocated[0].pitch = 100 * 4; ret = dfb->CreateSurface( dfb, &desc, &source ); if (ret) { D_DERROR( ret, "DFBTest/PreAlloc: IDirectFB::CreateSurface() for the preallocated source failed!\n" ); goto out; } /* Before any other operation the pixel data can be written to without locking */ gen_pixels( pixel_buffer, 100 * 4, 100 ); while (!quit) { void *ptr; int pitch; /* Lock source surface for writing before making updates to the pixel buffer */ source->Lock( source, DSLF_WRITE, &ptr, &pitch ); if (ptr == pixel_buffer) D_INFO( "DFBTest/PreAlloc: Locking preallocated source gave original preallocated pixel buffer :-)\n" ); else { if (static_caps) D_INFO( "DFBTest/PreAlloc: Locking preallocated source gave different pixel buffer, ERROR with static alloc!\n" ); else D_INFO( "DFBTest/PreAlloc: Locking preallocated source gave different pixel buffer, but OK (no static alloc)\n" ); } update_pixels( ptr, pitch, 100 ); /* Unlock source surface after writing, before making further Blits, to have the buffer be transfered to master again */ source->Unlock( source ); dest->Clear( dest, 0, 0, 0, 0xff ); /* First Blit from preallocated source, data will be transfered to master */ dest->Blit( dest, source, NULL, 50, 50 ); /* Second Blit from preallocated source, data is already master */ dest->Blit( dest, source, NULL, 150, 150 ); dest->Flip( dest, NULL, DSFLIP_NONE ); /* This will upload again the preallocated buffer to the master, where it is modified and outdates the preallocated buffer. Now it depends on the static alloc flag whether the next Lock will directly go into the shared memory allocation or the preallocated buffer again (with a transfer back from master to us). */ source->FillRectangle( source, 0, 0, 10, 10 ); /* Process keybuffer */ while (keybuffer->GetEvent( keybuffer, DFB_EVENT(&evt)) == DFB_OK) { if (evt.type == DIET_KEYPRESS) { switch (DFB_LOWER_CASE(evt.key_symbol)) { case DIKS_ESCAPE: case DIKS_SMALL_Q: case DIKS_BACK: case DIKS_STOP: case DIKS_EXIT: /* Quit main loop & test thread */ quit = true; break; default: break; } } } if (!quit) sleep( 5 ); } out: if (source) source->Release( source ); if (dest) dest->Release( dest ); keybuffer->Release( keybuffer ); /* Shutdown DirectFB. */ dfb->Release( dfb ); return ret; }