diff mbox

[Branch,~glcompbench-dev/glcompbench/trunk] Rev 63: Merging fade feature branch. This adds a new test scenario that simulates the

Message ID 20111014150612.26634.23436.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Jesse Barker Oct. 14, 2011, 3:06 p.m. UTC
Merge authors:
  Jesse Barker (jesse-barker)
Related merge proposals:
  https://code.launchpad.net/~jesse-barker/glcompbench/fade/+merge/79357
  proposed by: Jesse Barker (jesse-barker)
  review: Approve - Alexandros Frantzis (afrantzis)
------------------------------------------------------------
revno: 63 [merge]
committer: Jesse Barker <jesse.barker@linaro.org>
branch nick: trunk
timestamp: Fri 2011-10-14 08:03:44 -0700
message:
  Merging fade feature branch.  This adds a new test scenario that simulates the
  window fade in/out effect used by many window managers.
added:
  data/fade.frag
  src/composite-test-simple-fade.cc
modified:
  src/composite-test.h
  src/glcompbench.cc
  src/profiler.h


--
lp:glcompbench
https://code.launchpad.net/~glcompbench-dev/glcompbench/trunk

You are subscribed to branch lp:glcompbench.
To unsubscribe from this branch go to https://code.launchpad.net/~glcompbench-dev/glcompbench/trunk/+edit-subscription
diff mbox

Patch

=== added file 'data/fade.frag'
--- data/fade.frag	1970-01-01 00:00:00 +0000
+++ data/fade.frag	2011-10-13 22:48:52 +0000
@@ -0,0 +1,14 @@ 
+#ifdef GL_ES
+precision mediump float;
+#endif
+
+uniform float alpha_bias;
+uniform sampler2D Texture0;
+varying vec2 TextureCoord;
+
+void main(void)
+{
+    float alpha = 1.0 - alpha_bias;
+    vec4 texel = texture2D(Texture0, TextureCoord);
+    gl_FragColor = vec4(texel.xyz, alpha);
+}

=== added file 'src/composite-test-simple-fade.cc'
--- src/composite-test-simple-fade.cc	1970-01-01 00:00:00 +0000
+++ src/composite-test-simple-fade.cc	2011-10-14 12:41:30 +0000
@@ -0,0 +1,128 @@ 
+/*
+ * Copyright © 2011 Linaro Limited
+ *
+ * This file is part of glcompbench.
+ *
+ * glcompbench is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * glcompbench is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with glcompbench.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ *  Alexandros Frantzis <alexandros.frantzis@linaro.org>
+ *  Jesse Barker <jesse.barker@linaro.org>
+ */
+
+#include "gl-headers.h"
+#include "composite-test.h"
+#include "options.h"
+#include "log.h"
+#include <sstream>
+
+using std::string;
+
+const string CompositeTestSimpleFade::fade_bias_name_("alpha_bias");
+
+// We want to fade smoothly across the test duration, so take a timestamp
+// at the beginning of the test (beginning of the first draw), and take one
+// each time we'll update the fade bias to see if we should.  We know based
+// upon the fade increment constant how many times we should fade.
+class Fader
+{
+    uint64_t start_time_;
+    uint64_t last_eof_;
+    float bias_;
+    float duration_;
+    Fader();
+public:
+    Fader(const string& duration) :
+        last_eof_(0),
+        bias_(0.0)
+    {
+        // Convert the string representation of the duration in seconds
+        // to microseconds as that's what we'll need to track the time.
+        std::stringstream ss(duration);
+        ss >> duration_;
+        duration_ *= 1000000;
+        start_time_ = Profiler::get_timestamp_us();
+    }
+    ~Fader() {}
+    void update()
+    {
+        last_eof_ = Profiler::get_timestamp_us();
+        uint64_t howLong(last_eof_ - start_time_);
+        if (howLong < duration_)
+        {
+            // Still inside of the test duration.  Compute the bias.
+            bias_ = howLong / duration_;
+            return;
+        }
+        // Reset back to the beginning.
+        start_time_ = last_eof_;
+        bias_ = 0.0;
+    }
+    float bias() const { return bias_; }
+};
+
+void
+CompositeTestSimpleFade::draw(std::list<CompositeWindow *> &window_list)
+{
+    vboData_.bind();
+    glActiveTexture(GL_TEXTURE0);
+    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+    /* Set up the position of the attributes in the vertex array */
+    glVertexAttribPointer(vertexIndex_, 3, GL_FLOAT, GL_FALSE, 0, vboData_.vertexOffset());
+    glVertexAttribPointer(texcoordIndex_, 2, GL_FLOAT, GL_FALSE, 0, vboData_.texcoordOffset());
+
+    /* Enable the attributes */
+    glEnableVertexAttribArray(vertexIndex_);
+    glEnableVertexAttribArray(texcoordIndex_);
+
+    program_[projection_matrix_name_] = projection_matrix.getCurrent();
+    static Fader fader(options_["duration"].value);
+    program_[fade_bias_name_] = fader.bias();
+
+    /* Find out how many windows are visible and calculate the angular step */
+    GLuint visible_windows(num_visible_windows(window_list));
+    GLfloat angular_step(2 * M_PI / visible_windows);
+
+    /* Draw the windows in a circle using the calculated angular step */
+    GLint i(0);
+    for(std::list<CompositeWindow*>::iterator iter = window_list.begin();
+        iter != window_list.end(); ++iter)
+    {
+        CompositeWindow *comp_win = *iter;
+        GLuint tex = comp_win->get_texture().i;
+        if (tex) {
+            model_view_matrix.push();
+            model_view_matrix.translate(cos(angular_step * i),
+                                        sin(angular_step * i), 0);
+
+            /* Load shader ModelView uniform */
+            program_[model_view_matrix_name_] = model_view_matrix.getCurrent();
+
+            Log::debug("Drawing Win: 0x%x Tex: 0x%x\n",
+                       comp_win->get_xwindow(), comp_win->get_texture().i);
+
+            glBindTexture(GL_TEXTURE_2D, tex);
+            vboData_.draw();
+            model_view_matrix.pop();
+            ++i;
+        }
+    }
+
+    // Disable the attributes
+    glDisableVertexAttribArray(vertexIndex_);
+    glDisableVertexAttribArray(texcoordIndex_);
+    vboData_.unbind();
+    fader.update();
+}

=== modified file 'src/composite-test.h'
--- src/composite-test.h	2011-08-03 17:14:34 +0000
+++ src/composite-test.h	2011-10-14 02:09:08 +0000
@@ -209,4 +209,17 @@ 
     
 };
 
+class CompositeTestSimpleFade : public CompositeTestSimpleBase
+{
+    static const std::string fade_bias_name_;
+public:
+    CompositeTestSimpleFade() : 
+        CompositeTestSimpleBase("fade",
+                                GLCOMPBENCH_DATA_PATH"/default.vert",
+                                GLCOMPBENCH_DATA_PATH"/fade.frag")
+        {}
+
+    virtual void draw(std::list<CompositeWindow*> &window_list);
+};
+
 #endif // COMPOSITE_TEST_H_

=== modified file 'src/glcompbench.cc'
--- src/glcompbench.cc	2011-09-21 13:57:01 +0000
+++ src/glcompbench.cc	2011-10-13 22:48:52 +0000
@@ -38,6 +38,7 @@ 
 
 static const char *default_benchmarks[] = {
     "default",
+    "fade",
     "brick",
     "pixman",
     "xrender",
@@ -157,6 +158,7 @@ 
 
     Benchmark::register_test(*new CompositeTestDefaultOptions());
     Benchmark::register_test(*new CompositeTestSimpleDefault());
+    Benchmark::register_test(*new CompositeTestSimpleFade());
     Benchmark::register_test(*new CompositeTestSimpleBrick());
     Benchmark::register_test(*new CompositeTestPixman());
     Benchmark::register_test(*new CompositeTestXRender());

=== modified file 'src/profiler.h'
--- src/profiler.h	2011-04-04 12:56:06 +0000
+++ src/profiler.h	2011-10-14 12:41:30 +0000
@@ -135,6 +135,7 @@ 
     void reset_point(Point p);
     void reset(void);
     Point get_num_points() { return points_.size(); }
+    static uint64_t get_timestamp_us();
 
     /**
      * Gets the profiler singleton
@@ -147,7 +148,6 @@ 
 
 private:
     bool is_valid_point(Point p);
-    uint64_t get_timestamp_us();
     std::vector<ProfilerPoint *> points_;
 };