tr_winsys.c

Go to the documentation of this file.
00001 /**************************************************************************
00002  *
00003  * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
00004  * All Rights Reserved.
00005  *
00006  * Permission is hereby granted, free of charge, to any person obtaining a
00007  * copy of this software and associated documentation files (the
00008  * "Software"), to deal in the Software without restriction, including
00009  * without limitation the rights to use, copy, modify, merge, publish,
00010  * distribute, sub license, and/or sell copies of the Software, and to
00011  * permit persons to whom the Software is furnished to do so, subject to
00012  * the following conditions:
00013  *
00014  * The above copyright notice and this permission notice (including the
00015  * next paragraph) shall be included in all copies or substantial portions
00016  * of the Software.
00017  *
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
00021  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
00022  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00023  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00024  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00025  *
00026  **************************************************************************/
00027 
00028 #include "util/u_memory.h"
00029 #include "util/u_hash_table.h"
00030 
00031 #include "tr_dump.h"
00032 #include "tr_state.h"
00033 #include "tr_screen.h"
00034 #include "tr_texture.h"
00035 #include "tr_winsys.h"
00036 
00037 
00038 static unsigned trace_buffer_hash(void *buffer)
00039 {
00040    return (unsigned)(uintptr_t)buffer;
00041 }
00042 
00043 
00044 static int trace_buffer_compare(void *buffer1, void *buffer2)
00045 {
00046    return (char *)buffer2 - (char *)buffer1;
00047 }
00048 
00049                   
00050 static const char *
00051 trace_winsys_get_name(struct pipe_winsys *_winsys)
00052 {
00053    struct trace_winsys *tr_ws = trace_winsys(_winsys);
00054    struct pipe_winsys *winsys = tr_ws->winsys;
00055    const char *result;
00056    
00057    trace_dump_call_begin("pipe_winsys", "get_name");
00058    
00059    trace_dump_arg(ptr, winsys);
00060 
00061    result = winsys->get_name(winsys);
00062    
00063    trace_dump_ret(string, result);
00064    
00065    trace_dump_call_end();
00066    
00067    return result;
00068 }
00069 
00070 
00071 static void 
00072 trace_winsys_flush_frontbuffer(struct pipe_winsys *_winsys,
00073                                struct pipe_surface *surface,
00074                                void *context_private)
00075 {
00076    struct trace_winsys *tr_ws = trace_winsys(_winsys);
00077    struct pipe_winsys *winsys = tr_ws->winsys;
00078 
00079    assert(surface);
00080    if(surface->texture) {
00081       struct trace_screen *tr_scr = trace_screen(surface->texture->screen);
00082       struct trace_texture *tr_tex = trace_texture(tr_scr, surface->texture);
00083       struct trace_surface *tr_surf = trace_surface(tr_tex, surface);
00084       surface = tr_surf->surface;
00085    }
00086    
00087    trace_dump_call_begin("pipe_winsys", "flush_frontbuffer");
00088    
00089    trace_dump_arg(ptr, winsys);
00090    trace_dump_arg(ptr, surface);
00091    /* XXX: hide, as there is nothing we can do with this
00092    trace_dump_arg(ptr, context_private);
00093    */
00094 
00095    winsys->flush_frontbuffer(winsys, surface, context_private);
00096    
00097    trace_dump_call_end();
00098 }
00099 
00100 
00101 static struct pipe_surface *
00102 trace_winsys_surface_alloc(struct pipe_winsys *_winsys)
00103 {
00104    struct trace_winsys *tr_ws = trace_winsys(_winsys);
00105    struct pipe_winsys *winsys = tr_ws->winsys;
00106    struct pipe_surface *result;
00107    
00108    trace_dump_call_begin("pipe_winsys", "surface_alloc");
00109    
00110    trace_dump_arg(ptr, winsys);
00111 
00112    result = winsys->surface_alloc(winsys);
00113    
00114    trace_dump_ret(ptr, result);
00115    
00116    trace_dump_call_end();
00117    
00118    assert(!result || !result->texture);
00119 
00120    return result;
00121 }
00122 
00123 
00124 static int
00125 trace_winsys_surface_alloc_storage(struct pipe_winsys *_winsys,
00126                                    struct pipe_surface *surface,
00127                                    unsigned width, unsigned height,
00128                                    enum pipe_format format,
00129                                    unsigned flags,
00130                                    unsigned tex_usage)
00131 {
00132    struct trace_winsys *tr_ws = trace_winsys(_winsys);
00133    struct pipe_winsys *winsys = tr_ws->winsys;
00134    int result;
00135    
00136    assert(surface && !surface->texture);
00137 
00138    trace_dump_call_begin("pipe_winsys", "surface_alloc_storage");
00139    
00140    trace_dump_arg(ptr, winsys);
00141    trace_dump_arg(ptr, surface);
00142    trace_dump_arg(uint, width);
00143    trace_dump_arg(uint, height);
00144    trace_dump_arg(format, format);
00145    trace_dump_arg(uint, flags);
00146    trace_dump_arg(uint, tex_usage);
00147 
00148    result = winsys->surface_alloc_storage(winsys,
00149                                           surface,
00150                                           width, height,
00151                                           format,
00152                                           flags,
00153                                           tex_usage);
00154    
00155    trace_dump_ret(int, result);
00156    
00157    trace_dump_call_end();
00158    
00159    return result;
00160 }
00161 
00162 
00163 static void
00164 trace_winsys_surface_release(struct pipe_winsys *_winsys, 
00165                              struct pipe_surface **psurface)
00166 {
00167    struct trace_winsys *tr_ws = trace_winsys(_winsys);
00168    struct pipe_winsys *winsys = tr_ws->winsys;
00169    struct pipe_surface *surface = *psurface;
00170    
00171    assert(psurface && *psurface && !(*psurface)->texture);
00172    
00173    trace_dump_call_begin("pipe_winsys", "surface_release");
00174    
00175    trace_dump_arg(ptr, winsys);
00176    trace_dump_arg(ptr, surface);
00177 
00178    winsys->surface_release(winsys, psurface);
00179    
00180    trace_dump_call_end();
00181 }
00182 
00183 
00184 static struct pipe_buffer *
00185 trace_winsys_buffer_create(struct pipe_winsys *_winsys, 
00186                            unsigned alignment, 
00187                            unsigned usage,
00188                            unsigned size)
00189 {
00190    struct trace_winsys *tr_ws = trace_winsys(_winsys);
00191    struct pipe_winsys *winsys = tr_ws->winsys;
00192    struct pipe_buffer *buffer;
00193    
00194    trace_dump_call_begin("pipe_winsys", "buffer_create");
00195    
00196    trace_dump_arg(ptr, winsys);
00197    trace_dump_arg(uint, alignment);
00198    trace_dump_arg(uint, usage);
00199    trace_dump_arg(uint, size);
00200 
00201    buffer = winsys->buffer_create(winsys, alignment, usage, size);
00202    
00203    trace_dump_ret(ptr, buffer);
00204    
00205    trace_dump_call_end();
00206 
00207    /* Zero the buffer to avoid dumping uninitialized memory */
00208    if(buffer->usage & PIPE_BUFFER_USAGE_CPU_WRITE) {
00209       void *map;
00210       map = winsys->buffer_map(winsys, buffer, PIPE_BUFFER_USAGE_CPU_WRITE);
00211       if(map) {
00212          memset(map, 0, buffer->size);
00213          winsys->buffer_unmap(winsys, buffer);
00214       }
00215    }
00216    
00217    return buffer;
00218 }
00219 
00220 
00221 static struct pipe_buffer *
00222 trace_winsys_user_buffer_create(struct pipe_winsys *_winsys, 
00223                                 void *data,
00224                                 unsigned size)
00225 {
00226    struct trace_winsys *tr_ws = trace_winsys(_winsys);
00227    struct pipe_winsys *winsys = tr_ws->winsys;
00228    struct pipe_buffer *result;
00229    
00230    trace_dump_call_begin("pipe_winsys", "user_buffer_create");
00231    
00232    trace_dump_arg(ptr, winsys);
00233    trace_dump_arg_begin("data");
00234    trace_dump_bytes(data, size);
00235    trace_dump_arg_end();
00236    trace_dump_arg(uint, size);
00237 
00238    result = winsys->user_buffer_create(winsys, data, size);
00239    
00240    trace_dump_ret(ptr, result);
00241    
00242    trace_dump_call_end();
00243    
00244    /* XXX: Mark the user buffers. (we should wrap pipe_buffers, but is is 
00245     * impossible to do so while texture-less surfaces are still around */
00246    if(result) {
00247       assert(!(result->usage & TRACE_BUFFER_USAGE_USER));
00248       result->usage |= TRACE_BUFFER_USAGE_USER;
00249    }
00250    
00251    return result;
00252 }
00253 
00254 
00255 void
00256 trace_winsys_user_buffer_update(struct pipe_winsys *_winsys, 
00257                                 struct pipe_buffer *buffer)
00258 {
00259    struct trace_winsys *tr_ws = trace_winsys(_winsys);
00260    struct pipe_winsys *winsys = tr_ws->winsys;
00261    const void *map;
00262    
00263    if(buffer && buffer->usage & TRACE_BUFFER_USAGE_USER) {
00264       map = winsys->buffer_map(winsys, buffer, PIPE_BUFFER_USAGE_CPU_READ);
00265       if(map) {
00266          trace_dump_call_begin("pipe_winsys", "buffer_write");
00267          
00268          trace_dump_arg(ptr, winsys);
00269          
00270          trace_dump_arg(ptr, buffer);
00271          
00272          trace_dump_arg_begin("data");
00273          trace_dump_bytes(map, buffer->size);
00274          trace_dump_arg_end();
00275       
00276          trace_dump_arg_begin("size");
00277          trace_dump_uint(buffer->size);
00278          trace_dump_arg_end();
00279       
00280          trace_dump_call_end();
00281          
00282          winsys->buffer_unmap(winsys, buffer);
00283       }
00284    }
00285 }
00286 
00287 
00288 static void *
00289 trace_winsys_buffer_map(struct pipe_winsys *_winsys, 
00290                         struct pipe_buffer *buffer,
00291                         unsigned usage)
00292 {
00293    struct trace_winsys *tr_ws = trace_winsys(_winsys);
00294    struct pipe_winsys *winsys = tr_ws->winsys;
00295    void *map;
00296    
00297    map = winsys->buffer_map(winsys, buffer, usage);
00298    if(map) {
00299       if(usage & PIPE_BUFFER_USAGE_CPU_WRITE) {
00300          assert(!hash_table_get(tr_ws->buffer_maps, buffer));
00301          hash_table_set(tr_ws->buffer_maps, buffer, map);
00302       }
00303    }
00304    
00305    return map;
00306 }
00307 
00308 
00309 static void
00310 trace_winsys_buffer_unmap(struct pipe_winsys *_winsys, 
00311                           struct pipe_buffer *buffer)
00312 {
00313    struct trace_winsys *tr_ws = trace_winsys(_winsys);
00314    struct pipe_winsys *winsys = tr_ws->winsys;
00315    const void *map;
00316    
00317    map = hash_table_get(tr_ws->buffer_maps, buffer);
00318    if(map) {
00319       trace_dump_call_begin("pipe_winsys", "buffer_write");
00320       
00321       trace_dump_arg(ptr, winsys);
00322       
00323       trace_dump_arg(ptr, buffer);
00324       
00325       trace_dump_arg_begin("data");
00326       trace_dump_bytes(map, buffer->size);
00327       trace_dump_arg_end();
00328 
00329       trace_dump_arg_begin("size");
00330       trace_dump_uint(buffer->size);
00331       trace_dump_arg_end();
00332    
00333       trace_dump_call_end();
00334 
00335       hash_table_remove(tr_ws->buffer_maps, buffer);
00336    }
00337    
00338    winsys->buffer_unmap(winsys, buffer);
00339 }
00340 
00341 
00342 static void
00343 trace_winsys_buffer_destroy(struct pipe_winsys *_winsys,
00344                             struct pipe_buffer *buffer)
00345 {
00346    struct trace_winsys *tr_ws = trace_winsys(_winsys);
00347    struct pipe_winsys *winsys = tr_ws->winsys;
00348    
00349    trace_dump_call_begin("pipe_winsys", "buffer_destroy");
00350    
00351    trace_dump_arg(ptr, winsys);
00352    trace_dump_arg(ptr, buffer);
00353 
00354    winsys->buffer_destroy(winsys, buffer);
00355    
00356    trace_dump_call_end();
00357 }
00358 
00359 
00360 static void
00361 trace_winsys_fence_reference(struct pipe_winsys *_winsys,
00362                              struct pipe_fence_handle **pdst,
00363                              struct pipe_fence_handle *src)
00364 {
00365    struct trace_winsys *tr_ws = trace_winsys(_winsys);
00366    struct pipe_winsys *winsys = tr_ws->winsys;
00367    struct pipe_fence_handle *dst = *pdst;
00368    
00369    trace_dump_call_begin("pipe_winsys", "fence_reference");
00370    
00371    trace_dump_arg(ptr, winsys);
00372    trace_dump_arg(ptr, dst);
00373    trace_dump_arg(ptr, src);
00374 
00375    winsys->fence_reference(winsys, pdst, src);
00376    
00377    trace_dump_call_end();
00378 }
00379 
00380 
00381 static int
00382 trace_winsys_fence_signalled(struct pipe_winsys *_winsys,
00383                              struct pipe_fence_handle *fence,
00384                              unsigned flag)
00385 {
00386    struct trace_winsys *tr_ws = trace_winsys(_winsys);
00387    struct pipe_winsys *winsys = tr_ws->winsys;
00388    int result;
00389    
00390    trace_dump_call_begin("pipe_winsys", "fence_signalled");
00391    
00392    trace_dump_arg(ptr, winsys);
00393    trace_dump_arg(ptr, fence);
00394    trace_dump_arg(uint, flag);
00395 
00396    result = winsys->fence_signalled(winsys, fence, flag);
00397    
00398    trace_dump_ret(int, result);
00399    
00400    trace_dump_call_end();
00401    
00402    return result;
00403 }
00404 
00405 
00406 static int
00407 trace_winsys_fence_finish(struct pipe_winsys *_winsys,
00408                           struct pipe_fence_handle *fence,
00409                           unsigned flag)
00410 {
00411    struct trace_winsys *tr_ws = trace_winsys(_winsys);
00412    struct pipe_winsys *winsys = tr_ws->winsys;
00413    int result;
00414    
00415    trace_dump_call_begin("pipe_winsys", "fence_finish");
00416    
00417    trace_dump_arg(ptr, winsys);
00418    trace_dump_arg(ptr, fence);
00419    trace_dump_arg(uint, flag);
00420 
00421    result = winsys->fence_finish(winsys, fence, flag);
00422    
00423    trace_dump_ret(int, result);
00424    
00425    trace_dump_call_end();
00426    
00427    return result;
00428 }
00429 
00430 
00431 static void
00432 trace_winsys_destroy(struct pipe_winsys *_winsys)
00433 {
00434    struct trace_winsys *tr_ws = trace_winsys(_winsys);
00435    struct pipe_winsys *winsys = tr_ws->winsys;
00436    
00437    trace_dump_call_begin("pipe_winsys", "destroy");
00438    
00439    trace_dump_arg(ptr, winsys);
00440 
00441    /* 
00442    winsys->destroy(winsys); 
00443    */
00444    
00445    trace_dump_call_end();
00446    
00447    hash_table_destroy(tr_ws->buffer_maps);
00448 
00449    FREE(tr_ws);
00450 }
00451 
00452 
00453 struct pipe_winsys *
00454 trace_winsys_create(struct pipe_winsys *winsys)
00455 {
00456    struct trace_winsys *tr_ws;
00457    
00458    if(!winsys)
00459       goto error1;
00460    
00461    tr_ws = CALLOC_STRUCT(trace_winsys);
00462    if(!tr_ws)
00463       goto error1;
00464 
00465    tr_ws->base.destroy = trace_winsys_destroy;
00466    tr_ws->base.get_name = trace_winsys_get_name;
00467    tr_ws->base.flush_frontbuffer = trace_winsys_flush_frontbuffer;
00468    tr_ws->base.surface_alloc = trace_winsys_surface_alloc;
00469    tr_ws->base.surface_alloc_storage = trace_winsys_surface_alloc_storage;
00470    tr_ws->base.surface_release = trace_winsys_surface_release;
00471    tr_ws->base.buffer_create = trace_winsys_buffer_create;
00472    tr_ws->base.user_buffer_create = trace_winsys_user_buffer_create;
00473    tr_ws->base.buffer_map = trace_winsys_buffer_map;
00474    tr_ws->base.buffer_unmap = trace_winsys_buffer_unmap;
00475    tr_ws->base.buffer_destroy = trace_winsys_buffer_destroy;
00476    tr_ws->base.fence_reference = trace_winsys_fence_reference;
00477    tr_ws->base.fence_signalled = trace_winsys_fence_signalled;
00478    tr_ws->base.fence_finish = trace_winsys_fence_finish;
00479    
00480    tr_ws->winsys = winsys;
00481 
00482    tr_ws->buffer_maps = hash_table_create(trace_buffer_hash, 
00483                                           trace_buffer_compare);
00484    if(!tr_ws->buffer_maps)
00485       goto error2;
00486    
00487    trace_dump_call_begin("", "pipe_winsys_create");
00488    trace_dump_ret(ptr, winsys);
00489    trace_dump_call_end();
00490 
00491    return &tr_ws->base;
00492    
00493 error2:
00494    FREE(tr_ws);
00495 error1:
00496    return winsys;
00497 }

Generated on Tue Sep 29 06:25:17 2009 for Gallium3D by  doxygen 1.5.4