Gnash
0.8.10
|
00001 // 00002 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 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 GNASH_OPENVG_STYLE_H 00020 #define GNASH_OPENVG_STYLE_H 00021 00022 #include "CachedBitmap.h" 00023 #include "GnashImage.h" 00024 #include "Renderer.h" 00025 #include "FillStyle.h" 00026 #include "SWFCxForm.h" 00027 #include "SWFMatrix.h" 00028 #include "openvg/OpenVGBitmap.h" 00029 00030 namespace gnash { 00031 00032 // Forward declarations. 00033 class SolidFill; 00034 class GradientFill; 00035 class BitmapFill; 00036 class rgba; 00037 class StyleHandler; 00038 00039 namespace renderer { 00040 00041 namespace openvg { 00042 00048 00050 struct StyleHandler : boost::static_visitor<> 00051 { 00052 StyleHandler(const SWFCxForm& cx, 00053 const VGPaint &p, float x, float y) 00054 : _cxform(cx), 00055 _vgpaint(p), 00056 _x(x), 00057 _y(y) 00058 { 00059 // GNASH_REPORT_FUNCTION; 00060 } 00061 00062 void operator()(const GradientFill& g) const { 00063 GNASH_REPORT_FUNCTION; 00064 SWFMatrix mat = g.matrix(); 00065 Renderer_ovg::printVGMatrix(mat); 00066 // from OpenVG specification PDF 00067 // 00068 // dx(x - x0) + dy((y - y0) 00069 // g(x,y) = ------------------------ 00070 // dx^2 + dy^2 00071 // where dx = x1 - x0, dy = y1 - y0 00072 // 00073 int width = 800; 00074 int height = 480; 00075 const GradientFill::Type fill_type = g.type(); 00076 OpenVGBitmap* binfo = new OpenVGBitmap(_vgpaint); 00077 if (fill_type == GradientFill::LINEAR) { 00078 const std::vector<gnash::GradientRecord> &records = g.getRecords(); 00079 log_debug("Fill Style Type: Linear Gradient, %d records", records.size()); 00080 // Use the display size for the extent of the shape, 00081 // as it'll get clipped by OpenVG at the end of the 00082 // shape that is being filled with the gradient. 00083 binfo->createLinearBitmap(_x, _y, width, height, _cxform, records, _vgpaint); 00084 } 00085 if (fill_type == GradientFill::RADIAL) { 00086 float focalpt = g.focalPoint(); 00087 const std::vector<gnash::GradientRecord> &records = g.getRecords(); 00088 log_debug("Fill Style Type: Radial Gradient: focal is: %d, %d:%d", 00089 focalpt, _x, _y); 00090 binfo->createRadialBitmap(_x, _y, width, height, focalpt, 00091 _cxform, records, _vgpaint); 00092 } 00093 } 00094 00095 void operator()(const SolidFill& f) const { 00096 // GNASH_REPORT_FUNCTION; 00097 const rgba incolor = f.color(); 00098 rgba c = _cxform.transform(incolor); 00099 VGfloat color[] = { 00100 c.m_r / 255.0f, 00101 c.m_g / 255.0f, 00102 c.m_b / 255.0f, 00103 c.m_a / 255.0f 00104 }; 00105 00106 vgSetParameteri (_vgpaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR); 00107 vgSetParameterfv (_vgpaint, VG_PAINT_COLOR, 4, color); 00108 } 00109 00110 void operator()(const BitmapFill& b) const { 00111 GNASH_REPORT_FUNCTION; 00112 SWFMatrix mat = b.matrix(); 00113 const bool type = b.type(); 00114 CachedBitmap *cb = const_cast<CachedBitmap *>(b.bitmap()); 00115 OpenVGBitmap* binfo = new OpenVGBitmap(_vgpaint); 00116 if (!cb) { 00117 // See misc-swfmill.all/missing_bitmap.swf 00118 // _sh.add_color(agg::rgba8_pre(255,0,0,255)); 00119 } else if ( cb->disposed() ) { 00120 // See misc-ming.all/BeginBitmapFill.swf 00121 // _sh.add_color(agg::rgba8_pre(0,0,0,0)); 00122 } else { 00123 if (type == BitmapFill::TILED) { 00124 binfo->applyPatternBitmap(mat, OpenVGBitmap::WRAP_REPEAT, 00125 cb, _vgpaint); 00126 } else if (type == BitmapFill::CLIPPED) { 00127 binfo->applyPatternBitmap(mat, OpenVGBitmap::WRAP_PAD, 00128 cb, _vgpaint); 00129 } 00130 } 00131 } 00132 00133 private: 00134 const SWFCxForm& _cxform; 00135 const VGPaint& _vgpaint; 00136 float _x; 00137 float _y; 00138 }; 00139 00140 } // namespace gnash::renderer::openvg 00141 } // namespace gnash::renderer 00142 } // namespace gnash 00143 00144 #endif // __RENDER_OPENVG_STYLE_H__ 00145 00146 // local Variables: 00147 // mode: C++ 00148 // indent-tabs-mode: nil 00149 // End: