diff mbox

[Branch,~glmark2-dev/glmark2/trunk] Rev 274: SceneCollection: Consolidate the scene vector population into an object to

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

Commit Message

alexandros.frantzis@linaro.org May 27, 2013, 5:28 p.m. UTC
Merge authors:
  Jesse Barker (jesse-barker)
Related merge proposals:
  https://code.launchpad.net/~glmark2-dev/glmark2/scene-collection/+merge/164459
  proposed by: Jesse Barker (jesse-barker)
  review: Approve - Alexandros Frantzis (afrantzis)
------------------------------------------------------------
revno: 274 [merge]
author: Jesse Barker <jesse.barker@linaro.org>
committer: Alexandros Frantzis <alexandros.frantzis@canonical.com>
branch nick: trunk
timestamp: Mon 2013-05-27 20:22:08 +0300
message:
  SceneCollection: Consolidate the scene vector population into an object to
  simplify adding scenes across platforms (rather than having to add for Android
  separately from others).
  ------------- This line and the following will be ignored --------------
  
  added:
    src/scene-collection.h
  modified:
    src/android.cpp
    src/main.cpp
  unknown:
    android/bin/
    android/gen/
    android/libs/
    android/local.properties
    android/obj/
    android/proguard-project.txt
  pending merges:
    Jesse Barker 2013-05-17 SceneCollection: Consolidate the scene vector population into an object to
  2 shelves exist. See "bzr shelve --list" for details.
added:
  src/scene-collection.h
modified:
  src/android.cpp
  src/main.cpp


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

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

Patch

=== modified file 'src/android.cpp'
--- src/android.cpp	2013-05-17 14:54:18 +0000
+++ src/android.cpp	2013-05-17 16:39:23 +0000
@@ -33,10 +33,12 @@ 
 #include "util.h"
 #include "main-loop.h"
 #include "benchmark-collection.h"
+#include "scene-collection.h"
 
 static Canvas *g_canvas;
 static MainLoop *g_loop;
 static BenchmarkCollection *g_benchmark_collection;
+static SceneCollection *g_scene_collection;
 static std::ostream *g_log_extra;
 
 class MainLoopAndroid : public MainLoop
@@ -251,36 +253,6 @@ 
     DummyCanvas() : Canvas(0, 0) {}
 };
 
-/** 
- * Creates all the available scenes and adds them to the supplied vector.
- * 
- * @param scenes the vector to add the scenes to
- * @param canvas the canvas to create the scenes with
- */
-static void
-create_and_add_scenes(std::vector<Scene*>& scenes, Canvas& canvas)
-{
-    scenes.push_back(new SceneDefaultOptions(canvas));
-    scenes.push_back(new SceneBuild(canvas));
-    scenes.push_back(new SceneTexture(canvas));
-    scenes.push_back(new SceneShading(canvas));
-    scenes.push_back(new SceneConditionals(canvas));
-    scenes.push_back(new SceneFunction(canvas));
-    scenes.push_back(new SceneLoop(canvas));
-    scenes.push_back(new SceneBump(canvas));
-    scenes.push_back(new SceneEffect2D(canvas));
-    scenes.push_back(new ScenePulsar(canvas));
-    scenes.push_back(new SceneDesktop(canvas));
-    scenes.push_back(new SceneBuffer(canvas));
-    scenes.push_back(new SceneIdeas(canvas));
-    scenes.push_back(new SceneTerrain(canvas));
-    scenes.push_back(new SceneJellyfish(canvas));
-    scenes.push_back(new SceneShadow(canvas));
-    scenes.push_back(new SceneRefract(canvas));
-    scenes.push_back(new SceneClear(canvas));
-}
-
-
 void
 Java_org_linaro_glmark2_native_init(JNIEnv* env, jclass clazz,
                                     jobject asset_manager,
@@ -328,17 +300,9 @@ 
     Log::info("glmark2 %s\n", GLMARK_VERSION);
     g_canvas->print_info();
 
-    std::vector<Scene*> scenes;
-
     /* Add and register scenes */
-    create_and_add_scenes(scenes, *g_canvas);
-
-    for (std::vector<Scene*>::const_iterator iter = scenes.begin();
-         iter != scenes.end();
-         iter++)
-    {
-        Benchmark::register_scene(**iter);
-    }
+    g_scene_collection = new SceneCollection(*g_canvas);
+    g_scene_collection->register_scenes();
 
     g_benchmark_collection = new BenchmarkCollection();
     g_benchmark_collection->populate_from_options();
@@ -373,6 +337,7 @@ 
 
     delete g_loop;
     delete g_benchmark_collection;
+    delete g_scene_collection;
     delete g_canvas;
     delete g_log_extra;
 }
@@ -413,12 +378,11 @@ 
 
     Util::android_set_asset_manager(AAssetManager_fromJava(env, asset_manager));
 
-    std::vector<Scene*> scenes;
     DummyCanvas canvas;
+    SceneCollection sc(canvas);
+    const std::vector<Scene*>& scenes = sc.get();
     std::vector<jobject> si_vector;
 
-    create_and_add_scenes(scenes, canvas);
-
     /* Create SceneInfo instances for all the scenes */
     for (std::vector<Scene*>::const_iterator iter = scenes.begin();
          iter != scenes.end();
@@ -436,8 +400,6 @@ 
     for (size_t i = 0; i < si_vector.size(); i++)
         env->SetObjectArrayElement(si_array, i, si_vector[i]);
 
-    Util::dispose_pointer_vector(scenes);
-
     return si_array;
 }
 

=== modified file 'src/main.cpp'
--- src/main.cpp	2013-05-16 18:38:54 +0000
+++ src/main.cpp	2013-05-17 16:39:23 +0000
@@ -31,6 +31,7 @@ 
 #include "text-renderer.h"
 #include "main-loop.h"
 #include "benchmark-collection.h"
+#include "scene-collection.h"
 
 #include <iostream>
 #include <fstream>
@@ -215,10 +216,9 @@ 
 
     canvas.visual_config(Options::visual_config);
 
-    vector<Scene*> scenes;
-
     // Register the scenes, so they can be looked up by name
-    add_and_register_scenes(scenes, canvas);
+    SceneCollection scenes(canvas);
+    scenes.register_scenes();
 
     if (Options::list_scenes) {
         list_scenes();
@@ -243,7 +243,5 @@ 
     else
         do_benchmark(canvas);
 
-    Util::dispose_pointer_vector(scenes);
-
     return 0;
 }

=== added file 'src/scene-collection.h'
--- src/scene-collection.h	1970-01-01 00:00:00 +0000
+++ src/scene-collection.h	2013-05-17 16:39:23 +0000
@@ -0,0 +1,81 @@ 
+//
+// Copyright Š 2013 Linaro Limited
+//
+// This file is part of the glmark2 OpenGL (ES) 2.0 benchmark.
+//
+// glmark2 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.
+//
+// glmark2 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
+// glmark2.  If not, see <http://www.gnu.org/licenses/>.
+//
+// Authors:
+//  Jesse Barker
+//  Alexandros Frantzis
+//
+#ifndef GLMARK2_SCENE_COLLECTION_H_
+#define GLMARK2_SCENE_COLLECTION_H_
+
+#include <vector>
+#include "scene.h"
+
+
+class SceneCollection
+{
+public:
+    SceneCollection(Canvas& canvas) 
+    {
+        add_scenes(canvas);
+    }
+    ~SceneCollection() { Util::dispose_pointer_vector(scenes_); }
+    void register_scenes()
+    {
+        for (std::vector<Scene*>::const_iterator iter = scenes_.begin();
+             iter != scenes_.end();
+             iter++)
+        {
+            Benchmark::register_scene(**iter);
+        }
+    }
+    const std::vector<Scene*>& get() { return scenes_; }
+
+private:
+    std::vector<Scene*> scenes_;
+
+    //
+    // Creates all the available scenes and adds them to the supplied vector.
+    // 
+    // @param scenes the vector to add the scenes to
+    // @param canvas the canvas to create the scenes with
+    //
+    void add_scenes(Canvas& canvas)
+    {
+        scenes_.push_back(new SceneDefaultOptions(canvas));
+        scenes_.push_back(new SceneBuild(canvas));
+        scenes_.push_back(new SceneTexture(canvas));
+        scenes_.push_back(new SceneShading(canvas));
+        scenes_.push_back(new SceneConditionals(canvas));
+        scenes_.push_back(new SceneFunction(canvas));
+        scenes_.push_back(new SceneLoop(canvas));
+        scenes_.push_back(new SceneBump(canvas));
+        scenes_.push_back(new SceneEffect2D(canvas));
+        scenes_.push_back(new ScenePulsar(canvas));
+        scenes_.push_back(new SceneDesktop(canvas));
+        scenes_.push_back(new SceneBuffer(canvas));
+        scenes_.push_back(new SceneIdeas(canvas));
+        scenes_.push_back(new SceneTerrain(canvas));
+        scenes_.push_back(new SceneJellyfish(canvas));
+        scenes_.push_back(new SceneShadow(canvas));
+        scenes_.push_back(new SceneRefract(canvas));
+        scenes_.push_back(new SceneClear(canvas));
+
+    }
+};
+#endif // GLMARK2_SCENE_COLLECTION_H_