Author: Carlos Lopez <[email protected]>
Date:   Thu Jun  7 21:17:16 2012 +0200

Target_Scanline: Add a virtual method to create a surface instance. It would 
use the current render method to decide which type of surface to create. It has 
to be override by specific targets to make use of the proper surface backend.

---

 synfig-core/src/synfig/target_scanline.cpp |   80 +++++++++++++++++++---------
 synfig-core/src/synfig/target_scanline.h   |    5 ++
 2 files changed, 60 insertions(+), 25 deletions(-)

diff --git a/synfig-core/src/synfig/target_scanline.cpp 
b/synfig-core/src/synfig/target_scanline.cpp
index eea4a79..0fc332c 100644
--- a/synfig-core/src/synfig/target_scanline.cpp
+++ b/synfig-core/src/synfig/target_scanline.cpp
@@ -237,23 +237,30 @@ synfig::Target_Scanline::render(ProgressCallback *cb)
                                }else //use normal rendering...
                                {
                                #endif
-                                       Surface surface;
-
-                                       
if(!context.accelerated_render(&surface,quality,desc,0))
-                                       {
-                                               // For some reason, the 
accelerated renderer failed.
-                                               if(cb)cb->error(_("Accelerated 
Renderer Failure"));
-                                               return false;
-                                       }
-                                       else
+                                       Surface* surface(create_surface());
+                                       if(surface)
                                        {
-                                               // Put the surface we renderer
-                                               // onto the target.
-                                               if(!add_frame(&surface))
+                                               
if(!context.accelerated_render(surface,quality,desc,0))
                                                {
-                                                       
if(cb)cb->error(_("Unable to put surface on target"));
+                                                       // For some reason, the 
accelerated renderer failed.
+                                                       
if(cb)cb->error(_("Accelerated Renderer Failure"));
                                                        return false;
                                                }
+                                               else
+                                               {
+                                                       // Put the surface we 
renderer
+                                                       // onto the target.
+                                                       if(!add_frame(surface))
+                                                       {
+                                                               
if(cb)cb->error(_("Unable to put surface on target"));
+                                                               return false;
+                                                       }
+                                               }
+                                       }
+                                       else
+                                       {
+                                               if(cb)cb->error(_("Not 
supported render method"));
+                                               return false;                   
                        
                                        }
                                #if USE_PIXELRENDERING_LIMIT
                                }
@@ -385,23 +392,31 @@ synfig::Target_Scanline::render(ProgressCallback *cb)
                        }else
                        {
                        #endif
-                               Surface surface;
-
-                               
if(!context.accelerated_render(&surface,quality,desc,cb))
+                               Surface* surface(create_surface());
+                               if(surface)
                                {
-                                       if(cb)cb->error(_("Accelerated Renderer 
Failure"));
-                                       return false;
-                               }
-                               else
-                               {
-                                       // Put the surface we renderer
-                                       // onto the target.
-                                       if(!add_frame(&surface))
+                                       
if(!context.accelerated_render(surface,quality,desc,cb))
                                        {
-                                               if(cb)cb->error(_("Unable to 
put surface on target"));
+                                               if(cb)cb->error(_("Accelerated 
Renderer Failure"));
                                                return false;
                                        }
+                                       else
+                                       {
+                                               // Put the surface we renderer
+                                               // onto the target.
+                                               if(!add_frame(surface))
+                                               {
+                                                       
if(cb)cb->error(_("Unable to put surface on target"));
+                                                       return false;
+                                               }
+                                       }
+                               }
+                               else
+                               {
+                                       if(cb)cb->error(_("Not supported render 
method"));
+                                       return false;                           
                
                                }
+
                        #if USE_PIXELRENDERING_LIMIT
                        }
                        #endif
@@ -427,6 +442,21 @@ synfig::Target_Scanline::render(ProgressCallback *cb)
        return true;
 }
 
+Surface*
+Target_Scanline::create_surface()
+{
+       RenderMethod m(get_render_method());
+       switch(m)
+       {
+               case SOFTWARE:
+                       return new Surface;
+               break;
+               default:
+                       return NULL;
+               break;
+       }
+}
+
 bool
 Target_Scanline::add_frame(const Surface *surface)
 {
diff --git a/synfig-core/src/synfig/target_scanline.h 
b/synfig-core/src/synfig/target_scanline.h
index b02d19d..6b8b4a9 100644
--- a/synfig-core/src/synfig/target_scanline.h
+++ b/synfig-core/src/synfig/target_scanline.h
@@ -55,6 +55,11 @@ public:
 
        //! Renders the canvas to the target
        virtual bool render(ProgressCallback *cb=NULL);
+       
+       //! Obtain a surface pointer based on the render method
+       //! this function has to be overrrided by the derived targets 
+       //! to create the proper Cairo backend surface for each target type.
+       virtual Surface* create_surface(); 
 
        //! Marks the start of a frame
        /*! \return \c true on success, \c false upon an error.


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Synfig-devl mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/synfig-devl

Reply via email to