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 19 /// 20 /// Original Author: Visor <cutevisor@gmail.com>. 21 /// Heavily hacked by Rob <rob@welcomehome.org> to work with Gnash 22 /// git master. 23 /// 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 72 class DSOEXPORT Renderer_ovg: public Renderer 73 { 74 public: description()75 std::string description() const { return "OpenVG"; } 76 77 Renderer_ovg(); 78 Renderer_ovg(renderer::GnashDevice::dtype_t dtype); 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 setFillPaint(const VGPaint paint)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 145 /// Analyzes a set of paths to detect real presence of fills and/or outlines 146 /// TODO: This should be something the character tells us and should be 147 /// cached. 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 186 /// this paint object is used for solid, gradient, and pattern fills. 187 VGPaint _fillpaint; 188 189 /// this pain object is used for paths 190 VGPaint _strokepaint; 191 192 /// This stores the Aspect Ratio, which is required to properly 193 /// set the X axis scale. This is usually represented as 4:3 or 194 /// 16:9 for most framebuffers. To get the scale, divide the 2nd 195 /// argument by the first, ie... 4:3 = 3/4 = 0.75. 196 /// The official calculation for the aspect ratio for a monitor of 197 /// 800x480 returns a 5:3 aspect ratio, which for a WVGA LCD 198 /// touchscreen is wrong. The manufacturer specs say it's a 4:3 or 199 /// 16:9, so we use 4:3, which in my testing is correct. 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: 225