~tatokis/unity/gcc-72-errors

« back to all changes in this revision

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

  • Committer: Tim Penhey
  • Date: 2011-09-06 01:16:01 UTC
  • mto: This revision was merged to the branch mainline in revision 1507.
  • Revision ID: tim.penhey@canonical.com-20110906011601-bhosif2hg4xadqcq
Fix the leaking Regions on early exit.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
#include <time.h>
23
23
#include <X11/Xregion.h>
 
24
#include <boost/utility.hpp>
 
25
 
24
26
 
25
27
using namespace unity;
26
28
 
38
40
 
39
41
namespace unity
40
42
{
41
 
  /* region must be destroyed after it is used */
42
 
  Region geometryToRegion (nux::Geometry geo)
43
 
  {
44
 
    XRectangle rect;
45
 
    Region     reg;
46
 
 
47
 
    rect.x = geo.x;
48
 
    rect.y = geo.y;
49
 
    rect.width = geo.width;
50
 
    rect.height = geo.height;
51
 
 
52
 
    reg = XCreateRegion ();
53
 
    XUnionRectWithRegion (&rect, reg, reg);
54
 
 
55
 
    return reg;
56
 
  }
 
43
namespace x
 
44
{
 
45
// ::Region from XCreateRegion is ... a pointer to a struct.
 
46
class Region : boost::noncopyable
 
47
{
 
48
public:
 
49
  Region()
 
50
    : region_(::XCreateRegion())
 
51
    {}
 
52
 
 
53
  Region(::Region r)
 
54
    : region_(r)
 
55
    {}
 
56
 
 
57
  ~Region()
 
58
    {
 
59
      ::XDestroyRegion(region_);
 
60
    }
 
61
 
 
62
  operator ::Region()
 
63
    {
 
64
      return region_;
 
65
    }
 
66
private:
 
67
  ::Region region_;
 
68
};
 
69
}
 
70
 
 
71
/* region must be destroyed after it is used */
 
72
Region geometryToRegion(nux::Geometry const& geo)
 
73
{
 
74
  XRectangle rect;
 
75
  Region     reg;
 
76
 
 
77
  rect.x = geo.x;
 
78
  rect.y = geo.y;
 
79
  rect.width = geo.width;
 
80
  rect.height = geo.height;
 
81
 
 
82
  reg = XCreateRegion();
 
83
  XUnionRectWithRegion(&rect, reg, reg);
 
84
 
 
85
  return reg;
 
86
}
57
87
}
58
88
 
59
89
 
146
176
      }
147
177
      else
148
178
      {
149
 
        Region        xregion = unity::geometryToRegion (owner->GetAbsoluteGeometry());
150
 
        Region        damage_intersection     = XCreateRegion();
151
 
        Region        occlusion_intersection   = XCreateRegion();
 
179
        x::Region xregion(unity::geometryToRegion(owner->GetAbsoluteGeometry()));
 
180
        x::Region damage_intersection;
 
181
        x::Region occlusion_intersection;
152
182
 
153
183
        /* Determine if the damage region on screen actually intersected
154
184
         * a blurred region */
179
209
            owner->QueueDraw();
180
210
          }
181
211
        }
182
 
 
183
 
        XDestroyRegion(xregion);
184
 
        XDestroyRegion(damage_intersection);
185
 
        XDestroyRegion(occlusion_intersection);
186
212
      }
187
213
    }
188
214
  }
228
254
 
229
255
nux::ObjectPtr<nux::IOpenGLBaseTexture> BackgroundEffectHelper::GetBlurRegion(nux::Geometry geo, bool force_update)
230
256
{
231
 
  nux::GraphicsEngine* graphics_engine = nux::GetGraphicsDisplay()->GetGraphicsEngine();
232
 
  Region               xregion = unity::geometryToRegion (geo);
233
 
  Region               damage_intersection     = XCreateRegion();
234
 
 
235
257
  bool should_update = updates_enabled() || force_update || cache_dirty;
236
258
 
237
259
  /* Static blur: only update when the size changed */
244
266
 
245
267
  if (damage_region_)
246
268
  {
 
269
    x::Region xregion(unity::geometryToRegion(geo));
 
270
    x::Region damage_intersection;
 
271
 
247
272
    // Handle newly created windows
248
273
    if (popup_region_)
249
274
    {
258
283
 
259
284
    if (XEmptyRegion(damage_intersection) && !force_update)
260
285
      return blur_texture_;
261
 
 
262
 
    XDestroyRegion(xregion);
263
 
    XDestroyRegion(damage_intersection);
264
286
  }
265
287
 
 
288
  nux::GraphicsEngine* graphics_engine = nux::GetGraphicsDisplay()->GetGraphicsEngine();
266
289
  blur_geometry_ =  nux::Geometry(0, 0, graphics_engine->GetWindowWidth(), graphics_engine->GetWindowHeight()).Intersect(geo);
267
290
 
268
291
  if (blur_geometry_.IsNull() || blur_type == BLUR_NONE || !nux::GetGraphicsDisplay()->GetGpuDevice()->backup_texture0_.IsValid())