2 // Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012
3 // Free Software Foundation, Inc.
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.
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.
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
21 #include "flash/display/BitmapData_as.h"
22 #include "GnashImage.h"
23 #include "FillStyle.h"
24 #include "DynamicShape.h"
28 #include "movie_root.h"
29 #include "RunResources.h"
30 #include "Transform.h"
31 #include "BitmapMovieDefinition.h"
35 Bitmap::Bitmap(movie_root
& mr
, as_object
* object
, BitmapData_as
* bd
,
36 DisplayObject
* parent
)
38 DisplayObject(mr
, object
, parent
),
40 _width(_bitmapData
->width()),
41 _height(_bitmapData
->height())
43 _shape
.setBounds(SWFRect(0, 0,
44 pixelsToTwips(_width
), pixelsToTwips(_height
)));
46 assert(!bd
->disposed());
49 Bitmap::Bitmap(movie_root
& mr
, as_object
* object
,
50 const BitmapMovieDefinition
* def
, DisplayObject
* parent
)
52 DisplayObject(mr
, object
, parent
),
55 _width(def
->get_width_pixels()),
56 _height(def
->get_height_pixels())
58 _shape
.setBounds(def
->get_frame_size());
66 Bitmap::bitmap() const
68 if (_def
) return _def
->bitmap();
69 if (_bitmapData
) return _bitmapData
->bitmapInfo();
74 Bitmap::construct(as_object
* /*init*/)
76 if (_bitmapData
) _bitmapData
->attach(this);
78 if (!_def
&& !_bitmapData
) return;
80 // Width and height are a maximum of 2880, so there is no risk of
82 const int w
= pixelsToTwips(_width
);
83 const int h
= pixelsToTwips(_height
);
86 mat
.set_scale(1.0 / 20, 1.0 / 20);
88 // Can this be tiled? And smoothing?
89 FillStyle fill
= BitmapFill(BitmapFill::CLIPPED
, bitmap(), mat
,
90 BitmapFill::SMOOTHING_UNSPECIFIED
);
92 const size_t fillLeft
= _shape
.addFillStyle(fill
);
94 Path
bmpath(w
, h
, fillLeft
, 0, 0);
95 bmpath
.drawLineTo(w
, 0);
96 bmpath
.drawLineTo(0, 0);
97 bmpath
.drawLineTo(0, h
);
98 bmpath
.drawLineTo(w
, h
);
100 _shape
.add_path(bmpath
);
101 _shape
.setBounds(SWFRect(0, 0, w
, h
));
108 Bitmap::pointInShape(std::int32_t x
, std::int32_t y
) const
110 return pointInBounds(x
, y
);
114 Bitmap::display(Renderer
& renderer
, const Transform
& base
)
116 /// Don't display cleared Bitmaps.
117 if (!_def
&& !_bitmapData
) return;
119 const Transform xform
= base
* transform();
121 _shape
.display(renderer
, xform
);
126 Bitmap::add_invalidated_bounds(InvalidatedRanges
& ranges
, bool force
)
128 if (!force
&& !invalidated()) return;
130 ranges
.add(m_old_invalidated_ranges
);
133 bounds
.expand_to_transformed_rect(getWorldMatrix(*this), getBounds());
134 ranges
.add(bounds
.getRange());
139 Bitmap::getBounds() const
141 return _shape
.getBounds();
147 /// Nothing to do for disposed bitmaps.
148 if (!_bitmapData
) return;
152 if (_bitmapData
->disposed()) {
153 _bitmapData
= nullptr;