Gnash  0.8.10
OpenVGRenderer.h
Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
00003 //   Free Software Foundation, Inc.
00004 // 
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 3 of the License, or
00008 // (at your option) any later version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00018 
00024 
00025 #ifdef HAVE_CONFIG_H
00026 #include "gnashconfig.h"
00027 #endif
00028 
00029 #ifndef GNASH_RENDER_HANDLER_OVG_H
00030 #define GNASH_RENDER_HANDLER_OVG_H
00031 
00032 #include <EGL/egl.h>
00033 #include <vector>
00034 #include <list>
00035 #include <boost/scoped_array.hpp>
00036 #include <boost/scoped_ptr.hpp>
00037 
00038 #include "Geometry.h"
00039 #include "Renderer.h"
00040 //#include "directfb/DirectFBDevice.h"
00041 #include "GnashDevice.h"
00042 #include "CachedBitmap.h"
00043 #include "FillStyle.h"
00044 
00045 #include <VG/vgu.h>
00046 #ifdef HAVE_VG_EXT_H
00047 # include <VG/ext.h>
00048 #else
00049 # ifdef HAVE_VG_VGEXT_H
00050 #  include <VG/vgext.h>
00051 # endif
00052 #endif
00053 #include <VG/openvg.h>
00054 #include "openvg/OpenVGBitmap.h"
00055 #include "egl/eglDevice.h"
00056 
00057 namespace gnash {
00058 
00059 class SWFCxForm;
00060 class GnashImage;
00061 
00062 namespace renderer {
00063 
00064 namespace openvg {
00065 
00066 typedef std::vector<const Path*> PathRefs;
00067 typedef std::vector<Path> PathVec;
00068 typedef std::vector<geometry::Range2d<int> > ClipBounds;
00069 typedef std::vector<const Path*> PathPtrVec;
00070 
00071 // typedef std::map<const Path*, VGPath > PathPointMap;
00072 
00073 class  DSOEXPORT Renderer_ovg: public Renderer
00074 {
00075 public:
00076     std::string description() const { return "OpenVG"; }
00077 
00078     Renderer_ovg();
00079     Renderer_ovg(renderer::GnashDevice::dtype_t dtype);
00080     
00081     ~Renderer_ovg();
00082         
00083     void init(float x, float y);
00084     CachedBitmap *createCachedBitmap(std::auto_ptr<image::GnashImage> im);
00085 
00086     void drawVideoFrame(gnash::image::GnashImage*, const gnash::Transform&,
00087                         const gnash::SWFRect*, bool);
00088 
00089     void world_to_pixel(int& x, int& y, float world_x, float world_y) const;
00090     gnash::geometry::Range2d<int> world_to_pixel(const gnash::SWFRect& wb) const;
00091     gnash::geometry::Range2d<int> world_to_pixel(const geometry::Range2d<float>& wb) const;
00092     
00093     gnash::point pixel_to_world(int, int) const;
00094 
00095     // Called by movie_root::display()
00096     void begin_display(const gnash::rgba&, int, int, float,
00097                        float, float, float);
00098     void end_display();
00099     void drawLine(const std::vector<point>& coords, const rgba& fill,
00100                   const SWFMatrix& mat);
00101     void drawVideoFrame(image::GnashImage* frame, const SWFMatrix *m,
00102                    const SWFRect* bounds, bool smooth);
00103     void draw_poly(const std::vector<point>& corners,
00104                   const rgba& fill, const rgba& outline,
00105                   const SWFMatrix& mat, bool masked);
00106     // this is in master
00107     void drawShape(const gnash::SWF::ShapeRecord&, const gnash::Transform&);
00108     // This is from the patch
00109     void drawGlyph(const SWF::ShapeRecord& rec, const rgba& c,
00110                    const SWFMatrix& mat);
00111 
00112     void set_antialiased(bool enable);
00113     void begin_submit_mask();
00114     void end_submit_mask();
00115     void apply_mask();
00116     void disable_mask();
00117         
00118     void set_scale(float xscale, float yscale);
00119     void set_invalidated_regions(const InvalidatedRanges &ranges);
00120 
00121     // These weren't in the patch, and do nothing anyway
00122     Renderer *startInternalRender(gnash::image::GnashImage&);
00123     void endInternalRender();
00124 
00125     unsigned int getBitsPerPixel();
00126 
00127     void setFillPaint(const VGPaint paint) { _fillpaint = paint; }
00128 
00129     // These methods are only for debugging and development
00130     void printVGParams();
00131     void printVGHardware();
00132     static void printVGPath(VGPath path);
00133     static void printVGMatrix(VGfloat *mat);
00134     static void printVGMatrix(const SWFMatrix &mat);
00135 
00136     static const char *getErrorString(VGErrorCode error);
00137 
00138     // VGImage (CachedBitmap *x) { return _image_cache[x]; };
00139   private:
00140     void add_paths(const PathVec& path_vec);
00141     Path reverse_path(const Path& cur_path);
00142     const Path* find_connecting_path(const Path& to_connect,
00143                                      std::list<const Path*> path_refs);
00144     PathVec normalize_paths(const PathVec &paths);
00145     
00149     void analyze_paths(const PathVec &paths, bool& have_shape,
00150                        bool& have_outline);
00151     void apply_fill_style(const FillStyle& style, const SWFMatrix& /* mat */,
00152                           const SWFCxForm& cx);
00153     bool apply_line_style(const LineStyle& style, const SWFCxForm& cx,
00154                           const SWFMatrix& mat);
00155     void draw_outlines(const PathVec& path_vec, const SWFMatrix& mat,
00156                        const SWFCxForm& cx, const std::vector<
00157                        LineStyle>& line_styles);
00158     std::list<PathPtrVec> get_contours(const PathPtrVec &paths);
00159     PathPtrVec paths_by_style(const PathVec& path_vec, unsigned int style);
00160     std::vector<PathVec::const_iterator> find_subshapes(const PathVec& path_vec);
00161     void apply_matrix_to_paths(std::vector<Path>& paths, const SWFMatrix& mat);
00162     
00163     void draw_subshape(const PathVec& path_vec, const SWFMatrix& mat,
00164                        const SWFCxForm& cx,
00165                        const std::vector<FillStyle>& fill_styles,
00166                        const std::vector<LineStyle>& line_styles);
00167     void draw_mask(const PathVec& path_vec);    
00168     void draw_submask(const PathVec& path_vec, const SWFMatrix& mat,
00169                       const SWFCxForm& cx, const FillStyle& f_style);
00170 
00171     float       _xscale;
00172     float       _yscale;
00173     float       _width; // Width of the movie, in world coordinates.
00174     float       _height;
00175   
00176     // Output size.
00177     float       _display_width;
00178     float       _display_height;
00179   
00180     std::vector<PathVec> _masks;
00181     bool        _drawing_mask;
00182 #ifdef OPENVG_VERSION_1_1
00183     VGMaskLayer _mask_layer;
00184 #endif
00185     gnash::SWFMatrix stage_matrix;  // conversion from TWIPS to pixels
00186     
00188     VGPaint     _fillpaint;
00189 
00191     VGPaint     _strokepaint;
00192 
00201     double      _aspect_ratio;
00202     
00203     // FIXME: A cache for the VGImages might make some sense assuming
00204     // it takes more time to render the cached GnashImage to a
00205     // VGImage. Right now every til a fill style is applied, the
00206     // VGImage is rebuilt from the GnashImage. This appears to be
00207     // relatively fast, and possibly faster than the lookup in a map
00208     // as the size of the cache grows. The other issue would be when
00209     // to clear the cache, as we have no knowledge from the VM when
00210     // images are deleted, or unused.
00211     // std::map<CachedBitmap *, VGImage > _image_cache;
00212 };
00213 
00214 DSOEXPORT Renderer* create_handler(const char *pixelformat);
00215 
00216 } // namespace gnash::renderer::openvg
00217 } // namespace gnash::renderer
00218 } // namespace gnash
00219 
00220 #endif // __RENDER_HANDLER_OVG_H__
00221 
00222 // local Variables:
00223 // mode: C++
00224 // indent-tabs-mode: nil
00225 // End: