Gnash 0.8.10dev
|
00001 // 00002 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011 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 RENDER_HANDLER_H 00020 #define RENDER_HANDLER_H 00021 00096 00097 00142 00143 00144 #include <vector> 00145 #include <boost/noncopyable.hpp> 00146 00147 #include "dsodefs.h" // for DSOEXPORT 00148 00149 #include "GnashEnums.h" 00150 #include "Range2d.h" 00151 #include "Point2d.h" 00152 #include "RGBA.h" 00153 #include "log.h" 00154 #include "snappingrange.h" 00155 #include "SWFRect.h" 00156 00157 // Forward declarations. 00158 namespace gnash { 00159 class IOChannel; 00160 class CachedBitmap; 00161 class rgba; 00162 class Transform; 00163 class SWFMatrix; 00164 class FillStyle; 00165 class LineStyle; 00166 class Shape; 00167 class MorphShape; 00168 00169 // XXX: GnashImageProxy (delayed image rendering) 00170 class GnashVaapiImageProxy; 00171 00172 namespace SWF { 00173 class ShapeRecord; 00174 } 00175 namespace image { 00176 class GnashImage; 00177 } 00178 } 00179 00180 namespace gnash { 00181 00183 // 00188 class DSOEXPORT Renderer : boost::noncopyable 00189 { 00190 public: 00191 00192 Renderer() 00193 : 00194 _quality(QUALITY_HIGH) 00195 {} 00196 00197 virtual ~Renderer() {} 00198 00200 virtual std::string description() const = 0; 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( 00225 std::auto_ptr<image::GnashImage> im) = 0; 00226 00227 00231 00233 // 00253 virtual void drawVideoFrame(image::GnashImage* frame, 00254 const Transform& xform, const SWFRect* bounds, bool smooth) = 0; 00255 00257 // 00268 virtual void drawLine(const std::vector<point>& coords, 00269 const rgba& color, const SWFMatrix& mat) = 0; 00270 00272 // 00285 virtual void draw_poly(const std::vector<point>& corners, 00286 const rgba& fill, const rgba& outline, const SWFMatrix& mat, 00287 bool masked) = 0; 00288 00289 virtual void drawShape(const SWF::ShapeRecord& shape, 00290 const Transform& xform) = 0; 00291 00294 // 00306 virtual void drawGlyph(const SWF::ShapeRecord& rec, const rgba& color, 00307 const SWFMatrix& mat) = 0; 00308 00310 // 00314 // 00319 virtual void renderToImage(boost::shared_ptr<IOChannel> /*io*/, 00320 FileType /*type*/, int /*quality*/) const { 00321 00322 log_debug(_("Rendering to image not implemented for this " 00323 "renderer")); 00324 } 00325 00326 00330 00332 // 00343 virtual void set_invalidated_regions(const InvalidatedRanges& /*ranges*/) 00344 { 00345 } 00346 00350 00352 typedef boost::shared_ptr<GnashVaapiImageProxy> RenderImage; 00353 typedef std::vector<RenderImage> RenderImages; 00354 00355 // Get first render image 00356 virtual RenderImages::const_iterator getFirstRenderImage() const 00357 { return _render_images.begin(); } 00358 00359 // Get last render image 00360 virtual RenderImages::const_iterator getLastRenderImage() const 00361 { return _render_images.end(); } 00362 00364 00378 virtual void begin_submit_mask() = 0; 00379 virtual void end_submit_mask() = 0; 00380 virtual void disable_mask() = 0; 00382 00386 00388 virtual geometry::Range2d<int> world_to_pixel(const SWFRect& worldbounds) 00389 const = 0; 00390 00391 geometry::Range2d<int> world_to_pixel(const geometry::Range2d<int>& wb) 00392 const 00393 { 00394 if ((wb.isNull() || wb.isWorld())) return wb; 00395 return world_to_pixel(SWFRect(wb.getMinX(), wb.getMinY(), 00396 wb.getMaxX(), wb.getMaxY())); 00397 } 00398 00400 virtual point pixel_to_world(int x, int y) const = 0; 00401 00402 geometry::Range2d<int> pixel_to_world( 00403 const geometry::Range2d<int>& pixelbounds) const 00404 { 00405 point topleft = pixel_to_world( 00406 pixelbounds.getMinX(), pixelbounds.getMinY()); 00407 point bottomright = pixel_to_world( 00408 pixelbounds.getMaxX(), pixelbounds.getMaxY()); 00409 00410 return geometry::Range2d<int> (topleft.x, topleft.y, 00411 bottomright.x, bottomright.y); 00412 } 00413 00417 // 00425 virtual bool bounds_in_clipping_area(const geometry::Range2d<int>& /*b*/) 00426 const { 00427 return true; 00428 } 00429 00430 #ifdef USE_TESTSUITE 00431 00435 00436 00443 virtual bool getPixel(rgba& /*color_return*/, int /*x*/, int /*y*/) const { 00444 00445 log_debug("getPixel() not implemented for this renderer"); 00446 abort(); 00447 return false; // avoid compiler warning 00448 } 00449 00470 virtual bool initTestBuffer(unsigned /*width*/, unsigned /*height*/) { 00471 return false; 00472 } 00473 00475 // 00481 virtual unsigned int getBitsPerPixel() const { 00482 return 0; 00483 } 00484 00485 #endif 00486 00487 class External 00488 { 00489 public: 00491 // 00494 External(Renderer& r, const rgba& c, int w = 0, int h = 0, 00495 float x0 = 0, float x1 = 0, float y0 = 0, float y1 = 0) 00496 : 00497 _r(r) 00498 { 00499 _r.begin_display(c, w, h, x0, x1, y0, y1); 00500 } 00501 00502 ~External() { 00503 _r.end_display(); 00504 } 00505 00506 private: 00507 Renderer& _r; 00508 }; 00509 00510 class Internal 00511 { 00512 public: 00514 Internal(Renderer& r, image::GnashImage& im) 00515 : 00516 _r(r), 00517 _ext(_r.startInternalRender(im)) 00518 { 00519 } 00520 00521 Renderer* renderer() const { 00522 return _ext; 00523 } 00524 00525 ~Internal() { 00526 _r.endInternalRender(); 00527 } 00528 00529 private: 00530 Renderer& _r; 00531 Renderer* _ext; 00532 }; 00533 00534 protected: 00535 00537 Quality _quality; 00538 00539 // Delayed imaged to render 00540 RenderImages _render_images; 00541 00542 private: 00543 00545 // 00550 // 00553 virtual void begin_display(const rgba& background_color, 00554 int viewport_width, int viewport_height, 00555 float x0, float x1, float y0, float y1) = 0; 00556 00557 virtual void end_display() = 0; 00558 00560 // 00562 // 00564 virtual Renderer* startInternalRender(image::GnashImage& buffer) = 0; 00565 00567 // 00570 virtual void endInternalRender() = 0; 00571 00572 }; 00573 00574 } // namespace gnash 00575 00576 #endif 00577 00578 00579 // Local Variables: 00580 // mode: C++ 00581 // indent-tabs-mode: t 00582 // End: