From 27d1e03d7bdf8fcfe7292c06e40bc3e2fca9158e Mon Sep 17 00:00:00 2001 From: Denis Oliver Kropp Date: Tue, 19 Oct 2010 15:56:15 +0200 Subject: pluggit --- src/Updates.cxx | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/Updates.cxx (limited to 'src/Updates.cxx') 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 &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