~ubuntu-branches/ubuntu/precise/mesa/precise-updates

« back to all changes in this revision

Viewing changes to src/gallium/state_trackers/d3d1x/progs/d3d10app/d3d10winmain.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Christopher James Halse Rogers
  • Date: 2011-08-04 16:25:08 UTC
  • mfrom: (1.2.37 upstream)
  • Revision ID: james.westby@ubuntu.com-20110804162508-kujg82moxerjg1kk
Tags: 7.11-0ubuntu1
* Fake merge from Debian experimental, updating previous changelog entries.
  New upstream release fixes infrequent X crash (LP: #800778).
  Remaining Ubuntu changes:
 - debian/control
    + Drop lesstif-dev from Build-Depends; it's in Universe.
    + Comment out GLw libs since it depends on lesstif-dev.
    + Drop i686 swx11 libgl package.
    + Add libdrm-dev to mesa-common-dev Depends.
    + Drop libwayland-dev from Build-Depends; it's in Universe.
    + Update Breaks for Ubuntu versions
    + Enable llvm on armel as well as i386 and amd64
  - debian/rules
    + Use --disable-glw for swx11 targets too.
    + Don't enable motif for swx11 targets.
    + Use lzma compression for binary debs to save CD space.
    + Drop unloved mach64 driver.
    + Use --enable-shared-dricore to claw back CD space.
    + Enable llvmpipe software rasteriser.
    + Enable llvm on armel as well as i386 and amd64
  - debian/patches
    + 100_no_abi_tag.patch
    + 101_ubuntu_hidden_glname.patch
    + 103_savage-expose_fbmodes_with_nonzero_alpha.patch
  - rules, libgl1-mesa-{glx,dev,swx11,swx11-dev}.install.in,
    libgl1-mesa-{glx,swx11}.{postinst,prerm}.in, libgl1-mesa-dev.links.in:
    Install libGL.so* in /usr/lib/mesa to allow things to work with
    alternatives.
  - debian/not-installed:
    + Drop i686 files; we don't build 686-optimised packages in the first
      place.
  - debian/gbp.conf
    + Point at Ubuntu branch to make git-buildpackage less narky.
  - 113_fix_tls.diff: Fix crashes in unrelated code due to TLS usage.
  - debian/patches/111_export_searchdirs_in_dripc.diff:
    + Add drisearchdirs variable to dri.pc so the Xserver can pick up the
      alternate DRI driver dirs.
  - debian/patches/115_llvm_dynamic_linking.diff
    + Dynamically link DRI drivers to libllvm.  Saves ~6MiB per DRI driver.
  - debian/patches/116_use_shared_galliumcore.diff:
  - debian/libgl1-mesa-dri.install.in:
    + Link gallium DRI drivers against shared gallium routines to save CD
      space.
* debian/rules:
* debian/libgl1-mesa-dri-experimental.install.{i386,amd64}.in
  - Explicitly install i915g only when it has been built, matching what is
    done with r300g.
* debian/rules:
* debian/control:
* debian/libegl1-mesa{,-dev}.install.in:
* debian/libegl1-mesa.symbols:
  - Enable the Wayland EGL backend.
* debian/rules:
* debian/libegl1-mesa.{postinst,prerm,install}.in:
* debian/libegl1-mesa-dev.{install,links}.in:
* debian/libgles{1,2}-mesa.install.in:
* debian/libgles{1,2}-mesa-dev.links.in:
* debian/libopenvg1-mesa{,-dev}.install.in:
* debian/libopenvg1-mesa-dev.links.in:
  - Use alternatives for libEGL to match the handling of libGL.
    libEGL (and associated GL|ES and OpenVG libraries) now live in
    /usr/lib/$MULTIARCH/mesa-egl.  (LP: #812639)
* debian/patches/118_fix_24bpp_software_rendering.diff:
  - Cherry pick upstream patch from master fixing graphical corruption when
    using a 24bpp framebuffer and software rendering. (LP: #810339)
* debian/rules:
* debian/clean:
  - Generate xmlpool pot file and clean up other po files for
    pkgbinarymangler's benefit (LP: #410264).
* debian/patches/119_r600g_gnome_shell_rendering_fix.diff:
  - Cherry pick upstream commit fixing rendering corruption in gnome-shell
    (and therefore likely Unity as well).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**************************************************************************
2
 
 *
3
 
 * Copyright 2010 Luca Barbieri
4
 
 *
5
 
 * Permission is hereby granted, free of charge, to any person obtaining
6
 
 * a copy of this software and associated documentation files (the
7
 
 * "Software"), to deal in the Software without restriction, including
8
 
 * without limitation the rights to use, copy, modify, merge, publish,
9
 
 * distribute, sublicense, and/or sell copies of the Software, and to
10
 
 * permit persons to whom the Software is furnished to do so, subject to
11
 
 * the following conditions:
12
 
 *
13
 
 * The above copyright notice and this permission notice (including the
14
 
 * next paragraph) shall be included in all copies or substantial
15
 
 * portions of the Software.
16
 
 *
17
 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
 
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
 
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
 
 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21
 
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
 
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
 
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
 
 *
25
 
 **************************************************************************/
26
 
 
27
 
#define INITGUID
28
 
#include "d3d10app.h"
29
 
#include "stdio.h"
30
 
 
31
 
static d3d10_application* app;
32
 
static IDXGISwapChain* swap_chain;
33
 
static unsigned width, height;
34
 
static DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM;
35
 
static ID3D10Device* dev;
36
 
static ID3D10Device* ctx;
37
 
static int frames = 0;
38
 
static int buffer_count = 1;
39
 
 
40
 
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
41
 
{
42
 
        switch (message)
43
 
        {
44
 
        case WM_SIZE:
45
 
                width = lParam & 0xffff;
46
 
                height = lParam >> 16;
47
 
                
48
 
                swap_chain->ResizeBuffers(buffer_count, width, height, format, 0);
49
 
                frames = 0;
50
 
                break;
51
 
        case WM_DESTROY:
52
 
                PostQuitMessage(0);
53
 
                break;
54
 
        default:
55
 
                return DefWindowProc(hwnd, message, wParam, lParam);
56
 
        }
57
 
        return 0;
58
 
}
59
 
 
60
 
int main(int argc, char** argv)
61
 
{
62
 
        HINSTANCE hInstance = GetModuleHandle(NULL);
63
 
        WNDCLASSEXA wcex;
64
 
 
65
 
        wcex.cbSize = sizeof(WNDCLASSEX);
66
 
 
67
 
        wcex.style              = CS_HREDRAW | CS_VREDRAW;
68
 
        wcex.lpfnWndProc        = WndProc;
69
 
        wcex.cbClsExtra         = 0;
70
 
        wcex.cbWndExtra         = 0;
71
 
        wcex.hInstance          = hInstance;
72
 
        wcex.hIcon              = 0;
73
 
        wcex.hCursor            = LoadCursor(NULL, IDC_ARROW);
74
 
        wcex.hbrBackground      = (HBRUSH)(COLOR_WINDOW+1);
75
 
        wcex.lpszMenuName       = 0;
76
 
        wcex.lpszClassName      = "d3d10";
77
 
        wcex.hIconSm            = 0;
78
 
 
79
 
        RegisterClassExA(&wcex);
80
 
 
81
 
        HWND hwnd = CreateWindowA("d3d10", "d3d10", WS_OVERLAPPEDWINDOW,
82
 
                CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
83
 
 
84
 
        if(!hwnd)
85
 
                return FALSE;
86
 
 
87
 
        RECT rc;
88
 
        GetClientRect(hwnd, &rc );
89
 
        width = rc.right - rc.left;
90
 
        height = rc.bottom - rc.top;
91
 
 
92
 
        DXGI_SWAP_CHAIN_DESC swap_chain_desc;
93
 
        memset(&swap_chain_desc, 0, sizeof(swap_chain_desc));
94
 
        swap_chain_desc.BufferDesc.Width = width;
95
 
        swap_chain_desc.BufferDesc.Height = height;
96
 
        swap_chain_desc.BufferDesc.Format = format;
97
 
        swap_chain_desc.SampleDesc.Count = 1;
98
 
        swap_chain_desc.SampleDesc.Quality = 0;
99
 
        swap_chain_desc.OutputWindow = hwnd;
100
 
        swap_chain_desc.Windowed = TRUE;
101
 
        swap_chain_desc.BufferCount = buffer_count;
102
 
        swap_chain_desc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
103
 
        swap_chain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
104
 
        swap_chain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
105
 
 
106
 
        D3D10_FEATURE_LEVEL1 feature_level = D3D10_FEATURE_LEVEL_10_0;
107
 
 
108
 
        HRESULT hr;
109
 
        if(1)
110
 
        {
111
 
                hr = D3D10CreateDeviceAndSwapChain(
112
 
                        NULL,
113
 
                        D3D10_DRIVER_TYPE_HARDWARE,
114
 
                        NULL,
115
 
                        D3D10_CREATE_DEVICE_SINGLETHREADED, // | D3D10_CREATE_DEVICE_DEBUG,
116
 
                        D3D10_SDK_VERSION,
117
 
                        &swap_chain_desc,
118
 
                        &swap_chain,
119
 
                        &dev);
120
 
        }
121
 
        else
122
 
        {
123
 
                hr = D3D10CreateDeviceAndSwapChain1(
124
 
                        NULL,
125
 
                        D3D10_DRIVER_TYPE_HARDWARE,
126
 
                        NULL,
127
 
                        D3D10_CREATE_DEVICE_SINGLETHREADED, // | D3D10_CREATE_DEVICE_DEBUG,
128
 
                        feature_level,
129
 
                        D3D10_SDK_VERSION,
130
 
                        &swap_chain_desc,
131
 
                        &swap_chain,
132
 
                        (ID3D10Device1**)&dev);
133
 
        }
134
 
 
135
 
        if(!SUCCEEDED(hr))
136
 
        {
137
 
                fprintf(stderr, "Failed to create D3D10 device (hresult %08x)\n", hr);
138
 
                return 1;
139
 
        }
140
 
 
141
 
        ctx = dev;
142
 
 
143
 
        app = d3d10_application_create();
144
 
        if(!app->init(dev, argc, argv))
145
 
                return 1;
146
 
 
147
 
        ShowWindow(hwnd, SW_SHOWDEFAULT);
148
 
        UpdateWindow(hwnd);
149
 
 
150
 
        LARGE_INTEGER freq;
151
 
        QueryPerformanceFrequency(&freq);
152
 
        double period = 1.0 / (double)freq.QuadPart;
153
 
        LARGE_INTEGER ctime_li;
154
 
        QueryPerformanceCounter(&ctime_li);
155
 
        double start_time = ctime_li.QuadPart * period;
156
 
 
157
 
        MSG msg;
158
 
        for(;;)
159
 
        {
160
 
                if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
161
 
                {
162
 
                        if(msg.message == WM_QUIT)
163
 
                                break;
164
 
                        TranslateMessage(&msg);
165
 
                        DispatchMessage(&msg);
166
 
                }
167
 
                else if(width && height)
168
 
                {
169
 
                        ID3D10Texture2D* tex;
170
 
                        static ID3D10RenderTargetView* rtv;
171
 
                        ensure(swap_chain->GetBuffer(0, __uuidof(tex), (void**)&tex));
172
 
                        ensure(dev->CreateRenderTargetView(tex, NULL, &rtv));
173
 
 
174
 
                        QueryPerformanceCounter(&ctime_li);
175
 
                        double ctime = (double)ctime_li.QuadPart * period - start_time;
176
 
 
177
 
                        app->draw(ctx, rtv, width, height, ctime);
178
 
                        ctx->OMSetRenderTargets(0, 0, 0);
179
 
 
180
 
                        swap_chain->Present(0, 0);
181
 
                        rtv->Release();
182
 
                        tex->Release();
183
 
                }
184
 
                else
185
 
                        WaitMessage();
186
 
        }
187
 
        return (int) msg.wParam;
188
 
}