• 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 "glinterface.h"
6 #include "glinterfacetest.h"
7 #include "main.h"
8 
9 namespace glbench {
10 
11 namespace {
12 
IsEven(int value)13 bool IsEven(int value) {
14   return ((value % 2) == 0);
15 }
16 
17 }  // namespace
18 
19 class ContextTest : public GLInterfaceTest {
20  public:
ContextTest()21   ContextTest() {}
~ContextTest()22   virtual ~ContextTest() {}
23   virtual bool TestFunc(uint64_t iterations);
Name() const24   virtual const char* Name() const { return "context"; }
25 
26  private:
27   DISALLOW_COPY_AND_ASSIGN(ContextTest);
28 };
29 
TestFunc(uint64_t iterations)30 bool ContextTest::TestFunc(uint64_t iterations) {
31   GLInterface* interface = g_main_gl_interface.get();
32   CHECK(interface);
33   GLContext main_context = interface->GetMainContext();
34   GLContext new_context = interface->CreateContext();
35   CHECK(main_context);
36   CHECK(new_context);
37 
38   // re-bind VBO on new context
39   interface->MakeCurrent(new_context);
40   SetupGLRendering();
41   interface->MakeCurrent(main_context);
42 
43   for (uint64_t i = 0; i < iterations; ++i) {
44     if (!render_func_.is_null())
45       render_func_.Run();
46     interface->MakeCurrent(IsEven(i) ? new_context : main_context);
47   }
48 
49   interface->MakeCurrent(main_context);
50   interface->DeleteContext(new_context);
51   return true;
52 }
53 
GetContextTest()54 TestBase* GetContextTest() {
55   return new ContextTest;
56 }
57 
58 }  // namespace glbench
59