File: gl_context_virtual_unittest.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (103 lines) | stat: -rw-r--r-- 4,172 bytes parent folder | download | duplicates (5)
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
103
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "gpu/command_buffer/service/gl_context_virtual.h"

#include "gpu/command_buffer/client/client_test_helper.h"
#include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h"
#include "gpu/command_buffer/service/gpu_service_test.h"
#include "gpu/command_buffer/service/gpu_tracer.h"
#include "ui/gl/gl_context_stub.h"
#include "ui/gl/gl_share_group.h"
#include "ui/gl/gl_surface.h"

namespace gpu {
namespace gles2 {
namespace {

using testing::AnyNumber;
using testing::Return;

class GLContextVirtualTest : public GpuServiceTest {
 public:
  GLContextVirtualTest()
      : decoder_(new MockGLES2Decoder(&client_,
                                      &command_buffer_service_,
                                      &outputter_)) {}
  ~GLContextVirtualTest() override = default;

 protected:
  FakeCommandBufferServiceBase command_buffer_service_;
  FakeDecoderClient client_;
  TraceOutputter outputter_;
  std::unique_ptr<MockGLES2Decoder> decoder_;
};

// Tests that destroying a GLContextVirtual doesn't leave stale state that
// prevents a new one from initializing.
TEST_F(GLContextVirtualTest, Reinitialize) {
  EXPECT_CALL(*gl_, GetError())
      .Times(AnyNumber())
      .WillRepeatedly(Return(GL_NO_ERROR));
  EXPECT_CALL(*gl_, GetString(GL_VERSION))
      .Times(AnyNumber())
      .WillRepeatedly(Return(reinterpret_cast<unsigned const char *>("2.0")));
  EXPECT_CALL(*gl_, GetString(GL_EXTENSIONS))
      .Times(AnyNumber())
      .WillRepeatedly(Return(reinterpret_cast<unsigned const char *>("")));
  {
    auto base_context = base::MakeRefCounted<gl::GLContextStub>();
    gl::GLShareGroup* share_group = base_context->share_group();
    share_group->SetSharedContext(base_context.get());
    auto context = base::MakeRefCounted<GLContextVirtual>(
        share_group, base_context.get(), decoder_->AsWeakPtr());
    EXPECT_TRUE(context->Initialize(GetGLSurface(), gl::GLContextAttribs()));
    EXPECT_TRUE(context->MakeCurrent(GetGLSurface()));
  }
  {
    auto base_context = base::MakeRefCounted<gl::GLContextStub>();
    gl::GLShareGroup* share_group = base_context->share_group();
    share_group->SetSharedContext(base_context.get());
    auto context = base::MakeRefCounted<GLContextVirtual>(
        share_group, base_context.get(), decoder_->AsWeakPtr());
    EXPECT_TRUE(context->Initialize(GetGLSurface(), gl::GLContextAttribs()));
    EXPECT_TRUE(context->MakeCurrent(GetGLSurface()));
  }
}

// Tests that CheckStickyGraphicsResetStatus gets the state from the real
// context, but "virtualizes" the guilty party (i.e. makes it unknown).
TEST_F(GLContextVirtualTest, CheckStickyGraphicsResetStatus) {
  EXPECT_CALL(*gl_, GetError())
      .Times(AnyNumber())
      .WillRepeatedly(Return(GL_NO_ERROR));
  auto base_context = base::MakeRefCounted<gl::GLContextStub>();
  const char gl_extensions[] = "GL_KHR_robustness";
  base_context->SetExtensionsString(gl_extensions);

  gl::GLShareGroup* share_group = base_context->share_group();
  share_group->SetSharedContext(base_context.get());
  auto context = base::MakeRefCounted<GLContextVirtual>(
      share_group, base_context.get(), decoder_->AsWeakPtr());
  EXPECT_TRUE(context->Initialize(GetGLSurface(), gl::GLContextAttribs()));
  EXPECT_TRUE(context->MakeCurrent(GetGLSurface()));

  // If no reset, GLContextVirtual should report no error.
  EXPECT_CALL(*gl_, GetGraphicsResetStatusARB()).WillOnce(Return(GL_NO_ERROR));
  EXPECT_EQ(unsigned{GL_NO_ERROR}, context->CheckStickyGraphicsResetStatus());

  // If reset, GLContextVirtual should report an error, but with an unknown
  // guilty context.
  EXPECT_CALL(*gl_, GetGraphicsResetStatusARB())
      .WillOnce(Return(GL_GUILTY_CONTEXT_RESET));
  EXPECT_EQ(unsigned{GL_UNKNOWN_CONTEXT_RESET},
            context->CheckStickyGraphicsResetStatus());
  // The underlying real context still knows, though.
  EXPECT_EQ(unsigned{GL_GUILTY_CONTEXT_RESET},
            base_context->CheckStickyGraphicsResetStatus());
}

}  // anonymous namespace
}  // namespace gles2
}  // namespace gpu