Gnash  0.8.11dev
Renderer_cairo.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 
20 #ifndef BACKEND_RENDER_HANDLER_CAIRO_H
21 #define BACKEND_RENDER_HANDLER_CAIRO_H
22 
23 #include <vector>
24 #include <cairo/cairo.h>
25 #include "Renderer.h"
26 #include "Geometry.h"
27 
28 namespace gnash {
29  class Transform;
30  class SWFCxForm;
31 }
32 
33 namespace gnash {
34 
35  typedef std::vector<Path> PathVec;
36  typedef std::vector<const Path*> PathPtrVec;
37 
39 {
40 
41 public:
43  ~Renderer_cairo();
44 
45  std::string description() const { return "Cairo"; }
46 
47  CachedBitmap* createCachedBitmap(std::unique_ptr<image::GnashImage> im);
48 
49  void drawVideoFrame(image::GnashImage* baseframe, const Transform& xform,
50  const SWFRect* bounds, bool smooth);
51 
52  virtual geometry::Range2d<int> world_to_pixel(const SWFRect& worldbounds)
53  const;
54 
55  virtual point pixel_to_world(int x, int y) const;
56 
57  void set_color(const rgba& c);
58 
59  void set_invalidated_regions(const InvalidatedRanges& ranges);
60 
62  return nullptr;
63  }
64 
65  virtual void endInternalRender() {}
66 
67  virtual void begin_display(const rgba& bg_color,
68  int viewport_width, int viewport_height,
69  float x0, float x1, float y0, float y1);
70 
71  virtual void end_display();
72 
73  void set_scale(float xscale, float yscale);
74 
75  void set_translation(float xoff, float yoff);
76 
77  void drawLine(const std::vector<point>& coords, const rgba& color,
78  const SWFMatrix& mat);
79 
80  void draw_poly(const std::vector<point>& corners,
81  const rgba& fill, const rgba& outline,
82  const SWFMatrix& mat, bool masked);
83 
84  void set_antialiased(bool enable);
85 
86  void begin_submit_mask();
87  void end_submit_mask();
88  void disable_mask();
89 
90  void add_path(cairo_t* cr, const Path& cur_path);
91 
92  void apply_line_style(const LineStyle& style, const SWFCxForm& cx,
93  const SWFMatrix& mat);
94 
95  void draw_outlines(const PathVec& path_vec,
96  const std::vector<LineStyle>& line_styles,
97  const SWFCxForm& cx,
98  const SWFMatrix& mat);
99 
100  std::vector<PathVec::const_iterator> find_subshapes(const PathVec& path_vec);
101 
102  void draw_subshape(const PathVec& path_vec,
103  const SWFMatrix& mat, const SWFCxForm& cx,
104  const std::vector<FillStyle>& FillStyles,
105  const std::vector<LineStyle>& line_styles);
106 
107  void draw_mask(const PathVec& path_vec);
108 
109  void add_paths(const PathVec& path_vec);
110 
111  void apply_matrix_to_paths(std::vector<Path>& paths, const SWFMatrix& mat);
112 
113  void drawShape(const SWF::ShapeRecord& shape, const Transform& xform);
114 
115  void drawGlyph(const SWF::ShapeRecord& rec, const rgba& color,
116  const SWFMatrix& mat);
117 
118  void set_context(cairo_t* context);
119 
120  unsigned int getBitsPerPixel() const;
121 
122  bool getPixel(rgba& color_return, int x, int y) const;
123 
124  bool initTestBuffer(unsigned width, unsigned height);
125 
126 private:
128  cairo_t* _cr;
129  std::unique_ptr<std::uint8_t[]> _video_buffer;
130  std::vector<PathVec> _masks;
131  size_t _video_bufsize;
132  bool _drawing_mask;
133  InvalidatedRanges _invalidated_ranges;
134  cairo_matrix_t _stage_mat;
135 };
136 
137 
138 
139 namespace renderer {
140 
142 namespace cairo {
143 
146 
148 void set_context(Renderer* handler, cairo_t* context);
149 
150 } // namespace gnash::renderer::cairo
151 } // namespace gnash::renderer
152 } // namespace gnash
153 
154 #endif // BACKEND_RENDER_HANDLER_CAIRO_H
gnash::geometry::SnappingRanges2d< std::int32_t >
gnash::Renderer_cairo::draw_poly
void draw_poly(const std::vector< point > &corners, const rgba &fill, const rgba &outline, const SWFMatrix &mat, bool masked)
Draw a simple, solid filled polygon with a thin (~1 pixel) outline.
Definition: Renderer_cairo.cpp:719
gnash::CAP_NONE
@ CAP_NONE
Definition: LineStyle.h:39
gnash::geometry::Range2d
2d Range template class
Definition: Range2d.h:78
gnash::Renderer_cairo::~Renderer_cairo
~Renderer_cairo()
Definition: Renderer_cairo.cpp:452
gnash::SWFCxForm::transform
rgba transform(const rgba &in) const
Transform the given color, return the result.
Definition: SWFCxForm.cpp:49
gnash::GradientFill::RADIAL
@ RADIAL
Definition: FillStyle.h:162
gnash::LineStyle::joinStyle
JoinStyle joinStyle() const
Return the join style.
Definition: LineStyle.h:135
gnash::Path::ap
point ap
Start point of the path.
Definition: Geometry.h:179
gnash::Transform::colorTransform
SWFCxForm colorTransform
Definition: Transform.h:60
gnash::Renderer_cairo::description
std::string description() const
Return a description of this renderer.
Definition: Renderer_cairo.h:45
gnash::SolidFill
A SolidFill containing one color.
Definition: FillStyle.h:247
height
@ height
Definition: klash_part.cpp:329
gnash::image::GnashImage::width
size_t width() const
Get the image's width.
Definition: GnashImage.h:126
ShapeRecord.h
gnash::Renderer_cairo::add_paths
void add_paths(const PathVec &path_vec)
Definition: Renderer_cairo.cpp:955
gnash::PathVec
std::vector< Path > PathVec
Definition: Renderer_cairo.h:35
gnash::rgba::m_r
std::uint8_t m_r
Definition: RGBA.h:113
gnash::Renderer_cairo::drawLine
void drawLine(const std::vector< point > &coords, const rgba &color, const SWFMatrix &mat)
Draw a line-strip directly, using a thin, solid line.
Definition: Renderer_cairo.cpp:686
gnash::Renderer_cairo::find_subshapes
std::vector< PathVec::const_iterator > find_subshapes(const PathVec &path_vec)
gnash::QUALITY_BEST
@ QUALITY_BEST
Definition: GnashEnums.h:39
gnash::Renderer_cairo::set_context
void set_context(cairo_t *context)
Definition: Renderer_cairo.cpp:1020
gnash::image::ImageRGB
24-bit RGB bitmap
Definition: GnashImage.h:217
gnash::SWF::FILL_CLIPPED_BITMAP_HARD
@ FILL_CLIPPED_BITMAP_HARD
swf8 (alexis is wrong), non-smoothed / hard edges
Definition: SWF.h:1533
gnash::Edge::ap
point ap
Definition: Geometry.h:50
gnash::Transform::matrix
SWFMatrix matrix
Definition: Transform.h:59
gnash::geometry::Range2d::getMaxY
T getMaxY() const
Get max Y ordinate.
Definition: Range2d.h:633
gnash::Renderer_cairo::draw_outlines
void draw_outlines(const PathVec &path_vec, const std::vector< LineStyle > &line_styles, const SWFCxForm &cx, const SWFMatrix &mat)
Definition: Renderer_cairo.cpp:914
gnash::SWFRect::get_x_max
std::int32_t get_x_max() const
Get the x coordinate of the right-down corner.
Definition: SWFRect.h:122
gnash::SWFRect::getRange
geometry::Range2d< std::int32_t > getRange() const
Construct and return a Range2d object.
Definition: SWFRect.h:222
gnash::renderer::cairo::set_context
DSOEXPORT void set_context(Renderer *handler, cairo_t *context)
Make sure to call this before starting display.
Definition: Renderer_cairo.cpp:1143
y
std::int32_t y
Definition: BitmapData_as.cpp:435
gnash::key::i
@ i
Definition: GnashKey.h:155
LOG_ONCE
#define LOG_ONCE(x)
Definition: log.h:49
gnash::rgba
A basic RGBA type.
Definition: RGBA.h:36
_
#define _(String)
Definition: log.h:44
Renderer.h
gnash::StyleHandler::StyleHandler
StyleHandler()
Definition: Renderer_agg_style.h:442
gnash::SWF::ShapeRecord::subshapes
const Subshapes & subshapes() const
Definition: ShapeRecord.h:158
gnash::SWF::FILL_TILED_BITMAP
@ FILL_TILED_BITMAP
Definition: SWF.h:1526
Geometry.h
gnash::Renderer_cairo::Renderer_cairo
Renderer_cairo()
Implementation of Renderer_cairo class.
Definition: Renderer_cairo.cpp:444
gnash::Renderer_cairo::initTestBuffer
bool initTestBuffer(unsigned width, unsigned height)
Definition: Renderer_cairo.cpp:1031
gnash::FillStyle
FillStyle describes the various fill styles for shapes.
Definition: FillStyle.h:282
gnash::Edge::straight
bool straight() const
Definition: Geometry.h:77
Transform.h
gnash
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:41
gnash::SWF::FILL_CLIPPED_BITMAP
@ FILL_CLIPPED_BITMAP
Definition: SWF.h:1527
gnash::geometry::Range2d::getMaxX
T getMaxX() const
Get max X ordinate.
Definition: Range2d.h:613
gnash::SWF::ShapeRecord::getBounds
const SWFRect & getBounds() const
Definition: ShapeRecord.h:166
gnash::SWFRect::is_null
bool is_null() const
returns true if this is a NULL rectangle
Definition: SWFRect.h:75
gnash::key::g
@ g
Definition: GnashKey.h:153
gnash::SWFRect::get_y_max
std::int32_t get_y_max() const
Get the y coordinate of the right-down corner.
Definition: SWFRect.h:136
gnash::image::GnashImage
Base class for different types of bitmaps.
Definition: GnashImage.h:78
gnash::rgba::m_g
std::uint8_t m_g
Definition: RGBA.h:113
gnash::Renderer
Base class for render handlers.
Definition: Renderer.h:189
gnash::Renderer_cairo::world_to_pixel
virtual geometry::Range2d< int > world_to_pixel(const SWFRect &worldbounds) const
Converts world coordinates to pixel coordinates.
Definition: Renderer_cairo.cpp:575
gnash::key::m
@ m
Definition: GnashKey.h:159
utility.h
PathParser.h
gnash::CAP_SQUARE
@ CAP_SQUARE
Definition: LineStyle.h:40
start
@ start
Definition: klash_part.cpp:330
gnash::GradientRecord::ratio
std::uint8_t ratio
Definition: FillStyle.h:50
gnash::QUALITY_MEDIUM
@ QUALITY_MEDIUM
Definition: GnashEnums.h:37
gnash::SWFCxForm
Color transformation record.
Definition: SWFCxForm.h:35
gnash::geometry::Range2d::getMinX
T getMinX() const
Get min X ordinate.
Definition: Range2d.h:603
gnash::JOIN_BEVEL
@ JOIN_BEVEL
Definition: LineStyle.h:45
__FUNCTION__
#define __FUNCTION__
Definition: log.h:437
GnashImage.h
gnash::SWF::Subshape
Definition: ShapeRecord.h:41
gnash::LineStyle::endCapStyle
CapStyle endCapStyle() const
Return the end cap style.
Definition: LineStyle.h:130
gnash::Renderer_cairo::disable_mask
void disable_mask()
Definition: Renderer_cairo.cpp:790
UNUSED
#define UNUSED(x)
Definition: utility.h:113
gnash::log_error
void log_error(StringType msg, Args... args)
Definition: log.h:283
gnash::image::GnashImage::type
ImageType type() const
Return the ImageType of the image.
Definition: GnashImage.h:91
gnash::geometry::Range2d::isNull
bool isNull() const
Returns true if this is the NULL Range2d.
Definition: Range2d.h:181
gnash::Renderer_cairo::set_invalidated_regions
void set_invalidated_regions(const InvalidatedRanges &ranges)
Sets the update region (called prior to begin_display).
Definition: Renderer_cairo.cpp:611
CachedBitmap.h
gnash::LineStyle::miterLimitFactor
float miterLimitFactor() const
Return the miter limit factor.
Definition: LineStyle.h:140
gnash::SWFRect
Rectangle class, see swf defined rectangle record.
Definition: SWFRect.h:45
Renderer_cairo.h
gnash::Renderer_cairo::begin_display
virtual void begin_display(const rgba &bg_color, int viewport_width, int viewport_height, float x0, float x1, float y0, float y1)
Bracket the displaying of a frame from a movie.
Definition: Renderer_cairo.cpp:617
color
const VGfloat color[4]
Definition: testr_gtk.cpp:82
gnash::key::r
@ r
Definition: GnashKey.h:164
gnash::geometry::Range2d::isWorld
bool isWorld() const
Returns true if this is the WORLD Range2d.
Definition: Range2d.h:200
gnash::Renderer_cairo::getPixel
bool getPixel(rgba &color_return, int x, int y) const
Definition: Renderer_cairo.cpp:1073
fill
VGPaint fill
Definition: testr_gtk.cpp:86
gnash::SWF::FILL_TILED_BITMAP_HARD
@ FILL_TILED_BITMAP_HARD
swf8 (alexis is wrong), non-smoothed / hard edges
Definition: SWF.h:1530
gnash::Renderer_cairo::draw_subshape
void draw_subshape(const PathVec &path_vec, const SWFMatrix &mat, const SWFCxForm &cx, const std::vector< FillStyle > &FillStyles, const std::vector< LineStyle > &line_styles)
Definition: Renderer_cairo.cpp:932
gnash::renderer::opengl::for_each
void for_each(C &container, R(T::*pmf)(const A &), const A &arg)
Definition: Renderer_ogl.cpp:690
gnash::key::a
@ a
Definition: GnashKey.h:147
gnash::GradientRecord::color
rgba color
Definition: FillStyle.h:51
gnash::geometry::Point2d::x
std::int32_t x
The x coordinate.
Definition: Point2d.h:43
gnash::SWFRect::get_x_min
std::int32_t get_x_min() const
Get the x coordinate of the left-up corner.
Definition: SWFRect.h:115
gnash::CAP_ROUND
@ CAP_ROUND
Definition: LineStyle.h:38
gnash::Renderer::_quality
Quality _quality
Kept in parallel with movie_root's setting.
Definition: Renderer.h:589
gnash::Renderer_cairo::draw_mask
void draw_mask(const PathVec &path_vec)
Definition: Renderer_cairo.cpp:944
gnash::GradientFill
A GradientFill.
Definition: FillStyle.h:154
gnash::Renderer_cairo::set_color
void set_color(const rgba &c)
Definition: Renderer_cairo.cpp:604
gnash::SWFMatrix::transform
void transform(geometry::Point2d &p) const
Transform a given point by our SWFMatrix.
Definition: SWFMatrix.cpp:99
gnash::geometry::Range2d::getMinY
T getMinY() const
Get min Y ordinate.
Definition: Range2d.h:623
gnash::Renderer_cairo::drawVideoFrame
void drawVideoFrame(image::GnashImage *baseframe, const Transform &xform, const SWFRect *bounds, bool smooth)
Draws a video frame.
Definition: Renderer_cairo.cpp:487
gnash::get
T * get(as_object *o)
Extract the DisplayObject attached to an object.
Definition: as_object.h:842
gnash::Renderer_cairo::startInternalRender
virtual Renderer * startInternalRender(image::GnashImage &)
Setup the renderer to draw to an internal buffer.
Definition: Renderer_cairo.h:61
gnash::Path
A subset of a shape, a series of edges sharing a single set of styles.
Definition: Geometry.h:167
gnash::key::h
@ h
Definition: GnashKey.h:154
gnash::LineStyle
For the outside of outline shapes, or just bare lines.
Definition: LineStyle.h:51
gnash::geometry::Range2d::width
T width() const
Return width this Range2d.
Definition: Range2d.h:374
gnash::LineStyle::scaleThicknessHorizontally
bool scaleThicknessHorizontally() const
Return true if line thickness should be scaled horizontally.
Definition: LineStyle.h:120
gnash::SWFRect::height
std::int32_t height() const
Return height of this rectangle in TWIPS.
Definition: SWFRect.h:109
gnash::LineStyle::scaleThicknessVertically
bool scaleThicknessVertically() const
Return true if line thickness should be scaled vertically.
Definition: LineStyle.h:115
test.w
w
Definition: test.py:8
gnash::point
geometry::Point2d point
Definition: Point2d.h:143
gnash::key::_1
@ _1
Definition: GnashKey.h:95
gnash::JOIN_ROUND
@ JOIN_ROUND
Definition: LineStyle.h:44
gnash::LineStyle::startCapStyle
CapStyle startCapStyle() const
Return the start cap style.
Definition: LineStyle.h:125
gnash::JOIN_MITER
@ JOIN_MITER
Definition: LineStyle.h:46
gnash::image::scanline
GnashImage::iterator scanline(GnashImage &im, size_t row)
Get a pointer to a given row of any image.
Definition: GnashImage.h:392
gnash::SWFMatrix
Definition: SWFMatrix.h:54
gnash::geometry::Point2d
2D Point class
Definition: Point2d.h:39
gnash::geometry::SnappingRanges2d::size
size_type size() const
Returns the number of ranges in the list.
Definition: snappingrange.h:320
gnash::Renderer_cairo::end_submit_mask
void end_submit_mask()
Definition: Renderer_cairo.cpp:771
ImageIterators.h
gnash::renderer::cairo::create_handler
DSOEXPORT Renderer * create_handler()
Create a render handler.
Definition: Renderer_cairo.cpp:1136
gnash::rgba::m_a
std::uint8_t m_a
Definition: RGBA.h:113
gnash::QUALITY_HIGH
@ QUALITY_HIGH
Definition: GnashEnums.h:38
gnash::LineStyle::get_color
const rgba & get_color() const
Return line color and alpha.
Definition: LineStyle.h:156
gnash::Renderer_cairo::apply_line_style
void apply_line_style(const LineStyle &style, const SWFCxForm &cx, const SWFMatrix &mat)
Definition: Renderer_cairo.cpp:842
gnash::key::f
@ f
Definition: GnashKey.h:152
gnash::LineStyle::getThickness
std::uint16_t getThickness() const
Return thickness of the line, in TWIPS.
Definition: LineStyle.h:110
gnash::Renderer_cairo::drawGlyph
void drawGlyph(const SWF::ShapeRecord &rec, const rgba &color, const SWFMatrix &mat)
Draws a glyph (font character).
Definition: Renderer_cairo.cpp:996
gnash::Renderer_cairo::set_antialiased
void set_antialiased(bool enable)
Definition: Renderer_cairo.cpp:756
gnash::GradientFill::LINEAR
@ LINEAR
Definition: FillStyle.h:161
gnash::geometry::Range2d::height
T height() const
Return height this Range2dangle.
Definition: Range2d.h:385
gnash::Renderer_cairo::createCachedBitmap
CachedBitmap * createCachedBitmap(std::unique_ptr< image::GnashImage > im)
Given an image, returns a pointer to a CachedBitmap class that can later be passed to FillStyleX_bitm...
Definition: Renderer_cairo.cpp:458
gnash::SWFMatrix::concatenate
void concatenate(const SWFMatrix &m)
Concatenate m's transform onto ours.
Definition: SWFMatrix.cpp:148
gnash::key::c
@ c
Definition: GnashKey.h:149
gnash::image::TYPE_RGB
@ TYPE_RGB
Definition: GnashImage.h:49
gnash::GradientRecord
Definition: FillStyle.h:41
gnash::QUALITY_LOW
@ QUALITY_LOW
Definition: GnashEnums.h:36
gnash::Renderer_cairo::drawShape
void drawShape(const SWF::ShapeRecord &shape, const Transform &xform)
Definition: Renderer_cairo.cpp:974
gnash::SWFRect::width
std::int32_t width() const
Return width of this rectangle in TWIPS.
Definition: SWFRect.h:103
gnash::Renderer_cairo
Definition: Renderer_cairo.h:39
gnash::Edge::cp
point cp
Definition: Geometry.h:49
DSOEXPORT
#define DSOEXPORT
Definition: dsodefs.h:55
gnash::PathParser::PathParser
PathParser(const std::vector< Path > &paths, size_t num_styles)
Definition: PathParser.cpp:42
gnash::geometry::Point2d::y
std::int32_t y
The y coordinate.
Definition: Point2d.h:46
gnash::rgba::m_b
std::uint8_t m_b
Definition: RGBA.h:113
gnash::SWF::ShapeRecord
Holds information needed to draw a shape.
Definition: ShapeRecord.h:127
gnash::Renderer_cairo::apply_matrix_to_paths
void apply_matrix_to_paths(std::vector< Path > &paths, const SWFMatrix &mat)
Takes a path and translates it using the given SWFMatrix.
Definition: Renderer_cairo.cpp:965
gnash::Renderer_cairo::set_scale
void set_scale(float xscale, float yscale)
Sets the x/y scale for the movie
Definition: Renderer_cairo.cpp:672
FillStyle.h
gnash::Transform
The Transform class expresses a stage in a cumulative transformation.
Definition: Transform.h:34
gnash::Edge
Defines an edge with a control point and an anchor point.
Definition: Geometry.h:45
gnash::Path::transform
void transform(const SWFMatrix &mat)
Transform all path coordinates according to the given SWFMatrix.
Definition: Geometry.h:443
gnash::geometry::SnappingRanges2d::getRange
const RangeType & getRange(size_type index) const
Returns the range at the specified index.
Definition: snappingrange.h:326
width
@ width
Definition: klash_part.cpp:329
gnash::log_unimpl
void log_unimpl(StringType msg, Args... args)
Definition: log.h:289
gnash::Path::m_edges
std::vector< Edge > m_edges
Edges forming the path.
Definition: Geometry.h:182
gnash::Renderer_cairo::getBitsPerPixel
unsigned int getBitsPerPixel() const
Definition: Renderer_cairo.cpp:1052
gnash::Renderer_cairo::begin_submit_mask
void begin_submit_mask()
Definition: Renderer_cairo.cpp:762
gnash::CachedBitmap
A CachedBitmap is created by the renderer in a format of its choosing.
Definition: CachedBitmap.h:38
x
std::int32_t x
Definition: BitmapData_as.cpp:434
gnash::Renderer_cairo::set_translation
void set_translation(float xoff, float yoff)
Definition: Renderer_cairo.cpp:679
gnash::key::b
@ b
Definition: GnashKey.h:148
data
SimpleBuffer data
Definition: LocalConnection_as.cpp:151
gnash::key::e
@ e
Definition: GnashKey.h:151
gnash::Renderer_cairo::add_path
void add_path(cairo_t *cr, const Path &cur_path)
Definition: Renderer_cairo.cpp:799
gnash::Renderer_cairo::end_display
virtual void end_display()
Definition: Renderer_cairo.cpp:666
gnash::Renderer_cairo::endInternalRender
virtual void endInternalRender()
Finish internal rendering.
Definition: Renderer_cairo.h:65
gnash::image::TYPE_RGBA
@ TYPE_RGBA
Definition: GnashImage.h:50
gnash::SWFRect::get_y_min
std::int32_t get_y_min() const
Get the y coordinate of the left-up corner.
Definition: SWFRect.h:129
gnash::Renderer_cairo::pixel_to_world
virtual point pixel_to_world(int x, int y) const
Converts pixel coordinates to world coordinates (TWIPS)
Definition: Renderer_cairo.cpp:591
gnash::PathPtrVec
std::vector< const Path * > PathPtrVec
Definition: Renderer_cairo.h:36
gnash::image::GnashImage::height
size_t height() const
Get the image's width.
Definition: GnashImage.h:133