Gnash  0.8.11dev
OpenVGStyle.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 GNASH_OPENVG_STYLE_H
20 #define GNASH_OPENVG_STYLE_H
21 
22 #include "CachedBitmap.h"
23 #include "GnashImage.h"
24 #include "Renderer.h"
25 #include "FillStyle.h"
26 #include "SWFCxForm.h"
27 #include "SWFMatrix.h"
28 #include "openvg/OpenVGBitmap.h"
29 
30 namespace gnash {
31 
32 // Forward declarations.
33 class SolidFill;
34 class GradientFill;
35 class BitmapFill;
36 class rgba;
37 class StyleHandler;
38 
39 namespace renderer {
40 
41 namespace openvg {
42 
48 
50 struct StyleHandler : boost::static_visitor<>
51 {
53  const VGPaint &p, float x, float y)
54  : _cxform(cx),
55  _vgpaint(p),
56  _x(x),
57  _y(y)
58  {
59  // GNASH_REPORT_FUNCTION;
60  }
61 
62  void operator()(const GradientFill& g) const {
64  SWFMatrix mat = g.matrix();
66  // from OpenVG specification PDF
67  //
68  // dx(x - x0) + dy((y - y0)
69  // g(x,y) = ------------------------
70  // dx^2 + dy^2
71  // where dx = x1 - x0, dy = y1 - y0
72  //
73  int width = 800;
74  int height = 480;
75  const GradientFill::Type fill_type = g.type();
76  OpenVGBitmap* binfo = new OpenVGBitmap(_vgpaint);
77  if (fill_type == GradientFill::LINEAR) {
78  const std::vector<gnash::GradientRecord> &records = g.getRecords();
79  log_debug("Fill Style Type: Linear Gradient, %d records", records.size());
80  // Use the display size for the extent of the shape,
81  // as it'll get clipped by OpenVG at the end of the
82  // shape that is being filled with the gradient.
83  binfo->createLinearBitmap(_x, _y, width, height, _cxform, records, _vgpaint);
84  }
85  if (fill_type == GradientFill::RADIAL) {
86  float focalpt = g.focalPoint();
87  const std::vector<gnash::GradientRecord> &records = g.getRecords();
88  log_debug("Fill Style Type: Radial Gradient: focal is: %d, %d:%d",
89  focalpt, _x, _y);
90  binfo->createRadialBitmap(_x, _y, width, height, focalpt,
91  _cxform, records, _vgpaint);
92  }
93  }
94 
95  void operator()(const SolidFill& f) const {
96  // GNASH_REPORT_FUNCTION;
97  const rgba incolor = f.color();
98  rgba c = _cxform.transform(incolor);
99  VGfloat color[] = {
100  c.m_r / 255.0f,
101  c.m_g / 255.0f,
102  c.m_b / 255.0f,
103  c.m_a / 255.0f
104  };
105 
106  vgSetParameteri (_vgpaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
107  vgSetParameterfv (_vgpaint, VG_PAINT_COLOR, 4, color);
108  }
109 
110  void operator()(const BitmapFill& b) const {
112  SWFMatrix mat = b.matrix();
113  const bool type = b.type();
114  CachedBitmap *cb = const_cast<CachedBitmap *>(b.bitmap());
115  OpenVGBitmap* binfo = new OpenVGBitmap(_vgpaint);
116  if (!cb) {
117  // See misc-swfmill.all/missing_bitmap.swf
118  // _sh.add_color(agg::rgba8_pre(255,0,0,255));
119  } else if ( cb->disposed() ) {
120  // See misc-ming.all/BeginBitmapFill.swf
121  // _sh.add_color(agg::rgba8_pre(0,0,0,0));
122  } else {
123  if (type == BitmapFill::TILED) {
125  cb, _vgpaint);
126  } else if (type == BitmapFill::CLIPPED) {
128  cb, _vgpaint);
129  }
130  }
131  }
132 
133 private:
134  const SWFCxForm& _cxform;
135  const VGPaint& _vgpaint;
136  float _x;
137  float _y;
138 };
139 
140 } // namespace gnash::renderer::openvg
141 } // namespace gnash::renderer
142 } // namespace gnash
143 
144 #endif // __RENDER_OPENVG_STYLE_H__
145 
146 // local Variables:
147 // mode: C++
148 // indent-tabs-mode: nil
149 // End:
const CachedBitmap * bitmap() const
Get the actual Bitmap data.
Definition: FillStyle.cpp:182
std::uint8_t m_b
Definition: RGBA.h:113
OpenVGBitmap * createLinearBitmap(float x0, float y0, float x1, float y1, const SWFCxForm &cx, const GradientFill::GradientRecords &records, const VGPaint paint)
Definition: OpenVGBitmap.cpp:209
Definition: FillStyle.h:162
Type
The type of GradientFill.
Definition: FillStyle.h:160
virtual bool disposed() const =0
Whether the CachedBitmap has been disposed.
Definition: SWFMatrix.h:53
A SolidFill containing one color.
Definition: FillStyle.h:246
void operator()(const GradientFill &g) const
Definition: OpenVGStyle.h:62
void operator()(const BitmapFill &b) const
Definition: OpenVGStyle.h:110
OpenVGBitmap * applyPatternBitmap(const gnash::SWFMatrix &matrix, bitmap_wrap_mode mode, CachedBitmap *bitmap, VGPaint paint)
Definition: OpenVGBitmap.cpp:272
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
type
Definition: GnashKey.h:329
const SWFMatrix & matrix() const
Get the matrix of this BitmapFill.
Definition: FillStyle.h:130
void operator()(const SolidFill &f) const
Definition: OpenVGStyle.h:95
Definition: klash_part.cpp:329
Definition: GnashKey.h:149
Definition: GnashKey.h:152
Definition: FillStyle.h:161
Color transformation record.
Definition: SWFCxForm.h:34
double focalPoint() const
Get the focal point of this GradientFill.
Definition: FillStyle.h:228
std::uint8_t m_g
Definition: RGBA.h:113
const VGfloat color[4]
Definition: testr_gtk.cpp:82
A GradientFill.
Definition: FillStyle.h:153
static void printVGMatrix(VGfloat *mat)
Definition: OpenVGRenderer.cpp:1541
Type type() const
Get the Type of this BitmapFill.
Definition: FillStyle.h:117
Definition: klash_part.cpp:329
Transfer FillStyles to OpenVG styles.
Definition: OpenVGStyle.h:50
std::int32_t x
Definition: BitmapData_as.cpp:434
Definition: OpenVGBitmap.h:39
Definition: GnashKey.h:148
OpenVGBitmap * createRadialBitmap(float x0, float y0, float x1, float y1, float radial, const SWFCxForm &cx, const GradientFill::GradientRecords &records, VGPaint paint)
Definition: OpenVGBitmap.cpp:154
const SWFMatrix & matrix() const
Definition: FillStyle.h:191
std::uint8_t m_a
Definition: RGBA.h:113
std::int32_t y
Definition: BitmapData_as.cpp:435
Definition: GnashKey.h:162
#define GNASH_REPORT_FUNCTION
Definition: log.h:452
Definition: GnashKey.h:153
Type type() const
Definition: FillStyle.h:187
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
const GradientRecords & getRecords() const
Definition: FillStyle.h:203
void log_debug(StringType msg, Args... args)
Definition: log.h:301
StyleHandler(const SWFCxForm &cx, const VGPaint &p, float x, float y)
Definition: OpenVGStyle.h:52
rgba color() const
Get the color of the fill.
Definition: FillStyle.h:268
A BitmapFill.
Definition: FillStyle.h:70
rgba transform(const rgba &in) const
Transform the given color, return the result.
Definition: SWFCxForm.cpp:49
Definition: FillStyle.h:86
Definition: FillStyle.h:87
A basic RGBA type.
Definition: RGBA.h:35