summaryrefslogtreecommitdiff
path: root/test/smoke-tests/frame-rate-tests/clutter.js
blob: d3abb4b4d836d942125b48b404a230911a50475b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
const Clutter = imports.gi.Clutter;
const GdkPixbuf = imports.gi.GdkPixbuf;
const Cogl = imports.gi.Cogl;
const Lang = imports.lang;
const Endless = imports.gi.Endless;
Clutter.init(null, null);

let crossfade = ARGV[0] === "crossfade";

let file_dir = Endless.getCurrentFileDir();

let BACKGROUND1_PATH = file_dir + '/1080/background1.jpg';
let BACKGROUND2_PATH = file_dir + '/1080/background2.jpg';
if (ARGV[1] === "720") {
    BACKGROUND1_PATH = file_dir + '/720/background1.jpg';
    BACKGROUND2_PATH = file_dir + '/720/background2.jpg';
}

// Convenience function to load a gresource image into a Clutter.Image
function load_clutter_image(path) {
    let pixbuf = GdkPixbuf.Pixbuf.new_from_file(path);
    let image = new Clutter.Image();
    if (pixbuf != null) {
        image.set_data(pixbuf.get_pixels(),
                       pixbuf.get_has_alpha()
                           ? Cogl.PixelFormat.RGBA_8888
                           : Cogl.PixelFormat.RGB_888,
                       pixbuf.get_width(),
                       pixbuf.get_height(),
                       pixbuf.get_rowstride());
    }
    return image;
}

const TestStage = new Lang.Class ({
    Name: 'TestStage',
    Extends: Clutter.Stage,

    _init: function(params) {
        this.parent(params);
        this.set_fullscreen(true);
        this.connect("allocation-changed", Lang.bind(this, function(actor, allocation) {
            this._update_actors();
        }));

        this._page1 = new Clutter.Actor({
            "x-expand": true,
            "y-expand": true,
            "content": load_clutter_image(BACKGROUND1_PATH),
            "reactive": true
        });
        this.add_child(this._page1);
        this._page1.connect("button-press-event", Lang.bind(this, function(actor, event) {
            this._swap();
        }));

        this._page2 = new Clutter.Actor({
            "x-expand": true,
            "y-expand": true,
            "content": load_clutter_image(BACKGROUND2_PATH),
            "reactive": true
        });
        this.add_child(this._page2);
        this._page2.connect("button-press-event", Lang.bind(this, function(actor, event) {
            this._swap();
        }));

        this._update_actors();
        this.connect("key-press-event", Clutter.main_quit);
    },

    _swap: function() {
        this._swapped = !this._swapped;
        this._page1.save_easing_state();
        this._page2.save_easing_state();
        this._page1.set_easing_duration(10000);
        this._page2.set_easing_duration(10000);
        this._update_actors();
        this._page1.restore_easing_state();
        this._page2.restore_easing_state();
    },

    _update_actors: function() {
        this._page1.x = 0;
        this._page1.width = this.get_width();
        this._page1.height = this.get_height();
        this._page2.x = 0;
        this._page2.width = this.get_width();
        this._page2.height = this.get_height();
        if (crossfade) {
            if(this._swapped)
                this._page2.opacity = 255;
            else
                this._page2.opacity = 0;
        }
        else {
            if(this._swapped)
                this._page1.x = -this.get_width();
            else
                this._page2.x = this.get_width();
        }
    }
});


let stage = new TestStage();
stage.show();
Clutter.main();
stage.destroy();