diff mbox

[Branch,~glcompbench-dev/glcompbench/trunk] Rev 87: Merge of lp:~glcompbench-dev/glcompbench/scale.

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

Commit Message

Jesse Barker July 16, 2012, 5:01 p.m. UTC
Merge authors:
  Jesse Barker (jesse-barker)
Related merge proposals:
  https://code.launchpad.net/~glcompbench-dev/glcompbench/scale/+merge/113989
  proposed by: Jesse Barker (jesse-barker)
  review: Approve - Alexandros Frantzis (afrantzis)
  review: Resubmit - Jesse Barker (jesse-barker)
------------------------------------------------------------
revno: 87 [merge]
committer: Jesse Barker <jesse.barker@linaro.org>
branch nick: trunk
timestamp: Mon 2012-07-16 09:58:40 -0700
message:
  Merge of lp:~glcompbench-dev/glcompbench/scale.
  
  Adds new test CompositeTestSimpleScale (based upon CompositeTestSimpleBase).
added:
  src/composite-test-simple-scale.cc
modified:
  src/composite-test.h
  src/glcompbench.cc


--
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 'src/composite-test-simple-scale.cc'
--- src/composite-test-simple-scale.cc	1970-01-01 00:00:00 +0000
+++ src/composite-test-simple-scale.cc	2012-07-13 15:26:14 +0000
@@ -0,0 +1,150 @@ 
+/*
+ * Copyright © 2012 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;
+using std::list;
+
+bool
+CompositeTestSimpleScale::init_shaders(ShaderSource& vtx, ShaderSource& frg)
+{
+    static const string precisionString("default,default,default,default");
+    static const ShaderSource::Precision precision(precisionString);
+    vtx.precision(precision);
+    frg.precision(precision);
+    static const float alpha_bias(0.5);
+    frg.add_const("alpha_bias", alpha_bias);
+
+    return true;
+}
+
+// We want to scale 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 update the scale bias.
+class Scaler
+{
+    uint64_t start_time_;
+    uint64_t last_eof_;
+    float bias_;
+    float duration_;
+public:
+    Scaler() :
+        start_time_(0),
+        last_eof_(0),
+        bias_(0.0),
+        duration_(0.0) {}
+    ~Scaler() {}
+    void init(const string& duration)
+    {
+        // 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();
+    }
+    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_; }
+};
+
+static Scaler scaler;
+
+void
+CompositeTestSimpleScale::prepare_for_run(list<CompositeWindow*>& window_list)
+{
+    CompositeTestSimpleBase::prepare_for_run(window_list);
+    scaler.init(options_["duration"].value);
+}
+
+void
+CompositeTestSimpleScale::draw(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();
+
+    /* 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 */
+    float scale_bias(scaler.bias());
+    GLint i(0);
+    for(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);
+            model_view_matrix.scale(scale_bias, scale_bias, scale_bias);
+
+            /* 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();
+    scaler.update();
+}

=== modified file 'src/composite-test.h'
--- src/composite-test.h	2012-07-13 15:40:15 +0000
+++ src/composite-test.h	2012-07-16 16:58:40 +0000
@@ -245,4 +245,18 @@ 
     virtual void prepare_for_run(std::list<CompositeWindow*> &window_list);
 };
 
+class CompositeTestSimpleScale : public CompositeTestSimpleBase
+{
+public:
+    CompositeTestSimpleScale() : 
+        CompositeTestSimpleBase("scale",
+                                GLCOMPBENCH_DATA_PATH"/default.vert",
+                                GLCOMPBENCH_DATA_PATH"/default.frag")
+        {}
+
+    virtual bool init_shaders(ShaderSource& vtx, ShaderSource& frg);
+    virtual void draw(std::list<CompositeWindow*> &window_list);
+    virtual void prepare_for_run(std::list<CompositeWindow*> &window_list);
+};
+
 #endif // COMPOSITE_TEST_H_

=== modified file 'src/glcompbench.cc'
--- src/glcompbench.cc	2012-05-16 13:14:53 +0000
+++ src/glcompbench.cc	2012-07-06 17:28:21 +0000
@@ -47,6 +47,7 @@ 
     "fade",
     "blur",
     "brick",
+    "scale",
     "pixman",
     "xrender",
     NULL
@@ -199,6 +200,7 @@ 
     Benchmark::register_test(*new CompositeTestSimpleBlur());
     Benchmark::register_test(*new CompositeTestSimpleFade());
     Benchmark::register_test(*new CompositeTestSimpleBrick());
+    Benchmark::register_test(*new CompositeTestSimpleScale());
     Benchmark::register_test(*new CompositeTestPixman());
     Benchmark::register_test(*new CompositeTestXRender());