gallium: add usage parameter to pipe_buffer_create
[mesa.git] / src / gallium / state_trackers / d3d1x / dxgi / src / dxgi_native.cpp
index e1c34611d141d049476537fa7f3b6676f753d488..2e45f3f43e97be64ae08a34cc4309bbd416209d4 100644 (file)
@@ -256,11 +256,16 @@ struct GalliumDXGIAdapter
        {
                this->parent = factory;
 
+                /* FIXME handler should be static */
                handler.invalid_surface = handle_invalid_surface;
                handler.new_drm_screen = dxgi_loader_create_drm_screen;
                handler.new_sw_screen = dxgi_loader_create_sw_screen;
-               display = platform->create_display(dpy, &handler, this);
+               platform->set_event_handler(&handler);
+
+               display = platform->create_display(dpy, FALSE, this);
                if(!display)
+                   display = platform->create_display(dpy, TRUE, this);
+                if(!display)
                        throw E_FAIL;
                memset(&desc, 0, sizeof(desc));
                std::string s = std::string("GalliumD3D on ") + display->screen->get_name(display->screen) + " by " + display->screen->get_vendor(display->screen);
@@ -789,9 +794,9 @@ struct dxgi_blitter
                const unsigned semantic_indices[] = { 0, 0 };
                vs = util_make_vertex_passthrough_shader(pipe, 2, semantic_names, semantic_indices);
 
-               vbuf.buffer = pipe_buffer_create(pipe->screen, PIPE_BIND_VERTEX_BUFFER, sizeof(quad_data));
+               vbuf.buffer = pipe_buffer_create(pipe->screen, PIPE_BIND_VERTEX_BUFFER,
+                                                PIPE_USAGE_STREAM, sizeof(quad_data));
                vbuf.buffer_offset = 0;
-               vbuf.max_index = ~0;
                vbuf.stride = 4 * sizeof(float);
                pipe_buffer_write(pipe, vbuf.buffer, 0, sizeof(quad_data), quad_data);
 
@@ -1101,6 +1106,7 @@ struct GalliumDXGISwapChain : public GalliumDXGIObject<IDXGISwapChain, GalliumDX
                struct pipe_resource* dst;
                struct pipe_resource* src;
                struct pipe_surface* dst_surface;
+               enum native_attachment att;
 
                void* present_cookie;
                hr = parent->backend->BeginPresent(desc.OutputWindow, &present_cookie, &cur_window, &rect, &rgndata, &preserve_aspect_ratio);
@@ -1158,8 +1164,15 @@ struct GalliumDXGISwapChain : public GalliumDXGIObject<IDXGISwapChain, GalliumDX
                        unsigned blit_x, blit_y, blit_w, blit_h;
                        float black[4] = {0, 0, 0, 0};
 
-                       if(!formats_compatible || src->width0 != dst_w || src->height0 != dst_h)
-                               dst_surface = pipe->screen->get_tex_surface(pipe->screen, dst, 0, 0, 0, PIPE_BIND_RENDER_TARGET);
+                       if(!formats_compatible || src->width0 != dst_w || src->height0 != dst_h) {
+                               struct pipe_surface templat;
+                               templat.usage = PIPE_BIND_RENDER_TARGET;
+                               templat.format = dst->format;
+                               templat.u.tex.level = 0;
+                               templat.u.tex.first_layer = 0;
+                               templat.u.tex.last_layer = 0;
+                               dst_surface = pipe->create_surface(pipe, dst, &templat);
+                       }
 
                        if(preserve_aspect_ratio)
                        {
@@ -1198,10 +1211,12 @@ struct GalliumDXGISwapChain : public GalliumDXGIObject<IDXGISwapChain, GalliumDX
 
                        if(formats_compatible && blit_w == src->width0 && blit_h == src->height0)
                        {
-                               pipe_subresource sr;
-                               sr.face = 0;
-                               sr.level = 0;
-                               pipe->resource_copy_region(pipe, dst, sr, rect.left, rect.top, 0, src, sr, 0, 0, 0, blit_w, blit_h);
+                               pipe_box box;
+                               box.x = box.y = box.z;
+                               box.width = blit_w;
+                               box.height = blit_h;
+                               box.z = 1;
+                               pipe->resource_copy_region(pipe, dst, 0, rect.left, rect.top, 0, src, 0, &box);
                        }
                        else
                        {
@@ -1217,20 +1232,13 @@ struct GalliumDXGISwapChain : public GalliumDXGIObject<IDXGISwapChain, GalliumDX
                }
 
                if(dst_surface)
-                       pipe->screen->tex_surface_destroy(dst_surface);
+                       pipe->surface_destroy(pipe, dst_surface);
 
                pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, 0);
 
-               if(db)
-               {
-                       if(!surface->swap_buffers(surface))
-                               return DXGI_ERROR_DEVICE_REMOVED;
-               }
-               else
-               {
-                       if(!surface->flush_frontbuffer(surface))
-                               return DXGI_ERROR_DEVICE_REMOVED;
-               }
+               att = (db) ? NATIVE_ATTACHMENT_BACK_LEFT : NATIVE_ATTACHMENT_FRONT_LEFT;
+               if(!surface->present(surface, att, FALSE, 0))
+                       return DXGI_ERROR_DEVICE_REMOVED;
 
 end_present:
                parent->backend->EndPresent(desc.OutputWindow, present_cookie);