From 0dd5fa5fcec9bad9bd87ad0a9b04b63d47cd2a6c Mon Sep 17 00:00:00 2001 From: Matt Watson Date: Thu, 5 Sep 2013 17:11:06 -0700 Subject: Gtk and clutter tests for framerate Not the greatest code, command line parsing could be better, but these are smoke tests. README with some instructions [endlessm/eos-sdk#299] --- .../frame-rate-tests/1080/background1.jpg | Bin 0 -> 525725 bytes .../frame-rate-tests/1080/background2.jpg | Bin 0 -> 300852 bytes .../frame-rate-tests/720/background1.jpg | Bin 0 -> 169104 bytes .../frame-rate-tests/720/background2.jpg | Bin 0 -> 165416 bytes test/smoke-tests/frame-rate-tests/README | 16 +++ test/smoke-tests/frame-rate-tests/clutter.js | 109 +++++++++++++++++++++ test/smoke-tests/frame-rate-tests/gtk.css | 15 +++ test/smoke-tests/frame-rate-tests/gtk.js | 84 ++++++++++++++++ 8 files changed, 224 insertions(+) create mode 100644 test/smoke-tests/frame-rate-tests/1080/background1.jpg create mode 100644 test/smoke-tests/frame-rate-tests/1080/background2.jpg create mode 100644 test/smoke-tests/frame-rate-tests/720/background1.jpg create mode 100644 test/smoke-tests/frame-rate-tests/720/background2.jpg create mode 100644 test/smoke-tests/frame-rate-tests/README create mode 100644 test/smoke-tests/frame-rate-tests/clutter.js create mode 100644 test/smoke-tests/frame-rate-tests/gtk.css create mode 100644 test/smoke-tests/frame-rate-tests/gtk.js (limited to 'test') diff --git a/test/smoke-tests/frame-rate-tests/1080/background1.jpg b/test/smoke-tests/frame-rate-tests/1080/background1.jpg new file mode 100644 index 0000000..b7b463d Binary files /dev/null and b/test/smoke-tests/frame-rate-tests/1080/background1.jpg differ diff --git a/test/smoke-tests/frame-rate-tests/1080/background2.jpg b/test/smoke-tests/frame-rate-tests/1080/background2.jpg new file mode 100644 index 0000000..4e505d1 Binary files /dev/null and b/test/smoke-tests/frame-rate-tests/1080/background2.jpg differ diff --git a/test/smoke-tests/frame-rate-tests/720/background1.jpg b/test/smoke-tests/frame-rate-tests/720/background1.jpg new file mode 100644 index 0000000..d52e2a3 Binary files /dev/null and b/test/smoke-tests/frame-rate-tests/720/background1.jpg differ diff --git a/test/smoke-tests/frame-rate-tests/720/background2.jpg b/test/smoke-tests/frame-rate-tests/720/background2.jpg new file mode 100644 index 0000000..df23b5c Binary files /dev/null and b/test/smoke-tests/frame-rate-tests/720/background2.jpg differ diff --git a/test/smoke-tests/frame-rate-tests/README b/test/smoke-tests/frame-rate-tests/README new file mode 100644 index 0000000..0c5aa17 --- /dev/null +++ b/test/smoke-tests/frame-rate-tests/README @@ -0,0 +1,16 @@ +Some basic animation tests to help see what kinds of animation are possible on +what architectures. + +Usage: + CLUTTER_SHOW_FPS=1 gjs clutter.js [crossfade/slide] [1080/720] + GDK_DEBUG=frames gjs gtk.js [crossfade/slide] [1080/720] + +You can choose between a cross fade and a slide, and a 1080 or 720 image asset +to animate. (The screen resolution and not the asset size should really +determine frame rate, but just in case.) + +Clutter will print out a proper frame rate, whereas GTK will print out +a series of intervals between draw updates. During an animation these +should be at 16 milliseconds for 60 FPS. + +Click to trigger a slide. Press any key to quit. diff --git a/test/smoke-tests/frame-rate-tests/clutter.js b/test/smoke-tests/frame-rate-tests/clutter.js new file mode 100644 index 0000000..d3abb4b --- /dev/null +++ b/test/smoke-tests/frame-rate-tests/clutter.js @@ -0,0 +1,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(); diff --git a/test/smoke-tests/frame-rate-tests/gtk.css b/test/smoke-tests/frame-rate-tests/gtk.css new file mode 100644 index 0000000..c024276 --- /dev/null +++ b/test/smoke-tests/frame-rate-tests/gtk.css @@ -0,0 +1,15 @@ +#page1_1080 { + background-image: url("1080/background1.jpg"); +} + +#page2_1080 { + background-image: url("1080/background2.jpg"); +} + +#page1_720 { + background-image: url("720/background1.jpg"); +} + +#page2_720 { + background-image: url("720/background2.jpg"); +} diff --git a/test/smoke-tests/frame-rate-tests/gtk.js b/test/smoke-tests/frame-rate-tests/gtk.js new file mode 100644 index 0000000..8af1376 --- /dev/null +++ b/test/smoke-tests/frame-rate-tests/gtk.js @@ -0,0 +1,84 @@ +// Copyright 2013 Endless Mobile, Inc. + +const Lang = imports.lang; +const Gtk = imports.gi.Gtk; +const PLib = imports.gi.PLib; +const GObject = imports.gi.GObject; +const Endless = imports.gi.Endless; + +const TEST_APPLICATION_ID = "com.frametest"; + +let TRANSITION1 = PLib.StackTransitionType.SLIDE_LEFT; +let TRANSITION2 = PLib.StackTransitionType.SLIDE_RIGHT; +if (ARGV[0] === "crossfade") { + TRANSITION1 = PLib.StackTransitionType.CROSSFADE; + TRANSITION2 = PLib.StackTransitionType.CROSSFADE; +} + +let BACKGROUND1_NAME = "page1_1080"; +let BACKGROUND2_NAME = "page2_1080"; +if (ARGV[1] === "720") { + BACKGROUND1_NAME = "page1_720"; + BACKGROUND2_NAME = "page2_720"; +} + +const TestApplication = new Lang.Class ({ + Name: "TestApplication", + Extends: Gtk.Application, + + vfunc_startup: function() { + this.parent(); + + // First page + this._page1 = new Gtk.EventBox({ + name: BACKGROUND1_NAME, + expand: true + }); + this._page1.connect("button-press-event", Lang.bind(this, function () { + this._stack.set_transition_type(TRANSITION1); + this._stack.set_visible_child(this._page2); + })); + + // Second page + this._page2 = new Gtk.Button({ + name: BACKGROUND2_NAME, + expand: true + }); + this._page2.connect("button-press-event", Lang.bind(this, function () { + this._stack.set_transition_type(TRANSITION2); + this._stack.set_visible_child(this._page1); + })); + + this._stack = new PLib.Stack(); + this._stack.add(this._page1); + this._stack.add(this._page2); + + this._stack.set_transition_duration(10000); + + this._window = new Gtk.Window({ + application: this, + }); + this._window.add(this._stack); + this._window.show_all(); + this._window.fullscreen(); + this._window.connect("key-press-event", Lang.bind(this, function() { + this._window.destroy(); + })); + + let provider = new Gtk.CssProvider (); + provider.load_from_path (Endless.getCurrentFileDir() + "/gtk.css"); + let context = new Gtk.StyleContext(); + context.add_provider_for_screen(this._window.get_screen(), + provider, + Gtk.STYLE_PROVIDER_PRIORITY_USER); + + }, + + vfunc_activate: function() { + this.parent(); + } +}); + +let app = new TestApplication({ application_id: TEST_APPLICATION_ID, + flags: 0 }); +app.run(ARGV); -- cgit v1.2.3