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 "GnashEnums.h"
150 #include "Range2d.h"
151 #include "Point2d.h"
152 #include "RGBA.h"
153 #include "log.h"
154 #include "snappingrange.h"
155 #include "SWFRect.h"
156 
157 // Forward declarations.
158 namespace gnash {
159  class IOChannel;
160  class CachedBitmap;
161  class rgba;
162  class Transform;
163  class SWFMatrix;
164  class FillStyle;
165  class LineStyle;
166  class Shape;
167  class MorphShape;
168 
169  // XXX: GnashImageProxy (delayed image rendering)
170  class GnashVaapiImageProxy;
171 
172  namespace SWF {
173  class ShapeRecord;
174  }
175  namespace image {
176  class GnashImage;
177  }
178 }
179 
180 namespace gnash {
181 
183 //
188 class DSOEXPORT Renderer : boost::noncopyable
189 {
190 public:
191 
192  Renderer(): _quality(QUALITY_HIGH) { }
193 
194  virtual ~Renderer() {}
195 
197  virtual std::string description() const = 0;
198 
202 
204  virtual void set_scale(float /*xscale*/, float /*yscale*/) {}
205 
209  virtual void set_translation(float /*xoff*/, float /*yoff*/) {}
210 
211  void setQuality(Quality q) { _quality = q; }
212 
216 
221  virtual CachedBitmap *
222  createCachedBitmap(std::unique_ptr<image::GnashImage> im) = 0;
223 
224 
228 
230  //
250  virtual void drawVideoFrame(image::GnashImage* frame,
251  const Transform& xform, const SWFRect* bounds, bool smooth) = 0;
252 
254  //
265  virtual void drawLine(const std::vector<point>& coords,
266  const rgba& color, const SWFMatrix& mat) = 0;
267 
269  //
282  virtual void draw_poly(const std::vector<point>& corners,
283  const rgba& fill, const rgba& outline, const SWFMatrix& mat,
284  bool masked) = 0;
285 
286  virtual void drawShape(const SWF::ShapeRecord& shape,
287  const Transform& xform) = 0;
288 
291  //
303  virtual void drawGlyph(const SWF::ShapeRecord& rec, const rgba& color,
304  const SWFMatrix& mat) = 0;
305 
307  //
311  //
316  virtual void renderToImage(std::unique_ptr<IOChannel> /*io*/,
317  FileType /*type*/, int /*quality*/) const {
318 
319  log_debug(_("Rendering to image not implemented for this "
320  "renderer"));
321  }
322 
323 
327 
329  //
340  virtual void set_invalidated_regions(const InvalidatedRanges& /*ranges*/)
341  {
342  }
343 
347 
349  typedef std::shared_ptr<GnashVaapiImageProxy> RenderImage;
350  typedef std::vector<RenderImage> RenderImages;
351 
352  // Get first render image
353  virtual RenderImages::const_iterator getFirstRenderImage() const
354  { return _render_images.begin(); }
355 
356  // Get last render image
357  virtual RenderImages::const_iterator getLastRenderImage() const
358  { return _render_images.end(); }
359 
361 
375  virtual void begin_submit_mask() = 0;
376  virtual void end_submit_mask() = 0;
377  virtual void disable_mask() = 0;
379 
383 
385  virtual geometry::Range2d<int> world_to_pixel(const SWFRect& worldbounds)
386  const = 0;
387 
389  const
390  {
391  if ((wb.isNull() || wb.isWorld())) return wb;
392  return world_to_pixel(SWFRect(wb.getMinX(), wb.getMinY(),
393  wb.getMaxX(), wb.getMaxY()));
394  }
395 
397  virtual point pixel_to_world(int x, int y) const = 0;
398 
400  const geometry::Range2d<int>& pixelbounds) const
401  {
402  point topleft = pixel_to_world(
403  pixelbounds.getMinX(), pixelbounds.getMinY());
404  point bottomright = pixel_to_world(
405  pixelbounds.getMaxX(), pixelbounds.getMaxY());
406 
407  return geometry::Range2d<int> (topleft.x, topleft.y,
408  bottomright.x, bottomright.y);
409  }
410 
414  //
423  const {
424  return true;
425  }
426 
427 #ifdef USE_TESTSUITE
428 
429 
433 
434 
441  virtual bool getPixel(rgba& /*color_return*/, int /*x*/, int /*y*/) const {
442 
443  log_debug("getPixel() not implemented for this renderer");
444  abort();
445  return false; // avoid compiler warning
446  }
447 
448  void addRenderImage(std::shared_ptr<GnashVaapiImageProxy> image) {
449  _render_images.push_back(image);
450  }
451 
462  virtual bool getAveragePixel(rgba& color_return, int x, int y,
463  unsigned int radius) const
464  {
465 
466  assert(radius>0);
467 
468  // optimization:
469  if (radius==1) return getPixel(color_return, x, y);
470 
471  unsigned int r=0, g=0, b=0, a=0;
472 
473  x -= radius/2;
474  y -= radius/2;
475 
476  int xe = x+radius;
477  int ye = y+radius;
478 
479  rgba pixel;
480 
481  for (int yp=y; yp<ye; yp++)
482  for (int xp=x; xp<xe; xp++)
483  {
484  if (!getPixel(pixel, xp, yp))
485  return false;
486 
487  r += pixel.m_r;
488  g += pixel.m_g;
489  b += pixel.m_b;
490  a += pixel.m_a;
491  }
492 
493  int pcount = radius*radius;
494  color_return.m_r = r / pcount;
495  color_return.m_g = g / pcount;
496  color_return.m_b = b / pcount;
497  color_return.m_a = a / pcount;
498 
499  return true;
500  }
501 
522  virtual bool initTestBuffer(unsigned /*width*/, unsigned /*height*/) {
523  return false;
524  }
525 
527  //
533  virtual unsigned int getBitsPerPixel() const {
534  return 0;
535  }
536 
537 #endif
538 
539  class External
540  {
541  public:
543  //
546  External(Renderer& r, const rgba& c, int w = 0, int h = 0,
547  float x0 = 0, float x1 = 0, float y0 = 0, float y1 = 0)
548  :
549  _r(r)
550  {
551  _r.begin_display(c, w, h, x0, x1, y0, y1);
552  }
553 
555  _r.end_display();
556  }
557 
558  private:
559  Renderer& _r;
560  };
561 
562  class Internal
563  {
564  public:
567  :
568  _r(r),
569  _ext(_r.startInternalRender(im))
570  {
571  }
572 
573  Renderer* renderer() const {
574  return _ext;
575  }
576 
578  _r.endInternalRender();
579  }
580 
581  private:
582  Renderer& _r;
583  Renderer* _ext;
584  };
585 
586 protected:
587 
590 
591  // Delayed imaged to render
592  RenderImages _render_images;
593 
594 private:
596  //
601  //
604  virtual void begin_display(const rgba& background_color,
605  int viewport_width, int viewport_height,
606  float x0, float x1, float y0, float y1) = 0;
607 
608  virtual void end_display() = 0;
609 
611  //
613  //
615  virtual Renderer* startInternalRender(image::GnashImage& buffer) = 0;
616 
618  //
621  virtual void endInternalRender() = 0;
622 
623 };
624 
625 } // namespace gnash
626 
627 #endif
628 
629 
630 // Local Variables:
631 // mode: C++
632 // indent-tabs-mode: nil
633 // End:
Definition: GnashKey.h:147
virtual bool bounds_in_clipping_area(const geometry::Range2d< int > &) const
Checks if the given bounds are (partially) in the current drawing clipping area.
Definition: Renderer.h:422
External(Renderer &r, const rgba &c, int w=0, int h=0, float x0=0, float x1=0, float y0=0, float y1=0)
Prepare the renderer for external rendering.
Definition: Renderer.h:546
FileType
Definition: GnashEnums.h:25
std::shared_ptr< GnashVaapiImageProxy > RenderImage
Definition: Renderer.h:349
bool isNull() const
Returns true if this is the NULL Range2d.
Definition: Range2d.h:181
std::uint8_t m_b
Definition: RGBA.h:113
Definition: GnashEnums.h:38
T getMinY() const
Get min Y ordinate.
Definition: Range2d.h:623
VGPaint fill
Definition: testr_gtk.cpp:86
~External()
Definition: Renderer.h:554
virtual void set_invalidated_regions(const InvalidatedRanges &)
Sets the update region (called prior to begin_display).
Definition: Renderer.h:340
Definition: SWFMatrix.h:53
Definition: GnashKey.h:163
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
RenderImages _render_images
Definition: Renderer.h:592
Quality
Definition: GnashEnums.h:34
virtual RenderImages::const_iterator getFirstRenderImage() const
Definition: Renderer.h:353
geometry::Range2d< int > world_to_pixel(const geometry::Range2d< int > &wb) const
Definition: Renderer.h:388
2D Point class
Definition: Point2d.h:38
Definition: GnashKey.h:149
geometry::Range2d< int > pixel_to_world(const geometry::Range2d< int > &pixelbounds) const
Definition: Renderer.h:399
T getMaxY() const
Get max Y ordinate.
Definition: Range2d.h:633
std::uint8_t m_g
Definition: RGBA.h:113
Base class for render handlers.
Definition: Renderer.h:188
Renderer * renderer() const
Definition: Renderer.h:573
const VGfloat color[4]
Definition: testr_gtk.cpp:82
Definition: GnashKey.h:164
virtual void set_translation(float, float)
Definition: Renderer.h:209
std::vector< RenderImage > RenderImages
Definition: Renderer.h:350
T getMaxX() const
Get max X ordinate.
Definition: Range2d.h:613
Quality _quality
Kept in parallel with movie_root&#39;s setting.
Definition: Renderer.h:589
#define _(String)
Definition: log.h:44
Definition: Renderer.h:539
virtual void set_scale(float, float)
Sets the x/y scale for the movie.
Definition: Renderer.h:204
std::int32_t y
The y coordinate.
Definition: Point2d.h:46
Definition: Renderer.h:562
virtual void renderToImage(std::unique_ptr< IOChannel >, FileType, int) const
Draw the current rendering buffer to an image file.
Definition: Renderer.h:316
~Internal()
Definition: Renderer.h:577
void setQuality(Quality q)
Definition: Renderer.h:211
std::int32_t x
Definition: BitmapData_as.cpp:434
virtual ~Renderer()
Definition: Renderer.h:194
Renderer()
Definition: Renderer.h:192
Definition: GnashKey.h:148
#define DSOEXPORT
Definition: dsodefs.h:55
bool isWorld() const
Returns true if this is the WORLD Range2d.
Definition: Range2d.h:200
std::int32_t x
The x coordinate.
Definition: Point2d.h:43
std::uint8_t m_a
Definition: RGBA.h:113
std::int32_t y
Definition: BitmapData_as.cpp:435
Definition: GnashKey.h:154
Base class for different types of bitmaps.
Definition: GnashImage.h:77
w
Definition: test.py:8
Rectangle class, see swf defined rectangle record.
Definition: SWFRect.h:44
Internal(Renderer &r, image::GnashImage &im)
Prepare the renderer for internal rendering.
Definition: Renderer.h:566
virtual RenderImages::const_iterator getLastRenderImage() const
Definition: Renderer.h:357
Definition: GnashKey.h:153
std::uint8_t m_r
Definition: RGBA.h:113
A CachedBitmap is created by the renderer in a format of its choosing.
Definition: CachedBitmap.h:37
void log_debug(StringType msg, Args... args)
Definition: log.h:301
Holds information needed to draw a shape.
Definition: ShapeRecord.h:126
T getMinX() const
Get min X ordinate.
Definition: Range2d.h:603
Definition: GnashKey.h:331
The Transform class expresses a stage in a cumulative transformation.
Definition: Transform.h:33
A basic RGBA type.
Definition: RGBA.h:35