update version to the release
[gnash.git] / libcore / Bitmap.cpp
blob9a3573a9a3041fb97ccdacef4e9b0dbc96f5fbf4
1 //
2 // Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #include "Bitmap.h"
20 #include "flash/display/BitmapData_as.h"
21 #include "GnashImage.h"
22 #include "FillStyle.h"
23 #include "DynamicShape.h"
24 #include "SWFRect.h"
25 #include "Renderer.h"
26 #include "VM.h"
27 #include "movie_root.h"
28 #include "RunResources.h"
29 #include "Transform.h"
31 namespace gnash {
33 Bitmap::Bitmap(movie_root& mr, as_object* object, BitmapData_as* bd,
34 DisplayObject* parent)
36 DisplayObject(mr, object, parent),
37 _bitmapData(bd),
38 _width(_bitmapData->width()),
39 _height(_bitmapData->height())
41 _shape.setBounds(SWFRect(0, 0,
42 pixelsToTwips(_width), pixelsToTwips(_height)));
43 assert(bd);
44 assert(!bd->disposed());
47 Bitmap::Bitmap(movie_root& mr, as_object* object,
48 const BitmapMovieDefinition* def, DisplayObject* parent)
50 DisplayObject(mr, object, parent),
51 _def(def),
52 _bitmapData(0),
53 _width(def->get_width_pixels()),
54 _height(def->get_height_pixels())
56 _shape.setBounds(def->get_frame_size());
59 Bitmap::~Bitmap()
63 const CachedBitmap*
64 Bitmap::bitmap() const
66 if (_def) return _def->bitmap();
67 if (_bitmapData) return _bitmapData->bitmapInfo();
68 return 0;
71 void
72 Bitmap::construct(as_object* /*init*/)
74 if (_bitmapData) _bitmapData->attach(this);
76 if (!_def && !_bitmapData) return;
78 // Width and height are a maximum of 2880, so there is no risk of
79 // overflow
80 const int w = pixelsToTwips(_width);
81 const int h = pixelsToTwips(_height);
83 SWFMatrix mat;
84 mat.set_scale(1.0 / 20, 1.0 / 20);
86 // Can this be tiled? And smoothing?
87 FillStyle fill = BitmapFill(BitmapFill::CLIPPED, bitmap(), mat,
88 BitmapFill::SMOOTHING_UNSPECIFIED);
90 const size_t fillLeft = _shape.addFillStyle(fill);
92 Path bmpath(w, h, fillLeft, 0, 0, false);
93 bmpath.drawLineTo(w, 0);
94 bmpath.drawLineTo(0, 0);
95 bmpath.drawLineTo(0, h);
96 bmpath.drawLineTo(w, h);
98 _shape.add_path(bmpath);
99 _shape.finalize();
101 set_invalidated();
104 bool
105 Bitmap::pointInShape(boost::int32_t x, boost::int32_t y) const
107 return pointInBounds(x, y);
110 void
111 Bitmap::display(Renderer& renderer, const Transform& base)
113 /// Don't display cleared Bitmaps.
114 if (!_def && !_bitmapData) return;
116 const Transform xform = base * transform();
118 _shape.display(renderer, xform);
119 clear_invalidated();
122 void
123 Bitmap::add_invalidated_bounds(InvalidatedRanges& ranges, bool force)
125 if (!force && !invalidated()) return;
127 ranges.add(m_old_invalidated_ranges);
129 SWFRect bounds;
130 bounds.expand_to_transformed_rect(getWorldMatrix(*this), getBounds());
131 ranges.add(bounds.getRange());
135 SWFRect
136 Bitmap::getBounds() const
138 return _shape.getBounds();
141 void
142 Bitmap::update()
144 /// Nothing to do for disposed bitmaps.
145 if (!_bitmapData) return;
147 set_invalidated();
149 if (_bitmapData->disposed()) {
150 _bitmapData = 0;
151 _shape.clear();