~ubuntu-branches/ubuntu/saucy/gnash/saucy-proposed

« back to all changes in this revision

Viewing changes to libcore/Bitmap.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Sindhudweep Narayan Sarkar
  • Date: 2009-10-07 00:06:10 UTC
  • mfrom: (1.1.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20091007000610-mj9rwqe774gizn1j
Tags: 0.8.6-0ubuntu1
new upstream release 0.8.6 (LP: #435897)

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#include "Bitmap.h"
20
20
#include "flash/display/BitmapData_as.h"
21
21
#include "GnashImage.h"
 
22
#include "fill_style.h"
22
23
#include "DynamicShape.h"
23
24
#include "rect.h"
 
25
#include "Renderer.h"
 
26
#include "VM.h"
 
27
#include "movie_root.h"
24
28
 
25
29
namespace gnash {
26
30
 
27
 
Bitmap::Bitmap(boost::intrusive_ptr<BitmapData_as> bd, character* parent,
 
31
Bitmap::Bitmap(boost::intrusive_ptr<BitmapData_as> bd, DisplayObject* parent,
28
32
        int id)
29
33
    :
30
 
    character(parent, id),
 
34
    DisplayObject(parent, id),
31
35
    _bitmapData(bd),
32
36
    _bitmapInfo(0),
33
 
    _shapeDef(new DynamicShape),
34
37
    _width(_bitmapData->getWidth()),
35
38
    _height(_bitmapData->getHeight())
36
39
{
37
 
    _shapeDef->set_bound(rect(0, 0, _width * 20, _height * 20));
 
40
    _shape.setBounds(rect(0, 0, pixelsToTwips(_width), pixelsToTwips(_height)));
38
41
}
39
42
 
 
43
Bitmap::Bitmap(const BitmapMovieDefinition* const def, DisplayObject* parent,
 
44
        int id)
 
45
    :
 
46
    DisplayObject(parent, id),
 
47
    _def(def),
 
48
    _bitmapInfo(0),
 
49
    _width(twipsToPixels(def->get_frame_size().width())),
 
50
    _height(twipsToPixels(def->get_frame_size().height()))
 
51
{
 
52
    _shape.setBounds(def->get_frame_size());
 
53
}
40
54
 
41
55
Bitmap::~Bitmap()
42
56
{
43
57
}
44
58
 
 
59
const BitmapInfo*
 
60
Bitmap::bitmap() const
 
61
{
 
62
    if (_def) return _def->bitmap();
 
63
    return _bitmapInfo.get();
 
64
}
45
65
 
46
66
void
47
67
Bitmap::stagePlacementCallback(as_object* initObj)
48
68
{
49
69
    assert(!initObj);
50
 
 
51
 
    _bitmapData->registerBitmap(this);
 
70
    if (_bitmapData) _bitmapData->registerBitmap(this);
52
71
    update();
53
72
}
54
73
 
59
78
}
60
79
 
61
80
void
62
 
Bitmap::display()
 
81
Bitmap::display(Renderer& renderer)
63
82
{
64
 
    assert(_shapeDef);
65
 
 
66
 
    _shapeDef->display(this);
67
 
 
 
83
    /// Don't display cleared Bitmaps.
 
84
    if (!_def && !_bitmapData) return;
 
85
 
 
86
    _shape.display(renderer, *this);
68
87
    clear_invalidated();
69
88
}
70
89
 
84
103
rect
85
104
Bitmap::getBounds() const
86
105
{
87
 
    return _shapeDef->get_bound();
 
106
    return _shape.getBounds();
88
107
}
89
108
 
90
109
void
91
 
Bitmap::drawBitmap()
 
110
Bitmap::makeBitmap()
92
111
{
93
112
 
94
113
    const BitmapData_as::BitmapArray& data = _bitmapData->getBitmapData();
109
128
        }
110
129
    }
111
130
 
112
 
    _bitmapInfo = render::createBitmapInfo(im);
 
131
    Renderer* renderer = getRunResources(*this).renderer();
 
132
    if (renderer) _bitmapInfo = renderer->createBitmapInfo(im);
113
133
 
114
134
}
115
135
 
116
136
 
117
137
void
118
 
Bitmap::finalize()
 
138
Bitmap::checkBitmapData()
119
139
{
120
140
 
121
 
    if (!_bitmapData) return;
 
141
    /// Nothing to do for disposed bitmaps.
 
142
    if (_def && !_bitmapData) return;
122
143
 
123
144
    const BitmapData_as::BitmapArray& data = _bitmapData->getBitmapData();
124
145
 
126
147
    /// set _bitmapData to 0 to avoid any further interaction.
127
148
    if (data.empty()) {
128
149
        _bitmapData = 0;
129
 
        _shapeDef->set_bound(rect());
 
150
        _shape.clear();
130
151
        return;
131
152
    }
132
 
 
133
 
    drawBitmap();
 
153
}
 
154
 
 
155
void
 
156
Bitmap::makeBitmapShape()
 
157
{
 
158
 
 
159
    if (!_def && !_bitmapData) return;
 
160
 
 
161
    if (_bitmapData) makeBitmap();
134
162
 
135
163
    // Width and height are a maximum of 2880, so there is no risk of 
136
164
    // overflow 
137
 
    const int w = _width * 20;
138
 
    const int h = _height * 20;
139
 
 
140
 
    if (!_shapeDef) {
141
 
    }
 
165
    const int w = pixelsToTwips(_width);
 
166
    const int h = pixelsToTwips(_height);
142
167
 
143
168
    SWFMatrix mat;
144
169
    mat.set_scale(1.0 / 20, 1.0 / 20);
145
 
    fill_style fill(_bitmapInfo.get(), mat);
146
 
    const size_t fillLeft = _shapeDef->add_fill_style(fill);
147
 
 
148
 
 
149
 
    path bmpath(w, h, fillLeft, 0, 0, false);
 
170
    fill_style fill(bitmap(), mat);
 
171
    const size_t fillLeft = _shape.add_fill_style(fill);
 
172
 
 
173
    Path bmpath(w, h, fillLeft, 0, 0, false);
150
174
    bmpath.drawLineTo(w, 0);
151
175
    bmpath.drawLineTo(0, 0);
152
176
    bmpath.drawLineTo(0, h);
153
177
    bmpath.drawLineTo(w, h);
154
178
 
155
 
    _shapeDef->add_path(bmpath);
 
179
    _shape.add_path(bmpath);
156
180
 
157
 
    _shapeDef->finalize();
 
181
    _shape.finalize();
158
182
 
159
183
}
160
184
 
161
185
void
162
186
Bitmap::update()
163
187
{
164
 
 
165
188
    set_invalidated();
166
 
 
167
 
    finalize();
168
 
 
 
189
    checkBitmapData();
 
190
    makeBitmapShape();
169
191
}
170
192
 
171
193
}