~ubuntu-branches/ubuntu/hardy/kdebase-workspace/hardy-backports

« back to all changes in this revision

Viewing changes to kwin/scene_opengl.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Richard A. Johnson
  • Date: 2008-05-02 23:57:34 UTC
  • mfrom: (1.2.1 upstream) (20.1.22 hardy)
  • Revision ID: james.westby@ubuntu.com-20080502235734-kwrykz4qcvunwqf4
Tags: 4:4.0.4-0ubuntu1~hardy1
* New upstream release (LP: #225994)
* Updated control file (LP: #220655)
* Updated install files

Show diffs side-by-side

added added

removed removed

Lines of Context:
125
125
            !glXGetVisualFromFBConfig || !glXCreatePixmap || !glXDestroyPixmap ||
126
126
            !glXCreateWindow || !glXDestroyWindow )
127
127
        {
128
 
        kDebug( 1212 ) << "GLX_SGIX_fbconfig or required GLX functions missing";
 
128
        kError( 1212 ) << "GLX_SGIX_fbconfig or required GLX functions missing";
129
129
        return; // error
130
130
        }
131
131
    if( !selectMode())
134
134
        return; // error
135
135
    if( !initRenderingContext())
136
136
        return; // error
137
 
 
138
137
    // Initialize OpenGL
139
138
    initGL();
 
139
    if( !hasGLExtension( "GL_ARB_texture_non_power_of_two" )
 
140
        && !hasGLExtension( "GL_ARB_texture_rectangle" ))
 
141
        {
 
142
        kError( 1212 ) << "GL_ARB_texture_non_power_of_two and GL_ARB_texture_rectangle missing";
 
143
        return; // error
 
144
        }
140
145
    if( db )
141
146
        glDrawBuffer( GL_BACK );
142
147
    // Check whether certain features are supported
143
148
    has_waitSync = glXGetVideoSync ? true : false;
144
149
 
145
 
    int vis_buffer, vis_drawable;
146
 
    glXGetFBConfigAttrib( display(), fbcbuffer, GLX_VISUAL_ID, &vis_buffer );
147
 
    XVisualInfo* visinfo_buffer = glXGetVisualFromFBConfig( display(), fbcbuffer );
148
 
    kDebug( 1212 ) << "Buffer visual (depth " << visinfo_buffer->depth << "): 0x" << QString::number( vis_buffer, 16 );
149
 
    XFree( visinfo_buffer );
150
 
    for( int i = 0; i <= 32; i++ )
151
 
        {
152
 
        if( fbcdrawableinfo[ i ].fbconfig == NULL )
153
 
            continue;
154
 
        glXGetFBConfigAttrib( display(), fbcdrawableinfo[ i ].fbconfig, GLX_VISUAL_ID, &vis_drawable );
155
 
        kDebug( 1212 ) << "Drawable visual (depth " << i << "): 0x" << QString::number( vis_drawable, 16 );
156
 
        }
157
 
 
158
150
    // OpenGL scene setup
159
151
    glMatrixMode( GL_PROJECTION );
160
152
    glLoadIdentity();
162
154
    glOrtho( 0, displayWidth(), displayHeight(), 0, 0, 65535 );
163
155
    glMatrixMode( GL_MODELVIEW );
164
156
    glLoadIdentity();
165
 
    checkGLError( "Init" );
 
157
    if( checkGLError( "Init" ))
 
158
        {
 
159
        kError( 1212 ) << "OpenGL compositing setup failed";
 
160
        return; // error
 
161
        }
166
162
    kDebug( 1212 ) << "DB:" << db << ", TFP:" << tfp_mode << ", SHM:" << shm_mode
167
163
        << ", Direct:" << bool( glXIsDirect( display(), ctxbuffer )) << endl;
168
164
    init_ok = true;
293
289
#endif
294
290
    }
295
291
 
 
292
// TODO replace with just KXErrorHandler::errorCode() for 4.1
 
293
static int xerror = 0;
 
294
static bool xerrorhandler( int, int error, unsigned long )
 
295
    {
 
296
    if( xerror == 0 )
 
297
        xerror = error;
 
298
    return true;
 
299
    }
 
300
 
296
301
bool SceneOpenGL::initRenderingContext()
297
302
    {
298
303
    bool direct_rendering = options->glDirect;
299
304
    if( !tfp_mode && !shm_mode )
300
305
        direct_rendering = false; // fallback doesn't seem to work with direct rendering
301
 
    KXErrorHandler errs;
 
306
    xerror = 0;
 
307
    KXErrorHandler errs1( xerrorhandler );
302
308
    ctxbuffer = glXCreateNewContext( display(), fbcbuffer, GLX_RGBA_TYPE, NULL,
303
309
        direct_rendering ? GL_TRUE : GL_FALSE );
304
 
    if( ctxbuffer == NULL || !glXMakeCurrent( display(), glxbuffer, ctxbuffer )
305
 
        || errs.error( true ))
306
 
        { // failed
 
310
    bool failed = ( ctxbuffer == NULL || !glXMakeCurrent( display(), glxbuffer, ctxbuffer ));
 
311
    if( errs1.error( true )) // always check for error( having it all in one if() could skip
 
312
        failed = true;       // it due to evaluation short-circuiting
 
313
    if( failed )
 
314
        {
307
315
        if( !direct_rendering )
308
316
            {
309
 
            kDebug( 1212 ) << "Couldn't initialize rendering context";
 
317
            kDebug( 1212 ).nospace() << "Couldn't initialize rendering context (0x" << hex << xerror << ")";
310
318
            return false;
311
319
            }
312
320
        glXMakeCurrent( display(), None, NULL );
313
 
        glXDestroyContext( display(), ctxbuffer );
 
321
        if( ctxbuffer != NULL )
 
322
            glXDestroyContext( display(), ctxbuffer );
314
323
        direct_rendering = false; // try again
 
324
        xerror = 0;
 
325
        KXErrorHandler errs2( xerrorhandler );
315
326
        ctxbuffer = glXCreateNewContext( display(), fbcbuffer, GLX_RGBA_TYPE, NULL, GL_FALSE );
316
 
        if( ctxbuffer == NULL || !glXMakeCurrent( display(), glxbuffer, ctxbuffer ) || errs.error( true ))
 
327
        bool failed = ( ctxbuffer == NULL || !glXMakeCurrent( display(), glxbuffer, ctxbuffer ));
 
328
        if( errs2.error( true ))
 
329
            failed = true;
 
330
        if( failed )
317
331
            {
318
 
            kDebug( 1212 ) << "Couldn't initialize rendering context";
 
332
            kDebug( 1212 ).nospace() << "Couldn't initialize rendering context (0x" << hex << xerror << ")";
319
333
            return false;
320
334
            }
321
335
        }
363
377
        }
364
378
    else
365
379
        {
366
 
        kDebug( 1212 ) << "Couldn't create output buffer (failed to create overlay window?) !";
 
380
        kError( 1212 ) << "Couldn't create output buffer (failed to create overlay window?) !";
367
381
        return false; // error
368
382
        }
 
383
    int vis_buffer;
 
384
    glXGetFBConfigAttrib( display(), fbcbuffer, GLX_VISUAL_ID, &vis_buffer );
 
385
    XVisualInfo* visinfo_buffer = glXGetVisualFromFBConfig( display(), fbcbuffer );
 
386
    kDebug( 1212 ) << "Buffer visual (depth " << visinfo_buffer->depth << "): 0x" << QString::number( vis_buffer, 16 );
 
387
    XFree( visinfo_buffer );
369
388
    return true;
370
389
    }
371
390
 
403
422
                                  GLX_BUFFER_SIZE, &value );
404
423
            if( value != visual_depth && ( value - alpha ) != visual_depth )
405
424
                continue;
 
425
            glXGetFBConfigAttrib( display(), fbconfigs[ j ],
 
426
                                  GLX_RENDER_TYPE, &value );
 
427
            if( !( value & GLX_RGBA_BIT ))
 
428
                continue;
406
429
            int back_value;
407
430
            glXGetFBConfigAttrib( display(), fbconfigs[ j ],
408
431
                                  GLX_DOUBLEBUFFER, &back_value );
445
468
        XFree( fbconfigs );
446
469
    if( fbcbuffer_db == NULL && fbcbuffer_nondb == NULL )
447
470
        {
448
 
        kDebug( 1212 ) << "Couldn't find framebuffer configuration for buffer!";
 
471
        kError( 1212 ) << "Couldn't find framebuffer configuration for buffer!";
449
472
        return false;
450
473
        }
 
474
    for( int i = 0; i <= 32; i++ )
 
475
        {
 
476
        if( fbcdrawableinfo[ i ].fbconfig == NULL )
 
477
            continue;
 
478
        int vis_drawable = 0;
 
479
        glXGetFBConfigAttrib( display(), fbcdrawableinfo[ i ].fbconfig, GLX_VISUAL_ID, &vis_drawable );
 
480
        kDebug( 1212 ) << "Drawable visual (depth " << i << "): 0x" << QString::number( vis_drawable, 16 );
 
481
        }
451
482
    return true;
452
483
    }
453
484
 
488
519
                                  GLX_BUFFER_SIZE, &value );
489
520
            if( value != i && ( value - alpha ) != i )
490
521
                continue;
 
522
            glXGetFBConfigAttrib( display(), fbconfigs[ j ],
 
523
                                  GLX_RENDER_TYPE, &value );
 
524
            if( !( value & GLX_RGBA_BIT ))
 
525
                continue;
491
526
            if( tfp_mode )
492
527
                {
493
528
                value = 0;
558
593
        XFree( fbconfigs );
559
594
    if( fbcdrawableinfo[ DefaultDepth( display(), DefaultScreen( display())) ].fbconfig == NULL )
560
595
        {
561
 
        kDebug( 1212 ) << "Couldn't find framebuffer configuration for default depth!";
 
596
        kError( 1212 ) << "Couldn't find framebuffer configuration for default depth!";
562
597
        return false;
563
598
        }
564
599
    if( fbcdrawableinfo[ 32 ].fbconfig == NULL )
565
600
        {
566
 
        kDebug( 1212 ) << "Couldn't find framebuffer configuration for depth 32!";
 
601
        kError( 1212 ) << "Couldn't find framebuffer configuration for depth 32 (no ARGB GLX visual)!";
567
602
        return false;
568
603
        }
569
604
    return true;
744
779
        return;                 // by default
745
780
    Window* w = windows[ c ];
746
781
    w->discardShape();
747
 
    w->discardTexture();
 
782
    w->checkTextureSize();
748
783
    }
749
784
 
750
785
void SceneOpenGL::windowOpacityChanged( Toplevel* )
1122
1157
    texture.discard();
1123
1158
    }
1124
1159
 
 
1160
// This call is used in SceneOpenGL::windowGeometryShapeChanged(),
 
1161
// which originally called discardTexture(), however this was causing performance
 
1162
// problems with the launch feedback icon - large number of texture rebinds.
 
1163
// Since the launch feedback icon does not resize, only changes shape, it
 
1164
// is not necessary to rebind the texture (with no strict binding), therefore
 
1165
// discard the texture only if size changes.
 
1166
void SceneOpenGL::Window::checkTextureSize()
 
1167
    {
 
1168
    if( texture.size() != size())
 
1169
        discardTexture();
 
1170
    }
 
1171
 
1125
1172
// when the window's composite pixmap is discarded, undo binding it to the texture
1126
1173
void SceneOpenGL::Window::pixmapDiscarded()
1127
1174
    {