1 // Copyright 2019 The Chromium 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 "gpu/command_buffer/service/context_state_test_helpers.h"
6 
7 #include "gpu/command_buffer/service/feature_info.h"
8 #include "ui/gfx/geometry/size.h"
9 #include "ui/gl/gl_version_info.h"
10 
11 using ::testing::_;
12 
13 namespace gpu {
14 // Include the auto-generated part of this file. We split this because it means
15 // we can easily edit the non-auto generated parts right here in this file
16 // instead of having to edit some template or the code generator.
17 #include "gpu/command_buffer/service/context_state_test_helpers_autogen.h"
18 
SetupInitState(MockGL * gl,gles2::FeatureInfo * feature_info,const gfx::Size & initial_size)19 void ContextStateTestHelpers::SetupInitState(MockGL* gl,
20                                              gles2::FeatureInfo* feature_info,
21                                              const gfx::Size& initial_size) {
22   SetupInitCapabilitiesExpectations(gl, feature_info);
23   SetupInitStateExpectations(gl, feature_info, initial_size);
24 }
25 
SetupInitStateManualExpectations(MockGL * gl,gles2::FeatureInfo * feature_info)26 void ContextStateTestHelpers::SetupInitStateManualExpectations(
27     MockGL* gl,
28     gles2::FeatureInfo* feature_info) {
29   if (feature_info->IsES3Capable()) {
30     EXPECT_CALL(*gl, PixelStorei(GL_PACK_ROW_LENGTH, 0))
31         .Times(1)
32         .RetiresOnSaturation();
33     EXPECT_CALL(*gl, PixelStorei(GL_UNPACK_ROW_LENGTH, 0))
34         .Times(1)
35         .RetiresOnSaturation();
36     EXPECT_CALL(*gl, PixelStorei(GL_UNPACK_IMAGE_HEIGHT, 0))
37         .Times(1)
38         .RetiresOnSaturation();
39     if (feature_info->feature_flags().ext_window_rectangles) {
40       EXPECT_CALL(*gl, WindowRectanglesEXT(GL_EXCLUSIVE_EXT, 0, nullptr))
41           .Times(1)
42           .RetiresOnSaturation();
43     }
44   }
45 }
46 
SetupInitStateManualExpectationsForDoLineWidth(MockGL * gl,GLfloat width)47 void ContextStateTestHelpers::SetupInitStateManualExpectationsForDoLineWidth(
48     MockGL* gl,
49     GLfloat width) {
50   EXPECT_CALL(*gl, LineWidth(width)).Times(1).RetiresOnSaturation();
51 }
52 
ExpectEnableDisable(MockGL * gl,GLenum cap,bool enable)53 void ContextStateTestHelpers::ExpectEnableDisable(MockGL* gl,
54                                                   GLenum cap,
55                                                   bool enable) {
56   if (enable) {
57     EXPECT_CALL(*gl, Enable(cap)).Times(1).RetiresOnSaturation();
58   } else {
59     EXPECT_CALL(*gl, Disable(cap)).Times(1).RetiresOnSaturation();
60   }
61 }
62 
63 }  // namespace gpu
64