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 <memory>
36 
37 #include "Geometry.h"
38 #include "Renderer.h"
39 //#include "directfb/DirectFBDevice.h"
40 #include "GnashDevice.h"
41 #include "CachedBitmap.h"
42 #include "FillStyle.h"
43 
44 #include <VG/vgu.h>
45 #ifdef HAVE_VG_EXT_H
46 # include <VG/ext.h>
47 #else
48 # ifdef HAVE_VG_VGEXT_H
49 # include <VG/vgext.h>
50 # endif
51 #endif
52 #include <VG/openvg.h>
53 #include "openvg/OpenVGBitmap.h"
54 #include "egl/eglDevice.h"
55 
56 namespace gnash {
57 
58 class SWFCxForm;
59 class GnashImage;
60 
61 namespace renderer {
62 
63 namespace openvg {
64 
65 typedef std::vector<const Path*> PathRefs;
66 typedef std::vector<Path> PathVec;
67 typedef std::vector<geometry::Range2d<int> > ClipBounds;
68 typedef std::vector<const Path*> PathPtrVec;
69 
70 // typedef std::map<const Path*, VGPath > PathPointMap;
71 
73 {
74 public:
75  std::string description() const { return "OpenVG"; }
76 
77  Renderer_ovg();
79 
80  ~Renderer_ovg();
81 
82  void init(float x, float y);
83  CachedBitmap *createCachedBitmap(std::unique_ptr<image::GnashImage> im);
84 
85  void drawVideoFrame(gnash::image::GnashImage*, const gnash::Transform&,
86  const gnash::SWFRect*, bool);
87 
88  void world_to_pixel(int& x, int& y, float world_x, float world_y) const;
89  gnash::geometry::Range2d<int> world_to_pixel(const gnash::SWFRect& wb) const;
90  gnash::geometry::Range2d<int> world_to_pixel(const geometry::Range2d<float>& wb) const;
91 
92  gnash::point pixel_to_world(int, int) const;
93 
94  // Called by movie_root::display()
95  void begin_display(const gnash::rgba&, int, int, float,
96  float, float, float);
97  void end_display();
98  void drawLine(const std::vector<point>& coords, const rgba& fill,
99  const SWFMatrix& mat);
100  void drawVideoFrame(image::GnashImage* frame, const SWFMatrix *m,
101  const SWFRect* bounds, bool smooth);
102  void draw_poly(const std::vector<point>& corners,
103  const rgba& fill, const rgba& outline,
104  const SWFMatrix& mat, bool masked);
105  // this is in master
106  void drawShape(const gnash::SWF::ShapeRecord&, const gnash::Transform&);
107  // This is from the patch
108  void drawGlyph(const SWF::ShapeRecord& rec, const rgba& c,
109  const SWFMatrix& mat);
110 
111  void set_antialiased(bool enable);
112  void begin_submit_mask();
113  void end_submit_mask();
114  void apply_mask();
115  void disable_mask();
116 
117  void set_scale(float xscale, float yscale);
118  void set_invalidated_regions(const InvalidatedRanges &ranges);
119 
120  // These weren't in the patch, and do nothing anyway
121  Renderer *startInternalRender(gnash::image::GnashImage&);
122  void endInternalRender();
123 
124  unsigned int getBitsPerPixel();
125 
126  void setFillPaint(const VGPaint paint) { _fillpaint = paint; }
127 
128  // These methods are only for debugging and development
129  void printVGParams();
130  void printVGHardware();
131  static void printVGPath(VGPath path);
132  static void printVGMatrix(VGfloat *mat);
133  static void printVGMatrix(const SWFMatrix &mat);
134 
135  static const char *getErrorString(VGErrorCode error);
136 
137  // VGImage (CachedBitmap *x) { return _image_cache[x]; };
138  private:
139  void add_paths(const PathVec& path_vec);
140  Path reverse_path(const Path& cur_path);
141  const Path* find_connecting_path(const Path& to_connect,
142  std::list<const Path*> path_refs);
143  PathVec normalize_paths(const PathVec &paths);
144 
148  void analyze_paths(const PathVec &paths, bool& have_shape,
149  bool& have_outline);
150  void apply_fill_style(const FillStyle& style, const SWFMatrix& /* mat */,
151  const SWFCxForm& cx);
152  bool apply_line_style(const LineStyle& style, const SWFCxForm& cx,
153  const SWFMatrix& mat);
154  void draw_outlines(const PathVec& path_vec, const SWFMatrix& mat,
155  const SWFCxForm& cx, const std::vector<
156  LineStyle>& line_styles);
157  std::list<PathPtrVec> get_contours(const PathPtrVec &paths);
158  PathPtrVec paths_by_style(const PathVec& path_vec, unsigned int style);
159  std::vector<PathVec::const_iterator> find_subshapes(const PathVec& path_vec);
160  void apply_matrix_to_paths(std::vector<Path>& paths, const SWFMatrix& mat);
161 
162  void draw_subshape(const PathVec& path_vec, const SWFMatrix& mat,
163  const SWFCxForm& cx,
164  const std::vector<FillStyle>& fill_styles,
165  const std::vector<LineStyle>& line_styles);
166  void draw_mask(const PathVec& path_vec);
167  void draw_submask(const PathVec& path_vec, const SWFMatrix& mat,
168  const SWFCxForm& cx, const FillStyle& f_style);
169 
170  float _xscale;
171  float _yscale;
172  float _width; // Width of the movie, in world coordinates.
173  float _height;
174 
175  // Output size.
176  float _display_width;
177  float _display_height;
178 
179  std::vector<PathVec> _masks;
180  bool _drawing_mask;
181 #ifdef OPENVG_VERSION_1_1
182  VGMaskLayer _mask_layer;
183 #endif
184  gnash::SWFMatrix stage_matrix; // conversion from TWIPS to pixels
185 
187  VGPaint _fillpaint;
188 
190  VGPaint _strokepaint;
191 
200  double _aspect_ratio;
201 
202  // FIXME: A cache for the VGImages might make some sense assuming
203  // it takes more time to render the cached GnashImage to a
204  // VGImage. Right now every til a fill style is applied, the
205  // VGImage is rebuilt from the GnashImage. This appears to be
206  // relatively fast, and possibly faster than the lookup in a map
207  // as the size of the cache grows. The other issue would be when
208  // to clear the cache, as we have no knowledge from the VM when
209  // images are deleted, or unused.
210  // std::map<CachedBitmap *, VGImage > _image_cache;
211 };
212 
213 DSOEXPORT Renderer* create_handler(const char *pixelformat);
214 
215 } // namespace gnash::renderer::openvg
216 } // namespace gnash::renderer
217 } // namespace gnash
218 
219 #endif // __RENDER_HANDLER_OVG_H__
220 
221 // local Variables:
222 // mode: C++
223 // indent-tabs-mode: nil
224 // End:
std::vector< Path > PathVec
Definition: OpenVGRenderer.h:66
VGPaint fill
Definition: testr_gtk.cpp:86
Definition: SWFMatrix.h:53
VGPath path
Definition: testr_gtk.cpp:84
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
dtype_t
The list of supported device types.
Definition: GnashDevice.h:48
void setFillPaint(const VGPaint paint)
Definition: OpenVGRenderer.h:126
std::vector< geometry::Range2d< int > > ClipBounds
Definition: OpenVGRenderer.h:67
2D Point class
Definition: Point2d.h:38
Definition: GnashKey.h:149
Color transformation record.
Definition: SWFCxForm.h:34
Base class for render handlers.
Definition: Renderer.h:188
std::vector< const Path * > PathPtrVec
Definition: OpenVGRenderer.cpp:895
DSOEXPORT Renderer * create_handler(const char *)
Definition: OpenVGRenderer.cpp:1265
std::vector< const Path * > PathRefs
Definition: OpenVGRenderer.h:65
FillStyle describes the various fill styles for shapes.
Definition: FillStyle.h:281
A subset of a shape, a series of edges sharing a single set of styles.
Definition: Geometry.h:166
Definition: OpenVGRenderer.h:72
std::int32_t x
Definition: BitmapData_as.cpp:434
#define DSOEXPORT
Definition: dsodefs.h:55
For the outside of outline shapes, or just bare lines.
Definition: LineStyle.h:50
std::int32_t y
Definition: BitmapData_as.cpp:435
Base class for different types of bitmaps.
Definition: GnashImage.h:77
Rectangle class, see swf defined rectangle record.
Definition: SWFRect.h:44
Definition: GnashKey.h:159
A CachedBitmap is created by the renderer in a format of its choosing.
Definition: CachedBitmap.h:37
std::string description() const
Return a description of this renderer.
Definition: OpenVGRenderer.h:75
VGPaint paint
Definition: testr_gtk.cpp:85
Holds information needed to draw a shape.
Definition: ShapeRecord.h:126
The Transform class expresses a stage in a cumulative transformation.
Definition: Transform.h:33
A basic RGBA type.
Definition: RGBA.h:35