• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "base/bind.h"
6 #include "base/callback.h"
7 
8 #include "glinterface.h"
9 #include "glinterfacetest.h"
10 #include "main.h"
11 
12 namespace glbench {
13 
14 namespace {
15 
IsEven(int value)16 bool IsEven(int value) {
17   return ((value % 2) == 0);
18 }
19 
20 }  // namespace
21 
22 class ContextTest : public GLInterfaceTest {
23  public:
ContextTest()24   ContextTest() {}
~ContextTest()25   virtual ~ContextTest() {}
26   virtual bool TestFunc(uint64_t iterations);
Name() const27   virtual const char* Name() const { return "context"; }
28 
29  private:
30   DISALLOW_COPY_AND_ASSIGN(ContextTest);
31 };
32 
TestFunc(uint64_t iterations)33 bool ContextTest::TestFunc(uint64_t iterations) {
34   GLInterface* interface = g_main_gl_interface.get();
35   CHECK(interface);
36   GLContext main_context = interface->GetMainContext();
37   GLContext new_context = interface->CreateContext();
38   CHECK(main_context);
39   CHECK(new_context);
40 
41   // re-bind VBO on new context
42   interface->MakeCurrent(new_context);
43   SetupGLRendering();
44   interface->MakeCurrent(main_context);
45 
46   for (uint64_t i = 0 ; i < iterations; ++i) {
47     if (!render_func_.is_null())
48       render_func_.Run();
49     interface->MakeCurrent(IsEven(i) ? new_context : main_context);
50   }
51 
52   interface->MakeCurrent(main_context);
53   interface->DeleteContext(new_context);
54   return true;
55 }
56 
GetContextTest()57 TestBase* GetContextTest() {
58   return new ContextTest;
59 }
60 
61 } // namespace glbench
62