diff options
Diffstat (limited to 'src/Updates.cxx')
-rw-r--r-- | src/Updates.cxx | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/Updates.cxx b/src/Updates.cxx new file mode 100644 index 0000000..49f69d5 --- /dev/null +++ b/src/Updates.cxx @@ -0,0 +1,78 @@ +namespace PluggIt { + +class Updates +{ + private DFBUpdates m_updates; + private DFBRegion *m_regions; + + public Updates( unsigned int max_regions = 8 ) { + m_regions = (DFBRegion*) D_CALLOC( max_regions ?: 1, sizeof(DFBRegion) ); + + dfb_updates_init( &m_updates, m_regions, max_regions ); + } + + virtual ~Updates() { + dfb_updates_deinit( &m_updates ); + + D_FREE( m_regions ); + } + + + public void addRegion( const DFBRegion ®ion ) { + dfb_updates_add( &m_updates, ®ion ); + } + + public DFBRegion bounding() const { + return m_updates.bounding; + } + + public void get_rectangles( DFBRectangle *ret_rects, int *ret_num ) { + dfb_updates_get_rectangles( &m_updates, ret_rects, ret_num ); + } + + public unsigned int num_regions() const { + return m_updates.num_regions; + } + + public void reset() { + dfb_updates_reset( &m_updates ); + } + + + public void GetRectangles( vector<DFBRectangle_C> &rects ) { + D_MAGIC_ASSERT( &m_updates, DFBUpdates ); + D_ASSERT( m_updates.regions != NULL ); + D_ASSERT( m_updates.num_regions >= 0 ); + D_ASSERT( m_updates.num_regions <= m_updates.max_regions ); + + switch (m_updates.num_regions) { + case 0: + break; + + default: { + int n, d, total, bounding; + + dfb_updates_stat( &m_updates, &total, &bounding ); + + n = m_updates.max_regions - m_updates.num_regions + 1; + d = n + 1; + + /* Try to optimize updates. Use individual regions only if not too much overhead. */ + if (total < bounding * n / d) { + for (n=0; n<m_updates.num_regions; n++) + rects.push_back( DFBRectangle( m_updates.regions[n] ) ); + + break; + } + } + /* fall through */ + + case 1: + rects.push_back( DFBRectangle( m_updates.bounding ) ); + break; + } + } +}; + +} + |