Gnash  0.8.11dev
OpenVGRenderer.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 // Free Software Foundation, Inc.
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 
24 
25 #ifdef HAVE_CONFIG_H
26 #include "gnashconfig.h"
27 #endif
28 
29 #ifndef GNASH_RENDER_HANDLER_OVG_H
30 #define GNASH_RENDER_HANDLER_OVG_H
31 
32 #include <EGL/egl.h>
33 #include <vector>
34 #include <list>
35 #include <boost/scoped_array.hpp>
36 #include <boost/scoped_ptr.hpp>
37 
38 #include "Geometry.h"
39 #include "Renderer.h"
40 //#include "directfb/DirectFBDevice.h"
41 #include "GnashDevice.h"
42 #include "CachedBitmap.h"
43 #include "FillStyle.h"
44 
45 #include <VG/vgu.h>
46 #ifdef HAVE_VG_EXT_H
47 # include <VG/ext.h>
48 #else
49 # ifdef HAVE_VG_VGEXT_H
50 # include <VG/vgext.h>
51 # endif
52 #endif
53 #include <VG/openvg.h>
54 #include "openvg/OpenVGBitmap.h"
55 #include "egl/eglDevice.h"
56 
57 namespace gnash {
58 
59 class SWFCxForm;
60 class GnashImage;
61 
62 namespace renderer {
63 
64 namespace openvg {
65 
66 typedef std::vector<const Path*> PathRefs;
67 typedef std::vector<Path> PathVec;
68 typedef std::vector<geometry::Range2d<int> > ClipBounds;
69 typedef std::vector<const Path*> PathPtrVec;
70 
71 // typedef std::map<const Path*, VGPath > PathPointMap;
72 
74 {
75 public:
76  std::string description() const { return "OpenVG"; }
77 
78  Renderer_ovg();
80 
81  ~Renderer_ovg();
82 
83  void init(float x, float y);
84  CachedBitmap *createCachedBitmap(std::auto_ptr<image::GnashImage> im);
85 
86  void drawVideoFrame(gnash::image::GnashImage*, const gnash::Transform&,
87  const gnash::SWFRect*, bool);
88 
89  void world_to_pixel(int& x, int& y, float world_x, float world_y) const;
90  gnash::geometry::Range2d<int> world_to_pixel(const gnash::SWFRect& wb) const;
91  gnash::geometry::Range2d<int> world_to_pixel(const geometry::Range2d<float>& wb) const;
92 
93  gnash::point pixel_to_world(int, int) const;
94 
95  // Called by movie_root::display()
96  void begin_display(const gnash::rgba&, int, int, float,
97  float, float, float);
98  void end_display();
99  void drawLine(const std::vector<point>& coords, const rgba& fill,
100  const SWFMatrix& mat);
101  void drawVideoFrame(image::GnashImage* frame, const SWFMatrix *m,
102  const SWFRect* bounds, bool smooth);
103  void draw_poly(const std::vector<point>& corners,
104  const rgba& fill, const rgba& outline,
105  const SWFMatrix& mat, bool masked);
106  // this is in master
107  void drawShape(const gnash::SWF::ShapeRecord&, const gnash::Transform&);
108  // This is from the patch
109  void drawGlyph(const SWF::ShapeRecord& rec, const rgba& c,
110  const SWFMatrix& mat);
111 
112  void set_antialiased(bool enable);
113  void begin_submit_mask();
114  void end_submit_mask();
115  void apply_mask();
116  void disable_mask();
117 
118  void set_scale(float xscale, float yscale);
119  void set_invalidated_regions(const InvalidatedRanges &ranges);
120 
121  // These weren't in the patch, and do nothing anyway
122  Renderer *startInternalRender(gnash::image::GnashImage&);
123  void endInternalRender();
124 
125  unsigned int getBitsPerPixel();
126 
127  void setFillPaint(const VGPaint paint) { _fillpaint = paint; }
128 
129  // These methods are only for debugging and development
130  void printVGParams();
131  void printVGHardware();
132  static void printVGPath(VGPath path);
133  static void printVGMatrix(VGfloat *mat);
134  static void printVGMatrix(const SWFMatrix &mat);
135 
136  static const char *getErrorString(VGErrorCode error);
137 
138  // VGImage (CachedBitmap *x) { return _image_cache[x]; };
139  private:
140  void add_paths(const PathVec& path_vec);
141  Path reverse_path(const Path& cur_path);
142  const Path* find_connecting_path(const Path& to_connect,
143  std::list<const Path*> path_refs);
144  PathVec normalize_paths(const PathVec &paths);
145 
149  void analyze_paths(const PathVec &paths, bool& have_shape,
150  bool& have_outline);
151  void apply_fill_style(const FillStyle& style, const SWFMatrix& /* mat */,
152  const SWFCxForm& cx);
153  bool apply_line_style(const LineStyle& style, const SWFCxForm& cx,
154  const SWFMatrix& mat);
155  void draw_outlines(const PathVec& path_vec, const SWFMatrix& mat,
156  const SWFCxForm& cx, const std::vector<
157  LineStyle>& line_styles);
158  std::list<PathPtrVec> get_contours(const PathPtrVec &paths);
159  PathPtrVec paths_by_style(const PathVec& path_vec, unsigned int style);
160  std::vector<PathVec::const_iterator> find_subshapes(const PathVec& path_vec);
161  void apply_matrix_to_paths(std::vector<Path>& paths, const SWFMatrix& mat);
162 
163  void draw_subshape(const PathVec& path_vec, const SWFMatrix& mat,
164  const SWFCxForm& cx,
165  const std::vector<FillStyle>& fill_styles,
166  const std::vector<LineStyle>& line_styles);
167  void draw_mask(const PathVec& path_vec);
168  void draw_submask(const PathVec& path_vec, const SWFMatrix& mat,
169  const SWFCxForm& cx, const FillStyle& f_style);
170 
171  float _xscale;
172  float _yscale;
173  float _width; // Width of the movie, in world coordinates.
174  float _height;
175 
176  // Output size.
177  float _display_width;
178  float _display_height;
179 
180  std::vector<PathVec> _masks;
181  bool _drawing_mask;
182 #ifdef OPENVG_VERSION_1_1
183  VGMaskLayer _mask_layer;
184 #endif
185  gnash::SWFMatrix stage_matrix; // conversion from TWIPS to pixels
186 
188  VGPaint _fillpaint;
189 
191  VGPaint _strokepaint;
192 
201  double _aspect_ratio;
202 
203  // FIXME: A cache for the VGImages might make some sense assuming
204  // it takes more time to render the cached GnashImage to a
205  // VGImage. Right now every til a fill style is applied, the
206  // VGImage is rebuilt from the GnashImage. This appears to be
207  // relatively fast, and possibly faster than the lookup in a map
208  // as the size of the cache grows. The other issue would be when
209  // to clear the cache, as we have no knowledge from the VM when
210  // images are deleted, or unused.
211  // std::map<CachedBitmap *, VGImage > _image_cache;
212 };
213 
214 DSOEXPORT Renderer* create_handler(const char *pixelformat);
215 
216 } // namespace gnash::renderer::openvg
217 } // namespace gnash::renderer
218 } // namespace gnash
219 
220 #endif // __RENDER_HANDLER_OVG_H__
221 
222 // local Variables:
223 // mode: C++
224 // indent-tabs-mode: nil
225 // End: