Back to index

unity  6.0.0
BackgroundEffectHelper.h
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003  * Copyright (C) 2010 Canonical Ltd
00004  *
00005  * This program is free software: you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 3 as
00007  * published by the Free Software Foundation.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  *
00017  * Authored by: Jay Taoko <jay.taoko@canonical.com>
00018  */
00019 
00020 #ifndef BACKGROUND_EFFECT_HELPER_H
00021 #define BACKGROUND_EFFECT_HELPER_H
00022 
00023 #include "config.h"
00024 
00025 #include <Nux/Nux.h>
00026 #include <NuxGraphics/GLThread.h>
00027 
00028 namespace unity
00029 {
00030 
00031 enum BlurType
00032 {
00033   BLUR_NONE,
00034   BLUR_STATIC,
00035   BLUR_ACTIVE
00036 };
00037 
00038 }
00039 
00040 class BackgroundEffectHelper
00041 {
00042 public:
00043   BackgroundEffectHelper();
00044   ~BackgroundEffectHelper();
00045 
00046   nux::Property<nux::View*> owner;
00047   nux::Property<bool> enabled;
00048 
00049   nux::ObjectPtr<nux::IOpenGLBaseTexture> GetBlurRegion(nux::Geometry geo, bool force_update = false);
00050   // We could add more functions here to get different types of effects based on the background texture
00051   nux::ObjectPtr<nux::IOpenGLBaseTexture> GetPixelatedRegion(nux::Rect rect, int pixel_size, bool update);
00052 
00053   nux::ObjectPtr<nux::IOpenGLBaseTexture> GetRegion(nux::Geometry geo, bool force_update = false);
00054 
00055   void DirtyCache();
00056 
00057   static void ProcessDamage(nux::Geometry geo);
00058   static bool HasDirtyHelpers();
00059   static bool HasEnabledHelpers();
00060 
00061   static nux::Property<unity::BlurType> blur_type;
00062   static nux::Property<float> sigma_high;
00063   static nux::Property<float> sigma_med;
00064   static nux::Property<float> sigma_low;
00065   static nux::Property<bool> updates_enabled;
00066   static nux::Property<bool> detecting_occlusions;
00067 
00068   static nux::Geometry monitor_rect_;
00069   
00070   nux::FxStructure blur_fx_struct_;
00071   nux::FxStructure noise_fx_struct_;
00072   
00073 protected:
00074   static void Register   (BackgroundEffectHelper* self);
00075   static void Unregister (BackgroundEffectHelper* self);
00076 
00077 private:
00078   void OnEnabledChanged (bool value);
00079 
00080   nux::BaseTexture*                       noise_texture_;
00081   nux::ObjectPtr<nux::IOpenGLBaseTexture> blur_texture_;
00082   nux::ObjectPtr<nux::IOpenGLBaseTexture> resize_tmp_;
00083   nux::ObjectPtr<nux::IOpenGLBaseTexture> noisy_tmp_;
00084   nux::Geometry blur_geometry_;
00085 
00086   bool cache_dirty;
00087 
00088   static std::list<BackgroundEffectHelper*> registered_list_;
00089 };
00090 
00091 #endif
00092