diff options
Diffstat (limited to 'src/gallium/state_trackers')
102 files changed, 3062 insertions, 5113 deletions
diff --git a/src/gallium/state_trackers/dri/common/dri1_helper.c b/src/gallium/state_trackers/dri/common/dri1_helper.c index 7eeb868d422..b0dd974a964 100644 --- a/src/gallium/state_trackers/dri/common/dri1_helper.c +++ b/src/gallium/state_trackers/dri/common/dri1_helper.c @@ -84,7 +84,7 @@ dri1_swap_fences_clear(struct dri_drawable *drawable) } struct pipe_surface * -dri1_get_pipe_surface(struct dri_drawable *drawable, struct pipe_texture *ptex) +dri1_get_pipe_surface(struct dri_drawable *drawable, struct pipe_resource *ptex) { struct pipe_screen *pipe_screen = dri_screen(drawable->sPriv)->pipe_screen; struct pipe_surface *psurf = drawable->dri1_surface; @@ -93,7 +93,7 @@ dri1_get_pipe_surface(struct dri_drawable *drawable, struct pipe_texture *ptex) pipe_surface_reference(&drawable->dri1_surface, NULL); drawable->dri1_surface = pipe_screen->get_tex_surface(pipe_screen, - ptex, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_READ); + ptex, 0, 0, 0, PIPE_BIND_BLIT_SOURCE); psurf = drawable->dri1_surface; } diff --git a/src/gallium/state_trackers/dri/common/dri1_helper.h b/src/gallium/state_trackers/dri/common/dri1_helper.h index 3254b7ff872..c98adf2df22 100644 --- a/src/gallium/state_trackers/dri/common/dri1_helper.h +++ b/src/gallium/state_trackers/dri/common/dri1_helper.h @@ -47,7 +47,7 @@ void dri1_swap_fences_clear(struct dri_drawable *drawable); struct pipe_surface * -dri1_get_pipe_surface(struct dri_drawable *drawable, struct pipe_texture *ptex); +dri1_get_pipe_surface(struct dri_drawable *drawable, struct pipe_resource *ptex); void dri1_destroy_pipe_surface(struct dri_drawable *drawable); diff --git a/src/gallium/state_trackers/dri/common/dri_drawable.h b/src/gallium/state_trackers/dri/common/dri_drawable.h index 98abeb9ec05..315b7781654 100644 --- a/src/gallium/state_trackers/dri/common/dri_drawable.h +++ b/src/gallium/state_trackers/dri/common/dri_drawable.h @@ -55,7 +55,7 @@ struct dri_drawable unsigned old_w; unsigned old_h; - struct pipe_texture *textures[ST_ATTACHMENT_COUNT]; + struct pipe_resource *textures[ST_ATTACHMENT_COUNT]; unsigned int texture_mask, texture_stamp; struct pipe_fence_handle *swap_fences[DRI_SWAP_FENCES_MAX]; diff --git a/src/gallium/state_trackers/dri/common/dri_screen.c b/src/gallium/state_trackers/dri/common/dri_screen.c index 6fc7487071b..83616744ad0 100644 --- a/src/gallium/state_trackers/dri/common/dri_screen.c +++ b/src/gallium/state_trackers/dri/common/dri_screen.c @@ -93,34 +93,34 @@ dri_fill_in_modes(struct dri_screen *screen, pf_x8z24 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_Z24X8_UNORM, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0); + PIPE_BIND_DEPTH_STENCIL, 0); pf_z24x8 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_X8Z24_UNORM, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0); + PIPE_BIND_DEPTH_STENCIL, 0); pf_s8z24 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_Z24_UNORM_S8_USCALED, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0); + PIPE_BIND_DEPTH_STENCIL, 0); pf_z24s8 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_S8_USCALED_Z24_UNORM, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0); + PIPE_BIND_DEPTH_STENCIL, 0); pf_a8r8g8b8 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_B8G8R8A8_UNORM, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_RENDER_TARGET, 0); + PIPE_BIND_RENDER_TARGET, 0); pf_x8r8g8b8 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_RENDER_TARGET, 0); + PIPE_BIND_RENDER_TARGET, 0); pf_r5g6b5 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_B5G6R5_UNORM, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_RENDER_TARGET, 0); + PIPE_BIND_RENDER_TARGET, 0); /* We can only get a 16 or 32 bit depth buffer with getBuffersWithFormat */ if (dri_with_format(screen->sPriv)) { pf_z16 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_Z16_UNORM, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0); + PIPE_BIND_DEPTH_STENCIL, 0); pf_z32 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_Z32_UNORM, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0); + PIPE_BIND_DEPTH_STENCIL, 0); } else { pf_z16 = FALSE; pf_z32 = FALSE; @@ -288,12 +288,14 @@ dri_destroy_option_cache(struct dri_screen * screen) { int i; - for (i = 0; i < (1 << screen->optionCache.tableSize); ++i) { - FREE(screen->optionCache.info[i].name); - FREE(screen->optionCache.info[i].ranges); + if (screen->optionCache.info) { + for (i = 0; i < (1 << screen->optionCache.tableSize); ++i) { + FREE(screen->optionCache.info[i].name); + FREE(screen->optionCache.info[i].ranges); + } + FREE(screen->optionCache.info); } - FREE(screen->optionCache.info); FREE(screen->optionCache.values); } diff --git a/src/gallium/state_trackers/dri/common/dri_st_api.c b/src/gallium/state_trackers/dri/common/dri_st_api.c index 1a5259c68ba..261bae75a28 100644 --- a/src/gallium/state_trackers/dri/common/dri_st_api.c +++ b/src/gallium/state_trackers/dri/common/dri_st_api.c @@ -14,12 +14,13 @@ * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. * * Authors: * Chia-I Wu <olv@lunarg.com> @@ -46,7 +47,7 @@ static boolean dri_st_framebuffer_validate(struct st_framebuffer_iface *stfbi, const enum st_attachment_type *statts, unsigned count, - struct pipe_texture **out) + struct pipe_resource **out) { struct dri_drawable *drawable = (struct dri_drawable *) stfbi->st_manager_private; @@ -99,7 +100,7 @@ dri_st_framebuffer_validate(struct st_framebuffer_iface *stfbi, for (i = 0; i < count; i++) { out[i] = NULL; - pipe_texture_reference(&out[i], drawable->textures[statts[i]]); + pipe_resource_reference(&out[i], drawable->textures[statts[i]]); } return TRUE; @@ -156,7 +157,7 @@ dri_destroy_st_framebuffer(struct st_framebuffer_iface *stfbi) int i; for (i = 0; i < ST_ATTACHMENT_COUNT; i++) - pipe_texture_reference(&drawable->textures[i], NULL); + pipe_resource_reference(&drawable->textures[i], NULL); FREE(stfbi); } @@ -224,6 +225,31 @@ _dri_put_st_api(void) } } +static boolean +dri_st_manager_get_egl_image(struct st_manager *smapi, + struct st_egl_image *stimg) +{ + __DRIimage *img = NULL; + +#ifndef __NOT_HAVE_DRM_H + if (!__dri1_api_hooks) { + struct dri_context *ctx = (struct dri_context *) + stimg->stctxi->st_manager_private; + img = dri2_lookup_egl_image(ctx, stimg->egl_image); + } +#endif + if (!img) + return FALSE; + + stimg->texture = NULL; + pipe_resource_reference(&stimg->texture, img->texture); + stimg->face = img->face; + stimg->level = img->level; + stimg->zslice = img->zslice; + + return TRUE; +} + /** * Create a state tracker manager from the given screen. */ @@ -235,6 +261,7 @@ dri_create_st_manager(struct dri_screen *screen) smapi = CALLOC_STRUCT(st_manager); if (smapi) { smapi->screen = screen->pipe_screen; + smapi->get_egl_image = dri_st_manager_get_egl_image; _dri_get_st_api(); } diff --git a/src/gallium/state_trackers/dri/common/dri_st_api.h b/src/gallium/state_trackers/dri/common/dri_st_api.h index 99a217bfa79..11d86cfbdf7 100644 --- a/src/gallium/state_trackers/dri/common/dri_st_api.h +++ b/src/gallium/state_trackers/dri/common/dri_st_api.h @@ -14,12 +14,13 @@ * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. * * Authors: * Chia-I Wu <olv@lunarg.com> @@ -33,6 +34,15 @@ struct dri_screen; struct dri_drawable; +struct __DRIimageRec { + struct pipe_resource *texture; + unsigned face; + unsigned level; + unsigned zslice; + + void *loader_private; +}; + struct st_api * dri_get_st_api(void); diff --git a/src/gallium/state_trackers/dri/drm/SConscript b/src/gallium/state_trackers/dri/drm/SConscript index b9726ee3113..1dfaa402f2d 100644 --- a/src/gallium/state_trackers/dri/drm/SConscript +++ b/src/gallium/state_trackers/dri/drm/SConscript @@ -7,6 +7,8 @@ if env['dri']: env = env.Clone() + env.ParseConfig('pkg-config --cflags --libs libdrm') + env.Append(CPPPATH = [ '#/src/mesa', '#/src/gallium/state_trackers/dri/common', diff --git a/src/gallium/state_trackers/dri/drm/dri1.c b/src/gallium/state_trackers/dri/drm/dri1.c index cca7cd8f0c3..3cac1557cad 100644 --- a/src/gallium/state_trackers/dri/drm/dri1.c +++ b/src/gallium/state_trackers/dri/drm/dri1.c @@ -172,7 +172,7 @@ dri1_swap_copy(struct pipe_context *pipe, static void dri1_present_texture_locked(__DRIdrawable * dPriv, - struct pipe_texture *ptex, + struct pipe_resource *ptex, const struct drm_clip_rect *sub_box, struct pipe_fence_handle **fence) { @@ -216,7 +216,7 @@ dri1_present_texture_locked(__DRIdrawable * dPriv, static void dri1_copy_to_front(struct dri_context *ctx, - struct pipe_texture *ptex, + struct pipe_resource *ptex, __DRIdrawable * dPriv, const struct drm_clip_rect *sub_box, struct pipe_fence_handle **fence) @@ -254,7 +254,7 @@ dri1_flush_frontbuffer(struct dri_drawable *draw, struct dri_screen *screen = dri_screen(draw->sPriv); struct pipe_screen *pipe_screen = screen->pipe_screen; struct pipe_fence_handle *dummy_fence; - struct pipe_texture *ptex; + struct pipe_resource *ptex; if (!ctx) return; /* For now */ @@ -278,7 +278,7 @@ dri1_swap_buffers(__DRIdrawable * dPriv) struct dri_screen *screen = dri_screen(draw->sPriv); struct pipe_screen *pipe_screen = screen->pipe_screen; struct pipe_fence_handle *fence; - struct pipe_texture *ptex; + struct pipe_resource *ptex; assert(__dri1_api_hooks != NULL); @@ -308,7 +308,7 @@ dri1_copy_sub_buffer(__DRIdrawable * dPriv, int x, int y, int w, int h) struct drm_clip_rect sub_bbox; struct dri_drawable *draw = dri_drawable(dPriv); struct pipe_fence_handle *dummy_fence; - struct pipe_texture *ptex; + struct pipe_resource *ptex; assert(__dri1_api_hooks != NULL); @@ -340,7 +340,7 @@ dri1_allocate_textures(struct dri_drawable *drawable, unsigned mask) { struct dri_screen *screen = dri_screen(drawable->sPriv); - struct pipe_texture templ; + struct pipe_resource templ; unsigned width, height; boolean resized; int i; @@ -354,7 +354,7 @@ dri1_allocate_textures(struct dri_drawable *drawable, /* remove outdated textures */ if (resized) { for (i = 0; i < ST_ATTACHMENT_COUNT; i++) - pipe_texture_reference(&drawable->textures[i], NULL); + pipe_resource_reference(&drawable->textures[i], NULL); } memset(&templ, 0, sizeof(templ)); @@ -379,12 +379,12 @@ dri1_allocate_textures(struct dri_drawable *drawable, case ST_ATTACHMENT_FRONT_RIGHT: case ST_ATTACHMENT_BACK_RIGHT: format = drawable->stvis.color_format; - tex_usage = PIPE_TEXTURE_USAGE_DISPLAY_TARGET | - PIPE_TEXTURE_USAGE_RENDER_TARGET; + tex_usage = PIPE_BIND_DISPLAY_TARGET | + PIPE_BIND_RENDER_TARGET; break; case ST_ATTACHMENT_DEPTH_STENCIL: format = drawable->stvis.depth_stencil_format; - tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL; + tex_usage = PIPE_BIND_DEPTH_STENCIL; break; default: format = PIPE_FORMAT_NONE; @@ -393,10 +393,10 @@ dri1_allocate_textures(struct dri_drawable *drawable, if (format != PIPE_FORMAT_NONE) { templ.format = format; - templ.tex_usage = tex_usage; + templ.bind = tex_usage; drawable->textures[i] = - screen->pipe_screen->texture_create(screen->pipe_screen, &templ); + screen->pipe_screen->resource_create(screen->pipe_screen, &templ); } } diff --git a/src/gallium/state_trackers/dri/drm/dri2.c b/src/gallium/state_trackers/dri/drm/dri2.c index c632f0fe4f3..c6655847e9c 100644 --- a/src/gallium/state_trackers/dri/drm/dri2.c +++ b/src/gallium/state_trackers/dri/drm/dri2.c @@ -77,16 +77,32 @@ dri2_set_tex_buffer2(__DRIcontext *pDRICtx, GLint target, { struct dri_context *ctx = dri_context(pDRICtx); struct dri_drawable *drawable = dri_drawable(dPriv); - struct pipe_texture *pt; + struct pipe_resource *pt; dri_st_framebuffer_validate_att(drawable->stfb, ST_ATTACHMENT_FRONT_LEFT); pt = drawable->textures[ST_ATTACHMENT_FRONT_LEFT]; if (pt) { + enum pipe_format internal_format = pt->format; + + if (format == __DRI_TEXTURE_FORMAT_RGB) { + /* only need to cover the formats recognized by dri_fill_st_visual */ + switch (internal_format) { + case PIPE_FORMAT_B8G8R8A8_UNORM: + internal_format = PIPE_FORMAT_B8G8R8X8_UNORM; + break; + case PIPE_FORMAT_A8R8G8B8_UNORM: + internal_format = PIPE_FORMAT_X8R8G8B8_UNORM; + break; + default: + break; + } + } + ctx->st->teximage(ctx->st, (target == GL_TEXTURE_2D) ? ST_TEXTURE_2D : ST_TEXTURE_RECT, - 0, drawable->stvis.color_format, pt, FALSE); + 0, internal_format, pt, FALSE); } } @@ -130,6 +146,7 @@ dri2_drawable_get_format(struct dri_drawable *drawable, return format; } + /** * Retrieve __DRIbuffer from the DRI loader. */ @@ -235,7 +252,7 @@ dri2_drawable_get_buffers(struct dri_drawable *drawable, } /** - * Process __DRIbuffer and convert them into pipe_textures. + * Process __DRIbuffer and convert them into pipe_resources. */ static void dri2_drawable_process_buffers(struct dri_drawable *drawable, @@ -243,7 +260,7 @@ dri2_drawable_process_buffers(struct dri_drawable *drawable, { struct dri_screen *screen = dri_screen(drawable->sPriv); __DRIdrawable *dri_drawable = drawable->dPriv; - struct pipe_texture templ; + struct pipe_resource templ; struct winsys_handle whandle; boolean have_depth = FALSE; unsigned i; @@ -255,10 +272,10 @@ dri2_drawable_process_buffers(struct dri_drawable *drawable, return; for (i = 0; i < ST_ATTACHMENT_COUNT; i++) - pipe_texture_reference(&drawable->textures[i], NULL); + pipe_resource_reference(&drawable->textures[i], NULL); memset(&templ, 0, sizeof(templ)); - templ.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET; + templ.bind = PIPE_BIND_RENDER_TARGET; templ.target = PIPE_TEXTURE_2D; templ.last_level = 0; templ.width0 = dri_drawable->w; @@ -311,7 +328,7 @@ dri2_drawable_process_buffers(struct dri_drawable *drawable, whandle.stride = buf->pitch; drawable->textures[statt] = - screen->pipe_screen->texture_from_handle(screen->pipe_screen, + screen->pipe_screen->resource_from_handle(screen->pipe_screen, &templ, &whandle); } @@ -352,6 +369,110 @@ dri2_flush_frontbuffer(struct dri_drawable *drawable, } } +__DRIimage * +dri2_lookup_egl_image(struct dri_context *ctx, void *handle) +{ + __DRIimageLookupExtension *loader = ctx->sPriv->dri2.image; + __DRIimage *img; + + if (!loader->lookupEGLImage) + return NULL; + + img = loader->lookupEGLImage(ctx->cPriv, handle, ctx->cPriv->loaderPrivate); + + return img; +} + +static __DRIimage * +dri2_create_image_from_name(__DRIcontext *context, + int width, int height, int format, + int name, int pitch, void *loaderPrivate) +{ + struct dri_screen *screen = dri_screen(context->driScreenPriv); + __DRIimage *img; + struct pipe_resource templ; + struct winsys_handle whandle; + unsigned tex_usage; + enum pipe_format pf; + + tex_usage = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW; + + switch (format) { + case __DRI_IMAGE_FORMAT_RGB565: + pf = PIPE_FORMAT_B5G6R5_UNORM; + break; + case __DRI_IMAGE_FORMAT_XRGB8888: + pf = PIPE_FORMAT_B8G8R8X8_UNORM; + break; + case __DRI_IMAGE_FORMAT_ARGB8888: + pf = PIPE_FORMAT_B8G8R8A8_UNORM; + break; + default: + pf = PIPE_FORMAT_NONE; + break; + } + if (pf == PIPE_FORMAT_NONE) + return NULL; + + img = CALLOC_STRUCT(__DRIimageRec); + if (!img) + return NULL; + + memset(&templ, 0, sizeof(templ)); + templ.bind = tex_usage; + templ.format = pf; + templ.target = PIPE_TEXTURE_2D; + templ.last_level = 0; + templ.width0 = width; + templ.height0 = height; + templ.depth0 = 1; + + memset(&whandle, 0, sizeof(whandle)); + whandle.handle = name; + whandle.stride = pitch * util_format_get_blocksize(pf); + + img->texture = screen->pipe_screen->resource_from_handle(screen->pipe_screen, + &templ, &whandle); + if (!img->texture) { + FREE(img); + return NULL; + } + + img->face = 0; + img->level = 0; + img->zslice = 0; + img->loader_private = loaderPrivate; + + return img; +} + +static __DRIimage * +dri2_create_image_from_renderbuffer(__DRIcontext *context, + int renderbuffer, void *loaderPrivate) +{ + struct dri_context *ctx = dri_context(context->driverPrivate); + + if (!ctx->st->get_resource_for_egl_image) + return NULL; + + /* TODO */ + return NULL; +} + +static void +dri2_destroy_image(__DRIimage *img) +{ + pipe_resource_reference(&img->texture, NULL); + FREE(img); +} + +static struct __DRIimageExtensionRec dri2ImageExtension = { + { __DRI_IMAGE, __DRI_IMAGE_VERSION }, + dri2_create_image_from_name, + dri2_create_image_from_renderbuffer, + dri2_destroy_image, +}; + /* * Backend function init_screen. */ @@ -364,6 +485,7 @@ static const __DRIextension *dri_screen_extensions[] = { &driMediaStreamCounterExtension.base, &dri2TexBufferExtension.base, &dri2FlushExtension.base, + &dri2ImageExtension.base, NULL }; diff --git a/src/gallium/state_trackers/dri/drm/dri2.h b/src/gallium/state_trackers/dri/drm/dri2.h index 379963431fb..5b28850000b 100644 --- a/src/gallium/state_trackers/dri/drm/dri2.h +++ b/src/gallium/state_trackers/dri/drm/dri2.h @@ -43,4 +43,7 @@ dri2_allocate_textures(struct dri_drawable *drawable, const enum st_attachment_type *statts, unsigned count); +__DRIimage * +dri2_lookup_egl_image(struct dri_context *ctx, void *handle); + #endif /* DRI2_H */ diff --git a/src/gallium/state_trackers/dri/sw/drisw.c b/src/gallium/state_trackers/dri/sw/drisw.c index 42fa789aaf7..9106f0d5eb4 100644 --- a/src/gallium/state_trackers/dri/sw/drisw.c +++ b/src/gallium/state_trackers/dri/sw/drisw.c @@ -89,7 +89,7 @@ drisw_put_image(struct dri_drawable *drawable, static INLINE void drisw_present_texture(__DRIdrawable *dPriv, - struct pipe_texture *ptex) + struct pipe_resource *ptex) { struct dri_drawable *drawable = dri_drawable(dPriv); struct dri_screen *screen = dri_screen(drawable->sPriv); @@ -117,7 +117,7 @@ drisw_invalidate_drawable(__DRIdrawable *dPriv) static INLINE void drisw_copy_to_front(__DRIdrawable * dPriv, - struct pipe_texture *ptex) + struct pipe_resource *ptex) { drisw_present_texture(dPriv, ptex); @@ -133,7 +133,7 @@ drisw_swap_buffers(__DRIdrawable *dPriv) { struct dri_context *ctx = dri_get_current(); struct dri_drawable *drawable = dri_drawable(dPriv); - struct pipe_texture *ptex; + struct pipe_resource *ptex; if (!ctx) return; @@ -152,7 +152,7 @@ drisw_flush_frontbuffer(struct dri_drawable *drawable, enum st_attachment_type statt) { struct dri_context *ctx = dri_get_current(); - struct pipe_texture *ptex; + struct pipe_resource *ptex; if (!ctx) return; @@ -180,7 +180,7 @@ drisw_allocate_textures(struct dri_drawable *drawable, unsigned mask) { struct dri_screen *screen = dri_screen(drawable->sPriv); - struct pipe_texture templ; + struct pipe_resource templ; unsigned width, height; boolean resized; int i; @@ -194,7 +194,7 @@ drisw_allocate_textures(struct dri_drawable *drawable, /* remove outdated textures */ if (resized) { for (i = 0; i < ST_ATTACHMENT_COUNT; i++) - pipe_texture_reference(&drawable->textures[i], NULL); + pipe_resource_reference(&drawable->textures[i], NULL); } memset(&templ, 0, sizeof(templ)); @@ -219,12 +219,12 @@ drisw_allocate_textures(struct dri_drawable *drawable, case ST_ATTACHMENT_FRONT_RIGHT: case ST_ATTACHMENT_BACK_RIGHT: format = drawable->stvis.color_format; - tex_usage = PIPE_TEXTURE_USAGE_DISPLAY_TARGET | - PIPE_TEXTURE_USAGE_RENDER_TARGET; + tex_usage = PIPE_BIND_DISPLAY_TARGET | + PIPE_BIND_RENDER_TARGET; break; case ST_ATTACHMENT_DEPTH_STENCIL: format = drawable->stvis.depth_stencil_format; - tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL; + tex_usage = PIPE_BIND_DEPTH_STENCIL; break; default: format = PIPE_FORMAT_NONE; @@ -233,10 +233,10 @@ drisw_allocate_textures(struct dri_drawable *drawable, if (format != PIPE_FORMAT_NONE) { templ.format = format; - templ.tex_usage = tex_usage; + templ.bind = tex_usage; drawable->textures[i] = - screen->pipe_screen->texture_create(screen->pipe_screen, &templ); + screen->pipe_screen->resource_create(screen->pipe_screen, &templ); } } diff --git a/src/gallium/state_trackers/egl/common/egl_g3d.c b/src/gallium/state_trackers/egl/common/egl_g3d.c index 5eabe10558a..3ab72dce2f3 100644 --- a/src/gallium/state_trackers/egl/common/egl_g3d.c +++ b/src/gallium/state_trackers/egl/common/egl_g3d.c @@ -14,70 +14,28 @@ * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. */ -#include <assert.h> -#include <stdio.h> -#include <string.h> -#include "pipe/p_screen.h" -#include "util/u_memory.h" -#include "util/u_rect.h" -#include "util/u_inlines.h" #include "egldriver.h" #include "eglcurrent.h" -#include "eglconfigutil.h" #include "egllog.h" -#include "native.h" +#include "pipe/p_screen.h" +#include "util/u_memory.h" +#include "util/u_format.h" +#include "util/u_string.h" + #include "egl_g3d.h" +#include "egl_g3d_api.h" #include "egl_g3d_st.h" -#include "egl_g3d_image.h" - -/** - * Return the state tracker for the given context. - */ -static struct st_api * -egl_g3d_choose_st(_EGLDriver *drv, _EGLContext *ctx) -{ - struct egl_g3d_driver *gdrv = egl_g3d_driver(drv); - struct st_api *stapi; - EGLint idx = -1; - - switch (ctx->ClientAPI) { - case EGL_OPENGL_ES_API: - switch (ctx->ClientVersion) { - case 1: - idx = ST_API_OPENGL_ES1; - break; - case 2: - idx = ST_API_OPENGL_ES2; - break; - default: - _eglLog(_EGL_WARNING, "unknown client version %d", - ctx->ClientVersion); - break; - } - break; - case EGL_OPENVG_API: - idx = ST_API_OPENVG; - break; - case EGL_OPENGL_API: - idx = ST_API_OPENGL; - break; - default: - _eglLog(_EGL_WARNING, "unknown client API 0x%04x", ctx->ClientAPI); - break; - } - - stapi = (idx >= 0) ? gdrv->stapis[idx] : NULL; - return stapi; -} +#include "native.h" /** * Initialize the state trackers. @@ -157,7 +115,7 @@ egl_g3d_add_screens(_EGLDriver *drv, _EGLDisplay *dpy) gdpy->native->modeset->get_connectors(gdpy->native, &num_connectors, NULL); if (!num_connectors) { if (native_connectors) - free(native_connectors); + FREE(native_connectors); return; } @@ -172,13 +130,13 @@ egl_g3d_add_screens(_EGLDriver *drv, _EGLDisplay *dpy) gdpy->native->modeset->get_modes(gdpy->native, nconn, &num_modes); if (!num_modes) { if (native_modes) - free(native_modes); + FREE(native_modes); continue; } gscr = CALLOC_STRUCT(egl_g3d_screen); if (!gscr) { - free(native_modes); + FREE(native_modes); continue; } @@ -202,41 +160,137 @@ egl_g3d_add_screens(_EGLDriver *drv, _EGLDisplay *dpy) _eglAddScreen(dpy, &gscr->base); } - free(native_connectors); + FREE(native_connectors); } #endif /* EGL_MESA_screen_surface */ /** + * Initialize and validate the EGL config attributes. + */ +static EGLBoolean +init_config_attributes(_EGLConfig *conf, const struct native_config *nconf, + EGLint api_mask, enum pipe_format depth_stencil_format) +{ + uint rgba[4], depth_stencil[2], buffer_size; + EGLint surface_type; + EGLint i; + + /* get the color and depth/stencil component sizes */ + assert(nconf->color_format != PIPE_FORMAT_NONE); + buffer_size = 0; + for (i = 0; i < 4; i++) { + rgba[i] = util_format_get_component_bits(nconf->color_format, + UTIL_FORMAT_COLORSPACE_RGB, i); + buffer_size += rgba[i]; + } + for (i = 0; i < 2; i++) { + if (depth_stencil_format != PIPE_FORMAT_NONE) { + depth_stencil[i] = + util_format_get_component_bits(depth_stencil_format, + UTIL_FORMAT_COLORSPACE_ZS, i); + } + else { + depth_stencil[i] = 0; + } + } + + surface_type = 0x0; + if (nconf->window_bit) + surface_type |= EGL_WINDOW_BIT; + if (nconf->pixmap_bit) + surface_type |= EGL_PIXMAP_BIT; +#ifdef EGL_MESA_screen_surface + if (nconf->scanout_bit) + surface_type |= EGL_SCREEN_BIT_MESA; +#endif + + if (nconf->buffer_mask & (1 << NATIVE_ATTACHMENT_BACK_LEFT)) + surface_type |= EGL_PBUFFER_BIT; + + SET_CONFIG_ATTRIB(conf, EGL_CONFORMANT, api_mask); + SET_CONFIG_ATTRIB(conf, EGL_RENDERABLE_TYPE, api_mask); + + SET_CONFIG_ATTRIB(conf, EGL_RED_SIZE, rgba[0]); + SET_CONFIG_ATTRIB(conf, EGL_GREEN_SIZE, rgba[1]); + SET_CONFIG_ATTRIB(conf, EGL_BLUE_SIZE, rgba[2]); + SET_CONFIG_ATTRIB(conf, EGL_ALPHA_SIZE, rgba[3]); + SET_CONFIG_ATTRIB(conf, EGL_BUFFER_SIZE, buffer_size); + + SET_CONFIG_ATTRIB(conf, EGL_DEPTH_SIZE, depth_stencil[0]); + SET_CONFIG_ATTRIB(conf, EGL_STENCIL_SIZE, depth_stencil[1]); + + SET_CONFIG_ATTRIB(conf, EGL_SURFACE_TYPE, surface_type); + + SET_CONFIG_ATTRIB(conf, EGL_NATIVE_RENDERABLE, EGL_TRUE); + if (surface_type & EGL_WINDOW_BIT) { + SET_CONFIG_ATTRIB(conf, EGL_NATIVE_VISUAL_ID, nconf->native_visual_id); + SET_CONFIG_ATTRIB(conf, EGL_NATIVE_VISUAL_TYPE, + nconf->native_visual_type); + } + + if (surface_type & EGL_PBUFFER_BIT) { + SET_CONFIG_ATTRIB(conf, EGL_BIND_TO_TEXTURE_RGB, EGL_TRUE); + if (rgba[3]) + SET_CONFIG_ATTRIB(conf, EGL_BIND_TO_TEXTURE_RGBA, EGL_TRUE); + + SET_CONFIG_ATTRIB(conf, EGL_MAX_PBUFFER_WIDTH, 4096); + SET_CONFIG_ATTRIB(conf, EGL_MAX_PBUFFER_HEIGHT, 4096); + SET_CONFIG_ATTRIB(conf, EGL_MAX_PBUFFER_PIXELS, 4096 * 4096); + } + + SET_CONFIG_ATTRIB(conf, EGL_LEVEL, nconf->level); + SET_CONFIG_ATTRIB(conf, EGL_SAMPLES, nconf->samples); + SET_CONFIG_ATTRIB(conf, EGL_SAMPLE_BUFFERS, 1); + + if (nconf->slow_config) + SET_CONFIG_ATTRIB(conf, EGL_CONFIG_CAVEAT, EGL_SLOW_CONFIG); + + if (nconf->transparent_rgb) { + rgba[0] = nconf->transparent_rgb_values[0]; + rgba[1] = nconf->transparent_rgb_values[1]; + rgba[2] = nconf->transparent_rgb_values[2]; + + SET_CONFIG_ATTRIB(conf, EGL_TRANSPARENT_TYPE, EGL_TRANSPARENT_RGB); + SET_CONFIG_ATTRIB(conf, EGL_TRANSPARENT_RED_VALUE, rgba[0]); + SET_CONFIG_ATTRIB(conf, EGL_TRANSPARENT_GREEN_VALUE, rgba[1]); + SET_CONFIG_ATTRIB(conf, EGL_TRANSPARENT_BLUE_VALUE, rgba[2]); + } + + return _eglValidateConfig(conf, EGL_FALSE); +} + +/** * Initialize an EGL config from the native config. */ static EGLBoolean egl_g3d_init_config(_EGLDriver *drv, _EGLDisplay *dpy, - _EGLConfig *conf, const struct native_config *nconf) + _EGLConfig *conf, const struct native_config *nconf, + enum pipe_format depth_stencil_format) { struct egl_g3d_driver *gdrv = egl_g3d_driver(drv); struct egl_g3d_config *gconf = egl_g3d_config(conf); - const __GLcontextModes *mode = &nconf->mode; EGLint buffer_mask, api_mask; EGLBoolean valid; EGLint i; - buffer_mask = ST_ATTACHMENT_FRONT_LEFT_MASK; - if (mode->doubleBufferMode) + buffer_mask = 0x0; + if (nconf->buffer_mask & (1 << NATIVE_ATTACHMENT_FRONT_LEFT)) + buffer_mask |= ST_ATTACHMENT_FRONT_LEFT_MASK; + if (nconf->buffer_mask & (1 << NATIVE_ATTACHMENT_BACK_LEFT)) buffer_mask |= ST_ATTACHMENT_BACK_LEFT_MASK; - if (mode->stereoMode) { + if (nconf->buffer_mask & (1 << NATIVE_ATTACHMENT_FRONT_RIGHT)) buffer_mask |= ST_ATTACHMENT_FRONT_RIGHT_MASK; - if (mode->doubleBufferMode) - buffer_mask |= ST_ATTACHMENT_BACK_RIGHT_MASK; - } + if (nconf->buffer_mask & (1 << NATIVE_ATTACHMENT_BACK_RIGHT)) + buffer_mask |= ST_ATTACHMENT_BACK_RIGHT_MASK; gconf->stvis.buffer_mask = buffer_mask; gconf->stvis.color_format = nconf->color_format; - gconf->stvis.depth_stencil_format = nconf->depth_format; + gconf->stvis.depth_stencil_format = depth_stencil_format; gconf->stvis.accum_format = PIPE_FORMAT_NONE; - gconf->stvis.samples = 0; + gconf->stvis.samples = nconf->samples; - gconf->stvis.render_buffer = (buffer_mask & ST_ATTACHMENT_BACK_LEFT) ? + gconf->stvis.render_buffer = (buffer_mask & ST_ATTACHMENT_BACK_LEFT_MASK) ? ST_ATTACHMENT_BACK_LEFT : ST_ATTACHMENT_FRONT_LEFT; api_mask = 0; @@ -248,29 +302,19 @@ egl_g3d_init_config(_EGLDriver *drv, _EGLDisplay *dpy, } } /* this is required by EGL, not by OpenGL ES */ - if ((mode->drawableType & GLX_WINDOW_BIT) && !mode->doubleBufferMode) + if (nconf->window_bit && + gconf->stvis.render_buffer != ST_ATTACHMENT_BACK_LEFT) api_mask &= ~(EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT); if (!api_mask) { _eglLog(_EGL_DEBUG, "no state tracker supports config 0x%x", - mode->visualID); + nconf->native_visual_id); } - valid = _eglConfigFromContextModesRec(&gconf->base, - mode, api_mask, api_mask); - if (valid) { -#ifdef EGL_MESA_screen_surface - /* check if scanout surface bit is set */ - if (nconf->scanout_bit) { - EGLint val = GET_CONFIG_ATTRIB(&gconf->base, EGL_SURFACE_TYPE); - val |= EGL_SCREEN_BIT_MESA; - SET_CONFIG_ATTRIB(&gconf->base, EGL_SURFACE_TYPE, val); - } -#endif - valid = _eglValidateConfig(&gconf->base, EGL_FALSE); - } + valid = init_config_attributes(&gconf->base, + nconf, api_mask, depth_stencil_format); if (!valid) { - _eglLog(_EGL_DEBUG, "skip invalid config 0x%x", mode->visualID); + _eglLog(_EGL_DEBUG, "skip invalid config 0x%x", nconf->native_visual_id); return EGL_FALSE; } @@ -280,6 +324,46 @@ egl_g3d_init_config(_EGLDriver *drv, _EGLDisplay *dpy, } /** + * Get all interested depth/stencil formats of a display. + */ +static EGLint +egl_g3d_fill_depth_stencil_formats(_EGLDisplay *dpy, + enum pipe_format formats[8]) +{ + struct egl_g3d_display *gdpy = egl_g3d_display(dpy); + struct pipe_screen *screen = gdpy->native->screen; + const EGLint candidates[] = { + 1, PIPE_FORMAT_Z16_UNORM, + 1, PIPE_FORMAT_Z32_UNORM, + 2, PIPE_FORMAT_Z24_UNORM_S8_USCALED, PIPE_FORMAT_S8_USCALED_Z24_UNORM, + 2, PIPE_FORMAT_Z24X8_UNORM, PIPE_FORMAT_X8Z24_UNORM, + 0 + }; + const EGLint *fmt = candidates; + EGLint count; + + count = 0; + formats[count++] = PIPE_FORMAT_NONE; + + while (*fmt) { + EGLint i, n = *fmt++; + + /* pick the first supported format */ + for (i = 0; i < n; i++) { + if (screen->is_format_supported(screen, fmt[i], + PIPE_TEXTURE_2D, PIPE_BIND_DEPTH_STENCIL, 0)) { + formats[count++] = fmt[i]; + break; + } + } + + fmt += n; + } + + return count; +} + +/** * Add configs to display and return the next config ID. */ static EGLint @@ -287,32 +371,39 @@ egl_g3d_add_configs(_EGLDriver *drv, _EGLDisplay *dpy, EGLint id) { struct egl_g3d_display *gdpy = egl_g3d_display(dpy); const struct native_config **native_configs; - int num_configs, i; + enum pipe_format depth_stencil_formats[8]; + int num_formats, num_configs, i, j; native_configs = gdpy->native->get_configs(gdpy->native, &num_configs); if (!num_configs) { if (native_configs) - free(native_configs); + FREE(native_configs); return id; } + num_formats = egl_g3d_fill_depth_stencil_formats(dpy, + depth_stencil_formats); + for (i = 0; i < num_configs; i++) { - struct egl_g3d_config *gconf; - - gconf = CALLOC_STRUCT(egl_g3d_config); - if (gconf) { - _eglInitConfig(&gconf->base, dpy, id); - if (!egl_g3d_init_config(drv, dpy, &gconf->base, native_configs[i])) { - free(gconf); - continue; + for (j = 0; j < num_formats; j++) { + struct egl_g3d_config *gconf; + + gconf = CALLOC_STRUCT(egl_g3d_config); + if (gconf) { + _eglInitConfig(&gconf->base, dpy, id); + if (!egl_g3d_init_config(drv, dpy, &gconf->base, + native_configs[i], depth_stencil_formats[j])) { + FREE(gconf); + break; + } + + _eglAddConfig(dpy, &gconf->base); + id++; } - - _eglAddConfig(dpy, &gconf->base); - id++; } } - free(native_configs); + FREE(native_configs); return id; } @@ -353,10 +444,10 @@ egl_g3d_terminate(_EGLDriver *drv, _EGLDisplay *dpy) if (dpy->Screens) { for (i = 0; i < dpy->NumScreens; i++) { struct egl_g3d_screen *gscr = egl_g3d_screen(dpy->Screens[i]); - free(gscr->native_modes); - free(gscr); + FREE(gscr->native_modes); + FREE(gscr); } - free(dpy->Screens); + FREE(dpy->Screens); } if (gdpy->smapi) @@ -365,7 +456,7 @@ egl_g3d_terminate(_EGLDriver *drv, _EGLDisplay *dpy) if (gdpy->native) gdpy->native->destroy(gdpy->native); - free(gdpy); + FREE(gdpy); dpy->DriverData = NULL; return EGL_TRUE; @@ -435,456 +526,6 @@ fail: return EGL_FALSE; } -static _EGLContext * -egl_g3d_create_context(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, - _EGLContext *share, const EGLint *attribs) -{ - struct egl_g3d_display *gdpy = egl_g3d_display(dpy); - struct egl_g3d_context *gshare = egl_g3d_context(share); - struct egl_g3d_config *gconf = egl_g3d_config(conf); - struct egl_g3d_context *gctx; - - gctx = CALLOC_STRUCT(egl_g3d_context); - if (!gctx) { - _eglError(EGL_BAD_ALLOC, "eglCreateContext"); - return NULL; - } - - if (!_eglInitContext(&gctx->base, dpy, conf, attribs)) { - free(gctx); - return NULL; - } - - gctx->stapi = egl_g3d_choose_st(drv, &gctx->base); - if (!gctx->stapi) { - free(gctx); - return NULL; - } - - gctx->stctxi = gctx->stapi->create_context(gctx->stapi, gdpy->smapi, - &gconf->stvis, (gshare) ? gshare->stctxi : NULL); - if (!gctx->stctxi) { - free(gctx); - return NULL; - } - - gctx->stctxi->st_manager_private = (void *) &gctx->base; - - return &gctx->base; -} - -/** - * Destroy a context. - */ -static void -destroy_context(_EGLDisplay *dpy, _EGLContext *ctx) -{ - struct egl_g3d_context *gctx = egl_g3d_context(ctx); - - /* FIXME a context might live longer than its display */ - if (!dpy->Initialized) - _eglLog(_EGL_FATAL, "destroy a context with an unitialized display"); - - gctx->stctxi->destroy(gctx->stctxi); - - free(gctx); -} - -static EGLBoolean -egl_g3d_destroy_context(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx) -{ - if (!_eglIsContextBound(ctx)) - destroy_context(dpy, ctx); - return EGL_TRUE; -} - -struct egl_g3d_create_surface_arg { - EGLint type; - union { - EGLNativeWindowType win; - EGLNativePixmapType pix; - } u; -}; - -static _EGLSurface * -egl_g3d_create_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, - struct egl_g3d_create_surface_arg *arg, - const EGLint *attribs) -{ - struct egl_g3d_display *gdpy = egl_g3d_display(dpy); - struct egl_g3d_config *gconf = egl_g3d_config(conf); - struct egl_g3d_surface *gsurf; - struct native_surface *nsurf; - const char *err; - - switch (arg->type) { - case EGL_WINDOW_BIT: - err = "eglCreateWindowSurface"; - break; - case EGL_PIXMAP_BIT: - err = "eglCreatePixmapSurface"; - break; - case EGL_PBUFFER_BIT: - err = "eglCreatePBufferSurface"; - break; -#ifdef EGL_MESA_screen_surface - case EGL_SCREEN_BIT_MESA: - err = "eglCreateScreenSurface"; - break; -#endif - default: - err = "eglCreateUnknownSurface"; - break; - } - - gsurf = CALLOC_STRUCT(egl_g3d_surface); - if (!gsurf) { - _eglError(EGL_BAD_ALLOC, err); - return NULL; - } - - if (!_eglInitSurface(&gsurf->base, dpy, arg->type, conf, attribs)) { - free(gsurf); - return NULL; - } - - /* create the native surface */ - switch (arg->type) { - case EGL_WINDOW_BIT: - nsurf = gdpy->native->create_window_surface(gdpy->native, - arg->u.win, gconf->native); - break; - case EGL_PIXMAP_BIT: - nsurf = gdpy->native->create_pixmap_surface(gdpy->native, - arg->u.pix, gconf->native); - break; - case EGL_PBUFFER_BIT: - nsurf = gdpy->native->create_pbuffer_surface(gdpy->native, - gconf->native, gsurf->base.Width, gsurf->base.Height); - break; -#ifdef EGL_MESA_screen_surface - case EGL_SCREEN_BIT_MESA: - /* prefer back buffer (move to _eglInitSurface?) */ - gsurf->base.RenderBuffer = EGL_BACK_BUFFER; - nsurf = gdpy->native->modeset->create_scanout_surface(gdpy->native, - gconf->native, gsurf->base.Width, gsurf->base.Height); - break; -#endif - default: - nsurf = NULL; - break; - } - - if (!nsurf) { - free(gsurf); - return NULL; - } - /* initialize the geometry */ - if (!nsurf->validate(nsurf, 0x0, &gsurf->sequence_number, NULL, - &gsurf->base.Width, &gsurf->base.Height)) { - nsurf->destroy(nsurf); - free(gsurf); - return NULL; - } - - gsurf->stvis = gconf->stvis; - if (gsurf->base.RenderBuffer == EGL_SINGLE_BUFFER) - gsurf->stvis.render_buffer = ST_ATTACHMENT_FRONT_LEFT; - - gsurf->stfbi = egl_g3d_create_st_framebuffer(&gsurf->base); - if (!gsurf->stfbi) { - gsurf->native->destroy(gsurf->native); - free(gsurf); - return NULL; - } - - nsurf->user_data = &gsurf->base; - gsurf->native = nsurf; - - return &gsurf->base; -} - -static _EGLSurface * -egl_g3d_create_window_surface(_EGLDriver *drv, _EGLDisplay *dpy, - _EGLConfig *conf, EGLNativeWindowType win, - const EGLint *attribs) -{ - struct egl_g3d_create_surface_arg arg; - - memset(&arg, 0, sizeof(arg)); - arg.type = EGL_WINDOW_BIT; - arg.u.win = win; - - return egl_g3d_create_surface(drv, dpy, conf, &arg, attribs); -} - -static _EGLSurface * -egl_g3d_create_pixmap_surface(_EGLDriver *drv, _EGLDisplay *dpy, - _EGLConfig *conf, EGLNativePixmapType pix, - const EGLint *attribs) -{ - struct egl_g3d_create_surface_arg arg; - - memset(&arg, 0, sizeof(arg)); - arg.type = EGL_PIXMAP_BIT; - arg.u.pix = pix; - - return egl_g3d_create_surface(drv, dpy, conf, &arg, attribs); -} - -static _EGLSurface * -egl_g3d_create_pbuffer_surface(_EGLDriver *drv, _EGLDisplay *dpy, - _EGLConfig *conf, const EGLint *attribs) -{ - struct egl_g3d_create_surface_arg arg; - - memset(&arg, 0, sizeof(arg)); - arg.type = EGL_PBUFFER_BIT; - - return egl_g3d_create_surface(drv, dpy, conf, &arg, attribs); -} - -/** - * Destroy a surface. - */ -static void -destroy_surface(_EGLDisplay *dpy, _EGLSurface *surf) -{ - struct egl_g3d_surface *gsurf = egl_g3d_surface(surf); - - /* FIXME a surface might live longer than its display */ - if (!dpy->Initialized) - _eglLog(_EGL_FATAL, "destroy a surface with an unitialized display"); - - pipe_texture_reference(&gsurf->render_texture, NULL); - egl_g3d_destroy_st_framebuffer(gsurf->stfbi); - gsurf->native->destroy(gsurf->native); - free(gsurf); -} - -static EGLBoolean -egl_g3d_destroy_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf) -{ - if (!_eglIsSurfaceBound(surf)) - destroy_surface(dpy, surf); - return EGL_TRUE; -} - -static EGLBoolean -egl_g3d_make_current(_EGLDriver *drv, _EGLDisplay *dpy, - _EGLSurface *draw, _EGLSurface *read, _EGLContext *ctx) -{ - struct egl_g3d_context *gctx = egl_g3d_context(ctx); - struct egl_g3d_surface *gdraw = egl_g3d_surface(draw); - struct egl_g3d_surface *gread = egl_g3d_surface(read); - struct egl_g3d_context *old_gctx; - EGLBoolean ok = EGL_TRUE; - - /* bind the new context and return the "orphaned" one */ - if (!_eglBindContext(&ctx, &draw, &read)) - return EGL_FALSE; - old_gctx = egl_g3d_context(ctx); - - if (old_gctx) { - /* flush old context */ - old_gctx->stctxi->flush(old_gctx->stctxi, - PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, NULL); - } - - if (gctx) { - ok = gctx->stapi->make_current(gctx->stapi, gctx->stctxi, - (gdraw) ? gdraw->stfbi : NULL, (gread) ? gread->stfbi : NULL); - if (ok) { - gctx->stctxi->notify_invalid_framebuffer(gctx->stctxi, gdraw->stfbi); - if (gread != gdraw) { - gctx->stctxi->notify_invalid_framebuffer(gctx->stctxi, - gread->stfbi); - } - - if (gdraw->base.Type == EGL_WINDOW_BIT) { - gctx->base.WindowRenderBuffer = - (gdraw->stvis.render_buffer == ST_ATTACHMENT_FRONT_LEFT) ? - EGL_SINGLE_BUFFER : EGL_BACK_BUFFER; - } - } - } - else if (old_gctx) { - ok = old_gctx->stapi->make_current(old_gctx->stapi, NULL, NULL, NULL); - old_gctx->base.WindowRenderBuffer = EGL_NONE; - } - - if (ctx && !_eglIsContextLinked(ctx)) - destroy_context(dpy, ctx); - if (draw && !_eglIsSurfaceLinked(draw)) - destroy_surface(dpy, draw); - if (read && read != draw && !_eglIsSurfaceLinked(read)) - destroy_surface(dpy, read); - - return ok; -} - -static EGLBoolean -egl_g3d_swap_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf) -{ - struct egl_g3d_surface *gsurf = egl_g3d_surface(surf); - _EGLContext *ctx = _eglGetCurrentContext(); - struct egl_g3d_context *gctx = NULL; - - /* no-op for pixmap or pbuffer surface */ - if (gsurf->base.Type == EGL_PIXMAP_BIT || - gsurf->base.Type == EGL_PBUFFER_BIT) - return EGL_TRUE; - - /* or when the surface is single-buffered */ - if (gsurf->stvis.render_buffer == ST_ATTACHMENT_FRONT_LEFT) - return EGL_TRUE; - - if (ctx && ctx->DrawSurface == surf) - gctx = egl_g3d_context(ctx); - - /* flush if the surface is current */ - if (gctx) { - gctx->stctxi->flush(gctx->stctxi, - PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, NULL); - } - - return gsurf->native->swap_buffers(gsurf->native); -} - -/** - * Find a config that supports the pixmap. - */ -_EGLConfig * -egl_g3d_find_pixmap_config(_EGLDisplay *dpy, EGLNativePixmapType pix) -{ - struct egl_g3d_display *gdpy = egl_g3d_display(dpy); - struct egl_g3d_config *gconf; - EGLint i; - - for (i = 0; i < dpy->NumConfigs; i++) { - gconf = egl_g3d_config(dpy->Configs[i]); - if (gdpy->native->is_pixmap_supported(gdpy->native, pix, gconf->native)) - break; - } - - return (i < dpy->NumConfigs) ? &gconf->base : NULL; -} - -/** - * Get the pipe surface of the given attachment of the native surface. - */ -static struct pipe_surface * -get_pipe_surface(struct native_display *ndpy, struct native_surface *nsurf, - enum native_attachment natt) -{ - struct pipe_texture *textures[NUM_NATIVE_ATTACHMENTS]; - struct pipe_surface *psurf; - - textures[natt] = NULL; - nsurf->validate(nsurf, 1 << natt, NULL, textures, NULL, NULL); - if (!textures[natt]) - return NULL; - - psurf = ndpy->screen->get_tex_surface(ndpy->screen, textures[natt], - 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE); - pipe_texture_reference(&textures[natt], NULL); - - return psurf; -} - -static EGLBoolean -egl_g3d_copy_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, - EGLNativePixmapType target) -{ - struct egl_g3d_display *gdpy = egl_g3d_display(dpy); - struct egl_g3d_surface *gsurf = egl_g3d_surface(surf); - _EGLContext *ctx = _eglGetCurrentContext(); - struct egl_g3d_config *gconf; - struct native_surface *nsurf; - struct pipe_screen *screen = gdpy->native->screen; - struct pipe_surface *psurf; - - if (!gsurf->render_texture) - return EGL_TRUE; - - gconf = egl_g3d_config(egl_g3d_find_pixmap_config(dpy, target)); - if (!gconf) - return _eglError(EGL_BAD_NATIVE_PIXMAP, "eglCopyBuffers"); - - nsurf = gdpy->native->create_pixmap_surface(gdpy->native, - target, gconf->native); - if (!nsurf) - return _eglError(EGL_BAD_NATIVE_PIXMAP, "eglCopyBuffers"); - - /* flush if the surface is current */ - if (ctx && ctx->DrawSurface == &gsurf->base) { - struct egl_g3d_context *gctx = egl_g3d_context(ctx); - gctx->stctxi->flush(gctx->stctxi, - PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, NULL); - } - - /* create a pipe context to copy surfaces */ - if (!gdpy->pipe) { - gdpy->pipe = - gdpy->native->screen->context_create(gdpy->native->screen, NULL); - if (!gdpy->pipe) - return EGL_FALSE; - } - - psurf = get_pipe_surface(gdpy->native, nsurf, NATIVE_ATTACHMENT_FRONT_LEFT); - if (psurf) { - struct pipe_surface *psrc; - - psrc = screen->get_tex_surface(screen, gsurf->render_texture, - 0, 0, 0, PIPE_BUFFER_USAGE_GPU_READ); - if (psrc) { - gdpy->pipe->surface_copy(gdpy->pipe, psurf, 0, 0, - psrc, 0, 0, psurf->width, psurf->height); - pipe_surface_reference(&psrc, NULL); - - nsurf->flush_frontbuffer(nsurf); - } - - pipe_surface_reference(&psurf, NULL); - } - - nsurf->destroy(nsurf); - - return EGL_TRUE; -} - -static EGLBoolean -egl_g3d_wait_client(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx) -{ - struct egl_g3d_display *gdpy = egl_g3d_display(dpy); - struct egl_g3d_context *gctx = egl_g3d_context(ctx); - struct pipe_screen *screen = gdpy->native->screen; - struct pipe_fence_handle *fence = NULL; - - gctx->stctxi->flush(gctx->stctxi, - PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, &fence); - screen->fence_finish(screen, fence, 0); - screen->fence_reference(screen, &fence, NULL); - - return EGL_TRUE; -} - -static EGLBoolean -egl_g3d_wait_native(_EGLDriver *drv, _EGLDisplay *dpy, EGLint engine) -{ - _EGLContext *ctx = _eglGetCurrentContext(); - - if (engine != EGL_CORE_NATIVE_ENGINE) - return _eglError(EGL_BAD_PARAMETER, "eglWaitNative"); - - if (ctx && ctx->DrawSurface) { - struct egl_g3d_surface *gsurf = egl_g3d_surface(ctx->DrawSurface); - gsurf->native->wait(gsurf->native); - } - - return EGL_TRUE; -} - static _EGLProc egl_g3d_get_proc_address(_EGLDriver *drv, const char *procname) { @@ -907,165 +548,6 @@ egl_g3d_get_proc_address(_EGLDriver *drv, const char *procname) return (_EGLProc) NULL; } -static EGLBoolean -egl_g3d_bind_tex_image(_EGLDriver *drv, _EGLDisplay *dpy, - _EGLSurface *surf, EGLint buffer) -{ - struct egl_g3d_surface *gsurf = egl_g3d_surface(surf); - _EGLContext *es1 = _eglGetAPIContext(EGL_OPENGL_ES_API); - struct egl_g3d_context *gctx; - enum pipe_format internal_format; - enum st_texture_type target; - - if (!gsurf || gsurf->base.Type != EGL_PBUFFER_BIT) - return _eglError(EGL_BAD_SURFACE, "eglBindTexImage"); - if (buffer != EGL_BACK_BUFFER) - return _eglError(EGL_BAD_PARAMETER, "eglBindTexImage"); - if (gsurf->base.BoundToTexture) - return _eglError(EGL_BAD_ACCESS, "eglBindTexImage"); - - switch (gsurf->base.TextureFormat) { - case EGL_TEXTURE_RGB: - internal_format = PIPE_FORMAT_R8G8B8_UNORM; - break; - case EGL_TEXTURE_RGBA: - internal_format = PIPE_FORMAT_B8G8R8A8_UNORM; - break; - default: - return _eglError(EGL_BAD_MATCH, "eglBindTexImage"); - } - - switch (gsurf->base.TextureTarget) { - case EGL_TEXTURE_2D: - target = ST_TEXTURE_2D; - break; - default: - return _eglError(EGL_BAD_MATCH, "eglBindTexImage"); - } - - if (!es1) - return EGL_TRUE; - if (!gsurf->render_texture) - return EGL_FALSE; - - /* flush properly if the surface is bound */ - if (gsurf->base.CurrentContext) { - gctx = egl_g3d_context(gsurf->base.CurrentContext); - gctx->stctxi->flush(gctx->stctxi, - PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, NULL); - } - - gctx = egl_g3d_context(es1); - if (gctx->stctxi->teximage) { - if (!gctx->stctxi->teximage(gctx->stctxi, target, - gsurf->base.MipmapLevel, internal_format, - gsurf->render_texture, gsurf->base.MipmapTexture)) - return EGL_FALSE; - gsurf->base.BoundToTexture = EGL_TRUE; - } - - return EGL_TRUE; -} - -static EGLBoolean -egl_g3d_release_tex_image(_EGLDriver *drv, _EGLDisplay *dpy, - _EGLSurface *surf, EGLint buffer) -{ - struct egl_g3d_surface *gsurf = egl_g3d_surface(surf); - - if (!gsurf || gsurf->base.Type != EGL_PBUFFER_BIT || - !gsurf->base.BoundToTexture) - return _eglError(EGL_BAD_SURFACE, "eglReleaseTexImage"); - if (buffer != EGL_BACK_BUFFER) - return _eglError(EGL_BAD_PARAMETER, "eglReleaseTexImage"); - - if (gsurf->render_texture) { - _EGLContext *ctx = _eglGetAPIContext(EGL_OPENGL_ES_API); - struct egl_g3d_context *gctx = egl_g3d_context(ctx); - - /* what if the context the surface binds to is no longer current? */ - if (gctx) { - gctx->stctxi->teximage(gctx->stctxi, ST_TEXTURE_2D, - gsurf->base.MipmapLevel, PIPE_FORMAT_NONE, NULL, FALSE); - } - } - - gsurf->base.BoundToTexture = EGL_FALSE; - - return EGL_TRUE; -} - -#ifdef EGL_MESA_screen_surface - -static _EGLSurface * -egl_g3d_create_screen_surface(_EGLDriver *drv, _EGLDisplay *dpy, - _EGLConfig *conf, const EGLint *attribs) -{ - struct egl_g3d_create_surface_arg arg; - - memset(&arg, 0, sizeof(arg)); - arg.type = EGL_SCREEN_BIT_MESA; - - return egl_g3d_create_surface(drv, dpy, conf, &arg, attribs); -} - -static EGLBoolean -egl_g3d_show_screen_surface(_EGLDriver *drv, _EGLDisplay *dpy, - _EGLScreen *scr, _EGLSurface *surf, - _EGLMode *mode) -{ - struct egl_g3d_display *gdpy = egl_g3d_display(dpy); - struct egl_g3d_screen *gscr = egl_g3d_screen(scr); - struct egl_g3d_surface *gsurf = egl_g3d_surface(surf); - struct native_surface *nsurf; - const struct native_mode *nmode; - EGLBoolean changed; - - if (gsurf) { - EGLint idx; - - if (!mode) - return _eglError(EGL_BAD_MATCH, "eglShowSurfaceMESA"); - if (gsurf->base.Type != EGL_SCREEN_BIT_MESA) - return _eglError(EGL_BAD_SURFACE, "eglShowScreenSurfaceMESA"); - if (gsurf->base.Width < mode->Width || gsurf->base.Height < mode->Height) - return _eglError(EGL_BAD_MATCH, - "eglShowSurfaceMESA(surface smaller than mode size)"); - - /* find the index of the mode */ - for (idx = 0; idx < gscr->base.NumModes; idx++) - if (mode == &gscr->base.Modes[idx]) - break; - if (idx >= gscr->base.NumModes) { - return _eglError(EGL_BAD_MODE_MESA, - "eglShowSurfaceMESA(unknown mode)"); - } - - nsurf = gsurf->native; - nmode = gscr->native_modes[idx]; - } - else { - if (mode) - return _eglError(EGL_BAD_MATCH, "eglShowSurfaceMESA"); - - /* disable the screen */ - nsurf = NULL; - nmode = NULL; - } - - /* TODO surface panning by CRTC choosing */ - changed = gdpy->native->modeset->program(gdpy->native, 0, nsurf, - gscr->base.OriginX, gscr->base.OriginY, &gscr->native, 1, nmode); - if (changed) { - gscr->base.CurrentSurface = &gsurf->base; - gscr->base.CurrentMode = mode; - } - - return changed; -} - -#endif /* EGL_MESA_screen_surface */ - static EGLint egl_g3d_probe(_EGLDriver *drv, _EGLDisplay *dpy) { @@ -1107,7 +589,7 @@ egl_g3d_unload(_EGLDriver *drv) } egl_g3d_destroy_probe(drv, NULL); - free(gdrv); + FREE(gdrv); } _EGLDriver * @@ -1116,41 +598,18 @@ _eglMain(const char *args) static char driver_name[64]; struct egl_g3d_driver *gdrv; - snprintf(driver_name, sizeof(driver_name), + util_snprintf(driver_name, sizeof(driver_name), "Gallium/%s", native_get_name()); gdrv = CALLOC_STRUCT(egl_g3d_driver); if (!gdrv) return NULL; - _eglInitDriverFallbacks(&gdrv->base); - + egl_g3d_init_driver_api(&gdrv->base); gdrv->base.API.Initialize = egl_g3d_initialize; gdrv->base.API.Terminate = egl_g3d_terminate; - gdrv->base.API.CreateContext = egl_g3d_create_context; - gdrv->base.API.DestroyContext = egl_g3d_destroy_context; - gdrv->base.API.CreateWindowSurface = egl_g3d_create_window_surface; - gdrv->base.API.CreatePixmapSurface = egl_g3d_create_pixmap_surface; - gdrv->base.API.CreatePbufferSurface = egl_g3d_create_pbuffer_surface; - gdrv->base.API.DestroySurface = egl_g3d_destroy_surface; - gdrv->base.API.MakeCurrent = egl_g3d_make_current; - gdrv->base.API.SwapBuffers = egl_g3d_swap_buffers; - gdrv->base.API.CopyBuffers = egl_g3d_copy_buffers; - gdrv->base.API.WaitClient = egl_g3d_wait_client; - gdrv->base.API.WaitNative = egl_g3d_wait_native; gdrv->base.API.GetProcAddress = egl_g3d_get_proc_address; - gdrv->base.API.BindTexImage = egl_g3d_bind_tex_image; - gdrv->base.API.ReleaseTexImage = egl_g3d_release_tex_image; - - gdrv->base.API.CreateImageKHR = egl_g3d_create_image; - gdrv->base.API.DestroyImageKHR = egl_g3d_destroy_image; - -#ifdef EGL_MESA_screen_surface - gdrv->base.API.CreateScreenSurfaceMESA = egl_g3d_create_screen_surface; - gdrv->base.API.ShowScreenSurfaceMESA = egl_g3d_show_screen_surface; -#endif - gdrv->base.Name = driver_name; gdrv->base.Probe = egl_g3d_probe; gdrv->base.Unload = egl_g3d_unload; diff --git a/src/gallium/state_trackers/egl/common/egl_g3d.h b/src/gallium/state_trackers/egl/common/egl_g3d.h index 2788f1bf4ac..5a3c80b9689 100644 --- a/src/gallium/state_trackers/egl/common/egl_g3d.h +++ b/src/gallium/state_trackers/egl/common/egl_g3d.h @@ -14,12 +14,13 @@ * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. */ #ifndef _EGL_G3D_H_ @@ -70,8 +71,10 @@ struct egl_g3d_surface { struct st_visual stvis; struct st_framebuffer_iface *stfbi; + /* the native surface; NULL for pbuffers */ struct native_surface *native; - struct pipe_texture *render_texture; + struct pipe_resource *render_texture; + unsigned int sequence_number; }; @@ -83,7 +86,7 @@ struct egl_g3d_config { struct egl_g3d_image { _EGLImage base; - struct pipe_texture *texture; + struct pipe_resource *texture; unsigned face; unsigned level; unsigned zslice; @@ -100,8 +103,4 @@ _EGL_DRIVER_STANDARD_TYPECASTS(egl_g3d) _EGL_DRIVER_TYPECAST(egl_g3d_screen, _EGLScreen, obj) _EGL_DRIVER_TYPECAST(egl_g3d_image, _EGLImage, obj) - -_EGLConfig * -egl_g3d_find_pixmap_config(_EGLDisplay *dpy, EGLNativePixmapType pix); - #endif /* _EGL_G3D_H_ */ diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_api.c b/src/gallium/state_trackers/egl/common/egl_g3d_api.c new file mode 100644 index 00000000000..478516453ce --- /dev/null +++ b/src/gallium/state_trackers/egl/common/egl_g3d_api.c @@ -0,0 +1,731 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2009-2010 Chia-I Wu <olv@0xlab.org> + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include "egldriver.h" +#include "eglcurrent.h" +#include "egllog.h" + +#include "pipe/p_screen.h" +#include "util/u_memory.h" +#include "util/u_inlines.h" + +#include "egl_g3d.h" +#include "egl_g3d_api.h" +#include "egl_g3d_image.h" +#include "egl_g3d_st.h" +#include "native.h" + +/** + * Return the state tracker for the given context. + */ +static struct st_api * +egl_g3d_choose_st(_EGLDriver *drv, _EGLContext *ctx) +{ + struct egl_g3d_driver *gdrv = egl_g3d_driver(drv); + struct st_api *stapi; + EGLint idx = -1; + + switch (ctx->ClientAPI) { + case EGL_OPENGL_ES_API: + switch (ctx->ClientVersion) { + case 1: + idx = ST_API_OPENGL_ES1; + break; + case 2: + idx = ST_API_OPENGL_ES2; + break; + default: + _eglLog(_EGL_WARNING, "unknown client version %d", + ctx->ClientVersion); + break; + } + break; + case EGL_OPENVG_API: + idx = ST_API_OPENVG; + break; + case EGL_OPENGL_API: + idx = ST_API_OPENGL; + break; + default: + _eglLog(_EGL_WARNING, "unknown client API 0x%04x", ctx->ClientAPI); + break; + } + + stapi = (idx >= 0) ? gdrv->stapis[idx] : NULL; + return stapi; +} + +static _EGLContext * +egl_g3d_create_context(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, + _EGLContext *share, const EGLint *attribs) +{ + struct egl_g3d_display *gdpy = egl_g3d_display(dpy); + struct egl_g3d_context *gshare = egl_g3d_context(share); + struct egl_g3d_config *gconf = egl_g3d_config(conf); + struct egl_g3d_context *gctx; + + gctx = CALLOC_STRUCT(egl_g3d_context); + if (!gctx) { + _eglError(EGL_BAD_ALLOC, "eglCreateContext"); + return NULL; + } + + if (!_eglInitContext(&gctx->base, dpy, conf, attribs)) { + FREE(gctx); + return NULL; + } + + gctx->stapi = egl_g3d_choose_st(drv, &gctx->base); + if (!gctx->stapi) { + FREE(gctx); + return NULL; + } + + gctx->stctxi = gctx->stapi->create_context(gctx->stapi, gdpy->smapi, + &gconf->stvis, (gshare) ? gshare->stctxi : NULL); + if (!gctx->stctxi) { + FREE(gctx); + return NULL; + } + + gctx->stctxi->st_manager_private = (void *) &gctx->base; + + return &gctx->base; +} + +/** + * Destroy a context. + */ +static void +destroy_context(_EGLDisplay *dpy, _EGLContext *ctx) +{ + struct egl_g3d_context *gctx = egl_g3d_context(ctx); + + /* FIXME a context might live longer than its display */ + if (!dpy->Initialized) + _eglLog(_EGL_FATAL, "destroy a context with an unitialized display"); + + gctx->stctxi->destroy(gctx->stctxi); + + FREE(gctx); +} + +static EGLBoolean +egl_g3d_destroy_context(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx) +{ + if (!_eglIsContextBound(ctx)) + destroy_context(dpy, ctx); + return EGL_TRUE; +} + +struct egl_g3d_create_surface_arg { + EGLint type; + union { + EGLNativeWindowType win; + EGLNativePixmapType pix; + } u; +}; + +static _EGLSurface * +egl_g3d_create_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, + struct egl_g3d_create_surface_arg *arg, + const EGLint *attribs) +{ + struct egl_g3d_display *gdpy = egl_g3d_display(dpy); + struct egl_g3d_config *gconf = egl_g3d_config(conf); + struct egl_g3d_surface *gsurf; + struct native_surface *nsurf; + const char *err; + + switch (arg->type) { + case EGL_WINDOW_BIT: + err = "eglCreateWindowSurface"; + break; + case EGL_PIXMAP_BIT: + err = "eglCreatePixmapSurface"; + break; +#ifdef EGL_MESA_screen_surface + case EGL_SCREEN_BIT_MESA: + err = "eglCreateScreenSurface"; + break; +#endif + default: + err = "eglCreateUnknownSurface"; + break; + } + + gsurf = CALLOC_STRUCT(egl_g3d_surface); + if (!gsurf) { + _eglError(EGL_BAD_ALLOC, err); + return NULL; + } + + if (!_eglInitSurface(&gsurf->base, dpy, arg->type, conf, attribs)) { + FREE(gsurf); + return NULL; + } + + /* create the native surface */ + switch (arg->type) { + case EGL_WINDOW_BIT: + nsurf = gdpy->native->create_window_surface(gdpy->native, + arg->u.win, gconf->native); + break; + case EGL_PIXMAP_BIT: + nsurf = gdpy->native->create_pixmap_surface(gdpy->native, + arg->u.pix, gconf->native); + break; +#ifdef EGL_MESA_screen_surface + case EGL_SCREEN_BIT_MESA: + /* prefer back buffer (move to _eglInitSurface?) */ + gsurf->base.RenderBuffer = EGL_BACK_BUFFER; + nsurf = gdpy->native->modeset->create_scanout_surface(gdpy->native, + gconf->native, gsurf->base.Width, gsurf->base.Height); + break; +#endif + default: + nsurf = NULL; + break; + } + + if (!nsurf) { + FREE(gsurf); + return NULL; + } + /* initialize the geometry */ + if (!nsurf->validate(nsurf, 0x0, &gsurf->sequence_number, NULL, + &gsurf->base.Width, &gsurf->base.Height)) { + nsurf->destroy(nsurf); + FREE(gsurf); + return NULL; + } + + gsurf->stvis = gconf->stvis; + if (gsurf->base.RenderBuffer == EGL_SINGLE_BUFFER) + gsurf->stvis.render_buffer = ST_ATTACHMENT_FRONT_LEFT; + + gsurf->stfbi = egl_g3d_create_st_framebuffer(&gsurf->base); + if (!gsurf->stfbi) { + nsurf->destroy(nsurf); + FREE(gsurf); + return NULL; + } + + nsurf->user_data = &gsurf->base; + gsurf->native = nsurf; + + return &gsurf->base; +} + +static _EGLSurface * +egl_g3d_create_window_surface(_EGLDriver *drv, _EGLDisplay *dpy, + _EGLConfig *conf, EGLNativeWindowType win, + const EGLint *attribs) +{ + struct egl_g3d_create_surface_arg arg; + + memset(&arg, 0, sizeof(arg)); + arg.type = EGL_WINDOW_BIT; + arg.u.win = win; + + return egl_g3d_create_surface(drv, dpy, conf, &arg, attribs); +} + +static _EGLSurface * +egl_g3d_create_pixmap_surface(_EGLDriver *drv, _EGLDisplay *dpy, + _EGLConfig *conf, EGLNativePixmapType pix, + const EGLint *attribs) +{ + struct egl_g3d_create_surface_arg arg; + + memset(&arg, 0, sizeof(arg)); + arg.type = EGL_PIXMAP_BIT; + arg.u.pix = pix; + + return egl_g3d_create_surface(drv, dpy, conf, &arg, attribs); +} + +static _EGLSurface * +egl_g3d_create_pbuffer_surface(_EGLDriver *drv, _EGLDisplay *dpy, + _EGLConfig *conf, const EGLint *attribs) +{ + struct egl_g3d_config *gconf = egl_g3d_config(conf); + struct egl_g3d_surface *gsurf; + + gsurf = CALLOC_STRUCT(egl_g3d_surface); + if (!gsurf) { + _eglError(EGL_BAD_ALLOC, "eglCreatePbufferSurface"); + return NULL; + } + + if (!_eglInitSurface(&gsurf->base, dpy, EGL_PBUFFER_BIT, conf, attribs)) { + FREE(gsurf); + return NULL; + } + + gsurf->stvis = gconf->stvis; + + gsurf->stfbi = egl_g3d_create_st_framebuffer(&gsurf->base); + if (!gsurf->stfbi) { + FREE(gsurf); + return NULL; + } + + return &gsurf->base; +} + +/** + * Destroy a surface. + */ +static void +destroy_surface(_EGLDisplay *dpy, _EGLSurface *surf) +{ + struct egl_g3d_surface *gsurf = egl_g3d_surface(surf); + + /* FIXME a surface might live longer than its display */ + if (!dpy->Initialized) + _eglLog(_EGL_FATAL, "destroy a surface with an unitialized display"); + + pipe_resource_reference(&gsurf->render_texture, NULL); + egl_g3d_destroy_st_framebuffer(gsurf->stfbi); + if (gsurf->native) + gsurf->native->destroy(gsurf->native); + FREE(gsurf); +} + +static EGLBoolean +egl_g3d_destroy_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf) +{ + if (!_eglIsSurfaceBound(surf)) + destroy_surface(dpy, surf); + return EGL_TRUE; +} + +static EGLBoolean +egl_g3d_make_current(_EGLDriver *drv, _EGLDisplay *dpy, + _EGLSurface *draw, _EGLSurface *read, _EGLContext *ctx) +{ + struct egl_g3d_context *gctx = egl_g3d_context(ctx); + struct egl_g3d_surface *gdraw = egl_g3d_surface(draw); + struct egl_g3d_surface *gread = egl_g3d_surface(read); + struct egl_g3d_context *old_gctx; + EGLBoolean ok = EGL_TRUE; + + /* bind the new context and return the "orphaned" one */ + if (!_eglBindContext(&ctx, &draw, &read)) + return EGL_FALSE; + old_gctx = egl_g3d_context(ctx); + + if (old_gctx) { + /* flush old context */ + old_gctx->stctxi->flush(old_gctx->stctxi, + PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, NULL); + } + + if (gctx) { + ok = gctx->stapi->make_current(gctx->stapi, gctx->stctxi, + (gdraw) ? gdraw->stfbi : NULL, (gread) ? gread->stfbi : NULL); + if (ok) { + gctx->stctxi->notify_invalid_framebuffer(gctx->stctxi, gdraw->stfbi); + if (gread != gdraw) { + gctx->stctxi->notify_invalid_framebuffer(gctx->stctxi, + gread->stfbi); + } + + if (gdraw->base.Type == EGL_WINDOW_BIT) { + gctx->base.WindowRenderBuffer = + (gdraw->stvis.render_buffer == ST_ATTACHMENT_FRONT_LEFT) ? + EGL_SINGLE_BUFFER : EGL_BACK_BUFFER; + } + } + } + else if (old_gctx) { + ok = old_gctx->stapi->make_current(old_gctx->stapi, NULL, NULL, NULL); + old_gctx->base.WindowRenderBuffer = EGL_NONE; + } + + if (ctx && !_eglIsContextLinked(ctx)) + destroy_context(dpy, ctx); + if (draw && !_eglIsSurfaceLinked(draw)) + destroy_surface(dpy, draw); + if (read && read != draw && !_eglIsSurfaceLinked(read)) + destroy_surface(dpy, read); + + return ok; +} + +static EGLBoolean +egl_g3d_swap_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf) +{ + struct egl_g3d_surface *gsurf = egl_g3d_surface(surf); + _EGLContext *ctx = _eglGetCurrentContext(); + struct egl_g3d_context *gctx = NULL; + + /* no-op for pixmap or pbuffer surface */ + if (gsurf->base.Type == EGL_PIXMAP_BIT || + gsurf->base.Type == EGL_PBUFFER_BIT) + return EGL_TRUE; + + /* or when the surface is single-buffered */ + if (gsurf->stvis.render_buffer == ST_ATTACHMENT_FRONT_LEFT) + return EGL_TRUE; + + if (ctx && ctx->DrawSurface == surf) + gctx = egl_g3d_context(ctx); + + /* flush if the surface is current */ + if (gctx) { + gctx->stctxi->flush(gctx->stctxi, + PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, NULL); + } + + return gsurf->native->swap_buffers(gsurf->native); +} + +/** + * Get the pipe surface of the given attachment of the native surface. + */ +static struct pipe_surface * +get_pipe_surface(struct native_display *ndpy, struct native_surface *nsurf, + enum native_attachment natt, + unsigned bind) +{ + struct pipe_resource *textures[NUM_NATIVE_ATTACHMENTS]; + struct pipe_surface *psurf; + + textures[natt] = NULL; + nsurf->validate(nsurf, 1 << natt, NULL, textures, NULL, NULL); + if (!textures[natt]) + return NULL; + + psurf = ndpy->screen->get_tex_surface(ndpy->screen, textures[natt], + 0, 0, 0, bind); + pipe_resource_reference(&textures[natt], NULL); + + return psurf; +} + +static EGLBoolean +egl_g3d_copy_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, + EGLNativePixmapType target) +{ + struct egl_g3d_display *gdpy = egl_g3d_display(dpy); + struct egl_g3d_surface *gsurf = egl_g3d_surface(surf); + _EGLContext *ctx = _eglGetCurrentContext(); + struct egl_g3d_config *gconf; + struct native_surface *nsurf; + struct pipe_screen *screen = gdpy->native->screen; + struct pipe_surface *psurf; + + if (!gsurf->render_texture) + return EGL_TRUE; + + gconf = egl_g3d_config(egl_g3d_find_pixmap_config(dpy, target)); + if (!gconf) + return _eglError(EGL_BAD_NATIVE_PIXMAP, "eglCopyBuffers"); + + nsurf = gdpy->native->create_pixmap_surface(gdpy->native, + target, gconf->native); + if (!nsurf) + return _eglError(EGL_BAD_NATIVE_PIXMAP, "eglCopyBuffers"); + + /* flush if the surface is current */ + if (ctx && ctx->DrawSurface == &gsurf->base) { + struct egl_g3d_context *gctx = egl_g3d_context(ctx); + gctx->stctxi->flush(gctx->stctxi, + PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, NULL); + } + + /* create a pipe context to copy surfaces */ + if (!gdpy->pipe) { + gdpy->pipe = + gdpy->native->screen->context_create(gdpy->native->screen, NULL); + if (!gdpy->pipe) + return EGL_FALSE; + } + + psurf = get_pipe_surface(gdpy->native, nsurf, NATIVE_ATTACHMENT_FRONT_LEFT, + PIPE_BIND_BLIT_DESTINATION); + if (psurf) { + struct pipe_surface *psrc; + + psrc = screen->get_tex_surface(screen, gsurf->render_texture, + 0, 0, 0, PIPE_BIND_BLIT_SOURCE); + if (psrc) { + gdpy->pipe->surface_copy(gdpy->pipe, psurf, 0, 0, + psrc, 0, 0, psurf->width, psurf->height); + pipe_surface_reference(&psrc, NULL); + + nsurf->flush_frontbuffer(nsurf); + } + + pipe_surface_reference(&psurf, NULL); + } + + nsurf->destroy(nsurf); + + return EGL_TRUE; +} + +static EGLBoolean +egl_g3d_wait_client(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx) +{ + struct egl_g3d_display *gdpy = egl_g3d_display(dpy); + struct egl_g3d_context *gctx = egl_g3d_context(ctx); + struct pipe_screen *screen = gdpy->native->screen; + struct pipe_fence_handle *fence = NULL; + + gctx->stctxi->flush(gctx->stctxi, + PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, &fence); + screen->fence_finish(screen, fence, 0); + screen->fence_reference(screen, &fence, NULL); + + return EGL_TRUE; +} + +static EGLBoolean +egl_g3d_wait_native(_EGLDriver *drv, _EGLDisplay *dpy, EGLint engine) +{ + _EGLContext *ctx = _eglGetCurrentContext(); + + if (engine != EGL_CORE_NATIVE_ENGINE) + return _eglError(EGL_BAD_PARAMETER, "eglWaitNative"); + + if (ctx && ctx->DrawSurface) { + struct egl_g3d_surface *gsurf = egl_g3d_surface(ctx->DrawSurface); + + if (gsurf->native) + gsurf->native->wait(gsurf->native); + } + + return EGL_TRUE; +} + +static EGLBoolean +egl_g3d_bind_tex_image(_EGLDriver *drv, _EGLDisplay *dpy, + _EGLSurface *surf, EGLint buffer) +{ + struct egl_g3d_surface *gsurf = egl_g3d_surface(surf); + _EGLContext *es1 = _eglGetAPIContext(EGL_OPENGL_ES_API); + struct egl_g3d_context *gctx; + enum pipe_format internal_format; + enum st_texture_type target; + + if (!gsurf || gsurf->base.Type != EGL_PBUFFER_BIT) + return _eglError(EGL_BAD_SURFACE, "eglBindTexImage"); + if (buffer != EGL_BACK_BUFFER) + return _eglError(EGL_BAD_PARAMETER, "eglBindTexImage"); + if (gsurf->base.BoundToTexture) + return _eglError(EGL_BAD_ACCESS, "eglBindTexImage"); + + switch (gsurf->base.TextureFormat) { + case EGL_TEXTURE_RGB: + internal_format = PIPE_FORMAT_R8G8B8_UNORM; + break; + case EGL_TEXTURE_RGBA: + internal_format = PIPE_FORMAT_B8G8R8A8_UNORM; + break; + default: + return _eglError(EGL_BAD_MATCH, "eglBindTexImage"); + } + + switch (gsurf->base.TextureTarget) { + case EGL_TEXTURE_2D: + target = ST_TEXTURE_2D; + break; + default: + return _eglError(EGL_BAD_MATCH, "eglBindTexImage"); + } + + if (!es1) + return EGL_TRUE; + if (!gsurf->render_texture) + return EGL_FALSE; + + /* flush properly if the surface is bound */ + if (gsurf->base.CurrentContext) { + gctx = egl_g3d_context(gsurf->base.CurrentContext); + gctx->stctxi->flush(gctx->stctxi, + PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, NULL); + } + + gctx = egl_g3d_context(es1); + if (gctx->stctxi->teximage) { + if (!gctx->stctxi->teximage(gctx->stctxi, target, + gsurf->base.MipmapLevel, internal_format, + gsurf->render_texture, gsurf->base.MipmapTexture)) + return EGL_FALSE; + gsurf->base.BoundToTexture = EGL_TRUE; + } + + return EGL_TRUE; +} + +static EGLBoolean +egl_g3d_release_tex_image(_EGLDriver *drv, _EGLDisplay *dpy, + _EGLSurface *surf, EGLint buffer) +{ + struct egl_g3d_surface *gsurf = egl_g3d_surface(surf); + + if (!gsurf || gsurf->base.Type != EGL_PBUFFER_BIT || + !gsurf->base.BoundToTexture) + return _eglError(EGL_BAD_SURFACE, "eglReleaseTexImage"); + if (buffer != EGL_BACK_BUFFER) + return _eglError(EGL_BAD_PARAMETER, "eglReleaseTexImage"); + + if (gsurf->render_texture) { + _EGLContext *ctx = _eglGetAPIContext(EGL_OPENGL_ES_API); + struct egl_g3d_context *gctx = egl_g3d_context(ctx); + + /* what if the context the surface binds to is no longer current? */ + if (gctx) { + gctx->stctxi->teximage(gctx->stctxi, ST_TEXTURE_2D, + gsurf->base.MipmapLevel, PIPE_FORMAT_NONE, NULL, FALSE); + } + } + + gsurf->base.BoundToTexture = EGL_FALSE; + + return EGL_TRUE; +} + +#ifdef EGL_MESA_screen_surface + +static _EGLSurface * +egl_g3d_create_screen_surface(_EGLDriver *drv, _EGLDisplay *dpy, + _EGLConfig *conf, const EGLint *attribs) +{ + struct egl_g3d_create_surface_arg arg; + + memset(&arg, 0, sizeof(arg)); + arg.type = EGL_SCREEN_BIT_MESA; + + return egl_g3d_create_surface(drv, dpy, conf, &arg, attribs); +} + +static EGLBoolean +egl_g3d_show_screen_surface(_EGLDriver *drv, _EGLDisplay *dpy, + _EGLScreen *scr, _EGLSurface *surf, + _EGLMode *mode) +{ + struct egl_g3d_display *gdpy = egl_g3d_display(dpy); + struct egl_g3d_screen *gscr = egl_g3d_screen(scr); + struct egl_g3d_surface *gsurf = egl_g3d_surface(surf); + struct native_surface *nsurf; + const struct native_mode *nmode; + EGLBoolean changed; + + if (gsurf) { + EGLint idx; + + if (!mode) + return _eglError(EGL_BAD_MATCH, "eglShowSurfaceMESA"); + if (gsurf->base.Type != EGL_SCREEN_BIT_MESA) + return _eglError(EGL_BAD_SURFACE, "eglShowScreenSurfaceMESA"); + if (gsurf->base.Width < mode->Width || gsurf->base.Height < mode->Height) + return _eglError(EGL_BAD_MATCH, + "eglShowSurfaceMESA(surface smaller than mode size)"); + + /* find the index of the mode */ + for (idx = 0; idx < gscr->base.NumModes; idx++) + if (mode == &gscr->base.Modes[idx]) + break; + if (idx >= gscr->base.NumModes) { + return _eglError(EGL_BAD_MODE_MESA, + "eglShowSurfaceMESA(unknown mode)"); + } + + nsurf = gsurf->native; + nmode = gscr->native_modes[idx]; + } + else { + if (mode) + return _eglError(EGL_BAD_MATCH, "eglShowSurfaceMESA"); + + /* disable the screen */ + nsurf = NULL; + nmode = NULL; + } + + /* TODO surface panning by CRTC choosing */ + changed = gdpy->native->modeset->program(gdpy->native, 0, nsurf, + gscr->base.OriginX, gscr->base.OriginY, &gscr->native, 1, nmode); + if (changed) { + gscr->base.CurrentSurface = &gsurf->base; + gscr->base.CurrentMode = mode; + } + + return changed; +} + +#endif /* EGL_MESA_screen_surface */ + +/** + * Find a config that supports the pixmap. + */ +_EGLConfig * +egl_g3d_find_pixmap_config(_EGLDisplay *dpy, EGLNativePixmapType pix) +{ + struct egl_g3d_display *gdpy = egl_g3d_display(dpy); + struct egl_g3d_config *gconf; + EGLint i; + + for (i = 0; i < dpy->NumConfigs; i++) { + gconf = egl_g3d_config(dpy->Configs[i]); + if (gdpy->native->is_pixmap_supported(gdpy->native, pix, gconf->native)) + break; + } + + return (i < dpy->NumConfigs) ? &gconf->base : NULL; +} + +void +egl_g3d_init_driver_api(_EGLDriver *drv) +{ + _eglInitDriverFallbacks(drv); + + drv->API.CreateContext = egl_g3d_create_context; + drv->API.DestroyContext = egl_g3d_destroy_context; + drv->API.CreateWindowSurface = egl_g3d_create_window_surface; + drv->API.CreatePixmapSurface = egl_g3d_create_pixmap_surface; + drv->API.CreatePbufferSurface = egl_g3d_create_pbuffer_surface; + drv->API.DestroySurface = egl_g3d_destroy_surface; + drv->API.MakeCurrent = egl_g3d_make_current; + drv->API.SwapBuffers = egl_g3d_swap_buffers; + drv->API.CopyBuffers = egl_g3d_copy_buffers; + drv->API.WaitClient = egl_g3d_wait_client; + drv->API.WaitNative = egl_g3d_wait_native; + + drv->API.BindTexImage = egl_g3d_bind_tex_image; + drv->API.ReleaseTexImage = egl_g3d_release_tex_image; + + drv->API.CreateImageKHR = egl_g3d_create_image; + drv->API.DestroyImageKHR = egl_g3d_destroy_image; + +#ifdef EGL_MESA_screen_surface + drv->API.CreateScreenSurfaceMESA = egl_g3d_create_screen_surface; + drv->API.ShowScreenSurfaceMESA = egl_g3d_show_screen_surface; +#endif +} diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_api.h b/src/gallium/state_trackers/egl/common/egl_g3d_api.h new file mode 100644 index 00000000000..d5196c12fe9 --- /dev/null +++ b/src/gallium/state_trackers/egl/common/egl_g3d_api.h @@ -0,0 +1,37 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2009-2010 Chia-I Wu <olv@0xlab.org> + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef _EGL_G3D_API_H_ +#define _EGL_G3D_API_H_ + +#include "egl_g3d.h" + +void +egl_g3d_init_driver_api(_EGLDriver *drv); + +_EGLConfig * +egl_g3d_find_pixmap_config(_EGLDisplay *dpy, EGLNativePixmapType pix); + +#endif /* _EGL_G3D_API_H_ */ diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_image.c b/src/gallium/state_trackers/egl/common/egl_g3d_image.c index d701f9c9a88..b1fe30a776c 100644 --- a/src/gallium/state_trackers/egl/common/egl_g3d_image.c +++ b/src/gallium/state_trackers/egl/common/egl_g3d_image.c @@ -14,39 +14,39 @@ * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. * * Authors: * Chia-I Wu <olv@lunarg.com> */ -#include <assert.h> #include "pipe/p_screen.h" #include "util/u_memory.h" #include "util/u_rect.h" #include "util/u_inlines.h" #include "eglcurrent.h" -#include "egllog.h" #include "native.h" #include "egl_g3d.h" +#include "egl_g3d_api.h" #include "egl_g3d_image.h" /** * Reference and return the front left buffer of the native pixmap. */ -static struct pipe_texture * +static struct pipe_resource * egl_g3d_reference_native_pixmap(_EGLDisplay *dpy, EGLNativePixmapType pix) { struct egl_g3d_display *gdpy = egl_g3d_display(dpy); struct egl_g3d_config *gconf; struct native_surface *nsurf; - struct pipe_texture *textures[NUM_NATIVE_ATTACHMENTS]; + struct pipe_resource *textures[NUM_NATIVE_ATTACHMENTS]; enum native_attachment natt; gconf = egl_g3d_config(egl_g3d_find_pixmap_config(dpy, pix)); @@ -72,7 +72,7 @@ egl_g3d_create_image(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attribs) { - struct pipe_texture *ptex; + struct pipe_resource *ptex; struct egl_g3d_image *gimg; unsigned face = 0, level = 0, zslice = 0; @@ -83,7 +83,7 @@ egl_g3d_create_image(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx, } if (!_eglInitImage(&gimg->base, dpy, attribs)) { - free(gimg); + FREE(gimg); return NULL; } @@ -98,20 +98,20 @@ egl_g3d_create_image(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx, } if (!ptex) { - free(gimg); + FREE(gimg); return NULL; } if (level > ptex->last_level) { _eglError(EGL_BAD_MATCH, "eglCreateEGLImageKHR"); - pipe_texture_reference(&gimg->texture, NULL); - free(gimg); + pipe_resource_reference(&gimg->texture, NULL); + FREE(gimg); return NULL; } if (zslice > ptex->depth0) { _eglError(EGL_BAD_PARAMETER, "eglCreateEGLImageKHR"); - pipe_texture_reference(&gimg->texture, NULL); - free(gimg); + pipe_resource_reference(&gimg->texture, NULL); + FREE(gimg); return NULL; } @@ -129,8 +129,8 @@ egl_g3d_destroy_image(_EGLDriver *drv, _EGLDisplay *dpy, _EGLImage *img) { struct egl_g3d_image *gimg = egl_g3d_image(img); - pipe_texture_reference(&gimg->texture, NULL); - free(gimg); + pipe_resource_reference(&gimg->texture, NULL); + FREE(gimg); return EGL_TRUE; } diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_image.h b/src/gallium/state_trackers/egl/common/egl_g3d_image.h index c199c466456..adda9333715 100644 --- a/src/gallium/state_trackers/egl/common/egl_g3d_image.h +++ b/src/gallium/state_trackers/egl/common/egl_g3d_image.h @@ -14,12 +14,13 @@ * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. * * Authors: * Chia-I Wu <olv@lunarg.com> diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_st.c b/src/gallium/state_trackers/egl/common/egl_g3d_st.c index 6488965e5b0..57a479f6bca 100644 --- a/src/gallium/state_trackers/egl/common/egl_g3d_st.c +++ b/src/gallium/state_trackers/egl/common/egl_g3d_st.c @@ -14,12 +14,13 @@ * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. * * Authors: * Chia-I Wu <olv@lunarg.com> @@ -85,6 +86,37 @@ egl_g3d_create_st_api(enum st_api_type api) return mod->create_api(); } +static boolean +egl_g3d_st_manager_get_egl_image(struct st_manager *smapi, + struct st_egl_image *stimg) +{ + struct egl_g3d_st_manager *gsmapi = egl_g3d_st_manager(smapi); + EGLImageKHR handle = (EGLImageKHR) stimg->egl_image; + _EGLImage *img; + struct egl_g3d_image *gimg; + + /* this is called from state trackers */ + _eglLockMutex(&gsmapi->display->Mutex); + + img = _eglLookupImage(handle, gsmapi->display); + if (!img) { + _eglUnlockMutex(&gsmapi->display->Mutex); + return FALSE; + } + + gimg = egl_g3d_image(img); + + stimg->texture = NULL; + pipe_resource_reference(&stimg->texture, gimg->texture); + stimg->face = gimg->face; + stimg->level = gimg->level; + stimg->zslice = gimg->zslice; + + _eglUnlockMutex(&gsmapi->display->Mutex); + + return TRUE; +} + struct st_manager * egl_g3d_create_st_manager(_EGLDisplay *dpy) { @@ -96,6 +128,7 @@ egl_g3d_create_st_manager(_EGLDisplay *dpy) gsmapi->display = dpy; gsmapi->base.screen = gdpy->native->screen; + gsmapi->base.get_egl_image = egl_g3d_st_manager_get_egl_image; } return &gsmapi->base;; @@ -105,7 +138,54 @@ void egl_g3d_destroy_st_manager(struct st_manager *smapi) { struct egl_g3d_st_manager *gsmapi = egl_g3d_st_manager(smapi); - free(gsmapi); + FREE(gsmapi); +} + +static boolean +egl_g3d_st_framebuffer_flush_front_pbuffer(struct st_framebuffer_iface *stfbi, + enum st_attachment_type statt) +{ + return TRUE; +} + +static boolean +egl_g3d_st_framebuffer_validate_pbuffer(struct st_framebuffer_iface *stfbi, + const enum st_attachment_type *statts, + unsigned count, + struct pipe_resource **out) +{ + _EGLSurface *surf = (_EGLSurface *) stfbi->st_manager_private; + struct egl_g3d_surface *gsurf = egl_g3d_surface(surf); + struct pipe_resource templ; + unsigned i; + + for (i = 0; i < count; i++) { + out[i] = NULL; + + if (gsurf->stvis.render_buffer != statts[i]) + continue; + + if (!gsurf->render_texture) { + struct egl_g3d_display *gdpy = + egl_g3d_display(gsurf->base.Resource.Display); + struct pipe_screen *screen = gdpy->native->screen; + + memset(&templ, 0, sizeof(templ)); + templ.target = PIPE_TEXTURE_2D; + templ.last_level = 0; + templ.width0 = gsurf->base.Width; + templ.height0 = gsurf->base.Height; + templ.depth0 = 1; + templ.format = gsurf->stvis.color_format; + templ.bind = PIPE_BIND_RENDER_TARGET; + + gsurf->render_texture = screen->resource_create(screen, &templ); + } + + pipe_resource_reference(&out[i], gsurf->render_texture); + } + + return TRUE; } static boolean @@ -122,11 +202,11 @@ static boolean egl_g3d_st_framebuffer_validate(struct st_framebuffer_iface *stfbi, const enum st_attachment_type *statts, unsigned count, - struct pipe_texture **out) + struct pipe_resource **out) { _EGLSurface *surf = (_EGLSurface *) stfbi->st_manager_private; struct egl_g3d_surface *gsurf = egl_g3d_surface(surf); - struct pipe_texture *textures[NUM_NATIVE_ATTACHMENTS]; + struct pipe_resource *textures[NUM_NATIVE_ATTACHMENTS]; uint attachment_mask = 0; unsigned i; @@ -161,7 +241,7 @@ egl_g3d_st_framebuffer_validate(struct st_framebuffer_iface *stfbi, return FALSE; for (i = 0; i < count; i++) { - struct pipe_texture *tex; + struct pipe_resource *tex; int natt; switch (statts[i]) { @@ -186,7 +266,7 @@ egl_g3d_st_framebuffer_validate(struct st_framebuffer_iface *stfbi, tex = textures[natt]; if (statts[i] == stfbi->visual->render_buffer) - pipe_texture_reference(&gsurf->render_texture, tex); + pipe_resource_reference(&gsurf->render_texture, tex); if (attachment_mask & (1 << natt)) { /* transfer the ownership to the caller */ @@ -195,7 +275,7 @@ egl_g3d_st_framebuffer_validate(struct st_framebuffer_iface *stfbi, } else { /* the attachment is listed more than once */ - pipe_texture_reference(&out[i], tex); + pipe_resource_reference(&out[i], tex); } } } @@ -214,8 +294,14 @@ egl_g3d_create_st_framebuffer(_EGLSurface *surf) return NULL; stfbi->visual = &gsurf->stvis; - stfbi->flush_front = egl_g3d_st_framebuffer_flush_front; - stfbi->validate = egl_g3d_st_framebuffer_validate; + if (gsurf->base.Type != EGL_PBUFFER_BIT) { + stfbi->flush_front = egl_g3d_st_framebuffer_flush_front; + stfbi->validate = egl_g3d_st_framebuffer_validate; + } + else { + stfbi->flush_front = egl_g3d_st_framebuffer_flush_front_pbuffer; + stfbi->validate = egl_g3d_st_framebuffer_validate_pbuffer; + } stfbi->st_manager_private = (void *) &gsurf->base; return stfbi; @@ -224,5 +310,5 @@ egl_g3d_create_st_framebuffer(_EGLSurface *surf) void egl_g3d_destroy_st_framebuffer(struct st_framebuffer_iface *stfbi) { - free(stfbi); + FREE(stfbi); } diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_st.h b/src/gallium/state_trackers/egl/common/egl_g3d_st.h index ea8b4068cd8..c82681a22d8 100644 --- a/src/gallium/state_trackers/egl/common/egl_g3d_st.h +++ b/src/gallium/state_trackers/egl/common/egl_g3d_st.h @@ -14,12 +14,13 @@ * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. * * Authors: * Chia-I Wu <olv@lunarg.com> diff --git a/src/gallium/state_trackers/egl/common/native.h b/src/gallium/state_trackers/egl/common/native.h index 93c81b26e10..3f60348c489 100644 --- a/src/gallium/state_trackers/egl/common/native.h +++ b/src/gallium/state_trackers/egl/common/native.h @@ -14,26 +14,26 @@ * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. */ #ifndef _NATIVE_H_ #define _NATIVE_H_ #include "EGL/egl.h" /* for EGL native types */ -#include "GL/gl.h" /* for GL types needed by __GLcontextModes */ -#include "GL/internal/glcore.h" /* for __GLcontextModes */ #include "pipe/p_compiler.h" #include "pipe/p_screen.h" #include "pipe/p_context.h" #include "pipe/p_state.h" +#include "native_probe.h" #include "native_modeset.h" /** @@ -57,27 +57,6 @@ enum native_param_type { NATIVE_PARAM_USE_NATIVE_BUFFER }; -/** - * Enumerations for probe results. - */ -enum native_probe_result { - NATIVE_PROBE_UNKNOWN, - NATIVE_PROBE_FALLBACK, - NATIVE_PROBE_SUPPORTED, - NATIVE_PROBE_EXACT, -}; - -/** - * A probe object for display probe. - */ -struct native_probe { - int magic; - EGLNativeDisplayType display; - void *data; - - void (*destroy)(struct native_probe *nprobe); -}; - struct native_surface { /** * Available for caller's use. @@ -112,7 +91,7 @@ struct native_surface { * behavior might change in the future. */ boolean (*validate)(struct native_surface *nsurf, uint attachment_mask, - unsigned int *seq_num, struct pipe_texture **textures, + unsigned int *seq_num, struct pipe_resource **textures, int *width, int *height); /** @@ -121,15 +100,26 @@ struct native_surface { void (*wait)(struct native_surface *nsurf); }; +/** + * Describe a native display config. + */ struct native_config { - /* __GLcontextModes should go away some day */ - __GLcontextModes mode; + /* available buffers and their format */ + uint buffer_mask; enum pipe_format color_format; - enum pipe_format depth_format; - enum pipe_format stencil_format; - /* treat it as an additional flag to mode.drawableType */ + /* supported surface types */ + boolean window_bit; + boolean pixmap_bit; boolean scanout_bit; + + int native_visual_id; + int native_visual_type; + int level; + int samples; + boolean slow_config; + boolean transparent_rgb; + int transparent_rgb_values[3]; }; /** @@ -160,18 +150,14 @@ struct native_display { /** * Get the supported configs. The configs are owned by the display, but - * the returned array should be free()ed. - * - * The configs will be converted to EGL config by - * _eglConfigFromContextModesRec and validated by _eglValidateConfig. - * Those failing to pass the test will be skipped. + * the returned array should be FREE()ed. */ const struct native_config **(*get_configs)(struct native_display *ndpy, int *num_configs); /** * Test if a pixmap is supported by the given config. Required unless no - * config has GLX_PIXMAP_BIT set. + * config has pixmap_bit set. * * This function is usually called to find a config that supports a given * pixmap. Thus, it is usually called with the same pixmap in a row. @@ -182,29 +168,19 @@ struct native_display { /** - * Create a window surface. Required unless no config has GLX_WINDOW_BIT - * set. + * Create a window surface. Required unless no config has window_bit set. */ struct native_surface *(*create_window_surface)(struct native_display *ndpy, EGLNativeWindowType win, const struct native_config *nconf); /** - * Create a pixmap surface. Required unless no config has GLX_PIXMAP_BIT - * set. + * Create a pixmap surface. Required unless no config has pixmap_bit set. */ struct native_surface *(*create_pixmap_surface)(struct native_display *ndpy, EGLNativePixmapType pix, const struct native_config *nconf); - /** - * Create a pbuffer surface. Required unless no config has GLX_PBUFFER_BIT - * set. - */ - struct native_surface *(*create_pbuffer_surface)(struct native_display *ndpy, - const struct native_config *nconf, - uint width, uint height); - const struct native_display_modeset *modeset; }; @@ -231,22 +207,6 @@ native_attachment_mask_test(uint mask, enum native_attachment att) return !!(mask & (1 << att)); } -/** - * Return a probe object for the given display. - * - * Note that the returned object may be cached and used by different native - * display modules. It allows fast probing when multiple modules probe the - * same display. - */ -struct native_probe * -native_create_probe(EGLNativeDisplayType dpy); - -/** - * Probe the probe object. - */ -enum native_probe_result -native_get_probe_result(struct native_probe *nprobe); - const char * native_get_name(void); diff --git a/src/gallium/state_trackers/egl/common/native_modeset.h b/src/gallium/state_trackers/egl/common/native_modeset.h index 71dc3ec860e..dee757b3a88 100644 --- a/src/gallium/state_trackers/egl/common/native_modeset.h +++ b/src/gallium/state_trackers/egl/common/native_modeset.h @@ -14,12 +14,13 @@ * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. */ #ifndef _NATIVE_MODESET_H_ @@ -63,8 +64,8 @@ struct native_display_modeset { int *num_modes); /** - * Create a scan-out surface. Required unless no config has - * GLX_SCREEN_BIT_MESA set. + * Create a scan-out surface. Required unless no config has scanout_bit + * set. */ struct native_surface *(*create_scanout_surface)(struct native_display *ndpy, const struct native_config *nconf, diff --git a/src/gallium/state_trackers/egl/common/native_probe.h b/src/gallium/state_trackers/egl/common/native_probe.h new file mode 100644 index 00000000000..aeed9f85dd5 --- /dev/null +++ b/src/gallium/state_trackers/egl/common/native_probe.h @@ -0,0 +1,68 @@ +/* + * Mesa 3-D graphics library + * Version: 7.8 + * + * Copyright (C) 2009-2010 Chia-I Wu <olv@0xlab.org> + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef _NATIVE_PROBE_H_ +#define _NATIVE_PROBE_H_ + +#include "EGL/egl.h" /* for EGL native types */ + +/** + * Enumerations for probe results. + */ +enum native_probe_result { + NATIVE_PROBE_UNKNOWN, + NATIVE_PROBE_FALLBACK, + NATIVE_PROBE_SUPPORTED, + NATIVE_PROBE_EXACT, +}; + +/** + * A probe object for display probe. + */ +struct native_probe { + int magic; + EGLNativeDisplayType display; + void *data; + + void (*destroy)(struct native_probe *nprobe); +}; + +/** + * Return a probe object for the given display. + * + * Note that the returned object may be cached and used by different native + * display modules. It allows fast probing when multiple modules probe the + * same display. + */ +struct native_probe * +native_create_probe(EGLNativeDisplayType dpy); + +/** + * Probe the probe object. + */ +enum native_probe_result +native_get_probe_result(struct native_probe *nprobe); + +#endif /* _NATIVE_PROBE_H_ */ diff --git a/src/gallium/state_trackers/egl/kms/native_kms.c b/src/gallium/state_trackers/egl/kms/native_kms.c index 31747744907..860657349bc 100644 --- a/src/gallium/state_trackers/egl/kms/native_kms.c +++ b/src/gallium/state_trackers/egl/kms/native_kms.c @@ -14,35 +14,34 @@ * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. */ -#include <stdio.h> -#include <string.h> - #include "pipe/p_screen.h" #include "pipe/p_context.h" #include "util/u_debug.h" #include "util/u_memory.h" #include "util/u_inlines.h" +#include "util/u_string.h" #include "egllog.h" #include "native_kms.h" static boolean kms_surface_validate(struct native_surface *nsurf, uint attachment_mask, - unsigned int *seq_num, struct pipe_texture **textures, + unsigned int *seq_num, struct pipe_resource **textures, int *width, int *height) { struct kms_surface *ksurf = kms_surface(nsurf); struct kms_display *kdpy = ksurf->kdpy; struct pipe_screen *screen = kdpy->base.screen; - struct pipe_texture templ, *ptex; + struct pipe_resource templ, *ptex; int att; if (attachment_mask) { @@ -53,9 +52,7 @@ kms_surface_validate(struct native_surface *nsurf, uint attachment_mask, templ.height0 = ksurf->height; templ.depth0 = 1; templ.format = ksurf->color_format; - templ.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET; - if (ksurf->type == KMS_SURFACE_TYPE_SCANOUT) - templ.tex_usage |= PIPE_TEXTURE_USAGE_SCANOUT; + templ.bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SCANOUT; } /* create textures */ @@ -66,13 +63,13 @@ kms_surface_validate(struct native_surface *nsurf, uint attachment_mask, ptex = ksurf->textures[att]; if (!ptex) { - ptex = screen->texture_create(screen, &templ); + ptex = screen->resource_create(screen, &templ); ksurf->textures[att] = ptex; } if (textures) { textures[att] = NULL; - pipe_texture_reference(&textures[att], ptex); + pipe_resource_reference(&textures[att], ptex); } } @@ -118,7 +115,7 @@ kms_surface_init_framebuffers(struct native_surface *nsurf, boolean need_back) if (!ksurf->textures[natt]) return FALSE; - pipe_texture_reference(&fb->texture, ksurf->textures[natt]); + pipe_resource_reference(&fb->texture, ksurf->textures[natt]); } /* already initialized */ @@ -131,7 +128,7 @@ kms_surface_init_framebuffers(struct native_surface *nsurf, boolean need_back) memset(&whandle, 0, sizeof(whandle)); whandle.type = DRM_API_HANDLE_TYPE_KMS; - if (!kdpy->base.screen->texture_get_handle(kdpy->base.screen, + if (!kdpy->base.screen->resource_get_handle(kdpy->base.screen, fb->texture, &whandle)) return FALSE; @@ -155,10 +152,6 @@ kms_surface_flush_frontbuffer(struct native_surface *nsurf) struct kms_surface *ksurf = kms_surface(nsurf); struct kms_display *kdpy = ksurf->kdpy; - /* pbuffer is private */ - if (ksurf->type == KMS_SURFACE_TYPE_PBUFFER) - return TRUE; - if (ksurf->front_fb.is_passive) drmModeDirtyFB(kdpy->fd, ksurf->front_fb.buffer_id, NULL, 0); #endif @@ -173,13 +166,9 @@ kms_surface_swap_buffers(struct native_surface *nsurf) struct kms_crtc *kcrtc = &ksurf->current_crtc; struct kms_display *kdpy = ksurf->kdpy; struct kms_framebuffer tmp_fb; - struct pipe_texture *tmp_texture; + struct pipe_resource *tmp_texture; int err; - /* pbuffer is private */ - if (ksurf->type == KMS_SURFACE_TYPE_PBUFFER) - return TRUE; - if (!ksurf->back_fb.buffer_id) { if (!kms_surface_init_framebuffers(&ksurf->base, TRUE)) return FALSE; @@ -228,23 +217,22 @@ kms_surface_destroy(struct native_surface *nsurf) if (ksurf->front_fb.buffer_id) drmModeRmFB(ksurf->kdpy->fd, ksurf->front_fb.buffer_id); - pipe_texture_reference(&ksurf->front_fb.texture, NULL); + pipe_resource_reference(&ksurf->front_fb.texture, NULL); if (ksurf->back_fb.buffer_id) drmModeRmFB(ksurf->kdpy->fd, ksurf->back_fb.buffer_id); - pipe_texture_reference(&ksurf->back_fb.texture, NULL); + pipe_resource_reference(&ksurf->back_fb.texture, NULL); for (i = 0; i < NUM_NATIVE_ATTACHMENTS; i++) { - struct pipe_texture *ptex = ksurf->textures[i]; - pipe_texture_reference(&ptex, NULL); + struct pipe_resource *ptex = ksurf->textures[i]; + pipe_resource_reference(&ptex, NULL); } - free(ksurf); + FREE(ksurf); } static struct kms_surface * kms_display_create_surface(struct native_display *ndpy, - enum kms_surface_type type, const struct native_config *nconf, uint width, uint height) { @@ -257,7 +245,6 @@ kms_display_create_surface(struct native_display *ndpy, return NULL; ksurf->kdpy = kdpy; - ksurf->type = type; ksurf->color_format = kconf->base.color_format; ksurf->width = width; ksurf->height = height; @@ -475,7 +462,7 @@ kms_display_get_modes(struct native_display *ndpy, /* delete old data */ if (kconn->connector) { drmModeFreeConnector(kconn->connector); - free(kconn->kms_modes); + FREE(kconn->kms_modes); kconn->connector = NULL; kconn->kms_modes = NULL; @@ -488,7 +475,7 @@ kms_display_get_modes(struct native_display *ndpy, return NULL; count = kconn->connector->count_modes; - kconn->kms_modes = calloc(count, sizeof(*kconn->kms_modes)); + kconn->kms_modes = CALLOC(count, sizeof(*kconn->kms_modes)); if (!kconn->kms_modes) { drmModeFreeConnector(kconn->connector); kconn->connector = NULL; @@ -511,7 +498,7 @@ kms_display_get_modes(struct native_display *ndpy, kmode->base.refresh_rate = (kmode->base.refresh_rate + 500) / 1000; } - nmodes_return = malloc(count * sizeof(*nmodes_return)); + nmodes_return = MALLOC(count * sizeof(*nmodes_return)); if (nmodes_return) { for (i = 0; i < count; i++) nmodes_return[i] = &kconn->kms_modes[i].base; @@ -532,7 +519,7 @@ kms_display_get_connectors(struct native_display *ndpy, int *num_connectors, if (!kdpy->connectors) { kdpy->connectors = - calloc(kdpy->resources->count_connectors, sizeof(*kdpy->connectors)); + CALLOC(kdpy->resources->count_connectors, sizeof(*kdpy->connectors)); if (!kdpy->connectors) return NULL; @@ -546,7 +533,7 @@ kms_display_get_connectors(struct native_display *ndpy, int *num_connectors, kdpy->num_connectors = kdpy->resources->count_connectors; } - connectors = malloc(kdpy->num_connectors * sizeof(*connectors)); + connectors = MALLOC(kdpy->num_connectors * sizeof(*connectors)); if (connectors) { for (i = 0; i < kdpy->num_connectors; i++) connectors[i] = &kdpy->connectors[i].base; @@ -567,32 +554,18 @@ kms_display_create_scanout_surface(struct native_display *ndpy, { struct kms_surface *ksurf; - ksurf = kms_display_create_surface(ndpy, - KMS_SURFACE_TYPE_SCANOUT, nconf, width, height); + ksurf = kms_display_create_surface(ndpy, nconf, width, height); return &ksurf->base; } -static struct native_surface * -kms_display_create_pbuffer_surface(struct native_display *ndpy, - const struct native_config *nconf, - uint width, uint height) -{ - struct kms_surface *ksurf; - - ksurf = kms_display_create_surface(ndpy, - KMS_SURFACE_TYPE_PBUFFER, nconf, width, height); - return &ksurf->base; -} - - static boolean kms_display_is_format_supported(struct native_display *ndpy, enum pipe_format fmt, boolean is_color) { return ndpy->screen->is_format_supported(ndpy->screen, fmt, PIPE_TEXTURE_2D, - (is_color) ? PIPE_TEXTURE_USAGE_RENDER_TARGET : - PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0); + (is_color) ? PIPE_BIND_RENDER_TARGET : + PIPE_BIND_DEPTH_STENCIL, 0); } static const struct native_config ** @@ -606,14 +579,15 @@ kms_display_get_configs(struct native_display *ndpy, int *num_configs) struct native_config *nconf; enum pipe_format format; - kdpy->config = calloc(1, sizeof(*kdpy->config)); + kdpy->config = CALLOC(1, sizeof(*kdpy->config)); if (!kdpy->config) return NULL; nconf = &kdpy->config->base; - /* always double-buffered */ - nconf->mode.doubleBufferMode = TRUE; + nconf->buffer_mask = + (1 << NATIVE_ATTACHMENT_FRONT_LEFT) | + (1 << NATIVE_ATTACHMENT_BACK_LEFT); format = PIPE_FORMAT_B8G8R8A8_UNORM; if (!kms_display_is_format_supported(&kdpy->base, format, TRUE)) { @@ -621,45 +595,18 @@ kms_display_get_configs(struct native_display *ndpy, int *num_configs) if (!kms_display_is_format_supported(&kdpy->base, format, TRUE)) format = PIPE_FORMAT_NONE; } - if (format == PIPE_FORMAT_NONE) + if (format == PIPE_FORMAT_NONE) { + FREE(kdpy->config); + kdpy->config = NULL; return NULL; + } nconf->color_format = format; - nconf->mode.redBits = 8; - nconf->mode.greenBits = 8; - nconf->mode.blueBits = 8; - nconf->mode.alphaBits = 8; - nconf->mode.rgbBits = 32; - - format = PIPE_FORMAT_Z24_UNORM_S8_USCALED; - if (!kms_display_is_format_supported(&kdpy->base, format, FALSE)) { - format = PIPE_FORMAT_S8_USCALED_Z24_UNORM; - if (!kms_display_is_format_supported(&kdpy->base, format, FALSE)) - format = PIPE_FORMAT_NONE; - } - if (format != PIPE_FORMAT_NONE) { - nconf->depth_format = format; - nconf->stencil_format = format; - - nconf->mode.depthBits = 24; - nconf->mode.stencilBits = 8; - nconf->mode.haveDepthBuffer = TRUE; - nconf->mode.haveStencilBuffer = TRUE; - } nconf->scanout_bit = TRUE; - nconf->mode.drawableType = GLX_PBUFFER_BIT; - nconf->mode.swapMethod = GLX_SWAP_EXCHANGE_OML; - - nconf->mode.visualID = 0; - nconf->mode.visualType = EGL_NONE; - - nconf->mode.renderType = GLX_RGBA_BIT; - nconf->mode.rgbMode = TRUE; - nconf->mode.xRenderable = FALSE; } - configs = malloc(sizeof(*configs)); + configs = MALLOC(sizeof(*configs)); if (configs) { configs[0] = &kdpy->config->base; if (num_configs) @@ -691,21 +638,21 @@ kms_display_destroy(struct native_display *ndpy) int i; if (kdpy->config) - free(kdpy->config); + FREE(kdpy->config); if (kdpy->connectors) { for (i = 0; i < kdpy->num_connectors; i++) { struct kms_connector *kconn = &kdpy->connectors[i]; if (kconn->connector) { drmModeFreeConnector(kconn->connector); - free(kconn->kms_modes); + FREE(kconn->kms_modes); } } - free(kdpy->connectors); + FREE(kdpy->connectors); } if (kdpy->shown_surfaces) - free(kdpy->shown_surfaces); + FREE(kdpy->shown_surfaces); if (kdpy->saved_crtcs) { for (i = 0; i < kdpy->resources->count_crtcs; i++) { @@ -721,7 +668,7 @@ kms_display_destroy(struct native_display *ndpy) drmModeFreeCrtc(kcrtc->crtc); } } - free(kdpy->saved_crtcs); + FREE(kdpy->saved_crtcs); } if (kdpy->resources) @@ -735,7 +682,7 @@ kms_display_destroy(struct native_display *ndpy) if (kdpy->api) kdpy->api->destroy(kdpy->api); - free(kdpy); + FREE(kdpy); } /** @@ -798,7 +745,7 @@ kms_create_display(EGLNativeDisplayType dpy, kdpy->api = api; if (!kdpy->api) { _eglLog(_EGL_WARNING, "failed to create DRM API"); - free(kdpy); + FREE(kdpy); return NULL; } @@ -816,14 +763,14 @@ kms_create_display(EGLNativeDisplayType dpy, } kdpy->saved_crtcs = - calloc(kdpy->resources->count_crtcs, sizeof(*kdpy->saved_crtcs)); + CALLOC(kdpy->resources->count_crtcs, sizeof(*kdpy->saved_crtcs)); if (!kdpy->saved_crtcs) { kms_display_destroy(&kdpy->base); return NULL; } kdpy->shown_surfaces = - calloc(kdpy->resources->count_crtcs, sizeof(*kdpy->shown_surfaces)); + CALLOC(kdpy->resources->count_crtcs, sizeof(*kdpy->shown_surfaces)); if (!kdpy->shown_surfaces) { kms_display_destroy(&kdpy->base); return NULL; @@ -832,7 +779,6 @@ kms_create_display(EGLNativeDisplayType dpy, kdpy->base.destroy = kms_display_destroy; kdpy->base.get_param = kms_display_get_param; kdpy->base.get_configs = kms_display_get_configs; - kdpy->base.create_pbuffer_surface = kms_display_create_pbuffer_surface; kdpy->base.modeset = &kms_display_modeset; @@ -863,9 +809,9 @@ native_get_name(void) drm_api = drm_api_create(); if (drm_api) - snprintf(kms_name, sizeof(kms_name), "KMS/%s", drm_api->name); + util_snprintf(kms_name, sizeof(kms_name), "KMS/%s", drm_api->name); else - snprintf(kms_name, sizeof(kms_name), "KMS"); + util_snprintf(kms_name, sizeof(kms_name), "KMS"); return kms_name; } diff --git a/src/gallium/state_trackers/egl/kms/native_kms.h b/src/gallium/state_trackers/egl/kms/native_kms.h index f9cbcb158b5..3b08e930c52 100644 --- a/src/gallium/state_trackers/egl/kms/native_kms.h +++ b/src/gallium/state_trackers/egl/kms/native_kms.h @@ -14,12 +14,13 @@ * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. */ #ifndef _NATIVE_KMS_H_ @@ -35,11 +36,6 @@ #include "common/native.h" -enum kms_surface_type { - KMS_SURFACE_TYPE_PBUFFER, - KMS_SURFACE_TYPE_SCANOUT -}; - struct kms_config; struct kms_connector; struct kms_mode; @@ -69,7 +65,7 @@ struct kms_display { }; struct kms_framebuffer { - struct pipe_texture *texture; + struct pipe_resource *texture; boolean is_passive; uint32_t buffer_id; @@ -77,12 +73,11 @@ struct kms_framebuffer { struct kms_surface { struct native_surface base; - enum kms_surface_type type; enum pipe_format color_format; struct kms_display *kdpy; int width, height; - struct pipe_texture *textures[NUM_NATIVE_ATTACHMENTS]; + struct pipe_resource *textures[NUM_NATIVE_ATTACHMENTS]; unsigned int sequence_number; struct kms_framebuffer front_fb, back_fb; diff --git a/src/gallium/state_trackers/egl/x11/native_dri2.c b/src/gallium/state_trackers/egl/x11/native_dri2.c index 8c0553ce0d5..20e1a0052ca 100644 --- a/src/gallium/state_trackers/egl/x11/native_dri2.c +++ b/src/gallium/state_trackers/egl/x11/native_dri2.c @@ -14,12 +14,13 @@ * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. */ #include "util/u_memory.h" @@ -40,7 +41,6 @@ enum dri2_surface_type { DRI2_SURFACE_TYPE_WINDOW, DRI2_SURFACE_TYPE_PIXMAP, - DRI2_SURFACE_TYPE_PBUFFER }; struct dri2_display { @@ -72,7 +72,7 @@ struct dri2_surface { unsigned int server_stamp; unsigned int client_stamp; int width, height; - struct pipe_texture *textures[NUM_NATIVE_ATTACHMENTS]; + struct pipe_resource *textures[NUM_NATIVE_ATTACHMENTS]; uint valid_mask; boolean have_back, have_fake; @@ -113,14 +113,14 @@ dri2_surface_process_drawable_buffers(struct native_surface *nsurf, { struct dri2_surface *dri2surf = dri2_surface(nsurf); struct dri2_display *dri2dpy = dri2surf->dri2dpy; - struct pipe_texture templ; + struct pipe_resource templ; struct winsys_handle whandle; uint valid_mask; int i; /* free the old textures */ for (i = 0; i < NUM_NATIVE_ATTACHMENTS; i++) - pipe_texture_reference(&dri2surf->textures[i], NULL); + pipe_resource_reference(&dri2surf->textures[i], NULL); dri2surf->valid_mask = 0x0; dri2surf->have_back = FALSE; @@ -136,7 +136,7 @@ dri2_surface_process_drawable_buffers(struct native_surface *nsurf, templ.height0 = dri2surf->height; templ.depth0 = 1; templ.format = dri2surf->color_format; - templ.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET; + templ.bind = PIPE_BIND_RENDER_TARGET; valid_mask = 0x0; for (i = 0; i < num_xbufs; i++) { @@ -175,7 +175,7 @@ dri2_surface_process_drawable_buffers(struct native_surface *nsurf, memset(&whandle, 0, sizeof(whandle)); whandle.stride = xbuf->pitch; whandle.handle = xbuf->name; - dri2surf->textures[natt] = dri2dpy->base.screen->texture_from_handle( + dri2surf->textures[natt] = dri2dpy->base.screen->resource_from_handle( dri2dpy->base.screen, &templ, &whandle); if (dri2surf->textures[natt]) valid_mask |= 1 << natt; @@ -192,9 +192,19 @@ dri2_surface_get_buffers(struct native_surface *nsurf, uint buffer_mask) { struct dri2_surface *dri2surf = dri2_surface(nsurf); struct dri2_display *dri2dpy = dri2surf->dri2dpy; - unsigned int dri2atts[NUM_NATIVE_ATTACHMENTS]; + unsigned int dri2atts[NUM_NATIVE_ATTACHMENTS * 2]; int num_ins, num_outs, att; struct x11_drawable_buffer *xbufs; + uint bpp = util_format_get_blocksizebits(dri2surf->color_format); + boolean with_format = FALSE; /* never ask for depth/stencil */ + + /* We must get the front on servers which doesn't support with format + * due to a silly bug in core dri2. You can't copy to/from a buffer + * that you haven't requested and you recive BadValue errors */ + if (dri2surf->dri2dpy->dri_minor < 1) { + with_format = FALSE; + buffer_mask |= (1 << NATIVE_ATTACHMENT_FRONT_LEFT); + } /* prepare the attachments */ num_ins = 0; @@ -221,19 +231,22 @@ dri2_surface_get_buffers(struct native_surface *nsurf, uint buffer_mask) break; } - dri2atts[num_ins] = dri2att; - num_ins++; + dri2atts[num_ins++] = dri2att; + if (with_format) + dri2atts[num_ins++] = bpp; } } + if (with_format) + num_ins /= 2; xbufs = x11_drawable_get_buffers(dri2dpy->xscr, dri2surf->drawable, &dri2surf->width, &dri2surf->height, - dri2atts, FALSE, num_ins, &num_outs); + dri2atts, with_format, num_ins, &num_outs); /* we should be able to do better... */ if (xbufs && dri2surf->last_num_xbufs == num_outs && memcmp(dri2surf->last_xbufs, xbufs, sizeof(*xbufs) * num_outs) == 0) { - free(xbufs); + FREE(xbufs); dri2surf->client_stamp = dri2surf->server_stamp; return; } @@ -244,7 +257,7 @@ dri2_surface_get_buffers(struct native_surface *nsurf, uint buffer_mask) dri2surf->client_stamp = dri2surf->server_stamp; if (dri2surf->last_xbufs) - free(dri2surf->last_xbufs); + FREE(dri2surf->last_xbufs); dri2surf->last_xbufs = xbufs; dri2surf->last_num_xbufs = num_outs; } @@ -257,47 +270,8 @@ static boolean dri2_surface_update_buffers(struct native_surface *nsurf, uint buffer_mask) { struct dri2_surface *dri2surf = dri2_surface(nsurf); - struct dri2_display *dri2dpy = dri2surf->dri2dpy; - - /* create textures for pbuffer */ - if (dri2surf->type == DRI2_SURFACE_TYPE_PBUFFER) { - struct pipe_screen *screen = dri2dpy->base.screen; - struct pipe_texture templ; - uint new_valid = 0x0; - int att; - - buffer_mask &= ~dri2surf->valid_mask; - if (!buffer_mask) - return TRUE; - - memset(&templ, 0, sizeof(templ)); - templ.target = PIPE_TEXTURE_2D; - templ.last_level = 0; - templ.width0 = dri2surf->width; - templ.height0 = dri2surf->height; - templ.depth0 = 1; - templ.format = dri2surf->color_format; - templ.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET; - - for (att = 0; att < NUM_NATIVE_ATTACHMENTS; att++) { - if (native_attachment_mask_test(buffer_mask, att)) { - assert(!dri2surf->textures[att]); - dri2surf->textures[att] = screen->texture_create(screen, &templ); - if (!dri2surf->textures[att]) - break; - - new_valid |= 1 << att; - if (new_valid == buffer_mask) - break; - } - } - dri2surf->valid_mask |= new_valid; - /* no need to update the stamps */ - } - else { - dri2_surface_get_buffers(&dri2surf->base, buffer_mask); - } + dri2_surface_get_buffers(&dri2surf->base, buffer_mask); return ((dri2surf->valid_mask & buffer_mask) == buffer_mask); } @@ -318,10 +292,6 @@ dri2_surface_flush_frontbuffer(struct native_surface *nsurf) struct dri2_surface *dri2surf = dri2_surface(nsurf); struct dri2_display *dri2dpy = dri2surf->dri2dpy; - /* pbuffer is private */ - if (dri2surf->type == DRI2_SURFACE_TYPE_PBUFFER) - return TRUE; - /* copy to real front buffer */ if (dri2surf->have_fake) x11_drawable_copy_buffers(dri2dpy->xscr, dri2surf->drawable, @@ -344,10 +314,6 @@ dri2_surface_swap_buffers(struct native_surface *nsurf) struct dri2_surface *dri2surf = dri2_surface(nsurf); struct dri2_display *dri2dpy = dri2surf->dri2dpy; - /* pbuffer is private */ - if (dri2surf->type == DRI2_SURFACE_TYPE_PBUFFER) - return TRUE; - /* copy to front buffer */ if (dri2surf->have_back) x11_drawable_copy_buffers(dri2dpy->xscr, dri2surf->drawable, @@ -372,7 +338,7 @@ dri2_surface_swap_buffers(struct native_surface *nsurf) static boolean dri2_surface_validate(struct native_surface *nsurf, uint attachment_mask, - unsigned int *seq_num, struct pipe_texture **textures, + unsigned int *seq_num, struct pipe_resource **textures, int *width, int *height) { struct dri2_surface *dri2surf = dri2_surface(nsurf); @@ -390,10 +356,10 @@ dri2_surface_validate(struct native_surface *nsurf, uint attachment_mask, int att; for (att = 0; att < NUM_NATIVE_ATTACHMENTS; att++) { if (native_attachment_mask_test(attachment_mask, att)) { - struct pipe_texture *ptex = dri2surf->textures[att]; + struct pipe_resource *ptex = dri2surf->textures[att]; textures[att] = NULL; - pipe_texture_reference(&textures[att], ptex); + pipe_resource_reference(&textures[att], ptex); } } } @@ -426,11 +392,11 @@ dri2_surface_destroy(struct native_surface *nsurf) int i; if (dri2surf->last_xbufs) - free(dri2surf->last_xbufs); + FREE(dri2surf->last_xbufs); for (i = 0; i < NUM_NATIVE_ATTACHMENTS; i++) { - struct pipe_texture *ptex = dri2surf->textures[i]; - pipe_texture_reference(&ptex, NULL); + struct pipe_resource *ptex = dri2surf->textures[i]; + pipe_resource_reference(&ptex, NULL); } if (dri2surf->drawable) { @@ -440,7 +406,7 @@ dri2_surface_destroy(struct native_surface *nsurf) util_hash_table_remove(dri2surf->dri2dpy->surfaces, (void *) dri2surf->drawable); } - free(dri2surf); + FREE(dri2surf); } static struct dri2_surface * @@ -504,22 +470,6 @@ dri2_display_create_pixmap_surface(struct native_display *ndpy, return (dri2surf) ? &dri2surf->base : NULL; } -static struct native_surface * -dri2_display_create_pbuffer_surface(struct native_display *ndpy, - const struct native_config *nconf, - uint width, uint height) -{ - struct dri2_surface *dri2surf; - - dri2surf = dri2_display_create_surface(ndpy, DRI2_SURFACE_TYPE_PBUFFER, - (Drawable) None, nconf); - if (dri2surf) { - dri2surf->width = width; - dri2surf->height = height; - } - return (dri2surf) ? &dri2surf->base : NULL; -} - static int choose_color_format(const __GLcontextModes *mode, enum pipe_format formats[32]) { @@ -546,43 +496,13 @@ choose_color_format(const __GLcontextModes *mode, enum pipe_format formats[32]) return count; } -static int -choose_depth_stencil_format(const __GLcontextModes *mode, - enum pipe_format formats[32]) -{ - int count = 0; - - switch (mode->depthBits) { - case 32: - formats[count++] = PIPE_FORMAT_Z32_UNORM; - break; - case 24: - if (mode->stencilBits) { - formats[count++] = PIPE_FORMAT_Z24_UNORM_S8_USCALED; - formats[count++] = PIPE_FORMAT_S8_USCALED_Z24_UNORM; - } - else { - formats[count++] = PIPE_FORMAT_Z24X8_UNORM; - formats[count++] = PIPE_FORMAT_X8Z24_UNORM; - } - break; - case 16: - formats[count++] = PIPE_FORMAT_Z16_UNORM; - break; - default: - break; - } - - return count; -} - static boolean is_format_supported(struct pipe_screen *screen, enum pipe_format fmt, boolean is_color) { return screen->is_format_supported(screen, fmt, PIPE_TEXTURE_2D, - (is_color) ? PIPE_TEXTURE_USAGE_RENDER_TARGET : - PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0); + (is_color) ? PIPE_BIND_RENDER_TARGET : + PIPE_BIND_DEPTH_STENCIL, 0); } static boolean @@ -600,30 +520,18 @@ dri2_display_convert_config(struct native_display *ndpy, if (!mode->doubleBufferMode) return FALSE; - nconf->mode = *mode; - nconf->mode.renderType = GLX_RGBA_BIT; - nconf->mode.rgbMode = TRUE; - /* pbuffer is allocated locally and is always supported */ - nconf->mode.drawableType |= GLX_PBUFFER_BIT; - /* the swap method is always copy */ - nconf->mode.swapMethod = GLX_SWAP_COPY_OML; - - /* fix up */ - nconf->mode.rgbBits = - nconf->mode.redBits + nconf->mode.greenBits + - nconf->mode.blueBits + nconf->mode.alphaBits; - if (!(nconf->mode.drawableType & GLX_WINDOW_BIT)) { - nconf->mode.visualID = 0; - nconf->mode.visualType = GLX_NONE; - } - if (!(nconf->mode.drawableType & GLX_PBUFFER_BIT)) { - nconf->mode.bindToTextureRgb = FALSE; - nconf->mode.bindToTextureRgba = FALSE; - } + /* only interested in native renderable configs */ + if (!mode->xRenderable || !mode->drawableType) + return FALSE; - nconf->color_format = PIPE_FORMAT_NONE; - nconf->depth_format = PIPE_FORMAT_NONE; - nconf->stencil_format = PIPE_FORMAT_NONE; + nconf->buffer_mask = 1 << NATIVE_ATTACHMENT_FRONT_LEFT; + if (mode->doubleBufferMode) + nconf->buffer_mask |= 1 << NATIVE_ATTACHMENT_BACK_LEFT; + if (mode->stereoMode) { + nconf->buffer_mask |= 1 << NATIVE_ATTACHMENT_FRONT_RIGHT; + if (mode->doubleBufferMode) + nconf->buffer_mask |= 1 << NATIVE_ATTACHMENT_BACK_RIGHT; + } /* choose color format */ num_formats = choose_color_format(mode, formats); @@ -636,18 +544,24 @@ dri2_display_convert_config(struct native_display *ndpy, if (nconf->color_format == PIPE_FORMAT_NONE) return FALSE; - /* choose depth/stencil format */ - num_formats = choose_depth_stencil_format(mode, formats); - for (i = 0; i < num_formats; i++) { - if (is_format_supported(ndpy->screen, formats[i], FALSE)) { - nconf->depth_format = formats[i]; - nconf->stencil_format = formats[i]; - break; - } + if (mode->drawableType & GLX_WINDOW_BIT) + nconf->window_bit = TRUE; + if (mode->drawableType & GLX_PIXMAP_BIT) + nconf->pixmap_bit = TRUE; + + nconf->native_visual_id = mode->visualID; + nconf->native_visual_type = mode->visualType; + nconf->level = mode->level; + nconf->samples = mode->samples; + + nconf->slow_config = (mode->visualRating == GLX_SLOW_CONFIG); + + if (mode->transparentPixel == GLX_TRANSPARENT_RGB) { + nconf->transparent_rgb = TRUE; + nconf->transparent_rgb_values[0] = mode->transparentRed; + nconf->transparent_rgb_values[1] = mode->transparentGreen; + nconf->transparent_rgb_values[2] = mode->transparentBlue; } - if ((nconf->mode.depthBits && nconf->depth_format == PIPE_FORMAT_NONE) || - (nconf->mode.stencilBits && nconf->stencil_format == PIPE_FORMAT_NONE)) - return FALSE; return TRUE; } @@ -669,7 +583,7 @@ dri2_display_get_configs(struct native_display *ndpy, int *num_configs) return NULL; num_modes = x11_context_modes_count(modes); - dri2dpy->configs = calloc(num_modes, sizeof(*dri2dpy->configs)); + dri2dpy->configs = CALLOC(num_modes, sizeof(*dri2dpy->configs)); if (!dri2dpy->configs) return NULL; @@ -684,7 +598,7 @@ dri2_display_get_configs(struct native_display *ndpy, int *num_configs) dri2dpy->num_configs = count; } - configs = malloc(dri2dpy->num_configs * sizeof(*configs)); + configs = MALLOC(dri2dpy->num_configs * sizeof(*configs)); if (configs) { for (i = 0; i < dri2dpy->num_configs; i++) configs[i] = (const struct native_config *) &dri2dpy->configs[i]; @@ -735,7 +649,7 @@ dri2_display_destroy(struct native_display *ndpy) struct dri2_display *dri2dpy = dri2_display(ndpy); if (dri2dpy->configs) - free(dri2dpy->configs); + FREE(dri2dpy->configs); if (dri2dpy->base.screen) dri2dpy->base.screen->destroy(dri2dpy->base.screen); @@ -749,7 +663,7 @@ dri2_display_destroy(struct native_display *ndpy) XCloseDisplay(dri2dpy->dpy); if (dri2dpy->api && dri2dpy->api->destroy) dri2dpy->api->destroy(dri2dpy->api); - free(dri2dpy); + FREE(dri2dpy); } static void @@ -877,7 +791,6 @@ x11_create_dri2_display(EGLNativeDisplayType dpy, dri2dpy->base.is_pixmap_supported = dri2_display_is_pixmap_supported; dri2dpy->base.create_window_surface = dri2_display_create_window_surface; dri2dpy->base.create_pixmap_surface = dri2_display_create_pixmap_surface; - dri2dpy->base.create_pbuffer_surface = dri2_display_create_pbuffer_surface; return &dri2dpy->base; } diff --git a/src/gallium/state_trackers/egl/x11/native_x11.c b/src/gallium/state_trackers/egl/x11/native_x11.c index c6eb17ab1ac..b6d51bbf9fb 100644 --- a/src/gallium/state_trackers/egl/x11/native_x11.c +++ b/src/gallium/state_trackers/egl/x11/native_x11.c @@ -14,18 +14,19 @@ * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. */ -#include <stdio.h> #include <string.h> #include "util/u_debug.h" #include "util/u_memory.h" +#include "util/u_string.h" #include "state_tracker/drm_api.h" #include "egllog.h" @@ -40,8 +41,8 @@ static void x11_probe_destroy(struct native_probe *nprobe) { if (nprobe->data) - free(nprobe->data); - free(nprobe); + FREE(nprobe->data); + FREE(nprobe); } struct native_probe * @@ -61,7 +62,7 @@ native_create_probe(EGLNativeDisplayType dpy) if (!xdpy) { xdpy = XOpenDisplay(NULL); if (!xdpy) { - free(nprobe); + FREE(nprobe); return NULL; } } @@ -118,9 +119,9 @@ native_get_name(void) api = drm_api_create(); if (api) - snprintf(x11_name, sizeof(x11_name), "X11/%s", api->name); + util_snprintf(x11_name, sizeof(x11_name), "X11/%s", api->name); else - snprintf(x11_name, sizeof(x11_name), "X11"); + util_snprintf(x11_name, sizeof(x11_name), "X11"); return x11_name; } diff --git a/src/gallium/state_trackers/egl/x11/native_x11.h b/src/gallium/state_trackers/egl/x11/native_x11.h index 1566524926a..1678403b459 100644 --- a/src/gallium/state_trackers/egl/x11/native_x11.h +++ b/src/gallium/state_trackers/egl/x11/native_x11.h @@ -14,12 +14,13 @@ * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. */ #ifndef _NATIVE_X11_H_ diff --git a/src/gallium/state_trackers/egl/x11/native_ximage.c b/src/gallium/state_trackers/egl/x11/native_ximage.c index d69011ac5ee..22fcdcfa6d9 100644 --- a/src/gallium/state_trackers/egl/x11/native_ximage.c +++ b/src/gallium/state_trackers/egl/x11/native_ximage.c @@ -14,18 +14,15 @@ * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. */ -#include <assert.h> -#include <sys/ipc.h> -#include <sys/types.h> -#include <sys/shm.h> #include <X11/Xlib.h> #include <X11/Xutil.h> #include "util/u_memory.h" @@ -47,7 +44,6 @@ enum ximage_surface_type { XIMAGE_SURFACE_TYPE_WINDOW, XIMAGE_SURFACE_TYPE_PIXMAP, - XIMAGE_SURFACE_TYPE_PBUFFER }; struct ximage_display { @@ -65,7 +61,7 @@ struct ximage_display { }; struct ximage_buffer { - struct pipe_texture *texture; + struct pipe_resource *texture; struct xlib_drawable xdraw; }; @@ -116,7 +112,7 @@ ximage_surface_free_buffer(struct native_surface *nsurf, struct ximage_surface *xsurf = ximage_surface(nsurf); struct ximage_buffer *xbuf = &xsurf->buffers[which]; - pipe_texture_reference(&xbuf->texture, NULL); + pipe_resource_reference(&xbuf->texture, NULL); } static boolean @@ -126,7 +122,7 @@ ximage_surface_alloc_buffer(struct native_surface *nsurf, struct ximage_surface *xsurf = ximage_surface(nsurf); struct ximage_buffer *xbuf = &xsurf->buffers[which]; struct pipe_screen *screen = xsurf->xdpy->base.screen; - struct pipe_texture templ; + struct pipe_resource templ; /* free old data */ if (xbuf->texture) @@ -138,23 +134,21 @@ ximage_surface_alloc_buffer(struct native_surface *nsurf, templ.width0 = xsurf->width; templ.height0 = xsurf->height; templ.depth0 = 1; - templ.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET; - - if (xsurf->type != XIMAGE_SURFACE_TYPE_PBUFFER) { - switch (which) { - case NATIVE_ATTACHMENT_FRONT_LEFT: - case NATIVE_ATTACHMENT_FRONT_RIGHT: - templ.tex_usage |= PIPE_TEXTURE_USAGE_SCANOUT; - break; - case NATIVE_ATTACHMENT_BACK_LEFT: - case NATIVE_ATTACHMENT_BACK_RIGHT: - templ.tex_usage |= PIPE_TEXTURE_USAGE_DISPLAY_TARGET; - break; - default: - break; - } + templ.bind = PIPE_BIND_RENDER_TARGET; + + switch (which) { + case NATIVE_ATTACHMENT_FRONT_LEFT: + case NATIVE_ATTACHMENT_FRONT_RIGHT: + templ.bind |= PIPE_BIND_SCANOUT; + break; + case NATIVE_ATTACHMENT_BACK_LEFT: + case NATIVE_ATTACHMENT_BACK_RIGHT: + templ.bind |= PIPE_BIND_DISPLAY_TARGET; + break; + default: + break; } - xbuf->texture = screen->texture_create(screen, &templ); + xbuf->texture = screen->resource_create(screen, &templ); if (xbuf->texture) { xbuf->xdraw.visual = xsurf->visual.visual; xbuf->xdraw.depth = xsurf->visual.depth; @@ -182,10 +176,6 @@ ximage_surface_update_geometry(struct native_surface *nsurf) unsigned int w, h, border, depth; boolean updated = FALSE; - /* pbuffer has fixed geometry */ - if (xsurf->type == XIMAGE_SURFACE_TYPE_PBUFFER) - return FALSE; - ok = XGetGeometry(xsurf->xdpy->dpy, xsurf->drawable, &root, &x, &y, &w, &h, &border, &depth); if (ok && (xsurf->width != w || xsurf->height != h)) { @@ -263,9 +253,6 @@ ximage_surface_draw_buffer(struct native_surface *nsurf, struct pipe_screen *screen = xsurf->xdpy->base.screen; struct pipe_surface *psurf; - if (xsurf->type == XIMAGE_SURFACE_TYPE_PBUFFER) - return TRUE; - assert(xsurf->drawable && xbuf->texture); psurf = xsurf->draw_surface; @@ -273,7 +260,7 @@ ximage_surface_draw_buffer(struct native_surface *nsurf, pipe_surface_reference(&xsurf->draw_surface, NULL); psurf = screen->get_tex_surface(screen, - xbuf->texture, 0, 0, 0, PIPE_BUFFER_USAGE_CPU_READ); + xbuf->texture, 0, 0, 0, PIPE_BIND_DISPLAY_TARGET); if (!psurf) return FALSE; @@ -329,7 +316,7 @@ ximage_surface_swap_buffers(struct native_surface *nsurf) static boolean ximage_surface_validate(struct native_surface *nsurf, uint attachment_mask, - unsigned int *seq_num, struct pipe_texture **textures, + unsigned int *seq_num, struct pipe_resource **textures, int *width, int *height) { struct ximage_surface *xsurf = ximage_surface(nsurf); @@ -350,7 +337,7 @@ ximage_surface_validate(struct native_surface *nsurf, uint attachment_mask, struct ximage_buffer *xbuf = &xsurf->buffers[att]; textures[att] = NULL; - pipe_texture_reference(&textures[att], xbuf->texture); + pipe_resource_reference(&textures[att], xbuf->texture); } } } @@ -382,7 +369,7 @@ ximage_surface_destroy(struct native_surface *nsurf) for (i = 0; i < NUM_NATIVE_ATTACHMENTS; i++) ximage_surface_free_buffer(&xsurf->base, i); - free(xsurf); + FREE(xsurf); } static struct ximage_surface * @@ -404,12 +391,10 @@ ximage_display_create_surface(struct native_display *ndpy, xsurf->color_format = xconf->base.color_format; xsurf->drawable = drawable; - if (xsurf->type != XIMAGE_SURFACE_TYPE_PBUFFER) { - xsurf->drawable = drawable; - xsurf->visual = *xconf->visual; - /* initialize the geometry */ - ximage_surface_update_buffers(&xsurf->base, 0x0); - } + xsurf->drawable = drawable; + xsurf->visual = *xconf->visual; + /* initialize the geometry */ + ximage_surface_update_buffers(&xsurf->base, 0x0); xsurf->base.destroy = ximage_surface_destroy; xsurf->base.swap_buffers = ximage_surface_swap_buffers; @@ -444,22 +429,6 @@ ximage_display_create_pixmap_surface(struct native_display *ndpy, return (xsurf) ? &xsurf->base : NULL; } -static struct native_surface * -ximage_display_create_pbuffer_surface(struct native_display *ndpy, - const struct native_config *nconf, - uint width, uint height) -{ - struct ximage_surface *xsurf; - - xsurf = ximage_display_create_surface(ndpy, XIMAGE_SURFACE_TYPE_PBUFFER, - (Drawable) None, nconf); - if (xsurf) { - xsurf->width = width; - xsurf->height = height; - } - return (xsurf) ? &xsurf->base : NULL; -} - static enum pipe_format choose_format(const XVisualInfo *vinfo) { @@ -493,7 +462,7 @@ ximage_display_get_configs(struct native_display *ndpy, int *num_configs) /* first time */ if (!xdpy->configs) { const XVisualInfo *visuals; - int num_visuals, count, j; + int num_visuals, count; visuals = x11_screen_get_visuals(xdpy->xscr, &num_visuals); if (!visuals) @@ -503,57 +472,42 @@ ximage_display_get_configs(struct native_display *ndpy, int *num_configs) * Create two configs for each visual. * One with depth/stencil buffer; one without */ - xdpy->configs = calloc(num_visuals * 2, sizeof(*xdpy->configs)); + xdpy->configs = CALLOC(num_visuals * 2, sizeof(*xdpy->configs)); if (!xdpy->configs) return NULL; count = 0; for (i = 0; i < num_visuals; i++) { - for (j = 0; j < 2; j++) { - struct ximage_config *xconf = &xdpy->configs[count]; - __GLcontextModes *mode = &xconf->base.mode; - - xconf->visual = &visuals[i]; - xconf->base.color_format = choose_format(xconf->visual); - if (xconf->base.color_format == PIPE_FORMAT_NONE) - continue; - - x11_screen_convert_visual(xdpy->xscr, xconf->visual, mode); - /* support double buffer mode */ - mode->doubleBufferMode = TRUE; - - xconf->base.depth_format = PIPE_FORMAT_NONE; - xconf->base.stencil_format = PIPE_FORMAT_NONE; - /* create the second config with depth/stencil buffer */ - if (j == 1) { - xconf->base.depth_format = PIPE_FORMAT_Z24_UNORM_S8_USCALED; - xconf->base.stencil_format = PIPE_FORMAT_Z24_UNORM_S8_USCALED; - mode->depthBits = 24; - mode->stencilBits = 8; - mode->haveDepthBuffer = TRUE; - mode->haveStencilBuffer = TRUE; - } - - mode->maxPbufferWidth = 4096; - mode->maxPbufferHeight = 4096; - mode->maxPbufferPixels = 4096 * 4096; - mode->drawableType = - GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT; - mode->swapMethod = GLX_SWAP_EXCHANGE_OML; - - if (mode->alphaBits) - mode->bindToTextureRgba = TRUE; - else - mode->bindToTextureRgb = TRUE; - - count++; - } + struct ximage_config *xconf = &xdpy->configs[count]; + + xconf->visual = &visuals[i]; + xconf->base.color_format = choose_format(xconf->visual); + if (xconf->base.color_format == PIPE_FORMAT_NONE) + continue; + + xconf->base.buffer_mask = + (1 << NATIVE_ATTACHMENT_FRONT_LEFT) | + (1 << NATIVE_ATTACHMENT_BACK_LEFT); + + xconf->base.window_bit = TRUE; + xconf->base.pixmap_bit = TRUE; + + xconf->base.native_visual_id = xconf->visual->visualid; +#if defined(__cplusplus) || defined(c_plusplus) + xconf->base.native_visual_type = xconf->visual->c_class; +#else + xconf->base.native_visual_type = xconf->visual->class; +#endif + + xconf->base.slow_config = TRUE; + + count++; } xdpy->num_configs = count; } - configs = malloc(xdpy->num_configs * sizeof(*configs)); + configs = MALLOC(xdpy->num_configs * sizeof(*configs)); if (configs) { for (i = 0; i < xdpy->num_configs; i++) configs[i] = (const struct native_config *) &xdpy->configs[i]; @@ -616,14 +570,14 @@ ximage_display_destroy(struct native_display *ndpy) struct ximage_display *xdpy = ximage_display(ndpy); if (xdpy->configs) - free(xdpy->configs); + FREE(xdpy->configs); xdpy->base.screen->destroy(xdpy->base.screen); x11_screen_destroy(xdpy->xscr); if (xdpy->own_dpy) XCloseDisplay(xdpy->dpy); - free(xdpy); + FREE(xdpy); } @@ -694,7 +648,7 @@ x11_create_ximage_display(EGLNativeDisplayType dpy, if (!xdpy->dpy) { xdpy->dpy = XOpenDisplay(NULL); if (!xdpy->dpy) { - free(xdpy); + FREE(xdpy); return NULL; } xdpy->own_dpy = TRUE; @@ -705,7 +659,7 @@ x11_create_ximage_display(EGLNativeDisplayType dpy, xdpy->xscr_number = DefaultScreen(xdpy->dpy); xdpy->xscr = x11_screen_create(xdpy->dpy, xdpy->xscr_number); if (!xdpy->xscr) { - free(xdpy); + FREE(xdpy); return NULL; } @@ -718,7 +672,6 @@ x11_create_ximage_display(EGLNativeDisplayType dpy, xdpy->base.is_pixmap_supported = ximage_display_is_pixmap_supported; xdpy->base.create_window_surface = ximage_display_create_window_surface; xdpy->base.create_pixmap_surface = ximage_display_create_pixmap_surface; - xdpy->base.create_pbuffer_surface = ximage_display_create_pbuffer_surface; return &xdpy->base; } diff --git a/src/gallium/state_trackers/egl/x11/x11_screen.c b/src/gallium/state_trackers/egl/x11/x11_screen.c index f4096114844..6bdff26ec08 100644 --- a/src/gallium/state_trackers/egl/x11/x11_screen.c +++ b/src/gallium/state_trackers/egl/x11/x11_screen.c @@ -14,24 +14,24 @@ * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. */ #include <unistd.h> #include <fcntl.h> #include <sys/types.h> #include <sys/stat.h> +#include <xf86drm.h> #include <X11/Xlibint.h> #include <X11/extensions/XShm.h> + #include "util/u_memory.h" -#include "util/u_math.h" -#include "util/u_format.h" -#include "xf86drm.h" #include "egllog.h" #include "x11_screen.h" @@ -109,7 +109,7 @@ x11_screen_destroy(struct x11_screen *xscr) if (xscr->visuals) XFree(xscr->visuals); - free(xscr); + FREE(xscr); } static boolean @@ -176,63 +176,6 @@ x11_screen_get_visuals(struct x11_screen *xscr, int *num_visuals) return xscr->visuals; } -void -x11_screen_convert_visual(struct x11_screen *xscr, const XVisualInfo *visual, - __GLcontextModes *mode) -{ - int r, g, b, a; - int visual_type; - - r = util_bitcount(visual->red_mask); - g = util_bitcount(visual->green_mask); - b = util_bitcount(visual->blue_mask); - a = visual->depth - (r + g + b); -#if defined(__cplusplus) || defined(c_plusplus) - visual_type = visual->c_class; -#else - visual_type = visual->class; -#endif - - /* convert to GLX visual type */ - switch (visual_type) { - case TrueColor: - visual_type = GLX_TRUE_COLOR; - break; - case DirectColor: - visual_type = GLX_DIRECT_COLOR; - break; - case PseudoColor: - visual_type = GLX_PSEUDO_COLOR; - break; - case StaticColor: - visual_type = GLX_STATIC_COLOR; - break; - case GrayScale: - visual_type = GLX_GRAY_SCALE; - break; - case StaticGray: - visual_type = GLX_STATIC_GRAY; - break; - default: - visual_type = GLX_NONE; - break; - } - - mode->rgbBits = r + g + b + a; - mode->redBits = r; - mode->greenBits = g; - mode->blueBits = b; - mode->alphaBits = a; - mode->visualID = visual->visualid; - mode->visualType = visual_type; - - /* sane defaults */ - mode->renderType = GLX_RGBA_BIT; - mode->rgbMode = TRUE; - mode->visualRating = GLX_SLOW_CONFIG; - mode->xRenderable = TRUE; -} - /** * Return the GLX fbconfigs. */ @@ -435,7 +378,7 @@ x11_context_modes_create(unsigned count) next = &base; for (i = 0; i < count; i++) { - *next = (__GLcontextModes *) calloc(1, size); + *next = (__GLcontextModes *) CALLOC(1, size); if (*next == NULL) { x11_context_modes_destroy(base); base = NULL; @@ -455,7 +398,7 @@ x11_context_modes_destroy(__GLcontextModes *modes) { while (modes != NULL) { __GLcontextModes *next = modes->next; - free(modes); + FREE(modes); modes = next; } } diff --git a/src/gallium/state_trackers/egl/x11/x11_screen.h b/src/gallium/state_trackers/egl/x11/x11_screen.h index 37e8d5a40e6..a3c5ee1491e 100644 --- a/src/gallium/state_trackers/egl/x11/x11_screen.h +++ b/src/gallium/state_trackers/egl/x11/x11_screen.h @@ -14,12 +14,13 @@ * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. */ #ifndef _X11_SCREEN_H_ @@ -28,6 +29,8 @@ #include <X11/Xlib.h> #include <X11/Xutil.h> #include <X11/extensions/dri2tokens.h> +#include "GL/gl.h" /* for GL types needed by __GLcontextModes */ +#include "GL/internal/glcore.h" /* for __GLcontextModes */ #include "pipe/p_compiler.h" #include "common/native.h" @@ -64,10 +67,6 @@ x11_screen_support(struct x11_screen *xscr, enum x11_screen_extension ext); const XVisualInfo * x11_screen_get_visuals(struct x11_screen *xscr, int *num_visuals); -void -x11_screen_convert_visual(struct x11_screen *xscr, const XVisualInfo *visual, - __GLcontextModes *mode); - const __GLcontextModes * x11_screen_get_glx_configs(struct x11_screen *xscr); diff --git a/src/gallium/state_trackers/es/Makefile b/src/gallium/state_trackers/es/Makefile index 089d4411675..7370634ea24 100644 --- a/src/gallium/state_trackers/es/Makefile +++ b/src/gallium/state_trackers/es/Makefile @@ -22,6 +22,8 @@ GLES_2_LIB = GLESv2 GLES_2_LIB_NAME = lib$(GLES_2_LIB).so +# These two objects indirectly reference all public functions thanks to the use +# of _glapi_get_proc_address. ES1_OBJECTS = st_es1.o ES2_OBJECTS = st_es2.o @@ -56,9 +58,7 @@ $(TOP)/$(LIB_DIR)/$(GLES_1_LIB_NAME): $(ES1_OBJECTS) $(ES1_LIBS) $(GALLIUM_AUXIL -minor $(GLES_1_VERSION_MINOR) \ -patch $(GLES_1_VERSION_PATCH) \ -install $(TOP)/$(LIB_DIR) $(MKLIB_OPTIONS) \ - $(ES1_OBJECTS) \ - -Wl,--whole-archive $(ES1_LIBS) -Wl,--no-whole-archive \ - $(GALLIUM_AUXILIARIES) $(SYS_LIBS) + $(ES1_OBJECTS) $(ES1_LIBS) $(GALLIUM_AUXILIARIES) $(SYS_LIBS) $(TOP)/$(LIB_DIR)/$(GLES_2_LIB_NAME): $(ES2_OBJECTS) $(ES1_LIBS) $(GALLIUM_AUXILIARIES) $(MKLIB) -o $(GLES_2_LIB) -linker '$(CC)' -ldflags '$(LDFLAGS)' \ @@ -66,9 +66,7 @@ $(TOP)/$(LIB_DIR)/$(GLES_2_LIB_NAME): $(ES2_OBJECTS) $(ES1_LIBS) $(GALLIUM_AUXIL -minor $(GLES_2_VERSION_MINOR) \ -patch $(GLES_2_VERSION_PATCH) \ -install $(TOP)/$(LIB_DIR) $(MKLIB_OPTIONS) \ - $(ES2_OBJECTS) \ - -Wl,--whole-archive $(ES2_LIBS) -Wl,--no-whole-archive \ - $(GALLIUM_AUXILIARIES) $(SYS_LIBS) + $(ES2_OBJECTS) $(ES2_LIBS) $(GALLIUM_AUXILIARIES) $(SYS_LIBS) install: default $(INSTALL) -d $(DESTDIR)$(INSTALL_DIR)/include/GLES diff --git a/src/gallium/state_trackers/glx/xlib/xm_api.c b/src/gallium/state_trackers/glx/xlib/xm_api.c index c394430b94f..f3b0617f76b 100644 --- a/src/gallium/state_trackers/glx/xlib/xm_api.c +++ b/src/gallium/state_trackers/glx/xlib/xm_api.c @@ -339,7 +339,7 @@ static enum pipe_format choose_depth_stencil_format(XMesaDisplay xmdpy, int depth, int stencil) { const enum pipe_texture_target target = PIPE_TEXTURE_2D; - const unsigned tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL; + const unsigned tex_usage = PIPE_BIND_DEPTH_STENCIL; const unsigned geom_flags = (PIPE_TEXTURE_GEOM_NON_SQUARE | PIPE_TEXTURE_GEOM_NON_POWER_OF_TWO); enum pipe_format formats[8], fmt; diff --git a/src/gallium/state_trackers/glx/xlib/xm_st.c b/src/gallium/state_trackers/glx/xlib/xm_st.c index b6ed7e8e1e8..27b6da94bce 100644 --- a/src/gallium/state_trackers/glx/xlib/xm_st.c +++ b/src/gallium/state_trackers/glx/xlib/xm_st.c @@ -14,12 +14,13 @@ * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. * * Authors: * Chia-I Wu <olv@lunarg.com> @@ -39,7 +40,7 @@ struct xmesa_st_framebuffer { struct st_visual stvis; unsigned texture_width, texture_height, texture_mask; - struct pipe_texture *textures[ST_ATTACHMENT_COUNT]; + struct pipe_resource *textures[ST_ATTACHMENT_COUNT]; struct pipe_surface *display_surface; }; @@ -58,7 +59,7 @@ xmesa_st_framebuffer_display(struct st_framebuffer_iface *stfbi, enum st_attachment_type statt) { struct xmesa_st_framebuffer *xstfb = xmesa_st_framebuffer(stfbi); - struct pipe_texture *ptex = xstfb->textures[statt]; + struct pipe_resource *ptex = xstfb->textures[statt]; struct pipe_surface *psurf; if (!ptex) @@ -70,7 +71,7 @@ xmesa_st_framebuffer_display(struct st_framebuffer_iface *stfbi, pipe_surface_reference(&xstfb->display_surface, NULL); psurf = xstfb->screen->get_tex_surface(xstfb->screen, - ptex, 0, 0, 0, PIPE_BUFFER_USAGE_CPU_READ); + ptex, 0, 0, 0, PIPE_BIND_DISPLAY_TARGET); if (!psurf) return FALSE; @@ -93,8 +94,8 @@ xmesa_st_framebuffer_copy_textures(struct st_framebuffer_iface *stfbi, unsigned width, unsigned height) { struct xmesa_st_framebuffer *xstfb = xmesa_st_framebuffer(stfbi); - struct pipe_texture *src_ptex = xstfb->textures[src_statt]; - struct pipe_texture *dst_ptex = xstfb->textures[dst_statt]; + struct pipe_resource *src_ptex = xstfb->textures[src_statt]; + struct pipe_resource *dst_ptex = xstfb->textures[dst_statt]; struct pipe_surface *src, *dst; struct pipe_context *pipe; @@ -110,9 +111,9 @@ xmesa_st_framebuffer_copy_textures(struct st_framebuffer_iface *stfbi, } src = xstfb->screen->get_tex_surface(xstfb->screen, - src_ptex, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_READ); + src_ptex, 0, 0, 0, PIPE_BIND_BLIT_SOURCE); dst = xstfb->screen->get_tex_surface(xstfb->screen, - dst_ptex, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE); + dst_ptex, 0, 0, 0, PIPE_BIND_BLIT_DESTINATION); if (src && dst) pipe->surface_copy(pipe, dst, x, y, src, x, y, width, height); @@ -130,13 +131,13 @@ xmesa_st_framebuffer_validate_textures(struct st_framebuffer_iface *stfbi, unsigned mask) { struct xmesa_st_framebuffer *xstfb = xmesa_st_framebuffer(stfbi); - struct pipe_texture templ; + struct pipe_resource templ; unsigned i; /* remove outdated textures */ if (xstfb->texture_width != width || xstfb->texture_height != height) { for (i = 0; i < ST_ATTACHMENT_COUNT; i++) - pipe_texture_reference(&xstfb->textures[i], NULL); + pipe_resource_reference(&xstfb->textures[i], NULL); } memset(&templ, 0, sizeof(templ)); @@ -148,7 +149,7 @@ xmesa_st_framebuffer_validate_textures(struct st_framebuffer_iface *stfbi, for (i = 0; i < ST_ATTACHMENT_COUNT; i++) { enum pipe_format format; - unsigned tex_usage; + unsigned bind; /* the texture already exists or not requested */ if (xstfb->textures[i] || !(mask & (1 << i))) { @@ -164,12 +165,12 @@ xmesa_st_framebuffer_validate_textures(struct st_framebuffer_iface *stfbi, case ST_ATTACHMENT_FRONT_RIGHT: case ST_ATTACHMENT_BACK_RIGHT: format = xstfb->stvis.color_format; - tex_usage = PIPE_TEXTURE_USAGE_DISPLAY_TARGET | - PIPE_TEXTURE_USAGE_RENDER_TARGET; + bind = PIPE_BIND_DISPLAY_TARGET | + PIPE_BIND_RENDER_TARGET; break; case ST_ATTACHMENT_DEPTH_STENCIL: format = xstfb->stvis.depth_stencil_format; - tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL; + bind = PIPE_BIND_DEPTH_STENCIL; break; default: format = PIPE_FORMAT_NONE; @@ -178,10 +179,10 @@ xmesa_st_framebuffer_validate_textures(struct st_framebuffer_iface *stfbi, if (format != PIPE_FORMAT_NONE) { templ.format = format; - templ.tex_usage = tex_usage; + templ.bind = bind; xstfb->textures[i] = - xstfb->screen->texture_create(xstfb->screen, &templ); + xstfb->screen->resource_create(xstfb->screen, &templ); } } @@ -194,7 +195,7 @@ static boolean xmesa_st_framebuffer_validate(struct st_framebuffer_iface *stfbi, const enum st_attachment_type *statts, unsigned count, - struct pipe_texture **out) + struct pipe_resource **out) { struct xmesa_st_framebuffer *xstfb = xmesa_st_framebuffer(stfbi); unsigned statt_mask, new_mask, i; @@ -231,7 +232,7 @@ xmesa_st_framebuffer_validate(struct st_framebuffer_iface *stfbi, for (i = 0; i < count; i++) { out[i] = NULL; - pipe_texture_reference(&out[i], xstfb->textures[statts[i]]); + pipe_resource_reference(&out[i], xstfb->textures[statts[i]]); } return TRUE; @@ -291,7 +292,7 @@ xmesa_destroy_st_framebuffer(struct st_framebuffer_iface *stfbi) pipe_surface_reference(&xstfb->display_surface, NULL); for (i = 0; i < ST_ATTACHMENT_COUNT; i++) - pipe_texture_reference(&xstfb->textures[i], NULL); + pipe_resource_reference(&xstfb->textures[i], NULL); FREE(xstfb); FREE(stfbi); @@ -305,7 +306,7 @@ xmesa_swap_st_framebuffer(struct st_framebuffer_iface *stfbi) ret = xmesa_st_framebuffer_display(stfbi, ST_ATTACHMENT_BACK_LEFT); if (ret) { - struct pipe_texture **front, **back, *tmp; + struct pipe_resource **front, **back, *tmp; front = &xstfb->textures[ST_ATTACHMENT_FRONT_LEFT]; back = &xstfb->textures[ST_ATTACHMENT_BACK_LEFT]; diff --git a/src/gallium/state_trackers/glx/xlib/xm_st.h b/src/gallium/state_trackers/glx/xlib/xm_st.h index 396495c1893..862597617e3 100644 --- a/src/gallium/state_trackers/glx/xlib/xm_st.h +++ b/src/gallium/state_trackers/glx/xlib/xm_st.h @@ -14,12 +14,13 @@ * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. * * Authors: * Chia-I Wu <olv@lunarg.com> diff --git a/src/gallium/state_trackers/python/SConscript b/src/gallium/state_trackers/python/SConscript index 781f54bf2b9..aadeaa0a359 100644 --- a/src/gallium/state_trackers/python/SConscript +++ b/src/gallium/state_trackers/python/SConscript @@ -44,11 +44,10 @@ if 'python' in env['statetrackers']: gallium, ]) - if 'llvmpipe' in env['drivers']: + if env['llvm']: env.Append(CPPDEFINES = ['HAVE_LLVMPIPE']) - env.Tool('llvm') env.Prepend(LIBS = [llvmpipe]) - if 'softpipe' in env['drivers']: + if True: env.Append(CPPDEFINES = ['HAVE_SOFTPIPE']) env.Prepend(LIBS = [softpipe]) diff --git a/src/gallium/state_trackers/python/gallium.i b/src/gallium/state_trackers/python/gallium.i index aeed1cd118c..c6084f78aee 100644 --- a/src/gallium/state_trackers/python/gallium.i +++ b/src/gallium/state_trackers/python/gallium.i @@ -72,9 +72,8 @@ %rename(Device) st_device; %rename(Context) st_context; -%rename(Texture) pipe_texture; +%rename(Resource) pipe_resource; %rename(Surface) st_surface; -%rename(Buffer) pipe_buffer; %rename(BlendColor) pipe_blend_color; %rename(Blend) pipe_blend_state; diff --git a/src/gallium/state_trackers/python/p_context.i b/src/gallium/state_trackers/python/p_context.i index 02ce5647eb6..13c8d1a95e9 100644 --- a/src/gallium/state_trackers/python/p_context.i +++ b/src/gallium/state_trackers/python/p_context.i @@ -127,6 +127,45 @@ struct st_context { $self->gs = gs; } + struct pipe_sampler_view * + create_sampler_view(struct pipe_resource *texture, + enum pipe_format format = PIPE_FORMAT_NONE, + unsigned first_level = 0, + unsigned last_level = ~0, + unsigned swizzle_r = 0, + unsigned swizzle_g = 1, + unsigned swizzle_b = 2, + unsigned swizzle_a = 3) + { + struct pipe_context *pipe = $self->pipe; + struct pipe_sampler_view templat; + + memset(&templat, 0, sizeof templat); + if (format == PIPE_FORMAT_NONE) { + templat.format = texture->format; + } else { + templat.format = format; + } + templat.last_level = MIN2(last_level, texture->last_level); + templat.first_level = first_level; + templat.last_level = last_level; + templat.swizzle_r = swizzle_r; + templat.swizzle_g = swizzle_g; + templat.swizzle_b = swizzle_b; + templat.swizzle_a = swizzle_a; + + return pipe->create_sampler_view(pipe, texture, &templat); + } + + void + sampler_view_destroy(struct pipe_context *ctx, + struct pipe_sampler_view *view) + { + struct pipe_context *pipe = $self->pipe; + + pipe->sampler_view_destroy(pipe, view); + } + /* * Parameter-like state (or properties) */ @@ -144,7 +183,7 @@ struct st_context { } void set_constant_buffer(unsigned shader, unsigned index, - struct pipe_buffer *buffer ) + struct pipe_resource *buffer ) { $self->pipe->set_constant_buffer($self->pipe, shader, index, buffer); } @@ -167,8 +206,28 @@ struct st_context { cso_set_viewport($self->cso, state); } + void set_fragment_sampler_view(unsigned index, + struct pipe_sampler_view *view) + { + pipe_sampler_view_reference(&$self->fragment_sampler_views[index], view); + + $self->pipe->set_fragment_sampler_views($self->pipe, + PIPE_MAX_SAMPLERS, + $self->fragment_sampler_views); + } + + void set_vertex_sampler_view(unsigned index, + struct pipe_sampler_view *view) + { + pipe_sampler_view_reference(&$self->vertex_sampler_views[index], view); + + $self->pipe->set_vertex_sampler_views($self->pipe, + PIPE_MAX_VERTEX_SAMPLERS, + $self->vertex_sampler_views); + } + void set_fragment_sampler_texture(unsigned index, - struct pipe_texture *texture) { + struct pipe_resource *texture) { struct pipe_sampler_view templ; if(!texture) @@ -186,7 +245,7 @@ struct st_context { } void set_vertex_sampler_texture(unsigned index, - struct pipe_texture *texture) { + struct pipe_resource *texture) { struct pipe_sampler_view templ; if(!texture) @@ -208,7 +267,7 @@ struct st_context { unsigned stride, unsigned max_index, unsigned buffer_offset, - struct pipe_buffer *buffer) + struct pipe_resource *buffer) { unsigned i; struct pipe_vertex_buffer state; @@ -252,7 +311,7 @@ struct st_context { $self->pipe->draw_arrays($self->pipe, mode, start, count); } - void draw_elements( struct pipe_buffer *indexBuffer, + void draw_elements( struct pipe_resource *indexBuffer, unsigned indexSize, unsigned mode, unsigned start, unsigned count) { @@ -262,7 +321,7 @@ struct st_context { mode, start, count); } - void draw_range_elements( struct pipe_buffer *indexBuffer, + void draw_range_elements( struct pipe_resource *indexBuffer, unsigned indexSize, unsigned minIndex, unsigned maxIndex, unsigned mode, unsigned start, unsigned count) { @@ -279,7 +338,8 @@ struct st_context { { struct pipe_context *pipe = $self->pipe; struct pipe_screen *screen = pipe->screen; - struct pipe_buffer *vbuf; + struct pipe_resource *vbuf; + struct pipe_transfer *transfer; struct pipe_vertex_element velements[PIPE_MAX_ATTRIBS]; struct pipe_vertex_buffer vbuffer; float *map; @@ -289,17 +349,16 @@ struct st_context { size = num_verts * num_attribs * 4 * sizeof(float); vbuf = pipe_buffer_create(screen, - 32, - PIPE_BUFFER_USAGE_VERTEX, + PIPE_BIND_VERTEX_BUFFER, size); if(!vbuf) goto error1; - - map = pipe_buffer_map(screen, vbuf, PIPE_BUFFER_USAGE_CPU_WRITE); + + map = pipe_buffer_map(pipe, vbuf, PIPE_TRANSFER_WRITE, &transfer); if (!map) goto error2; memcpy(map, vertices, size); - pipe_buffer_unmap(screen, vbuf); + pipe_buffer_unmap(pipe, vbuf, transfer); cso_save_vertex_elements($self->cso); @@ -326,7 +385,7 @@ struct st_context { cso_restore_vertex_elements($self->cso); error2: - pipe_buffer_reference(&vbuf, NULL); + pipe_resource_reference(&vbuf, NULL); error1: ; } @@ -362,11 +421,11 @@ error1: struct pipe_surface *_dst = NULL; struct pipe_surface *_src = NULL; - _dst = st_pipe_surface(dst, PIPE_BUFFER_USAGE_GPU_WRITE); + _dst = st_pipe_surface(dst, PIPE_BIND_BLIT_DESTINATION); if(!_dst) SWIG_exception(SWIG_ValueError, "couldn't acquire destination surface for writing"); - _src = st_pipe_surface(src, PIPE_BUFFER_USAGE_GPU_READ); + _src = st_pipe_surface(src, PIPE_BIND_BLIT_SOURCE); if(!_src) SWIG_exception(SWIG_ValueError, "couldn't acquire source surface for reading"); @@ -384,7 +443,7 @@ error1: { struct pipe_surface *_dst = NULL; - _dst = st_pipe_surface(dst, PIPE_BUFFER_USAGE_GPU_WRITE); + _dst = st_pipe_surface(dst, PIPE_BIND_BLIT_DESTINATION); if(!_dst) SWIG_exception(SWIG_ValueError, "couldn't acquire destination surface for writing"); @@ -400,7 +459,7 @@ error1: unsigned x, unsigned y, unsigned w, unsigned h, char **STRING, int *LENGTH) { - struct pipe_texture *texture = surface->texture; + struct pipe_resource *texture = surface->texture; struct pipe_context *pipe = $self->pipe; struct pipe_transfer *transfer; unsigned stride; @@ -411,16 +470,16 @@ error1: if(!*STRING) return; - transfer = pipe->get_tex_transfer(pipe, - surface->texture, - surface->face, - surface->level, - surface->zslice, - PIPE_TRANSFER_READ, - x, y, w, h); + transfer = pipe_get_transfer(pipe, + surface->texture, + surface->face, + surface->level, + surface->zslice, + PIPE_TRANSFER_READ, + x, y, w, h); if(transfer) { pipe_get_tile_raw(pipe, transfer, 0, 0, w, h, *STRING, stride); - pipe->tex_transfer_destroy(pipe, transfer); + pipe->transfer_destroy(pipe, transfer); } } @@ -430,7 +489,7 @@ error1: unsigned x, unsigned y, unsigned w, unsigned h, const char *STRING, unsigned LENGTH, unsigned stride = 0) { - struct pipe_texture *texture = surface->texture; + struct pipe_resource *texture = surface->texture; struct pipe_context *pipe = $self->pipe; struct pipe_transfer *transfer; @@ -440,18 +499,18 @@ error1: if(LENGTH < util_format_get_nblocksy(texture->format, h) * stride) SWIG_exception(SWIG_ValueError, "offset must be smaller than buffer size"); - transfer = pipe->get_tex_transfer(pipe, - surface->texture, - surface->face, - surface->level, - surface->zslice, - PIPE_TRANSFER_WRITE, - x, y, w, h); + transfer = pipe_get_transfer(pipe, + surface->texture, + surface->face, + surface->level, + surface->zslice, + PIPE_TRANSFER_WRITE, + x, y, w, h); if(!transfer) SWIG_exception(SWIG_MemoryError, "couldn't initiate transfer"); pipe_put_tile_raw(pipe, transfer, 0, 0, w, h, STRING, stride); - pipe->tex_transfer_destroy(pipe, transfer); + pipe->transfer_destroy(pipe, transfer); fail: return; @@ -464,16 +523,16 @@ error1: { struct pipe_context *pipe = $self->pipe; struct pipe_transfer *transfer; - transfer = pipe->get_tex_transfer(pipe, - surface->texture, - surface->face, - surface->level, - surface->zslice, - PIPE_TRANSFER_READ, - x, y, w, h); + transfer = pipe_get_transfer(pipe, + surface->texture, + surface->face, + surface->level, + surface->zslice, + PIPE_TRANSFER_READ, + x, y, w, h); if(transfer) { pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba); - pipe->tex_transfer_destroy(pipe, transfer); + pipe->transfer_destroy(pipe, transfer); } } @@ -484,16 +543,16 @@ error1: { struct pipe_context *pipe = $self->pipe; struct pipe_transfer *transfer; - transfer = pipe->get_tex_transfer(pipe, - surface->texture, - surface->face, - surface->level, - surface->zslice, - PIPE_TRANSFER_WRITE, - x, y, w, h); + transfer = pipe_get_transfer(pipe, + surface->texture, + surface->face, + surface->level, + surface->zslice, + PIPE_TRANSFER_WRITE, + x, y, w, h); if(transfer) { pipe_put_tile_rgba(pipe, transfer, 0, 0, w, h, rgba); - pipe->tex_transfer_destroy(pipe, transfer); + pipe->transfer_destroy(pipe, transfer); } } @@ -526,14 +585,13 @@ error1: rgba8 = (unsigned char *) *STRING; - transfer = pipe->get_tex_transfer(pipe, - surface->texture, - surface->face, - surface->level, - surface->zslice, - PIPE_TRANSFER_READ, - x, y, - w, h); + transfer = pipe_get_transfer(pipe, + surface->texture, + surface->face, + surface->level, + surface->zslice, + PIPE_TRANSFER_READ, + x, y, w, h); if(transfer) { pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba); for(j = 0; j < h; ++j) { @@ -541,7 +599,7 @@ error1: for(k = 0; k <4; ++k) rgba8[j*w*4 + i*4 + k] = float_to_ubyte(rgba[j*w*4 + i*4 + k]); } - pipe->tex_transfer_destroy(pipe, transfer); + pipe->transfer_destroy(pipe, transfer); } free(rgba); @@ -554,16 +612,16 @@ error1: { struct pipe_context *pipe = $self->pipe; struct pipe_transfer *transfer; - transfer = pipe->get_tex_transfer(pipe, - surface->texture, - surface->face, - surface->level, - surface->zslice, - PIPE_TRANSFER_READ, - x, y, w, h); + transfer = pipe_get_transfer(pipe, + surface->texture, + surface->face, + surface->level, + surface->zslice, + PIPE_TRANSFER_READ, + x, y, w, h); if(transfer) { pipe_get_tile_z(pipe, transfer, 0, 0, w, h, z); - pipe->tex_transfer_destroy(pipe, transfer); + pipe->transfer_destroy(pipe, transfer); } } @@ -574,16 +632,16 @@ error1: { struct pipe_context *pipe = $self->pipe; struct pipe_transfer *transfer; - transfer = pipe->get_tex_transfer(pipe, - surface->texture, - surface->face, - surface->level, - surface->zslice, - PIPE_TRANSFER_WRITE, - x, y, w, h); + transfer = pipe_get_transfer(pipe, + surface->texture, + surface->face, + surface->level, + surface->zslice, + PIPE_TRANSFER_WRITE, + x, y, w, h); if(transfer) { pipe_put_tile_z(pipe, transfer, 0, 0, w, h, z); - pipe->tex_transfer_destroy(pipe, transfer); + pipe->transfer_destroy(pipe, transfer); } } @@ -611,20 +669,20 @@ error1: if(!rgba2) return ~0; - transfer = pipe->get_tex_transfer(pipe, - surface->texture, - surface->face, - surface->level, - surface->zslice, - PIPE_TRANSFER_READ, - x, y, w, h); + transfer = pipe_get_transfer(pipe, + surface->texture, + surface->face, + surface->level, + surface->zslice, + PIPE_TRANSFER_READ, + x, y, w, h); if(!transfer) { FREE(rgba2); return ~0; } pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba2); - pipe->tex_transfer_destroy(pipe, transfer); + pipe->transfer_destroy(pipe, transfer); p1 = rgba; p2 = rgba2; @@ -644,4 +702,54 @@ error1: return n; } + %cstring_input_binary(const char *STRING, unsigned LENGTH); + void + transfer_inline_write(struct pipe_resource *resource, + struct pipe_subresource *sr, + unsigned usage, + const struct pipe_box *box, + const char *STRING, unsigned LENGTH, + unsigned stride, + unsigned slice_stride) + { + struct pipe_context *pipe = $self->pipe; + + pipe->transfer_inline_write(pipe, resource, *sr, usage, box, STRING, stride, slice_stride); + } + + %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1)); + void buffer_read(struct pipe_resource *buffer, + char **STRING, int *LENGTH) + { + struct pipe_context *pipe = $self->pipe; + + assert(buffer->target == PIPE_BUFFER); + + *LENGTH = buffer->width0; + *STRING = (char *) malloc(buffer->width0); + if(!*STRING) + return; + + pipe_buffer_read(pipe, buffer, 0, buffer->width0, *STRING); + } + + void buffer_write(struct pipe_resource *buffer, + const char *STRING, unsigned LENGTH, unsigned offset = 0) + { + struct pipe_context *pipe = $self->pipe; + + assert(buffer->target == PIPE_BUFFER); + + if(offset > buffer->width0) + SWIG_exception(SWIG_ValueError, "offset must be smaller than buffer size"); + + if(offset + LENGTH > buffer->width0) + SWIG_exception(SWIG_ValueError, "data length must fit inside the buffer"); + + pipe_buffer_write(pipe, buffer, offset, LENGTH, STRING); + +fail: + return; + } + }; diff --git a/src/gallium/state_trackers/python/p_device.i b/src/gallium/state_trackers/python/p_device.i index 0eba488a078..959c13f54d9 100644 --- a/src/gallium/state_trackers/python/p_device.i +++ b/src/gallium/state_trackers/python/p_device.i @@ -81,20 +81,20 @@ struct st_device { /** * Check if the given pipe_format is supported as a texture or * drawing surface. - * \param type one of PIPE_TEXTURE, PIPE_SURFACE + * \param bind bitmask of PIPE_BIND flags */ int is_format_supported( enum pipe_format format, enum pipe_texture_target target, - unsigned tex_usage, + unsigned bind, unsigned geom_flags ) { /* We can't really display surfaces with the python statetracker so mask * out that usage */ - tex_usage &= ~PIPE_TEXTURE_USAGE_DISPLAY_TARGET; + bind &= ~PIPE_BIND_DISPLAY_TARGET; return $self->screen->is_format_supported( $self->screen, format, target, - tex_usage, + bind, geom_flags ); } @@ -103,21 +103,21 @@ struct st_device { return st_context_create($self); } - struct pipe_texture * - texture_create( + struct pipe_resource * + resource_create( enum pipe_format format, unsigned width, unsigned height, unsigned depth = 1, unsigned last_level = 0, enum pipe_texture_target target = PIPE_TEXTURE_2D, - unsigned tex_usage = 0 + unsigned bind = 0 ) { - struct pipe_texture templat; + struct pipe_resource templat; /* We can't really display surfaces with the python statetracker so mask * out that usage */ - tex_usage &= ~PIPE_TEXTURE_USAGE_DISPLAY_TARGET; + bind &= ~PIPE_BIND_DISPLAY_TARGET; memset(&templat, 0, sizeof(templat)); templat.format = format; @@ -126,14 +126,13 @@ struct st_device { templat.depth0 = depth; templat.last_level = last_level; templat.target = target; - templat.tex_usage = tex_usage; + templat.bind = bind; - return $self->screen->texture_create($self->screen, &templat); - } - - struct pipe_buffer * - buffer_create(unsigned size, unsigned alignment = 0, unsigned usage = 0) { - return pipe_buffer_create($self->screen, alignment, usage, size); + return $self->screen->resource_create($self->screen, &templat); } + struct pipe_resource * + buffer_create(unsigned size, unsigned bind = 0) { + return pipe_buffer_create($self->screen, bind, size); + } }; diff --git a/src/gallium/state_trackers/python/p_state.i b/src/gallium/state_trackers/python/p_state.i index eda77b56f8e..c1e6ea1b43c 100644 --- a/src/gallium/state_trackers/python/p_state.i +++ b/src/gallium/state_trackers/python/p_state.i @@ -114,7 +114,7 @@ SWIG_exception(SWIG_ValueError, "index out of bounds"); if(surface) { - _surface = st_pipe_surface(surface, PIPE_BUFFER_USAGE_GPU_WRITE); + _surface = st_pipe_surface(surface, PIPE_BIND_RENDER_TARGET); if(!_surface) SWIG_exception(SWIG_ValueError, "couldn't acquire surface for writing"); } @@ -131,7 +131,7 @@ struct pipe_surface *_surface = NULL; if(surface) { - _surface = st_pipe_surface(surface, PIPE_BUFFER_USAGE_GPU_WRITE); + _surface = st_pipe_surface(surface, PIPE_BIND_DEPTH_STENCIL); if(!_surface) SWIG_exception(SWIG_ValueError, "couldn't acquire surface for writing"); } diff --git a/src/gallium/state_trackers/python/p_texture.i b/src/gallium/state_trackers/python/p_texture.i index 923a6285289..ae506944c45 100644 --- a/src/gallium/state_trackers/python/p_texture.i +++ b/src/gallium/state_trackers/python/p_texture.i @@ -33,97 +33,105 @@ */ -%nodefaultctor pipe_texture; +%nodefaultctor pipe_resource; %nodefaultctor st_surface; -%nodefaultctor pipe_buffer; -%nodefaultdtor pipe_texture; +%nodefaultdtor pipe_resource; %nodefaultdtor st_surface; -%nodefaultdtor pipe_buffer; -%ignore pipe_texture::screen; +%ignore pipe_resource::screen; %immutable st_surface::texture; %immutable st_surface::face; %immutable st_surface::level; %immutable st_surface::zslice; -%newobject pipe_texture::get_surface; +%newobject pipe_resource::get_surface; +/* Avoid naming conflict with p_inlines.h's pipe_buffer_read/write */ +%rename(read) read_; +%rename(write) write_; -%extend pipe_texture { - - ~pipe_texture() { - struct pipe_texture *ptr = $self; - pipe_texture_reference(&ptr, NULL); +%extend pipe_resource { + + ~pipe_resource() { + struct pipe_resource *ptr = $self; + pipe_resource_reference(&ptr, NULL); } - + unsigned get_width(unsigned level=0) { return u_minify($self->width0, level); } - + unsigned get_height(unsigned level=0) { return u_minify($self->height0, level); } - + unsigned get_depth(unsigned level=0) { return u_minify($self->depth0, level); } - + /** Get a surface which is a "view" into a texture */ struct st_surface * get_surface(unsigned face=0, unsigned level=0, unsigned zslice=0) { struct st_surface *surface; - + if(face >= ($self->target == PIPE_TEXTURE_CUBE ? 6U : 1U)) SWIG_exception(SWIG_ValueError, "face out of bounds"); if(level > $self->last_level) SWIG_exception(SWIG_ValueError, "level out of bounds"); if(zslice >= u_minify($self->depth0, level)) SWIG_exception(SWIG_ValueError, "zslice out of bounds"); - + surface = CALLOC_STRUCT(st_surface); if(!surface) return NULL; - - pipe_texture_reference(&surface->texture, $self); + + pipe_resource_reference(&surface->texture, $self); surface->face = face; surface->level = level; surface->zslice = zslice; - + return surface; fail: return NULL; } - + + unsigned __len__(void) + { + assert($self->target == PIPE_BUFFER); + assert(p_atomic_read(&$self->reference.count) > 0); + return $self->width0; + } + }; struct st_surface { %immutable; - - struct pipe_texture *texture; + + struct pipe_resource *texture; unsigned face; unsigned level; unsigned zslice; - + }; %extend st_surface { - + %immutable; - + unsigned format; unsigned width; unsigned height; - + ~st_surface() { - pipe_texture_reference(&$self->texture, NULL); + pipe_resource_reference(&$self->texture, NULL); FREE($self); } - + }; @@ -146,55 +154,3 @@ struct st_surface return u_minify(surface->texture->height0, surface->level); } %} - -/* Avoid naming conflict with p_inlines.h's pipe_buffer_read/write */ -%rename(read) read_; -%rename(write) write_; - -%extend pipe_buffer { - - ~pipe_buffer() { - struct pipe_buffer *ptr = $self; - pipe_buffer_reference(&ptr, NULL); - } - - unsigned __len__(void) - { - assert(p_atomic_read(&$self->reference.count) > 0); - return $self->size; - } - - %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1)); - void read_(char **STRING, int *LENGTH) - { - struct pipe_screen *screen = $self->screen; - - assert(p_atomic_read(&$self->reference.count) > 0); - - *LENGTH = $self->size; - *STRING = (char *) malloc($self->size); - if(!*STRING) - return; - - pipe_buffer_read(screen, $self, 0, $self->size, *STRING); - } - - %cstring_input_binary(const char *STRING, unsigned LENGTH); - void write_(const char *STRING, unsigned LENGTH, unsigned offset = 0) - { - struct pipe_screen *screen = $self->screen; - - assert(p_atomic_read(&$self->reference.count) > 0); - - if(offset > $self->size) - SWIG_exception(SWIG_ValueError, "offset must be smaller than buffer size"); - - if(offset + LENGTH > $self->size) - SWIG_exception(SWIG_ValueError, "data length must fit inside the buffer"); - - pipe_buffer_write(screen, $self, offset, LENGTH, STRING); - -fail: - return; - } -}; diff --git a/src/gallium/state_trackers/python/st_device.c b/src/gallium/state_trackers/python/st_device.c index 4f227a092c5..135acad45e1 100644 --- a/src/gallium/state_trackers/python/st_device.c +++ b/src/gallium/state_trackers/python/st_device.c @@ -129,7 +129,7 @@ st_context_destroy(struct st_context *st_ctx) pipe_sampler_view_reference(&st_ctx->fragment_sampler_views[i], NULL); for(i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; ++i) pipe_sampler_view_reference(&st_ctx->vertex_sampler_views[i], NULL); - pipe_texture_reference(&st_ctx->default_texture, NULL); + pipe_resource_reference(&st_ctx->default_texture, NULL); FREE(st_ctx); @@ -231,8 +231,7 @@ st_context_create(struct st_device *st_dev) { struct pipe_context *pipe = st_ctx->pipe; struct pipe_screen *screen = st_dev->screen; - struct pipe_texture templat; - struct pipe_transfer *transfer; + struct pipe_resource templat; struct pipe_sampler_view view_templ; struct pipe_sampler_view *view; unsigned i; @@ -245,24 +244,21 @@ st_context_create(struct st_device *st_dev) templat.depth0 = 1; templat.last_level = 0; - st_ctx->default_texture = screen->texture_create( screen, &templat ); + st_ctx->default_texture = screen->resource_create( screen, &templat ); if(st_ctx->default_texture) { - transfer = pipe->get_tex_transfer(pipe, - st_ctx->default_texture, - 0, 0, 0, - PIPE_TRANSFER_WRITE, - 0, 0, - st_ctx->default_texture->width0, - st_ctx->default_texture->height0); - if (transfer) { - uint32_t *map; - map = (uint32_t *) pipe->transfer_map(pipe, transfer); - if(map) { - *map = 0x00000000; - pipe->transfer_unmap(pipe, transfer); - } - pipe->tex_transfer_destroy(pipe, transfer); - } + struct pipe_box box; + uint32_t zero = 0; + + u_box_origin_2d( 1, 1, &box ); + + pipe->transfer_inline_write(pipe, + st_ctx->default_texture, + u_subresource(0,0), + PIPE_TRANSFER_WRITE, + &box, + &zero, + sizeof zero, + 0); } u_sampler_view_default_template(&view_templ, diff --git a/src/gallium/state_trackers/python/st_device.h b/src/gallium/state_trackers/python/st_device.h index dcd0dc6e273..2dca7a1974e 100644 --- a/src/gallium/state_trackers/python/st_device.h +++ b/src/gallium/state_trackers/python/st_device.h @@ -40,7 +40,7 @@ struct st_winsys; struct st_surface { - struct pipe_texture *texture; + struct pipe_resource *texture; unsigned face; unsigned level; unsigned zslice; @@ -59,7 +59,7 @@ struct st_context void *fs; void *gs; - struct pipe_texture *default_texture; + struct pipe_resource *default_texture; struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS]; struct pipe_sampler_view *vertex_sampler_views[PIPE_MAX_VERTEX_SAMPLERS]; @@ -85,7 +85,7 @@ struct st_device static INLINE struct pipe_surface * st_pipe_surface(struct st_surface *surface, unsigned usage) { - struct pipe_texture *texture = surface->texture; + struct pipe_resource *texture = surface->texture; struct pipe_screen *screen = texture->screen; return screen->get_tex_surface(screen, texture, surface->face, surface->level, surface->zslice, usage); } diff --git a/src/gallium/state_trackers/python/st_sample.c b/src/gallium/state_trackers/python/st_sample.c index 218a77fb0a1..25bfbf1ab73 100644 --- a/src/gallium/state_trackers/python/st_sample.c +++ b/src/gallium/state_trackers/python/st_sample.c @@ -546,22 +546,22 @@ st_sample_surface(struct pipe_context *pipe, float *rgba, boolean norm) { - struct pipe_texture *texture = surface->texture; + struct pipe_resource *texture = surface->texture; unsigned width = u_minify(texture->width0, surface->level); unsigned height = u_minify(texture->height0, surface->level); uint rgba_stride = width * 4; struct pipe_transfer *transfer; void *raw; - transfer = pipe->get_tex_transfer(pipe, - surface->texture, - surface->face, - surface->level, - surface->zslice, - PIPE_TRANSFER_WRITE, - 0, 0, - width, - height); + transfer = pipe_get_transfer(pipe, + surface->texture, + surface->face, + surface->level, + surface->zslice, + PIPE_TRANSFER_WRITE, + 0, 0, + width, + height); if (!transfer) return; @@ -590,6 +590,6 @@ st_sample_surface(struct pipe_context *pipe, pipe->transfer_unmap(pipe, transfer); } - - pipe->tex_transfer_destroy(pipe, transfer); + + pipe->transfer_destroy(pipe, transfer); } diff --git a/src/gallium/state_trackers/vega/Makefile b/src/gallium/state_trackers/vega/Makefile index 7c315de8271..b871990cd9a 100644 --- a/src/gallium/state_trackers/vega/Makefile +++ b/src/gallium/state_trackers/vega/Makefile @@ -27,7 +27,6 @@ VG_SOURCES = \ vg_context.c \ vg_manager.c \ vg_state.c \ - vg_tracker.c \ vg_translate.c \ polygon.c \ bezier.c \ @@ -43,7 +42,8 @@ VG_SOURCES = \ VG_OBJECTS = $(VG_SOURCES:.c=.o) -VG_LIBS = $(GALLIUM_AUXILIARIES) -lm +VG_LIBS = $(GALLIUM_AUXILIARIES) +VG_LIB_DEPS = $(EXTRA_LIB_PATH) -lm ### Include directories @@ -65,7 +65,7 @@ $(TOP)/$(LIB_DIR)/$(VG_LIB_NAME): $(VG_OBJECTS) $(VG_LIBS) -minor $(VG_MINOR) \ -patch $(VG_TINY) \ -install $(TOP)/$(LIB_DIR) \ - $(VG_OBJECTS) $(VG_LIBS) + $(VG_OBJECTS) $(VG_LIBS) $(VG_LIB_DEPS) ###################################################################### # Generic stuff diff --git a/src/gallium/state_trackers/vega/api_filters.c b/src/gallium/state_trackers/vega/api_filters.c index a643f38624f..b1c08af9382 100644 --- a/src/gallium/state_trackers/vega/api_filters.c +++ b/src/gallium/state_trackers/vega/api_filters.c @@ -57,14 +57,14 @@ struct filter_info { struct pipe_sampler_view *extra_texture_view; }; -static INLINE struct pipe_texture *create_texture_1d(struct vg_context *ctx, +static INLINE struct pipe_resource *create_texture_1d(struct vg_context *ctx, const VGuint *color_data, const VGint color_data_len) { struct pipe_context *pipe = ctx->pipe; struct pipe_screen *screen = pipe->screen; - struct pipe_texture *tex = 0; - struct pipe_texture templ; + struct pipe_resource *tex = 0; + struct pipe_resource templ; memset(&templ, 0, sizeof(templ)); templ.target = PIPE_TEXTURE_1D; @@ -73,20 +73,20 @@ static INLINE struct pipe_texture *create_texture_1d(struct vg_context *ctx, templ.width0 = color_data_len; templ.height0 = 1; templ.depth0 = 1; - templ.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER; + templ.bind = PIPE_BIND_SAMPLER_VIEW; - tex = screen->texture_create(screen, &templ); + tex = screen->resource_create(screen, &templ); { /* upload color_data */ struct pipe_transfer *transfer = - pipe->get_tex_transfer(pipe, tex, + pipe_get_transfer(pipe, tex, 0, 0, 0, PIPE_TRANSFER_READ_WRITE , 0, 0, tex->width0, tex->height0); void *map = pipe->transfer_map(pipe, transfer); memcpy(map, color_data, sizeof(VGint)*color_data_len); pipe->transfer_unmap(pipe, transfer); - pipe->tex_transfer_destroy(pipe, transfer); + pipe->transfer_destroy(pipe, transfer); } return tex; @@ -97,7 +97,7 @@ static INLINE struct pipe_sampler_view *create_texture_1d_view(struct vg_context const VGint color_data_len) { struct pipe_context *pipe = ctx->pipe; - struct pipe_texture *texture; + struct pipe_resource *texture; struct pipe_sampler_view view_templ; struct pipe_sampler_view *view; @@ -109,7 +109,7 @@ static INLINE struct pipe_sampler_view *create_texture_1d_view(struct vg_context u_sampler_view_default_template(&view_templ, texture, texture->format); view = pipe->create_sampler_view(pipe, texture, &view_templ); /* want the texture to go away if the view is freed */ - pipe_texture_reference(&texture, NULL); + pipe_resource_reference(&texture, NULL); return view; } @@ -121,7 +121,7 @@ static INLINE struct pipe_surface * setup_framebuffer(struct vg_image *dst) struct pipe_framebuffer_state fb; struct pipe_surface *dst_surf = pipe->screen->get_tex_surface( pipe->screen, dst->sampler_view->texture, 0, 0, 0, - PIPE_BUFFER_USAGE_GPU_WRITE); + PIPE_BIND_RENDER_TARGET); /* drawing dest */ memset(&fb, 0, sizeof(fb)); @@ -170,14 +170,14 @@ static void setup_constant_buffer(struct vg_context *ctx, const void *buffer, VGint param_bytes) { struct pipe_context *pipe = ctx->pipe; - struct pipe_buffer **cbuf = &ctx->filter.buffer; + struct pipe_resource **cbuf = &ctx->filter.buffer; /* We always need to get a new buffer, to keep the drivers simple and * avoid gratuitous rendering synchronization. */ - pipe_buffer_reference(cbuf, NULL); + pipe_resource_reference(cbuf, NULL); - *cbuf = pipe_buffer_create(pipe->screen, 16, - PIPE_BUFFER_USAGE_CONSTANT, + *cbuf = pipe_buffer_create(pipe->screen, + PIPE_BIND_CONSTANT_BUFFER, param_bytes); if (*cbuf) { diff --git a/src/gallium/state_trackers/vega/api_images.c b/src/gallium/state_trackers/vega/api_images.c index fec473d9d23..6c7fd3b346c 100644 --- a/src/gallium/state_trackers/vega/api_images.c +++ b/src/gallium/state_trackers/vega/api_images.c @@ -441,9 +441,9 @@ void vgReadPixels(void * data, VGint dataStride, { struct pipe_transfer *transfer; - transfer = pipe->get_tex_transfer(pipe, strb->texture, 0, 0, 0, - PIPE_TRANSFER_READ, - 0, 0, width, height); + transfer = pipe_get_transfer(pipe, strb->texture, 0, 0, 0, + PIPE_TRANSFER_READ, + 0, 0, width, height); /* Do a row at a time to flip image data vertically */ for (i = 0; i < height; i++) { @@ -457,7 +457,7 @@ void vgReadPixels(void * data, VGint dataStride, dst += dataStride; } - pipe->tex_transfer_destroy(pipe, transfer); + pipe->transfer_destroy(pipe, transfer); } } diff --git a/src/gallium/state_trackers/vega/api_masks.c b/src/gallium/state_trackers/vega/api_masks.c index 2f2d925252d..7c28ea5c872 100644 --- a/src/gallium/state_trackers/vega/api_masks.c +++ b/src/gallium/state_trackers/vega/api_masks.c @@ -51,7 +51,7 @@ draw_clear_quad(struct vg_context *st, const VGfloat color[4]) { struct pipe_context *pipe = st->pipe; - struct pipe_buffer *buf; + struct pipe_resource *buf; VGuint i; /* positions */ @@ -81,7 +81,8 @@ draw_clear_quad(struct vg_context *st, /* put vertex data into vbuf */ buf = pipe_user_buffer_create(pipe->screen, st->clear.vertices, - sizeof(st->clear.vertices)); + sizeof(st->clear.vertices), + PIPE_BIND_VERTEX_BUFFER); /* draw */ @@ -93,7 +94,7 @@ draw_clear_quad(struct vg_context *st, 4, /* verts */ 2); /* attribs/vert */ - pipe_buffer_reference(&buf, NULL); + pipe_resource_reference(&buf, NULL); } } diff --git a/src/gallium/state_trackers/vega/image.c b/src/gallium/state_trackers/vega/image.c index c3268a84a60..9c323b1809c 100644 --- a/src/gallium/state_trackers/vega/image.c +++ b/src/gallium/state_trackers/vega/image.c @@ -81,7 +81,7 @@ static INLINE void vg_sync_size(VGfloat *src_loc, VGfloat *dst_loc) static void vg_copy_texture(struct vg_context *ctx, - struct pipe_texture *dst, VGint dx, VGint dy, + struct pipe_resource *dst, VGint dx, VGint dy, struct pipe_sampler_view *src, VGint sx, VGint sy, VGint width, VGint height) { @@ -217,9 +217,9 @@ void vg_copy_surface(struct vg_context *ctx, } -static struct pipe_texture *image_texture(struct vg_image *img) +static struct pipe_resource *image_texture(struct vg_image *img) { - struct pipe_texture *tex = img->sampler_view->texture; + struct pipe_resource *tex = img->sampler_view->texture; return tex; } @@ -251,7 +251,7 @@ struct vg_image * image_create(VGImageFormat format, struct pipe_context *pipe = ctx->pipe; struct vg_image *image = CALLOC_STRUCT(vg_image); enum pipe_format pformat = vg_format_to_pipe(format); - struct pipe_texture pt, *newtex; + struct pipe_resource pt, *newtex; struct pipe_sampler_view view_templ; struct pipe_sampler_view *view; struct pipe_screen *screen = ctx->pipe->screen; @@ -270,7 +270,7 @@ struct vg_image * image_create(VGImageFormat format, image->sampler.normalized_coords = 1; assert(screen->is_format_supported(screen, pformat, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_SAMPLER, 0)); + PIPE_BIND_SAMPLER_VIEW, 0)); memset(&pt, 0, sizeof(pt)); pt.target = PIPE_TEXTURE_2D; @@ -279,16 +279,16 @@ struct vg_image * image_create(VGImageFormat format, pt.width0 = width; pt.height0 = height; pt.depth0 = 1; - pt.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER; + pt.bind = PIPE_BIND_SAMPLER_VIEW; - newtex = screen->texture_create(screen, &pt); + newtex = screen->resource_create(screen, &pt); debug_assert(newtex); u_sampler_view_default_template(&view_templ, newtex, newtex->format); view = pipe->create_sampler_view(pipe, newtex, &view_templ); /* want the texture to go away if the view is freed */ - pipe_texture_reference(&newtex, NULL); + pipe_resource_reference(&newtex, NULL); image->sampler_view = view; @@ -388,7 +388,7 @@ void image_sub_data(struct vg_image *image, VGint i; struct vg_context *ctx = vg_current_context(); struct pipe_context *pipe = ctx->pipe; - struct pipe_texture *texture = image_texture(image); + struct pipe_resource *texture = image_texture(image); VGint xoffset = 0, yoffset = 0; if (x < 0) { @@ -421,7 +421,7 @@ void image_sub_data(struct vg_image *image, } { /* upload color_data */ - struct pipe_transfer *transfer = pipe->get_tex_transfer( + struct pipe_transfer *transfer = pipe_get_transfer( pipe, texture, 0, 0, 0, PIPE_TRANSFER_WRITE, 0, 0, texture->width0, texture->height0); src += (dataStride * yoffset); @@ -431,7 +431,7 @@ void image_sub_data(struct vg_image *image, y += yStep; src += dataStride; } - pipe->tex_transfer_destroy(pipe, transfer); + pipe->transfer_destroy(pipe, transfer); } } @@ -452,7 +452,7 @@ void image_get_sub_data(struct vg_image * image, { struct pipe_transfer *transfer = - pipe->get_tex_transfer(pipe, + pipe_get_transfer(pipe, image->sampler_view->texture, 0, 0, 0, PIPE_TRANSFER_READ, 0, 0, @@ -469,7 +469,7 @@ void image_get_sub_data(struct vg_image * image, dst += dataStride; } - pipe->tex_transfer_destroy(pipe, transfer); + pipe->transfer_destroy(pipe, transfer); } } @@ -576,7 +576,7 @@ void image_set_pixels(VGint dx, VGint dy, pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL); surf = screen->get_tex_surface(screen, image_texture(src), 0, 0, 0, - PIPE_BUFFER_USAGE_GPU_READ); + PIPE_BIND_BLIT_SOURCE); vg_copy_surface(ctx, strb->surface, dx, dy, surf, sx+src->x, sy+src->y, width, height); @@ -601,8 +601,8 @@ void image_get_pixels(struct vg_image *dst, VGint dx, VGint dy, pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL); surf = screen->get_tex_surface(screen, image_texture(dst), 0, 0, 0, - PIPE_BUFFER_USAGE_GPU_WRITE | - PIPE_BUFFER_USAGE_GPU_READ); + PIPE_BIND_BLIT_SOURCE); + vg_copy_surface(ctx, surf, dst->x + dx, dst->y + dy, strb->surface, sx, sy, width, height); diff --git a/src/gallium/state_trackers/vega/image.h b/src/gallium/state_trackers/vega/image.h index 805b35fab9f..a990c9c5873 100644 --- a/src/gallium/state_trackers/vega/image.h +++ b/src/gallium/state_trackers/vega/image.h @@ -30,7 +30,7 @@ #include "vg_context.h" #include "pipe/p_state.h" -struct pipe_texture; +struct pipe_resource; struct array; struct vg_context; struct pipe_surface; diff --git a/src/gallium/state_trackers/vega/mask.c b/src/gallium/state_trackers/vega/mask.c index 316ea7a9c95..6d627b0e8da 100644 --- a/src/gallium/state_trackers/vega/mask.c +++ b/src/gallium/state_trackers/vega/mask.c @@ -143,7 +143,7 @@ static void read_alpha_mask(void * data, VGint dataStride, struct pipe_surface *surf; surf = screen->get_tex_surface(screen, strb->texture, 0, 0, 0, - PIPE_BUFFER_USAGE_CPU_READ); + PIPE_BIND_TRANSFER_READ); /* Do a row at a time to flip image data vertically */ for (i = 0; i < height; i++) { @@ -217,7 +217,7 @@ static void setup_mask_framebuffer(struct pipe_surface *surf, static void setup_mask_operation(VGMaskOperation operation) { struct vg_context *ctx = vg_current_context(); - struct pipe_buffer **cbuf = &ctx->mask.cbuf; + struct pipe_resource **cbuf = &ctx->mask.cbuf; const VGint param_bytes = 4 * sizeof(VGfloat); const VGfloat ones[4] = {1.f, 1.f, 1.f, 1.f}; void *shader = 0; @@ -225,10 +225,10 @@ static void setup_mask_operation(VGMaskOperation operation) /* We always need to get a new buffer, to keep the drivers simple and * avoid gratuitous rendering synchronization. */ - pipe_buffer_reference(cbuf, NULL); + pipe_resource_reference(cbuf, NULL); - *cbuf = pipe_buffer_create(ctx->pipe->screen, 1, - PIPE_BUFFER_USAGE_CONSTANT, + *cbuf = pipe_buffer_create(ctx->pipe->screen, + PIPE_BIND_CONSTANT_BUFFER, param_bytes); if (*cbuf) { st_no_flush_pipe_buffer_write(ctx, *cbuf, @@ -318,16 +318,16 @@ static void setup_mask_samplers(struct pipe_sampler_view *umask) static void setup_mask_fill(const VGfloat color[4]) { struct vg_context *ctx = vg_current_context(); - struct pipe_buffer **cbuf = &ctx->mask.cbuf; + struct pipe_resource **cbuf = &ctx->mask.cbuf; const VGint param_bytes = 4 * sizeof(VGfloat); /* We always need to get a new buffer, to keep the drivers simple and * avoid gratuitous rendering synchronization. */ - pipe_buffer_reference(cbuf, NULL); + pipe_resource_reference(cbuf, NULL); - *cbuf = pipe_buffer_create(ctx->pipe->screen, 1, - PIPE_BUFFER_USAGE_CONSTANT, + *cbuf = pipe_buffer_create(ctx->pipe->screen, + PIPE_BIND_CONSTANT_BUFFER, param_bytes); if (*cbuf) { st_no_flush_pipe_buffer_write(ctx, *cbuf, 0, param_bytes, color); @@ -415,9 +415,9 @@ static void mask_using_texture(struct pipe_sampler_view *sampler_view, VGint width, VGint height) { struct vg_context *ctx = vg_current_context(); - struct pipe_texture *texture = sampler_view->texture; + struct pipe_resource *texture = sampler_view->texture; struct pipe_surface *surface = - alpha_mask_surface(ctx, PIPE_BUFFER_USAGE_GPU_WRITE); + alpha_mask_surface(ctx, PIPE_BIND_RENDER_TARGET); VGint offsets[4], loc[4]; if (!surface) @@ -482,12 +482,12 @@ struct vg_mask_layer * mask_layer_create(VGint width, VGint height) mask->height = height; { - struct pipe_texture pt; + struct pipe_resource pt; struct pipe_context *pipe = ctx->pipe; struct pipe_screen *screen = ctx->pipe->screen; struct pipe_sampler_view view_templ; struct pipe_sampler_view *view = NULL; - struct pipe_texture *texture; + struct pipe_resource *texture; memset(&pt, 0, sizeof(pt)); pt.target = PIPE_TEXTURE_2D; @@ -496,16 +496,16 @@ struct vg_mask_layer * mask_layer_create(VGint width, VGint height) pt.width0 = width; pt.height0 = height; pt.depth0 = 1; - pt.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER; + pt.bind = PIPE_BIND_SAMPLER_VIEW; pt.compressed = 0; - texture = screen->texture_create(screen, &pt); + texture = screen->resource_create(screen, &pt); if (texture) { u_sampler_view_default_template(&view_templ, texture, texture->format); view = pipe->create_sampler_view(pipe, texture, &view_templ); } - pipe_texture_reference(&texture, NULL); + pipe_resource_reference(&texture, NULL); mask->sampler_view = view; } @@ -519,7 +519,7 @@ void mask_layer_destroy(struct vg_mask_layer *layer) struct vg_context *ctx = vg_current_context(); vg_context_remove_object(ctx, VG_OBJECT_MASK, layer); - pipe_texture_release(&layer->texture); + pipe_resource_release(&layer->texture); free(layer); } @@ -537,7 +537,7 @@ void mask_layer_fill(struct vg_mask_layer *layer, surface = ctx->pipe->screen->get_tex_surface( ctx->pipe->screen, layer->sampler_view->texture, 0, 0, 0, - PIPE_BUFFER_USAGE_GPU_WRITE); + PIPE_BIND_RENDER_TARGET); surface_fill(surface, layer->width, layer->height, @@ -573,7 +573,7 @@ static void mask_layer_render_to(struct vg_mask_layer *layer, struct pipe_surface *surface; surface = screen->get_tex_surface(screen, layer->sampler_view->texture, 0, 0, 0, - PIPE_BUFFER_USAGE_GPU_WRITE); + PIPE_BIND_RENDER_TARGET); cso_save_framebuffer(ctx->cso_context); cso_save_fragment_shader(ctx->cso_context); @@ -664,7 +664,7 @@ void mask_fill(VGint x, VGint y, VGint width, VGint height, struct vg_context *ctx = vg_current_context(); VGfloat alpha_color[4] = {.0f, .0f, .0f, value}; struct pipe_surface *surf = alpha_mask_surface( - ctx, PIPE_BUFFER_USAGE_GPU_WRITE); + ctx, PIPE_BIND_RENDER_TARGET); #if DEBUG_MASKS debug_printf("mask_fill(%d, %d, %d, %d) with rgba(%f, %f, %f, %f)\n", diff --git a/src/gallium/state_trackers/vega/mask.h b/src/gallium/state_trackers/vega/mask.h index 4feacbefda8..c626402c864 100644 --- a/src/gallium/state_trackers/vega/mask.h +++ b/src/gallium/state_trackers/vega/mask.h @@ -31,7 +31,7 @@ struct path; struct vg_image; -struct pipe_texture; +struct pipe_resource; struct vg_mask_layer *mask_layer_create(VGint width, VGint height); void mask_layer_destroy(struct vg_mask_layer *layer); diff --git a/src/gallium/state_trackers/vega/paint.c b/src/gallium/state_trackers/vega/paint.c index 508e1863a57..05540e82752 100644 --- a/src/gallium/state_trackers/vega/paint.c +++ b/src/gallium/state_trackers/vega/paint.c @@ -79,7 +79,7 @@ struct vg_paint { } pattern; /* XXX next 3 all unneded? */ - struct pipe_buffer *cbuf; + struct pipe_resource *cbuf; struct pipe_shader_state fs_state; void *fs; }; @@ -143,12 +143,12 @@ static INLINE void create_gradient_data(const VGfloat *ramp_stops, data[size-1] = last_color; } -static INLINE struct pipe_texture *create_gradient_texture(struct vg_paint *p) +static INLINE struct pipe_resource *create_gradient_texture(struct vg_paint *p) { struct pipe_context *pipe = p->base.ctx->pipe; struct pipe_screen *screen = pipe->screen; - struct pipe_texture *tex = 0; - struct pipe_texture templ; + struct pipe_resource *tex = 0; + struct pipe_resource templ; memset(&templ, 0, sizeof(templ)); templ.target = PIPE_TEXTURE_1D; @@ -157,18 +157,18 @@ static INLINE struct pipe_texture *create_gradient_texture(struct vg_paint *p) templ.width0 = 1024; templ.height0 = 1; templ.depth0 = 1; - templ.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER; + templ.bind = PIPE_BIND_SAMPLER_VIEW; - tex = screen->texture_create(screen, &templ); + tex = screen->resource_create(screen, &templ); { /* upload color_data */ struct pipe_transfer *transfer = - st_no_flush_get_tex_transfer(p->base.ctx, tex, 0, 0, 0, + st_no_flush_get_transfer(p->base.ctx, tex, 0, 0, 0, PIPE_TRANSFER_WRITE, 0, 0, 1024, 1); void *map = pipe->transfer_map(pipe, transfer); memcpy(map, p->gradient.color_data, sizeof(VGint)*1024); pipe->transfer_unmap(pipe, transfer); - pipe->tex_transfer_destroy(pipe, transfer); + pipe->transfer_destroy(pipe, transfer); } return tex; @@ -177,7 +177,7 @@ static INLINE struct pipe_texture *create_gradient_texture(struct vg_paint *p) static INLINE struct pipe_sampler_view *create_gradient_sampler_view(struct vg_paint *p) { struct pipe_context *pipe = p->base.ctx->pipe; - struct pipe_texture *texture; + struct pipe_resource *texture; struct pipe_sampler_view view_templ; struct pipe_sampler_view *view; @@ -189,7 +189,7 @@ static INLINE struct pipe_sampler_view *create_gradient_sampler_view(struct vg_p u_sampler_view_default_template(&view_templ, texture, texture->format); view = pipe->create_sampler_view(pipe, texture, &view_templ); /* want the texture to go away if the view is freed */ - pipe_texture_reference(&texture, NULL); + pipe_resource_reference(&texture, NULL); return view; } diff --git a/src/gallium/state_trackers/vega/paint.h b/src/gallium/state_trackers/vega/paint.h index 9ea67c4b1e6..012cd3e5618 100644 --- a/src/gallium/state_trackers/vega/paint.h +++ b/src/gallium/state_trackers/vega/paint.h @@ -35,7 +35,7 @@ struct vg_paint; struct vg_image; struct pipe_sampler_state; -struct pipe_texture; +struct pipe_resource; struct vg_paint *paint_create(struct vg_context *ctx); void paint_destroy(struct vg_paint *paint); diff --git a/src/gallium/state_trackers/vega/polygon.c b/src/gallium/state_trackers/vega/polygon.c index eef2c1eb876..d2b7e489124 100644 --- a/src/gallium/state_trackers/vega/polygon.c +++ b/src/gallium/state_trackers/vega/polygon.c @@ -58,7 +58,7 @@ struct polygon VGint num_verts; VGboolean dirty; - struct pipe_buffer *vbuf; + struct pipe_resource *vbuf; struct pipe_screen *screen; }; @@ -110,7 +110,7 @@ struct polygon * polygon_create_from_data(float *data, int size) void polygon_destroy(struct polygon *poly) { if (poly->vbuf) - pipe_buffer_reference(&poly->vbuf, NULL); + pipe_resource_reference(&poly->vbuf, NULL); free(poly->data); free(poly); @@ -272,13 +272,14 @@ static void draw_polygon(struct vg_context *ctx, if (poly->vbuf == NULL || poly->dirty) { if (poly->vbuf) { - pipe_buffer_reference(&poly->vbuf, + pipe_resource_reference(&poly->vbuf, NULL); } poly->screen = pipe->screen; poly->vbuf= pipe_user_buffer_create(poly->screen, poly->data, - vert_size); + vert_size, + PIPE_BIND_VERTEX_BUFFER); poly->dirty = VG_FALSE; } diff --git a/src/gallium/state_trackers/vega/renderer.c b/src/gallium/state_trackers/vega/renderer.c index 2bb4c8bc756..48fbc3b330e 100644 --- a/src/gallium/state_trackers/vega/renderer.c +++ b/src/gallium/state_trackers/vega/renderer.c @@ -61,7 +61,7 @@ static void setup_shaders(struct renderer *ctx) ctx->fs = util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_2D); } -static struct pipe_buffer * +static struct pipe_resource * setup_vertex_data(struct renderer *ctx, float x0, float y0, float x1, float y1, float z) { @@ -91,10 +91,11 @@ setup_vertex_data(struct renderer *ctx, return pipe_user_buffer_create( ctx->pipe->screen, ctx->vertices, - sizeof(ctx->vertices) ); + sizeof(ctx->vertices), + PIPE_BIND_VERTEX_BUFFER); } -static struct pipe_buffer * +static struct pipe_resource * setup_vertex_data_tex(struct renderer *ctx, float x0, float y0, float x1, float y1, float s0, float t0, float s1, float t1, @@ -126,11 +127,12 @@ setup_vertex_data_tex(struct renderer *ctx, return pipe_user_buffer_create( ctx->pipe->screen, ctx->vertices, - sizeof(ctx->vertices) ); + sizeof(ctx->vertices), + PIPE_BIND_VERTEX_BUFFER); } -static struct pipe_buffer * +static struct pipe_resource * setup_vertex_data_qtex(struct renderer *ctx, float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3, @@ -163,7 +165,8 @@ setup_vertex_data_qtex(struct renderer *ctx, return pipe_user_buffer_create( ctx->pipe->screen, ctx->vertices, - sizeof(ctx->vertices) ); + sizeof(ctx->vertices), + PIPE_BIND_VERTEX_BUFFER); } struct renderer * renderer_create(struct vg_context *owner) @@ -206,7 +209,7 @@ void renderer_draw_quad(struct renderer *r, VGfloat x2, VGfloat y2, VGfloat depth) { - struct pipe_buffer *buf; + struct pipe_resource *buf; buf = setup_vertex_data(r, x1, y1, x2, y2, depth); @@ -217,20 +220,20 @@ void renderer_draw_quad(struct renderer *r, 4, /* verts */ 2); /* attribs/vert */ - pipe_buffer_reference( &buf, + pipe_resource_reference( &buf, NULL ); } } void renderer_draw_texture(struct renderer *r, - struct pipe_texture *tex, + struct pipe_resource *tex, VGfloat x1offset, VGfloat y1offset, VGfloat x2offset, VGfloat y2offset, VGfloat x1, VGfloat y1, VGfloat x2, VGfloat y2) { struct pipe_context *pipe = r->pipe; - struct pipe_buffer *buf; + struct pipe_resource *buf; VGfloat s0, t0, s1, t1; assert(tex->width0 != 0); @@ -256,7 +259,7 @@ void renderer_draw_texture(struct renderer *r, 4, /* verts */ 2); /* attribs/vert */ - pipe_buffer_reference( &buf, + pipe_resource_reference( &buf, NULL ); } @@ -267,17 +270,17 @@ void renderer_copy_texture(struct renderer *ctx, struct pipe_sampler_view *src, VGfloat sx1, VGfloat sy1, VGfloat sx2, VGfloat sy2, - struct pipe_texture *dst, + struct pipe_resource *dst, VGfloat dx1, VGfloat dy1, VGfloat dx2, VGfloat dy2) { struct pipe_context *pipe = ctx->pipe; struct pipe_screen *screen = pipe->screen; - struct pipe_texture *tex = src->texture; - struct pipe_buffer *buf; + struct pipe_resource *tex = src->texture; + struct pipe_resource *buf; struct pipe_surface *dst_surf = screen->get_tex_surface( screen, dst, 0, 0, 0, - PIPE_BUFFER_USAGE_GPU_WRITE); + PIPE_BIND_RENDER_TARGET); struct pipe_framebuffer_state fb; float s0, t0, s1, t1; @@ -304,7 +307,7 @@ void renderer_copy_texture(struct renderer *ctx, #endif assert(screen->is_format_supported(screen, dst_surf->format, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)); + PIPE_BIND_RENDER_TARGET, 0)); /* save state (restored below) */ cso_save_blend(ctx->cso); @@ -380,7 +383,7 @@ void renderer_copy_texture(struct renderer *ctx, 4, /* verts */ 2); /* attribs/vert */ - pipe_buffer_reference( &buf, + pipe_resource_reference( &buf, NULL ); } @@ -407,10 +410,10 @@ void renderer_copy_surface(struct renderer *ctx, { struct pipe_context *pipe = ctx->pipe; struct pipe_screen *screen = pipe->screen; - struct pipe_buffer *buf; + struct pipe_resource *buf; struct pipe_sampler_view view_templ; struct pipe_sampler_view *view; - struct pipe_texture texTemp, *tex; + struct pipe_resource texTemp, *tex; struct pipe_surface *texSurf; struct pipe_framebuffer_state fb; struct st_framebuffer *stfb = ctx->owner->draw_buffer; @@ -437,11 +440,11 @@ void renderer_copy_surface(struct renderer *ctx, } assert(screen->is_format_supported(screen, src->format, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_SAMPLER, 0)); + PIPE_BIND_SAMPLER_VIEW, 0)); assert(screen->is_format_supported(screen, dst->format, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_SAMPLER, 0)); + PIPE_BIND_SAMPLER_VIEW, 0)); assert(screen->is_format_supported(screen, dst->format, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)); + PIPE_BIND_RENDER_TARGET, 0)); /* * XXX for now we're always creating a temporary texture. @@ -457,7 +460,7 @@ void renderer_copy_surface(struct renderer *ctx, texTemp.height0 = srcH; texTemp.depth0 = 1; - tex = screen->texture_create(screen, &texTemp); + tex = screen->resource_create(screen, &texTemp); if (!tex) return; @@ -468,7 +471,7 @@ void renderer_copy_surface(struct renderer *ctx, return; texSurf = screen->get_tex_surface(screen, tex, 0, 0, 0, - PIPE_BUFFER_USAGE_GPU_WRITE); + PIPE_BIND_RENDER_TARGET); /* load temp texture */ if (pipe->surface_copy) { @@ -554,7 +557,7 @@ void renderer_copy_surface(struct renderer *ctx, 4, /* verts */ 2); /* attribs/vert */ - pipe_buffer_reference( &buf, + pipe_resource_reference( &buf, NULL ); } @@ -568,12 +571,12 @@ void renderer_copy_surface(struct renderer *ctx, cso_restore_vertex_shader(ctx->cso); cso_restore_viewport(ctx->cso); - pipe_texture_reference(&tex, NULL); + pipe_resource_reference(&tex, NULL); pipe_sampler_view_reference(&view, NULL); } void renderer_texture_quad(struct renderer *r, - struct pipe_texture *tex, + struct pipe_resource *tex, VGfloat x1offset, VGfloat y1offset, VGfloat x2offset, VGfloat y2offset, VGfloat x1, VGfloat y1, @@ -582,7 +585,7 @@ void renderer_texture_quad(struct renderer *r, VGfloat x4, VGfloat y4) { struct pipe_context *pipe = r->pipe; - struct pipe_buffer *buf; + struct pipe_resource *buf; VGfloat s0, t0, s1, t1; assert(tex->width0 != 0); @@ -608,7 +611,7 @@ void renderer_texture_quad(struct renderer *r, 4, /* verts */ 2); /* attribs/vert */ - pipe_buffer_reference(&buf, + pipe_resource_reference(&buf, NULL); } diff --git a/src/gallium/state_trackers/vega/renderer.h b/src/gallium/state_trackers/vega/renderer.h index 03366f13614..b1a9fb58be6 100644 --- a/src/gallium/state_trackers/vega/renderer.h +++ b/src/gallium/state_trackers/vega/renderer.h @@ -32,7 +32,7 @@ struct renderer; struct vg_context; -struct pipe_texture; +struct pipe_resource; struct pipe_sampler_view; struct pipe_surface; @@ -44,13 +44,13 @@ void renderer_draw_quad(struct renderer *, VGfloat x2, VGfloat y2, VGfloat depth); void renderer_draw_texture(struct renderer *, - struct pipe_texture *texture, + struct pipe_resource *texture, VGfloat x1offset, VGfloat y1offset, VGfloat x2offset, VGfloat y2offset, VGfloat x1, VGfloat y1, VGfloat x2, VGfloat y2); void renderer_texture_quad(struct renderer *, - struct pipe_texture *texture, + struct pipe_resource *texture, VGfloat x1offset, VGfloat y1offset, VGfloat x2offset, VGfloat y2offset, VGfloat x1, VGfloat y1, @@ -61,7 +61,7 @@ void renderer_copy_texture(struct renderer *r, struct pipe_sampler_view *src, VGfloat sx1, VGfloat sy1, VGfloat sx2, VGfloat sy2, - struct pipe_texture *dst, + struct pipe_resource *dst, VGfloat dx1, VGfloat dy1, VGfloat dx2, VGfloat dy2); void renderer_copy_surface(struct renderer *r, diff --git a/src/gallium/state_trackers/vega/shader.c b/src/gallium/state_trackers/vega/shader.c index f2ec24c57ff..6eef94ce767 100644 --- a/src/gallium/state_trackers/vega/shader.c +++ b/src/gallium/state_trackers/vega/shader.c @@ -51,7 +51,7 @@ struct shader { VGImageMode image_mode; float constants[MAX_CONSTANTS]; - struct pipe_buffer *cbuf; + struct pipe_resource *cbuf; struct pipe_shader_state fs_state; void *fs; }; @@ -96,7 +96,7 @@ static void setup_constant_buffer(struct shader *shader) { struct vg_context *ctx = shader->context; struct pipe_context *pipe = shader->context->pipe; - struct pipe_buffer **cbuf = &shader->cbuf; + struct pipe_resource **cbuf = &shader->cbuf; VGint param_bytes = paint_constant_buffer_size(shader->paint); float temp_buf[MAX_CONSTANTS]; @@ -106,12 +106,13 @@ static void setup_constant_buffer(struct shader *shader) if (*cbuf == NULL || memcmp(temp_buf, shader->constants, param_bytes) != 0) { - pipe_buffer_reference(cbuf, NULL); + pipe_resource_reference(cbuf, NULL); memcpy(shader->constants, temp_buf, param_bytes); *cbuf = pipe_user_buffer_create(pipe->screen, &shader->constants, - sizeof(shader->constants)); + sizeof(shader->constants), + PIPE_BIND_VERTEX_BUFFER); } ctx->pipe->set_constant_buffer(ctx->pipe, PIPE_SHADER_FRAGMENT, 0, *cbuf); diff --git a/src/gallium/state_trackers/vega/st_inlines.h b/src/gallium/state_trackers/vega/st_inlines.h index 4d12a4efdd6..7eaa67c76ae 100644 --- a/src/gallium/state_trackers/vega/st_inlines.h +++ b/src/gallium/state_trackers/vega/st_inlines.h @@ -42,8 +42,8 @@ #include "pipe/p_state.h" static INLINE struct pipe_transfer * -st_cond_flush_get_tex_transfer(struct vg_context *st, - struct pipe_texture *pt, +st_cond_flush_get_transfer(struct vg_context *st, + struct pipe_resource *pt, unsigned int face, unsigned int level, unsigned int zslice, @@ -52,20 +52,14 @@ st_cond_flush_get_tex_transfer(struct vg_context *st, unsigned int w, unsigned int h) { struct pipe_context *pipe = st->pipe; - unsigned referenced = - pipe->is_texture_referenced(pipe, pt, face, level); - if (referenced && ((referenced & PIPE_REFERENCED_FOR_WRITE) || - (usage & PIPE_TRANSFER_WRITE))) - vgFlush(); - - return pipe->get_tex_transfer(pipe, pt, face, level, zslice, usage, - x, y, w, h); + return pipe_get_transfer(pipe, pt, face, level, zslice, usage, + x, y, w, h); } static INLINE struct pipe_transfer * -st_no_flush_get_tex_transfer(struct vg_context *st, - struct pipe_texture *pt, +st_no_flush_get_transfer(struct vg_context *st, + struct pipe_resource *pt, unsigned int face, unsigned int level, unsigned int zslice, @@ -75,82 +69,53 @@ st_no_flush_get_tex_transfer(struct vg_context *st, { struct pipe_context *pipe = st->pipe; - return pipe->get_tex_transfer(pipe, pt, face, level, - zslice, usage, x, y, w, h); -} - -static INLINE void * -st_cond_flush_pipe_buffer_map(struct vg_context *st, - struct pipe_buffer *buf, - unsigned int map_flags) -{ - struct pipe_context *pipe = st->pipe; - unsigned int referenced = pipe->is_buffer_referenced(pipe, buf); - - if (referenced && ((referenced & PIPE_REFERENCED_FOR_WRITE) || - (map_flags & PIPE_BUFFER_USAGE_CPU_WRITE))) - vgFlush(); - - return pipe_buffer_map(pipe->screen, buf, map_flags); -} - -static INLINE void * -st_no_flush_pipe_buffer_map(struct vg_context *st, - struct pipe_buffer *buf, - unsigned int map_flags) -{ - return pipe_buffer_map(st->pipe->screen, buf, map_flags); + return pipe_get_transfer(pipe, pt, face, level, + zslice, usage, x, y, w, h); } static INLINE void st_cond_flush_pipe_buffer_write(struct vg_context *st, - struct pipe_buffer *buf, + struct pipe_resource *buf, unsigned int offset, unsigned int size, const void * data) { struct pipe_context *pipe = st->pipe; - if (pipe->is_buffer_referenced(pipe, buf)) - vgFlush(); - - pipe_buffer_write(pipe->screen, buf, offset, size, data); + pipe_buffer_write(pipe, buf, offset, size, data); } static INLINE void st_no_flush_pipe_buffer_write(struct vg_context *st, - struct pipe_buffer *buf, + struct pipe_resource *buf, unsigned int offset, unsigned int size, const void * data) { - pipe_buffer_write(st->pipe->screen, buf, offset, size, data); + pipe_buffer_write(st->pipe, buf, offset, size, data); } static INLINE void st_cond_flush_pipe_buffer_read(struct vg_context *st, - struct pipe_buffer *buf, + struct pipe_resource *buf, unsigned int offset, unsigned int size, void * data) { struct pipe_context *pipe = st->pipe; - if (pipe->is_buffer_referenced(pipe, buf) & PIPE_REFERENCED_FOR_WRITE) - vgFlush(); - - pipe_buffer_read(pipe->screen, buf, offset, size, data); + pipe_buffer_read(pipe, buf, offset, size, data); } static INLINE void st_no_flush_pipe_buffer_read(struct vg_context *st, - struct pipe_buffer *buf, + struct pipe_resource *buf, unsigned int offset, unsigned int size, void * data) { - pipe_buffer_read(st->pipe->screen, buf, offset, size, data); + pipe_buffer_read(st->pipe, buf, offset, size, data); } #endif diff --git a/src/gallium/state_trackers/vega/vg_context.c b/src/gallium/state_trackers/vega/vg_context.c index 11ebbbe5444..1a8952ce34a 100644 --- a/src/gallium/state_trackers/vega/vg_context.c +++ b/src/gallium/state_trackers/vega/vg_context.c @@ -132,8 +132,8 @@ struct vg_context * vg_create_context(struct pipe_context *pipe, void vg_destroy_context(struct vg_context *ctx) { - struct pipe_buffer **cbuf = &ctx->mask.cbuf; - struct pipe_buffer **vsbuf = &ctx->vs_const_buffer; + struct pipe_resource **cbuf = &ctx->mask.cbuf; + struct pipe_resource **vsbuf = &ctx->vs_const_buffer; util_destroy_blit(ctx->blit); renderer_destroy(ctx->renderer); @@ -142,10 +142,10 @@ void vg_destroy_context(struct vg_context *ctx) paint_destroy(ctx->default_paint); if (*cbuf) - pipe_buffer_reference(cbuf, NULL); + pipe_resource_reference(cbuf, NULL); if (*vsbuf) - pipe_buffer_reference(vsbuf, NULL); + pipe_resource_reference(vsbuf, NULL); if (ctx->clear.fs) { cso_delete_fragment_shader(ctx->cso_context, ctx->clear.fs); @@ -381,14 +381,14 @@ void vg_validate_state(struct vg_context *ctx) 2.f/fb->width, 2.f/fb->height, 1, 1, -1, -1, 0, 0 }; - struct pipe_buffer **cbuf = &ctx->vs_const_buffer; + struct pipe_resource **cbuf = &ctx->vs_const_buffer; vg_set_viewport(ctx, VEGA_Y0_BOTTOM); - pipe_buffer_reference(cbuf, NULL); - *cbuf = pipe_buffer_create(ctx->pipe->screen, 16, - PIPE_BUFFER_USAGE_CONSTANT, - param_bytes); + pipe_resource_reference(cbuf, NULL); + *cbuf = pipe_buffer_create(ctx->pipe->screen, + PIPE_BIND_CONSTANT_BUFFER, + param_bytes); if (*cbuf) { st_no_flush_pipe_buffer_write(ctx, *cbuf, @@ -451,7 +451,8 @@ void vg_prepare_blend_surface(struct vg_context *ctx) dest_surface = pipe->screen->get_tex_surface(pipe->screen, stfb->blend_texture_view->texture, 0, 0, 0, - PIPE_BUFFER_USAGE_GPU_WRITE); + PIPE_BIND_BLIT_DESTINATION | + PIPE_BIND_RENDER_TARGET); /* flip it, because we want to use it as a sampler */ util_blit_pixels_tex(ctx->blit, view, @@ -487,7 +488,8 @@ void vg_prepare_blend_surface_from_mask(struct vg_context *ctx) dest_surface = pipe->screen->get_tex_surface(pipe->screen, stfb->blend_texture_view->texture, 0, 0, 0, - PIPE_BUFFER_USAGE_GPU_WRITE); + PIPE_BIND_BLIT_DESTINATION | + PIPE_BIND_RENDER_TARGET); /* flip it, because we want to use it as a sampler */ util_blit_pixels_tex(ctx->blit, diff --git a/src/gallium/state_trackers/vega/vg_context.h b/src/gallium/state_trackers/vega/vg_context.h index c9e36d7d767..dac67192a54 100644 --- a/src/gallium/state_trackers/vega/vg_context.h +++ b/src/gallium/state_trackers/vega/vg_context.h @@ -46,7 +46,7 @@ struct vg_shader; struct st_renderbuffer { enum pipe_format format; struct pipe_surface *surface; - struct pipe_texture *texture; + struct pipe_resource *texture; VGint width, height; }; @@ -121,7 +121,7 @@ struct vg_context } clear; struct { - struct pipe_buffer *cbuf; + struct pipe_resource *cbuf; struct pipe_sampler_state sampler; struct vg_shader *union_fs; @@ -134,7 +134,7 @@ struct vg_context struct cso_context *cso_context; - struct pipe_buffer *stencil_quad; + struct pipe_resource *stencil_quad; VGfloat stencil_vertices[4][2][4]; struct renderer *renderer; @@ -143,7 +143,7 @@ struct vg_context struct pipe_sampler_state blend_sampler; struct { - struct pipe_buffer *buffer; + struct pipe_resource *buffer; void *color_matrix_fs; } filter; struct vg_paint *default_paint; @@ -153,7 +153,7 @@ struct vg_context struct vg_shader *plain_vs; struct vg_shader *clear_vs; struct vg_shader *texture_vs; - struct pipe_buffer *vs_const_buffer; + struct pipe_resource *vs_const_buffer; struct pipe_vertex_element velems[2]; }; diff --git a/src/gallium/state_trackers/vega/vg_manager.c b/src/gallium/state_trackers/vega/vg_manager.c index 25c2e853f2a..e4226754d13 100644 --- a/src/gallium/state_trackers/vega/vg_manager.c +++ b/src/gallium/state_trackers/vega/vg_manager.c @@ -2,6 +2,7 @@ * Mesa 3-D graphics library * Version: 7.9 * + * Copyright 2009 VMware, Inc. All Rights Reserved. * Copyright (C) 2010 LunarG Inc. * * Permission is hereby granted, free of charge, to any person obtaining a @@ -14,12 +15,13 @@ * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. * * Authors: * Chia-I Wu <olv@lunarg.com> @@ -31,11 +33,243 @@ #include "pipe/p_screen.h" #include "util/u_memory.h" #include "util/u_inlines.h" +#include "util/u_format.h" +#include "util/u_sampler.h" #include "vg_manager.h" #include "vg_context.h" -#include "vg_tracker.h" /* for st_resize_framebuffer */ #include "image.h" +#include "mask.h" + +static struct pipe_resource * +create_texture(struct pipe_context *pipe, enum pipe_format format, + VGint width, VGint height) +{ + struct pipe_resource templ; + + memset(&templ, 0, sizeof(templ)); + + if (format != PIPE_FORMAT_NONE) { + templ.format = format; + } + else { + templ.format = PIPE_FORMAT_B8G8R8A8_UNORM; + } + + templ.target = PIPE_TEXTURE_2D; + templ.width0 = width; + templ.height0 = height; + templ.depth0 = 1; + templ.last_level = 0; + + if (util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_ZS, 1)) { + templ.bind = PIPE_BIND_DEPTH_STENCIL; + } else { + templ.bind = (PIPE_BIND_DISPLAY_TARGET | + PIPE_BIND_RENDER_TARGET | + PIPE_BIND_SAMPLER_VIEW); + } + + return pipe->screen->resource_create(pipe->screen, &templ); +} + +static struct pipe_sampler_view * +create_tex_and_view(struct pipe_context *pipe, enum pipe_format format, + VGint width, VGint height) +{ + struct pipe_resource *texture; + struct pipe_sampler_view view_templ; + struct pipe_sampler_view *view; + + texture = create_texture(pipe, format, width, height); + + if (!texture) + return NULL; + + u_sampler_view_default_template(&view_templ, texture, texture->format); + view = pipe->create_sampler_view(pipe, texture, &view_templ); + /* want the texture to go away if the view is freed */ + pipe_resource_reference(&texture, NULL); + + return view; +} + +static void +setup_new_alpha_mask(struct vg_context *ctx, struct st_framebuffer *stfb) +{ + struct pipe_context *pipe = ctx->pipe; + struct pipe_sampler_view *old_sampler_view = stfb->alpha_mask_view; + + /* + we use PIPE_FORMAT_B8G8R8A8_UNORM because we want to render to + this texture and use it as a sampler, so while this wastes some + space it makes both of those a lot simpler + */ + stfb->alpha_mask_view = create_tex_and_view(pipe, + PIPE_FORMAT_B8G8R8A8_UNORM, stfb->width, stfb->height); + + if (!stfb->alpha_mask_view) { + if (old_sampler_view) + pipe_sampler_view_reference(&old_sampler_view, NULL); + return; + } + + /* XXX could this call be avoided? */ + vg_validate_state(ctx); + + /* alpha mask starts with 1.f alpha */ + mask_fill(0, 0, stfb->width, stfb->height, 1.f); + + /* if we had an old surface copy it over */ + if (old_sampler_view) { + struct pipe_surface *surface = pipe->screen->get_tex_surface( + pipe->screen, + stfb->alpha_mask_view->texture, + 0, 0, 0, + PIPE_BIND_RENDER_TARGET | + PIPE_BIND_BLIT_DESTINATION); + struct pipe_surface *old_surface = pipe->screen->get_tex_surface( + pipe->screen, + old_sampler_view->texture, + 0, 0, 0, + PIPE_BIND_BLIT_SOURCE); + pipe->surface_copy(pipe, + surface, + 0, 0, + old_surface, + 0, 0, + MIN2(old_surface->width, surface->width), + MIN2(old_surface->height, surface->height)); + if (surface) + pipe_surface_reference(&surface, NULL); + if (old_surface) + pipe_surface_reference(&old_surface, NULL); + } + + /* Free the old texture + */ + if (old_sampler_view) + pipe_sampler_view_reference(&old_sampler_view, NULL); +} + +static boolean +vg_context_update_depth_stencil_rb(struct vg_context * ctx, + uint width, uint height) +{ + struct st_renderbuffer *dsrb = ctx->draw_buffer->dsrb; + struct pipe_context *pipe = ctx->pipe; + unsigned surface_usage; + + if ((dsrb->width == width && dsrb->height == height) && dsrb->texture) + return FALSE; + + /* unreference existing ones */ + pipe_surface_reference(&dsrb->surface, NULL); + pipe_resource_reference(&dsrb->texture, NULL); + dsrb->width = dsrb->height = 0; + + /* Probably need dedicated flags for surface usage too: + */ + surface_usage = (PIPE_BIND_RENDER_TARGET | + PIPE_BIND_BLIT_SOURCE | + PIPE_BIND_BLIT_DESTINATION); + + dsrb->texture = create_texture(pipe, dsrb->format, width, height); + if (!dsrb->texture) + return TRUE; + + dsrb->surface = pipe->screen->get_tex_surface(pipe->screen, + dsrb->texture, + 0, 0, 0, + surface_usage); + if (!dsrb->surface) { + pipe_resource_reference(&dsrb->texture, NULL); + return TRUE; + } + + dsrb->width = width; + dsrb->height = height; + + assert(dsrb->surface->width == width); + assert(dsrb->surface->height == height); + + return TRUE; +} + +static boolean +vg_context_update_color_rb(struct vg_context *ctx, struct pipe_resource *pt) +{ + struct st_renderbuffer *strb = ctx->draw_buffer->strb; + struct pipe_screen *screen = ctx->pipe->screen; + + if (strb->texture == pt) { + pipe_resource_reference(&pt, NULL); + return FALSE; + } + + /* unreference existing ones */ + pipe_surface_reference(&strb->surface, NULL); + pipe_resource_reference(&strb->texture, NULL); + strb->width = strb->height = 0; + + strb->texture = pt; + strb->surface = screen->get_tex_surface(screen, strb->texture, 0, 0, 0, + PIPE_BIND_RENDER_TARGET | + PIPE_BIND_BLIT_SOURCE | + PIPE_BIND_BLIT_DESTINATION); + if (!strb->surface) { + pipe_resource_reference(&strb->texture, NULL); + return TRUE; + } + + strb->width = pt->width0; + strb->height = pt->height0; + + return TRUE; +} + +static void +vg_context_update_draw_buffer(struct vg_context *ctx, struct pipe_resource *pt) +{ + struct st_framebuffer *stfb = ctx->draw_buffer; + boolean new_cbuf, new_zsbuf, new_size; + + new_cbuf = vg_context_update_color_rb(ctx, pt); + new_zsbuf = + vg_context_update_depth_stencil_rb(ctx, pt->width0, pt->height0); + + new_size = (stfb->width != pt->width0 || stfb->height != pt->height0); + stfb->width = pt->width0; + stfb->height = pt->height0; + + if (new_cbuf || new_zsbuf || new_size) { + struct pipe_framebuffer_state *state = &ctx->state.g3d.fb; + + memset(state, 0, sizeof(struct pipe_framebuffer_state)); + state->width = stfb->width; + state->height = stfb->height; + state->nr_cbufs = 1; + state->cbufs[0] = stfb->strb->surface; + state->zsbuf = stfb->dsrb->surface; + + cso_set_framebuffer(ctx->cso_context, state); + } + + if (new_zsbuf || new_size) { + ctx->state.dirty |= VIEWPORT_DIRTY; + ctx->state.dirty |= DEPTH_STENCIL_DIRTY;/*to reset the scissors*/ + + ctx->pipe->clear(ctx->pipe, PIPE_CLEAR_DEPTHSTENCIL, NULL, 0.0, 0); + + /* we need all the other state already set */ + + setup_new_alpha_mask(ctx, stfb); + + pipe_sampler_view_reference( &stfb->blend_texture_view, NULL); + stfb->blend_texture_view = create_tex_and_view(ctx->pipe, + PIPE_FORMAT_B8G8R8A8_UNORM, stfb->width, stfb->height); + } +} /** * Flush the front buffer if the current context renders to the front buffer. @@ -48,16 +282,6 @@ vg_manager_flush_frontbuffer(struct vg_context *ctx) if (!stfb) return; - /* st_public.h is used */ - if (!stfb->iface) { - struct pipe_screen *screen = ctx->pipe->screen; - if (screen->flush_frontbuffer) { - screen->flush_frontbuffer(screen, - stfb->strb->surface, ctx->pipe->priv); - } - return; - } - switch (stfb->strb_att) { case ST_ATTACHMENT_FRONT_LEFT: case ST_ATTACHMENT_FRONT_RIGHT: @@ -74,23 +298,13 @@ vg_manager_flush_frontbuffer(struct vg_context *ctx) void vg_manager_validate_framebuffer(struct vg_context *ctx) { - struct pipe_screen *screen = ctx->pipe->screen; struct st_framebuffer *stfb = ctx->draw_buffer; - struct st_renderbuffer *rb; - struct pipe_texture *pt; + struct pipe_resource *pt; /* no binding surface */ if (!stfb) return; - /* st_public.h is used */ - if (!stfb->iface) { - struct pipe_screen *screen = ctx->pipe->screen; - if (screen->update_buffer) - screen->update_buffer(screen, ctx->pipe->priv); - return; - } - if (!p_atomic_read(&ctx->draw_buffer_invalid)) return; @@ -98,26 +312,13 @@ vg_manager_validate_framebuffer(struct vg_context *ctx) if (!stfb->iface->validate(stfb->iface, &stfb->strb_att, 1, &pt) || !pt) return; - rb = stfb->strb; - if (rb->texture == pt) { - pipe_texture_reference(&pt, NULL); - return; - } - - /* unreference existing ones */ - pipe_surface_reference(&rb->surface, NULL); - pipe_texture_reference(&rb->texture, NULL); - - rb->texture = pt; - rb->surface = screen->get_tex_surface(screen, rb->texture, 0, 0, 0, - PIPE_BUFFER_USAGE_GPU_READ | PIPE_BUFFER_USAGE_GPU_WRITE); - - rb->width = rb->surface->width; - rb->height = rb->surface->height; - - st_resize_framebuffer(stfb, rb->width, rb->height); - + /* + * unset draw_buffer_invalid first because vg_context_update_draw_buffer + * will cause the framebuffer to be validated again because of a call to + * vg_validate_state + */ p_atomic_set(&ctx->draw_buffer_invalid, FALSE); + vg_context_update_draw_buffer(ctx, pt); } @@ -194,7 +395,7 @@ static void destroy_renderbuffer(struct st_renderbuffer *strb) { pipe_surface_reference(&strb->surface, NULL); - pipe_texture_reference(&strb->texture, NULL); + pipe_resource_reference(&strb->texture, NULL); free(strb); } @@ -329,10 +530,7 @@ vg_api_is_visual_supported(struct st_api *stapi, const struct st_visual *visual) { /* the impl requires a depth/stencil buffer */ - if (visual->depth_stencil_format == PIPE_FORMAT_NONE) - return FALSE; - - return TRUE; + return util_format_is_depth_and_stencil(visual->depth_stencil_format); } static st_proc_t diff --git a/src/gallium/state_trackers/vega/vg_manager.h b/src/gallium/state_trackers/vega/vg_manager.h index 1a276c0f35e..1d97eb864ba 100644 --- a/src/gallium/state_trackers/vega/vg_manager.h +++ b/src/gallium/state_trackers/vega/vg_manager.h @@ -14,12 +14,13 @@ * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. * * Authors: * Chia-I Wu <olv@lunarg.com> diff --git a/src/gallium/state_trackers/vega/vg_tracker.c b/src/gallium/state_trackers/vega/vg_tracker.c deleted file mode 100644 index 108dd6a9751..00000000000 --- a/src/gallium/state_trackers/vega/vg_tracker.c +++ /dev/null @@ -1,461 +0,0 @@ -/************************************************************************** - * - * Copyright 2009 VMware, Inc. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#include "vg_context.h" -#include "vg_tracker.h" -#include "mask.h" - -#include "pipe/p_context.h" -#include "util/u_inlines.h" -#include "pipe/p_screen.h" -#include "util/u_format.h" -#include "util/u_sampler.h" -#include "util/u_memory.h" -#include "util/u_math.h" -#include "util/u_rect.h" - -/* advertise OpenVG support */ -PUBLIC const int st_api_OpenVG = 1; - -static struct pipe_texture * -create_texture(struct pipe_context *pipe, enum pipe_format format, - VGint width, VGint height) -{ - struct pipe_texture templ; - - memset(&templ, 0, sizeof(templ)); - - if (format != PIPE_FORMAT_NONE) { - templ.format = format; - } - else { - templ.format = PIPE_FORMAT_B8G8R8A8_UNORM; - } - - templ.target = PIPE_TEXTURE_2D; - templ.width0 = width; - templ.height0 = height; - templ.depth0 = 1; - templ.last_level = 0; - - if (util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_ZS, 1)) { - templ.tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL; - } else { - templ.tex_usage = (PIPE_TEXTURE_USAGE_DISPLAY_TARGET | - PIPE_TEXTURE_USAGE_RENDER_TARGET | - PIPE_TEXTURE_USAGE_SAMPLER); - } - - return pipe->screen->texture_create(pipe->screen, &templ); -} - -static struct pipe_sampler_view * -create_tex_and_view(struct pipe_context *pipe, enum pipe_format format, - VGint width, VGint height) -{ - struct pipe_texture *texture; - struct pipe_sampler_view view_templ; - struct pipe_sampler_view *view; - - texture = create_texture(pipe, format, width, height); - - if (!texture) - return NULL; - - u_sampler_view_default_template(&view_templ, texture, texture->format); - view = pipe->create_sampler_view(pipe, texture, &view_templ); - /* want the texture to go away if the view is freed */ - pipe_texture_reference(&texture, NULL); - - return view; -} - -/** - * Allocate a renderbuffer for a an on-screen window (not a user-created - * renderbuffer). The window system code determines the format. - */ -static struct st_renderbuffer * -st_new_renderbuffer_fb(enum pipe_format format) -{ - struct st_renderbuffer *strb; - - strb = CALLOC_STRUCT(st_renderbuffer); - if (!strb) { - /*_vega_error(NULL, VG_OUT_OF_MEMORY, "creating renderbuffer");*/ - return NULL; - } - - strb->format = format; - - return strb; -} - - -/** - * This is called to allocate the original drawing surface, and - * during window resize. - */ -static VGboolean -st_renderbuffer_alloc_storage(struct vg_context * ctx, - struct st_renderbuffer *strb, - VGuint width, VGuint height) -{ - struct pipe_context *pipe = ctx->pipe; - unsigned surface_usage; - - /* Free the old surface and texture - */ - pipe_surface_reference(&strb->surface, NULL); - pipe_texture_reference(&strb->texture, NULL); - - - /* Probably need dedicated flags for surface usage too: - */ - surface_usage = (PIPE_BUFFER_USAGE_GPU_READ | - PIPE_BUFFER_USAGE_GPU_WRITE); - - strb->texture = create_texture(pipe, strb->format, width, height); - - - if (!strb->texture) - return FALSE; - - strb->surface = pipe->screen->get_tex_surface(pipe->screen, - strb->texture, - 0, 0, 0, - surface_usage); - strb->width = width; - strb->height = height; - - assert(strb->surface->width == width); - assert(strb->surface->height == height); - - return strb->surface != NULL; -} - -struct vg_context * st_create_context(struct pipe_context *pipe, - const void *visual, - struct vg_context *share) -{ - struct vg_context *ctx = vg_create_context(pipe, visual, share); - /*debug_printf("--------- CREATE CONTEXT %p\n", ctx);*/ - return ctx; -} - -void st_destroy_context(struct vg_context *st) -{ - /*debug_printf("--------- DESTROY CONTEXT %p\n", st);*/ - vg_destroy_context(st); -} - -void st_copy_context_state(struct vg_context *dst, struct vg_context *src, - uint mask) -{ - fprintf(stderr, "FIXME: %s\n", __FUNCTION__); -} - -void st_get_framebuffer_dimensions(struct st_framebuffer *stfb, - uint *width, - uint *height) -{ - *width = stfb->strb->width; - *height = stfb->strb->height; -} - -struct st_framebuffer * st_create_framebuffer(const void *visual, - enum pipe_format colorFormat, - enum pipe_format depthFormat, - enum pipe_format stencilFormat, - uint width, uint height, - void *privateData) -{ - struct st_framebuffer *stfb = CALLOC_STRUCT(st_framebuffer); - if (stfb) { - struct st_renderbuffer *rb = - st_new_renderbuffer_fb(colorFormat); - stfb->strb = rb; -#if 0 - if (doubleBuffer) { - struct st_renderbuffer *rb = - st_new_renderbuffer_fb(colorFormat); - } -#endif - - /* we want to combine the depth/stencil */ - if (stencilFormat == depthFormat) - stfb->dsrb = st_new_renderbuffer_fb(stencilFormat); - else - stfb->dsrb = st_new_renderbuffer_fb(PIPE_FORMAT_Z24_UNORM_S8_USCALED); - - /*### currently we always allocate it but it's possible it's - not necessary if EGL_ALPHA_MASK_SIZE was 0 - */ - stfb->alpha_mask_view = NULL; - - stfb->width = width; - stfb->height = height; - stfb->privateData = privateData; - } - - return stfb; -} - -static void setup_new_alpha_mask(struct vg_context *ctx, - struct st_framebuffer *stfb, - uint width, uint height) -{ - struct pipe_context *pipe = ctx->pipe; - struct pipe_sampler_view *old_sampler_view = stfb->alpha_mask_view; - - /* - we use PIPE_FORMAT_B8G8R8A8_UNORM because we want to render to - this texture and use it as a sampler, so while this wastes some - space it makes both of those a lot simpler - */ - stfb->alpha_mask_view = - create_tex_and_view(pipe, PIPE_FORMAT_B8G8R8A8_UNORM, width, height); - - if (!stfb->alpha_mask_view) { - if (old_sampler_view) - pipe_sampler_view_reference(&old_sampler_view, NULL); - return; - } - - vg_validate_state(ctx); - - /* alpha mask starts with 1.f alpha */ - mask_fill(0, 0, width, height, 1.f); - - /* if we had an old surface copy it over */ - if (old_sampler_view) { - struct pipe_surface *surface = pipe->screen->get_tex_surface( - pipe->screen, - stfb->alpha_mask_view->texture, - 0, 0, 0, - PIPE_BUFFER_USAGE_GPU_WRITE); - struct pipe_surface *old_surface = pipe->screen->get_tex_surface( - pipe->screen, - old_sampler_view->texture, - 0, 0, 0, - PIPE_BUFFER_USAGE_GPU_READ); - if (pipe->surface_copy) { - pipe->surface_copy(pipe, - surface, - 0, 0, - old_surface, - 0, 0, - MIN2(old_surface->width, width), - MIN2(old_surface->height, height)); - } else { - util_surface_copy(pipe, FALSE, - surface, - 0, 0, - old_surface, - 0, 0, - MIN2(old_surface->width, width), - MIN2(old_surface->height, height)); - } - if (surface) - pipe_surface_reference(&surface, NULL); - if (old_surface) - pipe_surface_reference(&old_surface, NULL); - } - - /* Free the old texture - */ - if (old_sampler_view) - pipe_sampler_view_reference(&old_sampler_view, NULL); -} - -void st_resize_framebuffer(struct st_framebuffer *stfb, - uint width, uint height) -{ - struct vg_context *ctx = vg_current_context(); - struct st_renderbuffer *strb = stfb->strb; - struct pipe_framebuffer_state *state; - - if (!ctx) - return; - - state = &ctx->state.g3d.fb; - - /* If this is a noop, exit early and don't do the clear, etc below. - */ - if (stfb->width == width && - stfb->height == height && - state->zsbuf) - return; - - stfb->width = width; - stfb->height = height; - - if (strb->width != width || strb->height != height) - st_renderbuffer_alloc_storage(ctx, strb, - width, height); - - if (stfb->dsrb->width != width || stfb->dsrb->height != height) - st_renderbuffer_alloc_storage(ctx, stfb->dsrb, - width, height); - - { - VGuint i; - - memset(state, 0, sizeof(struct pipe_framebuffer_state)); - - state->width = width; - state->height = height; - - state->nr_cbufs = 1; - state->cbufs[0] = strb->surface; - for (i = 1; i < PIPE_MAX_COLOR_BUFS; ++i) - state->cbufs[i] = 0; - - state->zsbuf = stfb->dsrb->surface; - - cso_set_framebuffer(ctx->cso_context, state); - } - - ctx->state.dirty |= VIEWPORT_DIRTY; - ctx->state.dirty |= DEPTH_STENCIL_DIRTY;/*to reset the scissors*/ - - ctx->pipe->clear(ctx->pipe, PIPE_CLEAR_DEPTHSTENCIL, - NULL, 0.0, 0); - - /* we need all the other state already set */ - - setup_new_alpha_mask(ctx, stfb, width, height); - - pipe_sampler_view_reference( &stfb->blend_texture_view, NULL ); - stfb->blend_texture_view = create_tex_and_view(ctx->pipe, PIPE_FORMAT_B8G8R8A8_UNORM, - width, height); -} - -void st_set_framebuffer_surface(struct st_framebuffer *stfb, - uint surfIndex, struct pipe_surface *surf) -{ - struct st_renderbuffer *rb = stfb->strb; - - /* unreference existing surfaces */ - pipe_surface_reference( &rb->surface, NULL ); - pipe_texture_reference( &rb->texture, NULL ); - - /* reference new ones */ - pipe_surface_reference( &rb->surface, surf ); - pipe_texture_reference( &rb->texture, surf->texture ); - - rb->width = surf->width; - rb->height = surf->height; -} - -int st_get_framebuffer_surface(struct st_framebuffer *stfb, - uint surfIndex, struct pipe_surface **surf) -{ - struct st_renderbuffer *rb = stfb->strb; - *surf = rb->surface; - return VG_TRUE; -} - -int st_get_framebuffer_texture(struct st_framebuffer *stfb, - uint surfIndex, struct pipe_texture **tex) -{ - struct st_renderbuffer *rb = stfb->strb; - *tex = rb->texture; - return VG_TRUE; -} - -void * st_framebuffer_private(struct st_framebuffer *stfb) -{ - return stfb->privateData; -} - -void st_unreference_framebuffer(struct st_framebuffer *stfb) -{ - /* FIXME */ -} - -boolean st_make_current(struct vg_context *st, - struct st_framebuffer *draw, - struct st_framebuffer *read, - void *winsys_drawable_handle) -{ - vg_set_current_context(st); - if (st) - st->draw_buffer = draw; - return VG_TRUE; -} - -struct vg_context *st_get_current(void) -{ - return vg_current_context(); -} - -void st_flush(struct vg_context *st, uint pipeFlushFlags, - struct pipe_fence_handle **fence) -{ - st->pipe->flush(st->pipe, pipeFlushFlags, fence); -} - -void st_finish(struct vg_context *st) -{ - struct pipe_fence_handle *fence = NULL; - - st_flush(st, PIPE_FLUSH_RENDER_CACHE, &fence); - - st->pipe->screen->fence_finish(st->pipe->screen, fence, 0); - st->pipe->screen->fence_reference(st->pipe->screen, &fence, NULL); -} - -void st_notify_swapbuffers(struct st_framebuffer *stfb) -{ - struct vg_context *ctx = vg_current_context(); - if (ctx && ctx->draw_buffer == stfb) { - st_flush(ctx, - PIPE_FLUSH_RENDER_CACHE | - PIPE_FLUSH_SWAPBUFFERS | - PIPE_FLUSH_FRAME, - NULL); - } -} - -void st_notify_swapbuffers_complete(struct st_framebuffer *stfb) -{ -} - -int st_bind_texture_surface(struct pipe_surface *ps, int target, int level, - enum pipe_format format) -{ - return 0; -} - -int st_unbind_texture_surface(struct pipe_surface *ps, int target, int level) -{ - return 0; -} - -st_proc st_get_proc_address(const char *procname) -{ - return NULL; -} diff --git a/src/gallium/state_trackers/vega/vg_tracker.h b/src/gallium/state_trackers/vega/vg_tracker.h deleted file mode 100644 index 165a6b7a332..00000000000 --- a/src/gallium/state_trackers/vega/vg_tracker.h +++ /dev/null @@ -1,128 +0,0 @@ -/************************************************************************** - * - * Copyright 2009 VMware, Inc. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#ifndef VG_TRACKER_H -#define VG_TRACKER_H - -#include "VG/openvg.h" - -#include "pipe/p_compiler.h" -#include "pipe/p_format.h" - -#define ST_SURFACE_FRONT_LEFT 0 -#define ST_SURFACE_BACK_LEFT 1 -#define ST_SURFACE_FRONT_RIGHT 2 -#define ST_SURFACE_BACK_RIGHT 3 -#define ST_SURFACE_DEPTH 8 - -struct vg_context; -struct st_framebuffer; -struct pipe_context; -struct pipe_fence_handle; -struct pipe_surface; - - -PUBLIC -struct vg_context *st_create_context(struct pipe_context *pipe, - const void *visual, - struct vg_context *share); - -PUBLIC -void st_destroy_context( struct vg_context *st ); - -PUBLIC -void st_copy_context_state(struct vg_context *dst, struct vg_context *src, - uint mask); - -PUBLIC -struct st_framebuffer *st_create_framebuffer(const void *visual, - enum pipe_format colorFormat, - enum pipe_format depthFormat, - enum pipe_format stencilFormat, - uint width, uint height, - void *privateData); - -PUBLIC -void st_resize_framebuffer(struct st_framebuffer *stfb, - uint width, uint height); - -PUBLIC -void st_set_framebuffer_surface(struct st_framebuffer *stfb, - uint surfIndex, struct pipe_surface *surf); - -PUBLIC -void st_get_framebuffer_dimensions( struct st_framebuffer *stfb, - uint *width, uint *height); - -PUBLIC -int st_bind_texture_surface(struct pipe_surface *ps, int target, int level, - enum pipe_format format); - -PUBLIC -int st_unbind_texture_surface(struct pipe_surface *ps, int target, int level); - -PUBLIC -int st_get_framebuffer_surface(struct st_framebuffer *stfb, - uint surfIndex, struct pipe_surface **surf); - -PUBLIC -int st_get_framebuffer_texture(struct st_framebuffer *stfb, - uint surfIndex, struct pipe_texture **tex); - -PUBLIC -void *st_framebuffer_private(struct st_framebuffer *stfb); - -PUBLIC -void st_unreference_framebuffer(struct st_framebuffer *stfb); - -PUBLIC -boolean st_make_current(struct vg_context *st, - struct st_framebuffer *draw, - struct st_framebuffer *read, - void *winsys_drawable_handle); - -PUBLIC -struct vg_context *st_get_current(void); - -PUBLIC -void st_flush(struct vg_context *st, uint pipeFlushFlags, - struct pipe_fence_handle **fence); -PUBLIC -void st_finish(struct vg_context *st); - -PUBLIC -void st_notify_swapbuffers(struct st_framebuffer *stfb); -PUBLIC -void st_notify_swapbuffers_complete(struct st_framebuffer *stfb); - - -/** Generic function type */ -typedef void (*st_proc)(); - -PUBLIC -st_proc st_get_proc_address(const char *procname); - -#endif diff --git a/src/gallium/state_trackers/wgl/SConscript b/src/gallium/state_trackers/wgl/SConscript index 352c087475e..f59f3a9638a 100644 --- a/src/gallium/state_trackers/wgl/SConscript +++ b/src/gallium/state_trackers/wgl/SConscript @@ -28,6 +28,7 @@ if env['platform'] in ['windows']: 'stw_framebuffer.c', 'stw_getprocaddress.c', 'stw_pixelformat.c', + 'stw_st.c', 'stw_tls.c', 'stw_wgl.c', ] diff --git a/src/gallium/state_trackers/wgl/stw_context.c b/src/gallium/state_trackers/wgl/stw_context.c index 1f11b649c3e..0fb7cd83069 100644 --- a/src/gallium/state_trackers/wgl/stw_context.c +++ b/src/gallium/state_trackers/wgl/stw_context.c @@ -27,12 +27,13 @@ #include <windows.h> -#include "main/mtypes.h" -#include "main/context.h" #include "pipe/p_compiler.h" #include "pipe/p_context.h" +#include "state_tracker/st_api.h" + +/* for _mesa_share_state */ #include "state_tracker/st_context.h" -#include "state_tracker/st_public.h" +#include "main/context.h" #include "stw_icd.h" #include "stw_device.h" @@ -44,25 +45,13 @@ static INLINE struct stw_context * -stw_context(GLcontext *glctx) -{ - if(!glctx) - return NULL; - assert(glctx->DriverCtx); - return (struct stw_context *)glctx->DriverCtx; -} - -static INLINE struct stw_context * stw_current_context(void) { - /* We must check if multiple threads are being used or GET_CURRENT_CONTEXT - * might return the current context of the thread first seen. */ - _glapi_check_multithread(); + struct st_context_iface *st; - { - GET_CURRENT_CONTEXT( glctx ); - return stw_context(glctx); - } + st = (stw_dev) ? stw_dev->stapi->get_current(stw_dev->stapi) : NULL; + + return (struct stw_context *) ((st) ? st->st_manager_private : NULL); } BOOL APIENTRY @@ -114,7 +103,11 @@ DrvShareLists( ctx2 = stw_lookup_context_locked( dhglrc2 ); if (ctx1 && ctx2) { - ret = _mesa_share_state(ctx2->st->ctx, ctx1->st->ctx); + struct st_context *st1, *st2; + + st1 = (struct st_context *) ctx1->st; + st2 = (struct st_context *) ctx2->st; + ret = _mesa_share_state(st2->ctx, st1->ctx); } pipe_mutex_unlock( stw_dev->ctx_mutex ); @@ -122,20 +115,6 @@ DrvShareLists( return ret; } -static void -stw_viewport(GLcontext * glctx, GLint x, GLint y, - GLsizei width, GLsizei height) -{ - struct stw_context *ctx = (struct stw_context *)glctx->DriverCtx; - struct stw_framebuffer *fb; - - fb = stw_framebuffer_from_hdc( ctx->hdc ); - if(fb) { - stw_framebuffer_update(fb); - stw_framebuffer_release(fb); - } -} - DHGLRC APIENTRY DrvCreateContext( HDC hdc ) @@ -150,9 +129,7 @@ DrvCreateLayerContext( { int iPixelFormat; const struct stw_pixelformat_info *pfi; - GLvisual visual; struct stw_context *ctx = NULL; - struct pipe_context *pipe = NULL; if(!stw_dev) return 0; @@ -165,7 +142,6 @@ DrvCreateLayerContext( return 0; pfi = stw_pixelformat_get_info( iPixelFormat - 1 ); - stw_pixelformat_visual(&visual, pfi); ctx = CALLOC_STRUCT( stw_context ); if (ctx == NULL) @@ -174,18 +150,12 @@ DrvCreateLayerContext( ctx->hdc = hdc; ctx->iPixelFormat = iPixelFormat; - /* priv == hdc, pass to stw_flush_frontbuffer as context_private - */ - pipe = stw_dev->screen->context_create( stw_dev->screen, hdc ); - if (pipe == NULL) - goto no_pipe; - - ctx->st = st_create_context( pipe, &visual, NULL ); + ctx->st = stw_dev->stapi->create_context(stw_dev->stapi, + stw_dev->smapi, &pfi->stvis, NULL); if (ctx->st == NULL) goto no_st_ctx; - ctx->st->ctx->DriverCtx = ctx; - ctx->st->ctx->Driver.Viewport = stw_viewport; + ctx->st->st_manager_private = (void *) ctx; pipe_mutex_lock( stw_dev->ctx_mutex ); ctx->dhglrc = handle_table_add(stw_dev->ctx_table, ctx); @@ -196,11 +166,8 @@ DrvCreateLayerContext( return ctx->dhglrc; no_hglrc: - st_destroy_context(ctx->st); - goto no_pipe; /* st_context_destroy already destroys pipe */ + ctx->st->destroy(ctx->st); no_st_ctx: - pipe->destroy( pipe ); -no_pipe: FREE(ctx); no_ctx: return 0; @@ -226,9 +193,9 @@ DrvDeleteContext( /* Unbind current if deleting current context. */ if (curctx == ctx) - st_make_current( NULL, NULL, NULL, NULL ); + stw_dev->stapi->make_current(stw_dev->stapi, NULL, NULL, NULL); - st_destroy_context(ctx->st); + ctx->st->destroy(ctx->st); FREE(ctx); ret = TRUE; @@ -306,7 +273,7 @@ stw_make_current( curctx = stw_current_context(); if (curctx != NULL) { if (curctx->dhglrc != dhglrc) - st_flush(curctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); + curctx->st->flush(curctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); /* Return if already current. */ if (curctx->dhglrc == dhglrc && curctx->hdc == hdc) { @@ -314,10 +281,12 @@ stw_make_current( fb = stw_framebuffer_from_hdc( hdc ); goto success; } + + stw_framebuffer_reference(&curctx->current_framebuffer, NULL); } if (hdc == NULL || dhglrc == 0) { - return st_make_current( NULL, NULL, NULL, NULL ); + return stw_dev->stapi->make_current(stw_dev->stapi, NULL, NULL, NULL); } pipe_mutex_lock( stw_dev->ctx_mutex ); @@ -327,7 +296,10 @@ stw_make_current( goto fail; fb = stw_framebuffer_from_hdc( hdc ); - if(!fb) { + if (fb) { + stw_framebuffer_update(fb); + } + else { /* Applications should call SetPixelFormat before creating a context, * but not all do, and the opengl32 runtime seems to use a default pixel * format in some cases, so we must create a framebuffer for those here @@ -342,23 +314,17 @@ stw_make_current( if(fb->iPixelFormat != ctx->iPixelFormat) goto fail; - /* Lazy allocation of the frame buffer */ - if(!stw_framebuffer_allocate(fb)) - goto fail; - /* Bind the new framebuffer */ ctx->hdc = hdc; - /* pass to stw_flush_frontbuffer as context_private */ - ctx->st->pipe->priv = hdc; - - if(!st_make_current( ctx->st, fb->stfb, fb->stfb, hdc )) + if (!stw_dev->stapi->make_current(stw_dev->stapi, ctx->st, fb->stfb, fb->stfb)) goto fail; + stw_framebuffer_reference(&ctx->current_framebuffer, fb); + success: assert(fb); if(fb) { - stw_framebuffer_update(fb); stw_framebuffer_release(fb); } @@ -367,11 +333,40 @@ success: fail: if(fb) stw_framebuffer_release(fb); - st_make_current( NULL, NULL, NULL, NULL ); + stw_dev->stapi->make_current(stw_dev->stapi, NULL, NULL, NULL); return FALSE; } /** + * Flush the current context if it is bound to the framebuffer. + */ +void +stw_flush_current_locked( struct stw_framebuffer *fb ) +{ + struct stw_context *ctx = stw_current_context(); + + if (ctx && ctx->current_framebuffer == fb) { + ctx->st->flush(ctx->st, + PIPE_FLUSH_RENDER_CACHE | + PIPE_FLUSH_SWAPBUFFERS | + PIPE_FLUSH_FRAME, + NULL); + } +} + +/** + * Notify the current context that the framebuffer has become invalid. + */ +void +stw_notify_current_locked( struct stw_framebuffer *fb ) +{ + struct stw_context *ctx = stw_current_context(); + + if (ctx && ctx->current_framebuffer == fb) + ctx->st->notify_invalid_framebuffer(ctx->st, fb->stfb); +} + +/** * Although WGL allows different dispatch entrypoints per context */ static const GLCLTPROCTABLE cpt = diff --git a/src/gallium/state_trackers/wgl/stw_context.h b/src/gallium/state_trackers/wgl/stw_context.h index 256c27e21ef..0bbed84104a 100644 --- a/src/gallium/state_trackers/wgl/stw_context.h +++ b/src/gallium/state_trackers/wgl/stw_context.h @@ -30,14 +30,17 @@ #include <windows.h> -struct st_context; +struct stw_framebuffer; +struct st_context_iface; struct stw_context { - struct st_context *st; + struct st_context_iface *st; DHGLRC dhglrc; int iPixelFormat; HDC hdc; + + struct stw_framebuffer *current_framebuffer; }; DHGLRC stw_get_current_context( void ); @@ -46,4 +49,7 @@ HDC stw_get_current_dc( void ); BOOL stw_make_current( HDC hdc, DHGLRC dhglrc ); +void stw_flush_current_locked( struct stw_framebuffer *fb ); +void stw_notify_current_locked( struct stw_framebuffer *fb ); + #endif /* STW_CONTEXT_H */ diff --git a/src/gallium/state_trackers/wgl/stw_device.c b/src/gallium/state_trackers/wgl/stw_device.c index ea300f27cb5..61b207525ca 100644 --- a/src/gallium/state_trackers/wgl/stw_device.c +++ b/src/gallium/state_trackers/wgl/stw_device.c @@ -30,8 +30,8 @@ #include "glapi/glthread.h" #include "util/u_debug.h" #include "util/u_math.h" +#include "util/u_memory.h" #include "pipe/p_screen.h" -#include "state_tracker/st_public.h" #include "stw_device.h" #include "stw_winsys.h" @@ -39,6 +39,7 @@ #include "stw_icd.h" #include "stw_tls.h" #include "stw_framebuffer.h" +#include "stw_st.h" #ifdef WIN32_THREADS extern _glthread_Mutex OneTimeLock; @@ -48,28 +49,6 @@ extern _glthread_Mutex OneTimeLock; struct stw_device *stw_dev = NULL; -/** - * XXX: Dispatch pipe_screen::flush_front_buffer to our - * stw_winsys::flush_front_buffer. - */ -static void -stw_flush_frontbuffer(struct pipe_screen *screen, - struct pipe_surface *surface, - void *context_private ) -{ - HDC hdc = (HDC)context_private; - struct stw_framebuffer *fb; - - fb = stw_framebuffer_from_hdc( hdc ); - if (!fb) { - /* fb can be NULL if window was destroyed already */ - return; - } - - stw_framebuffer_present_locked(hdc, fb, surface); -} - - boolean stw_init(const struct stw_winsys *stw_winsys) { @@ -95,6 +74,11 @@ stw_init(const struct stw_winsys *stw_winsys) _glthread_INIT_MUTEX(OneTimeLock); #endif + stw_dev->stapi = stw_st_create_api(); + stw_dev->smapi = CALLOC_STRUCT(st_manager); + if (!stw_dev->stapi || !stw_dev->smapi) + goto error1; + screen = stw_winsys->create_screen(); if(!screen) goto error1; @@ -102,12 +86,9 @@ stw_init(const struct stw_winsys *stw_winsys) if(stw_winsys->get_adapter_luid) stw_winsys->get_adapter_luid(screen, &stw_dev->AdapterLuid); + stw_dev->smapi->screen = screen; stw_dev->screen = screen; - /* XXX - */ - stw_dev->screen->flush_frontbuffer = &stw_flush_frontbuffer; - pipe_mutex_init( stw_dev->ctx_mutex ); pipe_mutex_init( stw_dev->fb_mutex ); @@ -121,6 +102,11 @@ stw_init(const struct stw_winsys *stw_winsys) return TRUE; error1: + if (stw_dev->smapi) + FREE(stw_dev->smapi); + if (stw_dev->stapi) + stw_dev->stapi->destroy(stw_dev->stapi); + stw_dev = NULL; return FALSE; } @@ -170,6 +156,9 @@ stw_cleanup(void) pipe_mutex_destroy( stw_dev->fb_mutex ); pipe_mutex_destroy( stw_dev->ctx_mutex ); + FREE(stw_dev->smapi); + stw_dev->stapi->destroy(stw_dev->stapi); + stw_dev->screen->destroy(stw_dev->screen); #ifdef WIN32_THREADS diff --git a/src/gallium/state_trackers/wgl/stw_device.h b/src/gallium/state_trackers/wgl/stw_device.h index 2e9ba197dfa..1b836960d0d 100644 --- a/src/gallium/state_trackers/wgl/stw_device.h +++ b/src/gallium/state_trackers/wgl/stw_device.h @@ -40,6 +40,8 @@ struct pipe_screen; +struct st_api; +struct st_manager; struct stw_framebuffer; struct stw_device @@ -48,6 +50,9 @@ struct stw_device struct pipe_screen *screen; + struct st_api *stapi; + struct st_manager *smapi; + LUID AdapterLuid; struct stw_pixelformat_info pixelformats[STW_MAX_PIXELFORMATS]; diff --git a/src/gallium/state_trackers/wgl/stw_ext_pixelformat.c b/src/gallium/state_trackers/wgl/stw_ext_pixelformat.c index 8a9995aba8e..ab56800e28d 100644 --- a/src/gallium/state_trackers/wgl/stw_ext_pixelformat.c +++ b/src/gallium/state_trackers/wgl/stw_ext_pixelformat.c @@ -227,11 +227,11 @@ stw_query_attrib( break; case WGL_SAMPLE_BUFFERS_ARB: - *pvalue = pfi->numSampleBuffers; + *pvalue = 1; break; case WGL_SAMPLES_ARB: - *pvalue = pfi->numSamples; + *pvalue = pfi->stvis.samples; break; default: diff --git a/src/gallium/state_trackers/wgl/stw_framebuffer.c b/src/gallium/state_trackers/wgl/stw_framebuffer.c index 4f1629de2f2..259b22f22c7 100644 --- a/src/gallium/state_trackers/wgl/stw_framebuffer.c +++ b/src/gallium/state_trackers/wgl/stw_framebuffer.c @@ -27,18 +27,19 @@ #include <windows.h> -#include "main/context.h" #include "pipe/p_format.h" #include "pipe/p_screen.h" #include "util/u_format.h" -#include "state_tracker/st_context.h" -#include "state_tracker/st_public.h" +#include "util/u_memory.h" +#include "state_tracker/st_api.h" #include "stw_icd.h" #include "stw_framebuffer.h" #include "stw_device.h" #include "stw_winsys.h" #include "stw_tls.h" +#include "stw_context.h" +#include "stw_st.h" /** @@ -63,8 +64,8 @@ stw_framebuffer_from_hwnd_locked( /** * Destroy this framebuffer. Both stw_dev::fb_mutex and stw_framebuffer::mutex - * must be held, by this order. Obviously no further access to fb can be done - * after this. + * must be held, by this order. If there are still references to the + * framebuffer, nothing will happen. */ static INLINE void stw_framebuffer_destroy_locked( @@ -72,6 +73,13 @@ stw_framebuffer_destroy_locked( { struct stw_framebuffer **link; + /* check the reference count */ + fb->refcnt--; + if (fb->refcnt) { + pipe_mutex_unlock( fb->mutex ); + return; + } + link = &stw_dev->fb_head; while (*link != fb) link = &(*link)->next; @@ -82,7 +90,7 @@ stw_framebuffer_destroy_locked( if(fb->shared_surface) stw_dev->stw_winsys->shared_surface_close(stw_dev->screen, fb->shared_surface); - st_unreference_framebuffer(fb->stfb); + stw_st_destroy_framebuffer_locked(fb->stfb); pipe_mutex_unlock( fb->mutex ); @@ -230,9 +238,14 @@ stw_framebuffer_create( fb->iPixelFormat = iPixelFormat; fb->pfi = pfi = stw_pixelformat_get_info( iPixelFormat - 1 ); + fb->stfb = stw_st_create_framebuffer( fb ); + if (!fb->stfb) { + FREE( fb ); + return NULL; + } + + fb->refcnt = 1; - stw_pixelformat_visual(&fb->visual, pfi); - stw_framebuffer_get_size(fb); pipe_mutex_init( fb->mutex ); @@ -251,47 +264,31 @@ stw_framebuffer_create( return fb; } - -BOOL -stw_framebuffer_allocate( +/** + * Have ptr reference fb. The referenced framebuffer should be locked. + */ +void +stw_framebuffer_reference( + struct stw_framebuffer **ptr, struct stw_framebuffer *fb) { - assert(fb); - - if(!fb->stfb) { - const struct stw_pixelformat_info *pfi = fb->pfi; - enum pipe_format colorFormat, depthFormat, stencilFormat; + struct stw_framebuffer *old_fb = *ptr; - colorFormat = pfi->color_format; + if (old_fb == fb) + return; - if(util_format_get_component_bits(pfi->depth_stencil_format, UTIL_FORMAT_COLORSPACE_ZS, 0)) - depthFormat = pfi->depth_stencil_format; - else - depthFormat = PIPE_FORMAT_NONE; - - if(util_format_get_component_bits(pfi->depth_stencil_format, UTIL_FORMAT_COLORSPACE_ZS, 1)) - stencilFormat = pfi->depth_stencil_format; - else - stencilFormat = PIPE_FORMAT_NONE; - - assert(fb->must_resize); - assert(fb->width); - assert(fb->height); - - fb->stfb = st_create_framebuffer( - &fb->visual, - colorFormat, - depthFormat, - stencilFormat, - fb->width, - fb->height, - (void *) fb ); - - // to notify the context - fb->must_resize = TRUE; + if (fb) + fb->refcnt++; + if (old_fb) { + pipe_mutex_lock(stw_dev->fb_mutex); + + pipe_mutex_lock(old_fb->mutex); + stw_framebuffer_destroy_locked(old_fb); + + pipe_mutex_unlock(stw_dev->fb_mutex); } - - return fb->stfb ? TRUE : FALSE; + + *ptr = fb; } @@ -313,11 +310,6 @@ stw_framebuffer_update( * to know of their existing without using the not very portable PSAPI. */ stw_framebuffer_get_size(fb); - - if(fb->must_resize) { - st_resize_framebuffer(fb->stfb, fb->width, fb->height); - fb->must_resize = FALSE; - } } @@ -516,6 +508,7 @@ DrvPresentBuffers(HDC hdc, PGLPRESENTBUFFERSDATA data) } stw_framebuffer_update(fb); + stw_notify_current_locked(fb); stw_framebuffer_release(fb); @@ -544,6 +537,7 @@ stw_framebuffer_present_locked(HDC hdc, data.rect = fb->client_rect; data.pPrivateData = (void *)surface; + stw_notify_current_locked(fb); stw_framebuffer_release(fb); return stw_dev->callbacks.wglCbPresentBuffers(hdc, &data); @@ -554,7 +548,7 @@ stw_framebuffer_present_locked(HDC hdc, stw_dev->stw_winsys->present( screen, surface, hdc ); stw_framebuffer_update(fb); - + stw_notify_current_locked(fb); stw_framebuffer_release(fb); return TRUE; @@ -567,7 +561,6 @@ DrvSwapBuffers( HDC hdc ) { struct stw_framebuffer *fb; - struct pipe_surface *surface = NULL; if (!stw_dev) return FALSE; @@ -581,9 +574,9 @@ DrvSwapBuffers( return TRUE; } - st_swapbuffers(fb->stfb, &surface, NULL); + stw_flush_current_locked(fb); - return stw_framebuffer_present_locked(hdc, fb, surface); + return stw_st_swap_framebuffer_locked(fb->stfb); } diff --git a/src/gallium/state_trackers/wgl/stw_framebuffer.h b/src/gallium/state_trackers/wgl/stw_framebuffer.h index e61e9bf9c26..89d12300e67 100644 --- a/src/gallium/state_trackers/wgl/stw_framebuffer.h +++ b/src/gallium/state_trackers/wgl/stw_framebuffer.h @@ -30,11 +30,10 @@ #include <windows.h> -#include "main/mtypes.h" - #include "os/os_thread.h" struct pipe_surface; +struct st_framebuffer_iface; struct stw_pixelformat_info; /** @@ -64,13 +63,15 @@ struct stw_framebuffer int iPixelFormat; const struct stw_pixelformat_info *pfi; - GLvisual visual; + + struct st_framebuffer_iface *stfb; /* * Mutable members. */ - struct st_framebuffer *stfb; + unsigned refcnt; + /* FIXME: Make this work for multiple contexts bound to the same framebuffer */ boolean must_resize; @@ -114,6 +115,11 @@ stw_framebuffer_create( HDC hdc, int iPixelFormat ); +void +stw_framebuffer_reference( + struct stw_framebuffer **ptr, + struct stw_framebuffer *fb); + /** * Search a framebuffer with a matching HWND. * @@ -135,10 +141,6 @@ stw_framebuffer_from_hdc( HDC hdc ); BOOL -stw_framebuffer_allocate( - struct stw_framebuffer *fb ); - -BOOL stw_framebuffer_present_locked(HDC hdc, struct stw_framebuffer *fb, struct pipe_surface *surface); diff --git a/src/gallium/state_trackers/wgl/stw_pixelformat.c b/src/gallium/state_trackers/wgl/stw_pixelformat.c index 02ff89a388b..11e779d25f8 100644 --- a/src/gallium/state_trackers/wgl/stw_pixelformat.c +++ b/src/gallium/state_trackers/wgl/stw_pixelformat.c @@ -142,9 +142,6 @@ stw_pixelformat_add( memset(pfi, 0, sizeof *pfi); - pfi->color_format = color->format; - pfi->depth_stencil_format = depth->format; - pfi->pfd.nSize = sizeof pfi->pfd; pfi->pfd.nVersion = 1; @@ -184,11 +181,22 @@ stw_pixelformat_add( pfi->pfd.dwVisibleMask = 0; pfi->pfd.dwDamageMask = 0; - if(samples) { - pfi->numSampleBuffers = 1; - pfi->numSamples = samples; - extended = TRUE; - } + /* + * since state trackers can allocate depth/stencil/accum buffers, we provide + * only color buffers here + */ + pfi->stvis.buffer_mask = ST_ATTACHMENT_FRONT_LEFT_MASK; + if (doublebuffer) + pfi->stvis.buffer_mask = ST_ATTACHMENT_BACK_LEFT_MASK; + + pfi->stvis.color_format = color->format; + pfi->stvis.depth_stencil_format = depth->format; + + pfi->stvis.accum_format = (accum) ? + PIPE_FORMAT_R16G16B16A16_SNORM : PIPE_FORMAT_NONE; + + pfi->stvis.samples = samples; + pfi->stvis.render_buffer = ST_ATTACHMENT_INVALID; ++stw_dev->pixelformat_extended_count; @@ -218,8 +226,8 @@ stw_pixelformat_init( void ) const struct stw_pf_color_info *color = &stw_pf_color[j]; if(!screen->is_format_supported(screen, color->format, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_RENDER_TARGET | - PIPE_TEXTURE_USAGE_DISPLAY_TARGET, 0)) + PIPE_BIND_RENDER_TARGET | + PIPE_BIND_DISPLAY_TARGET, 0)) continue; for(k = 0; k < Elements(stw_pf_doublebuffer); ++k) { @@ -229,7 +237,7 @@ stw_pixelformat_init( void ) const struct stw_pf_depth_info *depth = &stw_pf_depth_stencil[l]; if(!screen->is_format_supported(screen, depth->format, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0)) + PIPE_BIND_DEPTH_STENCIL, 0)) continue; stw_pixelformat_add( stw_dev, color, depth, 0, doublebuffer, samples ); @@ -264,29 +272,6 @@ stw_pixelformat_get_info( uint index ) } -void -stw_pixelformat_visual(GLvisual *visual, - const struct stw_pixelformat_info *pfi ) -{ - memset(visual, 0, sizeof *visual); - _mesa_initialize_visual( - visual, - (pfi->pfd.dwFlags & PFD_DOUBLEBUFFER) ? GL_TRUE : GL_FALSE, - (pfi->pfd.dwFlags & PFD_STEREO) ? GL_TRUE : GL_FALSE, - pfi->pfd.cRedBits, - pfi->pfd.cGreenBits, - pfi->pfd.cBlueBits, - pfi->pfd.cAlphaBits, - pfi->pfd.cDepthBits, - pfi->pfd.cStencilBits, - pfi->pfd.cAccumRedBits, - pfi->pfd.cAccumGreenBits, - pfi->pfd.cAccumBlueBits, - pfi->pfd.cAccumAlphaBits, - pfi->numSamples ); -} - - LONG APIENTRY DrvDescribePixelFormat( HDC hdc, diff --git a/src/gallium/state_trackers/wgl/stw_pixelformat.h b/src/gallium/state_trackers/wgl/stw_pixelformat.h index 3a690b35bad..d405172773c 100644 --- a/src/gallium/state_trackers/wgl/stw_pixelformat.h +++ b/src/gallium/state_trackers/wgl/stw_pixelformat.h @@ -38,16 +38,13 @@ #include "pipe/p_compiler.h" #include "pipe/p_format.h" +#include "state_tracker/st_api.h" struct stw_pixelformat_info { - enum pipe_format color_format; - enum pipe_format depth_stencil_format; - PIXELFORMATDESCRIPTOR pfd; - unsigned numSampleBuffers; - unsigned numSamples; + struct st_visual stvis; }; void @@ -62,10 +59,6 @@ stw_pixelformat_get_extended_count( void ); const struct stw_pixelformat_info * stw_pixelformat_get_info( uint index ); -void -stw_pixelformat_visual(GLvisual *visual, - const struct stw_pixelformat_info *pfi ); - int stw_pixelformat_choose( HDC hdc, CONST PIXELFORMATDESCRIPTOR *ppfd ); diff --git a/src/gallium/state_trackers/wgl/stw_st.c b/src/gallium/state_trackers/wgl/stw_st.c new file mode 100644 index 00000000000..f4ea61ed2c6 --- /dev/null +++ b/src/gallium/state_trackers/wgl/stw_st.c @@ -0,0 +1,312 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu <olv@lunarg.com> + */ + +#include "util/u_memory.h" +#include "util/u_inlines.h" +#include "state_tracker/st_manager.h" /* for st_manager_create_api */ + +#include "stw_st.h" +#include "stw_device.h" +#include "stw_framebuffer.h" +#include "stw_pixelformat.h" + +struct stw_st_framebuffer { + struct st_framebuffer_iface base; + + struct stw_framebuffer *fb; + struct st_visual stvis; + + struct pipe_resource *textures[ST_ATTACHMENT_COUNT]; + unsigned texture_width, texture_height; + unsigned texture_mask; + + struct pipe_surface *front_surface, *back_surface; +}; + +static INLINE struct stw_st_framebuffer * +stw_st_framebuffer(struct st_framebuffer_iface *stfb) +{ + return (struct stw_st_framebuffer *) stfb; +} + +/** + * Remove outdated textures and create the requested ones. + */ +static void +stw_st_framebuffer_validate_locked(struct st_framebuffer_iface *stfb, + unsigned width, unsigned height, + unsigned mask) +{ + struct stw_st_framebuffer *stwfb = stw_st_framebuffer(stfb); + struct pipe_resource templ; + unsigned i; + + /* remove outdated surface */ + pipe_surface_reference(&stwfb->front_surface, NULL); + pipe_surface_reference(&stwfb->back_surface, NULL); + + /* remove outdated textures */ + if (stwfb->texture_width != width || stwfb->texture_height != height) { + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) + pipe_resource_reference(&stwfb->textures[i], NULL); + } + + memset(&templ, 0, sizeof(templ)); + templ.target = PIPE_TEXTURE_2D; + templ.width0 = width; + templ.height0 = height; + templ.depth0 = 1; + templ.last_level = 0; + + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) { + enum pipe_format format; + unsigned bind; + + /* the texture already exists or not requested */ + if (stwfb->textures[i] || !(mask & (1 << i))) { + /* remember the texture */ + if (stwfb->textures[i]) + mask |= (1 << i); + continue; + } + + switch (i) { + case ST_ATTACHMENT_FRONT_LEFT: + case ST_ATTACHMENT_BACK_LEFT: + format = stwfb->stvis.color_format; + bind = PIPE_BIND_DISPLAY_TARGET | + PIPE_BIND_RENDER_TARGET; + break; + case ST_ATTACHMENT_DEPTH_STENCIL: + format = stwfb->stvis.depth_stencil_format; + bind = PIPE_BIND_DEPTH_STENCIL; + break; + default: + format = PIPE_FORMAT_NONE; + break; + } + + if (format != PIPE_FORMAT_NONE) { + templ.format = format; + templ.bind = bind; + + stwfb->textures[i] = + stw_dev->screen->resource_create(stw_dev->screen, &templ); + } + } + + stwfb->texture_width = width; + stwfb->texture_height = height; + stwfb->texture_mask = mask; +} + +static boolean +stw_st_framebuffer_validate(struct st_framebuffer_iface *stfb, + const enum st_attachment_type *statts, + unsigned count, + struct pipe_resource **out) +{ + struct stw_st_framebuffer *stwfb = stw_st_framebuffer(stfb); + unsigned statt_mask, i; + + statt_mask = 0x0; + for (i = 0; i < count; i++) + statt_mask |= 1 << statts[i]; + + pipe_mutex_lock(stwfb->fb->mutex); + + if (stwfb->fb->must_resize || (statt_mask & ~stwfb->texture_mask)) { + stw_st_framebuffer_validate_locked(&stwfb->base, + stwfb->fb->width, stwfb->fb->height, statt_mask); + stwfb->fb->must_resize = FALSE; + } + + for (i = 0; i < count; i++) { + out[i] = NULL; + pipe_resource_reference(&out[i], stwfb->textures[statts[i]]); + } + + stw_framebuffer_release(stwfb->fb); + + return TRUE; +} + +static struct pipe_surface * +get_present_surface_locked(struct st_framebuffer_iface *stfb, + enum st_attachment_type statt) +{ + struct stw_st_framebuffer *stwfb = stw_st_framebuffer(stfb); + struct pipe_resource *ptex; + struct pipe_surface *psurf, **cache; + + ptex = stwfb->textures[statt]; + if (!ptex) + return NULL; + + psurf = NULL; + + switch (statt) { + case ST_ATTACHMENT_FRONT_LEFT: + cache = &stwfb->front_surface; + break; + case ST_ATTACHMENT_BACK_LEFT: + cache = &stwfb->back_surface; + break; + default: + cache = &psurf; + break; + } + + if (!*cache) { + *cache = stw_dev->screen->get_tex_surface(stw_dev->screen, + ptex, 0, 0, 0, + PIPE_BIND_DISPLAY_TARGET | + PIPE_BIND_RENDER_TARGET); + } + + if (psurf != *cache) + pipe_surface_reference(&psurf, *cache); + + return psurf; +} + +/** + * Present an attachment of the framebuffer. + */ +static boolean +stw_st_framebuffer_present_locked(struct st_framebuffer_iface *stfb, + enum st_attachment_type statt) +{ + struct stw_st_framebuffer *stwfb = stw_st_framebuffer(stfb); + struct pipe_surface *psurf; + + psurf = get_present_surface_locked(&stwfb->base, statt); + if (psurf) { + stw_framebuffer_present_locked(stwfb->fb->hDC, stwfb->fb, psurf); + pipe_surface_reference(&psurf, NULL); + } + + return TRUE; +} + +static boolean +stw_st_framebuffer_flush_front(struct st_framebuffer_iface *stfb, + enum st_attachment_type statt) +{ + struct stw_st_framebuffer *stwfb = stw_st_framebuffer(stfb); + + pipe_mutex_lock(stwfb->fb->mutex); + + return stw_st_framebuffer_present_locked(&stwfb->base, statt); +} + +/** + * Create a framebuffer interface. + */ +struct st_framebuffer_iface * +stw_st_create_framebuffer(struct stw_framebuffer *fb) +{ + struct stw_st_framebuffer *stwfb; + + stwfb = CALLOC_STRUCT(stw_st_framebuffer); + if (!stwfb) + return NULL; + + stwfb->fb = fb; + stwfb->stvis = fb->pfi->stvis; + + stwfb->base.visual = &stwfb->stvis; + stwfb->base.flush_front = stw_st_framebuffer_flush_front; + stwfb->base.validate = stw_st_framebuffer_validate; + + return &stwfb->base; +} + +/** + * Destroy a framebuffer interface. + */ +void +stw_st_destroy_framebuffer_locked(struct st_framebuffer_iface *stfb) +{ + struct stw_st_framebuffer *stwfb = stw_st_framebuffer(stfb); + int i; + + pipe_surface_reference(&stwfb->front_surface, NULL); + pipe_surface_reference(&stwfb->back_surface, NULL); + + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) + pipe_resource_reference(&stwfb->textures[i], NULL); + + FREE(stwfb); +} + +/** + * Swap the buffers of the given framebuffer. + */ +boolean +stw_st_swap_framebuffer_locked(struct st_framebuffer_iface *stfb) +{ + struct stw_st_framebuffer *stwfb = stw_st_framebuffer(stfb); + unsigned front = ST_ATTACHMENT_FRONT_LEFT, back = ST_ATTACHMENT_BACK_LEFT; + struct pipe_resource *ptex; + struct pipe_surface *psurf; + unsigned mask; + + /* swap the textures */ + ptex = stwfb->textures[front]; + stwfb->textures[front] = stwfb->textures[back]; + stwfb->textures[back] = ptex; + + /* swap the surfaces */ + psurf = stwfb->front_surface; + stwfb->front_surface = stwfb->back_surface; + stwfb->back_surface = psurf; + + /* convert to mask */ + front = 1 << front; + back = 1 << back; + + /* swap the bits in mask */ + mask = stwfb->texture_mask & ~(front | back); + if (stwfb->texture_mask & front) + mask |= back; + if (stwfb->texture_mask & back) + mask |= front; + stwfb->texture_mask = mask; + + front = ST_ATTACHMENT_FRONT_LEFT; + return stw_st_framebuffer_present_locked(&stwfb->base, front); +} + +/** + * Create an st_api of the state tracker. + */ +struct st_api * +stw_st_create_api(void) +{ + return st_manager_create_api(); +} diff --git a/src/gallium/state_trackers/wgl/stw_st.h b/src/gallium/state_trackers/wgl/stw_st.h new file mode 100644 index 00000000000..23771d8bef6 --- /dev/null +++ b/src/gallium/state_trackers/wgl/stw_st.h @@ -0,0 +1,47 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu <olv@lunarg.com> + */ + +#ifndef STW_ST_H +#define STW_ST_H + +#include "state_tracker/st_api.h" + +struct stw_framebuffer; + +struct st_api * +stw_st_create_api(void); + +struct st_framebuffer_iface * +stw_st_create_framebuffer(struct stw_framebuffer *fb); + +void +stw_st_destroy_framebuffer_locked(struct st_framebuffer_iface *stfb); + +boolean +stw_st_swap_framebuffer_locked(struct st_framebuffer_iface *stfb); + +#endif /* STW_ST_H */ diff --git a/src/gallium/state_trackers/xorg/xorg_crtc.c b/src/gallium/state_trackers/xorg/xorg_crtc.c index eef428232b0..669bd9edcf0 100644 --- a/src/gallium/state_trackers/xorg/xorg_crtc.c +++ b/src/gallium/state_trackers/xorg/xorg_crtc.c @@ -62,7 +62,7 @@ struct crtc_private drmModeCrtcPtr drm_crtc; /* hwcursor */ - struct pipe_texture *cursor_tex; + struct pipe_resource *cursor_tex; struct kms_bo *cursor_bo; unsigned cursor_handle; @@ -197,12 +197,12 @@ crtc_load_cursor_argb_ga3d(xf86CrtcPtr crtc, CARD32 * image) struct pipe_transfer *transfer; if (!crtcp->cursor_tex) { - struct pipe_texture templat; + struct pipe_resource templat; struct winsys_handle whandle; memset(&templat, 0, sizeof(templat)); - templat.tex_usage |= PIPE_TEXTURE_USAGE_RENDER_TARGET; - templat.tex_usage |= PIPE_TEXTURE_USAGE_SCANOUT; + templat.bind |= PIPE_BIND_RENDER_TARGET; + templat.bind |= PIPE_BIND_SCANOUT; templat.target = PIPE_TEXTURE_2D; templat.last_level = 0; templat.depth0 = 1; @@ -213,14 +213,14 @@ crtc_load_cursor_argb_ga3d(xf86CrtcPtr crtc, CARD32 * image) memset(&whandle, 0, sizeof(whandle)); whandle.type = DRM_API_HANDLE_TYPE_KMS; - crtcp->cursor_tex = ms->screen->texture_create(ms->screen, + crtcp->cursor_tex = ms->screen->resource_create(ms->screen, &templat); - ms->screen->texture_get_handle(ms->screen, crtcp->cursor_tex, &whandle); + ms->screen->resource_get_handle(ms->screen, crtcp->cursor_tex, &whandle); crtcp->cursor_handle = whandle.handle; } - transfer = ms->ctx->get_tex_transfer(ms->ctx, crtcp->cursor_tex, + transfer = pipe_get_transfer(ms->ctx, crtcp->cursor_tex, 0, 0, 0, PIPE_TRANSFER_WRITE, 0, 0, 64, 64); @@ -229,7 +229,7 @@ crtc_load_cursor_argb_ga3d(xf86CrtcPtr crtc, CARD32 * image) transfer->stride, 0, 0, 64, 64, (void*)image, 64 * 4, 0, 0); ms->ctx->transfer_unmap(ms->ctx, transfer); - ms->ctx->tex_transfer_destroy(ms->ctx, transfer); + ms->ctx->transfer_destroy(ms->ctx, transfer); } #if HAVE_LIBKMS @@ -329,7 +329,7 @@ xorg_crtc_cursor_destroy(xf86CrtcPtr crtc) struct crtc_private *crtcp = crtc->driver_private; if (crtcp->cursor_tex) - pipe_texture_reference(&crtcp->cursor_tex, NULL); + pipe_resource_reference(&crtcp->cursor_tex, NULL); #ifdef HAVE_LIBKMS if (crtcp->cursor_bo) kms_bo_destroy(&crtcp->cursor_bo); diff --git a/src/gallium/state_trackers/xorg/xorg_dri2.c b/src/gallium/state_trackers/xorg/xorg_dri2.c index 91c251bb4ff..b90f9c908d2 100644 --- a/src/gallium/state_trackers/xorg/xorg_dri2.c +++ b/src/gallium/state_trackers/xorg/xorg_dri2.c @@ -53,14 +53,14 @@ static Bool set_format_in_do_create_buffer; typedef struct { PixmapPtr pPixmap; - struct pipe_texture *tex; + struct pipe_resource *tex; struct pipe_fence_handle *fence; } *BufferPrivatePtr; static Bool dri2_do_create_buffer(DrawablePtr pDraw, DRI2BufferPtr buffer, unsigned int format) { - struct pipe_texture *tex = NULL; + struct pipe_resource *tex = NULL; ScreenPtr pScreen = pDraw->pScreen; ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; modesettingPtr ms = modesettingPTR(pScrn); @@ -101,9 +101,9 @@ dri2_do_create_buffer(DrawablePtr pDraw, DRI2BufferPtr buffer, unsigned int form /* Fall through */ case DRI2BufferDepth: if (exa_priv->depth_stencil_tex) - pipe_texture_reference(&tex, exa_priv->depth_stencil_tex); + pipe_resource_reference(&tex, exa_priv->depth_stencil_tex); else { - struct pipe_texture template; + struct pipe_resource template; unsigned depthBits = (format != 0) ? format : pDraw->depth; memset(&template, 0, sizeof(template)); template.target = PIPE_TEXTURE_2D; @@ -128,10 +128,10 @@ dri2_do_create_buffer(DrawablePtr pDraw, DRI2BufferPtr buffer, unsigned int form template.height0 = pDraw->height; template.depth0 = 1; template.last_level = 0; - template.tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL | - PIPE_TEXTURE_USAGE_SHARED; - tex = ms->screen->texture_create(ms->screen, &template); - pipe_texture_reference(&exa_priv->depth_stencil_tex, tex); + template.bind = PIPE_BIND_DEPTH_STENCIL | + PIPE_BIND_SHARED; + tex = ms->screen->resource_create(ms->screen, &template); + pipe_resource_reference(&exa_priv->depth_stencil_tex, tex); } break; } @@ -157,7 +157,7 @@ dri2_do_create_buffer(DrawablePtr pDraw, DRI2BufferPtr buffer, unsigned int form memset(&whandle, 0, sizeof(whandle)); whandle.type = DRM_API_HANDLE_TYPE_SHARED; - ms->screen->texture_get_handle(ms->screen, tex, &whandle); + ms->screen->resource_get_handle(ms->screen, tex, &whandle); buffer->name = whandle.handle; buffer->pitch = whandle.stride; @@ -185,9 +185,9 @@ dri2_do_destroy_buffer(DrawablePtr pDraw, DRI2BufferPtr buffer) BufferPrivatePtr private = buffer->driverPrivate; struct exa_pixmap_priv *exa_priv = exaGetPixmapDriverPrivate(private->pPixmap); - pipe_texture_reference(&private->tex, NULL); + pipe_resource_reference(&private->tex, NULL); ms->screen->fence_reference(ms->screen, &private->fence, NULL); - pipe_texture_reference(&exa_priv->depth_stencil_tex, NULL); + pipe_resource_reference(&exa_priv->depth_stencil_tex, NULL); (*pScreen->DestroyPixmap)(private->pPixmap); } @@ -437,11 +437,11 @@ xorg_dri2_init(ScreenPtr pScreen) ms->d_depth_bits_last = ms->screen->is_format_supported(ms->screen, PIPE_FORMAT_Z24X8_UNORM, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0); + PIPE_BIND_DEPTH_STENCIL, 0); ms->ds_depth_bits_last = ms->screen->is_format_supported(ms->screen, PIPE_FORMAT_Z24_UNORM_S8_USCALED, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0); + PIPE_BIND_DEPTH_STENCIL, 0); return DRI2ScreenInit(pScreen, &dri2info); } diff --git a/src/gallium/state_trackers/xorg/xorg_driver.c b/src/gallium/state_trackers/xorg/xorg_driver.c index 8ac5179545a..3687ee0db4e 100644 --- a/src/gallium/state_trackers/xorg/xorg_driver.c +++ b/src/gallium/state_trackers/xorg/xorg_driver.c @@ -676,10 +676,9 @@ drv_screen_init(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) } if (ms->screen) { - float maxf; int max; - maxf = ms->screen->get_paramf(ms->screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS); - max = (1 << (int)(maxf - 1.0f)); + max = ms->screen->get_param(ms->screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS); + max = 1 << (max - 1); max_width = max < max_width ? max : max_width; max_height = max < max_height ? max : max_height; } @@ -986,7 +985,7 @@ drv_destroy_front_buffer_ga3d(ScrnInfoPtr pScrn) ms->fb_id = -1; } - pipe_texture_reference(&ms->root_texture, NULL); + pipe_resource_reference(&ms->root_texture, NULL); return TRUE; } @@ -994,7 +993,7 @@ static Bool drv_create_front_buffer_ga3d(ScrnInfoPtr pScrn) { modesettingPtr ms = modesettingPTR(pScrn); - struct pipe_texture *tex; + struct pipe_resource *tex; struct winsys_handle whandle; unsigned fb_id; int ret; @@ -1010,7 +1009,7 @@ drv_create_front_buffer_ga3d(ScrnInfoPtr pScrn) memset(&whandle, 0, sizeof(whandle)); whandle.type = DRM_API_HANDLE_TYPE_KMS; - if (!ms->screen->texture_get_handle(ms->screen, tex, &whandle)) + if (!ms->screen->resource_get_handle(ms->screen, tex, &whandle)) goto err_destroy; ret = drmModeAddFB(ms->fd, @@ -1034,14 +1033,14 @@ drv_create_front_buffer_ga3d(ScrnInfoPtr pScrn) pScrn->frameY0 = 0; drv_adjust_frame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0); - pipe_texture_reference(&ms->root_texture, tex); - pipe_texture_reference(&tex, NULL); + pipe_resource_reference(&ms->root_texture, tex); + pipe_resource_reference(&tex, NULL); ms->fb_id = fb_id; return TRUE; err_destroy: - pipe_texture_reference(&tex, NULL); + pipe_resource_reference(&tex, NULL); return FALSE; } @@ -1051,7 +1050,7 @@ drv_bind_front_buffer_ga3d(ScrnInfoPtr pScrn) modesettingPtr ms = modesettingPTR(pScrn); ScreenPtr pScreen = pScrn->pScreen; PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen); - struct pipe_texture *check; + struct pipe_resource *check; xorg_exa_set_displayed_usage(rootPixmap); xorg_exa_set_shared_usage(rootPixmap); @@ -1063,7 +1062,7 @@ drv_bind_front_buffer_ga3d(ScrnInfoPtr pScrn) if (ms->root_texture != check) FatalError("Created new root texture\n"); - pipe_texture_reference(&check, NULL); + pipe_resource_reference(&check, NULL); return TRUE; } diff --git a/src/gallium/state_trackers/xorg/xorg_exa.c b/src/gallium/state_trackers/xorg/xorg_exa.c index 76e6411bb8c..d5a1be81747 100644 --- a/src/gallium/state_trackers/xorg/xorg_exa.c +++ b/src/gallium/state_trackers/xorg/xorg_exa.c @@ -188,7 +188,7 @@ ExaDownloadFromScreen(PixmapPtr pPix, int x, int y, int w, int h, char *dst, if (!priv || !priv->tex) return FALSE; - transfer = exa->pipe->get_tex_transfer(exa->pipe, priv->tex, 0, 0, 0, + transfer = pipe_get_transfer(exa->pipe, priv->tex, 0, 0, 0, PIPE_TRANSFER_READ, x, y, w, h); if (!transfer) return FALSE; @@ -203,7 +203,7 @@ ExaDownloadFromScreen(PixmapPtr pPix, int x, int y, int w, int h, char *dst, transfer->stride, 0, 0); exa->pipe->transfer_unmap(exa->pipe, transfer); - exa->pipe->tex_transfer_destroy(exa->pipe, transfer); + exa->pipe->transfer_destroy(exa->pipe, transfer); return TRUE; } @@ -222,7 +222,7 @@ ExaUploadToScreen(PixmapPtr pPix, int x, int y, int w, int h, char *src, if (!priv || !priv->tex) return FALSE; - transfer = exa->pipe->get_tex_transfer(exa->pipe, priv->tex, 0, 0, 0, + transfer = pipe_get_transfer(exa->pipe, priv->tex, 0, 0, 0, PIPE_TRANSFER_WRITE, x, y, w, h); if (!transfer) return FALSE; @@ -237,7 +237,7 @@ ExaUploadToScreen(PixmapPtr pPix, int x, int y, int w, int h, char *src, (unsigned char*)src, src_pitch, 0, 0); exa->pipe->transfer_unmap(exa->pipe, transfer); - exa->pipe->tex_transfer_destroy(exa->pipe, transfer); + exa->pipe->transfer_destroy(exa->pipe, transfer); return TRUE; } @@ -265,7 +265,7 @@ ExaPrepareAccess(PixmapPtr pPix, int index) assert(pPix->drawable.height <= priv->tex->height0); priv->map_transfer = - exa->pipe->get_tex_transfer(exa->pipe, priv->tex, 0, 0, 0, + pipe_get_transfer(exa->pipe, priv->tex, 0, 0, 0, #ifdef EXA_MIXED_PIXMAPS PIPE_TRANSFER_MAP_DIRECTLY | #endif @@ -309,7 +309,7 @@ ExaFinishAccess(PixmapPtr pPix, int index) if (--priv->map_count == 0) { assert(priv->map_transfer); exa->pipe->transfer_unmap(exa->pipe, priv->map_transfer); - exa->pipe->tex_transfer_destroy(exa->pipe, priv->map_transfer); + exa->pipe->transfer_destroy(exa->pipe, priv->map_transfer); priv->map_transfer = NULL; pPix->devPrivate.ptr = NULL; } @@ -347,7 +347,7 @@ ExaPrepareSolid(PixmapPtr pPixmap, int alu, Pixel planeMask, Pixel fg) if (!exa->scrn->is_format_supported(exa->scrn, priv->tex->format, priv->tex->target, - PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)) { + PIPE_BIND_RENDER_TARGET, 0)) { XORG_FALLBACK("format %s", util_format_name(priv->tex->format)); } @@ -428,12 +428,12 @@ ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir, if (!exa->scrn->is_format_supported(exa->scrn, priv->tex->format, priv->tex->target, - PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)) + PIPE_BIND_RENDER_TARGET, 0)) XORG_FALLBACK("pDst format %s", util_format_name(priv->tex->format)); if (!exa->scrn->is_format_supported(exa->scrn, src_priv->tex->format, src_priv->tex->target, - PIPE_TEXTURE_USAGE_SAMPLER, 0)) + PIPE_BIND_SAMPLER_VIEW, 0)) XORG_FALLBACK("pSrc format %s", util_format_name(src_priv->tex->format)); exa->copy.src = src_priv; @@ -453,13 +453,13 @@ ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir, exa->scrn->get_tex_surface( exa->scrn, exa->copy.src->tex, 0, 0, 0, - PIPE_BUFFER_USAGE_GPU_READ); + PIPE_BIND_BLIT_SOURCE); exa->copy.dst_surface = exa->scrn->get_tex_surface( exa->scrn, exa->copy.dst->tex, 0, 0, 0, - PIPE_BUFFER_USAGE_GPU_WRITE ); + PIPE_BIND_BLIT_DESTINATION ); } else { exa->copy.use_surface_copy = FALSE; @@ -468,14 +468,14 @@ ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir, exa->copy.src_texture = renderer_clone_texture( exa->renderer, exa->copy.src->tex ); else - pipe_texture_reference(&exa->copy.src_texture, + pipe_resource_reference(&exa->copy.src_texture, exa->copy.src->tex); exa->copy.dst_surface = exa->scrn->get_tex_surface(exa->scrn, exa->copy.dst->tex, 0, 0, 0, - PIPE_BUFFER_USAGE_GPU_WRITE); + PIPE_BIND_BLIT_DESTINATION); renderer_copy_prepare(exa->renderer, @@ -541,7 +541,7 @@ ExaDoneCopy(PixmapPtr pPixmap) exa->copy.dst = NULL; pipe_surface_reference(&exa->copy.src_surface, NULL); pipe_surface_reference(&exa->copy.dst_surface, NULL); - pipe_texture_reference(&exa->copy.src_texture, NULL); + pipe_resource_reference(&exa->copy.src_texture, NULL); } @@ -639,7 +639,7 @@ ExaPrepareComposite(int op, PicturePtr pSrcPicture, if (!exa->scrn->is_format_supported(exa->scrn, priv->tex->format, priv->tex->target, - PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)) + PIPE_BIND_RENDER_TARGET, 0)) XORG_FALLBACK("pDst format: %s", util_format_name(priv->tex->format)); if (priv->picture_format != pDstPicture->format) @@ -654,7 +654,7 @@ ExaPrepareComposite(int op, PicturePtr pSrcPicture, if (!exa->scrn->is_format_supported(exa->scrn, priv->tex->format, priv->tex->target, - PIPE_TEXTURE_USAGE_SAMPLER, 0)) + PIPE_BIND_SAMPLER_VIEW, 0)) XORG_FALLBACK("pSrc format: %s", util_format_name(priv->tex->format)); if (!picture_check_formats(priv, pSrcPicture)) @@ -671,7 +671,7 @@ ExaPrepareComposite(int op, PicturePtr pSrcPicture, if (!exa->scrn->is_format_supported(exa->scrn, priv->tex->format, priv->tex->target, - PIPE_TEXTURE_USAGE_SAMPLER, 0)) + PIPE_BIND_SAMPLER_VIEW, 0)) XORG_FALLBACK("pMask format: %s", util_format_name(priv->tex->format)); if (!picture_check_formats(priv, pMaskPicture)) @@ -744,7 +744,7 @@ ExaDestroyPixmap(ScreenPtr pScreen, void *dPriv) if (!priv) return; - pipe_texture_reference(&priv->tex, NULL); + pipe_resource_reference(&priv->tex, NULL); xfree(priv); } @@ -776,7 +776,7 @@ xorg_exa_set_displayed_usage(PixmapPtr pPixmap) return 0; } - priv->flags |= PIPE_TEXTURE_USAGE_SCANOUT; + priv->flags |= PIPE_BIND_SCANOUT; return 0; } @@ -792,7 +792,7 @@ xorg_exa_set_shared_usage(PixmapPtr pPixmap) return 0; } - priv->flags |= PIPE_TEXTURE_USAGE_SHARED; + priv->flags |= PIPE_BIND_SHARED; return 0; } @@ -867,8 +867,8 @@ ExaModifyPixmapHeader(PixmapPtr pPixmap, int width, int height, !size_match(width, priv->tex->width0) || !size_match(height, priv->tex->height0) || priv->tex_flags != priv->flags)) { - struct pipe_texture *texture = NULL; - struct pipe_texture template; + struct pipe_resource *texture = NULL; + struct pipe_resource template; memset(&template, 0, sizeof(template)); template.target = PIPE_TEXTURE_2D; @@ -884,16 +884,16 @@ ExaModifyPixmapHeader(PixmapPtr pPixmap, int width, int height, template.depth0 = 1; template.last_level = 0; - template.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET | priv->flags; + template.bind = PIPE_BIND_RENDER_TARGET | priv->flags; priv->tex_flags = priv->flags; - texture = exa->scrn->texture_create(exa->scrn, &template); + texture = exa->scrn->resource_create(exa->scrn, &template); if (priv->tex) { struct pipe_surface *dst_surf; struct pipe_surface *src_surf; dst_surf = exa->scrn->get_tex_surface( - exa->scrn, texture, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE); + exa->scrn, texture, 0, 0, 0, PIPE_BIND_BLIT_DESTINATION); src_surf = xorg_gpu_surface(exa->pipe->screen, priv); if (exa->pipe->surface_copy) { exa->pipe->surface_copy(exa->pipe, dst_surf, 0, 0, src_surf, @@ -908,29 +908,29 @@ ExaModifyPixmapHeader(PixmapPtr pPixmap, int width, int height, exa->scrn->tex_surface_destroy(src_surf); } - pipe_texture_reference(&priv->tex, texture); + pipe_resource_reference(&priv->tex, texture); /* the texture we create has one reference */ - pipe_texture_reference(&texture, NULL); + pipe_resource_reference(&texture, NULL); } return TRUE; } -struct pipe_texture * +struct pipe_resource * xorg_exa_get_texture(PixmapPtr pPixmap) { struct exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pPixmap); - struct pipe_texture *tex = NULL; - pipe_texture_reference(&tex, priv->tex); + struct pipe_resource *tex = NULL; + pipe_resource_reference(&tex, priv->tex); return tex; } Bool -xorg_exa_set_texture(PixmapPtr pPixmap, struct pipe_texture *tex) +xorg_exa_set_texture(PixmapPtr pPixmap, struct pipe_resource *tex) { struct exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pPixmap); - int mask = PIPE_TEXTURE_USAGE_SHARED | PIPE_TEXTURE_USAGE_SCANOUT; + int mask = PIPE_BIND_SHARED | PIPE_BIND_SCANOUT; if (!priv) return FALSE; @@ -939,20 +939,20 @@ xorg_exa_set_texture(PixmapPtr pPixmap, struct pipe_texture *tex) pPixmap->drawable.height != tex->height0) return FALSE; - pipe_texture_reference(&priv->tex, tex); - priv->tex_flags = tex->tex_usage & mask; + pipe_resource_reference(&priv->tex, tex); + priv->tex_flags = tex->bind & mask; return TRUE; } -struct pipe_texture * +struct pipe_resource * xorg_exa_create_root_texture(ScrnInfoPtr pScrn, int width, int height, int depth, int bitsPerPixel) { modesettingPtr ms = modesettingPTR(pScrn); struct exa_context *exa = ms->exa; - struct pipe_texture template; + struct pipe_resource template; int dummy; memset(&template, 0, sizeof(template)); @@ -962,11 +962,11 @@ xorg_exa_create_root_texture(ScrnInfoPtr pScrn, template.height0 = height; template.depth0 = 1; template.last_level = 0; - template.tex_usage |= PIPE_TEXTURE_USAGE_RENDER_TARGET; - template.tex_usage |= PIPE_TEXTURE_USAGE_SCANOUT; - template.tex_usage |= PIPE_TEXTURE_USAGE_SHARED; + template.bind |= PIPE_BIND_RENDER_TARGET; + template.bind |= PIPE_BIND_SCANOUT; + template.bind |= PIPE_BIND_SHARED; - return exa->scrn->texture_create(exa->scrn, &template); + return exa->scrn->resource_create(exa->scrn, &template); } void @@ -1073,9 +1073,12 @@ out_err: struct pipe_surface * xorg_gpu_surface(struct pipe_screen *scrn, struct exa_pixmap_priv *priv) { + + /* seems to get called both for blits and render target usage */ return scrn->get_tex_surface(scrn, priv->tex, 0, 0, 0, - PIPE_BUFFER_USAGE_GPU_READ | - PIPE_BUFFER_USAGE_GPU_WRITE); + PIPE_BIND_BLIT_SOURCE | + PIPE_BIND_BLIT_DESTINATION | + PIPE_BIND_RENDER_TARGET); } diff --git a/src/gallium/state_trackers/xorg/xorg_exa.h b/src/gallium/state_trackers/xorg/xorg_exa.h index 41b19061599..a35e9a5c901 100644 --- a/src/gallium/state_trackers/xorg/xorg_exa.h +++ b/src/gallium/state_trackers/xorg/xorg_exa.h @@ -43,7 +43,7 @@ struct exa_context struct pipe_surface *src_surface; struct pipe_surface *dst_surface; - struct pipe_texture *src_texture; + struct pipe_resource *src_texture; } copy; }; @@ -56,8 +56,8 @@ struct exa_pixmap_priv int picture_format; - struct pipe_texture *tex; - struct pipe_texture *depth_stencil_tex; + struct pipe_resource *tex; + struct pipe_resource *depth_stencil_tex; struct pipe_transfer *map_transfer; unsigned map_count; diff --git a/src/gallium/state_trackers/xorg/xorg_renderer.c b/src/gallium/state_trackers/xorg/xorg_renderer.c index 81b0dcf656f..13fa561390f 100644 --- a/src/gallium/state_trackers/xorg/xorg_renderer.c +++ b/src/gallium/state_trackers/xorg/xorg_renderer.c @@ -42,14 +42,16 @@ static INLINE void map_point(float *mat, float x, float y, } } -static INLINE struct pipe_buffer * +static INLINE struct pipe_resource * renderer_buffer_create(struct xorg_renderer *r) { - struct pipe_buffer *buf = + struct pipe_resource *buf = pipe_user_buffer_create(r->pipe->screen, r->buffer, sizeof(float)* - r->buffer_size); + r->buffer_size, +/* XXX was: PIPE_BUFFER_USAGE_PIXEL/PIPE_BUFFER_USAGE_GPU_WRITE even though this is a vertex buffer??? */ + PIPE_BIND_VERTEX_BUFFER); r->buffer_size = 0; return buf; @@ -59,7 +61,7 @@ static INLINE void renderer_draw(struct xorg_renderer *r) { struct pipe_context *pipe = r->pipe; - struct pipe_buffer *buf = 0; + struct pipe_resource *buf = 0; int num_verts = r->buffer_size/(r->attrs_per_vertex * NUM_COMPONENTS); if (!r->buffer_size) @@ -76,7 +78,7 @@ renderer_draw(struct xorg_renderer *r) num_verts, /* verts */ r->attrs_per_vertex); /* attribs/vert */ - pipe_buffer_reference(&buf, NULL); + pipe_resource_reference(&buf, NULL); } } @@ -161,7 +163,7 @@ static void add_vertex_data1(struct xorg_renderer *r, float srcX, float srcY, float dstX, float dstY, float width, float height, - struct pipe_texture *src, float *src_matrix) + struct pipe_resource *src, float *src_matrix) { float s0, t0, s1, t1, s2, t2, s3, t3; float pt0[2], pt1[2], pt2[2], pt3[2]; @@ -231,8 +233,8 @@ static void add_vertex_data2(struct xorg_renderer *r, float srcX, float srcY, float maskX, float maskY, float dstX, float dstY, float width, float height, - struct pipe_texture *src, - struct pipe_texture *mask, + struct pipe_resource *src, + struct pipe_resource *mask, float *src_matrix, float *mask_matrix) { float src_s0, src_t0, src_s1, src_t1; @@ -284,11 +286,11 @@ add_vertex_data2(struct xorg_renderer *r, src_s0, src_t1, mask_s0, mask_t1); } -static struct pipe_buffer * +static struct pipe_resource * setup_vertex_data_yuv(struct xorg_renderer *r, float srcX, float srcY, float srcW, float srcH, float dstX, float dstY, float dstW, float dstH, - struct pipe_texture **tex) + struct pipe_resource **tex) { float s0, t0, s1, t1; float spt0[2], spt1[2]; @@ -390,14 +392,14 @@ struct xorg_renderer * renderer_create(struct pipe_context *pipe) void renderer_destroy(struct xorg_renderer *r) { - struct pipe_buffer **vsbuf = &r->vs_const_buffer; - struct pipe_buffer **fsbuf = &r->fs_const_buffer; + struct pipe_resource **vsbuf = &r->vs_const_buffer; + struct pipe_resource **fsbuf = &r->fs_const_buffer; if (*vsbuf) - pipe_buffer_reference(vsbuf, NULL); + pipe_resource_reference(vsbuf, NULL); if (*fsbuf) - pipe_buffer_reference(fsbuf, NULL); + pipe_resource_reference(fsbuf, NULL); if (r->shaders) { xorg_shaders_destroy(r->shaders); @@ -420,17 +422,17 @@ void renderer_set_constants(struct xorg_renderer *r, const float *params, int param_bytes) { - struct pipe_buffer **cbuf = + struct pipe_resource **cbuf = (shader_type == PIPE_SHADER_VERTEX) ? &r->vs_const_buffer : &r->fs_const_buffer; - pipe_buffer_reference(cbuf, NULL); - *cbuf = pipe_buffer_create(r->pipe->screen, 16, - PIPE_BUFFER_USAGE_CONSTANT, + pipe_resource_reference(cbuf, NULL); + *cbuf = pipe_buffer_create(r->pipe->screen, + PIPE_BIND_CONSTANT_BUFFER, param_bytes); if (*cbuf) { - pipe_buffer_write(r->pipe->screen, *cbuf, + pipe_buffer_write(r->pipe, *cbuf, 0, param_bytes, params); } r->pipe->set_constant_buffer(r->pipe, shader_type, 0, *cbuf); @@ -439,7 +441,7 @@ void renderer_set_constants(struct xorg_renderer *r, void renderer_copy_prepare(struct xorg_renderer *r, struct pipe_surface *dst_surface, - struct pipe_texture *src_texture) + struct pipe_resource *src_texture) { struct pipe_context *pipe = r->pipe; struct pipe_screen *screen = pipe->screen; @@ -447,7 +449,7 @@ void renderer_copy_prepare(struct xorg_renderer *r, assert(screen->is_format_supported(screen, dst_surface->format, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_RENDER_TARGET, + PIPE_BIND_RENDER_TARGET, 0)); (void) screen; @@ -506,24 +508,24 @@ void renderer_copy_prepare(struct xorg_renderer *r, r->attrs_per_vertex = 2; } -struct pipe_texture * +struct pipe_resource * renderer_clone_texture(struct xorg_renderer *r, - struct pipe_texture *src) + struct pipe_resource *src) { enum pipe_format format; struct pipe_context *pipe = r->pipe; struct pipe_screen *screen = pipe->screen; - struct pipe_texture *pt; - struct pipe_texture templ; + struct pipe_resource *pt; + struct pipe_resource templ; - if (pipe->is_texture_referenced(pipe, src, 0, 0) & + if (pipe->is_resource_referenced(pipe, src, 0, 0) & PIPE_REFERENCED_FOR_WRITE) pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL); /* the coming in texture should already have that invariance */ debug_assert(screen->is_format_supported(screen, src->format, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_SAMPLER, 0)); + PIPE_BIND_SAMPLER_VIEW, 0)); format = src->format; @@ -534,9 +536,9 @@ renderer_clone_texture(struct xorg_renderer *r, templ.width0 = src->width0; templ.height0 = src->height0; templ.depth0 = 1; - templ.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER; + templ.bind = PIPE_BIND_SAMPLER_VIEW; - pt = screen->texture_create(screen, &templ); + pt = screen->resource_create(screen, &templ); debug_assert(!pt || pipe_is_referenced(&pt->reference)); @@ -546,9 +548,9 @@ renderer_clone_texture(struct xorg_renderer *r, { /* copy source framebuffer surface into texture */ struct pipe_surface *ps_read = screen->get_tex_surface( - screen, src, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_READ); + screen, src, 0, 0, 0, PIPE_BIND_BLIT_SOURCE); struct pipe_surface *ps_tex = screen->get_tex_surface( - screen, pt, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE ); + screen, pt, 0, 0, 0, PIPE_BIND_BLIT_DESTINATION ); if (pipe->surface_copy) { pipe->surface_copy(pipe, ps_tex, /* dest */ @@ -608,10 +610,10 @@ void renderer_copy_pixmap(struct xorg_renderer *r, void renderer_draw_yuv(struct xorg_renderer *r, int src_x, int src_y, int src_w, int src_h, int dst_x, int dst_y, int dst_w, int dst_h, - struct pipe_texture **textures) + struct pipe_resource **textures) { struct pipe_context *pipe = r->pipe; - struct pipe_buffer *buf = 0; + struct pipe_resource *buf = 0; buf = setup_vertex_data_yuv(r, src_x, src_y, src_w, src_h, @@ -628,7 +630,7 @@ void renderer_draw_yuv(struct xorg_renderer *r, 4, /* verts */ num_attribs); /* attribs/vert */ - pipe_buffer_reference(&buf, NULL); + pipe_resource_reference(&buf, NULL); } } diff --git a/src/gallium/state_trackers/xorg/xorg_renderer.h b/src/gallium/state_trackers/xorg/xorg_renderer.h index cc5802e79b2..0454a6513d4 100644 --- a/src/gallium/state_trackers/xorg/xorg_renderer.h +++ b/src/gallium/state_trackers/xorg/xorg_renderer.h @@ -23,8 +23,8 @@ struct xorg_renderer { int fb_width; int fb_height; - struct pipe_buffer *vs_const_buffer; - struct pipe_buffer *fs_const_buffer; + struct pipe_resource *vs_const_buffer; + struct pipe_resource *fs_const_buffer; float buffer[BUF_SIZE]; int buffer_size; @@ -56,7 +56,7 @@ void renderer_set_constants(struct xorg_renderer *r, void renderer_draw_yuv(struct xorg_renderer *r, int src_x, int src_y, int src_w, int src_h, int dst_x, int dst_y, int dst_w, int dst_h, - struct pipe_texture **textures); + struct pipe_resource **textures); void renderer_begin_solid(struct xorg_renderer *r); void renderer_solid(struct xorg_renderer *r, @@ -77,13 +77,13 @@ void renderer_texture(struct xorg_renderer *r, void renderer_draw_flush(struct xorg_renderer *r); -struct pipe_texture * +struct pipe_resource * renderer_clone_texture(struct xorg_renderer *r, - struct pipe_texture *src); + struct pipe_resource *src); void renderer_copy_prepare(struct xorg_renderer *r, struct pipe_surface *dst_surface, - struct pipe_texture *src_texture); + struct pipe_resource *src_texture); void renderer_copy_pixmap(struct xorg_renderer *r, int dx, int dy, diff --git a/src/gallium/state_trackers/xorg/xorg_tracker.h b/src/gallium/state_trackers/xorg/xorg_tracker.h index c1884ebd115..cb6773424a8 100644 --- a/src/gallium/state_trackers/xorg/xorg_tracker.h +++ b/src/gallium/state_trackers/xorg/xorg_tracker.h @@ -118,7 +118,7 @@ typedef struct _modesettingRec struct pipe_context *ctx; boolean d_depth_bits_last; boolean ds_depth_bits_last; - struct pipe_texture *root_texture; + struct pipe_resource *root_texture; /* exa */ struct exa_context *exa; @@ -142,7 +142,7 @@ Bool xorg_has_gallium(ScrnInfoPtr pScrn); /*********************************************************************** * xorg_exa.c */ -struct pipe_texture * +struct pipe_resource * xorg_exa_get_texture(PixmapPtr pPixmap); int @@ -152,9 +152,9 @@ int xorg_exa_set_shared_usage(PixmapPtr pPixmap); Bool -xorg_exa_set_texture(PixmapPtr pPixmap, struct pipe_texture *tex); +xorg_exa_set_texture(PixmapPtr pPixmap, struct pipe_resource *tex); -struct pipe_texture * +struct pipe_resource * xorg_exa_create_root_texture(ScrnInfoPtr pScrn, int width, int height, int depth, int bpp); diff --git a/src/gallium/state_trackers/xorg/xorg_xv.c b/src/gallium/state_trackers/xorg/xorg_xv.c index 5efda6837de..a221594454e 100644 --- a/src/gallium/state_trackers/xorg/xorg_xv.c +++ b/src/gallium/state_trackers/xorg/xorg_xv.c @@ -91,7 +91,7 @@ struct xorg_xv_port_priv { int current_set; /* juggle two sets of seperate Y, U and V * textures */ - struct pipe_texture *yuv[2][3]; + struct pipe_resource *yuv[2][3]; struct pipe_sampler_view *yuv_views[2][3]; }; @@ -156,13 +156,13 @@ query_best_size(ScrnInfoPtr pScrn, *p_h = drw_h; } -static INLINE struct pipe_texture * +static INLINE struct pipe_resource * create_component_texture(struct pipe_context *pipe, int width, int height) { struct pipe_screen *screen = pipe->screen; - struct pipe_texture *tex = 0; - struct pipe_texture templ; + struct pipe_resource *tex = 0; + struct pipe_resource templ; memset(&templ, 0, sizeof(templ)); templ.target = PIPE_TEXTURE_2D; @@ -171,9 +171,9 @@ create_component_texture(struct pipe_context *pipe, templ.width0 = width; templ.height0 = height; templ.depth0 = 1; - templ.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER; + templ.bind = PIPE_BIND_SAMPLER_VIEW; - tex = screen->texture_create(screen, &templ); + tex = screen->resource_create(screen, &templ); return tex; } @@ -181,7 +181,7 @@ create_component_texture(struct pipe_context *pipe, static int check_yuv_textures(struct xorg_xv_port_priv *priv, int width, int height) { - struct pipe_texture **dst = priv->yuv[priv->current_set]; + struct pipe_resource **dst = priv->yuv[priv->current_set]; struct pipe_sampler_view **dst_view = priv->yuv_views[priv->current_set]; struct pipe_sampler_view view_templ; struct pipe_context *pipe = priv->r->pipe; @@ -189,19 +189,19 @@ check_yuv_textures(struct xorg_xv_port_priv *priv, int width, int height) if (!dst[0] || dst[0]->width0 != width || dst[0]->height0 != height) { - pipe_texture_reference(&dst[0], NULL); + pipe_resource_reference(&dst[0], NULL); pipe_sampler_view_reference(&dst_view[0], NULL); } if (!dst[1] || dst[1]->width0 != width || dst[1]->height0 != height) { - pipe_texture_reference(&dst[1], NULL); + pipe_resource_reference(&dst[1], NULL); pipe_sampler_view_reference(&dst_view[1], NULL); } if (!dst[2] || dst[2]->width0 != width || dst[2]->height0 != height) { - pipe_texture_reference(&dst[2], NULL); + pipe_resource_reference(&dst[2], NULL); pipe_sampler_view_reference(&dst_view[2], NULL); } @@ -303,7 +303,7 @@ copy_packed_data(ScrnInfoPtr pScrn, unsigned short w, unsigned short h) { int i, j; - struct pipe_texture **dst = port->yuv[port->current_set]; + struct pipe_resource **dst = port->yuv[port->current_set]; struct pipe_transfer *ytrans, *utrans, *vtrans; struct pipe_context *pipe = port->r->pipe; char *ymap, *vmap, *umap; @@ -311,15 +311,15 @@ copy_packed_data(ScrnInfoPtr pScrn, int yidx, uidx, vidx; int y_array_size = w * h; - ytrans = pipe->get_tex_transfer(pipe, dst[0], + ytrans = pipe_get_transfer(pipe, dst[0], 0, 0, 0, PIPE_TRANSFER_WRITE, left, top, w, h); - utrans = pipe->get_tex_transfer(pipe, dst[1], + utrans = pipe_get_transfer(pipe, dst[1], 0, 0, 0, PIPE_TRANSFER_WRITE, left, top, w, h); - vtrans = pipe->get_tex_transfer(pipe, dst[2], + vtrans = pipe_get_transfer(pipe, dst[2], 0, 0, 0, PIPE_TRANSFER_WRITE, left, top, w, h); @@ -395,9 +395,9 @@ copy_packed_data(ScrnInfoPtr pScrn, pipe->transfer_unmap(pipe, ytrans); pipe->transfer_unmap(pipe, utrans); pipe->transfer_unmap(pipe, vtrans); - pipe->tex_transfer_destroy(pipe, ytrans); - pipe->tex_transfer_destroy(pipe, utrans); - pipe->tex_transfer_destroy(pipe, vtrans); + pipe->transfer_destroy(pipe, ytrans); + pipe->transfer_destroy(pipe, utrans); + pipe->transfer_destroy(pipe, vtrans); } @@ -416,7 +416,7 @@ draw_yuv(struct xorg_xv_port_priv *port, int src_x, int src_y, int src_w, int src_h, int dst_x, int dst_y, int dst_w, int dst_h) { - struct pipe_texture **textures = port->yuv[port->current_set]; + struct pipe_resource **textures = port->yuv[port->current_set]; /*debug_printf(" draw_yuv([%d, %d, %d ,%d], [%d, %d, %d, %d])\n", src_x, src_y, src_w, src_h, @@ -461,12 +461,12 @@ bind_shaders(struct xorg_xv_port_priv *port) } static INLINE void -conditional_flush(struct pipe_context *pipe, struct pipe_texture **tex, +conditional_flush(struct pipe_context *pipe, struct pipe_resource **tex, int num) { int i; for (i = 0; i < num; ++i) { - if (tex[i] && pipe->is_texture_referenced(pipe, tex[i], 0, 0) & + if (tex[i] && pipe->is_resource_referenced(pipe, tex[i], 0, 0) & PIPE_REFERENCED_FOR_WRITE) { pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL); return; @@ -479,7 +479,7 @@ bind_samplers(struct xorg_xv_port_priv *port) { struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS]; struct pipe_sampler_state sampler; - struct pipe_texture **dst = port->yuv[port->current_set]; + struct pipe_resource **dst = port->yuv[port->current_set]; struct pipe_sampler_view **dst_views = port->yuv_views[port->current_set]; memset(&sampler, 0, sizeof(struct pipe_sampler_state)); diff --git a/src/gallium/state_trackers/xorg/xvmc/Makefile b/src/gallium/state_trackers/xorg/xvmc/Makefile deleted file mode 100644 index 126dc6d58f1..00000000000 --- a/src/gallium/state_trackers/xorg/xvmc/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -TOP = ../../../../.. -include $(TOP)/configs/current - -LIBNAME = xvmctracker - -LIBRARY_INCLUDES = \ - $(shell pkg-config --cflags-only-I xvmc) \ - -I$(TOP)/src/gallium/winsys/g3dvl - -C_SOURCES = block.c \ - surface.c \ - context.c \ - subpicture.c \ - attributes.c - -include ../../../Makefile.template diff --git a/src/gallium/state_trackers/xorg/xvmc/SConscript b/src/gallium/state_trackers/xorg/xvmc/SConscript deleted file mode 100644 index cb25d68bd80..00000000000 --- a/src/gallium/state_trackers/xorg/xvmc/SConscript +++ /dev/null @@ -1,27 +0,0 @@ -####################################################################### -# SConscript for xvmc state_tracker - -Import('*') - -if 'xorg/xvmc' in env['statetrackers']: - - env = env.Clone() - - env.Append(CPPPATH = [ - '#/src/gallium/include', - '#/src/gallium/auxiliary', - '#/src/gallium/winsys/g3dvl', - ]) - - env.ParseConfig('pkg-config --cflags --libs xvmc') - - st_xvmc = env.ConvenienceLibrary( - target = 'st_xvmc', - source = [ 'block.c', - 'surface.c', - 'context.c', - 'subpicture.c', - 'attributes.c', - ] - ) - Export('st_xvmc') diff --git a/src/gallium/state_trackers/xorg/xvmc/attributes.c b/src/gallium/state_trackers/xorg/xvmc/attributes.c deleted file mode 100644 index 79a67838e6e..00000000000 --- a/src/gallium/state_trackers/xorg/xvmc/attributes.c +++ /dev/null @@ -1,46 +0,0 @@ -/************************************************************************** - * - * Copyright 2009 Younes Manton. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#include <assert.h> -#include <X11/Xlib.h> -#include <X11/extensions/Xvlib.h> -#include <X11/extensions/XvMClib.h> - -XvAttribute* XvMCQueryAttributes(Display *dpy, XvMCContext *context, int *number) -{ - return NULL; -} - -Status XvMCSetAttribute(Display *dpy, XvMCContext *context, Atom attribute, int value) -{ - return BadImplementation; -} - -Status XvMCGetAttribute(Display *dpy, XvMCContext *context, Atom attribute, int *value) -{ - return BadImplementation; -} diff --git a/src/gallium/state_trackers/xorg/xvmc/block.c b/src/gallium/state_trackers/xorg/xvmc/block.c deleted file mode 100644 index 5102375fcf8..00000000000 --- a/src/gallium/state_trackers/xorg/xvmc/block.c +++ /dev/null @@ -1,88 +0,0 @@ -/************************************************************************** - * - * Copyright 2009 Younes Manton. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#include <assert.h> -#include <X11/Xlib.h> -#include <X11/extensions/XvMClib.h> -#include <util/u_memory.h> -#include "xvmc_private.h" - -Status XvMCCreateBlocks(Display *dpy, XvMCContext *context, unsigned int num_blocks, XvMCBlockArray *blocks) -{ - assert(dpy); - - if (!context) - return XvMCBadContext; - if (num_blocks == 0) - return BadValue; - - assert(blocks); - - blocks->context_id = context->context_id; - blocks->num_blocks = num_blocks; - blocks->blocks = MALLOC(BLOCK_SIZE_BYTES * num_blocks); - blocks->privData = NULL; - - return Success; -} - -Status XvMCDestroyBlocks(Display *dpy, XvMCBlockArray *blocks) -{ - assert(dpy); - assert(blocks); - FREE(blocks->blocks); - - return Success; -} - -Status XvMCCreateMacroBlocks(Display *dpy, XvMCContext *context, unsigned int num_blocks, XvMCMacroBlockArray *blocks) -{ - assert(dpy); - - if (!context) - return XvMCBadContext; - if (num_blocks == 0) - return BadValue; - - assert(blocks); - - blocks->context_id = context->context_id; - blocks->num_blocks = num_blocks; - blocks->macro_blocks = MALLOC(sizeof(XvMCMacroBlock) * num_blocks); - blocks->privData = NULL; - - return Success; -} - -Status XvMCDestroyMacroBlocks(Display *dpy, XvMCMacroBlockArray *blocks) -{ - assert(dpy); - assert(blocks); - FREE(blocks->macro_blocks); - - return Success; -} diff --git a/src/gallium/state_trackers/xorg/xvmc/context.c b/src/gallium/state_trackers/xorg/xvmc/context.c deleted file mode 100644 index c8a389385a8..00000000000 --- a/src/gallium/state_trackers/xorg/xvmc/context.c +++ /dev/null @@ -1,252 +0,0 @@ -/************************************************************************** - * - * Copyright 2009 Younes Manton. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#include <assert.h> -#include <X11/Xlibint.h> -#include <X11/extensions/XvMClib.h> -#include <pipe/p_screen.h> -#include <pipe/p_video_context.h> -#include <pipe/p_video_state.h> -#include <pipe/p_state.h> -#include <vl_winsys.h> -#include <util/u_memory.h> -#include <util/u_debug.h> -#include <vl/vl_csc.h> -#include "xvmc_private.h" - -static Status Validate(Display *dpy, XvPortID port, int surface_type_id, - unsigned int width, unsigned int height, int flags, - bool *found_port, int *screen, int *chroma_format, - int *mc_type, int *surface_flags) -{ - bool found_surface = false; - XvAdaptorInfo *adaptor_info; - unsigned int num_adaptors; - int num_types; - unsigned int max_width, max_height; - Status ret; - - assert(dpy); - assert(found_port); - assert(screen); - assert(chroma_format); - assert(mc_type); - assert(surface_flags); - - *found_port = false; - - for (unsigned int i = 0; i < XScreenCount(dpy); ++i) { - ret = XvQueryAdaptors(dpy, XRootWindow(dpy, i), &num_adaptors, &adaptor_info); - if (ret != Success) - return ret; - - for (unsigned int j = 0; j < num_adaptors && !*found_port; ++j) { - for (unsigned int k = 0; k < adaptor_info[j].num_ports && !*found_port; ++k) { - XvMCSurfaceInfo *surface_info; - - if (adaptor_info[j].base_id + k != port) - continue; - - *found_port = true; - - surface_info = XvMCListSurfaceTypes(dpy, adaptor_info[j].base_id, &num_types); - if (!surface_info) { - XvFreeAdaptorInfo(adaptor_info); - return BadAlloc; - } - - for (unsigned int l = 0; l < num_types && !found_surface; ++l) { - if (surface_info[l].surface_type_id != surface_type_id) - continue; - - found_surface = true; - max_width = surface_info[l].max_width; - max_height = surface_info[l].max_height; - *chroma_format = surface_info[l].chroma_format; - *mc_type = surface_info[l].mc_type; - *surface_flags = surface_info[l].flags; - *screen = i; - } - - XFree(surface_info); - } - } - - XvFreeAdaptorInfo(adaptor_info); - } - - if (!*found_port) - return XvBadPort; - if (!found_surface) - return BadMatch; - if (width > max_width || height > max_height) - return BadValue; - if (flags != XVMC_DIRECT && flags != 0) - return BadValue; - - return Success; -} - -static enum pipe_video_profile ProfileToPipe(int xvmc_profile) -{ - if (xvmc_profile & XVMC_MPEG_1) - assert(0); - if (xvmc_profile & XVMC_MPEG_2) - return PIPE_VIDEO_PROFILE_MPEG2_MAIN; - if (xvmc_profile & XVMC_H263) - assert(0); - if (xvmc_profile & XVMC_MPEG_4) - assert(0); - - assert(0); - - return -1; -} - -static enum pipe_video_chroma_format FormatToPipe(int xvmc_format) -{ - switch (xvmc_format) { - case XVMC_CHROMA_FORMAT_420: - return PIPE_VIDEO_CHROMA_FORMAT_420; - case XVMC_CHROMA_FORMAT_422: - return PIPE_VIDEO_CHROMA_FORMAT_422; - case XVMC_CHROMA_FORMAT_444: - return PIPE_VIDEO_CHROMA_FORMAT_444; - default: - assert(0); - } - - return -1; -} - -Status XvMCCreateContext(Display *dpy, XvPortID port, int surface_type_id, - int width, int height, int flags, XvMCContext *context) -{ - bool found_port; - int scrn; - int chroma_format; - int mc_type; - int surface_flags; - Status ret; - struct pipe_screen *screen; - struct pipe_video_context *vpipe; - XvMCContextPrivate *context_priv; - float csc[16]; - - assert(dpy); - - if (!context) - return XvMCBadContext; - - ret = Validate(dpy, port, surface_type_id, width, height, flags, - &found_port, &scrn, &chroma_format, &mc_type, &surface_flags); - - /* Success and XvBadPort have the same value */ - if (ret != Success || !found_port) - return ret; - - /* XXX: Current limits */ - if (chroma_format != XVMC_CHROMA_FORMAT_420) { - debug_printf("[XvMCg3dvl] Cannot decode requested surface type. Unsupported chroma format.\n"); - return BadImplementation; - } - if (mc_type != (XVMC_MOCOMP | XVMC_MPEG_2)) { - debug_printf("[XvMCg3dvl] Cannot decode requested surface type. Non-MPEG2/Mocomp acceleration unsupported.\n"); - return BadImplementation; - } - if (!(surface_flags & XVMC_INTRA_UNSIGNED)) { - debug_printf("[XvMCg3dvl] Cannot decode requested surface type. Signed intra unsupported.\n"); - return BadImplementation; - } - - context_priv = CALLOC(1, sizeof(XvMCContextPrivate)); - if (!context_priv) - return BadAlloc; - - /* TODO: Reuse screen if process creates another context */ - screen = vl_screen_create(dpy, scrn); - - if (!screen) { - FREE(context_priv); - return BadAlloc; - } - - vpipe = vl_video_create(dpy, scrn, screen, ProfileToPipe(mc_type), - FormatToPipe(chroma_format), width, height); - - if (!vpipe) { - screen->destroy(screen); - FREE(context_priv); - return BadAlloc; - } - - /* TODO: Define some Xv attribs to allow users to specify color standard, procamp */ - vl_csc_get_matrix - ( - debug_get_bool_option("G3DVL_NO_CSC", FALSE) ? - VL_CSC_COLOR_STANDARD_IDENTITY : VL_CSC_COLOR_STANDARD_BT_601, - NULL, true, csc - ); - vpipe->set_csc_matrix(vpipe, csc); - - context_priv->vpipe = vpipe; - - context->context_id = XAllocID(dpy); - context->surface_type_id = surface_type_id; - context->width = width; - context->height = height; - context->flags = flags; - context->port = port; - context->privData = context_priv; - - SyncHandle(); - - return Success; -} - -Status XvMCDestroyContext(Display *dpy, XvMCContext *context) -{ - struct pipe_screen *screen; - struct pipe_video_context *vpipe; - XvMCContextPrivate *context_priv; - - assert(dpy); - - if (!context || !context->privData) - return XvMCBadContext; - - context_priv = context->privData; - vpipe = context_priv->vpipe; - pipe_surface_reference(&context_priv->backbuffer, NULL); - screen = vpipe->screen; - vpipe->destroy(vpipe); - screen->destroy(screen); - FREE(context_priv); - context->privData = NULL; - - return Success; -} diff --git a/src/gallium/state_trackers/xorg/xvmc/subpicture.c b/src/gallium/state_trackers/xorg/xvmc/subpicture.c deleted file mode 100644 index 69898d5fcd3..00000000000 --- a/src/gallium/state_trackers/xorg/xvmc/subpicture.c +++ /dev/null @@ -1,195 +0,0 @@ -/************************************************************************** - * - * Copyright 2009 Younes Manton. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#include <assert.h> -#include <X11/Xlibint.h> -#include <X11/extensions/XvMClib.h> - -Status XvMCCreateSubpicture(Display *dpy, XvMCContext *context, XvMCSubpicture *subpicture, - unsigned short width, unsigned short height, int xvimage_id) -{ - assert(dpy); - - if (!context) - return XvMCBadContext; - - assert(subpicture); - - /*if (width > || height > ) - return BadValue;*/ - - /*if (xvimage_id != ) - return BadMatch;*/ - - subpicture->subpicture_id = XAllocID(dpy); - subpicture->context_id = context->context_id; - subpicture->xvimage_id = xvimage_id; - subpicture->width = width; - subpicture->height = height; - subpicture->num_palette_entries = 0; - subpicture->entry_bytes = 0; - subpicture->component_order[0] = 0; - subpicture->component_order[1] = 0; - subpicture->component_order[2] = 0; - subpicture->component_order[3] = 0; - /* TODO: subpicture->privData = ;*/ - - SyncHandle(); - - return Success; -} - -Status XvMCClearSubpicture(Display *dpy, XvMCSubpicture *subpicture, short x, short y, - unsigned short width, unsigned short height, unsigned int color) -{ - assert(dpy); - - if (!subpicture) - return XvMCBadSubpicture; - - /* TODO: Assert clear rect is within bounds? Or clip? */ - - return Success; -} - -Status XvMCCompositeSubpicture(Display *dpy, XvMCSubpicture *subpicture, XvImage *image, - short srcx, short srcy, unsigned short width, unsigned short height, - short dstx, short dsty) -{ - assert(dpy); - - if (!subpicture) - return XvMCBadSubpicture; - - assert(image); - - if (subpicture->xvimage_id != image->id) - return BadMatch; - - /* TODO: Assert rects are within bounds? Or clip? */ - - return Success; -} - -Status XvMCDestroySubpicture(Display *dpy, XvMCSubpicture *subpicture) -{ - assert(dpy); - - if (!subpicture) - return XvMCBadSubpicture; - - return BadImplementation; -} - -Status XvMCSetSubpicturePalette(Display *dpy, XvMCSubpicture *subpicture, unsigned char *palette) -{ - assert(dpy); - - if (!subpicture) - return XvMCBadSubpicture; - - assert(palette); - - /* We don't support paletted subpictures */ - return BadMatch; -} - -Status XvMCBlendSubpicture(Display *dpy, XvMCSurface *target_surface, XvMCSubpicture *subpicture, - short subx, short suby, unsigned short subw, unsigned short subh, - short surfx, short surfy, unsigned short surfw, unsigned short surfh) -{ - assert(dpy); - - if (!target_surface) - return XvMCBadSurface; - - if (!subpicture) - return XvMCBadSubpicture; - - if (target_surface->context_id != subpicture->context_id) - return BadMatch; - - /* TODO: Assert rects are within bounds? Or clip? */ - return Success; -} - -Status XvMCBlendSubpicture2(Display *dpy, XvMCSurface *source_surface, XvMCSurface *target_surface, - XvMCSubpicture *subpicture, short subx, short suby, unsigned short subw, unsigned short subh, - short surfx, short surfy, unsigned short surfw, unsigned short surfh) -{ - assert(dpy); - - if (!source_surface || !target_surface) - return XvMCBadSurface; - - if (!subpicture) - return XvMCBadSubpicture; - - if (source_surface->context_id != subpicture->context_id) - return BadMatch; - - if (source_surface->context_id != subpicture->context_id) - return BadMatch; - - /* TODO: Assert rects are within bounds? Or clip? */ - return Success; -} - -Status XvMCSyncSubpicture(Display *dpy, XvMCSubpicture *subpicture) -{ - assert(dpy); - - if (!subpicture) - return XvMCBadSubpicture; - - return Success; -} - -Status XvMCFlushSubpicture(Display *dpy, XvMCSubpicture *subpicture) -{ - assert(dpy); - - if (!subpicture) - return XvMCBadSubpicture; - - return Success; -} - -Status XvMCGetSubpictureStatus(Display *dpy, XvMCSubpicture *subpicture, int *status) -{ - assert(dpy); - - if (!subpicture) - return XvMCBadSubpicture; - - assert(status); - - /* TODO */ - *status = 0; - - return Success; -} diff --git a/src/gallium/state_trackers/xorg/xvmc/surface.c b/src/gallium/state_trackers/xorg/xvmc/surface.c deleted file mode 100644 index 12d94e0c5ca..00000000000 --- a/src/gallium/state_trackers/xorg/xvmc/surface.c +++ /dev/null @@ -1,408 +0,0 @@ -/************************************************************************** - * - * Copyright 2009 Younes Manton. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#include <assert.h> -#include <X11/Xlibint.h> -#include <pipe/p_video_context.h> -#include <pipe/p_video_state.h> -#include <pipe/p_state.h> -#include <util/u_memory.h> -#include "xvmc_private.h" - -static enum pipe_mpeg12_macroblock_type TypeToPipe(int xvmc_mb_type) -{ - if (xvmc_mb_type & XVMC_MB_TYPE_INTRA) - return PIPE_MPEG12_MACROBLOCK_TYPE_INTRA; - if ((xvmc_mb_type & (XVMC_MB_TYPE_MOTION_FORWARD | XVMC_MB_TYPE_MOTION_BACKWARD)) == XVMC_MB_TYPE_MOTION_FORWARD) - return PIPE_MPEG12_MACROBLOCK_TYPE_FWD; - if ((xvmc_mb_type & (XVMC_MB_TYPE_MOTION_FORWARD | XVMC_MB_TYPE_MOTION_BACKWARD)) == XVMC_MB_TYPE_MOTION_BACKWARD) - return PIPE_MPEG12_MACROBLOCK_TYPE_BKWD; - if ((xvmc_mb_type & (XVMC_MB_TYPE_MOTION_FORWARD | XVMC_MB_TYPE_MOTION_BACKWARD)) == (XVMC_MB_TYPE_MOTION_FORWARD | XVMC_MB_TYPE_MOTION_BACKWARD)) - return PIPE_MPEG12_MACROBLOCK_TYPE_BI; - - assert(0); - - return -1; -} - -static enum pipe_mpeg12_picture_type PictureToPipe(int xvmc_pic) -{ - switch (xvmc_pic) { - case XVMC_TOP_FIELD: - return PIPE_MPEG12_PICTURE_TYPE_FIELD_TOP; - case XVMC_BOTTOM_FIELD: - return PIPE_MPEG12_PICTURE_TYPE_FIELD_BOTTOM; - case XVMC_FRAME_PICTURE: - return PIPE_MPEG12_PICTURE_TYPE_FRAME; - default: - assert(0); - } - - return -1; -} - -static enum pipe_mpeg12_motion_type MotionToPipe(int xvmc_motion_type, int xvmc_dct_type) -{ - switch (xvmc_motion_type) { - case XVMC_PREDICTION_FRAME: - return xvmc_dct_type == XVMC_DCT_TYPE_FIELD ? - PIPE_MPEG12_MOTION_TYPE_16x8 : PIPE_MPEG12_MOTION_TYPE_FRAME; - case XVMC_PREDICTION_FIELD: - return PIPE_MPEG12_MOTION_TYPE_FIELD; - case XVMC_PREDICTION_DUAL_PRIME: - return PIPE_MPEG12_MOTION_TYPE_DUALPRIME; - default: - assert(0); - } - - return -1; -} - -static bool -CreateOrResizeBackBuffer(struct pipe_video_context *vpipe, unsigned int width, unsigned int height, - struct pipe_surface **backbuffer) -{ - struct pipe_texture template; - struct pipe_texture *tex; - - assert(vpipe); - - if (*backbuffer) { - if ((*backbuffer)->width != width || (*backbuffer)->height != height) - pipe_surface_reference(backbuffer, NULL); - else - return true; - } - - memset(&template, 0, sizeof(struct pipe_texture)); - template.target = PIPE_TEXTURE_2D; - /* XXX: Needs to match the drawable's format? */ - template.format = PIPE_FORMAT_B8G8R8X8_UNORM; - template.last_level = 0; - template.width0 = width; - template.height0 = height; - template.depth0 = 1; - template.tex_usage = PIPE_TEXTURE_USAGE_SHARED; - - tex = vpipe->screen->texture_create(vpipe->screen, &template); - if (!tex) - return false; - - *backbuffer = vpipe->screen->get_tex_surface(vpipe->screen, tex, 0, 0, 0, - PIPE_BUFFER_USAGE_GPU_READ | - PIPE_BUFFER_USAGE_GPU_WRITE); - pipe_texture_reference(&tex, NULL); - - if (!*backbuffer) - return false; - - /* Clear the backbuffer in case the video doesn't cover the whole window */ - /* FIXME: Need to clear every time a frame moves and leaves dirty rects */ - vpipe->clear_surface(vpipe, 0, 0, width, height, 0, *backbuffer); - - return true; -} - -static void -MacroBlocksToPipe(const XvMCMacroBlockArray *xvmc_macroblocks, - const XvMCBlockArray *xvmc_blocks, - unsigned int first_macroblock, - unsigned int num_macroblocks, - struct pipe_mpeg12_macroblock *pipe_macroblocks) -{ - unsigned int i, j, k, l; - XvMCMacroBlock *xvmc_mb; - - assert(xvmc_macroblocks); - assert(xvmc_blocks); - assert(pipe_macroblocks); - assert(num_macroblocks); - - xvmc_mb = xvmc_macroblocks->macro_blocks + first_macroblock; - - for (i = 0; i < num_macroblocks; ++i) { - pipe_macroblocks->base.codec = PIPE_VIDEO_CODEC_MPEG12; - pipe_macroblocks->mbx = xvmc_mb->x; - pipe_macroblocks->mby = xvmc_mb->y; - pipe_macroblocks->mb_type = TypeToPipe(xvmc_mb->macroblock_type); - if (pipe_macroblocks->mb_type != PIPE_MPEG12_MACROBLOCK_TYPE_INTRA) - pipe_macroblocks->mo_type = MotionToPipe(xvmc_mb->motion_type, xvmc_mb->dct_type); - /* Get rid of Valgrind 'undefined' warnings */ - else - pipe_macroblocks->mo_type = -1; - pipe_macroblocks->dct_type = xvmc_mb->dct_type == XVMC_DCT_TYPE_FIELD ? - PIPE_MPEG12_DCT_TYPE_FIELD : PIPE_MPEG12_DCT_TYPE_FRAME; - - for (j = 0; j < 2; ++j) - for (k = 0; k < 2; ++k) - for (l = 0; l < 2; ++l) - pipe_macroblocks->pmv[j][k][l] = xvmc_mb->PMV[j][k][l]; - - pipe_macroblocks->cbp = xvmc_mb->coded_block_pattern; - pipe_macroblocks->blocks = xvmc_blocks->blocks + xvmc_mb->index * BLOCK_SIZE_SAMPLES; - - ++pipe_macroblocks; - ++xvmc_mb; - } -} - -Status XvMCCreateSurface(Display *dpy, XvMCContext *context, XvMCSurface *surface) -{ - XvMCContextPrivate *context_priv; - struct pipe_video_context *vpipe; - XvMCSurfacePrivate *surface_priv; - struct pipe_video_surface *vsfc; - - assert(dpy); - - if (!context) - return XvMCBadContext; - if (!surface) - return XvMCBadSurface; - - context_priv = context->privData; - vpipe = context_priv->vpipe; - - surface_priv = CALLOC(1, sizeof(XvMCSurfacePrivate)); - if (!surface_priv) - return BadAlloc; - - vsfc = vpipe->screen->video_surface_create(vpipe->screen, vpipe->chroma_format, - vpipe->width, vpipe->height); - if (!vsfc) { - FREE(surface_priv); - return BadAlloc; - } - - surface_priv->pipe_vsfc = vsfc; - surface_priv->context = context; - - surface->surface_id = XAllocID(dpy); - surface->context_id = context->context_id; - surface->surface_type_id = context->surface_type_id; - surface->width = context->width; - surface->height = context->height; - surface->privData = surface_priv; - - SyncHandle(); - - return Success; -} - -Status XvMCRenderSurface(Display *dpy, XvMCContext *context, unsigned int picture_structure, - XvMCSurface *target_surface, XvMCSurface *past_surface, XvMCSurface *future_surface, - unsigned int flags, unsigned int num_macroblocks, unsigned int first_macroblock, - XvMCMacroBlockArray *macroblocks, XvMCBlockArray *blocks -) -{ - struct pipe_video_context *vpipe; - struct pipe_surface *t_vsfc; - struct pipe_surface *p_vsfc; - struct pipe_surface *f_vsfc; - XvMCContextPrivate *context_priv; - XvMCSurfacePrivate *target_surface_priv; - XvMCSurfacePrivate *past_surface_priv; - XvMCSurfacePrivate *future_surface_priv; - struct pipe_mpeg12_macroblock pipe_macroblocks[num_macroblocks]; - - assert(dpy); - - if (!context || !context->privData) - return XvMCBadContext; - if (!target_surface || !target_surface->privData) - return XvMCBadSurface; - - if (picture_structure != XVMC_TOP_FIELD && - picture_structure != XVMC_BOTTOM_FIELD && - picture_structure != XVMC_FRAME_PICTURE) - return BadValue; - /* Bkwd pred equivalent to fwd (past && !future) */ - if (future_surface && !past_surface) - return BadMatch; - - assert(context->context_id == target_surface->context_id); - assert(!past_surface || context->context_id == past_surface->context_id); - assert(!future_surface || context->context_id == future_surface->context_id); - - assert(macroblocks); - assert(blocks); - - assert(macroblocks->context_id == context->context_id); - assert(blocks->context_id == context->context_id); - - assert(flags == 0 || flags == XVMC_SECOND_FIELD); - - target_surface_priv = target_surface->privData; - past_surface_priv = past_surface ? past_surface->privData : NULL; - future_surface_priv = future_surface ? future_surface->privData : NULL; - - assert(target_surface_priv->context == context); - assert(!past_surface || past_surface_priv->context == context); - assert(!future_surface || future_surface_priv->context == context); - - context_priv = context->privData; - vpipe = context_priv->vpipe; - - t_vsfc = target_surface_priv->pipe_vsfc; - p_vsfc = past_surface ? past_surface_priv->pipe_vsfc : NULL; - f_vsfc = future_surface ? future_surface_priv->pipe_vsfc : NULL; - - MacroBlocksToPipe(macroblocks, blocks, first_macroblock, - num_macroblocks, pipe_macroblocks); - - vpipe->set_decode_target(vpipe, t_vsfc); - vpipe->decode_macroblocks(vpipe, p_vsfc, f_vsfc, num_macroblocks, - &pipe_macroblocks->base, target_surface_priv->render_fence); - - return Success; -} - -Status XvMCFlushSurface(Display *dpy, XvMCSurface *surface) -{ - assert(dpy); - - if (!surface) - return XvMCBadSurface; - - return Success; -} - -Status XvMCSyncSurface(Display *dpy, XvMCSurface *surface) -{ - assert(dpy); - - if (!surface) - return XvMCBadSurface; - - return Success; -} - -Status XvMCPutSurface(Display *dpy, XvMCSurface *surface, Drawable drawable, - short srcx, short srcy, unsigned short srcw, unsigned short srch, - short destx, short desty, unsigned short destw, unsigned short desth, - int flags) -{ - Window root; - int x, y; - unsigned int width, height; - unsigned int border_width; - unsigned int depth; - struct pipe_video_context *vpipe; - XvMCSurfacePrivate *surface_priv; - XvMCContextPrivate *context_priv; - XvMCContext *context; - struct pipe_video_rect src_rect = {srcx, srcy, srcw, srch}; - struct pipe_video_rect dst_rect = {destx, desty, destw, desth}; - - assert(dpy); - - if (!surface || !surface->privData) - return XvMCBadSurface; - - if (XGetGeometry(dpy, drawable, &root, &x, &y, &width, &height, &border_width, &depth) == BadDrawable) - return BadDrawable; - - assert(flags == XVMC_TOP_FIELD || flags == XVMC_BOTTOM_FIELD || flags == XVMC_FRAME_PICTURE); - assert(srcx + srcw - 1 < surface->width); - assert(srcy + srch - 1 < surface->height); - /* - * Some apps (mplayer) hit these asserts because they call - * this function after the window has been resized by the WM - * but before they've handled the corresponding XEvent and - * know about the new dimensions. The output should be clipped - * until the app updates destw and desth. - */ - /* - assert(destx + destw - 1 < width); - assert(desty + desth - 1 < height); - */ - - surface_priv = surface->privData; - context = surface_priv->context; - context_priv = context->privData; - vpipe = context_priv->vpipe; - - if (!CreateOrResizeBackBuffer(vpipe, width, height, &context_priv->backbuffer)) - return BadAlloc; - - vpipe->render_picture(vpipe, surface_priv->pipe_vsfc, PictureToPipe(flags), &src_rect, - context_priv->backbuffer, &dst_rect, surface_priv->disp_fence); - - vl_video_bind_drawable(vpipe, drawable); - - vpipe->screen->flush_frontbuffer - ( - vpipe->screen, - context_priv->backbuffer, - vpipe->priv - ); - - return Success; -} - -Status XvMCGetSurfaceStatus(Display *dpy, XvMCSurface *surface, int *status) -{ - assert(dpy); - - if (!surface) - return XvMCBadSurface; - - assert(status); - - *status = 0; - - return Success; -} - -Status XvMCDestroySurface(Display *dpy, XvMCSurface *surface) -{ - XvMCSurfacePrivate *surface_priv; - - assert(dpy); - - if (!surface || !surface->privData) - return XvMCBadSurface; - - surface_priv = surface->privData; - pipe_video_surface_reference(&surface_priv->pipe_vsfc, NULL); - FREE(surface_priv); - surface->privData = NULL; - - return Success; -} - -Status XvMCHideSurface(Display *dpy, XvMCSurface *surface) -{ - assert(dpy); - - if (!surface || !surface->privData) - return XvMCBadSurface; - - /* No op, only for overlaid rendering */ - - return Success; -} diff --git a/src/gallium/state_trackers/xorg/xvmc/tests/.gitignore b/src/gallium/state_trackers/xorg/xvmc/tests/.gitignore deleted file mode 100644 index e1d2f9023df..00000000000 --- a/src/gallium/state_trackers/xorg/xvmc/tests/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -test_context -test_surface -test_blocks -test_rendering -xvmc_bench diff --git a/src/gallium/state_trackers/xorg/xvmc/tests/Makefile b/src/gallium/state_trackers/xorg/xvmc/tests/Makefile deleted file mode 100644 index c875dd76058..00000000000 --- a/src/gallium/state_trackers/xorg/xvmc/tests/Makefile +++ /dev/null @@ -1,28 +0,0 @@ -TOP = ../../../../../.. -include $(TOP)/configs/current - -LIBS = -lXvMCW -lXvMC -lXv -lX11 - -############################################# - -.PHONY: default clean - -default: test_context test_surface test_blocks test_rendering xvmc_bench - -test_context: test_context.o testlib.o - $(CC) $(LDFLAGS) -o $@ $^ $(LIBS) - -test_surface: test_surface.o testlib.o - $(CC) $(LDFLAGS) -o $@ $^ $(LIBS) - -test_blocks: test_blocks.o testlib.o - $(CC) $(LDFLAGS) -o $@ $^ $(LIBS) - -test_rendering: test_rendering.o testlib.o - $(CC) $(LDFLAGS) -o $@ $^ $(LIBS) - -xvmc_bench: xvmc_bench.o testlib.o - $(CC) $(LDFLAGS) -o $@ $^ $(LIBS) - -clean: - $(RM) -rf *.o test_context test_surface test_blocks test_rendering xvmc_bench diff --git a/src/gallium/state_trackers/xorg/xvmc/tests/test_blocks.c b/src/gallium/state_trackers/xorg/xvmc/tests/test_blocks.c deleted file mode 100644 index 994e3ca4d14..00000000000 --- a/src/gallium/state_trackers/xorg/xvmc/tests/test_blocks.c +++ /dev/null @@ -1,111 +0,0 @@ -/************************************************************************** - * - * Copyright 2009 Younes Manton. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#include <assert.h> -#include <error.h> -#include "testlib.h" - -int main(int argc, char **argv) -{ - const unsigned int width = 16, height = 16; - const unsigned int min_required_blocks = 1, min_required_macroblocks = 1; - const unsigned int mc_types[2] = {XVMC_MOCOMP | XVMC_MPEG_2, XVMC_IDCT | XVMC_MPEG_2}; - - Display *display; - XvPortID port_num; - int surface_type_id; - unsigned int is_overlay, intra_unsigned; - int colorkey; - XvMCContext context; - XvMCSurface surface; - XvMCBlockArray blocks = {0}; - XvMCMacroBlockArray macroblocks = {0}; - - display = XOpenDisplay(NULL); - - if (!GetPort - ( - display, - width, - height, - XVMC_CHROMA_FORMAT_420, - mc_types, - 2, - &port_num, - &surface_type_id, - &is_overlay, - &intra_unsigned - )) - { - XCloseDisplay(display); - error(1, 0, "Error, unable to find a good port.\n"); - } - - if (is_overlay) - { - Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0); - XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey); - } - - assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, &context) == Success); - assert(XvMCCreateSurface(display, &context, &surface) == Success); - - /* Test NULL context */ - assert(XvMCCreateBlocks(display, NULL, 1, &blocks) == XvMCBadContext); - /* Test 0 blocks */ - assert(XvMCCreateBlocks(display, &context, 0, &blocks) == BadValue); - /* Test valid params */ - assert(XvMCCreateBlocks(display, &context, min_required_blocks, &blocks) == Success); - /* Test context id assigned and correct */ - assert(blocks.context_id == context.context_id); - /* Test number of blocks assigned and correct */ - assert(blocks.num_blocks == min_required_blocks); - /* Test block pointer valid */ - assert(blocks.blocks != NULL); - /* Test NULL context */ - assert(XvMCCreateMacroBlocks(display, NULL, 1, ¯oblocks) == XvMCBadContext); - /* Test 0 macroblocks */ - assert(XvMCCreateMacroBlocks(display, &context, 0, ¯oblocks) == BadValue); - /* Test valid params */ - assert(XvMCCreateMacroBlocks(display, &context, min_required_macroblocks, ¯oblocks) == Success); - /* Test context id assigned and correct */ - assert(macroblocks.context_id == context.context_id); - /* Test macroblock pointer valid */ - assert(macroblocks.macro_blocks != NULL); - /* Test valid params */ - assert(XvMCDestroyMacroBlocks(display, ¯oblocks) == Success); - /* Test valid params */ - assert(XvMCDestroyBlocks(display, &blocks) == Success); - - assert(XvMCDestroySurface(display, &surface) == Success); - assert(XvMCDestroyContext(display, &context) == Success); - - XvUngrabPort(display, port_num, CurrentTime); - XCloseDisplay(display); - - return 0; -} diff --git a/src/gallium/state_trackers/xorg/xvmc/tests/test_context.c b/src/gallium/state_trackers/xorg/xvmc/tests/test_context.c deleted file mode 100644 index 3da957c9330..00000000000 --- a/src/gallium/state_trackers/xorg/xvmc/tests/test_context.c +++ /dev/null @@ -1,119 +0,0 @@ -/************************************************************************** - * - * Copyright 2009 Younes Manton. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#include <assert.h> -#include <error.h> -#include "testlib.h" - -int main(int argc, char **argv) -{ - const unsigned int width = 16, height = 16; - const unsigned int mc_types[2] = {XVMC_MOCOMP | XVMC_MPEG_2, XVMC_IDCT | XVMC_MPEG_2}; - - Display *display; - XvPortID port_num; - int surface_type_id; - unsigned int is_overlay, intra_unsigned; - int colorkey; - XvMCContext context = {0}; - - display = XOpenDisplay(NULL); - - if (!GetPort - ( - display, - width, - height, - XVMC_CHROMA_FORMAT_420, - mc_types, - 2, - &port_num, - &surface_type_id, - &is_overlay, - &intra_unsigned - )) - { - XCloseDisplay(display); - error(1, 0, "Error, unable to find a good port.\n"); - } - - if (is_overlay) - { - Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0); - XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey); - } - - /* Test NULL context */ - /* XXX: XvMCBadContext not a valid return for XvMCCreateContext in the XvMC API, but openChrome driver returns it */ - assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, NULL) == XvMCBadContext); - /* Test invalid port */ - /* XXX: Success and XvBadPort have the same value, if this call actually gets passed the validation step as of now we'll crash later */ - assert(XvMCCreateContext(display, -1, surface_type_id, width, height, XVMC_DIRECT, &context) == XvBadPort); - /* Test invalid surface */ - assert(XvMCCreateContext(display, port_num, -1, width, height, XVMC_DIRECT, &context) == BadMatch); - /* Test invalid flags */ - assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, -1, &context) == BadValue); - /* Test huge width */ - assert(XvMCCreateContext(display, port_num, surface_type_id, 16384, height, XVMC_DIRECT, &context) == BadValue); - /* Test huge height */ - assert(XvMCCreateContext(display, port_num, surface_type_id, width, 16384, XVMC_DIRECT, &context) == BadValue); - /* Test huge width & height */ - assert(XvMCCreateContext(display, port_num, surface_type_id, 16384, 16384, XVMC_DIRECT, &context) == BadValue); - /* Test valid params */ - assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, &context) == Success); - /* Test context id assigned */ - assert(context.context_id != 0); - /* Test surface type id assigned and correct */ - assert(context.surface_type_id == surface_type_id); - /* Test width & height assigned and correct */ - assert(context.width == width && context.height == height); - /* Test port assigned and correct */ - assert(context.port == port_num); - /* Test flags assigned and correct */ - assert(context.flags == XVMC_DIRECT); - /* Test NULL context */ - assert(XvMCDestroyContext(display, NULL) == XvMCBadContext); - /* Test valid params */ - assert(XvMCDestroyContext(display, &context) == Success); - /* Test awkward but valid width */ - assert(XvMCCreateContext(display, port_num, surface_type_id, width + 1, height, XVMC_DIRECT, &context) == Success); - assert(context.width >= width + 1); - assert(XvMCDestroyContext(display, &context) == Success); - /* Test awkward but valid height */ - assert(XvMCCreateContext(display, port_num, surface_type_id, width, height + 1, XVMC_DIRECT, &context) == Success); - assert(context.height >= height + 1); - assert(XvMCDestroyContext(display, &context) == Success); - /* Test awkward but valid width & height */ - assert(XvMCCreateContext(display, port_num, surface_type_id, width + 1, height + 1, XVMC_DIRECT, &context) == Success); - assert(context.width >= width + 1 && context.height >= height + 1); - assert(XvMCDestroyContext(display, &context) == Success); - - XvUngrabPort(display, port_num, CurrentTime); - XCloseDisplay(display); - - return 0; -} diff --git a/src/gallium/state_trackers/xorg/xvmc/tests/test_rendering.c b/src/gallium/state_trackers/xorg/xvmc/tests/test_rendering.c deleted file mode 100644 index 6058783a798..00000000000 --- a/src/gallium/state_trackers/xorg/xvmc/tests/test_rendering.c +++ /dev/null @@ -1,317 +0,0 @@ -/************************************************************************** - * - * Copyright 2009 Younes Manton. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#include <assert.h> -#include <stdio.h> -#include <string.h> -#include <error.h> -#include "testlib.h" - -#define BLOCK_WIDTH 8 -#define BLOCK_HEIGHT 8 -#define BLOCK_SIZE (BLOCK_WIDTH * BLOCK_HEIGHT) -#define MACROBLOCK_WIDTH 16 -#define MACROBLOCK_HEIGHT 16 -#define MACROBLOCK_WIDTH_IN_BLOCKS (MACROBLOCK_WIDTH / BLOCK_WIDTH) -#define MACROBLOCK_HEIGHT_IN_BLOCKS (MACROBLOCK_HEIGHT / BLOCK_HEIGHT) -#define BLOCKS_PER_MACROBLOCK 6 - -#define INPUT_WIDTH 16 -#define INPUT_HEIGHT 16 -#define INPUT_WIDTH_IN_MACROBLOCKS (INPUT_WIDTH / MACROBLOCK_WIDTH) -#define INPUT_HEIGHT_IN_MACROBLOCKS (INPUT_HEIGHT / MACROBLOCK_HEIGHT) -#define NUM_MACROBLOCKS (INPUT_WIDTH_IN_MACROBLOCKS * INPUT_HEIGHT_IN_MACROBLOCKS) - -#define DEFAULT_OUTPUT_WIDTH INPUT_WIDTH -#define DEFAULT_OUTPUT_HEIGHT INPUT_HEIGHT -#define DEFAULT_ACCEPTABLE_ERR 0.01 - -void ParseArgs(int argc, char **argv, unsigned int *output_width, unsigned int *output_height, double *acceptable_error, int *prompt); -void Gradient(short *block, unsigned int start, unsigned int stop, int horizontal); - -void ParseArgs(int argc, char **argv, unsigned int *output_width, unsigned int *output_height, double *acceptable_error, int *prompt) -{ - int fail = 0; - int i; - - *output_width = DEFAULT_OUTPUT_WIDTH; - *output_height = DEFAULT_OUTPUT_WIDTH; - *acceptable_error = DEFAULT_ACCEPTABLE_ERR; - *prompt = 1; - - for (i = 1; i < argc && !fail; ++i) - { - if (!strcmp(argv[i], "-w")) - { - if (sscanf(argv[++i], "%u", output_width) != 1) - fail = 1; - } - else if (!strcmp(argv[i], "-h")) - { - if (sscanf(argv[++i], "%u", output_height) != 1) - fail = 1; - } - else if (!strcmp(argv[i], "-e")) - { - if (sscanf(argv[++i], "%lf", acceptable_error) != 1) - fail = 1; - } - else if (strcmp(argv[i], "-n")) - *prompt = 0; - else - fail = 1; - } - - if (fail) - error - ( - 1, 0, - "Bad argument.\n" - "\n" - "Usage: %s [options]\n" - "\t-w <width>\tOutput width\n" - "\t-h <height>\tOutput height\n" - "\t-e <error>\tAcceptable margin of error per pixel, from 0 to 1\n" - "\t-n\tDon't prompt for quit\n", - argv[0] - ); -} - -void Gradient(short *block, unsigned int start, unsigned int stop, int horizontal) -{ - unsigned int x, y; - unsigned int range = stop - start; - - if (horizontal) - { - for (y = 0; y < BLOCK_HEIGHT; ++y) - for (x = 0; x < BLOCK_WIDTH; ++x) - block[y * BLOCK_WIDTH + x] = (short)(start + range * (x / (float)(BLOCK_WIDTH - 1))); - } - else - { - for (y = 0; y < BLOCK_HEIGHT; ++y) - for (x = 0; x < BLOCK_WIDTH; ++x) - block[y * BLOCK_WIDTH + x] = (short)(start + range * (y / (float)(BLOCK_HEIGHT - 1))); - } -} - -int main(int argc, char **argv) -{ - unsigned int output_width; - unsigned int output_height; - double acceptable_error; - int prompt; - Display *display; - Window root, window; - const unsigned int mc_types[2] = {XVMC_MOCOMP | XVMC_MPEG_2, XVMC_IDCT | XVMC_MPEG_2}; - XvPortID port_num; - int surface_type_id; - unsigned int is_overlay, intra_unsigned; - int colorkey; - XvMCContext context; - XvMCSurface surface; - XvMCBlockArray block_array; - XvMCMacroBlockArray mb_array; - int mbx, mby, bx, by; - XvMCMacroBlock *mb; - short *blocks; - int quit = 0; - - ParseArgs(argc, argv, &output_width, &output_height, &acceptable_error, &prompt); - - display = XOpenDisplay(NULL); - - if (!GetPort - ( - display, - INPUT_WIDTH, - INPUT_HEIGHT, - XVMC_CHROMA_FORMAT_420, - mc_types, - 2, - &port_num, - &surface_type_id, - &is_overlay, - &intra_unsigned - )) - { - XCloseDisplay(display); - error(1, 0, "Error, unable to find a good port.\n"); - } - - if (is_overlay) - { - Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0); - XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey); - } - - root = XDefaultRootWindow(display); - window = XCreateSimpleWindow(display, root, 0, 0, output_width, output_height, 0, 0, colorkey); - - assert(XvMCCreateContext(display, port_num, surface_type_id, INPUT_WIDTH, INPUT_HEIGHT, XVMC_DIRECT, &context) == Success); - assert(XvMCCreateSurface(display, &context, &surface) == Success); - assert(XvMCCreateBlocks(display, &context, NUM_MACROBLOCKS * BLOCKS_PER_MACROBLOCK, &block_array) == Success); - assert(XvMCCreateMacroBlocks(display, &context, NUM_MACROBLOCKS, &mb_array) == Success); - - mb = mb_array.macro_blocks; - blocks = block_array.blocks; - - for (mby = 0; mby < INPUT_HEIGHT_IN_MACROBLOCKS; ++mby) - for (mbx = 0; mbx < INPUT_WIDTH_IN_MACROBLOCKS; ++mbx) - { - mb->x = mbx; - mb->y = mby; - mb->macroblock_type = XVMC_MB_TYPE_INTRA; - /*mb->motion_type = ;*/ - /*mb->motion_vertical_field_select = ;*/ - mb->dct_type = XVMC_DCT_TYPE_FRAME; - /*mb->PMV[0][0][0] = ; - mb->PMV[0][0][1] = ; - mb->PMV[0][1][0] = ; - mb->PMV[0][1][1] = ; - mb->PMV[1][0][0] = ; - mb->PMV[1][0][1] = ; - mb->PMV[1][1][0] = ; - mb->PMV[1][1][1] = ;*/ - mb->index = (mby * INPUT_WIDTH_IN_MACROBLOCKS + mbx) * BLOCKS_PER_MACROBLOCK; - mb->coded_block_pattern = 0x3F; - - mb++; - - for (by = 0; by < MACROBLOCK_HEIGHT_IN_BLOCKS; ++by) - for (bx = 0; bx < MACROBLOCK_WIDTH_IN_BLOCKS; ++bx) - { - const int start = 16, stop = 235, range = stop - start; - - Gradient - ( - blocks, - (short)(start + range * ((mbx * MACROBLOCK_WIDTH + bx * BLOCK_WIDTH) / (float)(INPUT_WIDTH - 1))), - (short)(start + range * ((mbx * MACROBLOCK_WIDTH + bx * BLOCK_WIDTH + BLOCK_WIDTH - 1) / (float)(INPUT_WIDTH - 1))), - 1 - ); - - blocks += BLOCK_SIZE; - } - - for (by = 0; by < MACROBLOCK_HEIGHT_IN_BLOCKS / 2; ++by) - for (bx = 0; bx < MACROBLOCK_WIDTH_IN_BLOCKS / 2; ++bx) - { - const int start = 16, stop = 240, range = stop - start; - - Gradient - ( - blocks, - (short)(start + range * ((mbx * MACROBLOCK_WIDTH + bx * BLOCK_WIDTH) / (float)(INPUT_WIDTH - 1))), - (short)(start + range * ((mbx * MACROBLOCK_WIDTH + bx * BLOCK_WIDTH + BLOCK_WIDTH - 1) / (float)(INPUT_WIDTH - 1))), - 1 - ); - - blocks += BLOCK_SIZE; - - Gradient - ( - blocks, - (short)(start + range * ((mbx * MACROBLOCK_WIDTH + bx * BLOCK_WIDTH) / (float)(INPUT_WIDTH - 1))), - (short)(start + range * ((mbx * MACROBLOCK_WIDTH + bx * BLOCK_WIDTH + BLOCK_WIDTH - 1) / (float)(INPUT_WIDTH - 1))), - 1 - ); - - blocks += BLOCK_SIZE; - } - } - - XSelectInput(display, window, ExposureMask | KeyPressMask); - XMapWindow(display, window); - XSync(display, 0); - - /* Test NULL context */ - assert(XvMCRenderSurface(display, NULL, XVMC_FRAME_PICTURE, &surface, NULL, NULL, 0, NUM_MACROBLOCKS, 0, &mb_array, &block_array) == XvMCBadContext); - /* Test NULL surface */ - assert(XvMCRenderSurface(display, &context, XVMC_FRAME_PICTURE, NULL, NULL, NULL, 0, NUM_MACROBLOCKS, 0, &mb_array, &block_array) == XvMCBadSurface); - /* Test bad picture structure */ - assert(XvMCRenderSurface(display, &context, 0, &surface, NULL, NULL, 0, NUM_MACROBLOCKS, 0, &mb_array, &block_array) == BadValue); - /* Test valid params */ - assert(XvMCRenderSurface(display, &context, XVMC_FRAME_PICTURE, &surface, NULL, NULL, 0, NUM_MACROBLOCKS, 0, &mb_array, &block_array) == Success); - - /* Test NULL surface */ - assert(XvMCPutSurface(display, NULL, window, 0, 0, INPUT_WIDTH, INPUT_HEIGHT, 0, 0, output_width, output_height, XVMC_FRAME_PICTURE) == XvMCBadSurface); - /* Test bad window */ - /* XXX: X halts with a bad drawable for some reason, doesn't return BadDrawable as expected */ - /*assert(XvMCPutSurface(display, &surface, 0, 0, 0, width, height, 0, 0, width, height, XVMC_FRAME_PICTURE) == BadDrawable);*/ - - if (prompt) - { - puts("Press any button to quit..."); - - while (!quit) - { - if (XPending(display) > 0) - { - XEvent event; - - XNextEvent(display, &event); - - switch (event.type) - { - case Expose: - { - /* Test valid params */ - assert - ( - XvMCPutSurface - ( - display, &surface, window, - 0, 0, INPUT_WIDTH, INPUT_HEIGHT, - 0, 0, output_width, output_height, - XVMC_FRAME_PICTURE - ) == Success - ); - break; - } - case KeyPress: - { - quit = 1; - break; - } - } - } - } - } - - assert(XvMCDestroyBlocks(display, &block_array) == Success); - assert(XvMCDestroyMacroBlocks(display, &mb_array) == Success); - assert(XvMCDestroySurface(display, &surface) == Success); - assert(XvMCDestroyContext(display, &context) == Success); - - XvUngrabPort(display, port_num, CurrentTime); - XDestroyWindow(display, window); - XCloseDisplay(display); - - return 0; -} diff --git a/src/gallium/state_trackers/xorg/xvmc/tests/test_surface.c b/src/gallium/state_trackers/xorg/xvmc/tests/test_surface.c deleted file mode 100644 index b65eb265c0a..00000000000 --- a/src/gallium/state_trackers/xorg/xvmc/tests/test_surface.c +++ /dev/null @@ -1,98 +0,0 @@ -/************************************************************************** - * - * Copyright 2009 Younes Manton. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#include <assert.h> -#include <error.h> -#include "testlib.h" - -int main(int argc, char **argv) -{ - const unsigned int width = 16, height = 16; - const unsigned int mc_types[2] = {XVMC_MOCOMP | XVMC_MPEG_2, XVMC_IDCT | XVMC_MPEG_2}; - - Display *display; - XvPortID port_num; - int surface_type_id; - unsigned int is_overlay, intra_unsigned; - int colorkey; - XvMCContext context; - XvMCSurface surface = {0}; - - display = XOpenDisplay(NULL); - - if (!GetPort - ( - display, - width, - height, - XVMC_CHROMA_FORMAT_420, - mc_types, - 2, - &port_num, - &surface_type_id, - &is_overlay, - &intra_unsigned - )) - { - XCloseDisplay(display); - error(1, 0, "Error, unable to find a good port.\n"); - } - - if (is_overlay) - { - Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0); - XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey); - } - - assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, &context) == Success); - - /* Test NULL context */ - assert(XvMCCreateSurface(display, NULL, &surface) == XvMCBadContext); - /* Test NULL surface */ - assert(XvMCCreateSurface(display, &context, NULL) == XvMCBadSurface); - /* Test valid params */ - assert(XvMCCreateSurface(display, &context, &surface) == Success); - /* Test surface id assigned */ - assert(surface.surface_id != 0); - /* Test context id assigned and correct */ - assert(surface.context_id == context.context_id); - /* Test surface type id assigned and correct */ - assert(surface.surface_type_id == surface_type_id); - /* Test width & height assigned and correct */ - assert(surface.width == width && surface.height == height); - /* Test valid params */ - assert(XvMCDestroySurface(display, &surface) == Success); - /* Test NULL surface */ - assert(XvMCDestroySurface(display, NULL) == XvMCBadSurface); - - assert(XvMCDestroyContext(display, &context) == Success); - - XvUngrabPort(display, port_num, CurrentTime); - XCloseDisplay(display); - - return 0; -} diff --git a/src/gallium/state_trackers/xorg/xvmc/tests/testlib.c b/src/gallium/state_trackers/xorg/xvmc/tests/testlib.c deleted file mode 100644 index 142c09bb590..00000000000 --- a/src/gallium/state_trackers/xorg/xvmc/tests/testlib.c +++ /dev/null @@ -1,146 +0,0 @@ -/************************************************************************** - * - * Copyright 2009 Younes Manton. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#include "testlib.h" -#include <stdio.h> - -/* -void test(int pred, const char *pred_string, const char *doc_string, const char *file, unsigned int line) -{ - fputs(doc_string, stderr); - if (!pred) - fprintf(stderr, " FAIL!\n\t\"%s\" at %s:%u\n", pred_string, file, line); - else - fputs(" PASS!\n", stderr); -} -*/ - -int GetPort -( - Display *display, - unsigned int width, - unsigned int height, - unsigned int chroma_format, - const unsigned int *mc_types, - unsigned int num_mc_types, - XvPortID *port_id, - int *surface_type_id, - unsigned int *is_overlay, - unsigned int *intra_unsigned -) -{ - unsigned int found_port = 0; - XvAdaptorInfo *adaptor_info; - unsigned int num_adaptors; - int num_types; - int ev_base, err_base; - unsigned int i, j, k, l; - - if (!XvMCQueryExtension(display, &ev_base, &err_base)) - return 0; - if (XvQueryAdaptors(display, XDefaultRootWindow(display), &num_adaptors, &adaptor_info) != Success) - return 0; - - for (i = 0; i < num_adaptors && !found_port; ++i) - { - if (adaptor_info[i].type & XvImageMask) - { - XvMCSurfaceInfo *surface_info = XvMCListSurfaceTypes(display, adaptor_info[i].base_id, &num_types); - - if (surface_info) - { - for (j = 0; j < num_types && !found_port; ++j) - { - if - ( - surface_info[j].chroma_format == chroma_format && - surface_info[j].max_width >= width && - surface_info[j].max_height >= height - ) - { - for (k = 0; k < num_mc_types && !found_port; ++k) - { - if (surface_info[j].mc_type == mc_types[k]) - { - for (l = 0; l < adaptor_info[i].num_ports && !found_port; ++l) - { - if (XvGrabPort(display, adaptor_info[i].base_id + l, CurrentTime) == Success) - { - *port_id = adaptor_info[i].base_id + l; - *surface_type_id = surface_info[j].surface_type_id; - *is_overlay = surface_info[j].flags & XVMC_OVERLAID_SURFACE; - *intra_unsigned = surface_info[j].flags & XVMC_INTRA_UNSIGNED; - found_port = 1; - } - } - } - } - } - } - - XFree(surface_info); - } - } - } - - XvFreeAdaptorInfo(adaptor_info); - - return found_port; -} - -unsigned int align(unsigned int value, unsigned int alignment) -{ - return (value + alignment - 1) & ~(alignment - 1); -} - -/* From the glibc manual */ -int timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y) -{ - /* Perform the carry for the later subtraction by updating y. */ - if (x->tv_usec < y->tv_usec) - { - int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1; - y->tv_usec -= 1000000 * nsec; - y->tv_sec += nsec; - } - if (x->tv_usec - y->tv_usec > 1000000) - { - int nsec = (x->tv_usec - y->tv_usec) / 1000000; - y->tv_usec += 1000000 * nsec; - y->tv_sec -= nsec; - } - - /* - * Compute the time remaining to wait. - * tv_usec is certainly positive. - */ - result->tv_sec = x->tv_sec - y->tv_sec; - result->tv_usec = x->tv_usec - y->tv_usec; - - /* Return 1 if result is negative. */ - return x->tv_sec < y->tv_sec; -} diff --git a/src/gallium/state_trackers/xorg/xvmc/tests/testlib.h b/src/gallium/state_trackers/xorg/xvmc/tests/testlib.h deleted file mode 100644 index 0438e52928b..00000000000 --- a/src/gallium/state_trackers/xorg/xvmc/tests/testlib.h +++ /dev/null @@ -1,69 +0,0 @@ -/************************************************************************** - * - * Copyright 2009 Younes Manton. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#ifndef testlib_h -#define testlib_h - -/* -#define TEST(pred, doc) test(pred, #pred, doc, __FILE__, __LINE__) - -void test(int pred, const char *pred_string, const char *doc_string, const char *file, unsigned int line); -*/ - -#include <sys/time.h> -#include <X11/Xlib.h> -#include <X11/extensions/XvMClib.h> - -/* - * display: IN A valid X display - * width, height: IN Surface size that the port must display - * chroma_format: IN Chroma format that the port must display - * mc_types, num_mc_types: IN List of MC types that the port must support, first port that matches the first mc_type will be returned - * port_id: OUT Your port's ID - * surface_type_id: OUT Your port's surface ID - * is_overlay: OUT If 1, port uses overlay surfaces, you need to set a colorkey - * intra_unsigned: OUT If 1, port uses unsigned values for intra-coded blocks - */ -int GetPort -( - Display *display, - unsigned int width, - unsigned int height, - unsigned int chroma_format, - const unsigned int *mc_types, - unsigned int num_mc_types, - XvPortID *port_id, - int *surface_type_id, - unsigned int *is_overlay, - unsigned int *intra_unsigned -); - -unsigned int align(unsigned int value, unsigned int alignment); - -int timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y); - -#endif diff --git a/src/gallium/state_trackers/xorg/xvmc/tests/xvmc_bench.c b/src/gallium/state_trackers/xorg/xvmc/tests/xvmc_bench.c deleted file mode 100644 index bf94d856234..00000000000 --- a/src/gallium/state_trackers/xorg/xvmc/tests/xvmc_bench.c +++ /dev/null @@ -1,300 +0,0 @@ -/************************************************************************** - * - * Copyright 2009 Younes Manton. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#include <assert.h> -#include <stdio.h> -#include <string.h> -#include <error.h> -#include <sys/time.h> -#include "testlib.h" - -#define MACROBLOCK_WIDTH 16 -#define MACROBLOCK_HEIGHT 16 -#define BLOCKS_PER_MACROBLOCK 6 - -#define DEFAULT_INPUT_WIDTH 720 -#define DEFAULT_INPUT_HEIGHT 480 -#define DEFAULT_REPS 100 - -#define PIPELINE_STEP_MC 1 -#define PIPELINE_STEP_CSC 2 -#define PIPELINE_STEP_SWAP 4 - -#define MB_TYPE_I 1 -#define MB_TYPE_P 2 -#define MB_TYPE_B 4 - -struct Config -{ - unsigned int input_width; - unsigned int input_height; - unsigned int output_width; - unsigned int output_height; - unsigned int pipeline; - unsigned int mb_types; - unsigned int reps; -}; - -void ParseArgs(int argc, char **argv, struct Config *config); - -void ParseArgs(int argc, char **argv, struct Config *config) -{ - int fail = 0; - int i; - - config->input_width = DEFAULT_INPUT_WIDTH; - config->input_height = DEFAULT_INPUT_HEIGHT; - config->output_width = 0; - config->output_height = 0; - config->pipeline = 0; - config->mb_types = 0; - config->reps = DEFAULT_REPS; - - for (i = 1; i < argc && !fail; ++i) - { - if (!strcmp(argv[i], "-iw")) - { - if (sscanf(argv[++i], "%u", &config->input_width) != 1) - fail = 1; - } - else if (!strcmp(argv[i], "-ih")) - { - if (sscanf(argv[++i], "%u", &config->input_height) != 1) - fail = 1; - } - else if (!strcmp(argv[i], "-ow")) - { - if (sscanf(argv[++i], "%u", &config->output_width) != 1) - fail = 1; - } - else if (!strcmp(argv[i], "-oh")) - { - if (sscanf(argv[++i], "%u", &config->output_height) != 1) - fail = 1; - } - else if (!strcmp(argv[i], "-p")) - { - char *token = strtok(argv[++i], ","); - - while (token && !fail) - { - if (!strcmp(token, "mc")) - config->pipeline |= PIPELINE_STEP_MC; - else if (!strcmp(token, "csc")) - config->pipeline |= PIPELINE_STEP_CSC; - else if (!strcmp(token, "swp")) - config->pipeline |= PIPELINE_STEP_SWAP; - else - fail = 1; - - if (!fail) - token = strtok(NULL, ","); - } - } - else if (!strcmp(argv[i], "-mb")) - { - char *token = strtok(argv[++i], ","); - - while (token && !fail) - { - if (strcmp(token, "i")) - config->mb_types |= MB_TYPE_I; - else if (strcmp(token, "p")) - config->mb_types |= MB_TYPE_P; - else if (strcmp(token, "b")) - config->mb_types |= MB_TYPE_B; - else - fail = 1; - - if (!fail) - token = strtok(NULL, ","); - } - } - else if (!strcmp(argv[i], "-r")) - { - if (sscanf(argv[++i], "%u", &config->reps) != 1) - fail = 1; - } - else - fail = 1; - } - - if (fail) - error - ( - 1, 0, - "Bad argument.\n" - "\n" - "Usage: %s [options]\n" - "\t-iw <width>\tInput width\n" - "\t-ih <height>\tInput height\n" - "\t-ow <width>\tOutput width\n" - "\t-oh <height>\tOutput height\n" - "\t-p <pipeline>\tPipeline to test\n" - "\t-mb <mb type>\tMacroBlock types to use\n" - "\t-r <reps>\tRepetitions\n\n" - "\tPipeline steps: mc,csc,swap\n" - "\tMB types: i,p,b\n", - argv[0] - ); - - if (config->output_width == 0) - config->output_width = config->input_width; - if (config->output_height == 0) - config->output_height = config->input_height; - if (!config->pipeline) - config->pipeline = PIPELINE_STEP_MC | PIPELINE_STEP_CSC | PIPELINE_STEP_SWAP; - if (!config->mb_types) - config->mb_types = MB_TYPE_I | MB_TYPE_P | MB_TYPE_B; -} - -int main(int argc, char **argv) -{ - struct Config config; - Display *display; - Window root, window; - const unsigned int mc_types[2] = {XVMC_MOCOMP | XVMC_MPEG_2, XVMC_IDCT | XVMC_MPEG_2}; - XvPortID port_num; - int surface_type_id; - unsigned int is_overlay, intra_unsigned; - int colorkey; - XvMCContext context; - XvMCSurface surface; - XvMCBlockArray block_array; - XvMCMacroBlockArray mb_array; - unsigned int mbw, mbh; - unsigned int mbx, mby; - unsigned int reps; - struct timeval start, stop, diff; - double diff_secs; - - ParseArgs(argc, argv, &config); - - mbw = align(config.input_width, MACROBLOCK_WIDTH) / MACROBLOCK_WIDTH; - mbh = align(config.input_height, MACROBLOCK_HEIGHT) / MACROBLOCK_HEIGHT; - - display = XOpenDisplay(NULL); - - if (!GetPort - ( - display, - config.input_width, - config.input_height, - XVMC_CHROMA_FORMAT_420, - mc_types, - 2, - &port_num, - &surface_type_id, - &is_overlay, - &intra_unsigned - )) - { - XCloseDisplay(display); - error(1, 0, "Error, unable to find a good port.\n"); - } - - if (is_overlay) - { - Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0); - XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey); - } - - root = XDefaultRootWindow(display); - window = XCreateSimpleWindow(display, root, 0, 0, config.output_width, config.output_height, 0, 0, colorkey); - - assert(XvMCCreateContext(display, port_num, surface_type_id, config.input_width, config.input_height, XVMC_DIRECT, &context) == Success); - assert(XvMCCreateSurface(display, &context, &surface) == Success); - assert(XvMCCreateBlocks(display, &context, mbw * mbh * BLOCKS_PER_MACROBLOCK, &block_array) == Success); - assert(XvMCCreateMacroBlocks(display, &context, mbw * mbh, &mb_array) == Success); - - for (mby = 0; mby < mbh; ++mby) - for (mbx = 0; mbx < mbw; ++mbx) - { - mb_array.macro_blocks[mby * mbw + mbx].x = mbx; - mb_array.macro_blocks[mby * mbw + mbx].y = mby; - mb_array.macro_blocks[mby * mbw + mbx].macroblock_type = XVMC_MB_TYPE_INTRA; - /*mb->motion_type = ;*/ - /*mb->motion_vertical_field_select = ;*/ - mb_array.macro_blocks[mby * mbw + mbx].dct_type = XVMC_DCT_TYPE_FRAME; - /*mb->PMV[0][0][0] = ; - mb->PMV[0][0][1] = ; - mb->PMV[0][1][0] = ; - mb->PMV[0][1][1] = ; - mb->PMV[1][0][0] = ; - mb->PMV[1][0][1] = ; - mb->PMV[1][1][0] = ; - mb->PMV[1][1][1] = ;*/ - mb_array.macro_blocks[mby * mbw + mbx].index = (mby * mbw + mbx) * BLOCKS_PER_MACROBLOCK; - mb_array.macro_blocks[mby * mbw + mbx].coded_block_pattern = 0x3F; - } - - XSelectInput(display, window, ExposureMask | KeyPressMask); - XMapWindow(display, window); - XSync(display, 0); - - gettimeofday(&start, NULL); - - for (reps = 0; reps < config.reps; ++reps) - { - if (config.pipeline & PIPELINE_STEP_MC) - { - assert(XvMCRenderSurface(display, &context, XVMC_FRAME_PICTURE, &surface, NULL, NULL, 0, mbw * mbh, 0, &mb_array, &block_array) == Success); - assert(XvMCFlushSurface(display, &surface) == Success); - } - if (config.pipeline & PIPELINE_STEP_CSC) - assert(XvMCPutSurface(display, &surface, window, 0, 0, config.input_width, config.input_height, 0, 0, config.output_width, config.output_height, XVMC_FRAME_PICTURE) == Success); - } - - gettimeofday(&stop, NULL); - - timeval_subtract(&diff, &stop, &start); - diff_secs = (double)diff.tv_sec + (double)diff.tv_usec / 1000000.0; - - printf("XvMC Benchmark\n"); - printf("Input: %u,%u\nOutput: %u,%u\n", config.input_width, config.input_height, config.output_width, config.output_height); - printf("Pipeline: "); - if (config.pipeline & PIPELINE_STEP_MC) - printf("|mc|"); - if (config.pipeline & PIPELINE_STEP_CSC) - printf("|csc|"); - if (config.pipeline & PIPELINE_STEP_SWAP) - printf("|swap|"); - printf("\n"); - printf("Reps: %u\n", config.reps); - printf("Total time: %.2lf (%.2lf reps / sec)\n", diff_secs, config.reps / diff_secs); - - assert(XvMCDestroyBlocks(display, &block_array) == Success); - assert(XvMCDestroyMacroBlocks(display, &mb_array) == Success); - assert(XvMCDestroySurface(display, &surface) == Success); - assert(XvMCDestroyContext(display, &context) == Success); - - XvUngrabPort(display, port_num, CurrentTime); - XDestroyWindow(display, window); - XCloseDisplay(display); - - return 0; -} diff --git a/src/gallium/state_trackers/xorg/xvmc/xvmc_private.h b/src/gallium/state_trackers/xorg/xvmc/xvmc_private.h deleted file mode 100644 index 42337631ca1..00000000000 --- a/src/gallium/state_trackers/xorg/xvmc/xvmc_private.h +++ /dev/null @@ -1,58 +0,0 @@ -/************************************************************************** - * - * Copyright 2009 Younes Manton. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#ifndef xvmc_private_h -#define xvmc_private_h - -#include <X11/Xlib.h> -#include <X11/extensions/XvMClib.h> - -#define BLOCK_SIZE_SAMPLES 64 -#define BLOCK_SIZE_BYTES (BLOCK_SIZE_SAMPLES * 2) - -struct pipe_video_context; -struct pipe_surface; -struct pipe_fence_handle; - -typedef struct -{ - struct pipe_video_context *vpipe; - struct pipe_surface *backbuffer; -} XvMCContextPrivate; - -typedef struct -{ - struct pipe_video_surface *pipe_vsfc; - struct pipe_fence_handle *render_fence; - struct pipe_fence_handle *disp_fence; - - /* Some XvMC functions take a surface but not a context, - so we keep track of which context each surface belongs to. */ - XvMCContext *context; -} XvMCSurfacePrivate; - -#endif /* xvmc_private_h */ |