Gnash  0.8.10
Renderer_gles1.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 
00019 #ifndef GNASH_RENDER_HANDLER_GLES1_H
00020 #define GNASH_RENDER_HANDLER_GLES1_H
00021 
00022 #ifdef HAVE_CONFIG_H
00023 #include "gnashconfig.h"
00024 #endif
00025 
00026 #include <vector>
00027 
00028 // gles-1.0c for Linux
00029 #ifdef HAVE_GLES1_GL_H
00030 # include <GLES/gl.h>
00031 #endif
00032 #ifdef HAVE_GLES1_EGL_H
00033 #include <GLES/egl.h>
00034 #endif
00035 
00036 #include "Renderer.h"
00037 #include "Geometry.h"
00038 #include "egl/eglDevice.h"
00039 
00040 #include <map>
00041 
00042 namespace gnash {
00043 
00044 class GnashImage;
00045 class SWFCxForm;
00046 
00047 namespace renderer {
00048 
00049 namespace gles1 {
00050 
00051 typedef std::vector<const Path*> PathRefs;
00052 
00053 struct oglVertex {
00054     oglVertex(GLfloat x, GLfloat y, GLfloat z = 0.0)
00055         : _x(x), _y(y), _z(z)
00056         {
00057         }
00058     
00059     oglVertex(const point& p)
00060         : _x(p.x), _y(p.y), _z(0.0)
00061         {
00062         }
00063     
00064     GLfloat _x;
00065     GLfloat _y;
00066     GLfloat _z;
00067 };
00068 
00069 typedef std::map<const Path*, std::vector<oglVertex> > PathPointMap;
00070 
00071 class WholeShape
00072 {
00073 public:
00074     void newPath(const Path& new_path)
00075     {
00076         PathRefs refs;
00077         refs.push_back(&new_path); 
00078         shape.push_back(refs);
00079     }
00080   
00081     void addPath(const Path& add_path)
00082     {
00083         PathRefs& refs = shape.back();
00084         refs.push_back(&add_path);
00085     }
00086   
00087     void addPathRefs(const PathRefs& pathrefs)
00088     {
00089         PathRefs new_refs(pathrefs.begin(), pathrefs.end());
00090         shape.push_back(new_refs);
00091     }
00092   
00093     const std::vector<PathRefs>& get() const
00094     {
00095         return shape;
00096     }
00097 private:
00098     std::vector<PathRefs> shape;
00099 };
00100 
00101     class bitmap_info_ogl //: public BitmapInfo
00102 {
00103 public:
00104     
00106     enum bitmap_wrap_mode
00107     {
00108         WRAP_REPEAT,
00109         WRAP_CLAMP
00110     };
00111     
00112     bitmap_info_ogl(GnashImage* image, GLenum pixelformat,
00113                     bool ogl_accessible);
00114     ~bitmap_info_ogl();
00115     
00116     void apply(const gnash::SWFMatrix& bitmap_matrix,
00117                bitmap_wrap_mode wrap_mode) const;
00118 private:
00119     inline bool ogl_accessible() const;
00120     void setup() const;    
00121     void upload(boost::uint8_t* data, size_t width, size_t height) const;
00122     
00123     mutable std::auto_ptr<GnashImage> _img;
00124     GLenum _pixel_format;
00125     GLenum _ogl_img_type;
00126     mutable bool _ogl_accessible;  
00127     mutable GLuint _texture_id;
00128     size_t _orig_width;
00129     size_t _orig_height;
00130 };
00131 
00132 class  DSOEXPORT Renderer_gles1: public Renderer, public EGLDevice
00133 {
00134 public:
00135     std::string description() const { return "OpenGLES1"; }
00136     Renderer_gles1();
00137     Renderer_gles1(GnashDevice::dtype_t dtype);
00138     
00139     ~Renderer_gles1();
00140         
00141     void init(float x, float y);
00142     CachedBitmap *createCachedBitmap(std::auto_ptr<image::GnashImage> im);
00143 
00144     void world_to_pixel(int& x, int& y, float world_x, float world_y) const;
00145     gnash::geometry::Range2d<int> world_to_pixel(const gnash::SWFRect& wb) const;
00146     geometry::Range2d<int> world_to_pixel(const geometry::Range2d<float>& wb) const;
00147     gnash::point pixel_to_world(int, int) const;
00148 
00149     void begin_display(const gnash::rgba&, int, int, float,
00150                                         float, float, float);
00151     // // This is from the patch
00152     // void begin_display(const rgba& bg_color, int viewport_x0,
00153     //                    int viewport_y0, int viewport_width,
00154     //                    int viewport_height, float x0, float x1,
00155     //                    float y0, float y1);
00156     void end_display();
00157     void drawLine(const std::vector<point>& coords, const rgba& fill,
00158                   const SWFMatrix& mat);
00159     void drawVideoFrame(gnash::image::GnashImage *frame, const gnash::Transform& tx,
00160                         const gnash::SWFRect *bounds, bool smooth);
00161     void draw_poly(const std::vector<point>& corners,
00162                   const rgba& fill, const rgba& outline,
00163                   const SWFMatrix& mat, bool masked);
00164     void drawShape(const gnash::SWF::ShapeRecord&, const gnash::Transform&);
00165     void drawGlyph(const SWF::ShapeRecord& rec, const rgba& c,
00166                    const SWFMatrix& mat);
00167 
00168     void set_antialiased(bool enable);
00169     void begin_submit_mask();
00170     void end_submit_mask();
00171     void apply_mask();
00172     void disable_mask();
00173         
00174     void set_scale(float xscale, float yscale);
00175     void set_invalidated_regions(const InvalidatedRanges &ranges);
00176 
00177     // These weren't in the patch
00178     Renderer *startInternalRender(gnash::image::GnashImage&);
00179     void endInternalRender();
00180 
00181     unsigned int getBitsPerPixel();
00182     bool initTestBuffer(unsigned width, unsigned height);
00183 
00184     // These methods are only for debugging and development
00185     void printVGParams();
00186     void printVGHardware();
00187     void printVGPath();
00188   private:
00189     unsigned char *_testBuffer; // buffer used by initTestBuffer() only
00190 };    
00191 
00192 DSOEXPORT Renderer* create_handler(const char *pixelformat);
00193 
00194 } // namespace gnash::renderer::gles1
00195 } // namespace gnash::renderer
00196 } // namespace gnash
00197 
00198 #endif // __RENDER_HANDLER_GLES1_H__
00199 
00200 // local Variables:
00201 // mode: C++
00202 // indent-tabs-mode: nil
00203 // End: