1010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
2010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// found in the LICENSE file.
4010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
5010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "gpu/command_buffer/service/gles2_cmd_decoder.h"
6010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
7010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "base/command_line.h"
8010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "base/strings/string_number_conversions.h"
9010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "gpu/command_buffer/common/gles2_cmd_format.h"
10010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "gpu/command_buffer/common/gles2_cmd_utils.h"
11010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "gpu/command_buffer/common/id_allocator.h"
12010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "gpu/command_buffer/service/async_pixel_transfer_delegate_mock.h"
13010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "gpu/command_buffer/service/async_pixel_transfer_manager.h"
14010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "gpu/command_buffer/service/async_pixel_transfer_manager_mock.h"
15010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "gpu/command_buffer/service/cmd_buffer_engine.h"
16010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "gpu/command_buffer/service/context_group.h"
17010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "gpu/command_buffer/service/context_state.h"
18010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "gpu/command_buffer/service/gl_surface_mock.h"
19010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "gpu/command_buffer/service/gles2_cmd_decoder_unittest.h"
20010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
21010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "gpu/command_buffer/service/gpu_switches.h"
22010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "gpu/command_buffer/service/image_manager.h"
23010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "gpu/command_buffer/service/mailbox_manager.h"
24010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "gpu/command_buffer/service/mocks.h"
25010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "gpu/command_buffer/service/program_manager.h"
26010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "gpu/command_buffer/service/test_helper.h"
27010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h"
28010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "ui/gl/gl_implementation.h"
29010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "ui/gl/gl_mock.h"
30010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "ui/gl/gl_surface_stub.h"
31010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
32010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#if !defined(GL_DEPTH24_STENCIL8)
33010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#define GL_DEPTH24_STENCIL8 0x88F0
34010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#endif
35010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
36010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)using ::gfx::MockGLInterface;
37010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)using ::testing::_;
38010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)using ::testing::DoAll;
39010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)using ::testing::InSequence;
40010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)using ::testing::Invoke;
41010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)using ::testing::MatcherCast;
42010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)using ::testing::Mock;
43010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)using ::testing::Pointee;
44010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)using ::testing::Return;
45010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)using ::testing::SaveArg;
46010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)using ::testing::SetArrayArgument;
47010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)using ::testing::SetArgumentPointee;
48010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)using ::testing::SetArgPointee;
49010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)using ::testing::StrEq;
50010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)using ::testing::StrictMock;
51010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
52010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)namespace gpu {
53010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)namespace gles2 {
54010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
55010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)using namespace cmds;
56010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
57010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)class GLES2DecoderRestoreStateTest : public GLES2DecoderManualInitTest {
58010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) public:
59010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  GLES2DecoderRestoreStateTest() {}
60010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
61010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) protected:
62010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  void AddExpectationsForActiveTexture(GLenum unit);
63010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  void AddExpectationsForBindTexture(GLenum target, GLuint id);
64010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  void InitializeContextState(ContextState* state,
65010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                              uint32 non_default_unit,
66010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                              uint32 active_unit);
67010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)};
68010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
69010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)INSTANTIATE_TEST_CASE_P(Service,
70010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                        GLES2DecoderRestoreStateTest,
71010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                        ::testing::Bool());
72010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
73010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)void GLES2DecoderRestoreStateTest::AddExpectationsForActiveTexture(
74010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    GLenum unit) {
75010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_CALL(*gl_, ActiveTexture(unit)).Times(1).RetiresOnSaturation();
76010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)}
77010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
78010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)void GLES2DecoderRestoreStateTest::AddExpectationsForBindTexture(GLenum target,
79010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                                                                 GLuint id) {
80010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_CALL(*gl_, BindTexture(target, id)).Times(1).RetiresOnSaturation();
81010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)}
82010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
83010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)void GLES2DecoderRestoreStateTest::InitializeContextState(
84010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    ContextState* state,
85010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    uint32 non_default_unit,
86010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    uint32 active_unit) {
87010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  state->texture_units.resize(group().max_texture_units());
88010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  for (uint32 tt = 0; tt < state->texture_units.size(); ++tt) {
89010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    TextureRef* ref_cube_map =
90010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        group().texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_CUBE_MAP);
91010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    state->texture_units[tt].bound_texture_cube_map = ref_cube_map;
92010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    TextureRef* ref_2d =
93010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        (tt == non_default_unit)
94010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)            ? group().texture_manager()->GetTexture(client_texture_id_)
95010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)            : group().texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_2D);
96010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    state->texture_units[tt].bound_texture_2d = ref_2d;
97010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  }
98010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  state->active_texture_unit = active_unit;
99010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)}
100010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
101010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)TEST_P(GLES2DecoderRestoreStateTest, NullPreviousStateBGR) {
102010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  InitState init;
103010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  init.gl_version = "3.0";
104010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  init.bind_generates_resource = true;
105010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  InitDecoder(init);
106010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  SetupTexture();
107010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
108010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  InSequence sequence;
109010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Expect to restore texture bindings for unit GL_TEXTURE0.
110010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  AddExpectationsForActiveTexture(GL_TEXTURE0);
111010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
112010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP,
113010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                                TestHelper::kServiceDefaultTextureCubemapId);
114010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
115010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Expect to restore texture bindings for remaining units.
116010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  for (uint32 i = 1; i < group().max_texture_units(); ++i) {
117010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    AddExpectationsForActiveTexture(GL_TEXTURE0 + i);
118010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    AddExpectationsForBindTexture(GL_TEXTURE_2D,
119010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                                  TestHelper::kServiceDefaultTexture2dId);
120010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP,
121010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                                  TestHelper::kServiceDefaultTextureCubemapId);
122010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  }
123010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
124010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Expect to restore the active texture unit to GL_TEXTURE0.
125010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  AddExpectationsForActiveTexture(GL_TEXTURE0);
126010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
127010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  GetDecoder()->RestoreAllTextureUnitBindings(NULL);
128010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)}
129010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
130010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)TEST_P(GLES2DecoderRestoreStateTest, NullPreviousState) {
131010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  InitState init;
132010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  init.gl_version = "3.0";
133010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  InitDecoder(init);
134010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  SetupTexture();
135010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
136010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  InSequence sequence;
137010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Expect to restore texture bindings for unit GL_TEXTURE0.
138010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  AddExpectationsForActiveTexture(GL_TEXTURE0);
139010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
140010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP, 0);
141010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
142010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Expect to restore texture bindings for remaining units.
143010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  for (uint32 i = 1; i < group().max_texture_units(); ++i) {
144010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    AddExpectationsForActiveTexture(GL_TEXTURE0 + i);
145010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    AddExpectationsForBindTexture(GL_TEXTURE_2D, 0);
146010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP, 0);
147010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  }
148010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
149010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Expect to restore the active texture unit to GL_TEXTURE0.
150010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  AddExpectationsForActiveTexture(GL_TEXTURE0);
151010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
152010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  GetDecoder()->RestoreAllTextureUnitBindings(NULL);
153010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)}
154010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
155010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)TEST_P(GLES2DecoderRestoreStateTest, WithPreviousStateBGR) {
156010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  InitState init;
157010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  init.gl_version = "3.0";
158010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  init.bind_generates_resource = true;
159010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  InitDecoder(init);
160010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  SetupTexture();
161010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
162010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Construct a previous ContextState with all texture bindings
163010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // set to default textures.
164010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  ContextState prev_state(NULL, NULL, NULL);
165010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  InitializeContextState(&prev_state, std::numeric_limits<uint32>::max(), 0);
166010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
167010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  InSequence sequence;
168010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Expect to restore only GL_TEXTURE_2D binding for GL_TEXTURE0 unit,
169010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // since the rest of the bindings haven't changed between the current
170010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // state and the |prev_state|.
171010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  AddExpectationsForActiveTexture(GL_TEXTURE0);
172010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
173010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
174010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Expect to restore active texture unit to GL_TEXTURE0.
175010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  AddExpectationsForActiveTexture(GL_TEXTURE0);
176010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
177010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  GetDecoder()->RestoreAllTextureUnitBindings(&prev_state);
178010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)}
179010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
180010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)TEST_P(GLES2DecoderRestoreStateTest, WithPreviousState) {
181010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  InitState init;
182010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  init.gl_version = "3.0";
183010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  InitDecoder(init);
184010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  SetupTexture();
185010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
186010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Construct a previous ContextState with all texture bindings
187010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // set to default textures.
188010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  ContextState prev_state(NULL, NULL, NULL);
189010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  InitializeContextState(&prev_state, std::numeric_limits<uint32>::max(), 0);
190010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
191010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  InSequence sequence;
192010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Expect to restore only GL_TEXTURE_2D binding for GL_TEXTURE0 unit,
193010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // since the rest of the bindings haven't changed between the current
194010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // state and the |prev_state|.
195010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  AddExpectationsForActiveTexture(GL_TEXTURE0);
196010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
197010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
198010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Expect to restore active texture unit to GL_TEXTURE0.
199010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  AddExpectationsForActiveTexture(GL_TEXTURE0);
200010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
201010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  GetDecoder()->RestoreAllTextureUnitBindings(&prev_state);
202010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)}
203010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
204010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)TEST_P(GLES2DecoderRestoreStateTest, ActiveUnit1) {
205010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  InitState init;
206010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  init.gl_version = "3.0";
207010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  InitDecoder(init);
208010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
209010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Bind a non-default texture to GL_TEXTURE1 unit.
210010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1));
211010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  ActiveTexture cmd;
212010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  cmd.Init(GL_TEXTURE1);
213010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
214010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_EQ(GL_NO_ERROR, GetGLError());
215010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  SetupTexture();
216010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
217010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Construct a previous ContextState with all texture bindings
218010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // set to default textures.
219010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  ContextState prev_state(NULL, NULL, NULL);
220010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  InitializeContextState(&prev_state, std::numeric_limits<uint32>::max(), 0);
221010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
222010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  InSequence sequence;
223010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Expect to restore only GL_TEXTURE_2D binding for GL_TEXTURE1 unit,
224010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // since the rest of the bindings haven't changed between the current
225010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // state and the |prev_state|.
226010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  AddExpectationsForActiveTexture(GL_TEXTURE1);
227010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
228010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
229010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Expect to restore active texture unit to GL_TEXTURE1.
230010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  AddExpectationsForActiveTexture(GL_TEXTURE1);
231010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
232010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  GetDecoder()->RestoreAllTextureUnitBindings(&prev_state);
233010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)}
234010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
235010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)TEST_P(GLES2DecoderRestoreStateTest, NonDefaultUnit0BGR) {
236010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  InitState init;
237010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  init.gl_version = "3.0";
238010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  init.bind_generates_resource = true;
239010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  InitDecoder(init);
240010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
241010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Bind a non-default texture to GL_TEXTURE1 unit.
242010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1));
243010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  SpecializedSetup<ActiveTexture, 0>(true);
244010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  ActiveTexture cmd;
245010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  cmd.Init(GL_TEXTURE1);
246010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
247010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_EQ(GL_NO_ERROR, GetGLError());
248010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  SetupTexture();
249010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
250010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Construct a previous ContextState with GL_TEXTURE_2D target in
251010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // GL_TEXTURE0 unit bound to a non-default texture and the rest
252010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // set to default textures.
253010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  ContextState prev_state(NULL, NULL, NULL);
254010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  InitializeContextState(&prev_state, 0, kServiceTextureId);
255010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
256010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  InSequence sequence;
257010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Expect to restore GL_TEXTURE_2D binding for GL_TEXTURE0 unit to
258010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // a default texture.
259010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  AddExpectationsForActiveTexture(GL_TEXTURE0);
260010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  AddExpectationsForBindTexture(GL_TEXTURE_2D,
261010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                                TestHelper::kServiceDefaultTexture2dId);
262010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
263010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Expect to restore GL_TEXTURE_2D binding for GL_TEXTURE1 unit to
264010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // non-default.
265010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  AddExpectationsForActiveTexture(GL_TEXTURE1);
266010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
267010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
268010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Expect to restore active texture unit to GL_TEXTURE1.
269010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  AddExpectationsForActiveTexture(GL_TEXTURE1);
270010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
271010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  GetDecoder()->RestoreAllTextureUnitBindings(&prev_state);
272010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)}
273010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
274010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)TEST_P(GLES2DecoderRestoreStateTest, NonDefaultUnit1BGR) {
275010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  InitState init;
276010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  init.gl_version = "3.0";
277010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  init.bind_generates_resource = true;
278010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  InitDecoder(init);
279010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
280010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Bind a non-default texture to GL_TEXTURE0 unit.
281010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  SetupTexture();
282010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
283010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Construct a previous ContextState with GL_TEXTURE_2D target in
284010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // GL_TEXTURE1 unit bound to a non-default texture and the rest
285010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // set to default textures.
286010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  ContextState prev_state(NULL, NULL, NULL);
287010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  InitializeContextState(&prev_state, 1, kServiceTextureId);
288010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
289010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  InSequence sequence;
290010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Expect to restore GL_TEXTURE_2D binding to the non-default texture
291010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // for GL_TEXTURE0 unit.
292010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  AddExpectationsForActiveTexture(GL_TEXTURE0);
293010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
294010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
295010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Expect to restore GL_TEXTURE_2D binding to the default texture
296010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // for GL_TEXTURE1 unit.
297010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  AddExpectationsForActiveTexture(GL_TEXTURE1);
298010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  AddExpectationsForBindTexture(GL_TEXTURE_2D,
299010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                                TestHelper::kServiceDefaultTexture2dId);
300010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
301010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Expect to restore active texture unit to GL_TEXTURE0.
302010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  AddExpectationsForActiveTexture(GL_TEXTURE0);
303010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
304010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  GetDecoder()->RestoreAllTextureUnitBindings(&prev_state);
305010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)}
306010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
307010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)TEST_P(GLES2DecoderRestoreStateTest, DefaultUnit0) {
308010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  InitState init;
309010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  init.gl_version = "3.0";
310010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  InitDecoder(init);
311010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
312010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Bind a non-default texture to GL_TEXTURE1 unit.
313010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1));
314010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  SpecializedSetup<ActiveTexture, 0>(true);
315010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  ActiveTexture cmd;
316010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  cmd.Init(GL_TEXTURE1);
317010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
318010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_EQ(GL_NO_ERROR, GetGLError());
319010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  SetupTexture();
320010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
321010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Construct a previous ContextState with GL_TEXTURE_2D target in
322010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // GL_TEXTURE0 unit bound to a non-default texture and the rest
323010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // set to default textures.
324010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  ContextState prev_state(NULL, NULL, NULL);
325010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  InitializeContextState(&prev_state, 0, kServiceTextureId);
326010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
327010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  InSequence sequence;
328010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Expect to restore GL_TEXTURE_2D binding for GL_TEXTURE0 unit to
329010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // the 0 texture.
330010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  AddExpectationsForActiveTexture(GL_TEXTURE0);
331010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  AddExpectationsForBindTexture(GL_TEXTURE_2D, 0);
332010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
333010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Expect to restore GL_TEXTURE_2D binding for GL_TEXTURE1 unit to
334010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // non-default.
335010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  AddExpectationsForActiveTexture(GL_TEXTURE1);
336010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
337010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
338010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Expect to restore active texture unit to GL_TEXTURE1.
339010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  AddExpectationsForActiveTexture(GL_TEXTURE1);
340010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
341010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  GetDecoder()->RestoreAllTextureUnitBindings(&prev_state);
342010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)}
343010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
344010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)TEST_P(GLES2DecoderRestoreStateTest, DefaultUnit1) {
345010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  InitState init;
346010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  init.gl_version = "3.0";
347010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  InitDecoder(init);
348010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
349010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Bind a non-default texture to GL_TEXTURE0 unit.
350010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  SetupTexture();
351010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
352010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Construct a previous ContextState with GL_TEXTURE_2D target in
353010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // GL_TEXTURE1 unit bound to a non-default texture and the rest
354010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // set to default textures.
355010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  ContextState prev_state(NULL, NULL, NULL);
356010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  InitializeContextState(&prev_state, 1, kServiceTextureId);
357010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
358010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  InSequence sequence;
359010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Expect to restore GL_TEXTURE_2D binding to the non-default texture
360010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // for GL_TEXTURE0 unit.
361010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  AddExpectationsForActiveTexture(GL_TEXTURE0);
362010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
363010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
364010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Expect to restore GL_TEXTURE_2D binding to the 0 texture
365010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // for GL_TEXTURE1 unit.
366010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  AddExpectationsForActiveTexture(GL_TEXTURE1);
367010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  AddExpectationsForBindTexture(GL_TEXTURE_2D, 0);
368010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
369010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Expect to restore active texture unit to GL_TEXTURE0.
370010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  AddExpectationsForActiveTexture(GL_TEXTURE0);
371010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
372010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  GetDecoder()->RestoreAllTextureUnitBindings(&prev_state);
373010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)}
374010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
375010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)TEST_P(GLES2DecoderManualInitTest, ContextStateCapabilityCaching) {
376010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  struct TestInfo {
377010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    GLenum gl_enum;
378010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    bool default_state;
379010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    bool expect_set;
380010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  };
381010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
382010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // TODO(vmiura): Should autogen this to match build_gles2_cmd_buffer.py.
383010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  TestInfo test[] = {{GL_BLEND, false, true},
384010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                     {GL_CULL_FACE, false, true},
385010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                     {GL_DEPTH_TEST, false, false},
386010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                     {GL_DITHER, true, true},
387010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                     {GL_POLYGON_OFFSET_FILL, false, true},
388010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                     {GL_SAMPLE_ALPHA_TO_COVERAGE, false, true},
389010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                     {GL_SAMPLE_COVERAGE, false, true},
390010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                     {GL_SCISSOR_TEST, false, true},
391010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                     {GL_STENCIL_TEST, false, false},
392010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                     {0, false, false}};
393010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
394010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  InitState init;
395010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  init.gl_version = "2.1";
396010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  InitDecoder(init);
397010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
398010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  for (int i = 0; test[i].gl_enum; i++) {
399010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    bool enable_state = test[i].default_state;
400010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
401010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    // Test setting default state initially is ignored.
402010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    EnableDisableTest(test[i].gl_enum, enable_state, test[i].expect_set);
403010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
404010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    // Test new and cached state changes.
405010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    for (int n = 0; n < 3; n++) {
406010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      enable_state = !enable_state;
407010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      EnableDisableTest(test[i].gl_enum, enable_state, test[i].expect_set);
408010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      EnableDisableTest(test[i].gl_enum, enable_state, test[i].expect_set);
409010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    }
410010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  }
411010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)}
412010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
413010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// TODO(vmiura): Tests for VAO restore.
414010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
415010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// TODO(vmiura): Tests for ContextState::RestoreAttribute().
416010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
417010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// TODO(vmiura): Tests for ContextState::RestoreBufferBindings().
418010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
419010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// TODO(vmiura): Tests for ContextState::RestoreProgramBindings().
420010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
421010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// TODO(vmiura): Tests for ContextState::RestoreRenderbufferBindings().
422010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
423010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// TODO(vmiura): Tests for ContextState::RestoreProgramBindings().
424010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
425010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// TODO(vmiura): Tests for ContextState::RestoreGlobalState().
426010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
427010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)}  // namespace gles2
428010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)}  // namespace gpu
429