~brandontschaefer/unity/bump-to-new-nux-abi

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
 * Copyright (C) 2010 Canonical Ltd
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authored by: Jay Taoko <jay.taoko@canonical.com>
 */

#ifndef BACKGROUND_EFFECT_HELPER_H
#define BACKGROUND_EFFECT_HELPER_H

#include "config.h"

#include <Nux/Nux.h>
#include <NuxGraphics/GLThread.h>
#include <UnityCore/ConnectionManager.h>

namespace unity
{

enum BlurType
{
  BLUR_NONE,
  BLUR_STATIC,
  BLUR_ACTIVE
};

class BackgroundEffectHelper
{
public:
  BackgroundEffectHelper();
  BackgroundEffectHelper(nux::View*);
  ~BackgroundEffectHelper();

  nux::Property<nux::View*> owner;
  nux::Property<bool> enabled;

  nux::ObjectPtr<nux::IOpenGLBaseTexture> GetBlurRegion(bool force_update = false);
  nux::ObjectPtr<nux::IOpenGLBaseTexture> GetRegion(bool force_update = false);
  // We could add more functions here to get different types of effects based on the background texture
  // nux::ObjectPtr<nux::IOpenGLBaseTexture> GetPixelatedRegion(nux::Rect rect, int pixel_size, bool update);

  typedef std::function<nux::Geometry()> GeometryGetterFunc;
  void SetGeometryGetter(GeometryGetterFunc const&);

  void DirtyCache();

  static void ProcessDamage(nux::Geometry const& geo);
  static bool HasDirtyHelpers();
  static bool HasEnabledHelpers();
  static std::vector<nux::Geometry> const& GetBlurGeometries();

  static nux::Property<unity::BlurType> blur_type;
  static nux::Geometry monitor_rect_;

  static sigc::signal<void, nux::Geometry const&> blur_region_needs_update_;

protected:
  static void Register   (BackgroundEffectHelper* self);
  static void Unregister (BackgroundEffectHelper* self);

private:
  static float GetBlurSigma();
  static int GetBlurRadius();
  static void UpdateBlurGeometries();

  void OnEnabledChanged(bool value);
  void OnOwnerChanged(nux::View*);
  void SetupOwner(nux::View*);
  bool UpdateOwnerGeometry();

  nux::ObjectPtr<nux::BaseTexture> noise_texture_;
  nux::ObjectPtr<nux::IOpenGLBaseTexture> blur_texture_;
  nux::ObjectPtr<nux::IOpenGLBaseTexture> resize_tmp_;
  nux::ObjectPtr<nux::IOpenGLBaseTexture> noisy_tmp_;
  nux::FxStructure blur_fx_struct_;
  nux::FxStructure noise_fx_struct_;
  nux::Geometry blur_geometry_;
  nux::Geometry requested_blur_geometry_;
  GeometryGetterFunc geo_getter_func_;
  connection::Manager connections_;

  bool cache_dirty;

  static std::list<BackgroundEffectHelper*> registered_list_;
  static std::vector<nux::Geometry> blur_geometries_;
};

}

#endif