~smspillaz/unity/unity.fix_877778

« back to all changes in this revision

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

  • Committer: smspillaz
  • Date: 2012-04-06 01:57:09 UTC
  • mfrom: (2164.1.74 unity)
  • Revision ID: sam.spilsbury@canonical.com-20120406015709-rv0g4h4lj0566x5h
Merge lp:unity and style

Show diffs side-by-side

added added

removed removed

Lines of Context:
321
321
  cache_dirty = false;
322
322
  return blur_texture_;
323
323
}
 
324
 
 
325
nux::ObjectPtr<nux::IOpenGLBaseTexture> BackgroundEffectHelper::GetRegion(nux::Geometry geo, bool force_update)
 
326
{
 
327
  bool should_update = force_update || cache_dirty;
 
328
 
 
329
  /* Static blur: only update when the size changed */
 
330
  if ((!should_update)
 
331
      && blur_texture_.IsValid()
 
332
      && (geo == blur_geometry_))
 
333
  {
 
334
    return blur_texture_;
 
335
  }
 
336
 
 
337
  nux::GraphicsEngine* graphics_engine = nux::GetGraphicsDisplay()->GetGraphicsEngine();
 
338
  
 
339
  int monitor_width = BackgroundEffectHelper::monitor_rect_.width;
 
340
  int monitor_height = BackgroundEffectHelper::monitor_rect_.height;
 
341
 
 
342
  nux::Geometry temp = geo;
 
343
  temp.OffsetPosition(-monitor_rect_.x, -monitor_rect_.y);
 
344
  blur_geometry_ =  nux::Geometry(0, 0, monitor_width, monitor_height).Intersect(temp);
 
345
 
 
346
  nux::GpuDevice* gpu_device = nux::GetGraphicsDisplay()->GetGpuDevice();
 
347
  if (blur_geometry_.IsNull() || !gpu_device->backup_texture0_.IsValid())
 
348
  {
 
349
    return nux::ObjectPtr<nux::IOpenGLBaseTexture>();
 
350
  }
 
351
 
 
352
  // save the current fbo
 
353
  nux::ObjectPtr<nux::IOpenGLFrameBufferObject> current_fbo = gpu_device->GetCurrentFrameBufferObject();
 
354
  gpu_device->DeactivateFrameBuffer();
 
355
 
 
356
  // Set a viewport to the requested size
 
357
  // FIXME: We need to do multiple passes for the dirty region
 
358
  // on the underlying backup texture so that we're only updating
 
359
  // the bits that we need
 
360
  graphics_engine->SetViewport(0, 0, blur_geometry_.width, blur_geometry_.height);
 
361
  graphics_engine->SetScissor(0, 0, blur_geometry_.width, blur_geometry_.height);
 
362
  // Disable nux scissoring
 
363
  graphics_engine->GetRenderStates ().EnableScissor (false);
 
364
 
 
365
  // The background texture is the same size as the monitor where we are rendering.
 
366
  nux::TexCoordXForm texxform__bg;
 
367
  texxform__bg.flip_v_coord = false;
 
368
  texxform__bg.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);
 
369
  texxform__bg.uoffset = ((float) blur_geometry_.x) / monitor_width;
 
370
  texxform__bg.voffset = ((float) monitor_height - blur_geometry_.y - blur_geometry_.height) / monitor_height;
 
371
 
 
372
  {
 
373
    nux::ObjectPtr<nux::IOpenGLBaseTexture> device_texture = gpu_device->backup_texture0_;
 
374
    nux::ObjectPtr<nux::CachedBaseTexture> noise_device_texture = graphics_engine->CacheResource(noise_texture_);
 
375
 
 
376
    unsigned int offset = 0;
 
377
    int quad_width = blur_geometry_.width;
 
378
    int quad_height = blur_geometry_.height;
 
379
 
 
380
    unsigned int buffer_width = quad_width + 2 * offset;
 
381
    unsigned int buffer_height = quad_height + 2 * offset;
 
382
 
 
383
    texxform__bg.SetFilter(nux::TEXFILTER_NEAREST, nux::TEXFILTER_NEAREST);
 
384
    texxform__bg.flip_v_coord = true;
 
385
 
 
386
    // Copy source texture
 
387
    graphics_engine->QRP_GetCopyTexture(buffer_width, buffer_height,
 
388
                                        blur_texture_, device_texture,
 
389
                                        texxform__bg, nux::color::White);
 
390
  }
 
391
 
 
392
  if (current_fbo.IsValid())
 
393
  {
 
394
    current_fbo->Activate(true);
 
395
    graphics_engine->Push2DWindow(current_fbo->GetWidth(), current_fbo->GetHeight());
 
396
    graphics_engine->GetRenderStates ().EnableScissor (true);
 
397
  }
 
398
  else
 
399
  {
 
400
    graphics_engine->SetViewport(0, 0, monitor_width, monitor_height);
 
401
    graphics_engine->Push2DWindow(monitor_width, monitor_height);
 
402
 
 
403
    graphics_engine->ApplyClippingRectangle();
 
404
  }
 
405
 
 
406
  cache_dirty = false;
 
407
  return blur_texture_;
 
408
}
 
409