• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

Renderer.h

Go to the documentation of this file.
00001 // 
00002 //     Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
00003 //     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 // 
00020 //
00021 
00022 #ifndef RENDER_HANDLER_H
00023 #define RENDER_HANDLER_H
00024 
00099 
00100     
00145 
00146 
00147 #include <vector>
00148 #include <boost/noncopyable.hpp>
00149 
00150 #include "dsodefs.h" // for DSOEXPORT
00151 
00152 #include "FileTypes.h"
00153 #include "gnash.h" // Quality
00154 #include "Range2d.h"
00155 #include "Point2d.h"
00156 #include "RGBA.h"
00157 #include "log.h"
00158 #include "snappingrange.h"
00159 #include "SWFRect.h"
00160 
00161 // Forward declarations.
00162 namespace gnash {
00163     class CachedBitmap;
00164     class rgba;
00165     class SWFMatrix;
00166     class cxform;
00167     class FillStyle;
00168     class LineStyle;
00169 
00170     // XXX: GnashImageProxy (delayed image rendering)
00171     class GnashVaapiImageProxy;
00172 
00173     namespace SWF {
00174         class ShapeRecord;
00175     }
00176 
00177     class Shape;
00178     class MorphShape;
00179 
00180     class GnashImage;
00181 }
00182 
00183 namespace gnash {
00184 
00186 //
00191 class DSOEXPORT Renderer : boost::noncopyable
00192 {
00193 public:
00194 
00195     Renderer()
00196         :
00197         _quality(QUALITY_HIGH)
00198     {}
00199 
00200     virtual ~Renderer() {}
00201 
00205 
00207     virtual void set_scale(float /*xscale*/, float /*yscale*/) {} 
00208 
00212     virtual void set_translation(float /*xoff*/, float /*yoff*/) {}
00213 
00214     void setQuality(Quality q) { _quality = q; }
00215         
00219     
00224     virtual CachedBitmap* createCachedBitmap(std::auto_ptr<GnashImage> im) = 0;
00225 
00226 
00230 
00232     //
00252     virtual void drawVideoFrame(GnashImage* frame, const SWFMatrix* mat,
00253             const SWFRect* bounds, bool smooth) = 0;
00254 
00256     //
00267     virtual void drawLine(const std::vector<point>& coords,
00268             const rgba& color, const SWFMatrix& mat) = 0;
00269         
00271     //
00284     virtual void draw_poly(const point* corners, size_t corner_count, 
00285         const rgba& fill, const rgba& outline, const SWFMatrix& mat,
00286         bool masked) = 0;
00287         
00288     virtual void drawShape(const SWF::ShapeRecord& shape, const cxform& cx,
00289             const SWFMatrix& worldMat) = 0;
00290         
00293     //
00305     virtual void drawGlyph(const SWF::ShapeRecord& rec, const rgba& color,
00306            const SWFMatrix& mat) = 0;
00307 
00308 
00310     //
00314     //
00319     virtual void renderToImage(boost::shared_ptr<IOChannel> /*io*/,
00320         FileType /*type*/) const {
00321 
00322         log_debug(_("Rendering to image not implemented for this "
00323             "renderer"));
00324     }
00325         
00326 
00330     
00332     //
00344     virtual void set_invalidated_region(const SWFRect& /*bounds*/) {}
00345 
00346     virtual void set_invalidated_regions(const InvalidatedRanges& /*ranges*/)
00347     {        
00348     }
00349     
00351     //
00365     virtual void begin_display(const rgba& background_color, 
00366                     int viewport_width, int viewport_height,
00367                     float x0, float x1, float y0, float y1) = 0;
00368 
00369     virtual void end_display() = 0;
00370 
00374 
00376     typedef boost::shared_ptr<GnashVaapiImageProxy> RenderImage;
00377     typedef std::vector<RenderImage> RenderImages;
00378 
00379     // Get first render image
00380     virtual RenderImages::iterator getFirstRenderImage()
00381             { return _render_images.begin(); }
00382     virtual RenderImages::const_iterator getFirstRenderImage() const
00383             { return _render_images.begin(); }
00384 
00385     // Get last render image
00386     virtual RenderImages::iterator getLastRenderImage()
00387             { return _render_images.end(); }
00388     virtual RenderImages::const_iterator getLastRenderImage() const
00389             { return _render_images.end(); }
00390     
00392         
00406     virtual void begin_submit_mask() = 0;
00407     virtual void end_submit_mask() = 0;
00408     virtual void disable_mask() = 0;
00410     
00414     
00416     virtual geometry::Range2d<int> world_to_pixel(const SWFRect& worldbounds) = 0;
00417     
00419     virtual point pixel_to_world(int x, int y) = 0;
00420     
00421     virtual geometry::Range2d<int> pixel_to_world(
00422                     const geometry::Range2d<int>& pixelbounds)
00423     {
00424         point topleft = pixel_to_world(
00425                         pixelbounds.getMinX(), pixelbounds.getMinY());
00426         point bottomright = pixel_to_world(
00427                         pixelbounds.getMaxX(), pixelbounds.getMaxY());
00428         
00429         return geometry::Range2d<int> (topleft.x, topleft.y, 
00430             bottomright.x, bottomright.y);
00431     }
00432     
00433     virtual geometry::Range2d<int> world_to_pixel(
00434                     const geometry::Range2d<int>& worldbounds)
00435     {
00436         if ((worldbounds.isNull() || worldbounds.isWorld())) return worldbounds;
00437 
00438         // We always get compiler warnings on casting floats to int
00439         // here, so we cast it ourselves to get rid of the warning
00440         // message. Note that in both cases this rounds the float to
00441         // an integer by dropping the decimal part.
00442         return world_to_pixel(SWFRect(static_cast<int>(worldbounds.getMinX()),
00443                                    static_cast<int>(worldbounds.getMinY()),
00444                                    static_cast<int>(worldbounds.getMaxX()),
00445                                    static_cast<int>(worldbounds.getMaxY())));
00446     }
00447         
00451     //
00465     virtual bool bounds_in_clipping_area(const SWFRect& bounds) {
00466         return bounds_in_clipping_area(bounds.getRange());
00467     }
00468     
00469     virtual bool bounds_in_clipping_area(const InvalidatedRanges& ranges)
00470     {
00471         for (unsigned int rno=0; rno<ranges.size(); rno++) 
00472         {
00473             if (bounds_in_clipping_area(ranges.getRange(rno)))
00474                 return true;
00475         }
00476                 
00477         return false;
00478     }
00479     
00480     virtual bool bounds_in_clipping_area(
00481             const geometry::Range2d<int>& /*bounds*/)
00482     {
00483         return true;
00484     }
00485 
00486 #ifdef USE_TESTSUITE
00487 
00491 
00492 
00499     virtual bool getPixel(rgba& /*color_return*/, int /*x*/, int /*y*/) const {
00500 
00501         log_debug("getPixel() not implemented for this renderer");
00502         abort();        
00503         return false; // avoid compiler warning        
00504     }
00505     
00506     
00517     virtual bool getAveragePixel(rgba& color_return, int x, int y, 
00518         unsigned int radius) const
00519     {
00520     
00521         assert(radius>0); 
00522     
00523         // optimization:
00524         if (radius==1) return getPixel(color_return, x, y);
00525     
00526         unsigned int r=0, g=0, b=0, a=0;
00527         
00528         x -= radius/2;
00529         y -= radius/2;
00530         
00531         int xe = x+radius;
00532         int ye = y+radius;
00533 
00534         rgba pixel;
00535         
00536         for (int yp=y; yp<ye; yp++)
00537         for (int xp=x; xp<xe; xp++)
00538         {
00539             if (!getPixel(pixel, xp, yp))
00540                 return false;
00541                 
00542             r += pixel.m_r;            
00543             g += pixel.m_g;            
00544             b += pixel.m_b;            
00545             a += pixel.m_a;            
00546         }
00547         
00548         int pcount = radius*radius; 
00549         color_return.m_r = r / pcount; 
00550         color_return.m_g = g / pcount; 
00551         color_return.m_b = b / pcount; 
00552         color_return.m_a = a / pcount; 
00553         
00554         return true;
00555     }
00556     
00557     
00578     virtual bool initTestBuffer(unsigned /*width*/, unsigned /*height*/) {
00579         return false;
00580     }
00581 
00583     //
00589     virtual unsigned int getBitsPerPixel() const {
00590         return 0;
00591     }
00592     
00593 #endif
00594 
00595 protected:
00596 
00598     Quality _quality;
00599 
00600     // Delayed imaged to render
00601     RenderImages _render_images;
00602 }; 
00603 
00604 } // namespace gnash
00605 
00606 #endif 
00607 
00608 
00609 // Local Variables:
00610 // mode: C++
00611 // indent-tabs-mode: t
00612 // End:

Generated on Thu Sep 30 2010 14:35:02 for Gnash by  doxygen 1.7.1