Skip to content

Commit 3445fc9

Browse files
committed
Rust upgrade progress
1 parent bfc22fa commit 3445fc9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+539
-426
lines changed

src/components/gfx/buffer_map.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5+
use collections::hashmap::HashMap;
56
use geom::size::Size2D;
67
use layers::platform::surface::NativePaintingGraphicsContext;
78
use servo_msg::compositor_msg::Tile;
8-
use std::hashmap::HashMap;
9-
use std::to_bytes::Cb;
10-
use std::util;
9+
use std::hash::Hash;
10+
use std::hash::sip::SipState;
11+
use std::mem;
1112

1213
/// This is a struct used to store buffers when they are not in use.
1314
/// The render task can quickly query for a particular size of buffer when it
@@ -27,16 +28,18 @@ pub struct BufferMap<T> {
2728
/// A key with which to store buffers. It is based on the size of the buffer.
2829
struct BufferKey([uint, ..2]);
2930

30-
impl IterBytes for BufferKey {
31-
fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool {
32-
let i = if lsb0 {0} else {1};
33-
self[i].iter_bytes(lsb0, |x| f(x)) && self[1 - i].iter_bytes(lsb0, |x| f(x))
31+
impl Hash for BufferKey {
32+
fn hash(&self, state: &mut SipState) {
33+
let BufferKey(ref bytes) = *self;
34+
bytes.as_slice().hash(state);
3435
}
3536
}
3637

3738
impl Eq for BufferKey {
3839
fn eq(&self, other: &BufferKey) -> bool {
39-
self[0] == other[0] && self[1] == other[1]
40+
let BufferKey(s) = *self;
41+
let BufferKey(o) = *other;
42+
s[0] == o[0] && s[1] == o[1]
4043
}
4144
}
4245

@@ -79,9 +82,10 @@ impl<T: Tile> BufferMap<T> {
7982

8083
self.mem += new_buffer.get_mem();
8184
// use lazy insertion function to prevent unnecessary allocation
85+
let counter = &self.counter;
8286
self.map.find_or_insert_with(new_key, |_| BufferValue {
8387
buffers: ~[],
84-
last_action: self.counter
88+
last_action: *counter
8589
}).buffers.push(new_buffer);
8690

8791
let mut opt_key: Option<BufferKey> = None;
@@ -97,7 +101,7 @@ impl<T: Tile> BufferMap<T> {
97101
};
98102
if {
99103
let list = &mut self.map.get_mut(&old_key).buffers;
100-
let condemned_buffer = list.pop();
104+
let condemned_buffer = list.pop().take_unwrap();
101105
self.mem -= condemned_buffer.get_mem();
102106
condemned_buffer.destroy(graphics_context);
103107
list.is_empty()
@@ -120,7 +124,7 @@ impl<T: Tile> BufferMap<T> {
120124
buffer_val.last_action = self.counter;
121125
self.counter += 1;
122126

123-
let buffer = buffer_val.buffers.pop();
127+
let buffer = buffer_val.buffers.pop().take_unwrap();
124128
self.mem -= buffer.get_mem();
125129
if buffer_val.buffers.is_empty() {
126130
flag = true;
@@ -139,7 +143,7 @@ impl<T: Tile> BufferMap<T> {
139143

140144
/// Destroys all buffers.
141145
pub fn clear(&mut self, graphics_context: &NativePaintingGraphicsContext) {
142-
let map = util::replace(&mut self.map, HashMap::new());
146+
let map = mem::replace(&mut self.map, HashMap::new());
143147
for (_, value) in map.move_iter() {
144148
for tile in value.buffers.move_iter() {
145149
tile.destroy(graphics_context)

src/components/gfx/display_list.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ use color::Color;
1818
use render_context::RenderContext;
1919
use text::TextRun;
2020

21-
use extra::arc::Arc;
2221
use geom::{Point2D, Rect, Size2D, SideOffsets2D};
2322
use servo_net::image::base::Image;
2423
use servo_util::geometry::Au;
2524
use servo_util::range::Range;
2625
use std::cast::transmute_region;
27-
use std::vec::VecIterator;
26+
use std::vec::Items;
2827
use style::computed_values::border_style;
28+
use sync::Arc;
2929

3030
pub struct DisplayListCollection<E> {
3131
lists: ~[DisplayList<E>]
@@ -70,7 +70,7 @@ pub struct DisplayList<E> {
7070

7171
pub enum DisplayListIterator<'a,E> {
7272
EmptyDisplayListIterator,
73-
ParentDisplayListIterator(VecIterator<'a,DisplayList<E>>),
73+
ParentDisplayListIterator(Items<'a,DisplayList<E>>),
7474
}
7575

7676
impl<'a,E> Iterator<&'a DisplayList<E>> for DisplayListIterator<'a,E> {
@@ -226,7 +226,7 @@ pub struct ClipDisplayItem<E> {
226226

227227
pub enum DisplayItemIterator<'a,E> {
228228
EmptyDisplayItemIterator,
229-
ParentDisplayItemIterator(VecIterator<'a,DisplayItem<E>>),
229+
ParentDisplayItemIterator(Items<'a,DisplayItem<E>>),
230230
}
231231

232232
impl<'a,E> Iterator<&'a DisplayItem<E>> for DisplayItemIterator<'a,E> {

src/components/gfx/font.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use azure::{AzFloat, AzScaledFontRef};
66
use azure::azure_hl::{BackendType, ColorPattern};
77
use azure::scaled_font::ScaledFont;
8-
use extra::arc::Arc;
98
use geom::{Point2D, Rect, Size2D};
109
use std::cast;
1110
use std::ptr;
@@ -15,6 +14,7 @@ use std::cell::RefCell;
1514
use servo_util::cache::{Cache, HashCache};
1615
use servo_util::range::Range;
1716
use style::computed_values::{text_decoration, font_weight, font_style};
17+
use sync::Arc;
1818

1919
use color::Color;
2020
use font_context::FontContext;
@@ -230,7 +230,7 @@ impl<'a> Font {
230230

231231
let metrics = handle.get_metrics();
232232

233-
return Ok(Rc::from_mut(RefCell::new(Font {
233+
return Ok(Rc::new(RefCell::new(Font {
234234
handle: handle,
235235
azure_font: None,
236236
shaper: None,
@@ -269,7 +269,7 @@ impl<'a> Font {
269269
Err(()) => return Err(())
270270
};
271271

272-
return Ok(Rc::from_mut(RefCell::new(Font::new_from_adopted_handle(fctx, styled_handle, style, backend))));
272+
return Ok(Rc::new(RefCell::new(Font::new_from_adopted_handle(fctx, styled_handle, style, backend))));
273273
}
274274

275275
fn make_shaper(&'a mut self) -> &'a Shaper {
@@ -394,9 +394,9 @@ impl Font {
394394
// TODO(Issue #64): this call needs to move into azure_hl.rs
395395
AzDrawTargetFillGlyphs(target.azure_draw_target,
396396
azfontref,
397-
ptr::to_unsafe_ptr(&glyphbuf),
397+
&glyphbuf,
398398
azure_pattern,
399-
ptr::to_unsafe_ptr(&options),
399+
&options,
400400
ptr::null());
401401
}
402402
}
@@ -428,9 +428,10 @@ impl Font {
428428

429429
//FIXME (ksh8281)
430430
self.make_shaper();
431+
let shaper = &self.shaper;
431432
self.shape_cache.find_or_create(&text, |txt| {
432433
let mut glyphs = GlyphStore::new(text.char_len(), is_whitespace);
433-
self.shaper.get_ref().shape_text(*txt, &mut glyphs);
434+
shaper.get_ref().shape_text(*txt, &mut glyphs);
434435
Arc::new(glyphs)
435436
})
436437
}
@@ -444,8 +445,9 @@ impl Font {
444445
}
445446

446447
pub fn glyph_h_advance(&mut self, glyph: GlyphIndex) -> FractionalPixel {
448+
let handle = &self.handle;
447449
self.glyph_advance_cache.find_or_create(&glyph, |glyph| {
448-
match self.handle.glyph_h_advance(*glyph) {
450+
match handle.glyph_h_advance(*glyph) {
449451
Some(adv) => adv,
450452
None => /* FIXME: Need fallback strategy */ 10f64 as FractionalPixel
451453
}

src/components/gfx/font_context.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use platform::font::FontHandle;
99
use platform::font_context::FontContextHandle;
1010

1111
use azure::azure_hl::BackendType;
12+
use collections::hashmap::HashMap;
1213
use servo_util::cache::{Cache, LRUCache};
1314
use servo_util::time::ProfilerChan;
14-
use std::hashmap::HashMap;
1515

1616
use std::rc::Rc;
1717
use std::cell::RefCell;
@@ -198,11 +198,9 @@ impl FontContext {
198198

199199
debug!("(create font group) --- finished ---");
200200

201-
unsafe {
202-
Rc::new_unchecked(
203-
RefCell::new(
204-
FontGroup::new(style.families.to_owned(), &used_style, fonts)))
205-
}
201+
Rc::new(
202+
RefCell::new(
203+
FontGroup::new(style.families.to_owned(), &used_style, fonts)))
206204
}
207205

208206
fn create_font_instance(&self, desc: &FontDescriptor) -> Result<Rc<RefCell<Font>>, ()> {
@@ -213,7 +211,7 @@ impl FontContext {
213211
desc.style.clone());
214212
result_handle.and_then(|handle| {
215213
Ok(
216-
Rc::from_mut(
214+
Rc::new(
217215
RefCell::new(
218216
Font::new_from_adopted_handle(self,
219217
handle,

src/components/gfx/font_list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5+
use collections::hashmap::HashMap;
56
use font::SpecifiedFontStyle;
67
use gfx_font::FontHandleMethods;
78
use platform::font::FontHandle;
@@ -11,7 +12,6 @@ use style::computed_values::{font_weight, font_style};
1112

1213
use servo_util::time::{ProfilerChan, profile};
1314
use servo_util::time;
14-
use std::hashmap::HashMap;
1515

1616
pub type FontFamilyMap = HashMap<~str, FontFamily>;
1717

src/components/gfx/gfx.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,31 @@
77

88
#[feature(globs, managed_boxes, macro_rules)];
99

10-
extern mod azure;
11-
extern mod extra;
12-
extern mod geom;
13-
extern mod layers;
14-
extern mod stb_image;
15-
extern mod png;
16-
extern mod servo_net = "net";
17-
extern mod servo_util = "util";
18-
extern mod style;
19-
extern mod servo_msg = "msg";
10+
extern crate azure;
11+
extern crate collections;
12+
extern crate extra;
13+
extern crate geom;
14+
extern crate layers;
15+
extern crate stb_image;
16+
extern crate png;
17+
extern crate servo_net = "net";
18+
extern crate servo_util = "util";
19+
extern crate servo_msg = "msg";
20+
extern crate style;
21+
extern crate sync;
2022

2123
// Eventually we would like the shaper to be pluggable, as many operating systems have their own
2224
// shapers. For now, however, this is a hard dependency.
23-
extern mod harfbuzz;
25+
extern crate harfbuzz;
2426

2527
// Linux and Android-specific library dependencies
26-
#[cfg(target_os="linux")] #[cfg(target_os="android")] extern mod fontconfig;
27-
#[cfg(target_os="linux")] #[cfg(target_os="android")] extern mod freetype;
28+
#[cfg(target_os="linux")] #[cfg(target_os="android")] extern crate fontconfig;
29+
#[cfg(target_os="linux")] #[cfg(target_os="android")] extern crate freetype;
2830

2931
// Mac OS-specific library dependencies
30-
#[cfg(target_os="macos")] extern mod core_foundation;
31-
#[cfg(target_os="macos")] extern mod core_graphics;
32-
#[cfg(target_os="macos")] extern mod core_text;
32+
#[cfg(target_os="macos")] extern crate core_foundation;
33+
#[cfg(target_os="macos")] extern crate core_graphics;
34+
#[cfg(target_os="macos")] extern crate core_text;
3335

3436
pub use gfx_font = font;
3537
pub use gfx_font_context = font_context;

src/components/gfx/macros.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ macro_rules! bitfield(
99
impl $bitfieldname {
1010
#[inline]
1111
pub fn $getter(self) -> bool {
12-
(*self & $value) != 0
12+
let $bitfieldname(this) = self;
13+
(this & $value) != 0
1314
}
1415

1516
#[inline]
1617
pub fn $setter(&mut self, value: bool) {
17-
*self = $bitfieldname((**self & !$value) | (if value { $value } else { 0 }))
18+
let $bitfieldname(this) = *self;
19+
*self = $bitfieldname((this & !$value) | (if value { $value } else { 0 }))
1820
}
1921
}
2022
)

src/components/gfx/platform/android/font.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
extern mod freetype;
5+
extern crate freetype;
66

77
use font::{FontHandleMethods, FontMetrics, FontTableMethods};
88
use font::{FontTableTag, FractionalPixel, SpecifiedFontStyle, UsedFontStyle};

src/components/gfx/platform/android/font_list.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
extern mod freetype;
6-
extern mod fontconfig;
5+
extern crate freetype;
6+
extern crate fontconfig;
77

88
use fontconfig::fontconfig::{
99
FcChar8, FcResultMatch, FcSetSystem, FcPattern,

src/components/gfx/platform/linux/font.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
extern mod freetype;
5+
extern crate freetype;
66

77
use font::{FontHandleMethods, FontMetrics, FontTableMethods};
88
use font::{FontTableTag, FractionalPixel, SpecifiedFontStyle, UsedFontStyle};

src/components/gfx/platform/linux/font_list.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
extern mod freetype;
6-
extern mod fontconfig;
5+
extern crate freetype;
6+
extern crate fontconfig;
77

88
use fontconfig::fontconfig::{
99
FcChar8, FcResultMatch, FcSetSystem, FcPattern,

src/components/gfx/platform/macos/font.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
/// Implementation of Quartz (CoreGraphics) fonts.
66
7-
extern mod core_foundation;
8-
extern mod core_graphics;
9-
extern mod core_text;
7+
extern crate core_foundation;
8+
extern crate core_graphics;
9+
extern crate core_text;
1010

1111
use font::{FontHandleMethods, FontMetrics, FontTableMethods};
1212
use font::FontTableTag;
@@ -130,8 +130,8 @@ impl FontHandleMethods for FontHandle {
130130
let glyphs: [CGGlyph, ..1] = [0 as CGGlyph];
131131
let count: CFIndex = 1;
132132

133-
let result = self.ctfont.get_glyphs_for_characters(ptr::to_unsafe_ptr(&characters[0]),
134-
ptr::to_unsafe_ptr(&glyphs[0]),
133+
let result = self.ctfont.get_glyphs_for_characters(&characters[0],
134+
&glyphs[0],
135135
count);
136136

137137
if !result {

src/components/gfx/platform/macos/font_list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ use font_list::{FontEntry, FontFamily, FontFamilyMap};
77
use platform::macos::font::FontHandle;
88
use platform::macos::font_context::FontContextHandle;
99

10+
use collections::hashmap::HashMap;
1011
use core_foundation::base::TCFType;
1112
use core_foundation::string::{CFString, CFStringRef};
1213
use core_text::font_descriptor::{CTFontDescriptor, CTFontDescriptorRef};
1314
use core_text;
1415
use std::cast;
15-
use std::hashmap::HashMap;
1616

1717
pub struct FontListHandle {
1818
fctx: FontContextHandle,

src/components/gfx/render_context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use azure::azure_hl::{B8G8R8A8, Color, ColorPattern, DrawOptions};
99
use azure::azure_hl::{DrawSurfaceOptions, DrawTarget, Linear, StrokeOptions};
1010
use azure::AZ_CAP_BUTT;
1111
use azure::AzFloat;
12-
use extra::arc::Arc;
1312
use geom::point::Point2D;
1413
use geom::rect::Rect;
1514
use geom::size::Size2D;
@@ -20,6 +19,7 @@ use servo_util::geometry::Au;
2019
use servo_util::opts::Opts;
2120
use std::libc::types::common::c99::uint16_t;
2221
use std::libc::size_t;
22+
use sync::Arc;
2323

2424
pub struct RenderContext<'a> {
2525
draw_target: &'a DrawTarget,

0 commit comments

Comments
 (0)