Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / gpu / command_buffer / service / texture_manager_unittest.cc
blob532e25f06d3ea548c6162ec8f915afd04ea3d335
1 // Copyright (c) 2012 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.
5 #include "gpu/command_buffer/service/texture_manager.h"
7 #include <utility>
9 #include "base/command_line.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "gpu/command_buffer/service/error_state_mock.h"
12 #include "gpu/command_buffer/service/feature_info.h"
13 #include "gpu/command_buffer/service/framebuffer_manager.h"
14 #include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h"
15 #include "gpu/command_buffer/service/gpu_service_test.h"
16 #include "gpu/command_buffer/service/mailbox_manager.h"
17 #include "gpu/command_buffer/service/memory_tracking.h"
18 #include "gpu/command_buffer/service/mocks.h"
19 #include "gpu/command_buffer/service/test_helper.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "ui/gl/gl_image_stub.h"
22 #include "ui/gl/gl_mock.h"
23 #include "ui/gl/gl_switches.h"
25 using ::testing::AtLeast;
26 using ::testing::Pointee;
27 using ::testing::Return;
28 using ::testing::SetArgPointee;
29 using ::testing::StrictMock;
30 using ::testing::_;
32 namespace gpu {
33 namespace gles2 {
35 class TextureTestHelper {
36 public:
37 static bool IsNPOT(const Texture* texture) {
38 return texture->npot();
40 static bool IsTextureComplete(const Texture* texture) {
41 return texture->texture_complete();
43 static bool IsCubeComplete(const Texture* texture) {
44 return texture->cube_complete();
48 class TextureManagerTest : public GpuServiceTest {
49 public:
50 static const GLint kMaxTextureSize = 16;
51 static const GLint kMaxCubeMapTextureSize = 8;
52 static const GLint kMaxRectangleTextureSize = 16;
53 static const GLint kMaxExternalTextureSize = 16;
54 static const GLint kMax3DTextureSize = 256;
55 static const GLint kMax2dLevels = 5;
56 static const GLint kMaxCubeMapLevels = 4;
57 static const GLint kMaxExternalLevels = 1;
58 static const bool kUseDefaultTextures = false;
60 TextureManagerTest() {
61 // Always run with this command line, but the ES3 features are not
62 // enabled without FeatureInfo::EnableES3Validators().
63 base::CommandLine command_line(0, nullptr);
64 command_line.AppendSwitch(switches::kEnableUnsafeES3APIs);
65 feature_info_ = new FeatureInfo(command_line);
68 ~TextureManagerTest() override {}
70 protected:
71 void SetUp() override {
72 GpuServiceTest::SetUp();
73 manager_.reset(new TextureManager(NULL,
74 feature_info_.get(),
75 kMaxTextureSize,
76 kMaxCubeMapTextureSize,
77 kMaxRectangleTextureSize,
78 kMax3DTextureSize,
79 kUseDefaultTextures));
80 TestHelper::SetupTextureManagerInitExpectations(
81 gl_.get(), "", kUseDefaultTextures);
82 manager_->Initialize();
83 error_state_.reset(new ::testing::StrictMock<gles2::MockErrorState>());
86 void TearDown() override {
87 manager_->Destroy(false);
88 manager_.reset();
89 GpuServiceTest::TearDown();
92 void SetParameter(
93 TextureRef* texture_ref, GLenum pname, GLint value, GLenum error) {
94 TestHelper::SetTexParameteriWithExpectations(
95 gl_.get(), error_state_.get(), manager_.get(),
96 texture_ref, pname, value, error);
99 scoped_refptr<FeatureInfo> feature_info_;
100 scoped_ptr<TextureManager> manager_;
101 scoped_ptr<MockErrorState> error_state_;
104 // GCC requires these declarations, but MSVC requires they not be present
105 #ifndef COMPILER_MSVC
106 const GLint TextureManagerTest::kMaxTextureSize;
107 const GLint TextureManagerTest::kMaxCubeMapTextureSize;
108 const GLint TextureManagerTest::kMaxRectangleTextureSize;
109 const GLint TextureManagerTest::kMaxExternalTextureSize;
110 const GLint TextureManagerTest::kMax2dLevels;
111 const GLint TextureManagerTest::kMaxCubeMapLevels;
112 const GLint TextureManagerTest::kMaxExternalLevels;
113 #endif
115 TEST_F(TextureManagerTest, Basic) {
116 const GLuint kClient1Id = 1;
117 const GLuint kService1Id = 11;
118 const GLuint kClient2Id = 2;
119 EXPECT_FALSE(manager_->HaveUnrenderableTextures());
120 EXPECT_FALSE(manager_->HaveUnsafeTextures());
121 EXPECT_FALSE(manager_->HaveUnclearedMips());
122 // Check we can create texture.
123 manager_->CreateTexture(kClient1Id, kService1Id);
124 // Check texture got created.
125 scoped_refptr<TextureRef> texture = manager_->GetTexture(kClient1Id);
126 ASSERT_TRUE(texture.get() != NULL);
127 EXPECT_EQ(kService1Id, texture->service_id());
128 EXPECT_EQ(kClient1Id, texture->client_id());
129 EXPECT_EQ(texture->texture(), manager_->GetTextureForServiceId(
130 texture->service_id()));
131 // Check we get nothing for a non-existent texture.
132 EXPECT_TRUE(manager_->GetTexture(kClient2Id) == NULL);
133 // Check trying to a remove non-existent textures does not crash.
134 manager_->RemoveTexture(kClient2Id);
135 // Check that it gets deleted when the last reference is released.
136 EXPECT_CALL(*gl_, DeleteTextures(1, ::testing::Pointee(kService1Id)))
137 .Times(1)
138 .RetiresOnSaturation();
139 // Check we can't get the texture after we remove it.
140 manager_->RemoveTexture(kClient1Id);
141 EXPECT_TRUE(manager_->GetTexture(kClient1Id) == NULL);
142 EXPECT_EQ(0u, texture->client_id());
145 TEST_F(TextureManagerTest, SetParameter) {
146 const GLuint kClient1Id = 1;
147 const GLuint kService1Id = 11;
148 // Check we can create texture.
149 manager_->CreateTexture(kClient1Id, kService1Id);
150 // Check texture got created.
151 TextureRef* texture_ref = manager_->GetTexture(kClient1Id);
152 ASSERT_TRUE(texture_ref != NULL);
153 Texture* texture = texture_ref->texture();
154 manager_->SetTarget(texture_ref, GL_TEXTURE_2D);
155 SetParameter(texture_ref, GL_TEXTURE_MIN_FILTER, GL_NEAREST, GL_NO_ERROR);
156 EXPECT_EQ(static_cast<GLenum>(GL_NEAREST), texture->min_filter());
157 SetParameter(texture_ref, GL_TEXTURE_MAG_FILTER, GL_NEAREST, GL_NO_ERROR);
158 EXPECT_EQ(static_cast<GLenum>(GL_NEAREST), texture->mag_filter());
159 SetParameter(texture_ref, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE, GL_NO_ERROR);
160 EXPECT_EQ(static_cast<GLenum>(GL_CLAMP_TO_EDGE), texture->wrap_s());
161 SetParameter(texture_ref, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE, GL_NO_ERROR);
162 EXPECT_EQ(static_cast<GLenum>(GL_CLAMP_TO_EDGE), texture->wrap_t());
163 SetParameter(texture_ref, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1, GL_NO_ERROR);
164 SetParameter(texture_ref, GL_TEXTURE_MAX_ANISOTROPY_EXT, 2, GL_NO_ERROR);
165 SetParameter(
166 texture_ref, GL_TEXTURE_MIN_FILTER, GL_CLAMP_TO_EDGE, GL_INVALID_ENUM);
167 EXPECT_EQ(static_cast<GLenum>(GL_NEAREST), texture->min_filter());
168 SetParameter(
169 texture_ref, GL_TEXTURE_MAG_FILTER, GL_CLAMP_TO_EDGE, GL_INVALID_ENUM);
170 EXPECT_EQ(static_cast<GLenum>(GL_NEAREST), texture->min_filter());
171 SetParameter(texture_ref, GL_TEXTURE_WRAP_S, GL_NEAREST, GL_INVALID_ENUM);
172 EXPECT_EQ(static_cast<GLenum>(GL_CLAMP_TO_EDGE), texture->wrap_s());
173 SetParameter(texture_ref, GL_TEXTURE_WRAP_T, GL_NEAREST, GL_INVALID_ENUM);
174 EXPECT_EQ(static_cast<GLenum>(GL_CLAMP_TO_EDGE), texture->wrap_t());
175 SetParameter(texture_ref, GL_TEXTURE_MAX_ANISOTROPY_EXT, 0, GL_INVALID_VALUE);
178 TEST_F(TextureManagerTest, UseDefaultTexturesTrue) {
179 bool use_default_textures = true;
180 scoped_refptr<FeatureInfo> feature_info(new FeatureInfo());
182 TestHelper::SetupTextureManagerInitExpectations(
183 gl_.get(), "GL_ANGLE_texture_usage", use_default_textures);
184 TextureManager manager(NULL,
185 feature_info_.get(),
186 kMaxTextureSize,
187 kMaxCubeMapTextureSize,
188 kMaxRectangleTextureSize,
189 kMax3DTextureSize,
190 use_default_textures);
191 manager.Initialize();
193 EXPECT_TRUE(manager.GetDefaultTextureInfo(GL_TEXTURE_2D) != NULL);
194 EXPECT_TRUE(manager.GetDefaultTextureInfo(GL_TEXTURE_CUBE_MAP) != NULL);
196 // TODO(vmiura): Test GL_TEXTURE_EXTERNAL_OES & GL_TEXTURE_RECTANGLE_ARB.
198 manager.Destroy(false);
201 TEST_F(TextureManagerTest, UseDefaultTexturesFalse) {
202 bool use_default_textures = false;
203 TestHelper::SetupTextureManagerInitExpectations(
204 gl_.get(), "GL_ANGLE_texture_usage", use_default_textures);
205 TextureManager manager(NULL,
206 feature_info_.get(),
207 kMaxTextureSize,
208 kMaxCubeMapTextureSize,
209 kMaxRectangleTextureSize,
210 kMax3DTextureSize,
211 use_default_textures);
212 manager.Initialize();
214 EXPECT_TRUE(manager.GetDefaultTextureInfo(GL_TEXTURE_2D) == NULL);
215 EXPECT_TRUE(manager.GetDefaultTextureInfo(GL_TEXTURE_CUBE_MAP) == NULL);
217 // TODO(vmiura): Test GL_TEXTURE_EXTERNAL_OES & GL_TEXTURE_RECTANGLE_ARB.
219 manager.Destroy(false);
222 TEST_F(TextureManagerTest, TextureUsageExt) {
223 TestHelper::SetupTextureManagerInitExpectations(
224 gl_.get(), "GL_ANGLE_texture_usage", kUseDefaultTextures);
225 TextureManager manager(NULL,
226 feature_info_.get(),
227 kMaxTextureSize,
228 kMaxCubeMapTextureSize,
229 kMaxRectangleTextureSize,
230 kMax3DTextureSize,
231 kUseDefaultTextures);
232 manager.Initialize();
233 const GLuint kClient1Id = 1;
234 const GLuint kService1Id = 11;
235 // Check we can create texture.
236 manager.CreateTexture(kClient1Id, kService1Id);
237 // Check texture got created.
238 TextureRef* texture_ref = manager.GetTexture(kClient1Id);
239 ASSERT_TRUE(texture_ref != NULL);
240 TestHelper::SetTexParameteriWithExpectations(
241 gl_.get(), error_state_.get(), &manager, texture_ref,
242 GL_TEXTURE_USAGE_ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE, GL_NO_ERROR);
243 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_ATTACHMENT_ANGLE),
244 texture_ref->texture()->usage());
245 manager.Destroy(false);
248 TEST_F(TextureManagerTest, Destroy) {
249 const GLuint kClient1Id = 1;
250 const GLuint kService1Id = 11;
251 TestHelper::SetupTextureManagerInitExpectations(
252 gl_.get(), "", kUseDefaultTextures);
253 TextureManager manager(NULL,
254 feature_info_.get(),
255 kMaxTextureSize,
256 kMaxCubeMapTextureSize,
257 kMaxRectangleTextureSize,
258 kMax3DTextureSize,
259 kUseDefaultTextures);
260 manager.Initialize();
261 // Check we can create texture.
262 manager.CreateTexture(kClient1Id, kService1Id);
263 // Check texture got created.
264 TextureRef* texture = manager.GetTexture(kClient1Id);
265 ASSERT_TRUE(texture != NULL);
266 EXPECT_CALL(*gl_, DeleteTextures(1, ::testing::Pointee(kService1Id)))
267 .Times(1)
268 .RetiresOnSaturation();
269 TestHelper::SetupTextureManagerDestructionExpectations(
270 gl_.get(), "", kUseDefaultTextures);
271 manager.Destroy(true);
272 // Check that resources got freed.
273 texture = manager.GetTexture(kClient1Id);
274 ASSERT_TRUE(texture == NULL);
277 TEST_F(TextureManagerTest, MaxValues) {
278 // Check we get the right values for the max sizes.
279 EXPECT_EQ(kMax2dLevels, manager_->MaxLevelsForTarget(GL_TEXTURE_2D));
280 EXPECT_EQ(kMaxCubeMapLevels,
281 manager_->MaxLevelsForTarget(GL_TEXTURE_CUBE_MAP));
282 EXPECT_EQ(kMaxCubeMapLevels,
283 manager_->MaxLevelsForTarget(GL_TEXTURE_CUBE_MAP_POSITIVE_X));
284 EXPECT_EQ(kMaxCubeMapLevels,
285 manager_->MaxLevelsForTarget(GL_TEXTURE_CUBE_MAP_NEGATIVE_X));
286 EXPECT_EQ(kMaxCubeMapLevels,
287 manager_->MaxLevelsForTarget(GL_TEXTURE_CUBE_MAP_POSITIVE_Y));
288 EXPECT_EQ(kMaxCubeMapLevels,
289 manager_->MaxLevelsForTarget(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y));
290 EXPECT_EQ(kMaxCubeMapLevels,
291 manager_->MaxLevelsForTarget(GL_TEXTURE_CUBE_MAP_POSITIVE_Z));
292 EXPECT_EQ(kMaxCubeMapLevels,
293 manager_->MaxLevelsForTarget(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z));
294 EXPECT_EQ(kMaxExternalLevels,
295 manager_->MaxLevelsForTarget(GL_TEXTURE_EXTERNAL_OES));
296 EXPECT_EQ(kMaxTextureSize, manager_->MaxSizeForTarget(GL_TEXTURE_2D));
297 EXPECT_EQ(kMaxCubeMapTextureSize,
298 manager_->MaxSizeForTarget(GL_TEXTURE_CUBE_MAP));
299 EXPECT_EQ(kMaxCubeMapTextureSize,
300 manager_->MaxSizeForTarget(GL_TEXTURE_CUBE_MAP_POSITIVE_X));
301 EXPECT_EQ(kMaxCubeMapTextureSize,
302 manager_->MaxSizeForTarget(GL_TEXTURE_CUBE_MAP_NEGATIVE_X));
303 EXPECT_EQ(kMaxCubeMapTextureSize,
304 manager_->MaxSizeForTarget(GL_TEXTURE_CUBE_MAP_POSITIVE_Y));
305 EXPECT_EQ(kMaxCubeMapTextureSize,
306 manager_->MaxSizeForTarget(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y));
307 EXPECT_EQ(kMaxCubeMapTextureSize,
308 manager_->MaxSizeForTarget(GL_TEXTURE_CUBE_MAP_POSITIVE_Z));
309 EXPECT_EQ(kMaxCubeMapTextureSize,
310 manager_->MaxSizeForTarget(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z));
311 EXPECT_EQ(kMaxRectangleTextureSize,
312 manager_->MaxSizeForTarget(GL_TEXTURE_RECTANGLE_ARB));
313 EXPECT_EQ(kMaxExternalTextureSize,
314 manager_->MaxSizeForTarget(GL_TEXTURE_EXTERNAL_OES));
317 TEST_F(TextureManagerTest, ValidForTarget) {
318 // check 2d
319 EXPECT_TRUE(manager_->ValidForTarget(
320 GL_TEXTURE_2D, 0, kMaxTextureSize, kMaxTextureSize, 1));
321 EXPECT_TRUE(manager_->ValidForTarget(
322 GL_TEXTURE_2D, kMax2dLevels - 1, 1, 1, 1));
323 EXPECT_FALSE(manager_->ValidForTarget(
324 GL_TEXTURE_2D, kMax2dLevels - 1, 1, 2, 1));
325 EXPECT_FALSE(manager_->ValidForTarget(
326 GL_TEXTURE_2D, kMax2dLevels - 1, 2, 1, 1));
327 // check level out of range.
328 EXPECT_FALSE(manager_->ValidForTarget(
329 GL_TEXTURE_2D, kMax2dLevels, kMaxTextureSize, 1, 1));
330 // check has depth.
331 EXPECT_FALSE(manager_->ValidForTarget(
332 GL_TEXTURE_2D, kMax2dLevels, kMaxTextureSize, 1, 2));
333 // Check NPOT width on level 0
334 EXPECT_TRUE(manager_->ValidForTarget(GL_TEXTURE_2D, 0, 5, 2, 1));
335 // Check NPOT height on level 0
336 EXPECT_TRUE(manager_->ValidForTarget(GL_TEXTURE_2D, 0, 2, 5, 1));
337 // Check NPOT width on level 1
338 EXPECT_FALSE(manager_->ValidForTarget(GL_TEXTURE_2D, 1, 5, 2, 1));
339 // Check NPOT height on level 1
340 EXPECT_FALSE(manager_->ValidForTarget(GL_TEXTURE_2D, 1, 2, 5, 1));
342 // check cube
343 EXPECT_TRUE(manager_->ValidForTarget(
344 GL_TEXTURE_CUBE_MAP, 0,
345 kMaxCubeMapTextureSize, kMaxCubeMapTextureSize, 1));
346 EXPECT_TRUE(manager_->ValidForTarget(
347 GL_TEXTURE_CUBE_MAP, kMaxCubeMapLevels - 1, 1, 1, 1));
348 EXPECT_FALSE(manager_->ValidForTarget(
349 GL_TEXTURE_CUBE_MAP, kMaxCubeMapLevels - 1, 2, 2, 1));
350 // check level out of range.
351 EXPECT_FALSE(manager_->ValidForTarget(
352 GL_TEXTURE_CUBE_MAP, kMaxCubeMapLevels,
353 kMaxCubeMapTextureSize, 1, 1));
354 // check not square.
355 EXPECT_FALSE(manager_->ValidForTarget(
356 GL_TEXTURE_CUBE_MAP, kMaxCubeMapLevels,
357 kMaxCubeMapTextureSize, 1, 1));
358 // check has depth.
359 EXPECT_FALSE(manager_->ValidForTarget(
360 GL_TEXTURE_CUBE_MAP, kMaxCubeMapLevels,
361 kMaxCubeMapTextureSize, 1, 2));
363 for (GLint level = 0; level < kMax2dLevels; ++level) {
364 EXPECT_TRUE(manager_->ValidForTarget(
365 GL_TEXTURE_2D, level, kMaxTextureSize >> level, 1, 1));
366 EXPECT_TRUE(manager_->ValidForTarget(
367 GL_TEXTURE_2D, level, 1, kMaxTextureSize >> level, 1));
368 EXPECT_FALSE(manager_->ValidForTarget(
369 GL_TEXTURE_2D, level, (kMaxTextureSize >> level) + 1, 1, 1));
370 EXPECT_FALSE(manager_->ValidForTarget(
371 GL_TEXTURE_2D, level, 1, (kMaxTextureSize >> level) + 1, 1));
374 for (GLint level = 0; level < kMaxCubeMapLevels; ++level) {
375 EXPECT_TRUE(manager_->ValidForTarget(
376 GL_TEXTURE_CUBE_MAP, level,
377 kMaxCubeMapTextureSize >> level,
378 kMaxCubeMapTextureSize >> level,
379 1));
380 EXPECT_FALSE(manager_->ValidForTarget(
381 GL_TEXTURE_CUBE_MAP, level,
382 (kMaxCubeMapTextureSize >> level) * 2,
383 (kMaxCubeMapTextureSize >> level) * 2,
384 1));
388 TEST_F(TextureManagerTest, ValidForTargetNPOT) {
389 TestHelper::SetupFeatureInfoInitExpectations(
390 gl_.get(), "GL_OES_texture_npot");
391 scoped_refptr<FeatureInfo> feature_info(new FeatureInfo());
392 feature_info->Initialize();
393 TextureManager manager(NULL,
394 feature_info.get(),
395 kMaxTextureSize,
396 kMaxCubeMapTextureSize,
397 kMaxRectangleTextureSize,
398 kMax3DTextureSize,
399 kUseDefaultTextures);
400 // Check NPOT width on level 0
401 EXPECT_TRUE(manager.ValidForTarget(GL_TEXTURE_2D, 0, 5, 2, 1));
402 // Check NPOT height on level 0
403 EXPECT_TRUE(manager.ValidForTarget(GL_TEXTURE_2D, 0, 2, 5, 1));
404 // Check NPOT width on level 1
405 EXPECT_TRUE(manager.ValidForTarget(GL_TEXTURE_2D, 1, 5, 2, 1));
406 // Check NPOT height on level 1
407 EXPECT_TRUE(manager.ValidForTarget(GL_TEXTURE_2D, 1, 2, 5, 1));
408 manager.Destroy(false);
411 class TextureTestBase : public GpuServiceTest {
412 public:
413 static const GLint kMaxTextureSize = 16;
414 static const GLint kMaxCubeMapTextureSize = 8;
415 static const GLint kMaxRectangleTextureSize = 16;
416 static const GLint kMax3DTextureSize = 256;
417 static const GLint kMax2dLevels = 5;
418 static const GLint kMaxCubeMapLevels = 4;
419 static const GLuint kClient1Id = 1;
420 static const GLuint kService1Id = 11;
421 static const bool kUseDefaultTextures = false;
423 TextureTestBase()
424 : feature_info_(new FeatureInfo()) {
426 ~TextureTestBase() override { texture_ref_ = NULL; }
428 protected:
429 void SetUpBase(MemoryTracker* memory_tracker, std::string extensions) {
430 GpuServiceTest::SetUp();
431 if (!extensions.empty()) {
432 TestHelper::SetupFeatureInfoInitExpectations(gl_.get(),
433 extensions.c_str());
434 feature_info_->Initialize();
437 manager_.reset(new TextureManager(memory_tracker,
438 feature_info_.get(),
439 kMaxTextureSize,
440 kMaxCubeMapTextureSize,
441 kMaxRectangleTextureSize,
442 kMax3DTextureSize,
443 kUseDefaultTextures));
444 decoder_.reset(new ::testing::StrictMock<gles2::MockGLES2Decoder>());
445 error_state_.reset(new ::testing::StrictMock<gles2::MockErrorState>());
446 manager_->CreateTexture(kClient1Id, kService1Id);
447 texture_ref_ = manager_->GetTexture(kClient1Id);
448 ASSERT_TRUE(texture_ref_.get() != NULL);
451 void TearDown() override {
452 if (texture_ref_.get()) {
453 // If it's not in the manager then setting texture_ref_ to NULL will
454 // delete the texture.
455 if (!texture_ref_->client_id()) {
456 // Check that it gets deleted when the last reference is released.
457 EXPECT_CALL(*gl_,
458 DeleteTextures(1, ::testing::Pointee(texture_ref_->service_id())))
459 .Times(1)
460 .RetiresOnSaturation();
462 texture_ref_ = NULL;
464 manager_->Destroy(false);
465 manager_.reset();
466 GpuServiceTest::TearDown();
469 void SetParameter(
470 TextureRef* texture_ref, GLenum pname, GLint value, GLenum error) {
471 TestHelper::SetTexParameteriWithExpectations(
472 gl_.get(), error_state_.get(), manager_.get(),
473 texture_ref, pname, value, error);
476 scoped_ptr<MockGLES2Decoder> decoder_;
477 scoped_ptr<MockErrorState> error_state_;
478 scoped_refptr<FeatureInfo> feature_info_;
479 scoped_ptr<TextureManager> manager_;
480 scoped_refptr<TextureRef> texture_ref_;
483 class TextureTest : public TextureTestBase {
484 protected:
485 void SetUp() override { SetUpBase(NULL, std::string()); }
488 class TextureMemoryTrackerTest : public TextureTestBase {
489 protected:
490 void SetUp() override {
491 mock_memory_tracker_ = new StrictMock<MockMemoryTracker>();
492 SetUpBase(mock_memory_tracker_.get(), std::string());
495 scoped_refptr<MockMemoryTracker> mock_memory_tracker_;
498 #define EXPECT_MEMORY_ALLOCATION_CHANGE(old_size, new_size, pool) \
499 EXPECT_CALL(*mock_memory_tracker_.get(), \
500 TrackMemoryAllocatedChange(old_size, new_size, pool)) \
501 .Times(1).RetiresOnSaturation()
503 TEST_F(TextureTest, Basic) {
504 Texture* texture = texture_ref_->texture();
505 EXPECT_EQ(0u, texture->target());
506 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture));
507 EXPECT_FALSE(TextureTestHelper::IsCubeComplete(texture));
508 EXPECT_FALSE(manager_->CanGenerateMipmaps(texture_ref_.get()));
509 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture));
510 EXPECT_EQ(0, texture->num_uncleared_mips());
511 EXPECT_TRUE(manager_->CanRender(texture_ref_.get()));
512 EXPECT_TRUE(texture->SafeToRenderFrom());
513 EXPECT_FALSE(texture->IsImmutable());
514 EXPECT_EQ(static_cast<GLenum>(GL_NEAREST_MIPMAP_LINEAR),
515 texture->min_filter());
516 EXPECT_EQ(static_cast<GLenum>(GL_LINEAR), texture->mag_filter());
517 EXPECT_EQ(static_cast<GLenum>(GL_REPEAT), texture->wrap_s());
518 EXPECT_EQ(static_cast<GLenum>(GL_REPEAT), texture->wrap_t());
519 EXPECT_FALSE(manager_->HaveUnrenderableTextures());
520 EXPECT_FALSE(manager_->HaveUnsafeTextures());
521 EXPECT_EQ(0u, texture->estimated_size());
524 TEST_F(TextureTest, SetTargetTexture2D) {
525 Texture* texture = texture_ref_->texture();
526 manager_->SetTarget(texture_ref_.get(), GL_TEXTURE_2D);
527 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture));
528 EXPECT_FALSE(TextureTestHelper::IsCubeComplete(texture));
529 EXPECT_FALSE(manager_->CanGenerateMipmaps(texture_ref_.get()));
530 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture));
531 EXPECT_FALSE(manager_->CanRender(texture_ref_.get()));
532 EXPECT_TRUE(texture->SafeToRenderFrom());
533 EXPECT_FALSE(texture->IsImmutable());
536 TEST_F(TextureTest, SetTargetTextureExternalOES) {
537 Texture* texture = texture_ref_->texture();
538 manager_->SetTarget(texture_ref_.get(), GL_TEXTURE_EXTERNAL_OES);
539 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture));
540 EXPECT_FALSE(TextureTestHelper::IsCubeComplete(texture));
541 EXPECT_FALSE(manager_->CanGenerateMipmaps(texture_ref_.get()));
542 EXPECT_TRUE(TextureTestHelper::IsNPOT(texture));
543 EXPECT_TRUE(manager_->CanRender(texture_ref_.get()));
544 EXPECT_TRUE(texture->SafeToRenderFrom());
545 EXPECT_TRUE(texture->IsImmutable());
548 TEST_F(TextureTest, ZeroSizeCanNotRender) {
549 manager_->SetTarget(texture_ref_.get(), GL_TEXTURE_2D);
550 EXPECT_FALSE(manager_->CanRender(texture_ref_.get()));
551 manager_->SetLevelInfo(texture_ref_.get(),
552 GL_TEXTURE_2D,
554 GL_RGBA,
559 GL_RGBA,
560 GL_UNSIGNED_BYTE,
561 true);
562 EXPECT_TRUE(manager_->CanRender(texture_ref_.get()));
563 manager_->SetLevelInfo(texture_ref_.get(),
564 GL_TEXTURE_2D,
566 GL_RGBA,
571 GL_RGBA,
572 GL_UNSIGNED_BYTE,
573 true);
574 EXPECT_FALSE(manager_->CanRender(texture_ref_.get()));
577 TEST_F(TextureTest, EstimatedSize) {
578 manager_->SetTarget(texture_ref_.get(), GL_TEXTURE_2D);
579 manager_->SetLevelInfo(texture_ref_.get(),
580 GL_TEXTURE_2D,
582 GL_RGBA,
587 GL_RGBA,
588 GL_UNSIGNED_BYTE,
589 true);
590 EXPECT_EQ(8u * 4u * 4u, texture_ref_->texture()->estimated_size());
591 manager_->SetLevelInfo(texture_ref_.get(),
592 GL_TEXTURE_2D,
594 GL_RGBA,
599 GL_RGBA,
600 GL_UNSIGNED_BYTE,
601 true);
602 EXPECT_EQ(8u * 4u * 4u * 2u, texture_ref_->texture()->estimated_size());
605 TEST_F(TextureMemoryTrackerTest, EstimatedSize) {
606 manager_->SetTarget(texture_ref_.get(), GL_TEXTURE_2D);
607 EXPECT_MEMORY_ALLOCATION_CHANGE(0, 128, MemoryTracker::kUnmanaged);
608 manager_->SetLevelInfo(texture_ref_.get(),
609 GL_TEXTURE_2D,
611 GL_RGBA,
616 GL_RGBA,
617 GL_UNSIGNED_BYTE,
618 true);
619 EXPECT_MEMORY_ALLOCATION_CHANGE(128, 0, MemoryTracker::kUnmanaged);
620 EXPECT_MEMORY_ALLOCATION_CHANGE(0, 256, MemoryTracker::kUnmanaged);
621 manager_->SetLevelInfo(texture_ref_.get(),
622 GL_TEXTURE_2D,
624 GL_RGBA,
629 GL_RGBA,
630 GL_UNSIGNED_BYTE,
631 true);
632 // Add expectation for texture deletion.
633 EXPECT_MEMORY_ALLOCATION_CHANGE(256, 0, MemoryTracker::kUnmanaged);
634 EXPECT_MEMORY_ALLOCATION_CHANGE(0, 0, MemoryTracker::kUnmanaged);
637 TEST_F(TextureMemoryTrackerTest, SetParameterPool) {
638 manager_->SetTarget(texture_ref_.get(), GL_TEXTURE_2D);
639 EXPECT_MEMORY_ALLOCATION_CHANGE(0, 128, MemoryTracker::kUnmanaged);
640 manager_->SetLevelInfo(texture_ref_.get(),
641 GL_TEXTURE_2D,
643 GL_RGBA,
648 GL_RGBA,
649 GL_UNSIGNED_BYTE,
650 true);
651 EXPECT_MEMORY_ALLOCATION_CHANGE(128, 0, MemoryTracker::kUnmanaged);
652 EXPECT_MEMORY_ALLOCATION_CHANGE(0, 128, MemoryTracker::kManaged);
653 SetParameter(texture_ref_.get(),
654 GL_TEXTURE_POOL_CHROMIUM,
655 GL_TEXTURE_POOL_MANAGED_CHROMIUM,
656 GL_NO_ERROR);
657 // Add expectation for texture deletion.
658 EXPECT_MEMORY_ALLOCATION_CHANGE(128, 0, MemoryTracker::kManaged);
659 EXPECT_MEMORY_ALLOCATION_CHANGE(0, 0, MemoryTracker::kUnmanaged);
660 EXPECT_MEMORY_ALLOCATION_CHANGE(0, 0, MemoryTracker::kManaged);
663 TEST_F(TextureTest, POT2D) {
664 manager_->SetTarget(texture_ref_.get(), GL_TEXTURE_2D);
665 Texture* texture = texture_ref_->texture();
666 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), texture->target());
667 // Check Setting level 0 to POT
668 manager_->SetLevelInfo(texture_ref_.get(),
669 GL_TEXTURE_2D,
671 GL_RGBA,
676 GL_RGBA,
677 GL_UNSIGNED_BYTE,
678 true);
679 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture));
680 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture));
681 EXPECT_FALSE(manager_->CanRender(texture_ref_.get()));
682 EXPECT_EQ(0, texture->num_uncleared_mips());
683 EXPECT_TRUE(manager_->HaveUnrenderableTextures());
684 // Set filters to something that will work with a single mip.
685 SetParameter(
686 texture_ref_.get(), GL_TEXTURE_MIN_FILTER, GL_LINEAR, GL_NO_ERROR);
687 EXPECT_TRUE(manager_->CanRender(texture_ref_.get()));
688 EXPECT_FALSE(manager_->HaveUnrenderableTextures());
689 // Set them back.
690 SetParameter(texture_ref_.get(),
691 GL_TEXTURE_MIN_FILTER,
692 GL_LINEAR_MIPMAP_LINEAR,
693 GL_NO_ERROR);
694 EXPECT_TRUE(manager_->HaveUnrenderableTextures());
696 EXPECT_TRUE(manager_->CanGenerateMipmaps(texture_ref_.get()));
697 // Make mips.
698 EXPECT_TRUE(manager_->MarkMipmapsGenerated(texture_ref_.get()));
699 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture));
700 EXPECT_TRUE(manager_->CanRender(texture_ref_.get()));
701 EXPECT_FALSE(manager_->HaveUnrenderableTextures());
702 // Change a mip.
703 manager_->SetLevelInfo(texture_ref_.get(),
704 GL_TEXTURE_2D,
706 GL_RGBA,
711 GL_RGBA,
712 GL_UNSIGNED_BYTE,
713 true);
714 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture));
715 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture));
716 EXPECT_TRUE(manager_->CanGenerateMipmaps(texture_ref_.get()));
717 EXPECT_FALSE(manager_->CanRender(texture_ref_.get()));
718 EXPECT_TRUE(manager_->HaveUnrenderableTextures());
719 // Set a level past the number of mips that would get generated.
720 manager_->SetLevelInfo(texture_ref_.get(),
721 GL_TEXTURE_2D,
723 GL_RGBA,
728 GL_RGBA,
729 GL_UNSIGNED_BYTE,
730 true);
731 EXPECT_TRUE(manager_->CanGenerateMipmaps(texture_ref_.get()));
732 // Make mips.
733 EXPECT_TRUE(manager_->MarkMipmapsGenerated(texture_ref_.get()));
734 EXPECT_TRUE(manager_->CanRender(texture_ref_.get()));
735 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture));
736 EXPECT_FALSE(manager_->HaveUnrenderableTextures());
739 TEST_F(TextureMemoryTrackerTest, MarkMipmapsGenerated) {
740 manager_->SetTarget(texture_ref_.get(), GL_TEXTURE_2D);
741 EXPECT_MEMORY_ALLOCATION_CHANGE(0, 64, MemoryTracker::kUnmanaged);
742 manager_->SetLevelInfo(texture_ref_.get(),
743 GL_TEXTURE_2D,
745 GL_RGBA,
750 GL_RGBA,
751 GL_UNSIGNED_BYTE,
752 true);
753 EXPECT_MEMORY_ALLOCATION_CHANGE(64, 0, MemoryTracker::kUnmanaged);
754 EXPECT_MEMORY_ALLOCATION_CHANGE(0, 84, MemoryTracker::kUnmanaged);
755 EXPECT_TRUE(manager_->MarkMipmapsGenerated(texture_ref_.get()));
756 EXPECT_MEMORY_ALLOCATION_CHANGE(84, 0, MemoryTracker::kUnmanaged);
757 EXPECT_MEMORY_ALLOCATION_CHANGE(0, 0, MemoryTracker::kUnmanaged);
760 TEST_F(TextureTest, UnusedMips) {
761 manager_->SetTarget(texture_ref_.get(), GL_TEXTURE_2D);
762 Texture* texture = texture_ref_->texture();
763 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), texture->target());
764 // Set level zero to large size.
765 manager_->SetLevelInfo(texture_ref_.get(),
766 GL_TEXTURE_2D,
768 GL_RGBA,
773 GL_RGBA,
774 GL_UNSIGNED_BYTE,
775 true);
776 EXPECT_TRUE(manager_->MarkMipmapsGenerated(texture_ref_.get()));
777 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture));
778 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture));
779 EXPECT_TRUE(manager_->CanRender(texture_ref_.get()));
780 EXPECT_FALSE(manager_->HaveUnrenderableTextures());
781 // Set level zero to large smaller (levels unused mips)
782 manager_->SetLevelInfo(texture_ref_.get(),
783 GL_TEXTURE_2D,
785 GL_RGBA,
790 GL_RGBA,
791 GL_UNSIGNED_BYTE,
792 true);
793 EXPECT_TRUE(manager_->MarkMipmapsGenerated(texture_ref_.get()));
794 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture));
795 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture));
796 EXPECT_TRUE(manager_->CanRender(texture_ref_.get()));
797 EXPECT_FALSE(manager_->HaveUnrenderableTextures());
798 // Set an unused level to some size
799 manager_->SetLevelInfo(texture_ref_.get(),
800 GL_TEXTURE_2D,
802 GL_RGBA,
807 GL_RGBA,
808 GL_UNSIGNED_BYTE,
809 true);
810 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture));
811 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture));
812 EXPECT_TRUE(manager_->CanRender(texture_ref_.get()));
813 EXPECT_FALSE(manager_->HaveUnrenderableTextures());
816 TEST_F(TextureTest, NPOT2D) {
817 manager_->SetTarget(texture_ref_.get(), GL_TEXTURE_2D);
818 Texture* texture = texture_ref_->texture();
819 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), texture->target());
820 // Check Setting level 0 to NPOT
821 manager_->SetLevelInfo(texture_ref_.get(),
822 GL_TEXTURE_2D,
824 GL_RGBA,
829 GL_RGBA,
830 GL_UNSIGNED_BYTE,
831 true);
832 EXPECT_TRUE(TextureTestHelper::IsNPOT(texture));
833 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture));
834 EXPECT_FALSE(manager_->CanGenerateMipmaps(texture_ref_.get()));
835 EXPECT_FALSE(manager_->CanRender(texture_ref_.get()));
836 EXPECT_TRUE(manager_->HaveUnrenderableTextures());
837 SetParameter(
838 texture_ref_.get(), GL_TEXTURE_MIN_FILTER, GL_LINEAR, GL_NO_ERROR);
839 EXPECT_FALSE(manager_->CanRender(texture_ref_.get()));
840 EXPECT_TRUE(manager_->HaveUnrenderableTextures());
841 SetParameter(
842 texture_ref_.get(), GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE, GL_NO_ERROR);
843 EXPECT_FALSE(manager_->CanRender(texture_ref_.get()));
844 EXPECT_TRUE(manager_->HaveUnrenderableTextures());
845 SetParameter(
846 texture_ref_.get(), GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE, GL_NO_ERROR);
847 EXPECT_TRUE(manager_->CanRender(texture_ref_.get()));
848 EXPECT_FALSE(manager_->HaveUnrenderableTextures());
849 // Change it to POT.
850 manager_->SetLevelInfo(texture_ref_.get(),
851 GL_TEXTURE_2D,
853 GL_RGBA,
858 GL_RGBA,
859 GL_UNSIGNED_BYTE,
860 true);
861 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture));
862 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture));
863 EXPECT_TRUE(manager_->CanGenerateMipmaps(texture_ref_.get()));
864 EXPECT_FALSE(manager_->HaveUnrenderableTextures());
867 TEST_F(TextureTest, NPOT2DNPOTOK) {
868 TestHelper::SetupFeatureInfoInitExpectations(
869 gl_.get(), "GL_OES_texture_npot");
870 scoped_refptr<FeatureInfo> feature_info(new FeatureInfo());
871 feature_info->Initialize();
872 TextureManager manager(NULL,
873 feature_info.get(),
874 kMaxTextureSize,
875 kMaxCubeMapTextureSize,
876 kMaxRectangleTextureSize,
877 kMax3DTextureSize,
878 kUseDefaultTextures);
879 manager.CreateTexture(kClient1Id, kService1Id);
880 TextureRef* texture_ref = manager.GetTexture(kClient1Id);
881 ASSERT_TRUE(texture_ref != NULL);
882 Texture* texture = texture_ref->texture();
884 manager.SetTarget(texture_ref, GL_TEXTURE_2D);
885 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), texture->target());
886 // Check Setting level 0 to NPOT
887 manager.SetLevelInfo(texture_ref,
888 GL_TEXTURE_2D, 0, GL_RGBA, 4, 5, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, true);
889 EXPECT_TRUE(TextureTestHelper::IsNPOT(texture));
890 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture));
891 EXPECT_TRUE(manager.CanGenerateMipmaps(texture_ref));
892 EXPECT_FALSE(manager.CanRender(texture_ref));
893 EXPECT_TRUE(manager.HaveUnrenderableTextures());
894 EXPECT_TRUE(manager.MarkMipmapsGenerated(texture_ref));
895 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture));
896 EXPECT_TRUE(manager.CanRender(texture_ref));
897 EXPECT_FALSE(manager.HaveUnrenderableTextures());
898 manager.Destroy(false);
901 TEST_F(TextureTest, POTCubeMap) {
902 manager_->SetTarget(texture_ref_.get(), GL_TEXTURE_CUBE_MAP);
903 Texture* texture = texture_ref_->texture();
904 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_CUBE_MAP), texture->target());
905 // Check Setting level 0 each face to POT
906 manager_->SetLevelInfo(texture_ref_.get(),
907 GL_TEXTURE_CUBE_MAP_POSITIVE_X,
909 GL_RGBA,
914 GL_RGBA,
915 GL_UNSIGNED_BYTE,
916 true);
917 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture));
918 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture));
919 EXPECT_FALSE(TextureTestHelper::IsCubeComplete(texture));
920 EXPECT_FALSE(manager_->CanGenerateMipmaps(texture_ref_.get()));
921 EXPECT_FALSE(manager_->CanRender(texture_ref_.get()));
922 EXPECT_TRUE(manager_->HaveUnrenderableTextures());
923 manager_->SetLevelInfo(texture_ref_.get(),
924 GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
926 GL_RGBA,
931 GL_RGBA,
932 GL_UNSIGNED_BYTE,
933 true);
934 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture));
935 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture));
936 EXPECT_FALSE(TextureTestHelper::IsCubeComplete(texture));
937 EXPECT_FALSE(manager_->CanGenerateMipmaps(texture_ref_.get()));
938 EXPECT_FALSE(manager_->CanRender(texture_ref_.get()));
939 EXPECT_TRUE(manager_->HaveUnrenderableTextures());
940 manager_->SetLevelInfo(texture_ref_.get(),
941 GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
943 GL_RGBA,
948 GL_RGBA,
949 GL_UNSIGNED_BYTE,
950 true);
951 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture));
952 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture));
953 EXPECT_FALSE(TextureTestHelper::IsCubeComplete(texture));
954 EXPECT_FALSE(manager_->CanGenerateMipmaps(texture_ref_.get()));
955 EXPECT_FALSE(manager_->CanRender(texture_ref_.get()));
956 EXPECT_TRUE(manager_->HaveUnrenderableTextures());
957 manager_->SetLevelInfo(texture_ref_.get(),
958 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
960 GL_RGBA,
965 GL_RGBA,
966 GL_UNSIGNED_BYTE,
967 true);
968 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture));
969 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture));
970 EXPECT_FALSE(TextureTestHelper::IsCubeComplete(texture));
971 EXPECT_FALSE(manager_->CanRender(texture_ref_.get()));
972 EXPECT_FALSE(manager_->CanGenerateMipmaps(texture_ref_.get()));
973 EXPECT_TRUE(manager_->HaveUnrenderableTextures());
974 manager_->SetLevelInfo(texture_ref_.get(),
975 GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
977 GL_RGBA,
982 GL_RGBA,
983 GL_UNSIGNED_BYTE,
984 true);
985 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture));
986 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture));
987 EXPECT_FALSE(TextureTestHelper::IsCubeComplete(texture));
988 EXPECT_FALSE(manager_->CanGenerateMipmaps(texture_ref_.get()));
989 EXPECT_FALSE(manager_->CanRender(texture_ref_.get()));
990 EXPECT_TRUE(manager_->HaveUnrenderableTextures());
991 manager_->SetLevelInfo(texture_ref_.get(),
992 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
994 GL_RGBA,
999 GL_RGBA,
1000 GL_UNSIGNED_BYTE,
1001 true);
1002 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture));
1003 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture));
1004 EXPECT_TRUE(TextureTestHelper::IsCubeComplete(texture));
1005 EXPECT_TRUE(manager_->CanGenerateMipmaps(texture_ref_.get()));
1006 EXPECT_FALSE(manager_->CanRender(texture_ref_.get()));
1007 EXPECT_TRUE(manager_->HaveUnrenderableTextures());
1009 // Make mips.
1010 EXPECT_TRUE(manager_->MarkMipmapsGenerated(texture_ref_.get()));
1011 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture));
1012 EXPECT_TRUE(TextureTestHelper::IsCubeComplete(texture));
1013 EXPECT_TRUE(manager_->CanRender(texture_ref_.get()));
1014 EXPECT_FALSE(manager_->HaveUnrenderableTextures());
1016 // Change a mip.
1017 manager_->SetLevelInfo(texture_ref_.get(),
1018 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
1020 GL_RGBA,
1025 GL_RGBA,
1026 GL_UNSIGNED_BYTE,
1027 true);
1028 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture));
1029 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture));
1030 EXPECT_TRUE(TextureTestHelper::IsCubeComplete(texture));
1031 EXPECT_TRUE(manager_->CanGenerateMipmaps(texture_ref_.get()));
1032 // Set a level past the number of mips that would get generated.
1033 manager_->SetLevelInfo(texture_ref_.get(),
1034 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
1036 GL_RGBA,
1041 GL_RGBA,
1042 GL_UNSIGNED_BYTE,
1043 true);
1044 EXPECT_TRUE(manager_->CanGenerateMipmaps(texture_ref_.get()));
1045 // Make mips.
1046 EXPECT_TRUE(manager_->MarkMipmapsGenerated(texture_ref_.get()));
1047 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture));
1048 EXPECT_TRUE(TextureTestHelper::IsCubeComplete(texture));
1051 TEST_F(TextureTest, GetLevelSize) {
1052 manager_->SetTarget(texture_ref_.get(), GL_TEXTURE_3D);
1053 manager_->SetLevelInfo(texture_ref_.get(),
1054 GL_TEXTURE_3D,
1056 GL_RGBA,
1061 GL_RGBA,
1062 GL_UNSIGNED_BYTE,
1063 true);
1064 GLsizei width = -1;
1065 GLsizei height = -1;
1066 GLsizei depth = -1;
1067 Texture* texture = texture_ref_->texture();
1068 EXPECT_FALSE(
1069 texture->GetLevelSize(GL_TEXTURE_3D, -1, &width, &height, &depth));
1070 EXPECT_FALSE(
1071 texture->GetLevelSize(GL_TEXTURE_3D, 1000, &width, &height, &depth));
1072 EXPECT_FALSE(
1073 texture->GetLevelSize(GL_TEXTURE_3D, 0, &width, &height, &depth));
1074 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_3D, 1, &width, &height, &depth));
1075 EXPECT_EQ(4, width);
1076 EXPECT_EQ(5, height);
1077 EXPECT_EQ(6, depth);
1078 manager_->RemoveTexture(kClient1Id);
1079 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_3D, 1, &width, &height, &depth));
1080 EXPECT_EQ(4, width);
1081 EXPECT_EQ(5, height);
1082 EXPECT_EQ(6, depth);
1085 TEST_F(TextureTest, GetLevelType) {
1086 manager_->SetTarget(texture_ref_.get(), GL_TEXTURE_2D);
1087 manager_->SetLevelInfo(texture_ref_.get(),
1088 GL_TEXTURE_2D,
1090 GL_RGBA,
1095 GL_RGBA,
1096 GL_UNSIGNED_BYTE,
1097 true);
1098 GLenum type = 0;
1099 GLenum format = 0;
1100 Texture* texture = texture_ref_->texture();
1101 EXPECT_FALSE(texture->GetLevelType(GL_TEXTURE_2D, -1, &type, &format));
1102 EXPECT_FALSE(texture->GetLevelType(GL_TEXTURE_2D, 1000, &type, &format));
1103 EXPECT_FALSE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &format));
1104 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 1, &type, &format));
1105 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
1106 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), format);
1107 manager_->RemoveTexture(kClient1Id);
1108 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 1, &type, &format));
1109 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
1110 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), format);
1113 TEST_F(TextureTest, ValidForTexture) {
1114 manager_->SetTarget(texture_ref_.get(), GL_TEXTURE_2D);
1115 manager_->SetLevelInfo(texture_ref_.get(),
1116 GL_TEXTURE_2D,
1118 GL_RGBA,
1123 GL_RGBA,
1124 GL_UNSIGNED_BYTE,
1125 true);
1126 // Check bad face.
1127 Texture* texture = texture_ref_->texture();
1128 EXPECT_FALSE(texture->ValidForTexture(
1129 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
1130 1, 0, 0, 0, 4, 5, 6, GL_UNSIGNED_BYTE));
1131 // Check bad level.
1132 EXPECT_FALSE(texture->ValidForTexture(
1133 GL_TEXTURE_2D, 0, 0, 0, 0, 4, 5, 6, GL_UNSIGNED_BYTE));
1134 // Check bad xoffset.
1135 EXPECT_FALSE(texture->ValidForTexture(
1136 GL_TEXTURE_2D, 1, -1, 0, 0, 4, 5, 6, GL_UNSIGNED_BYTE));
1137 // Check bad xoffset + width > width.
1138 EXPECT_FALSE(texture->ValidForTexture(
1139 GL_TEXTURE_2D, 1, 1, 0, 0, 4, 5, 6, GL_UNSIGNED_BYTE));
1140 // Check bad yoffset.
1141 EXPECT_FALSE(texture->ValidForTexture(
1142 GL_TEXTURE_2D, 1, 0, -1, 0, 4, 5, 6, GL_UNSIGNED_BYTE));
1143 // Check bad yoffset + height > height.
1144 EXPECT_FALSE(texture->ValidForTexture(
1145 GL_TEXTURE_2D, 1, 0, 1, 0, 4, 5, 6, GL_UNSIGNED_BYTE));
1146 // Check bad zoffset.
1147 EXPECT_FALSE(texture->ValidForTexture(
1148 GL_TEXTURE_2D, 1, 0, 0, -1, 4, 5, 6, GL_UNSIGNED_BYTE));
1149 // Check bad zoffset + depth > depth.
1150 EXPECT_FALSE(texture->ValidForTexture(
1151 GL_TEXTURE_2D, 1, 0, 0, 1, 4, 5, 6, GL_UNSIGNED_BYTE));
1152 // Check bad width.
1153 EXPECT_FALSE(texture->ValidForTexture(
1154 GL_TEXTURE_2D, 1, 0, 0, 0, 5, 5, 6, GL_UNSIGNED_BYTE));
1155 // Check bad height.
1156 EXPECT_FALSE(texture->ValidForTexture(
1157 GL_TEXTURE_2D, 1, 0, 0, 0, 4, 6, 6, GL_UNSIGNED_BYTE));
1158 // Check bad depth.
1159 EXPECT_FALSE(texture->ValidForTexture(
1160 GL_TEXTURE_2D, 1, 0, 0, 0, 4, 5, 7, GL_UNSIGNED_BYTE));
1161 // Check bad type.
1162 EXPECT_FALSE(texture->ValidForTexture(
1163 GL_TEXTURE_2D, 1, 0, 0, 0, 4, 5, 6, GL_UNSIGNED_SHORT_4_4_4_4));
1164 // Check valid full size
1165 EXPECT_TRUE(texture->ValidForTexture(
1166 GL_TEXTURE_2D, 1, 0, 0, 0, 4, 5, 6, GL_UNSIGNED_BYTE));
1167 // Check valid particial size.
1168 EXPECT_TRUE(texture->ValidForTexture(
1169 GL_TEXTURE_2D, 1, 1, 1, 1, 2, 3, 4, GL_UNSIGNED_BYTE));
1170 manager_->RemoveTexture(kClient1Id);
1171 EXPECT_TRUE(texture->ValidForTexture(
1172 GL_TEXTURE_2D, 1, 0, 0, 0, 4, 5, 6, GL_UNSIGNED_BYTE));
1175 TEST_F(TextureTest, FloatNotLinear) {
1176 TestHelper::SetupFeatureInfoInitExpectations(
1177 gl_.get(), "GL_OES_texture_float");
1178 scoped_refptr<FeatureInfo> feature_info(new FeatureInfo());
1179 feature_info->Initialize();
1180 TextureManager manager(NULL,
1181 feature_info.get(),
1182 kMaxTextureSize,
1183 kMaxCubeMapTextureSize,
1184 kMaxRectangleTextureSize,
1185 kMax3DTextureSize,
1186 kUseDefaultTextures);
1187 manager.CreateTexture(kClient1Id, kService1Id);
1188 TextureRef* texture_ref = manager.GetTexture(kClient1Id);
1189 ASSERT_TRUE(texture_ref != NULL);
1190 manager.SetTarget(texture_ref, GL_TEXTURE_2D);
1191 Texture* texture = texture_ref->texture();
1192 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), texture->target());
1193 manager.SetLevelInfo(texture_ref,
1194 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_FLOAT, true);
1195 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture));
1196 TestHelper::SetTexParameteriWithExpectations(
1197 gl_.get(), error_state_.get(), &manager,
1198 texture_ref, GL_TEXTURE_MAG_FILTER, GL_NEAREST, GL_NO_ERROR);
1199 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture));
1200 TestHelper::SetTexParameteriWithExpectations(
1201 gl_.get(), error_state_.get(), &manager, texture_ref,
1202 GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST, GL_NO_ERROR);
1203 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture));
1204 manager.Destroy(false);
1207 TEST_F(TextureTest, FloatLinear) {
1208 TestHelper::SetupFeatureInfoInitExpectations(
1209 gl_.get(), "GL_OES_texture_float GL_OES_texture_float_linear");
1210 scoped_refptr<FeatureInfo> feature_info(new FeatureInfo());
1211 feature_info->Initialize();
1212 TextureManager manager(NULL,
1213 feature_info.get(),
1214 kMaxTextureSize,
1215 kMaxCubeMapTextureSize,
1216 kMaxRectangleTextureSize,
1217 kMax3DTextureSize,
1218 kUseDefaultTextures);
1219 manager.CreateTexture(kClient1Id, kService1Id);
1220 TextureRef* texture_ref = manager.GetTexture(kClient1Id);
1221 ASSERT_TRUE(texture_ref != NULL);
1222 manager.SetTarget(texture_ref, GL_TEXTURE_2D);
1223 Texture* texture = texture_ref->texture();
1224 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), texture->target());
1225 manager.SetLevelInfo(texture_ref,
1226 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_FLOAT, true);
1227 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture));
1228 manager.Destroy(false);
1231 TEST_F(TextureTest, HalfFloatNotLinear) {
1232 TestHelper::SetupFeatureInfoInitExpectations(
1233 gl_.get(), "GL_OES_texture_half_float");
1234 scoped_refptr<FeatureInfo> feature_info(new FeatureInfo());
1235 feature_info->Initialize();
1236 TextureManager manager(NULL,
1237 feature_info.get(),
1238 kMaxTextureSize,
1239 kMaxCubeMapTextureSize,
1240 kMaxRectangleTextureSize,
1241 kMax3DTextureSize,
1242 kUseDefaultTextures);
1243 manager.CreateTexture(kClient1Id, kService1Id);
1244 TextureRef* texture_ref = manager.GetTexture(kClient1Id);
1245 ASSERT_TRUE(texture_ref != NULL);
1246 manager.SetTarget(texture_ref, GL_TEXTURE_2D);
1247 Texture* texture = texture_ref->texture();
1248 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), texture->target());
1249 manager.SetLevelInfo(texture_ref,
1250 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_HALF_FLOAT_OES, true);
1251 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture));
1252 TestHelper::SetTexParameteriWithExpectations(
1253 gl_.get(), error_state_.get(), &manager,
1254 texture_ref, GL_TEXTURE_MAG_FILTER, GL_NEAREST, GL_NO_ERROR);
1255 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture));
1256 TestHelper::SetTexParameteriWithExpectations(
1257 gl_.get(), error_state_.get(), &manager, texture_ref,
1258 GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST, GL_NO_ERROR);
1259 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture));
1260 manager.Destroy(false);
1263 TEST_F(TextureTest, HalfFloatLinear) {
1264 TestHelper::SetupFeatureInfoInitExpectations(
1265 gl_.get(), "GL_OES_texture_half_float GL_OES_texture_half_float_linear");
1266 scoped_refptr<FeatureInfo> feature_info(new FeatureInfo());
1267 feature_info->Initialize();
1268 TextureManager manager(NULL,
1269 feature_info.get(),
1270 kMaxTextureSize,
1271 kMaxCubeMapTextureSize,
1272 kMaxRectangleTextureSize,
1273 kMax3DTextureSize,
1274 kUseDefaultTextures);
1275 manager.CreateTexture(kClient1Id, kService1Id);
1276 TextureRef* texture_ref = manager.GetTexture(kClient1Id);
1277 ASSERT_TRUE(texture_ref != NULL);
1278 manager.SetTarget(texture_ref, GL_TEXTURE_2D);
1279 Texture* texture = texture_ref->texture();
1280 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), texture->target());
1281 manager.SetLevelInfo(texture_ref,
1282 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_HALF_FLOAT_OES, true);
1283 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture));
1284 manager.Destroy(false);
1287 TEST_F(TextureTest, EGLImageExternal) {
1288 TestHelper::SetupFeatureInfoInitExpectations(
1289 gl_.get(), "GL_OES_EGL_image_external");
1290 scoped_refptr<FeatureInfo> feature_info(new FeatureInfo());
1291 feature_info->Initialize();
1292 TextureManager manager(NULL,
1293 feature_info.get(),
1294 kMaxTextureSize,
1295 kMaxCubeMapTextureSize,
1296 kMaxRectangleTextureSize,
1297 kMax3DTextureSize,
1298 kUseDefaultTextures);
1299 manager.CreateTexture(kClient1Id, kService1Id);
1300 TextureRef* texture_ref = manager.GetTexture(kClient1Id);
1301 ASSERT_TRUE(texture_ref != NULL);
1302 manager.SetTarget(texture_ref, GL_TEXTURE_EXTERNAL_OES);
1303 Texture* texture = texture_ref->texture();
1304 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), texture->target());
1305 EXPECT_FALSE(manager.CanGenerateMipmaps(texture_ref));
1306 manager.Destroy(false);
1309 TEST_F(TextureTest, DepthTexture) {
1310 TestHelper::SetupFeatureInfoInitExpectations(
1311 gl_.get(), "GL_ANGLE_depth_texture");
1312 scoped_refptr<FeatureInfo> feature_info(new FeatureInfo());
1313 feature_info->Initialize();
1314 TextureManager manager(NULL,
1315 feature_info.get(),
1316 kMaxTextureSize,
1317 kMaxCubeMapTextureSize,
1318 kMaxRectangleTextureSize,
1319 kMax3DTextureSize,
1320 kUseDefaultTextures);
1321 manager.CreateTexture(kClient1Id, kService1Id);
1322 TextureRef* texture_ref = manager.GetTexture(kClient1Id);
1323 ASSERT_TRUE(texture_ref != NULL);
1324 manager.SetTarget(texture_ref, GL_TEXTURE_2D);
1325 manager.SetLevelInfo(
1326 texture_ref, GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 4, 4, 1, 0,
1327 GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, false);
1328 EXPECT_FALSE(manager.CanGenerateMipmaps(texture_ref));
1329 manager.Destroy(false);
1332 TEST_F(TextureTest, SafeUnsafe) {
1333 static const GLuint kClient2Id = 2;
1334 static const GLuint kService2Id = 12;
1335 static const GLuint kClient3Id = 3;
1336 static const GLuint kService3Id = 13;
1337 EXPECT_FALSE(manager_->HaveUnclearedMips());
1338 Texture* texture = texture_ref_->texture();
1339 EXPECT_EQ(0, texture->num_uncleared_mips());
1340 manager_->SetTarget(texture_ref_.get(), GL_TEXTURE_2D);
1341 manager_->SetLevelInfo(texture_ref_.get(),
1342 GL_TEXTURE_2D,
1344 GL_RGBA,
1349 GL_RGBA,
1350 GL_UNSIGNED_BYTE,
1351 false);
1352 EXPECT_FALSE(texture->SafeToRenderFrom());
1353 EXPECT_TRUE(manager_->HaveUnsafeTextures());
1354 EXPECT_TRUE(manager_->HaveUnclearedMips());
1355 EXPECT_EQ(1, texture->num_uncleared_mips());
1356 manager_->SetLevelCleared(texture_ref_.get(), GL_TEXTURE_2D, 0, true);
1357 EXPECT_TRUE(texture->SafeToRenderFrom());
1358 EXPECT_FALSE(manager_->HaveUnsafeTextures());
1359 EXPECT_FALSE(manager_->HaveUnclearedMips());
1360 EXPECT_EQ(0, texture->num_uncleared_mips());
1361 manager_->SetLevelInfo(texture_ref_.get(),
1362 GL_TEXTURE_2D,
1364 GL_RGBA,
1369 GL_RGBA,
1370 GL_UNSIGNED_BYTE,
1371 false);
1372 EXPECT_FALSE(texture->SafeToRenderFrom());
1373 EXPECT_TRUE(manager_->HaveUnsafeTextures());
1374 EXPECT_TRUE(manager_->HaveUnclearedMips());
1375 EXPECT_EQ(1, texture->num_uncleared_mips());
1376 manager_->SetLevelCleared(texture_ref_.get(), GL_TEXTURE_2D, 1, true);
1377 EXPECT_TRUE(texture->SafeToRenderFrom());
1378 EXPECT_FALSE(manager_->HaveUnsafeTextures());
1379 EXPECT_FALSE(manager_->HaveUnclearedMips());
1380 EXPECT_EQ(0, texture->num_uncleared_mips());
1381 manager_->SetLevelInfo(texture_ref_.get(),
1382 GL_TEXTURE_2D,
1384 GL_RGBA,
1389 GL_RGBA,
1390 GL_UNSIGNED_BYTE,
1391 false);
1392 manager_->SetLevelInfo(texture_ref_.get(),
1393 GL_TEXTURE_2D,
1395 GL_RGBA,
1400 GL_RGBA,
1401 GL_UNSIGNED_BYTE,
1402 false);
1403 EXPECT_FALSE(texture->SafeToRenderFrom());
1404 EXPECT_TRUE(manager_->HaveUnsafeTextures());
1405 EXPECT_TRUE(manager_->HaveUnclearedMips());
1406 EXPECT_EQ(2, texture->num_uncleared_mips());
1407 manager_->SetLevelCleared(texture_ref_.get(), GL_TEXTURE_2D, 0, true);
1408 EXPECT_FALSE(texture->SafeToRenderFrom());
1409 EXPECT_TRUE(manager_->HaveUnsafeTextures());
1410 EXPECT_TRUE(manager_->HaveUnclearedMips());
1411 EXPECT_EQ(1, texture->num_uncleared_mips());
1412 manager_->SetLevelCleared(texture_ref_.get(), GL_TEXTURE_2D, 1, true);
1413 EXPECT_TRUE(texture->SafeToRenderFrom());
1414 EXPECT_FALSE(manager_->HaveUnsafeTextures());
1415 EXPECT_FALSE(manager_->HaveUnclearedMips());
1416 EXPECT_EQ(0, texture->num_uncleared_mips());
1417 manager_->SetLevelInfo(texture_ref_.get(),
1418 GL_TEXTURE_2D,
1420 GL_RGBA,
1425 GL_RGBA,
1426 GL_UNSIGNED_BYTE,
1427 false);
1428 EXPECT_FALSE(texture->SafeToRenderFrom());
1429 EXPECT_TRUE(manager_->HaveUnsafeTextures());
1430 EXPECT_TRUE(manager_->HaveUnclearedMips());
1431 EXPECT_EQ(1, texture->num_uncleared_mips());
1432 manager_->MarkMipmapsGenerated(texture_ref_.get());
1433 EXPECT_TRUE(texture->SafeToRenderFrom());
1434 EXPECT_FALSE(manager_->HaveUnsafeTextures());
1435 EXPECT_FALSE(manager_->HaveUnclearedMips());
1436 EXPECT_EQ(0, texture->num_uncleared_mips());
1438 manager_->CreateTexture(kClient2Id, kService2Id);
1439 scoped_refptr<TextureRef> texture_ref2(
1440 manager_->GetTexture(kClient2Id));
1441 ASSERT_TRUE(texture_ref2.get() != NULL);
1442 manager_->SetTarget(texture_ref2.get(), GL_TEXTURE_2D);
1443 EXPECT_FALSE(manager_->HaveUnsafeTextures());
1444 EXPECT_FALSE(manager_->HaveUnclearedMips());
1445 Texture* texture2 = texture_ref2->texture();
1446 EXPECT_EQ(0, texture2->num_uncleared_mips());
1447 manager_->SetLevelInfo(texture_ref2.get(),
1448 GL_TEXTURE_2D,
1450 GL_RGBA,
1455 GL_RGBA,
1456 GL_UNSIGNED_BYTE,
1457 true);
1458 EXPECT_FALSE(manager_->HaveUnsafeTextures());
1459 EXPECT_FALSE(manager_->HaveUnclearedMips());
1460 EXPECT_EQ(0, texture2->num_uncleared_mips());
1461 manager_->SetLevelInfo(texture_ref2.get(),
1462 GL_TEXTURE_2D,
1464 GL_RGBA,
1469 GL_RGBA,
1470 GL_UNSIGNED_BYTE,
1471 false);
1472 EXPECT_TRUE(manager_->HaveUnsafeTextures());
1473 EXPECT_TRUE(manager_->HaveUnclearedMips());
1474 EXPECT_EQ(1, texture2->num_uncleared_mips());
1476 manager_->CreateTexture(kClient3Id, kService3Id);
1477 scoped_refptr<TextureRef> texture_ref3(
1478 manager_->GetTexture(kClient3Id));
1479 ASSERT_TRUE(texture_ref3.get() != NULL);
1480 manager_->SetTarget(texture_ref3.get(), GL_TEXTURE_2D);
1481 manager_->SetLevelInfo(texture_ref3.get(),
1482 GL_TEXTURE_2D,
1484 GL_RGBA,
1489 GL_RGBA,
1490 GL_UNSIGNED_BYTE,
1491 false);
1492 EXPECT_TRUE(manager_->HaveUnsafeTextures());
1493 EXPECT_TRUE(manager_->HaveUnclearedMips());
1494 Texture* texture3 = texture_ref3->texture();
1495 EXPECT_EQ(1, texture3->num_uncleared_mips());
1496 manager_->SetLevelCleared(texture_ref2.get(), GL_TEXTURE_2D, 0, true);
1497 EXPECT_TRUE(manager_->HaveUnsafeTextures());
1498 EXPECT_TRUE(manager_->HaveUnclearedMips());
1499 EXPECT_EQ(0, texture2->num_uncleared_mips());
1500 manager_->SetLevelCleared(texture_ref3.get(), GL_TEXTURE_2D, 0, true);
1501 EXPECT_FALSE(manager_->HaveUnsafeTextures());
1502 EXPECT_FALSE(manager_->HaveUnclearedMips());
1503 EXPECT_EQ(0, texture3->num_uncleared_mips());
1505 manager_->SetLevelInfo(texture_ref2.get(),
1506 GL_TEXTURE_2D,
1508 GL_RGBA,
1513 GL_RGBA,
1514 GL_UNSIGNED_BYTE,
1515 false);
1516 manager_->SetLevelInfo(texture_ref3.get(),
1517 GL_TEXTURE_2D,
1519 GL_RGBA,
1524 GL_RGBA,
1525 GL_UNSIGNED_BYTE,
1526 false);
1527 EXPECT_TRUE(manager_->HaveUnsafeTextures());
1528 EXPECT_TRUE(manager_->HaveUnclearedMips());
1529 EXPECT_EQ(1, texture2->num_uncleared_mips());
1530 EXPECT_EQ(1, texture3->num_uncleared_mips());
1531 manager_->RemoveTexture(kClient3Id);
1532 EXPECT_TRUE(manager_->HaveUnsafeTextures());
1533 EXPECT_TRUE(manager_->HaveUnclearedMips());
1534 manager_->RemoveTexture(kClient2Id);
1535 EXPECT_TRUE(manager_->HaveUnsafeTextures());
1536 EXPECT_TRUE(manager_->HaveUnclearedMips());
1537 EXPECT_CALL(*gl_, DeleteTextures(1, ::testing::Pointee(kService2Id)))
1538 .Times(1)
1539 .RetiresOnSaturation();
1540 texture_ref2 = NULL;
1541 EXPECT_TRUE(manager_->HaveUnsafeTextures());
1542 EXPECT_TRUE(manager_->HaveUnclearedMips());
1543 EXPECT_CALL(*gl_, DeleteTextures(1, ::testing::Pointee(kService3Id)))
1544 .Times(1)
1545 .RetiresOnSaturation();
1546 texture_ref3 = NULL;
1547 EXPECT_FALSE(manager_->HaveUnsafeTextures());
1548 EXPECT_FALSE(manager_->HaveUnclearedMips());
1551 TEST_F(TextureTest, ClearTexture) {
1552 EXPECT_CALL(*decoder_, ClearLevel(_, _, _, _, _, _, _, _, _))
1553 .WillRepeatedly(Return(true));
1554 manager_->SetTarget(texture_ref_.get(), GL_TEXTURE_2D);
1555 manager_->SetLevelInfo(texture_ref_.get(),
1556 GL_TEXTURE_2D,
1558 GL_RGBA,
1563 GL_RGBA,
1564 GL_UNSIGNED_BYTE,
1565 false);
1566 manager_->SetLevelInfo(texture_ref_.get(),
1567 GL_TEXTURE_2D,
1569 GL_RGBA,
1574 GL_RGBA,
1575 GL_UNSIGNED_BYTE,
1576 false);
1577 Texture* texture = texture_ref_->texture();
1578 EXPECT_FALSE(texture->SafeToRenderFrom());
1579 EXPECT_TRUE(manager_->HaveUnsafeTextures());
1580 EXPECT_TRUE(manager_->HaveUnclearedMips());
1581 EXPECT_EQ(2, texture->num_uncleared_mips());
1582 manager_->ClearRenderableLevels(decoder_.get(), texture_ref_.get());
1583 EXPECT_TRUE(texture->SafeToRenderFrom());
1584 EXPECT_FALSE(manager_->HaveUnsafeTextures());
1585 EXPECT_FALSE(manager_->HaveUnclearedMips());
1586 EXPECT_EQ(0, texture->num_uncleared_mips());
1587 manager_->SetLevelInfo(texture_ref_.get(),
1588 GL_TEXTURE_2D,
1590 GL_RGBA,
1595 GL_RGBA,
1596 GL_UNSIGNED_BYTE,
1597 false);
1598 manager_->SetLevelInfo(texture_ref_.get(),
1599 GL_TEXTURE_2D,
1601 GL_RGBA,
1606 GL_RGBA,
1607 GL_UNSIGNED_BYTE,
1608 false);
1609 EXPECT_FALSE(texture->SafeToRenderFrom());
1610 EXPECT_TRUE(manager_->HaveUnsafeTextures());
1611 EXPECT_TRUE(manager_->HaveUnclearedMips());
1612 EXPECT_EQ(2, texture->num_uncleared_mips());
1613 manager_->ClearTextureLevel(
1614 decoder_.get(), texture_ref_.get(), GL_TEXTURE_2D, 0);
1615 EXPECT_FALSE(texture->SafeToRenderFrom());
1616 EXPECT_TRUE(manager_->HaveUnsafeTextures());
1617 EXPECT_TRUE(manager_->HaveUnclearedMips());
1618 EXPECT_EQ(1, texture->num_uncleared_mips());
1619 manager_->ClearTextureLevel(
1620 decoder_.get(), texture_ref_.get(), GL_TEXTURE_2D, 1);
1621 EXPECT_TRUE(texture->SafeToRenderFrom());
1622 EXPECT_FALSE(manager_->HaveUnsafeTextures());
1623 EXPECT_FALSE(manager_->HaveUnclearedMips());
1624 EXPECT_EQ(0, texture->num_uncleared_mips());
1627 TEST_F(TextureTest, UseDeletedTexture) {
1628 static const GLuint kClient2Id = 2;
1629 static const GLuint kService2Id = 12;
1630 // Make the default texture renderable
1631 manager_->SetTarget(texture_ref_.get(), GL_TEXTURE_2D);
1632 manager_->SetLevelInfo(texture_ref_.get(),
1633 GL_TEXTURE_2D,
1635 GL_RGBA,
1640 GL_RGBA,
1641 GL_UNSIGNED_BYTE,
1642 false);
1643 EXPECT_FALSE(manager_->HaveUnrenderableTextures());
1644 // Make a new texture
1645 manager_->CreateTexture(kClient2Id, kService2Id);
1646 scoped_refptr<TextureRef> texture_ref(
1647 manager_->GetTexture(kClient2Id));
1648 manager_->SetTarget(texture_ref.get(), GL_TEXTURE_2D);
1649 EXPECT_FALSE(manager_->CanRender(texture_ref.get()));
1650 EXPECT_TRUE(manager_->HaveUnrenderableTextures());
1651 // Remove it.
1652 manager_->RemoveTexture(kClient2Id);
1653 EXPECT_FALSE(manager_->CanRender(texture_ref.get()));
1654 EXPECT_TRUE(manager_->HaveUnrenderableTextures());
1655 // Check that we can still manipulate it and it effects the manager.
1656 manager_->SetLevelInfo(texture_ref.get(),
1657 GL_TEXTURE_2D,
1659 GL_RGBA,
1664 GL_RGBA,
1665 GL_UNSIGNED_BYTE,
1666 false);
1667 EXPECT_TRUE(manager_->CanRender(texture_ref.get()));
1668 EXPECT_FALSE(manager_->HaveUnrenderableTextures());
1669 EXPECT_CALL(*gl_, DeleteTextures(1, ::testing::Pointee(kService2Id)))
1670 .Times(1)
1671 .RetiresOnSaturation();
1672 texture_ref = NULL;
1675 TEST_F(TextureTest, GetLevelImage) {
1676 manager_->SetTarget(texture_ref_.get(), GL_TEXTURE_2D);
1677 manager_->SetLevelInfo(texture_ref_.get(),
1678 GL_TEXTURE_2D,
1680 GL_RGBA,
1685 GL_RGBA,
1686 GL_UNSIGNED_BYTE,
1687 true);
1688 Texture* texture = texture_ref_->texture();
1689 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 1) == NULL);
1690 // Set image.
1691 scoped_refptr<gfx::GLImage> image(new gfx::GLImageStub);
1692 manager_->SetLevelImage(texture_ref_.get(), GL_TEXTURE_2D, 1, image.get());
1693 EXPECT_FALSE(texture->GetLevelImage(GL_TEXTURE_2D, 1) == NULL);
1694 // Remove it.
1695 manager_->SetLevelImage(texture_ref_.get(), GL_TEXTURE_2D, 1, NULL);
1696 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 1) == NULL);
1697 manager_->SetLevelImage(texture_ref_.get(), GL_TEXTURE_2D, 1, image.get());
1698 // Image should be reset when SetLevelInfo is called.
1699 manager_->SetLevelInfo(texture_ref_.get(),
1700 GL_TEXTURE_2D,
1702 GL_RGBA,
1707 GL_RGBA,
1708 GL_UNSIGNED_BYTE,
1709 true);
1710 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 1) == NULL);
1713 namespace {
1715 bool InSet(std::set<std::string>* string_set, const std::string& str) {
1716 std::pair<std::set<std::string>::iterator, bool> result =
1717 string_set->insert(str);
1718 return !result.second;
1721 } // anonymous namespace
1723 TEST_F(TextureTest, AddToSignature) {
1724 manager_->SetTarget(texture_ref_.get(), GL_TEXTURE_2D);
1725 manager_->SetLevelInfo(texture_ref_.get(),
1726 GL_TEXTURE_2D,
1728 GL_RGBA,
1733 GL_RGBA,
1734 GL_UNSIGNED_BYTE,
1735 true);
1736 std::string signature1;
1737 std::string signature2;
1738 manager_->AddToSignature(texture_ref_.get(), GL_TEXTURE_2D, 1, &signature1);
1740 std::set<std::string> string_set;
1741 EXPECT_FALSE(InSet(&string_set, signature1));
1743 // check changing 1 thing makes a different signature.
1744 manager_->SetLevelInfo(texture_ref_.get(),
1745 GL_TEXTURE_2D,
1747 GL_RGBA,
1752 GL_RGBA,
1753 GL_UNSIGNED_BYTE,
1754 true);
1755 manager_->AddToSignature(texture_ref_.get(), GL_TEXTURE_2D, 1, &signature2);
1756 EXPECT_FALSE(InSet(&string_set, signature2));
1758 // check putting it back makes the same signature.
1759 manager_->SetLevelInfo(texture_ref_.get(),
1760 GL_TEXTURE_2D,
1762 GL_RGBA,
1767 GL_RGBA,
1768 GL_UNSIGNED_BYTE,
1769 true);
1770 signature2.clear();
1771 manager_->AddToSignature(texture_ref_.get(), GL_TEXTURE_2D, 1, &signature2);
1772 EXPECT_EQ(signature1, signature2);
1774 // Check setting cleared status does not change signature.
1775 manager_->SetLevelInfo(texture_ref_.get(),
1776 GL_TEXTURE_2D,
1778 GL_RGBA,
1783 GL_RGBA,
1784 GL_UNSIGNED_BYTE,
1785 false);
1786 signature2.clear();
1787 manager_->AddToSignature(texture_ref_.get(), GL_TEXTURE_2D, 1, &signature2);
1788 EXPECT_EQ(signature1, signature2);
1790 // Check changing other settings changes signature.
1791 manager_->SetLevelInfo(texture_ref_.get(),
1792 GL_TEXTURE_2D,
1794 GL_RGBA,
1799 GL_RGBA,
1800 GL_UNSIGNED_BYTE,
1801 false);
1802 signature2.clear();
1803 manager_->AddToSignature(texture_ref_.get(), GL_TEXTURE_2D, 1, &signature2);
1804 EXPECT_FALSE(InSet(&string_set, signature2));
1806 manager_->SetLevelInfo(texture_ref_.get(),
1807 GL_TEXTURE_2D,
1809 GL_RGBA,
1814 GL_RGBA,
1815 GL_UNSIGNED_BYTE,
1816 false);
1817 signature2.clear();
1818 manager_->AddToSignature(texture_ref_.get(), GL_TEXTURE_2D, 1, &signature2);
1819 EXPECT_FALSE(InSet(&string_set, signature2));
1821 manager_->SetLevelInfo(texture_ref_.get(),
1822 GL_TEXTURE_2D,
1824 GL_RGBA,
1829 GL_RGBA,
1830 GL_UNSIGNED_BYTE,
1831 false);
1832 signature2.clear();
1833 manager_->AddToSignature(texture_ref_.get(), GL_TEXTURE_2D, 1, &signature2);
1834 EXPECT_FALSE(InSet(&string_set, signature2));
1836 manager_->SetLevelInfo(texture_ref_.get(),
1837 GL_TEXTURE_2D,
1839 GL_RGBA,
1844 GL_RGB,
1845 GL_UNSIGNED_BYTE,
1846 false);
1847 signature2.clear();
1848 manager_->AddToSignature(texture_ref_.get(), GL_TEXTURE_2D, 1, &signature2);
1849 EXPECT_FALSE(InSet(&string_set, signature2));
1851 manager_->SetLevelInfo(texture_ref_.get(),
1852 GL_TEXTURE_2D,
1854 GL_RGBA,
1859 GL_RGBA,
1860 GL_FLOAT,
1861 false);
1862 signature2.clear();
1863 manager_->AddToSignature(texture_ref_.get(), GL_TEXTURE_2D, 1, &signature2);
1864 EXPECT_FALSE(InSet(&string_set, signature2));
1866 // put it back
1867 manager_->SetLevelInfo(texture_ref_.get(),
1868 GL_TEXTURE_2D,
1870 GL_RGBA,
1875 GL_RGBA,
1876 GL_UNSIGNED_BYTE,
1877 false);
1878 signature2.clear();
1879 manager_->AddToSignature(texture_ref_.get(), GL_TEXTURE_2D, 1, &signature2);
1880 EXPECT_EQ(signature1, signature2);
1882 // check changing parameters changes signature.
1883 SetParameter(
1884 texture_ref_.get(), GL_TEXTURE_MIN_FILTER, GL_NEAREST, GL_NO_ERROR);
1885 signature2.clear();
1886 manager_->AddToSignature(texture_ref_.get(), GL_TEXTURE_2D, 1, &signature2);
1887 EXPECT_FALSE(InSet(&string_set, signature2));
1889 SetParameter(texture_ref_.get(),
1890 GL_TEXTURE_MIN_FILTER,
1891 GL_NEAREST_MIPMAP_LINEAR,
1892 GL_NO_ERROR);
1893 SetParameter(
1894 texture_ref_.get(), GL_TEXTURE_MAG_FILTER, GL_NEAREST, GL_NO_ERROR);
1895 signature2.clear();
1896 manager_->AddToSignature(texture_ref_.get(), GL_TEXTURE_2D, 1, &signature2);
1897 EXPECT_FALSE(InSet(&string_set, signature2));
1899 SetParameter(
1900 texture_ref_.get(), GL_TEXTURE_MAG_FILTER, GL_LINEAR, GL_NO_ERROR);
1901 SetParameter(
1902 texture_ref_.get(), GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE, GL_NO_ERROR);
1903 signature2.clear();
1904 manager_->AddToSignature(texture_ref_.get(), GL_TEXTURE_2D, 1, &signature2);
1905 EXPECT_FALSE(InSet(&string_set, signature2));
1907 SetParameter(texture_ref_.get(), GL_TEXTURE_WRAP_S, GL_REPEAT, GL_NO_ERROR);
1908 SetParameter(
1909 texture_ref_.get(), GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE, GL_NO_ERROR);
1910 signature2.clear();
1911 manager_->AddToSignature(texture_ref_.get(), GL_TEXTURE_2D, 1, &signature2);
1912 EXPECT_FALSE(InSet(&string_set, signature2));
1914 // Check putting it back genenerates the same signature
1915 SetParameter(texture_ref_.get(), GL_TEXTURE_WRAP_T, GL_REPEAT, GL_NO_ERROR);
1916 signature2.clear();
1917 manager_->AddToSignature(texture_ref_.get(), GL_TEXTURE_2D, 1, &signature2);
1918 EXPECT_EQ(signature1, signature2);
1920 // Check the set was acutally getting different signatures.
1921 EXPECT_EQ(11u, string_set.size());
1924 class ProduceConsumeTextureTest : public TextureTest,
1925 public ::testing::WithParamInterface<GLenum> {
1926 public:
1927 void SetUp() override {
1928 TextureTest::SetUpBase(NULL, "GL_OES_EGL_image_external");
1929 manager_->CreateTexture(kClient2Id, kService2Id);
1930 texture2_ = manager_->GetTexture(kClient2Id);
1932 EXPECT_CALL(*decoder_.get(), GetErrorState())
1933 .WillRepeatedly(Return(error_state_.get()));
1936 void TearDown() override {
1937 if (texture2_.get()) {
1938 // If it's not in the manager then setting texture2_ to NULL will
1939 // delete the texture.
1940 if (!texture2_->client_id()) {
1941 // Check that it gets deleted when the last reference is released.
1942 EXPECT_CALL(
1943 *gl_,
1944 DeleteTextures(1, ::testing::Pointee(texture2_->service_id())))
1945 .Times(1).RetiresOnSaturation();
1947 texture2_ = NULL;
1949 TextureTest::TearDown();
1952 protected:
1953 struct LevelInfo {
1954 LevelInfo(GLenum target,
1955 GLenum format,
1956 GLsizei width,
1957 GLsizei height,
1958 GLsizei depth,
1959 GLint border,
1960 GLenum type,
1961 bool cleared)
1962 : target(target),
1963 format(format),
1964 width(width),
1965 height(height),
1966 depth(depth),
1967 border(border),
1968 type(type),
1969 cleared(cleared) {}
1971 LevelInfo()
1972 : target(0),
1973 format(0),
1974 width(-1),
1975 height(-1),
1976 depth(1),
1977 border(0),
1978 type(0),
1979 cleared(false) {}
1981 bool operator==(const LevelInfo& other) const {
1982 return target == other.target && format == other.format &&
1983 width == other.width && height == other.height &&
1984 depth == other.depth && border == other.border &&
1985 type == other.type && cleared == other.cleared;
1988 GLenum target;
1989 GLenum format;
1990 GLsizei width;
1991 GLsizei height;
1992 GLsizei depth;
1993 GLint border;
1994 GLenum type;
1995 bool cleared;
1998 void SetLevelInfo(TextureRef* texture_ref,
1999 GLint level,
2000 const LevelInfo& info) {
2001 manager_->SetLevelInfo(texture_ref,
2002 info.target,
2003 level,
2004 info.format,
2005 info.width,
2006 info.height,
2007 info.depth,
2008 info.border,
2009 info.format,
2010 info.type,
2011 info.cleared);
2014 static LevelInfo GetLevelInfo(const TextureRef* texture_ref,
2015 GLint target,
2016 GLint level) {
2017 const Texture* texture = texture_ref->texture();
2018 LevelInfo info;
2019 info.target = target;
2020 EXPECT_TRUE(texture->GetLevelSize(target, level, &info.width,
2021 &info.height, &info.depth));
2022 EXPECT_TRUE(texture->GetLevelType(target, level, &info.type,
2023 &info.format));
2024 info.cleared = texture->IsLevelCleared(target, level);
2025 return info;
2028 Texture* Produce(TextureRef* texture_ref) {
2029 Texture* texture = manager_->Produce(texture_ref);
2030 EXPECT_TRUE(texture != NULL);
2031 return texture;
2034 void Consume(GLuint client_id, Texture* texture) {
2035 EXPECT_TRUE(manager_->Consume(client_id, texture));
2038 scoped_refptr<TextureRef> texture2_;
2040 private:
2041 static const GLuint kClient2Id;
2042 static const GLuint kService2Id;
2045 const GLuint ProduceConsumeTextureTest::kClient2Id = 2;
2046 const GLuint ProduceConsumeTextureTest::kService2Id = 12;
2048 TEST_F(ProduceConsumeTextureTest, ProduceConsume2D) {
2049 manager_->SetTarget(texture_ref_.get(), GL_TEXTURE_2D);
2050 Texture* texture = texture_ref_->texture();
2051 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), texture->target());
2052 LevelInfo level0(
2053 GL_TEXTURE_2D, GL_RGBA, 4, 4, 1, 0, GL_UNSIGNED_BYTE, true);
2054 SetLevelInfo(texture_ref_.get(), 0, level0);
2055 EXPECT_TRUE(manager_->MarkMipmapsGenerated(texture_ref_.get()));
2056 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture));
2057 LevelInfo level1 = GetLevelInfo(texture_ref_.get(), GL_TEXTURE_2D, 1);
2058 LevelInfo level2 = GetLevelInfo(texture_ref_.get(), GL_TEXTURE_2D, 2);
2059 Texture* produced_texture = Produce(texture_ref_.get());
2060 EXPECT_EQ(produced_texture, texture);
2062 // Make this texture bigger with more levels, and make sure they get
2063 // clobbered correctly during Consume().
2064 manager_->SetTarget(texture2_.get(), GL_TEXTURE_2D);
2065 SetLevelInfo(
2066 texture2_.get(),
2068 LevelInfo(GL_TEXTURE_2D, GL_RGBA, 16, 16, 1, 0, GL_UNSIGNED_BYTE, false));
2069 EXPECT_TRUE(manager_->MarkMipmapsGenerated(texture2_.get()));
2070 texture = texture2_->texture();
2071 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture));
2072 EXPECT_EQ(1024U + 256U + 64U + 16U + 4U, texture->estimated_size());
2074 GLuint client_id = texture2_->client_id();
2075 manager_->RemoveTexture(client_id);
2076 Consume(client_id, produced_texture);
2077 scoped_refptr<TextureRef> restored_texture = manager_->GetTexture(client_id);
2078 EXPECT_EQ(produced_texture, restored_texture->texture());
2079 EXPECT_EQ(level0, GetLevelInfo(restored_texture.get(), GL_TEXTURE_2D, 0));
2080 EXPECT_EQ(level1, GetLevelInfo(restored_texture.get(), GL_TEXTURE_2D, 1));
2081 EXPECT_EQ(level2, GetLevelInfo(restored_texture.get(), GL_TEXTURE_2D, 2));
2082 texture = restored_texture->texture();
2083 EXPECT_EQ(64U + 16U + 4U, texture->estimated_size());
2084 GLint w, h;
2085 EXPECT_FALSE(texture->GetLevelSize(GL_TEXTURE_2D, 3, &w, &h, nullptr));
2087 // However the old texture ref still exists if it was referenced somewhere.
2088 EXPECT_EQ(1024U + 256U + 64U + 16U + 4U,
2089 texture2_->texture()->estimated_size());
2092 TEST_F(ProduceConsumeTextureTest, ProduceConsumeClearRectangle) {
2093 manager_->SetTarget(texture_ref_.get(), GL_TEXTURE_RECTANGLE_ARB);
2094 Texture* texture = texture_ref_->texture();
2095 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_RECTANGLE_ARB), texture->target());
2096 LevelInfo level0(
2097 GL_TEXTURE_RECTANGLE_ARB, GL_RGBA, 1, 1, 1, 0, GL_UNSIGNED_BYTE, false);
2098 SetLevelInfo(texture_ref_.get(), 0, level0);
2099 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture));
2100 Texture* produced_texture = Produce(texture_ref_.get());
2101 EXPECT_EQ(produced_texture, texture);
2102 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_RECTANGLE_ARB),
2103 produced_texture->target());
2105 GLuint client_id = texture2_->client_id();
2106 manager_->RemoveTexture(client_id);
2107 Consume(client_id, produced_texture);
2108 scoped_refptr<TextureRef> restored_texture = manager_->GetTexture(client_id);
2109 EXPECT_EQ(produced_texture, restored_texture->texture());
2111 // See if we can clear the previously uncleared level now.
2112 EXPECT_EQ(level0,
2113 GetLevelInfo(restored_texture.get(), GL_TEXTURE_RECTANGLE_ARB, 0));
2114 EXPECT_CALL(*decoder_, ClearLevel(_, _, _, _, _, _, _, _, _))
2115 .WillRepeatedly(Return(true));
2116 EXPECT_TRUE(manager_->ClearTextureLevel(
2117 decoder_.get(), restored_texture.get(), GL_TEXTURE_RECTANGLE_ARB, 0));
2120 TEST_F(ProduceConsumeTextureTest, ProduceConsumeExternal) {
2121 manager_->SetTarget(texture_ref_.get(), GL_TEXTURE_EXTERNAL_OES);
2122 Texture* texture = texture_ref_->texture();
2123 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), texture->target());
2124 LevelInfo level0(
2125 GL_TEXTURE_EXTERNAL_OES, GL_RGBA, 1, 1, 1, 0, GL_UNSIGNED_BYTE, false);
2126 SetLevelInfo(texture_ref_.get(), 0, level0);
2127 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture));
2128 Texture* produced_texture = Produce(texture_ref_.get());
2129 EXPECT_EQ(produced_texture, texture);
2131 GLuint client_id = texture2_->client_id();
2132 manager_->RemoveTexture(client_id);
2133 Consume(client_id, produced_texture);
2134 scoped_refptr<TextureRef> restored_texture = manager_->GetTexture(client_id);
2135 EXPECT_EQ(produced_texture, restored_texture->texture());
2136 EXPECT_EQ(level0,
2137 GetLevelInfo(restored_texture.get(), GL_TEXTURE_EXTERNAL_OES, 0));
2140 TEST_P(ProduceConsumeTextureTest, ProduceConsumeTextureWithImage) {
2141 GLenum target = GetParam();
2142 manager_->SetTarget(texture_ref_.get(), target);
2143 Texture* texture = texture_ref_->texture();
2144 EXPECT_EQ(static_cast<GLenum>(target), texture->target());
2145 scoped_refptr<gfx::GLImage> image(new gfx::GLImageStub);
2146 manager_->SetLevelInfo(texture_ref_.get(),
2147 target,
2149 GL_RGBA,
2154 GL_RGBA,
2155 GL_UNSIGNED_BYTE,
2156 true);
2157 manager_->SetLevelImage(texture_ref_.get(), target, 0, image.get());
2158 GLuint service_id = texture->service_id();
2159 Texture* produced_texture = Produce(texture_ref_.get());
2161 GLuint client_id = texture2_->client_id();
2162 manager_->RemoveTexture(client_id);
2163 Consume(client_id, produced_texture);
2164 scoped_refptr<TextureRef> restored_texture = manager_->GetTexture(client_id);
2165 EXPECT_EQ(produced_texture, restored_texture->texture());
2166 EXPECT_EQ(service_id, restored_texture->service_id());
2167 EXPECT_EQ(image.get(), restored_texture->texture()->GetLevelImage(target, 0));
2170 static const GLenum kTextureTargets[] = {GL_TEXTURE_2D, GL_TEXTURE_EXTERNAL_OES,
2171 GL_TEXTURE_RECTANGLE_ARB, };
2173 INSTANTIATE_TEST_CASE_P(Target,
2174 ProduceConsumeTextureTest,
2175 ::testing::ValuesIn(kTextureTargets));
2177 TEST_F(ProduceConsumeTextureTest, ProduceConsumeCube) {
2178 manager_->SetTarget(texture_ref_.get(), GL_TEXTURE_CUBE_MAP);
2179 Texture* texture = texture_ref_->texture();
2180 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_CUBE_MAP), texture->target());
2181 LevelInfo face0(GL_TEXTURE_CUBE_MAP_POSITIVE_X,
2182 GL_RGBA,
2187 GL_UNSIGNED_BYTE,
2188 true);
2189 LevelInfo face5(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
2190 GL_RGBA,
2195 GL_UNSIGNED_BYTE,
2196 true);
2197 SetLevelInfo(texture_ref_.get(), 0, face0);
2198 SetLevelInfo(texture_ref_.get(), 0, face5);
2199 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture));
2200 Texture* produced_texture = Produce(texture_ref_.get());
2201 EXPECT_EQ(produced_texture, texture);
2203 GLuint client_id = texture2_->client_id();
2204 manager_->RemoveTexture(client_id);
2205 Consume(client_id, produced_texture);
2206 scoped_refptr<TextureRef> restored_texture = manager_->GetTexture(client_id);
2207 EXPECT_EQ(produced_texture, restored_texture->texture());
2208 EXPECT_EQ(
2209 face0,
2210 GetLevelInfo(restored_texture.get(), GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0));
2211 EXPECT_EQ(
2212 face5,
2213 GetLevelInfo(restored_texture.get(), GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0));
2216 class CountingMemoryTracker : public MemoryTracker {
2217 public:
2218 CountingMemoryTracker() {
2219 current_size_[0] = 0;
2220 current_size_[1] = 0;
2223 void TrackMemoryAllocatedChange(size_t old_size,
2224 size_t new_size,
2225 Pool pool) override {
2226 DCHECK_LT(static_cast<size_t>(pool), arraysize(current_size_));
2227 current_size_[pool] += new_size - old_size;
2230 bool EnsureGPUMemoryAvailable(size_t size_needed) override { return true; }
2232 size_t GetSize(Pool pool) {
2233 DCHECK_LT(static_cast<size_t>(pool), arraysize(current_size_));
2234 return current_size_[pool];
2237 private:
2238 ~CountingMemoryTracker() override {}
2240 size_t current_size_[2];
2241 DISALLOW_COPY_AND_ASSIGN(CountingMemoryTracker);
2244 class SharedTextureTest : public GpuServiceTest {
2245 public:
2246 static const bool kUseDefaultTextures = false;
2248 SharedTextureTest() : feature_info_(new FeatureInfo()) {}
2250 ~SharedTextureTest() override {}
2252 void SetUp() override {
2253 GpuServiceTest::SetUp();
2254 memory_tracker1_ = new CountingMemoryTracker;
2255 texture_manager1_.reset(
2256 new TextureManager(memory_tracker1_.get(),
2257 feature_info_.get(),
2258 TextureManagerTest::kMaxTextureSize,
2259 TextureManagerTest::kMaxCubeMapTextureSize,
2260 TextureManagerTest::kMaxRectangleTextureSize,
2261 TextureManagerTest::kMax3DTextureSize,
2262 kUseDefaultTextures));
2263 memory_tracker2_ = new CountingMemoryTracker;
2264 texture_manager2_.reset(
2265 new TextureManager(memory_tracker2_.get(),
2266 feature_info_.get(),
2267 TextureManagerTest::kMaxTextureSize,
2268 TextureManagerTest::kMaxCubeMapTextureSize,
2269 TextureManagerTest::kMaxRectangleTextureSize,
2270 TextureManagerTest::kMax3DTextureSize,
2271 kUseDefaultTextures));
2272 TestHelper::SetupTextureManagerInitExpectations(
2273 gl_.get(), "", kUseDefaultTextures);
2274 texture_manager1_->Initialize();
2275 TestHelper::SetupTextureManagerInitExpectations(
2276 gl_.get(), "", kUseDefaultTextures);
2277 texture_manager2_->Initialize();
2280 void TearDown() override {
2281 texture_manager2_->Destroy(false);
2282 texture_manager2_.reset();
2283 texture_manager1_->Destroy(false);
2284 texture_manager1_.reset();
2285 GpuServiceTest::TearDown();
2288 protected:
2289 scoped_refptr<FeatureInfo> feature_info_;
2290 scoped_refptr<CountingMemoryTracker> memory_tracker1_;
2291 scoped_ptr<TextureManager> texture_manager1_;
2292 scoped_refptr<CountingMemoryTracker> memory_tracker2_;
2293 scoped_ptr<TextureManager> texture_manager2_;
2296 TEST_F(SharedTextureTest, DeleteTextures) {
2297 scoped_refptr<TextureRef> ref1 = texture_manager1_->CreateTexture(10, 10);
2298 scoped_refptr<TextureRef> ref2 =
2299 texture_manager2_->Consume(20, ref1->texture());
2300 EXPECT_CALL(*gl_, DeleteTextures(1, _))
2301 .Times(0);
2302 ref1 = NULL;
2303 texture_manager1_->RemoveTexture(10);
2304 testing::Mock::VerifyAndClearExpectations(gl_.get());
2306 EXPECT_CALL(*gl_, DeleteTextures(1, _))
2307 .Times(1)
2308 .RetiresOnSaturation();
2309 ref2 = NULL;
2310 texture_manager2_->RemoveTexture(20);
2311 testing::Mock::VerifyAndClearExpectations(gl_.get());
2314 TEST_F(SharedTextureTest, TextureSafetyAccounting) {
2315 EXPECT_FALSE(texture_manager1_->HaveUnrenderableTextures());
2316 EXPECT_FALSE(texture_manager1_->HaveUnsafeTextures());
2317 EXPECT_FALSE(texture_manager1_->HaveUnclearedMips());
2318 EXPECT_FALSE(texture_manager2_->HaveUnrenderableTextures());
2319 EXPECT_FALSE(texture_manager2_->HaveUnsafeTextures());
2320 EXPECT_FALSE(texture_manager2_->HaveUnclearedMips());
2322 // Newly created texture is renderable.
2323 scoped_refptr<TextureRef> ref1 = texture_manager1_->CreateTexture(10, 10);
2324 EXPECT_FALSE(texture_manager1_->HaveUnrenderableTextures());
2325 EXPECT_FALSE(texture_manager1_->HaveUnsafeTextures());
2326 EXPECT_FALSE(texture_manager1_->HaveUnclearedMips());
2328 // Associate new texture ref to other texture manager, should account for it
2329 // too.
2330 scoped_refptr<TextureRef> ref2 =
2331 texture_manager2_->Consume(20, ref1->texture());
2332 EXPECT_FALSE(texture_manager2_->HaveUnrenderableTextures());
2333 EXPECT_FALSE(texture_manager2_->HaveUnsafeTextures());
2334 EXPECT_FALSE(texture_manager2_->HaveUnclearedMips());
2336 // Make texture renderable but uncleared on one texture manager, should affect
2337 // other one.
2338 texture_manager1_->SetTarget(ref1.get(), GL_TEXTURE_2D);
2339 EXPECT_TRUE(texture_manager1_->HaveUnrenderableTextures());
2340 EXPECT_FALSE(texture_manager1_->HaveUnsafeTextures());
2341 EXPECT_FALSE(texture_manager1_->HaveUnclearedMips());
2342 EXPECT_TRUE(texture_manager2_->HaveUnrenderableTextures());
2343 EXPECT_FALSE(texture_manager2_->HaveUnsafeTextures());
2344 EXPECT_FALSE(texture_manager2_->HaveUnclearedMips());
2346 texture_manager1_->SetLevelInfo(ref1.get(),
2347 GL_TEXTURE_2D,
2349 GL_RGBA,
2354 GL_RGBA,
2355 GL_UNSIGNED_BYTE,
2356 false);
2357 EXPECT_FALSE(texture_manager1_->HaveUnrenderableTextures());
2358 EXPECT_TRUE(texture_manager1_->HaveUnsafeTextures());
2359 EXPECT_TRUE(texture_manager1_->HaveUnclearedMips());
2360 EXPECT_FALSE(texture_manager2_->HaveUnrenderableTextures());
2361 EXPECT_TRUE(texture_manager2_->HaveUnsafeTextures());
2362 EXPECT_TRUE(texture_manager2_->HaveUnclearedMips());
2364 // Make texture cleared on one texture manager, should affect other one.
2365 texture_manager1_->SetLevelCleared(ref1.get(), GL_TEXTURE_2D, 0, true);
2366 EXPECT_FALSE(texture_manager1_->HaveUnsafeTextures());
2367 EXPECT_FALSE(texture_manager1_->HaveUnclearedMips());
2368 EXPECT_FALSE(texture_manager2_->HaveUnsafeTextures());
2369 EXPECT_FALSE(texture_manager2_->HaveUnclearedMips());
2371 EXPECT_CALL(*gl_, DeleteTextures(1, _))
2372 .Times(1)
2373 .RetiresOnSaturation();
2374 texture_manager1_->RemoveTexture(10);
2375 texture_manager2_->RemoveTexture(20);
2378 TEST_F(SharedTextureTest, FBOCompletenessCheck) {
2379 const GLenum kCompleteValue = GL_FRAMEBUFFER_COMPLETE;
2380 FramebufferManager framebuffer_manager1(1, 1);
2381 texture_manager1_->set_framebuffer_manager(&framebuffer_manager1);
2382 FramebufferManager framebuffer_manager2(1, 1);
2383 texture_manager2_->set_framebuffer_manager(&framebuffer_manager2);
2385 scoped_refptr<TextureRef> ref1 = texture_manager1_->CreateTexture(10, 10);
2386 framebuffer_manager1.CreateFramebuffer(10, 10);
2387 scoped_refptr<Framebuffer> framebuffer1 =
2388 framebuffer_manager1.GetFramebuffer(10);
2389 framebuffer1->AttachTexture(
2390 GL_COLOR_ATTACHMENT0, ref1.get(), GL_TEXTURE_2D, 0, 0);
2391 EXPECT_FALSE(framebuffer_manager1.IsComplete(framebuffer1.get()));
2392 EXPECT_NE(kCompleteValue, framebuffer1->IsPossiblyComplete());
2394 // Make FBO complete in manager 1.
2395 texture_manager1_->SetTarget(ref1.get(), GL_TEXTURE_2D);
2396 texture_manager1_->SetLevelInfo(ref1.get(),
2397 GL_TEXTURE_2D,
2399 GL_RGBA,
2404 GL_RGBA,
2405 GL_UNSIGNED_BYTE,
2406 true);
2407 EXPECT_EQ(kCompleteValue, framebuffer1->IsPossiblyComplete());
2408 framebuffer_manager1.MarkAsComplete(framebuffer1.get());
2409 EXPECT_TRUE(framebuffer_manager1.IsComplete(framebuffer1.get()));
2411 // Share texture with manager 2.
2412 scoped_refptr<TextureRef> ref2 =
2413 texture_manager2_->Consume(20, ref1->texture());
2414 framebuffer_manager2.CreateFramebuffer(20, 20);
2415 scoped_refptr<Framebuffer> framebuffer2 =
2416 framebuffer_manager2.GetFramebuffer(20);
2417 framebuffer2->AttachTexture(
2418 GL_COLOR_ATTACHMENT0, ref2.get(), GL_TEXTURE_2D, 0, 0);
2419 EXPECT_FALSE(framebuffer_manager2.IsComplete(framebuffer2.get()));
2420 EXPECT_EQ(kCompleteValue, framebuffer2->IsPossiblyComplete());
2421 framebuffer_manager2.MarkAsComplete(framebuffer2.get());
2422 EXPECT_TRUE(framebuffer_manager2.IsComplete(framebuffer2.get()));
2424 // Change level for texture, both FBOs should be marked incomplete
2425 texture_manager1_->SetLevelInfo(ref1.get(),
2426 GL_TEXTURE_2D,
2428 GL_RGBA,
2433 GL_RGBA,
2434 GL_UNSIGNED_BYTE,
2435 true);
2436 EXPECT_FALSE(framebuffer_manager1.IsComplete(framebuffer1.get()));
2437 EXPECT_EQ(kCompleteValue, framebuffer1->IsPossiblyComplete());
2438 framebuffer_manager1.MarkAsComplete(framebuffer1.get());
2439 EXPECT_TRUE(framebuffer_manager1.IsComplete(framebuffer1.get()));
2440 EXPECT_FALSE(framebuffer_manager2.IsComplete(framebuffer2.get()));
2441 EXPECT_EQ(kCompleteValue, framebuffer2->IsPossiblyComplete());
2442 framebuffer_manager2.MarkAsComplete(framebuffer2.get());
2443 EXPECT_TRUE(framebuffer_manager2.IsComplete(framebuffer2.get()));
2445 EXPECT_CALL(*gl_, DeleteFramebuffersEXT(1, _))
2446 .Times(2)
2447 .RetiresOnSaturation();
2448 framebuffer_manager1.RemoveFramebuffer(10);
2449 framebuffer_manager2.RemoveFramebuffer(20);
2450 EXPECT_CALL(*gl_, DeleteTextures(1, _))
2451 .Times(1)
2452 .RetiresOnSaturation();
2453 texture_manager1_->RemoveTexture(10);
2454 texture_manager2_->RemoveTexture(20);
2457 TEST_F(SharedTextureTest, Memory) {
2458 size_t initial_memory1 = memory_tracker1_->GetSize(MemoryTracker::kUnmanaged);
2459 size_t initial_memory2 = memory_tracker2_->GetSize(MemoryTracker::kUnmanaged);
2461 // Newly created texture is unrenderable.
2462 scoped_refptr<TextureRef> ref1 = texture_manager1_->CreateTexture(10, 10);
2463 texture_manager1_->SetTarget(ref1.get(), GL_TEXTURE_2D);
2464 texture_manager1_->SetLevelInfo(ref1.get(),
2465 GL_TEXTURE_2D,
2467 GL_RGBA,
2472 GL_RGBA,
2473 GL_UNSIGNED_BYTE,
2474 false);
2476 EXPECT_LT(0u, ref1->texture()->estimated_size());
2477 EXPECT_EQ(initial_memory1 + ref1->texture()->estimated_size(),
2478 memory_tracker1_->GetSize(MemoryTracker::kUnmanaged));
2480 // Associate new texture ref to other texture manager, it doesn't account for
2481 // the texture memory, the first memory tracker still has it.
2482 scoped_refptr<TextureRef> ref2 =
2483 texture_manager2_->Consume(20, ref1->texture());
2484 EXPECT_EQ(initial_memory1 + ref1->texture()->estimated_size(),
2485 memory_tracker1_->GetSize(MemoryTracker::kUnmanaged));
2486 EXPECT_EQ(initial_memory2,
2487 memory_tracker2_->GetSize(MemoryTracker::kUnmanaged));
2489 // Delete the texture, memory should go to the remaining tracker.
2490 texture_manager1_->RemoveTexture(10);
2491 ref1 = NULL;
2492 EXPECT_EQ(initial_memory1,
2493 memory_tracker1_->GetSize(MemoryTracker::kUnmanaged));
2494 EXPECT_EQ(initial_memory2 + ref2->texture()->estimated_size(),
2495 memory_tracker2_->GetSize(MemoryTracker::kUnmanaged));
2497 EXPECT_CALL(*gl_, DeleteTextures(1, _))
2498 .Times(1)
2499 .RetiresOnSaturation();
2500 ref2 = NULL;
2501 texture_manager2_->RemoveTexture(20);
2502 EXPECT_EQ(initial_memory2,
2503 memory_tracker2_->GetSize(MemoryTracker::kUnmanaged));
2506 TEST_F(SharedTextureTest, Images) {
2507 scoped_refptr<TextureRef> ref1 = texture_manager1_->CreateTexture(10, 10);
2508 scoped_refptr<TextureRef> ref2 =
2509 texture_manager2_->Consume(20, ref1->texture());
2511 texture_manager1_->SetTarget(ref1.get(), GL_TEXTURE_2D);
2512 texture_manager1_->SetLevelInfo(ref1.get(),
2513 GL_TEXTURE_2D,
2515 GL_RGBA,
2520 GL_RGBA,
2521 GL_UNSIGNED_BYTE,
2522 true);
2523 EXPECT_FALSE(ref1->texture()->HasImages());
2524 EXPECT_FALSE(ref2->texture()->HasImages());
2525 EXPECT_FALSE(texture_manager1_->HaveImages());
2526 EXPECT_FALSE(texture_manager2_->HaveImages());
2527 scoped_refptr<gfx::GLImage> image1(new gfx::GLImageStub);
2528 texture_manager1_->SetLevelImage(ref1.get(), GL_TEXTURE_2D, 1, image1.get());
2529 EXPECT_TRUE(ref1->texture()->HasImages());
2530 EXPECT_TRUE(ref2->texture()->HasImages());
2531 EXPECT_TRUE(texture_manager1_->HaveImages());
2532 EXPECT_TRUE(texture_manager2_->HaveImages());
2533 scoped_refptr<gfx::GLImage> image2(new gfx::GLImageStub);
2534 texture_manager1_->SetLevelImage(ref1.get(), GL_TEXTURE_2D, 1, image2.get());
2535 EXPECT_TRUE(ref1->texture()->HasImages());
2536 EXPECT_TRUE(ref2->texture()->HasImages());
2537 EXPECT_TRUE(texture_manager1_->HaveImages());
2538 EXPECT_TRUE(texture_manager2_->HaveImages());
2539 texture_manager1_->SetLevelInfo(ref1.get(),
2540 GL_TEXTURE_2D,
2542 GL_RGBA,
2547 GL_RGBA,
2548 GL_UNSIGNED_BYTE,
2549 true);
2550 EXPECT_FALSE(ref1->texture()->HasImages());
2551 EXPECT_FALSE(ref2->texture()->HasImages());
2552 EXPECT_FALSE(texture_manager1_->HaveImages());
2553 EXPECT_FALSE(texture_manager1_->HaveImages());
2555 EXPECT_CALL(*gl_, DeleteTextures(1, _))
2556 .Times(1)
2557 .RetiresOnSaturation();
2558 texture_manager1_->RemoveTexture(10);
2559 texture_manager2_->RemoveTexture(20);
2563 class TextureFormatTypeValidationTest : public TextureManagerTest {
2564 public:
2565 TextureFormatTypeValidationTest() {}
2566 ~TextureFormatTypeValidationTest() override {}
2568 protected:
2569 void SetupFeatureInfo(const char* gl_extensions, const char* gl_version) {
2570 TestHelper::SetupFeatureInfoInitExpectationsWithGLVersion(
2571 gl_.get(), gl_extensions, "", gl_version);
2572 feature_info_->Initialize();
2575 void ExpectValid(GLenum format, GLenum type, GLenum internal_format) {
2576 EXPECT_TRUE(manager_->ValidateTextureParameters(
2577 error_state_.get(), "", format, type, internal_format, 0));
2580 void ExpectInvalid(GLenum format, GLenum type, GLenum internal_format) {
2581 EXPECT_CALL(*error_state_,
2582 SetGLError(_, _, _, _, _))
2583 .Times(1)
2584 .RetiresOnSaturation();
2585 EXPECT_FALSE(manager_->ValidateTextureParameters(
2586 error_state_.get(), "", format, type, internal_format, 0));
2589 void ExpectInvalidEnum(GLenum format, GLenum type, GLenum internal_format) {
2590 EXPECT_CALL(*error_state_,
2591 SetGLErrorInvalidEnum(_, _, _, _, _))
2592 .Times(1)
2593 .RetiresOnSaturation();
2594 EXPECT_FALSE(manager_->ValidateTextureParameters(
2595 error_state_.get(), "", format, type, internal_format, 0));
2599 TEST_F(TextureFormatTypeValidationTest, ES2Basic) {
2600 SetupFeatureInfo("", "OpenGL ES 2.0");
2602 ExpectValid(GL_ALPHA, GL_UNSIGNED_BYTE, GL_ALPHA);
2603 ExpectValid(GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_RGB);
2604 ExpectValid(GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_RGBA);
2605 ExpectValid(GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_LUMINANCE);
2606 ExpectValid(GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_LUMINANCE_ALPHA);
2608 ExpectInvalid(GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_ALPHA);
2610 // float / half_float.
2611 ExpectInvalidEnum(GL_RGBA, GL_FLOAT, GL_RGBA);
2612 ExpectInvalidEnum(GL_RGBA, GL_HALF_FLOAT_OES, GL_RGBA);
2614 // GL_EXT_bgra
2615 ExpectInvalidEnum(GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_BGRA_EXT);
2617 // depth / stencil
2618 ExpectInvalidEnum(GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT);
2619 ExpectInvalidEnum(GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_DEPTH_STENCIL);
2621 // SRGB
2622 ExpectInvalidEnum(GL_SRGB_EXT, GL_UNSIGNED_BYTE, GL_SRGB_EXT);
2623 ExpectInvalidEnum(GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE, GL_SRGB_ALPHA_EXT);
2625 // ES3
2626 ExpectInvalidEnum(GL_RGB, GL_UNSIGNED_BYTE, GL_RGB8);
2629 TEST_F(TextureFormatTypeValidationTest, ES2WithExtBGRA) {
2630 SetupFeatureInfo("GL_EXT_bgra", "OpenGL ES 2.0");
2632 ExpectValid(GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_BGRA_EXT);
2635 TEST_F(TextureFormatTypeValidationTest, ES2WithExtTextureFormatBGRA8888) {
2636 SetupFeatureInfo("GL_EXT_texture_format_BGRA8888", "OpenGL ES 2.0");
2638 ExpectValid(GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_BGRA_EXT);
2641 TEST_F(TextureFormatTypeValidationTest, ES2WithAppleTextureFormatBGRA8888) {
2642 SetupFeatureInfo("GL_APPLE_texture_format_BGRA8888", "OpenGL ES 2.0");
2644 ExpectValid(GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_BGRA_EXT);
2647 TEST_F(TextureFormatTypeValidationTest, ES2WithArbDepth) {
2648 SetupFeatureInfo("GL_ARB_depth_texture", "OpenGL ES 2.0");
2650 ExpectValid(GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT);
2651 ExpectValid(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT);
2652 ExpectInvalidEnum(GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_DEPTH_STENCIL);
2655 TEST_F(TextureFormatTypeValidationTest, ES2WithOesDepth) {
2656 SetupFeatureInfo("GL_OES_depth_texture", "OpenGL ES 2.0");
2658 ExpectValid(GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT);
2659 ExpectValid(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT);
2660 ExpectInvalidEnum(GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_DEPTH_STENCIL);
2663 TEST_F(TextureFormatTypeValidationTest, ES2WithAngleDepth) {
2664 SetupFeatureInfo("GL_ANGLE_depth_texture", "OpenGL ES 2.0");
2666 ExpectValid(GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT);
2667 ExpectValid(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT);
2668 ExpectInvalidEnum(GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_DEPTH_STENCIL);
2671 TEST_F(TextureFormatTypeValidationTest, ES2WithExtPackedDepthStencil) {
2672 SetupFeatureInfo(
2673 "GL_EXT_packed_depth_stencil GL_ARB_depth_texture", "OpenGL ES 2.0");
2675 ExpectValid(GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT);
2676 ExpectValid(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT);
2677 ExpectValid(GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_DEPTH_STENCIL);
2680 TEST_F(TextureFormatTypeValidationTest, ES2WithRGWithFloat) {
2681 SetupFeatureInfo(
2682 "GL_EXT_texture_rg GL_OES_texture_float GL_OES_texture_half_float",
2683 "OpenGL ES 2.0");
2685 ExpectValid(GL_RED_EXT, GL_HALF_FLOAT_OES, GL_RED_EXT);
2686 ExpectValid(GL_RG_EXT, GL_HALF_FLOAT_OES, GL_RG_EXT);
2687 ExpectValid(GL_RED_EXT, GL_UNSIGNED_BYTE, GL_RED_EXT);
2688 ExpectValid(GL_RG_EXT, GL_UNSIGNED_BYTE, GL_RG_EXT);
2690 ExpectInvalidEnum(GL_RED_EXT, GL_BYTE, GL_RED_EXT);
2691 ExpectInvalidEnum(GL_RG_EXT, GL_BYTE, GL_RG_EXT);
2692 ExpectInvalidEnum(GL_RED_EXT, GL_SHORT, GL_RED_EXT);
2693 ExpectInvalidEnum(GL_RG_EXT, GL_SHORT, GL_RG_EXT);
2696 TEST_F(TextureFormatTypeValidationTest, ES2WithRGNoFloat) {
2697 SetupFeatureInfo("GL_ARB_texture_rg", "OpenGL ES 2.0");
2699 ExpectValid(GL_RED_EXT, GL_UNSIGNED_BYTE, GL_RED_EXT);
2700 ExpectValid(GL_RG_EXT, GL_UNSIGNED_BYTE, GL_RG_EXT);
2702 ExpectInvalidEnum(GL_RED_EXT, GL_HALF_FLOAT_OES, GL_RED_EXT);
2703 ExpectInvalidEnum(GL_RG_EXT, GL_HALF_FLOAT_OES, GL_RG_EXT);
2706 TEST_F(TextureFormatTypeValidationTest, ES2OnTopOfES3) {
2707 SetupFeatureInfo("", "OpenGL ES 3.0");
2709 ExpectInvalidEnum(GL_RGB, GL_FLOAT, GL_RGB);
2710 ExpectInvalidEnum(GL_RGBA, GL_FLOAT, GL_RGBA);
2711 ExpectInvalidEnum(GL_LUMINANCE, GL_FLOAT, GL_LUMINANCE);
2712 ExpectInvalidEnum(GL_LUMINANCE_ALPHA, GL_FLOAT, GL_LUMINANCE_ALPHA);
2713 ExpectInvalidEnum(GL_ALPHA, GL_FLOAT, GL_ALPHA);
2715 ExpectInvalidEnum(GL_SRGB_EXT, GL_UNSIGNED_BYTE, GL_SRGB_EXT);
2716 ExpectInvalidEnum(GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE, GL_SRGB_ALPHA_EXT);
2719 TEST_F(TextureFormatTypeValidationTest, ES2WithOesTextureFloat) {
2720 SetupFeatureInfo("GL_OES_texture_float", "OpenGL ES 2.0");
2722 ExpectValid(GL_RGB, GL_FLOAT, GL_RGB);
2723 ExpectValid(GL_RGBA, GL_FLOAT, GL_RGBA);
2724 ExpectValid(GL_LUMINANCE, GL_FLOAT, GL_LUMINANCE);
2725 ExpectValid(GL_LUMINANCE_ALPHA, GL_FLOAT, GL_LUMINANCE_ALPHA);
2726 ExpectValid(GL_ALPHA, GL_FLOAT, GL_ALPHA);
2728 ExpectInvalidEnum(GL_RGB, GL_HALF_FLOAT_OES, GL_RGB);
2729 ExpectInvalidEnum(GL_RGBA, GL_HALF_FLOAT_OES, GL_RGBA);
2730 ExpectInvalidEnum(GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_LUMINANCE);
2731 ExpectInvalidEnum(GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, GL_LUMINANCE_ALPHA);
2732 ExpectInvalidEnum(GL_ALPHA, GL_HALF_FLOAT_OES, GL_ALPHA);
2735 TEST_F(TextureFormatTypeValidationTest, ES2WithOesTextureFloatLinear) {
2736 SetupFeatureInfo(
2737 "GL_OES_texture_float GL_OES_texture_float_linear", "OpenGL ES 2.0");
2739 ExpectValid(GL_RGB, GL_FLOAT, GL_RGB);
2740 ExpectValid(GL_RGBA, GL_FLOAT, GL_RGBA);
2741 ExpectValid(GL_LUMINANCE, GL_FLOAT, GL_LUMINANCE);
2742 ExpectValid(GL_LUMINANCE_ALPHA, GL_FLOAT, GL_LUMINANCE_ALPHA);
2743 ExpectValid(GL_ALPHA, GL_FLOAT, GL_ALPHA);
2745 ExpectInvalidEnum(GL_RGB, GL_HALF_FLOAT_OES, GL_RGB);
2746 ExpectInvalidEnum(GL_RGBA, GL_HALF_FLOAT_OES, GL_RGBA);
2747 ExpectInvalidEnum(GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_LUMINANCE);
2748 ExpectInvalidEnum(GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, GL_LUMINANCE_ALPHA);
2749 ExpectInvalidEnum(GL_ALPHA, GL_HALF_FLOAT_OES, GL_ALPHA);
2752 TEST_F(TextureFormatTypeValidationTest, ES2WithOesTextureHalfFloat) {
2753 SetupFeatureInfo("GL_OES_texture_half_float", "OpenGL ES 2.0");
2755 ExpectValid(GL_RGB, GL_HALF_FLOAT_OES, GL_RGB);
2756 ExpectValid(GL_RGBA, GL_HALF_FLOAT_OES, GL_RGBA);
2757 ExpectValid(GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_LUMINANCE);
2758 ExpectValid(GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, GL_LUMINANCE_ALPHA);
2759 ExpectValid(GL_ALPHA, GL_HALF_FLOAT_OES, GL_ALPHA);
2761 ExpectInvalidEnum(GL_RGB, GL_FLOAT, GL_RGB);
2762 ExpectInvalidEnum(GL_RGBA, GL_FLOAT, GL_RGBA);
2763 ExpectInvalidEnum(GL_LUMINANCE, GL_FLOAT, GL_LUMINANCE);
2764 ExpectInvalidEnum(GL_LUMINANCE_ALPHA, GL_FLOAT, GL_LUMINANCE_ALPHA);
2765 ExpectInvalidEnum(GL_ALPHA, GL_FLOAT, GL_ALPHA);
2768 TEST_F(TextureFormatTypeValidationTest, ES2WithOesTextureHalfFloatLinear) {
2769 SetupFeatureInfo(
2770 "GL_OES_texture_half_float GL_OES_texture_half_float_linear",
2771 "OpenGL ES 2.0");
2773 ExpectValid(GL_RGB, GL_HALF_FLOAT_OES, GL_RGB);
2774 ExpectValid(GL_RGBA, GL_HALF_FLOAT_OES, GL_RGBA);
2775 ExpectValid(GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_LUMINANCE);
2776 ExpectValid(GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, GL_LUMINANCE_ALPHA);
2777 ExpectValid(GL_ALPHA, GL_HALF_FLOAT_OES, GL_ALPHA);
2779 ExpectInvalidEnum(GL_RGB, GL_FLOAT, GL_RGB);
2780 ExpectInvalidEnum(GL_RGBA, GL_FLOAT, GL_RGBA);
2781 ExpectInvalidEnum(GL_LUMINANCE, GL_FLOAT, GL_LUMINANCE);
2782 ExpectInvalidEnum(GL_LUMINANCE_ALPHA, GL_FLOAT, GL_LUMINANCE_ALPHA);
2783 ExpectInvalidEnum(GL_ALPHA, GL_FLOAT, GL_ALPHA);
2786 TEST_F(TextureFormatTypeValidationTest, ES3Basic) {
2787 SetupFeatureInfo("", "OpenGL ES 3.0");
2788 EXPECT_CALL(*gl_, GetIntegerv(GL_MAX_COLOR_ATTACHMENTS, _))
2789 .WillOnce(SetArgPointee<1>(8))
2790 .RetiresOnSaturation();
2791 EXPECT_CALL(*gl_, GetIntegerv(GL_MAX_DRAW_BUFFERS, _))
2792 .WillOnce(SetArgPointee<1>(8))
2793 .RetiresOnSaturation();
2794 feature_info_->EnableES3Validators();
2796 ExpectValid(GL_ALPHA, GL_UNSIGNED_BYTE, GL_ALPHA);
2797 ExpectValid(GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_RGB);
2798 ExpectValid(GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_RGBA);
2799 ExpectValid(GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_LUMINANCE);
2800 ExpectValid(GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_LUMINANCE_ALPHA);
2802 ExpectValid(GL_RG, GL_BYTE, GL_RG8_SNORM);
2803 ExpectValid(GL_RG_INTEGER, GL_UNSIGNED_INT, GL_RG32UI);
2804 ExpectValid(GL_RG_INTEGER, GL_SHORT, GL_RG16I);
2805 ExpectValid(GL_RGB, GL_UNSIGNED_BYTE, GL_SRGB8);
2806 ExpectValid(GL_RGBA, GL_HALF_FLOAT, GL_RGBA16F);
2807 ExpectValid(GL_RGBA, GL_FLOAT, GL_RGBA16F);
2808 ExpectValid(GL_RGBA, GL_FLOAT, GL_RGBA32F);
2810 ExpectValid(GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT16);
2811 ExpectValid(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT24);
2812 ExpectValid(GL_DEPTH_COMPONENT, GL_FLOAT, GL_DEPTH_COMPONENT32F);
2813 ExpectValid(GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_DEPTH24_STENCIL8);
2814 ExpectValid(GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV,
2815 GL_DEPTH32F_STENCIL8);
2817 ExpectInvalid(GL_RGB_INTEGER, GL_INT, GL_RGBA8);
2820 } // namespace gles2
2821 } // namespace gpu