File: gl_fence_sync_unittest.cc

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (102 lines) | stat: -rw-r--r-- 2,917 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <GLES2/gl2extchromium.h>

#include <memory>

#include "base/bind.h"
#include "gpu/command_buffer/common/sync_token.h"
#include "gpu/command_buffer/service/sync_point_manager.h"
#include "gpu/command_buffer/tests/gl_manager.h"
#include "gpu/command_buffer/tests/gl_test_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

#define SHADER(Src) #Src

namespace gpu {

class GLFenceSyncTest : public testing::Test {
 protected:
  void SetUp() override {
    sync_point_manager_.reset(new SyncPointManager(false));

    GLManager::Options options;
    options.sync_point_manager = sync_point_manager_.get();
    gl1_.Initialize(options);
    gl2_.Initialize(options);
  }

  void TearDown() override {
    gl2_.Destroy();
    gl1_.Destroy();

    sync_point_manager_.reset();
  }

  std::unique_ptr<SyncPointManager> sync_point_manager_;
  GLManager gl1_;
  GLManager gl2_;
};

TEST_F(GLFenceSyncTest, SimpleReleaseWait) {
  gl1_.MakeCurrent();

  const GLuint64 fence_sync = glInsertFenceSyncCHROMIUM();
  SyncToken sync_token;
  glFlush();
  glGenSyncTokenCHROMIUM(fence_sync, sync_token.GetData());
  ASSERT_TRUE(GL_NO_ERROR == glGetError());

  // Make sure it is actually released.
  scoped_refptr<SyncPointClientState> gl1_client_state =
      sync_point_manager_->GetSyncPointClientState(gl1_.GetNamespaceID(),
                                                   gl1_.GetCommandBufferID());
  EXPECT_TRUE(gl1_client_state->IsFenceSyncReleased(fence_sync));

  gl2_.MakeCurrent();
  glWaitSyncTokenCHROMIUM(sync_token.GetConstData());
  glFinish();

  // gl2 should not have released anything.
  scoped_refptr<SyncPointClientState> gl2_client_state =
      sync_point_manager_->GetSyncPointClientState(gl2_.GetNamespaceID(),
                                                   gl2_.GetCommandBufferID());
  EXPECT_EQ(0u, gl2_client_state->fence_sync_release());
}

static void TestCallback(int* storage, int assign) {
  *storage = assign;
}

TEST_F(GLFenceSyncTest, SimpleReleaseSignal) {
  gl1_.MakeCurrent();

  // Pause the command buffer so the fence sync does not immediately trigger.
  gl1_.SetCommandsPaused(true);

  const GLuint64 fence_sync = glInsertFenceSyncCHROMIUM();
  SyncToken sync_token;
  glGenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData());
  glFlush();
  ASSERT_TRUE(sync_token.HasData());

  gl2_.MakeCurrent();
  int callback_called = 0;
  gl2_.SignalSyncToken(sync_token,
                       base::Bind(TestCallback, &callback_called, 1));

  gl1_.MakeCurrent();
  EXPECT_EQ(0, callback_called);

  gl1_.SetCommandsPaused(false);
  glFinish();

  EXPECT_EQ(1, callback_called);
}

}  // namespace gpu