Gnash  0.8.11dev
Renderer.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 
19 #ifndef RENDER_HANDLER_H
20 #define RENDER_HANDLER_H
21 
96 
97 
142 
143 
144 #include <vector>
145 #include <boost/noncopyable.hpp>
146 
147 #include "dsodefs.h" // for DSOEXPORT
148 
149 #include "boost/shared_array.hpp"
150 #include "boost/scoped_ptr.hpp"
151 #include "GnashEnums.h"
152 #include "Range2d.h"
153 #include "Point2d.h"
154 #include "RGBA.h"
155 #include "log.h"
156 #include "snappingrange.h"
157 #include "SWFRect.h"
158 
159 // Forward declarations.
160 namespace gnash {
161  class IOChannel;
162  class CachedBitmap;
163  class rgba;
164  class Transform;
165  class SWFMatrix;
166  class FillStyle;
167  class LineStyle;
168  class Shape;
169  class MorphShape;
170 
171  // XXX: GnashImageProxy (delayed image rendering)
172  class GnashVaapiImageProxy;
173 
174  namespace SWF {
175  class ShapeRecord;
176  }
177  namespace image {
178  class GnashImage;
179  }
180 }
181 
182 namespace gnash {
183 
185 //
190 class DSOEXPORT Renderer : boost::noncopyable
191 {
192 public:
193 
195 
196  virtual ~Renderer() {}
197 
199  virtual std::string description() const = 0;
200 
204 
206  virtual void set_scale(float /*xscale*/, float /*yscale*/) {}
207 
211  virtual void set_translation(float /*xoff*/, float /*yoff*/) {}
212 
214 
218 
223  virtual CachedBitmap *
224  createCachedBitmap(std::auto_ptr<image::GnashImage> im) = 0;
225 
226 
230 
232  //
252  virtual void drawVideoFrame(image::GnashImage* frame,
253  const Transform& xform, const SWFRect* bounds, bool smooth) = 0;
254 
256  //
267  virtual void drawLine(const std::vector<point>& coords,
268  const rgba& color, const SWFMatrix& mat) = 0;
269 
271  //
284  virtual void draw_poly(const std::vector<point>& corners,
285  const rgba& fill, const rgba& outline, const SWFMatrix& mat,
286  bool masked) = 0;
287 
288  virtual void drawShape(const SWF::ShapeRecord& shape,
289  const Transform& xform) = 0;
290 
293  //
305  virtual void drawGlyph(const SWF::ShapeRecord& rec, const rgba& color,
306  const SWFMatrix& mat) = 0;
307 
309  //
313  //
318  virtual void renderToImage(boost::shared_ptr<IOChannel> /*io*/,
319  FileType /*type*/, int /*quality*/) const {
320 
321  log_debug(_("Rendering to image not implemented for this "
322  "renderer"));
323  }
324 
325 
329 
331  //
342  virtual void set_invalidated_regions(const InvalidatedRanges& /*ranges*/)
343  {
344  }
345 
349 
351  typedef boost::shared_ptr<GnashVaapiImageProxy> RenderImage;
352  typedef std::vector<RenderImage> RenderImages;
353 
354  // Get first render image
355  virtual RenderImages::const_iterator getFirstRenderImage() const
356  { return _render_images.begin(); }
357 
358  // Get last render image
359  virtual RenderImages::const_iterator getLastRenderImage() const
360  { return _render_images.end(); }
361 
363 
377  virtual void begin_submit_mask() = 0;
378  virtual void end_submit_mask() = 0;
379  virtual void disable_mask() = 0;
381 
385 
387  virtual geometry::Range2d<int> world_to_pixel(const SWFRect& worldbounds)
388  const = 0;
389 
391  const
392  {
393  if ((wb.isNull() || wb.isWorld())) return wb;
394  return world_to_pixel(SWFRect(wb.getMinX(), wb.getMinY(),
395  wb.getMaxX(), wb.getMaxY()));
396  }
397 
399  virtual point pixel_to_world(int x, int y) const = 0;
400 
402  const geometry::Range2d<int>& pixelbounds) const
403  {
404  point topleft = pixel_to_world(
405  pixelbounds.getMinX(), pixelbounds.getMinY());
406  point bottomright = pixel_to_world(
407  pixelbounds.getMaxX(), pixelbounds.getMaxY());
408 
409  return geometry::Range2d<int> (topleft.x, topleft.y,
410  bottomright.x, bottomright.y);
411  }
412 
416  //
425  const {
426  return true;
427  }
428 
429 #ifdef USE_TESTSUITE
430 
431 
435 
436 
443  virtual bool getPixel(rgba& /*color_return*/, int /*x*/, int /*y*/) const {
444 
445  log_debug("getPixel() not implemented for this renderer");
446  abort();
447  return false; // avoid compiler warning
448  }
449 
450  void addRenderImage(boost::shared_ptr<GnashVaapiImageProxy> image) {
451  _render_images.push_back(image);
452  }
453 
464  virtual bool getAveragePixel(rgba& color_return, int x, int y,
465  unsigned int radius) const
466  {
467 
468  assert(radius>0);
469 
470  // optimization:
471  if (radius==1) return getPixel(color_return, x, y);
472 
473  unsigned int r=0, g=0, b=0, a=0;
474 
475  x -= radius/2;
476  y -= radius/2;
477 
478  int xe = x+radius;
479  int ye = y+radius;
480 
481  rgba pixel;
482 
483  for (int yp=y; yp<ye; yp++)
484  for (int xp=x; xp<xe; xp++)
485  {
486  if (!getPixel(pixel, xp, yp))
487  return false;
488 
489  r += pixel.m_r;
490  g += pixel.m_g;
491  b += pixel.m_b;
492  a += pixel.m_a;
493  }
494 
495  int pcount = radius*radius;
496  color_return.m_r = r / pcount;
497  color_return.m_g = g / pcount;
498  color_return.m_b = b / pcount;
499  color_return.m_a = a / pcount;
500 
501  return true;
502  }
503 
524  virtual bool initTestBuffer(unsigned /*width*/, unsigned /*height*/) {
525  return false;
526  }
527 
529  //
535  virtual unsigned int getBitsPerPixel() const {
536  return 0;
537  }
538 
539 #endif
540 
541  class External
542  {
543  public:
545  //
548  External(Renderer& r, const rgba& c, int w = 0, int h = 0,
549  float x0 = 0, float x1 = 0, float y0 = 0, float y1 = 0)
550  :
551  _r(r)
552  {
553  _r.begin_display(c, w, h, x0, x1, y0, y1);
554  }
555 
557  _r.end_display();
558  }
559 
560  private:
561  Renderer& _r;
562  };
563 
564  class Internal
565  {
566  public:
569  :
570  _r(r),
571  _ext(_r.startInternalRender(im))
572  {
573  }
574 
575  Renderer* renderer() const {
576  return _ext;
577  }
578 
580  _r.endInternalRender();
581  }
582 
583  private:
584  Renderer& _r;
585  Renderer* _ext;
586  };
587 
588 protected:
589 
592 
593  // Delayed imaged to render
595 
596 private:
598  //
603  //
606  virtual void begin_display(const rgba& background_color,
607  int viewport_width, int viewport_height,
608  float x0, float x1, float y0, float y1) = 0;
609 
610  virtual void end_display() = 0;
611 
613  //
615  //
617  virtual Renderer* startInternalRender(image::GnashImage& buffer) = 0;
618 
620  //
623  virtual void endInternalRender() = 0;
624 
625 };
626 
627 } // namespace gnash
628 
629 #endif
630 
631 
632 // Local Variables:
633 // mode: C++
634 // indent-tabs-mode: nil
635 // End: