~unity-team/unity/unity.blur-but-faster-fbo-disabler

« back to all changes in this revision

Viewing changes to plugins/unityshell/src/unityshell.cpp

  • Committer: Sam Spilsbury
  • Date: 2011-08-20 08:29:59 UTC
  • mfrom: (1371.3.6 unity.blur_fixes_fbo)
  • Revision ID: sam.spilsbury@canonical.com-20110820082959-tdx23qxqxm0qgiip
Merge in blur fbo branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
111
111
  , _key_nav_mode_requested(false)
112
112
  , _last_output(nullptr)
113
113
  , switcher_desktop_icon(nullptr)
114
 
  , mActiveFbo (0)
 
114
  , _active_fbo (0)
115
115
  , grab_index_ (0)
116
116
{
117
117
  Timer timer;
162
162
 
163
163
  if (GL::fbo)
164
164
  {
165
 
    foreach (CompOutput &o, screen->outputDevs ())
166
 
      uScreen->mFbos[&o] = UnityFBO::Ptr (new UnityFBO (&o));
167
 
    
168
 
    uScreen->mFbos[&(screen->fullscreenOutput ())] = UnityFBO::Ptr (new UnityFBO (&(screen->fullscreenOutput ())));
 
165
    CompRect geometry = CompRect (0, 0, screen->width (), screen->height ());
 
166
 
 
167
    uScreen->_fbo = UnityFBO::Ptr (new UnityFBO (geometry));
169
168
  }
170
169
 
171
170
  optionSetLauncherHideModeNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));
305
304
   * drivers (lp:703140). */
306
305
  glDisable(GL_LIGHTING);
307
306
 
 
307
  if (BackgroundEffectHelper::EnabledBackgroundHelpers () &&
 
308
      _fbo->status ())
 
309
      _fbo->unbind ();
 
310
 
308
311
  /* reset matrices */
309
312
  glPushAttrib(GL_VIEWPORT_BIT | GL_ENABLE_BIT |
310
313
               GL_TEXTURE_BIT | GL_COLOR_BUFFER_BIT | GL_SCISSOR_BIT);
320
323
 
321
324
void UnityScreen::nuxEpilogue()
322
325
{
323
 
  (*GL::bindFramebuffer)(GL_FRAMEBUFFER_EXT, mActiveFbo);
324
 
 
325
326
  glMatrixMode(GL_PROJECTION);
326
327
  glLoadIdentity();
327
328
  glMatrixMode(GL_MODELVIEW);
343
344
  glPopAttrib();
344
345
 
345
346
  glDisable(GL_SCISSOR_TEST);
 
347
 
 
348
  if (BackgroundEffectHelper::EnabledBackgroundHelpers ())
 
349
      _fbo->bind ();
346
350
}
347
351
 
348
352
void UnityScreen::OnLauncherHiddenChanged()
353
357
    screen->removeAction(&optionGetLauncherRevealEdge());
354
358
}
355
359
 
356
 
void UnityScreen::paintPanelShadow(const GLMatrix& matrix)
 
360
void UnityScreen::paintPanelShadow()
357
361
{
358
 
  if (relayoutSourceId > 0)
359
 
    return;
360
 
 
361
 
  if (PluginAdapter::Default()->IsExpoActive())
362
 
    return;
363
 
 
364
 
  nuxPrologue();
365
 
 
366
362
  CompOutput* output = _last_output;
 
363
  GLMatrix    sTransform = GLMatrix ();
367
364
  float vc[4];
368
365
  float h = 20.0f;
369
366
  float w = 1.0f;
374
371
  float x2 = x1 + output->width();
375
372
  float y2 = y1 + h;
376
373
 
 
374
  if (relayoutSourceId > 0)
 
375
    return;
 
376
 
 
377
  if (PluginAdapter::Default()->IsExpoActive())
 
378
    return;
 
379
 
 
380
  sTransform.toScreenSpace (output, -DEFAULT_Z_CAMERA);
 
381
 
377
382
  vc[0] = x1;
378
383
  vc[1] = x2;
379
384
  vc[2] = y1;
411
416
      glDisable(GL_BLEND);
412
417
    }
413
418
  }
414
 
  nuxEpilogue();
415
419
}
416
420
 
417
421
void
430
434
{
431
435
  CompOutput *output = _last_output;
432
436
 
433
 
  mFbos[output]->unbind ();
434
 
 
435
 
  /* Draw the bit of the relevant framebuffer for each output */
436
 
  mFbos[output]->paint ();
437
 
 
438
437
  nuxPrologue();
439
 
  nux::ObjectPtr<nux::IOpenGLTexture2D> device_texture = 
440
 
  nux::GetGraphicsDisplay()->GetGpuDevice()->CreateTexture2DFromID(mFbos[output]->texture(), 
441
 
  output->width(), output->height(), 1, nux::BITFMT_R8G8B8A8);
442
 
 
443
 
  nux::GetGraphicsDisplay()->GetGpuDevice()->backup_texture0_ = device_texture;
 
438
 
 
439
  if (BackgroundEffectHelper::EnabledBackgroundHelpers () &&
 
440
      _fbo->status ())
 
441
  {
 
442
      _fbo->paint (output);
 
443
      nux::ObjectPtr<nux::IOpenGLTexture2D> device_texture =
 
444
          nux::GetGraphicsDisplay()->GetGpuDevice()->CreateTexture2DFromID(_fbo->texture (),
 
445
                                                                           output->width(),
 
446
                                                                           output->height(),
 
447
                                                                           1,
 
448
                                                                           nux::BITFMT_R8G8B8A8);
 
449
 
 
450
      nux::GetGraphicsDisplay()->GetGpuDevice()->backup_texture0_ = device_texture;
 
451
  }
444
452
 
445
453
  nux::Geometry geo = nux::Geometry (output->x (), output->y (), output->width (), output->height ());
446
454
 
447
455
  wt->RenderInterfaceFromForeignCmd (&geo);
448
456
  nuxEpilogue();
449
457
 
450
 
if (switcherController->Visible ())
 
458
  /* We aren't painting the fbo after this so no need to have it bound */
 
459
  if (BackgroundEffectHelper::EnabledBackgroundHelpers () &&
 
460
      _fbo->status ())
 
461
      _fbo->unbind ();
 
462
 
 
463
  if (switcherController->Visible ())
451
464
  {
452
465
    LayoutWindowList targets = switcherController->ExternalRenderTargets ();
453
466
 
502
515
{
503
516
  bool ret;
504
517
 
505
 
  /* bind the framebuffer here */
506
 
  mFbos[output]->bind ();
507
 
 
508
518
  doShellRepaint = true;
509
519
  allowWindowPaint = true;
510
520
  _last_output = output;
527
537
                                           CompOutput* output,
528
538
                                           unsigned int mask)
529
539
{
530
 
  /* bind the framebuffer here */
531
 
  mFbos[output]->bind ();
532
540
  allowWindowPaint = false;
533
541
  /* urgh */
534
542
  gScreen->glPaintOutput(attrib, transform, region, output, mask);
558
566
 
559
567
}
560
568
 
 
569
void UnityScreen::paint (CompOutput::ptrList &outputs,
 
570
                         unsigned int mask)
 
571
{
 
572
  if (BackgroundEffectHelper::EnabledBackgroundHelpers ())
 
573
      _fbo->bind ();
 
574
 
 
575
  cScreen->paint (outputs, mask);
 
576
}
561
577
/* Grab changed nux regions and add damage rects for them */
562
578
void UnityScreen::damageNuxRegions()
563
579
{
1111
1127
 
1112
1128
  if (window->type() == CompWindowTypeDesktopMask)
1113
1129
  {
1114
 
    uScreen->paintPanelShadow(matrix);
 
1130
    uScreen->paintPanelShadow();
1115
1131
  }
1116
1132
 
1117
1133
  return ret;
1281
1297
 
1282
1298
  if (GL::fbo)
1283
1299
  {
1284
 
    foreach (CompOutput &o, screen->outputDevs ())
1285
 
      uScreen->mFbos[&o] = UnityFBO::Ptr (new UnityFBO (&o));
1286
 
    
1287
 
    uScreen->mFbos[&(screen->fullscreenOutput ())] = UnityFBO::Ptr (new UnityFBO (&(screen->fullscreenOutput ())));
 
1300
    CompRect geometry = CompRect (0, 0, screen->width (), screen->height ());
 
1301
 
 
1302
    uScreen->_fbo = UnityFBO::Ptr (new UnityFBO (geometry));
1288
1303
  }
1289
1304
 
1290
1305
  scr = gdk_screen_get_default ();
1318
1333
{
1319
1334
  UnityScreen* uScr = reinterpret_cast<UnityScreen*>(data);
1320
1335
 
1321
 
  uScreen->mFbos.clear ();
1322
 
 
1323
1336
  uScr->NeedsRelayout ();
1324
1337
  uScr->Relayout();
1325
1338
  uScr->relayoutSourceId = 0;
1350
1363
  ScheduleRelayout(500);
1351
1364
}
1352
1365
 
1353
 
void UnityFBO::paint ()
 
1366
void UnityFBO::paint (CompOutput *output)
1354
1367
{
1355
 
  //CompositeScreen *cScreen = CompositeScreen::get (screen);
1356
 
  //unsigned int    mask = cScreen->damageMask ();
1357
1368
  float texx, texy, texwidth, texheight;
1358
1369
 
1359
1370
  /* Draw the bit of the relevant framebuffer for each output */
1360
1371
  GLMatrix transform;
1361
1372
 
1362
 
  glViewport (output->x (), screen->height () - output->y2 (), output->width (), output->height ());
 
1373
  glPushAttrib (GL_VIEWPORT_BIT);
 
1374
  glViewport (0, 0, screen->width (), screen->height ());
1363
1375
 
1364
 
  transform.toScreenSpace (output, -DEFAULT_Z_CAMERA);
 
1376
  transform.toScreenSpace (&screen->fullscreenOutput (), -DEFAULT_Z_CAMERA);
1365
1377
  glPushMatrix ();
1366
1378
  glLoadMatrixf (transform.getMatrix ());
1367
1379
 
1406
1418
    glDisable (GL_SCISSOR_TEST);
1407
1419
    glPopAttrib ();
1408
1420
  }
 
1421
  glPopAttrib ();
1409
1422
 
1410
1423
  glPopMatrix();
1411
1424
}
1417
1430
 
1418
1431
  glDrawBuffer (GL_BACK);
1419
1432
  glReadBuffer (GL_BACK);
 
1433
  glPopAttrib ();
1420
1434
 
1421
1435
}
1422
1436
 
1436
1450
    glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1437
1451
    glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1438
1452
    glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1439
 
    glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, output->width (), output->height (), 0, GL_BGRA,
 
1453
    glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, mGeometry.width (), mGeometry.height (), 0, GL_BGRA,
1440
1454
#if IMAGE_BYTE_ORDER == MSBFirst
1441
1455
                  GL_UNSIGNED_INT_8_8_8_8_REV,
1442
1456
#else
1502
1516
  {
1503
1517
    uScreen->setActiveFbo (mFboHandle);
1504
1518
 
 
1519
    glPushAttrib (GL_VIEWPORT_BIT | GL_CURRENT_BIT);
 
1520
 
1505
1521
    glDrawBuffer (GL_COLOR_ATTACHMENT0_EXT);
1506
1522
    glReadBuffer (GL_COLOR_ATTACHMENT0_EXT);
1507
1523
 
1508
1524
    glViewport (0,
1509
1525
                0,
1510
 
                output->width (),
1511
 
                output->height ());
 
1526
                mGeometry.width (),
 
1527
                mGeometry.height ());
1512
1528
 
1513
1529
  }
1514
1530
}
1515
1531
 
1516
 
UnityFBO::UnityFBO (CompOutput *o)
 
1532
UnityFBO::UnityFBO (CompRect geometry)
1517
1533
 : mFboStatus (false)
1518
1534
 , mFBTexture (0)
1519
 
 , output (o)
 
1535
 , mGeometry (geometry)
1520
1536
{
1521
1537
  (*GL::genFramebuffers) (1, &mFboHandle);
1522
1538
}