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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif
#include "gpu/command_buffer/service/gles2_cmd_decoder.h"
#include <stdint.h>
#include "base/command_line.h"
#include "base/strings/string_number_conversions.h"
#include "gpu/command_buffer/common/gles2_cmd_format.h"
#include "gpu/command_buffer/common/gles2_cmd_utils.h"
#include "gpu/command_buffer/service/context_group.h"
#include "gpu/command_buffer/service/context_state.h"
#include "gpu/command_buffer/service/gl_surface_mock.h"
#include "gpu/command_buffer/service/gles2_cmd_decoder_unittest.h"
#include "gpu/command_buffer/service/gpu_switches.h"
#include "gpu/command_buffer/service/mocks.h"
#include "gpu/command_buffer/service/program_manager.h"
#include "gpu/command_buffer/service/test_helper.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_mock.h"
#include "ui/gl/gl_surface_stub.h"
#if !defined(GL_DEPTH24_STENCIL8)
#define GL_DEPTH24_STENCIL8 0x88F0
#endif
using ::gl::MockGLInterface;
using ::testing::_;
using ::testing::DoAll;
using ::testing::InSequence;
using ::testing::Invoke;
using ::testing::MatcherCast;
using ::testing::Mock;
using ::testing::Pointee;
using ::testing::Return;
using ::testing::SaveArg;
using ::testing::SetArrayArgument;
using ::testing::SetArgPointee;
using ::testing::SetArgPointee;
using ::testing::StrEq;
using ::testing::StrictMock;
namespace gpu {
namespace gles2 {
namespace {
void SetupUpdateES3UnpackParametersExpectations(::gl::MockGLInterface* gl,
GLint row_length,
GLint image_height) {
EXPECT_CALL(*gl, PixelStorei(GL_UNPACK_ROW_LENGTH, row_length))
.Times(1)
.RetiresOnSaturation();
EXPECT_CALL(*gl, PixelStorei(GL_UNPACK_IMAGE_HEIGHT, image_height))
.Times(1)
.RetiresOnSaturation();
}
} // namespace anonymous
class GLES2DecoderRestoreStateTest : public GLES2DecoderManualInitTest {
public:
GLES2DecoderRestoreStateTest() = default;
protected:
void AddExpectationsForActiveTexture(GLenum unit);
void AddExpectationsForBindTexture(GLenum target, GLuint id);
void InitializeContextState(ContextState* state,
uint32_t non_default_unit,
uint32_t active_unit);
// ES3 specific.
scoped_refptr<FeatureInfo> SetupForES3Test();
void AddExpectationsForBindSampler(GLuint unit, GLuint id);
};
INSTANTIATE_TEST_SUITE_P(Service,
GLES2DecoderRestoreStateTest,
::testing::Bool());
void GLES2DecoderRestoreStateTest::AddExpectationsForActiveTexture(
GLenum unit) {
EXPECT_CALL(*gl_, ActiveTexture(unit)).Times(1).RetiresOnSaturation();
}
void GLES2DecoderRestoreStateTest::AddExpectationsForBindTexture(GLenum target,
GLuint id) {
EXPECT_CALL(*gl_, BindTexture(target, id)).Times(1).RetiresOnSaturation();
}
void GLES2DecoderRestoreStateTest::InitializeContextState(
ContextState* state,
uint32_t non_default_unit,
uint32_t active_unit) {
state->texture_units.resize(group().max_texture_units());
for (uint32_t tt = 0; tt < state->texture_units.size(); ++tt) {
TextureRef* ref_cube_map =
group().texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_CUBE_MAP);
state->texture_units[tt].bound_texture_cube_map = ref_cube_map;
TextureRef* ref_2d =
(tt == non_default_unit)
? group().texture_manager()->GetTexture(client_texture_id_)
: group().texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_2D);
state->texture_units[tt].bound_texture_2d = ref_2d;
}
state->active_texture_unit = active_unit;
// Set up the sampler units just for convenience of the ES3-specific
// tests in this file.
state->sampler_units.resize(group().max_texture_units());
}
scoped_refptr<FeatureInfo> GLES2DecoderRestoreStateTest::SetupForES3Test() {
InitState init;
init.gl_version = "OpenGL ES 3.0";
init.context_type = CONTEXT_TYPE_OPENGLES3;
InitDecoder(init);
// Construct a previous ContextState assuming an ES3 context and with all
// texture bindings set to default textures.
scoped_refptr<FeatureInfo> feature_info = new FeatureInfo;
TestHelper::SetupFeatureInfoInitExpectationsWithGLVersion(
gl_.get(), "", "", "OpenGL ES 3.0", CONTEXT_TYPE_OPENGLES3);
feature_info->InitializeForTesting(CONTEXT_TYPE_OPENGLES3);
return feature_info;
}
void GLES2DecoderRestoreStateTest::AddExpectationsForBindSampler(GLuint unit,
GLuint id) {
EXPECT_CALL(*gl_, BindSampler(unit, id)).Times(1).RetiresOnSaturation();
}
TEST_P(GLES2DecoderRestoreStateTest, NullPreviousStateBGR) {
InitState init;
init.gl_version = "OpenGL ES 2.0";
init.bind_generates_resource = true;
InitDecoder(init);
SetupTexture();
InSequence sequence;
// Expect to restore texture bindings for unit GL_TEXTURE0.
AddExpectationsForActiveTexture(GL_TEXTURE0);
AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP,
TestHelper::kServiceDefaultTextureCubemapId);
// Expect to restore texture bindings for remaining units.
for (uint32_t i = 1; i < group().max_texture_units(); ++i) {
AddExpectationsForActiveTexture(GL_TEXTURE0 + i);
AddExpectationsForBindTexture(GL_TEXTURE_2D,
TestHelper::kServiceDefaultTexture2dId);
AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP,
TestHelper::kServiceDefaultTextureCubemapId);
}
// Expect to restore the active texture unit to GL_TEXTURE0.
AddExpectationsForActiveTexture(GL_TEXTURE0);
GetDecoder()->RestoreAllTextureUnitAndSamplerBindings(nullptr);
}
TEST_P(GLES2DecoderRestoreStateTest, NullPreviousState) {
InitState init;
init.gl_version = "OpenGL ES 2.0";
InitDecoder(init);
SetupTexture();
InSequence sequence;
// Expect to restore texture bindings for unit GL_TEXTURE0.
AddExpectationsForActiveTexture(GL_TEXTURE0);
AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP, 0);
// Expect to restore texture bindings for remaining units.
for (uint32_t i = 1; i < group().max_texture_units(); ++i) {
AddExpectationsForActiveTexture(GL_TEXTURE0 + i);
AddExpectationsForBindTexture(GL_TEXTURE_2D, 0);
AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP, 0);
}
// Expect to restore the active texture unit to GL_TEXTURE0.
AddExpectationsForActiveTexture(GL_TEXTURE0);
GetDecoder()->RestoreAllTextureUnitAndSamplerBindings(nullptr);
}
TEST_P(GLES2DecoderRestoreStateTest, WithPreviousStateBGR) {
InitState init;
init.bind_generates_resource = true;
InitDecoder(init);
SetupTexture();
// Construct a previous ContextState with all texture bindings
// set to default textures.
ContextState prev_state(nullptr);
InitializeContextState(&prev_state, std::numeric_limits<uint32_t>::max(), 0);
InSequence sequence;
// Expect to restore only GL_TEXTURE_2D binding for GL_TEXTURE0 unit,
// since the rest of the bindings haven't changed between the current
// state and the |prev_state|.
AddExpectationsForActiveTexture(GL_TEXTURE0);
AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
// Expect to restore active texture unit to GL_TEXTURE0.
AddExpectationsForActiveTexture(GL_TEXTURE0);
GetDecoder()->RestoreAllTextureUnitAndSamplerBindings(&prev_state);
}
TEST_P(GLES2DecoderRestoreStateTest, WithPreviousState) {
InitState init;
InitDecoder(init);
SetupTexture();
// Construct a previous ContextState with all texture bindings
// set to default textures.
ContextState prev_state(nullptr);
InitializeContextState(&prev_state, std::numeric_limits<uint32_t>::max(), 0);
InSequence sequence;
// Expect to restore only GL_TEXTURE_2D binding for GL_TEXTURE0 unit,
// since the rest of the bindings haven't changed between the current
// state and the |prev_state|.
AddExpectationsForActiveTexture(GL_TEXTURE0);
AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
// Expect to restore active texture unit to GL_TEXTURE0.
AddExpectationsForActiveTexture(GL_TEXTURE0);
GetDecoder()->RestoreAllTextureUnitAndSamplerBindings(&prev_state);
}
TEST_P(GLES2DecoderRestoreStateTest, ActiveUnit1) {
InitState init;
InitDecoder(init);
// Bind a non-default texture to GL_TEXTURE1 unit.
EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1));
cmds::ActiveTexture cmd;
cmd.Init(GL_TEXTURE1);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
SetupTexture();
// Construct a previous ContextState with all texture bindings
// set to default textures.
ContextState prev_state(nullptr);
InitializeContextState(&prev_state, std::numeric_limits<uint32_t>::max(), 0);
InSequence sequence;
// Expect to restore only GL_TEXTURE_2D binding for GL_TEXTURE1 unit,
// since the rest of the bindings haven't changed between the current
// state and the |prev_state|.
AddExpectationsForActiveTexture(GL_TEXTURE1);
AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
// Expect to restore active texture unit to GL_TEXTURE1.
AddExpectationsForActiveTexture(GL_TEXTURE1);
GetDecoder()->RestoreAllTextureUnitAndSamplerBindings(&prev_state);
}
TEST_P(GLES2DecoderRestoreStateTest, NonDefaultUnit0BGR) {
InitState init;
init.bind_generates_resource = true;
InitDecoder(init);
// Bind a non-default texture to GL_TEXTURE1 unit.
EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1));
SpecializedSetup<cmds::ActiveTexture, 0>(true);
cmds::ActiveTexture cmd;
cmd.Init(GL_TEXTURE1);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
SetupTexture();
// Construct a previous ContextState with GL_TEXTURE_2D target in
// GL_TEXTURE0 unit bound to a non-default texture and the rest
// set to default textures.
ContextState prev_state(nullptr);
InitializeContextState(&prev_state, 0, kServiceTextureId);
InSequence sequence;
// Expect to restore GL_TEXTURE_2D binding for GL_TEXTURE0 unit to
// a default texture.
AddExpectationsForActiveTexture(GL_TEXTURE0);
AddExpectationsForBindTexture(GL_TEXTURE_2D,
TestHelper::kServiceDefaultTexture2dId);
// Expect to restore GL_TEXTURE_2D binding for GL_TEXTURE1 unit to
// non-default.
AddExpectationsForActiveTexture(GL_TEXTURE1);
AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
// Expect to restore active texture unit to GL_TEXTURE1.
AddExpectationsForActiveTexture(GL_TEXTURE1);
GetDecoder()->RestoreAllTextureUnitAndSamplerBindings(&prev_state);
}
TEST_P(GLES2DecoderRestoreStateTest, NonDefaultUnit1BGR) {
InitState init;
init.bind_generates_resource = true;
InitDecoder(init);
// Bind a non-default texture to GL_TEXTURE0 unit.
SetupTexture();
// Construct a previous ContextState with GL_TEXTURE_2D target in
// GL_TEXTURE1 unit bound to a non-default texture and the rest
// set to default textures.
ContextState prev_state(nullptr);
InitializeContextState(&prev_state, 1, kServiceTextureId);
InSequence sequence;
// Expect to restore GL_TEXTURE_2D binding to the non-default texture
// for GL_TEXTURE0 unit.
AddExpectationsForActiveTexture(GL_TEXTURE0);
AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
// Expect to restore GL_TEXTURE_2D binding to the default texture
// for GL_TEXTURE1 unit.
AddExpectationsForActiveTexture(GL_TEXTURE1);
AddExpectationsForBindTexture(GL_TEXTURE_2D,
TestHelper::kServiceDefaultTexture2dId);
// Expect to restore active texture unit to GL_TEXTURE0.
AddExpectationsForActiveTexture(GL_TEXTURE0);
GetDecoder()->RestoreAllTextureUnitAndSamplerBindings(&prev_state);
}
TEST_P(GLES2DecoderRestoreStateTest, DefaultUnit0) {
InitState init;
InitDecoder(init);
// Bind a non-default texture to GL_TEXTURE1 unit.
EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1));
SpecializedSetup<cmds::ActiveTexture, 0>(true);
cmds::ActiveTexture cmd;
cmd.Init(GL_TEXTURE1);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
SetupTexture();
// Construct a previous ContextState with GL_TEXTURE_2D target in
// GL_TEXTURE0 unit bound to a non-default texture and the rest
// set to default textures.
ContextState prev_state(nullptr);
InitializeContextState(&prev_state, 0, kServiceTextureId);
InSequence sequence;
// Expect to restore GL_TEXTURE_2D binding for GL_TEXTURE0 unit to
// the 0 texture.
AddExpectationsForActiveTexture(GL_TEXTURE0);
AddExpectationsForBindTexture(GL_TEXTURE_2D, 0);
// Expect to restore GL_TEXTURE_2D binding for GL_TEXTURE1 unit to
// non-default.
AddExpectationsForActiveTexture(GL_TEXTURE1);
AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
// Expect to restore active texture unit to GL_TEXTURE1.
AddExpectationsForActiveTexture(GL_TEXTURE1);
GetDecoder()->RestoreAllTextureUnitAndSamplerBindings(&prev_state);
}
TEST_P(GLES2DecoderRestoreStateTest, DefaultUnit1) {
InitState init;
InitDecoder(init);
// Bind a non-default texture to GL_TEXTURE0 unit.
SetupTexture();
// Construct a previous ContextState with GL_TEXTURE_2D target in
// GL_TEXTURE1 unit bound to a non-default texture and the rest
// set to default textures.
ContextState prev_state(nullptr);
InitializeContextState(&prev_state, 1, kServiceTextureId);
InSequence sequence;
// Expect to restore GL_TEXTURE_2D binding to the non-default texture
// for GL_TEXTURE0 unit.
AddExpectationsForActiveTexture(GL_TEXTURE0);
AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
// Expect to restore GL_TEXTURE_2D binding to the 0 texture
// for GL_TEXTURE1 unit.
AddExpectationsForActiveTexture(GL_TEXTURE1);
AddExpectationsForBindTexture(GL_TEXTURE_2D, 0);
// Expect to restore active texture unit to GL_TEXTURE0.
AddExpectationsForActiveTexture(GL_TEXTURE0);
GetDecoder()->RestoreAllTextureUnitAndSamplerBindings(&prev_state);
}
TEST_P(GLES2DecoderRestoreStateTest, ES3NullPreviousStateWithSampler) {
// This ES3-specific test is scoped within GLES2DecoderRestoreStateTest
// to avoid doing large refactorings of these tests.
InitState init;
init.gl_version = "OpenGL ES 3.0";
init.context_type = CONTEXT_TYPE_OPENGLES3;
InitDecoder(init);
SetupTexture();
SetupSampler();
InSequence sequence;
// Expect to restore texture bindings for unit GL_TEXTURE0.
AddExpectationsForActiveTexture(GL_TEXTURE0);
AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP, 0);
AddExpectationsForBindTexture(GL_TEXTURE_2D_ARRAY, 0);
AddExpectationsForBindTexture(GL_TEXTURE_3D, 0);
// Expect to restore sampler binding for unit GL_TEXTURE0.
AddExpectationsForBindSampler(0, kServiceSamplerId);
// Expect to restore texture bindings for remaining units.
for (uint32_t i = 1; i < group().max_texture_units(); ++i) {
AddExpectationsForActiveTexture(GL_TEXTURE0 + i);
AddExpectationsForBindTexture(GL_TEXTURE_2D, 0);
AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP, 0);
AddExpectationsForBindTexture(GL_TEXTURE_2D_ARRAY, 0);
AddExpectationsForBindTexture(GL_TEXTURE_3D, 0);
AddExpectationsForBindSampler(i, 0);
}
// Expect to restore the active texture unit to GL_TEXTURE0.
AddExpectationsForActiveTexture(GL_TEXTURE0);
GetDecoder()->RestoreAllTextureUnitAndSamplerBindings(nullptr);
}
TEST_P(GLES2DecoderRestoreStateTest, ES3RestoreExistingSampler) {
// This ES3-specific test is scoped within GLES2DecoderRestoreStateTest
// to avoid doing large refactorings of these tests.
auto feature_info = SetupForES3Test();
SetupSampler();
// Construct a previous ContextState assuming an ES3 context and with all
// texture bindings set to default textures.
ContextState prev_state(feature_info.get());
InitializeContextState(&prev_state, std::numeric_limits<uint32_t>::max(), 0);
InSequence sequence;
// Expect to restore sampler binding for unit GL_TEXTURE0.
AddExpectationsForBindSampler(0, kServiceSamplerId);
// Expect to restore the active texture unit to GL_TEXTURE0.
AddExpectationsForActiveTexture(GL_TEXTURE0);
GetDecoder()->RestoreAllTextureUnitAndSamplerBindings(&prev_state);
}
TEST_P(GLES2DecoderRestoreStateTest, ES3RestoreZeroSampler) {
// This ES3-specific test is scoped within GLES2DecoderRestoreStateTest
// to avoid doing large refactorings of these tests.
auto feature_info = SetupForES3Test();
// Construct a previous ContextState assuming an ES3 context and with all
// texture bindings set to default textures.
SamplerManager sampler_manager(feature_info.get());
ContextState prev_state(feature_info.get());
InitializeContextState(&prev_state, std::numeric_limits<uint32_t>::max(), 0);
// Set up a sampler in the previous state. The client_id and service_id
// don't matter except that they're non-zero.
prev_state.sampler_units[0] = new Sampler(&sampler_manager, 1, 2);
InSequence sequence;
// Expect to restore the zero sampler on unit GL_TEXTURE0.
AddExpectationsForBindSampler(0, 0);
// Expect to restore the active texture unit to GL_TEXTURE0.
AddExpectationsForActiveTexture(GL_TEXTURE0);
GetDecoder()->RestoreAllTextureUnitAndSamplerBindings(&prev_state);
// Tell the sampler manager to destroy itself without a context so we
// don't have to set up more expectations.
sampler_manager.Destroy(false);
}
TEST_P(GLES2DecoderManualInitTest, ContextStateCapabilityCaching) {
struct TestInfo {
GLenum gl_enum;
bool default_state;
bool expect_set;
};
// TODO(vmiura): Should autogen this to match build_gles2_cmd_buffer.py.
TestInfo test[] = {{GL_BLEND, false, true},
{GL_CULL_FACE, false, true},
{GL_DEPTH_TEST, false, false},
{GL_DITHER, true, true},
{GL_POLYGON_OFFSET_FILL, false, true},
{GL_SAMPLE_ALPHA_TO_COVERAGE, false, true},
{GL_SAMPLE_COVERAGE, false, true},
{GL_SCISSOR_TEST, false, true},
{GL_STENCIL_TEST, false, false},
{0, false, false}};
InitState init;
InitDecoder(init);
for (int i = 0; test[i].gl_enum; i++) {
bool enable_state = test[i].default_state;
// Test setting default state initially is ignored.
EnableDisableTest(test[i].gl_enum, enable_state, test[i].expect_set);
// Test new and cached state changes.
for (int n = 0; n < 3; n++) {
enable_state = !enable_state;
EnableDisableTest(test[i].gl_enum, enable_state, test[i].expect_set);
EnableDisableTest(test[i].gl_enum, enable_state, test[i].expect_set);
}
}
}
TEST_P(GLES3DecoderTest, ES3PixelStoreiWithPixelUnpackBuffer) {
// Without PIXEL_UNPACK_BUFFER bound, PixelStorei with unpack parameters
// is cached and not passed down to GL.
EXPECT_CALL(*gl_, PixelStorei(_, _)).Times(0);
cmds::PixelStorei cmd;
cmd.Init(GL_UNPACK_ROW_LENGTH, 8);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
// When a PIXEL_UNPACK_BUFFER is bound, all cached unpack parameters are
// applied to GL.
SetupUpdateES3UnpackParametersExpectations(gl_.get(), 8, 0);
DoBindBuffer(GL_PIXEL_UNPACK_BUFFER, client_buffer_id_, kServiceBufferId);
// Now with a bound PIXEL_UNPACK_BUFFER, all PixelStorei calls with unpack
// parameters are applied to GL.
EXPECT_CALL(*gl_, PixelStorei(GL_UNPACK_ROW_LENGTH, 16))
.Times(1)
.RetiresOnSaturation();
cmd.Init(GL_UNPACK_ROW_LENGTH, 16);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
// Now unbind PIXEL_UNPACK_BUFFER, all ES3 unpack parameters are set back to
// 0.
SetupUpdateES3UnpackParametersExpectations(gl_.get(), 0, 0);
DoBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0, 0);
// Again, PixelStorei calls with unpack parameters are cached.
EXPECT_CALL(*gl_, PixelStorei(_, _)).Times(0);
cmd.Init(GL_UNPACK_ROW_LENGTH, 32);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
// Bind a PIXEL_UNPACK_BUFFER again.
SetupUpdateES3UnpackParametersExpectations(gl_.get(), 32, 0);
DoBindBuffer(GL_PIXEL_UNPACK_BUFFER, client_buffer_id_, kServiceBufferId);
}
// TODO(vmiura): Tests for VAO restore.
// TODO(vmiura): Tests for ContextState::RestoreAttribute().
// TODO(vmiura): Tests for ContextState::RestoreBufferBindings().
// TODO(vmiura): Tests for ContextState::RestoreProgramBindings().
// TODO(vmiura): Tests for ContextState::RestoreRenderbufferBindings().
// TODO(vmiura): Tests for ContextState::RestoreProgramBindings().
// TODO(vmiura): Tests for ContextState::RestoreGlobalState().
} // namespace gles2
} // namespace gpu
|