1 /* === S Y N F I G ========================================================= */ 2 /*! \file synfig/rendering/surface.h 3 ** \brief Surface Header 4 ** 5 ** $Id$ 6 ** 7 ** \legal 8 ** ......... ... 2015 Ivan Mahonin 9 ** 10 ** This package is free software; you can redistribute it and/or 11 ** modify it under the terms of the GNU General Public License as 12 ** published by the Free Software Foundation; either version 2 of 13 ** the License, or (at your option) any later version. 14 ** 15 ** This package is distributed in the hope that it will be useful, 16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 ** General Public License for more details. 19 ** \endlegal 20 */ 21 /* ========================================================================= */ 22 23 /* === S T A R T =========================================================== */ 24 25 #ifndef __SYNFIG_RENDERING_SURFACE_H 26 #define __SYNFIG_RENDERING_SURFACE_H 27 28 /* === H E A D E R S ======================================================= */ 29 30 #include <synfig/color.h> 31 #include <synfig/vector.h> 32 33 #include "resource.h" 34 35 /* === M A C R O S ========================================================= */ 36 37 /* === T Y P E D E F S ===================================================== */ 38 39 /* === C L A S S E S & S T R U C T S ======================================= */ 40 41 namespace synfig 42 { 43 namespace rendering 44 { 45 46 class Surface: public Resource 47 { 48 public: 49 typedef etl::handle<Surface> Handle; 50 51 private: 52 int width; 53 int height; 54 bool created; 55 56 protected: 57 void mark_as_created(bool create = true); 58 virtual bool create_vfunc() = 0; 59 virtual bool assign_vfunc(const Surface &surface) = 0; 60 virtual void destroy_vfunc() = 0; 61 virtual bool get_pixels_vfunc(Color *buffer) const = 0; 62 63 public: 64 // TODO: move to Resource? 65 bool is_temporary; 66 67 Surface(); 68 virtual ~Surface(); 69 70 void set_size(int width, int height); 71 72 bool create(); 73 bool assign(const Color *buffer); 74 bool assign(const Color *buffer, int width, int height); 75 bool assign(const Surface &surface); 76 bool assign(const Handle &surface); 77 void destroy(); 78 79 bool empty() const; get_width()80 int get_width() const { return width; } get_height()81 int get_height() const { return height; } get_pixels_count()82 int get_pixels_count() const { return get_width()*get_height(); } 83 size_t get_buffer_size() const; is_created()84 bool is_created() const { return created; } 85 bool get_pixels(Color *buffer) const; 86 set_size(const VectorInt & x)87 void set_size(const VectorInt &x) 88 { set_size(x[0], x[1]); } get_size()89 VectorInt get_size() const 90 { return VectorInt(get_width(), get_height()); } 91 }; 92 93 } /* end namespace rendering */ 94 } /* end namespace synfig */ 95 96 /* -- E N D ----------------------------------------------------------------- */ 97 98 #endif 99