1 //----------------------------------------------------------------------------
2 // Anti-Grain Geometry (AGG) - Version 2.5
3 // A high quality rendering engine for C++
4 // Copyright (C) 2002-2006 Maxim Shemanarev
5 // Contact: mcseem@antigrain.com
6 //          mcseemagg@yahoo.com
7 //          http://antigrain.com
8 //
9 // AGG is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU General Public License
11 // as published by the Free Software Foundation; either version 2
12 // of the License, or (at your option) any later version.
13 //
14 // AGG is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with AGG; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22 // MA 02110-1301, USA.
23 //----------------------------------------------------------------------------
24 
25 #ifndef AGG_SPAN_ALLOCATOR_INCLUDED
26 #define AGG_SPAN_ALLOCATOR_INCLUDED
27 
28 #include "agg_array.h"
29 
30 namespace agg
31 {
32     //----------------------------------------------------------span_allocator
33     template<class ColorT> class span_allocator
34     {
35     public:
36         typedef ColorT color_type;
37 
38         //--------------------------------------------------------------------
allocate(unsigned span_len)39         AGG_INLINE color_type* allocate(unsigned span_len)
40         {
41             if(span_len > m_span.size())
42             {
43                 // To reduce the number of reallocs we align the
44                 // span_len to 256 color elements.
45                 // Well, I just like this number and it looks reasonable.
46                 //-----------------------
47                 m_span.resize(((span_len + 255) >> 8) << 8);
48             }
49             return &m_span[0];
50         }
51 
span()52         AGG_INLINE color_type* span()               { return &m_span[0]; }
max_span_len()53         AGG_INLINE unsigned    max_span_len() const { return m_span.size(); }
54 
55     private:
56         pod_array<color_type> m_span;
57     };
58 }
59 
60 
61 #endif
62 
63 
64