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"
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
;
35 class TextureTestHelper
{
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
{
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
{}
71 void SetUp() override
{
72 GpuServiceTest::SetUp();
73 manager_
.reset(new TextureManager(NULL
,
76 kMaxCubeMapTextureSize
,
77 kMaxRectangleTextureSize
,
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);
89 GpuServiceTest::TearDown();
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
;
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
)))
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
);
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());
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
,
187 kMaxCubeMapTextureSize
,
188 kMaxRectangleTextureSize
,
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
,
208 kMaxCubeMapTextureSize
,
209 kMaxRectangleTextureSize
,
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
,
228 kMaxCubeMapTextureSize
,
229 kMaxRectangleTextureSize
,
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
,
256 kMaxCubeMapTextureSize
,
257 kMaxRectangleTextureSize
,
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
)))
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
) {
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));
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));
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));
355 EXPECT_FALSE(manager_
->ValidForTarget(
356 GL_TEXTURE_CUBE_MAP
, kMaxCubeMapLevels
,
357 kMaxCubeMapTextureSize
, 1, 1));
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
,
380 EXPECT_FALSE(manager_
->ValidForTarget(
381 GL_TEXTURE_CUBE_MAP
, level
,
382 (kMaxCubeMapTextureSize
>> level
) * 2,
383 (kMaxCubeMapTextureSize
>> level
) * 2,
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
,
396 kMaxCubeMapTextureSize
,
397 kMaxRectangleTextureSize
,
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
{
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;
424 : feature_info_(new FeatureInfo()) {
426 ~TextureTestBase() override
{ texture_ref_
= NULL
; }
429 void SetUpBase(MemoryTracker
* memory_tracker
, std::string extensions
) {
430 GpuServiceTest::SetUp();
431 if (!extensions
.empty()) {
432 TestHelper::SetupFeatureInfoInitExpectations(gl_
.get(),
434 feature_info_
->Initialize();
437 manager_
.reset(new TextureManager(memory_tracker
,
440 kMaxCubeMapTextureSize
,
441 kMaxRectangleTextureSize
,
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.
458 DeleteTextures(1, ::testing::Pointee(texture_ref_
->service_id())))
460 .RetiresOnSaturation();
464 manager_
->Destroy(false);
466 GpuServiceTest::TearDown();
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
{
485 void SetUp() override
{ SetUpBase(NULL
, std::string()); }
488 class TextureMemoryTrackerTest
: public TextureTestBase
{
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(), GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 1,
552 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect(1, 1));
553 EXPECT_TRUE(manager_
->CanRender(texture_ref_
.get()));
554 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 0, GL_RGBA
, 0, 0, 1,
555 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect());
556 EXPECT_FALSE(manager_
->CanRender(texture_ref_
.get()));
559 TEST_F(TextureTest
, EstimatedSize
) {
560 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_2D
);
561 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 0, GL_RGBA
, 8, 4, 1,
562 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect(8, 4));
563 EXPECT_EQ(8u * 4u * 4u, texture_ref_
->texture()->estimated_size());
564 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 2, GL_RGBA
, 8, 4, 1,
565 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect(8, 4));
566 EXPECT_EQ(8u * 4u * 4u * 2u, texture_ref_
->texture()->estimated_size());
569 TEST_F(TextureMemoryTrackerTest
, EstimatedSize
) {
570 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_2D
);
571 EXPECT_MEMORY_ALLOCATION_CHANGE(0, 128, MemoryTracker::kUnmanaged
);
572 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 0, GL_RGBA
, 8, 4, 1,
573 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect(8, 4));
574 EXPECT_MEMORY_ALLOCATION_CHANGE(128, 0, MemoryTracker::kUnmanaged
);
575 EXPECT_MEMORY_ALLOCATION_CHANGE(0, 256, MemoryTracker::kUnmanaged
);
576 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 2, GL_RGBA
, 8, 4, 1,
577 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect(8, 4));
578 // Add expectation for texture deletion.
579 EXPECT_MEMORY_ALLOCATION_CHANGE(256, 0, MemoryTracker::kUnmanaged
);
580 EXPECT_MEMORY_ALLOCATION_CHANGE(0, 0, MemoryTracker::kUnmanaged
);
583 TEST_F(TextureMemoryTrackerTest
, SetParameterPool
) {
584 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_2D
);
585 EXPECT_MEMORY_ALLOCATION_CHANGE(0, 128, MemoryTracker::kUnmanaged
);
586 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 0, GL_RGBA
, 8, 4, 1,
587 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect(8, 4));
588 EXPECT_MEMORY_ALLOCATION_CHANGE(128, 0, MemoryTracker::kUnmanaged
);
589 EXPECT_MEMORY_ALLOCATION_CHANGE(0, 128, MemoryTracker::kManaged
);
590 SetParameter(texture_ref_
.get(),
591 GL_TEXTURE_POOL_CHROMIUM
,
592 GL_TEXTURE_POOL_MANAGED_CHROMIUM
,
594 // Add expectation for texture deletion.
595 EXPECT_MEMORY_ALLOCATION_CHANGE(128, 0, MemoryTracker::kManaged
);
596 EXPECT_MEMORY_ALLOCATION_CHANGE(0, 0, MemoryTracker::kUnmanaged
);
597 EXPECT_MEMORY_ALLOCATION_CHANGE(0, 0, MemoryTracker::kManaged
);
600 TEST_F(TextureTest
, POT2D
) {
601 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_2D
);
602 Texture
* texture
= texture_ref_
->texture();
603 EXPECT_EQ(static_cast<GLenum
>(GL_TEXTURE_2D
), texture
->target());
604 // Check Setting level 0 to POT
605 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 0, GL_RGBA
, 4, 4, 1,
606 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect(4, 4));
607 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture
));
608 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture
));
609 EXPECT_FALSE(manager_
->CanRender(texture_ref_
.get()));
610 EXPECT_TRUE(texture
->SafeToRenderFrom());
611 EXPECT_TRUE(manager_
->HaveUnrenderableTextures());
612 // Set filters to something that will work with a single mip.
614 texture_ref_
.get(), GL_TEXTURE_MIN_FILTER
, GL_LINEAR
, GL_NO_ERROR
);
615 EXPECT_TRUE(manager_
->CanRender(texture_ref_
.get()));
616 EXPECT_FALSE(manager_
->HaveUnrenderableTextures());
618 SetParameter(texture_ref_
.get(),
619 GL_TEXTURE_MIN_FILTER
,
620 GL_LINEAR_MIPMAP_LINEAR
,
622 EXPECT_TRUE(manager_
->HaveUnrenderableTextures());
624 EXPECT_TRUE(manager_
->CanGenerateMipmaps(texture_ref_
.get()));
626 EXPECT_TRUE(manager_
->MarkMipmapsGenerated(texture_ref_
.get()));
627 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture
));
628 EXPECT_TRUE(manager_
->CanRender(texture_ref_
.get()));
629 EXPECT_FALSE(manager_
->HaveUnrenderableTextures());
631 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 1, GL_RGBA
, 4, 4, 1,
632 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect(4, 4));
633 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture
));
634 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture
));
635 EXPECT_TRUE(manager_
->CanGenerateMipmaps(texture_ref_
.get()));
636 EXPECT_FALSE(manager_
->CanRender(texture_ref_
.get()));
637 EXPECT_TRUE(manager_
->HaveUnrenderableTextures());
638 // Set a level past the number of mips that would get generated.
639 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 3, GL_RGBA
, 4, 4, 1,
640 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect(4, 4));
641 EXPECT_TRUE(manager_
->CanGenerateMipmaps(texture_ref_
.get()));
643 EXPECT_TRUE(manager_
->MarkMipmapsGenerated(texture_ref_
.get()));
644 EXPECT_TRUE(manager_
->CanRender(texture_ref_
.get()));
645 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture
));
646 EXPECT_FALSE(manager_
->HaveUnrenderableTextures());
649 TEST_F(TextureMemoryTrackerTest
, MarkMipmapsGenerated
) {
650 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_2D
);
651 EXPECT_MEMORY_ALLOCATION_CHANGE(0, 64, MemoryTracker::kUnmanaged
);
652 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 0, GL_RGBA
, 4, 4, 1,
653 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect(4, 4));
654 EXPECT_MEMORY_ALLOCATION_CHANGE(64, 0, MemoryTracker::kUnmanaged
);
655 EXPECT_MEMORY_ALLOCATION_CHANGE(0, 84, MemoryTracker::kUnmanaged
);
656 EXPECT_TRUE(manager_
->MarkMipmapsGenerated(texture_ref_
.get()));
657 EXPECT_MEMORY_ALLOCATION_CHANGE(84, 0, MemoryTracker::kUnmanaged
);
658 EXPECT_MEMORY_ALLOCATION_CHANGE(0, 0, MemoryTracker::kUnmanaged
);
661 TEST_F(TextureTest
, UnusedMips
) {
662 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_2D
);
663 Texture
* texture
= texture_ref_
->texture();
664 EXPECT_EQ(static_cast<GLenum
>(GL_TEXTURE_2D
), texture
->target());
665 // Set level zero to large size.
666 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 0, GL_RGBA
, 4, 4, 1,
667 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect(4, 4));
668 EXPECT_TRUE(manager_
->MarkMipmapsGenerated(texture_ref_
.get()));
669 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture
));
670 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture
));
671 EXPECT_TRUE(manager_
->CanRender(texture_ref_
.get()));
672 EXPECT_FALSE(manager_
->HaveUnrenderableTextures());
673 // Set level zero to large smaller (levels unused mips)
674 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 1,
675 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect(2, 2));
676 EXPECT_TRUE(manager_
->MarkMipmapsGenerated(texture_ref_
.get()));
677 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture
));
678 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture
));
679 EXPECT_TRUE(manager_
->CanRender(texture_ref_
.get()));
680 EXPECT_FALSE(manager_
->HaveUnrenderableTextures());
681 // Set an unused level to some size
682 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 4, GL_RGBA
, 16, 16,
683 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect(16, 16));
684 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture
));
685 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture
));
686 EXPECT_TRUE(manager_
->CanRender(texture_ref_
.get()));
687 EXPECT_FALSE(manager_
->HaveUnrenderableTextures());
690 TEST_F(TextureTest
, NPOT2D
) {
691 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_2D
);
692 Texture
* texture
= texture_ref_
->texture();
693 EXPECT_EQ(static_cast<GLenum
>(GL_TEXTURE_2D
), texture
->target());
694 // Check Setting level 0 to NPOT
695 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 0, GL_RGBA
, 4, 5, 1,
696 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect(4, 5));
697 EXPECT_TRUE(TextureTestHelper::IsNPOT(texture
));
698 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture
));
699 EXPECT_FALSE(manager_
->CanGenerateMipmaps(texture_ref_
.get()));
700 EXPECT_FALSE(manager_
->CanRender(texture_ref_
.get()));
701 EXPECT_TRUE(manager_
->HaveUnrenderableTextures());
703 texture_ref_
.get(), GL_TEXTURE_MIN_FILTER
, GL_LINEAR
, GL_NO_ERROR
);
704 EXPECT_FALSE(manager_
->CanRender(texture_ref_
.get()));
705 EXPECT_TRUE(manager_
->HaveUnrenderableTextures());
707 texture_ref_
.get(), GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
, GL_NO_ERROR
);
708 EXPECT_FALSE(manager_
->CanRender(texture_ref_
.get()));
709 EXPECT_TRUE(manager_
->HaveUnrenderableTextures());
711 texture_ref_
.get(), GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
, GL_NO_ERROR
);
712 EXPECT_TRUE(manager_
->CanRender(texture_ref_
.get()));
713 EXPECT_FALSE(manager_
->HaveUnrenderableTextures());
715 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 0, GL_RGBA
, 4, 4, 1,
716 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect(4, 4));
717 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture
));
718 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture
));
719 EXPECT_TRUE(manager_
->CanGenerateMipmaps(texture_ref_
.get()));
720 EXPECT_FALSE(manager_
->HaveUnrenderableTextures());
723 TEST_F(TextureTest
, NPOT2DNPOTOK
) {
724 TestHelper::SetupFeatureInfoInitExpectations(
725 gl_
.get(), "GL_OES_texture_npot");
726 scoped_refptr
<FeatureInfo
> feature_info(new FeatureInfo());
727 feature_info
->Initialize();
728 TextureManager
manager(NULL
,
731 kMaxCubeMapTextureSize
,
732 kMaxRectangleTextureSize
,
734 kUseDefaultTextures
);
735 manager
.CreateTexture(kClient1Id
, kService1Id
);
736 TextureRef
* texture_ref
= manager
.GetTexture(kClient1Id
);
737 ASSERT_TRUE(texture_ref
!= NULL
);
738 Texture
* texture
= texture_ref
->texture();
740 manager
.SetTarget(texture_ref
, GL_TEXTURE_2D
);
741 EXPECT_EQ(static_cast<GLenum
>(GL_TEXTURE_2D
), texture
->target());
742 // Check Setting level 0 to NPOT
743 manager
.SetLevelInfo(texture_ref
, GL_TEXTURE_2D
, 0, GL_RGBA
, 4, 5, 1, 0,
744 GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect(4, 5));
745 EXPECT_TRUE(TextureTestHelper::IsNPOT(texture
));
746 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture
));
747 EXPECT_TRUE(manager
.CanGenerateMipmaps(texture_ref
));
748 EXPECT_FALSE(manager
.CanRender(texture_ref
));
749 EXPECT_TRUE(manager
.HaveUnrenderableTextures());
750 EXPECT_TRUE(manager
.MarkMipmapsGenerated(texture_ref
));
751 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture
));
752 EXPECT_TRUE(manager
.CanRender(texture_ref
));
753 EXPECT_FALSE(manager
.HaveUnrenderableTextures());
754 manager
.Destroy(false);
757 TEST_F(TextureTest
, POTCubeMap
) {
758 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_CUBE_MAP
);
759 Texture
* texture
= texture_ref_
->texture();
760 EXPECT_EQ(static_cast<GLenum
>(GL_TEXTURE_CUBE_MAP
), texture
->target());
761 // Check Setting level 0 each face to POT
762 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_CUBE_MAP_POSITIVE_X
, 0,
763 GL_RGBA
, 4, 4, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
765 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture
));
766 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture
));
767 EXPECT_FALSE(TextureTestHelper::IsCubeComplete(texture
));
768 EXPECT_FALSE(manager_
->CanGenerateMipmaps(texture_ref_
.get()));
769 EXPECT_FALSE(manager_
->CanRender(texture_ref_
.get()));
770 EXPECT_TRUE(manager_
->HaveUnrenderableTextures());
771 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_CUBE_MAP_NEGATIVE_X
, 0,
772 GL_RGBA
, 4, 4, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
774 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture
));
775 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture
));
776 EXPECT_FALSE(TextureTestHelper::IsCubeComplete(texture
));
777 EXPECT_FALSE(manager_
->CanGenerateMipmaps(texture_ref_
.get()));
778 EXPECT_FALSE(manager_
->CanRender(texture_ref_
.get()));
779 EXPECT_TRUE(manager_
->HaveUnrenderableTextures());
780 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_CUBE_MAP_POSITIVE_Y
, 0,
781 GL_RGBA
, 4, 4, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
783 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture
));
784 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture
));
785 EXPECT_FALSE(TextureTestHelper::IsCubeComplete(texture
));
786 EXPECT_FALSE(manager_
->CanGenerateMipmaps(texture_ref_
.get()));
787 EXPECT_FALSE(manager_
->CanRender(texture_ref_
.get()));
788 EXPECT_TRUE(manager_
->HaveUnrenderableTextures());
789 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
, 0,
790 GL_RGBA
, 4, 4, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
792 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture
));
793 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture
));
794 EXPECT_FALSE(TextureTestHelper::IsCubeComplete(texture
));
795 EXPECT_FALSE(manager_
->CanRender(texture_ref_
.get()));
796 EXPECT_FALSE(manager_
->CanGenerateMipmaps(texture_ref_
.get()));
797 EXPECT_TRUE(manager_
->HaveUnrenderableTextures());
798 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_CUBE_MAP_POSITIVE_Z
, 0,
799 GL_RGBA
, 4, 4, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
801 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture
));
802 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture
));
803 EXPECT_FALSE(TextureTestHelper::IsCubeComplete(texture
));
804 EXPECT_FALSE(manager_
->CanGenerateMipmaps(texture_ref_
.get()));
805 EXPECT_FALSE(manager_
->CanRender(texture_ref_
.get()));
806 EXPECT_TRUE(manager_
->HaveUnrenderableTextures());
807 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
, 0,
808 GL_RGBA
, 4, 4, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
810 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture
));
811 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture
));
812 EXPECT_TRUE(TextureTestHelper::IsCubeComplete(texture
));
813 EXPECT_TRUE(manager_
->CanGenerateMipmaps(texture_ref_
.get()));
814 EXPECT_FALSE(manager_
->CanRender(texture_ref_
.get()));
815 EXPECT_TRUE(manager_
->HaveUnrenderableTextures());
818 EXPECT_TRUE(manager_
->MarkMipmapsGenerated(texture_ref_
.get()));
819 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture
));
820 EXPECT_TRUE(TextureTestHelper::IsCubeComplete(texture
));
821 EXPECT_TRUE(manager_
->CanRender(texture_ref_
.get()));
822 EXPECT_FALSE(manager_
->HaveUnrenderableTextures());
825 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
, 1,
826 GL_RGBA
, 4, 4, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
828 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture
));
829 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture
));
830 EXPECT_TRUE(TextureTestHelper::IsCubeComplete(texture
));
831 EXPECT_TRUE(manager_
->CanGenerateMipmaps(texture_ref_
.get()));
832 // Set a level past the number of mips that would get generated.
833 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
, 3,
834 GL_RGBA
, 4, 4, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
836 EXPECT_TRUE(manager_
->CanGenerateMipmaps(texture_ref_
.get()));
838 EXPECT_TRUE(manager_
->MarkMipmapsGenerated(texture_ref_
.get()));
839 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture
));
840 EXPECT_TRUE(TextureTestHelper::IsCubeComplete(texture
));
843 TEST_F(TextureTest
, GetLevelSize
) {
844 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_3D
);
845 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_3D
, 1, GL_RGBA
, 4, 5, 6,
846 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect(4, 5));
850 Texture
* texture
= texture_ref_
->texture();
852 texture
->GetLevelSize(GL_TEXTURE_3D
, -1, &width
, &height
, &depth
));
854 texture
->GetLevelSize(GL_TEXTURE_3D
, 1000, &width
, &height
, &depth
));
856 texture
->GetLevelSize(GL_TEXTURE_3D
, 0, &width
, &height
, &depth
));
857 EXPECT_TRUE(texture
->GetLevelSize(GL_TEXTURE_3D
, 1, &width
, &height
, &depth
));
859 EXPECT_EQ(5, height
);
861 manager_
->RemoveTexture(kClient1Id
);
862 EXPECT_TRUE(texture
->GetLevelSize(GL_TEXTURE_3D
, 1, &width
, &height
, &depth
));
864 EXPECT_EQ(5, height
);
868 TEST_F(TextureTest
, GetLevelType
) {
869 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_2D
);
870 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 1, GL_RGBA
, 4, 5, 1,
871 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect(4, 5));
874 Texture
* texture
= texture_ref_
->texture();
875 EXPECT_FALSE(texture
->GetLevelType(GL_TEXTURE_2D
, -1, &type
, &format
));
876 EXPECT_FALSE(texture
->GetLevelType(GL_TEXTURE_2D
, 1000, &type
, &format
));
877 EXPECT_FALSE(texture
->GetLevelType(GL_TEXTURE_2D
, 0, &type
, &format
));
878 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 1, &type
, &format
));
879 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
880 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), format
);
881 manager_
->RemoveTexture(kClient1Id
);
882 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 1, &type
, &format
));
883 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
884 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), format
);
887 TEST_F(TextureTest
, ValidForTexture
) {
888 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_2D
);
889 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 1, GL_RGBA
, 4, 5, 6,
890 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect(4, 5));
892 Texture
* texture
= texture_ref_
->texture();
893 EXPECT_FALSE(texture
->ValidForTexture(
894 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
,
895 1, 0, 0, 0, 4, 5, 6, GL_UNSIGNED_BYTE
));
897 EXPECT_FALSE(texture
->ValidForTexture(
898 GL_TEXTURE_2D
, 0, 0, 0, 0, 4, 5, 6, GL_UNSIGNED_BYTE
));
899 // Check bad xoffset.
900 EXPECT_FALSE(texture
->ValidForTexture(
901 GL_TEXTURE_2D
, 1, -1, 0, 0, 4, 5, 6, GL_UNSIGNED_BYTE
));
902 // Check bad xoffset + width > width.
903 EXPECT_FALSE(texture
->ValidForTexture(
904 GL_TEXTURE_2D
, 1, 1, 0, 0, 4, 5, 6, GL_UNSIGNED_BYTE
));
905 // Check bad yoffset.
906 EXPECT_FALSE(texture
->ValidForTexture(
907 GL_TEXTURE_2D
, 1, 0, -1, 0, 4, 5, 6, GL_UNSIGNED_BYTE
));
908 // Check bad yoffset + height > height.
909 EXPECT_FALSE(texture
->ValidForTexture(
910 GL_TEXTURE_2D
, 1, 0, 1, 0, 4, 5, 6, GL_UNSIGNED_BYTE
));
911 // Check bad zoffset.
912 EXPECT_FALSE(texture
->ValidForTexture(
913 GL_TEXTURE_2D
, 1, 0, 0, -1, 4, 5, 6, GL_UNSIGNED_BYTE
));
914 // Check bad zoffset + depth > depth.
915 EXPECT_FALSE(texture
->ValidForTexture(
916 GL_TEXTURE_2D
, 1, 0, 0, 1, 4, 5, 6, GL_UNSIGNED_BYTE
));
918 EXPECT_FALSE(texture
->ValidForTexture(
919 GL_TEXTURE_2D
, 1, 0, 0, 0, 5, 5, 6, GL_UNSIGNED_BYTE
));
921 EXPECT_FALSE(texture
->ValidForTexture(
922 GL_TEXTURE_2D
, 1, 0, 0, 0, 4, 6, 6, GL_UNSIGNED_BYTE
));
924 EXPECT_FALSE(texture
->ValidForTexture(
925 GL_TEXTURE_2D
, 1, 0, 0, 0, 4, 5, 7, GL_UNSIGNED_BYTE
));
927 EXPECT_FALSE(texture
->ValidForTexture(
928 GL_TEXTURE_2D
, 1, 0, 0, 0, 4, 5, 6, GL_UNSIGNED_SHORT_4_4_4_4
));
929 // Check valid full size
930 EXPECT_TRUE(texture
->ValidForTexture(
931 GL_TEXTURE_2D
, 1, 0, 0, 0, 4, 5, 6, GL_UNSIGNED_BYTE
));
932 // Check valid particial size.
933 EXPECT_TRUE(texture
->ValidForTexture(
934 GL_TEXTURE_2D
, 1, 1, 1, 1, 2, 3, 4, GL_UNSIGNED_BYTE
));
935 manager_
->RemoveTexture(kClient1Id
);
936 EXPECT_TRUE(texture
->ValidForTexture(
937 GL_TEXTURE_2D
, 1, 0, 0, 0, 4, 5, 6, GL_UNSIGNED_BYTE
));
940 TEST_F(TextureTest
, FloatNotLinear
) {
941 TestHelper::SetupFeatureInfoInitExpectations(
942 gl_
.get(), "GL_OES_texture_float");
943 scoped_refptr
<FeatureInfo
> feature_info(new FeatureInfo());
944 feature_info
->Initialize();
945 TextureManager
manager(NULL
,
948 kMaxCubeMapTextureSize
,
949 kMaxRectangleTextureSize
,
951 kUseDefaultTextures
);
952 manager
.CreateTexture(kClient1Id
, kService1Id
);
953 TextureRef
* texture_ref
= manager
.GetTexture(kClient1Id
);
954 ASSERT_TRUE(texture_ref
!= NULL
);
955 manager
.SetTarget(texture_ref
, GL_TEXTURE_2D
);
956 Texture
* texture
= texture_ref
->texture();
957 EXPECT_EQ(static_cast<GLenum
>(GL_TEXTURE_2D
), texture
->target());
958 manager
.SetLevelInfo(texture_ref
, GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 1, 0,
959 GL_RGBA
, GL_FLOAT
, gfx::Rect(1, 1));
960 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture
));
961 TestHelper::SetTexParameteriWithExpectations(
962 gl_
.get(), error_state_
.get(), &manager
,
963 texture_ref
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
, GL_NO_ERROR
);
964 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture
));
965 TestHelper::SetTexParameteriWithExpectations(
966 gl_
.get(), error_state_
.get(), &manager
, texture_ref
,
967 GL_TEXTURE_MIN_FILTER
, GL_NEAREST_MIPMAP_NEAREST
, GL_NO_ERROR
);
968 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture
));
969 manager
.Destroy(false);
972 TEST_F(TextureTest
, FloatLinear
) {
973 TestHelper::SetupFeatureInfoInitExpectations(
974 gl_
.get(), "GL_OES_texture_float GL_OES_texture_float_linear");
975 scoped_refptr
<FeatureInfo
> feature_info(new FeatureInfo());
976 feature_info
->Initialize();
977 TextureManager
manager(NULL
,
980 kMaxCubeMapTextureSize
,
981 kMaxRectangleTextureSize
,
983 kUseDefaultTextures
);
984 manager
.CreateTexture(kClient1Id
, kService1Id
);
985 TextureRef
* texture_ref
= manager
.GetTexture(kClient1Id
);
986 ASSERT_TRUE(texture_ref
!= NULL
);
987 manager
.SetTarget(texture_ref
, GL_TEXTURE_2D
);
988 Texture
* texture
= texture_ref
->texture();
989 EXPECT_EQ(static_cast<GLenum
>(GL_TEXTURE_2D
), texture
->target());
990 manager
.SetLevelInfo(texture_ref
, GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 1, 0,
991 GL_RGBA
, GL_FLOAT
, gfx::Rect(1, 1));
992 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture
));
993 manager
.Destroy(false);
996 TEST_F(TextureTest
, HalfFloatNotLinear
) {
997 TestHelper::SetupFeatureInfoInitExpectations(
998 gl_
.get(), "GL_OES_texture_half_float");
999 scoped_refptr
<FeatureInfo
> feature_info(new FeatureInfo());
1000 feature_info
->Initialize();
1001 TextureManager
manager(NULL
,
1004 kMaxCubeMapTextureSize
,
1005 kMaxRectangleTextureSize
,
1007 kUseDefaultTextures
);
1008 manager
.CreateTexture(kClient1Id
, kService1Id
);
1009 TextureRef
* texture_ref
= manager
.GetTexture(kClient1Id
);
1010 ASSERT_TRUE(texture_ref
!= NULL
);
1011 manager
.SetTarget(texture_ref
, GL_TEXTURE_2D
);
1012 Texture
* texture
= texture_ref
->texture();
1013 EXPECT_EQ(static_cast<GLenum
>(GL_TEXTURE_2D
), texture
->target());
1014 manager
.SetLevelInfo(texture_ref
, GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 1, 0,
1015 GL_RGBA
, GL_HALF_FLOAT_OES
, gfx::Rect(1, 1));
1016 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture
));
1017 TestHelper::SetTexParameteriWithExpectations(
1018 gl_
.get(), error_state_
.get(), &manager
,
1019 texture_ref
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
, GL_NO_ERROR
);
1020 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture
));
1021 TestHelper::SetTexParameteriWithExpectations(
1022 gl_
.get(), error_state_
.get(), &manager
, texture_ref
,
1023 GL_TEXTURE_MIN_FILTER
, GL_NEAREST_MIPMAP_NEAREST
, GL_NO_ERROR
);
1024 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture
));
1025 manager
.Destroy(false);
1028 TEST_F(TextureTest
, HalfFloatLinear
) {
1029 TestHelper::SetupFeatureInfoInitExpectations(
1030 gl_
.get(), "GL_OES_texture_half_float GL_OES_texture_half_float_linear");
1031 scoped_refptr
<FeatureInfo
> feature_info(new FeatureInfo());
1032 feature_info
->Initialize();
1033 TextureManager
manager(NULL
,
1036 kMaxCubeMapTextureSize
,
1037 kMaxRectangleTextureSize
,
1039 kUseDefaultTextures
);
1040 manager
.CreateTexture(kClient1Id
, kService1Id
);
1041 TextureRef
* texture_ref
= manager
.GetTexture(kClient1Id
);
1042 ASSERT_TRUE(texture_ref
!= NULL
);
1043 manager
.SetTarget(texture_ref
, GL_TEXTURE_2D
);
1044 Texture
* texture
= texture_ref
->texture();
1045 EXPECT_EQ(static_cast<GLenum
>(GL_TEXTURE_2D
), texture
->target());
1046 manager
.SetLevelInfo(texture_ref
, GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 1, 0,
1047 GL_RGBA
, GL_HALF_FLOAT_OES
, gfx::Rect(1, 1));
1048 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture
));
1049 manager
.Destroy(false);
1052 TEST_F(TextureTest
, EGLImageExternal
) {
1053 TestHelper::SetupFeatureInfoInitExpectations(
1054 gl_
.get(), "GL_OES_EGL_image_external");
1055 scoped_refptr
<FeatureInfo
> feature_info(new FeatureInfo());
1056 feature_info
->Initialize();
1057 TextureManager
manager(NULL
,
1060 kMaxCubeMapTextureSize
,
1061 kMaxRectangleTextureSize
,
1063 kUseDefaultTextures
);
1064 manager
.CreateTexture(kClient1Id
, kService1Id
);
1065 TextureRef
* texture_ref
= manager
.GetTexture(kClient1Id
);
1066 ASSERT_TRUE(texture_ref
!= NULL
);
1067 manager
.SetTarget(texture_ref
, GL_TEXTURE_EXTERNAL_OES
);
1068 Texture
* texture
= texture_ref
->texture();
1069 EXPECT_EQ(static_cast<GLenum
>(GL_TEXTURE_EXTERNAL_OES
), texture
->target());
1070 EXPECT_FALSE(manager
.CanGenerateMipmaps(texture_ref
));
1071 manager
.Destroy(false);
1074 TEST_F(TextureTest
, DepthTexture
) {
1075 TestHelper::SetupFeatureInfoInitExpectations(
1076 gl_
.get(), "GL_ANGLE_depth_texture");
1077 scoped_refptr
<FeatureInfo
> feature_info(new FeatureInfo());
1078 feature_info
->Initialize();
1079 TextureManager
manager(NULL
,
1082 kMaxCubeMapTextureSize
,
1083 kMaxRectangleTextureSize
,
1085 kUseDefaultTextures
);
1086 manager
.CreateTexture(kClient1Id
, kService1Id
);
1087 TextureRef
* texture_ref
= manager
.GetTexture(kClient1Id
);
1088 ASSERT_TRUE(texture_ref
!= NULL
);
1089 manager
.SetTarget(texture_ref
, GL_TEXTURE_2D
);
1090 manager
.SetLevelInfo(texture_ref
, GL_TEXTURE_2D
, 0, GL_DEPTH_COMPONENT
, 4, 4,
1091 1, 0, GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, gfx::Rect());
1092 EXPECT_FALSE(manager
.CanGenerateMipmaps(texture_ref
));
1093 manager
.Destroy(false);
1096 TEST_F(TextureTest
, SafeUnsafe
) {
1097 static const GLuint kClient2Id
= 2;
1098 static const GLuint kService2Id
= 12;
1099 static const GLuint kClient3Id
= 3;
1100 static const GLuint kService3Id
= 13;
1101 EXPECT_FALSE(manager_
->HaveUnclearedMips());
1102 Texture
* texture
= texture_ref_
->texture();
1103 EXPECT_EQ(0, texture
->num_uncleared_mips());
1104 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_2D
);
1105 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 0, GL_RGBA
, 4, 4, 1,
1106 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect());
1107 EXPECT_FALSE(texture
->SafeToRenderFrom());
1108 EXPECT_TRUE(manager_
->HaveUnsafeTextures());
1109 EXPECT_TRUE(manager_
->HaveUnclearedMips());
1110 EXPECT_EQ(1, texture
->num_uncleared_mips());
1111 manager_
->SetLevelCleared(texture_ref_
.get(), GL_TEXTURE_2D
, 0, true);
1112 EXPECT_TRUE(texture
->SafeToRenderFrom());
1113 EXPECT_FALSE(manager_
->HaveUnsafeTextures());
1114 EXPECT_FALSE(manager_
->HaveUnclearedMips());
1115 EXPECT_EQ(0, texture
->num_uncleared_mips());
1116 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 1, GL_RGBA
, 8, 8, 1,
1117 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect());
1118 EXPECT_FALSE(texture
->SafeToRenderFrom());
1119 EXPECT_TRUE(manager_
->HaveUnsafeTextures());
1120 EXPECT_TRUE(manager_
->HaveUnclearedMips());
1121 EXPECT_EQ(1, texture
->num_uncleared_mips());
1122 manager_
->SetLevelCleared(texture_ref_
.get(), GL_TEXTURE_2D
, 1, true);
1123 EXPECT_TRUE(texture
->SafeToRenderFrom());
1124 EXPECT_FALSE(manager_
->HaveUnsafeTextures());
1125 EXPECT_FALSE(manager_
->HaveUnclearedMips());
1126 EXPECT_EQ(0, texture
->num_uncleared_mips());
1127 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 0, GL_RGBA
, 4, 4, 1,
1128 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect());
1129 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 1, GL_RGBA
, 8, 8, 1,
1130 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect());
1131 EXPECT_FALSE(texture
->SafeToRenderFrom());
1132 EXPECT_TRUE(manager_
->HaveUnsafeTextures());
1133 EXPECT_TRUE(manager_
->HaveUnclearedMips());
1134 EXPECT_EQ(2, texture
->num_uncleared_mips());
1135 manager_
->SetLevelCleared(texture_ref_
.get(), GL_TEXTURE_2D
, 0, true);
1136 EXPECT_FALSE(texture
->SafeToRenderFrom());
1137 EXPECT_TRUE(manager_
->HaveUnsafeTextures());
1138 EXPECT_TRUE(manager_
->HaveUnclearedMips());
1139 EXPECT_EQ(1, texture
->num_uncleared_mips());
1140 manager_
->SetLevelCleared(texture_ref_
.get(), GL_TEXTURE_2D
, 1, true);
1141 EXPECT_TRUE(texture
->SafeToRenderFrom());
1142 EXPECT_FALSE(manager_
->HaveUnsafeTextures());
1143 EXPECT_FALSE(manager_
->HaveUnclearedMips());
1144 EXPECT_EQ(0, texture
->num_uncleared_mips());
1145 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 1, GL_RGBA
, 8, 8, 1,
1146 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect());
1147 EXPECT_FALSE(texture
->SafeToRenderFrom());
1148 EXPECT_TRUE(manager_
->HaveUnsafeTextures());
1149 EXPECT_TRUE(manager_
->HaveUnclearedMips());
1150 EXPECT_EQ(1, texture
->num_uncleared_mips());
1151 manager_
->MarkMipmapsGenerated(texture_ref_
.get());
1152 EXPECT_TRUE(texture
->SafeToRenderFrom());
1153 EXPECT_FALSE(manager_
->HaveUnsafeTextures());
1154 EXPECT_FALSE(manager_
->HaveUnclearedMips());
1155 EXPECT_EQ(0, texture
->num_uncleared_mips());
1157 manager_
->CreateTexture(kClient2Id
, kService2Id
);
1158 scoped_refptr
<TextureRef
> texture_ref2(
1159 manager_
->GetTexture(kClient2Id
));
1160 ASSERT_TRUE(texture_ref2
.get() != NULL
);
1161 manager_
->SetTarget(texture_ref2
.get(), GL_TEXTURE_2D
);
1162 EXPECT_FALSE(manager_
->HaveUnsafeTextures());
1163 EXPECT_FALSE(manager_
->HaveUnclearedMips());
1164 Texture
* texture2
= texture_ref2
->texture();
1165 EXPECT_EQ(0, texture2
->num_uncleared_mips());
1166 manager_
->SetLevelInfo(texture_ref2
.get(), GL_TEXTURE_2D
, 0, GL_RGBA
, 8, 8, 1,
1167 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect(8, 8));
1168 EXPECT_FALSE(manager_
->HaveUnsafeTextures());
1169 EXPECT_FALSE(manager_
->HaveUnclearedMips());
1170 EXPECT_EQ(0, texture2
->num_uncleared_mips());
1171 manager_
->SetLevelInfo(texture_ref2
.get(), GL_TEXTURE_2D
, 0, GL_RGBA
, 8, 8, 1,
1172 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect(1, 1));
1173 EXPECT_TRUE(manager_
->HaveUnsafeTextures());
1174 EXPECT_TRUE(manager_
->HaveUnclearedMips());
1175 EXPECT_EQ(1, texture2
->num_uncleared_mips());
1177 manager_
->CreateTexture(kClient3Id
, kService3Id
);
1178 scoped_refptr
<TextureRef
> texture_ref3(
1179 manager_
->GetTexture(kClient3Id
));
1180 ASSERT_TRUE(texture_ref3
.get() != NULL
);
1181 manager_
->SetTarget(texture_ref3
.get(), GL_TEXTURE_2D
);
1182 manager_
->SetLevelInfo(texture_ref3
.get(), GL_TEXTURE_2D
, 0, GL_RGBA
, 8, 8, 1,
1183 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect(2, 2));
1184 EXPECT_TRUE(manager_
->HaveUnsafeTextures());
1185 EXPECT_TRUE(manager_
->HaveUnclearedMips());
1186 Texture
* texture3
= texture_ref3
->texture();
1187 EXPECT_EQ(1, texture3
->num_uncleared_mips());
1188 manager_
->SetLevelCleared(texture_ref2
.get(), GL_TEXTURE_2D
, 0, true);
1189 EXPECT_TRUE(manager_
->HaveUnsafeTextures());
1190 EXPECT_TRUE(manager_
->HaveUnclearedMips());
1191 EXPECT_EQ(0, texture2
->num_uncleared_mips());
1192 manager_
->SetLevelCleared(texture_ref3
.get(), GL_TEXTURE_2D
, 0, true);
1193 EXPECT_FALSE(manager_
->HaveUnsafeTextures());
1194 EXPECT_FALSE(manager_
->HaveUnclearedMips());
1195 EXPECT_EQ(0, texture3
->num_uncleared_mips());
1197 manager_
->SetLevelInfo(texture_ref2
.get(), GL_TEXTURE_2D
, 0, GL_RGBA
, 8, 8, 1,
1198 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect(1, 1, 1, 1));
1199 manager_
->SetLevelInfo(texture_ref3
.get(), GL_TEXTURE_2D
, 0, GL_RGBA
, 8, 8, 1,
1200 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect(4, 4, 4, 4));
1201 EXPECT_TRUE(manager_
->HaveUnsafeTextures());
1202 EXPECT_TRUE(manager_
->HaveUnclearedMips());
1203 EXPECT_EQ(1, texture2
->num_uncleared_mips());
1204 EXPECT_EQ(1, texture3
->num_uncleared_mips());
1205 manager_
->RemoveTexture(kClient3Id
);
1206 EXPECT_TRUE(manager_
->HaveUnsafeTextures());
1207 EXPECT_TRUE(manager_
->HaveUnclearedMips());
1208 manager_
->RemoveTexture(kClient2Id
);
1209 EXPECT_TRUE(manager_
->HaveUnsafeTextures());
1210 EXPECT_TRUE(manager_
->HaveUnclearedMips());
1211 EXPECT_CALL(*gl_
, DeleteTextures(1, ::testing::Pointee(kService2Id
)))
1213 .RetiresOnSaturation();
1214 texture_ref2
= NULL
;
1215 EXPECT_TRUE(manager_
->HaveUnsafeTextures());
1216 EXPECT_TRUE(manager_
->HaveUnclearedMips());
1217 EXPECT_CALL(*gl_
, DeleteTextures(1, ::testing::Pointee(kService3Id
)))
1219 .RetiresOnSaturation();
1220 texture_ref3
= NULL
;
1221 EXPECT_FALSE(manager_
->HaveUnsafeTextures());
1222 EXPECT_FALSE(manager_
->HaveUnclearedMips());
1225 TEST_F(TextureTest
, ClearTexture
) {
1226 EXPECT_CALL(*decoder_
, ClearLevel(_
, _
, _
, _
, _
, _
, _
, _
, _
))
1227 .WillRepeatedly(Return(true));
1228 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_2D
);
1229 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 0, GL_RGBA
, 4, 4, 1,
1230 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect());
1231 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 1, GL_RGBA
, 4, 4, 1,
1232 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect());
1233 Texture
* texture
= texture_ref_
->texture();
1234 EXPECT_FALSE(texture
->SafeToRenderFrom());
1235 EXPECT_TRUE(manager_
->HaveUnsafeTextures());
1236 EXPECT_TRUE(manager_
->HaveUnclearedMips());
1237 EXPECT_EQ(2, texture
->num_uncleared_mips());
1238 manager_
->ClearRenderableLevels(decoder_
.get(), texture_ref_
.get());
1239 EXPECT_TRUE(texture
->SafeToRenderFrom());
1240 EXPECT_FALSE(manager_
->HaveUnsafeTextures());
1241 EXPECT_FALSE(manager_
->HaveUnclearedMips());
1242 EXPECT_EQ(0, texture
->num_uncleared_mips());
1243 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 0, GL_RGBA
, 4, 4, 1,
1244 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect(2, 2));
1245 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 1, GL_RGBA
, 4, 4, 1,
1246 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect(4, 3));
1247 EXPECT_FALSE(texture
->SafeToRenderFrom());
1248 EXPECT_TRUE(manager_
->HaveUnsafeTextures());
1249 EXPECT_TRUE(manager_
->HaveUnclearedMips());
1250 EXPECT_EQ(2, texture
->num_uncleared_mips());
1251 manager_
->ClearTextureLevel(
1252 decoder_
.get(), texture_ref_
.get(), GL_TEXTURE_2D
, 0);
1253 EXPECT_FALSE(texture
->SafeToRenderFrom());
1254 EXPECT_TRUE(manager_
->HaveUnsafeTextures());
1255 EXPECT_TRUE(manager_
->HaveUnclearedMips());
1256 EXPECT_EQ(1, texture
->num_uncleared_mips());
1257 manager_
->ClearTextureLevel(
1258 decoder_
.get(), texture_ref_
.get(), GL_TEXTURE_2D
, 1);
1259 EXPECT_TRUE(texture
->SafeToRenderFrom());
1260 EXPECT_FALSE(manager_
->HaveUnsafeTextures());
1261 EXPECT_FALSE(manager_
->HaveUnclearedMips());
1262 EXPECT_EQ(0, texture
->num_uncleared_mips());
1265 TEST_F(TextureTest
, UseDeletedTexture
) {
1266 static const GLuint kClient2Id
= 2;
1267 static const GLuint kService2Id
= 12;
1268 // Make the default texture renderable
1269 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_2D
);
1270 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 1,
1271 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect());
1272 EXPECT_FALSE(manager_
->HaveUnrenderableTextures());
1273 // Make a new texture
1274 manager_
->CreateTexture(kClient2Id
, kService2Id
);
1275 scoped_refptr
<TextureRef
> texture_ref(
1276 manager_
->GetTexture(kClient2Id
));
1277 manager_
->SetTarget(texture_ref
.get(), GL_TEXTURE_2D
);
1278 EXPECT_FALSE(manager_
->CanRender(texture_ref
.get()));
1279 EXPECT_TRUE(manager_
->HaveUnrenderableTextures());
1281 manager_
->RemoveTexture(kClient2Id
);
1282 EXPECT_FALSE(manager_
->CanRender(texture_ref
.get()));
1283 EXPECT_TRUE(manager_
->HaveUnrenderableTextures());
1284 // Check that we can still manipulate it and it effects the manager.
1285 manager_
->SetLevelInfo(texture_ref
.get(), GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 1,
1286 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect());
1287 EXPECT_TRUE(manager_
->CanRender(texture_ref
.get()));
1288 EXPECT_FALSE(manager_
->HaveUnrenderableTextures());
1289 EXPECT_CALL(*gl_
, DeleteTextures(1, ::testing::Pointee(kService2Id
)))
1291 .RetiresOnSaturation();
1295 TEST_F(TextureTest
, GetLevelImage
) {
1296 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_2D
);
1297 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 1, GL_RGBA
, 2, 2, 1,
1298 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect(2, 2));
1299 Texture
* texture
= texture_ref_
->texture();
1300 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 1) == NULL
);
1302 scoped_refptr
<gfx::GLImage
> image(new gfx::GLImageStub
);
1303 manager_
->SetLevelImage(texture_ref_
.get(), GL_TEXTURE_2D
, 1, image
.get());
1304 EXPECT_FALSE(texture
->GetLevelImage(GL_TEXTURE_2D
, 1) == NULL
);
1306 manager_
->SetLevelImage(texture_ref_
.get(), GL_TEXTURE_2D
, 1, NULL
);
1307 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 1) == NULL
);
1308 manager_
->SetLevelImage(texture_ref_
.get(), GL_TEXTURE_2D
, 1, image
.get());
1309 // Image should be reset when SetLevelInfo is called.
1310 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 1, GL_RGBA
, 2, 2, 1,
1311 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect(2, 2));
1312 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 1) == NULL
);
1317 bool InSet(std::set
<std::string
>* string_set
, const std::string
& str
) {
1318 std::pair
<std::set
<std::string
>::iterator
, bool> result
=
1319 string_set
->insert(str
);
1320 return !result
.second
;
1323 } // anonymous namespace
1325 TEST_F(TextureTest
, AddToSignature
) {
1326 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_2D
);
1327 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 1, GL_RGBA
, 2, 2, 1,
1328 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect(2, 2));
1329 std::string signature1
;
1330 std::string signature2
;
1331 manager_
->AddToSignature(texture_ref_
.get(), GL_TEXTURE_2D
, 1, &signature1
);
1333 std::set
<std::string
> string_set
;
1334 EXPECT_FALSE(InSet(&string_set
, signature1
));
1336 // check changing 1 thing makes a different signature.
1337 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 1, GL_RGBA
, 4, 2, 1,
1338 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect(4, 2));
1339 manager_
->AddToSignature(texture_ref_
.get(), GL_TEXTURE_2D
, 1, &signature2
);
1340 EXPECT_FALSE(InSet(&string_set
, signature2
));
1342 // check putting it back makes the same signature.
1343 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 1, GL_RGBA
, 2, 2, 1,
1344 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect(2, 2));
1346 manager_
->AddToSignature(texture_ref_
.get(), GL_TEXTURE_2D
, 1, &signature2
);
1347 EXPECT_EQ(signature1
, signature2
);
1349 // Check setting cleared status does not change signature.
1350 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 1, GL_RGBA
, 2, 2, 1,
1351 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect());
1353 manager_
->AddToSignature(texture_ref_
.get(), GL_TEXTURE_2D
, 1, &signature2
);
1354 EXPECT_EQ(signature1
, signature2
);
1356 // Check changing other settings changes signature.
1357 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 1, GL_RGBA
, 2, 4, 1,
1358 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect());
1360 manager_
->AddToSignature(texture_ref_
.get(), GL_TEXTURE_2D
, 1, &signature2
);
1361 EXPECT_FALSE(InSet(&string_set
, signature2
));
1363 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 1, GL_RGBA
, 2, 2, 2,
1364 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect());
1366 manager_
->AddToSignature(texture_ref_
.get(), GL_TEXTURE_2D
, 1, &signature2
);
1367 EXPECT_FALSE(InSet(&string_set
, signature2
));
1369 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 1, GL_RGBA
, 2, 2, 1,
1370 1, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect());
1372 manager_
->AddToSignature(texture_ref_
.get(), GL_TEXTURE_2D
, 1, &signature2
);
1373 EXPECT_FALSE(InSet(&string_set
, signature2
));
1375 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 1, GL_RGBA
, 2, 2, 1,
1376 0, GL_RGB
, GL_UNSIGNED_BYTE
, gfx::Rect());
1378 manager_
->AddToSignature(texture_ref_
.get(), GL_TEXTURE_2D
, 1, &signature2
);
1379 EXPECT_FALSE(InSet(&string_set
, signature2
));
1381 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 1, GL_RGBA
, 2, 2, 1,
1382 0, GL_RGBA
, GL_FLOAT
, gfx::Rect());
1384 manager_
->AddToSignature(texture_ref_
.get(), GL_TEXTURE_2D
, 1, &signature2
);
1385 EXPECT_FALSE(InSet(&string_set
, signature2
));
1388 manager_
->SetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 1, GL_RGBA
, 2, 2, 1,
1389 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect());
1391 manager_
->AddToSignature(texture_ref_
.get(), GL_TEXTURE_2D
, 1, &signature2
);
1392 EXPECT_EQ(signature1
, signature2
);
1394 // check changing parameters changes signature.
1396 texture_ref_
.get(), GL_TEXTURE_MIN_FILTER
, GL_NEAREST
, GL_NO_ERROR
);
1398 manager_
->AddToSignature(texture_ref_
.get(), GL_TEXTURE_2D
, 1, &signature2
);
1399 EXPECT_FALSE(InSet(&string_set
, signature2
));
1401 SetParameter(texture_ref_
.get(),
1402 GL_TEXTURE_MIN_FILTER
,
1403 GL_NEAREST_MIPMAP_LINEAR
,
1406 texture_ref_
.get(), GL_TEXTURE_MAG_FILTER
, GL_NEAREST
, GL_NO_ERROR
);
1408 manager_
->AddToSignature(texture_ref_
.get(), GL_TEXTURE_2D
, 1, &signature2
);
1409 EXPECT_FALSE(InSet(&string_set
, signature2
));
1412 texture_ref_
.get(), GL_TEXTURE_MAG_FILTER
, GL_LINEAR
, GL_NO_ERROR
);
1414 texture_ref_
.get(), GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
, GL_NO_ERROR
);
1416 manager_
->AddToSignature(texture_ref_
.get(), GL_TEXTURE_2D
, 1, &signature2
);
1417 EXPECT_FALSE(InSet(&string_set
, signature2
));
1419 SetParameter(texture_ref_
.get(), GL_TEXTURE_WRAP_S
, GL_REPEAT
, GL_NO_ERROR
);
1421 texture_ref_
.get(), GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
, GL_NO_ERROR
);
1423 manager_
->AddToSignature(texture_ref_
.get(), GL_TEXTURE_2D
, 1, &signature2
);
1424 EXPECT_FALSE(InSet(&string_set
, signature2
));
1426 // Check putting it back genenerates the same signature
1427 SetParameter(texture_ref_
.get(), GL_TEXTURE_WRAP_T
, GL_REPEAT
, GL_NO_ERROR
);
1429 manager_
->AddToSignature(texture_ref_
.get(), GL_TEXTURE_2D
, 1, &signature2
);
1430 EXPECT_EQ(signature1
, signature2
);
1432 // Check the set was acutally getting different signatures.
1433 EXPECT_EQ(11u, string_set
.size());
1436 class ProduceConsumeTextureTest
: public TextureTest
,
1437 public ::testing::WithParamInterface
<GLenum
> {
1439 void SetUp() override
{
1440 TextureTest::SetUpBase(NULL
, "GL_OES_EGL_image_external");
1441 manager_
->CreateTexture(kClient2Id
, kService2Id
);
1442 texture2_
= manager_
->GetTexture(kClient2Id
);
1444 EXPECT_CALL(*decoder_
.get(), GetErrorState())
1445 .WillRepeatedly(Return(error_state_
.get()));
1448 void TearDown() override
{
1449 if (texture2_
.get()) {
1450 // If it's not in the manager then setting texture2_ to NULL will
1451 // delete the texture.
1452 if (!texture2_
->client_id()) {
1453 // Check that it gets deleted when the last reference is released.
1456 DeleteTextures(1, ::testing::Pointee(texture2_
->service_id())))
1457 .Times(1).RetiresOnSaturation();
1461 TextureTest::TearDown();
1466 LevelInfo(GLenum target
,
1473 const gfx::Rect
& cleared_rect
)
1481 cleared_rect(cleared_rect
) {}
1492 bool operator==(const LevelInfo
& other
) const {
1493 return target
== other
.target
&& format
== other
.format
&&
1494 width
== other
.width
&& height
== other
.height
&&
1495 depth
== other
.depth
&& border
== other
.border
&&
1496 type
== other
.type
&& cleared_rect
== other
.cleared_rect
;
1506 gfx::Rect cleared_rect
;
1509 void SetLevelInfo(TextureRef
* texture_ref
,
1511 const LevelInfo
& info
) {
1512 manager_
->SetLevelInfo(texture_ref
, info
.target
, level
, info
.format
,
1513 info
.width
, info
.height
, info
.depth
, info
.border
,
1514 info
.format
, info
.type
, info
.cleared_rect
);
1517 static LevelInfo
GetLevelInfo(const TextureRef
* texture_ref
,
1520 const Texture
* texture
= texture_ref
->texture();
1522 info
.target
= target
;
1523 EXPECT_TRUE(texture
->GetLevelSize(target
, level
, &info
.width
,
1524 &info
.height
, &info
.depth
));
1525 EXPECT_TRUE(texture
->GetLevelType(target
, level
, &info
.type
,
1527 info
.cleared_rect
= texture
->GetLevelClearedRect(target
, level
);
1531 Texture
* Produce(TextureRef
* texture_ref
) {
1532 Texture
* texture
= manager_
->Produce(texture_ref
);
1533 EXPECT_TRUE(texture
!= NULL
);
1537 void Consume(GLuint client_id
, Texture
* texture
) {
1538 EXPECT_TRUE(manager_
->Consume(client_id
, texture
));
1541 scoped_refptr
<TextureRef
> texture2_
;
1544 static const GLuint kClient2Id
;
1545 static const GLuint kService2Id
;
1548 const GLuint
ProduceConsumeTextureTest::kClient2Id
= 2;
1549 const GLuint
ProduceConsumeTextureTest::kService2Id
= 12;
1551 TEST_F(ProduceConsumeTextureTest
, ProduceConsume2D
) {
1552 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_2D
);
1553 Texture
* texture
= texture_ref_
->texture();
1554 EXPECT_EQ(static_cast<GLenum
>(GL_TEXTURE_2D
), texture
->target());
1555 LevelInfo
level0(GL_TEXTURE_2D
, GL_RGBA
, 4, 4, 1, 0, GL_UNSIGNED_BYTE
,
1557 SetLevelInfo(texture_ref_
.get(), 0, level0
);
1558 EXPECT_TRUE(manager_
->MarkMipmapsGenerated(texture_ref_
.get()));
1559 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture
));
1560 LevelInfo level1
= GetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 1);
1561 LevelInfo level2
= GetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 2);
1562 Texture
* produced_texture
= Produce(texture_ref_
.get());
1563 EXPECT_EQ(produced_texture
, texture
);
1565 // Make this texture bigger with more levels, and make sure they get
1566 // clobbered correctly during Consume().
1567 manager_
->SetTarget(texture2_
.get(), GL_TEXTURE_2D
);
1568 SetLevelInfo(texture2_
.get(), 0, LevelInfo(GL_TEXTURE_2D
, GL_RGBA
, 16, 16, 1,
1569 0, GL_UNSIGNED_BYTE
, gfx::Rect()));
1570 EXPECT_TRUE(manager_
->MarkMipmapsGenerated(texture2_
.get()));
1571 texture
= texture2_
->texture();
1572 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture
));
1573 EXPECT_EQ(1024U + 256U + 64U + 16U + 4U, texture
->estimated_size());
1575 GLuint client_id
= texture2_
->client_id();
1576 manager_
->RemoveTexture(client_id
);
1577 Consume(client_id
, produced_texture
);
1578 scoped_refptr
<TextureRef
> restored_texture
= manager_
->GetTexture(client_id
);
1579 EXPECT_EQ(produced_texture
, restored_texture
->texture());
1580 EXPECT_EQ(level0
, GetLevelInfo(restored_texture
.get(), GL_TEXTURE_2D
, 0));
1581 EXPECT_EQ(level1
, GetLevelInfo(restored_texture
.get(), GL_TEXTURE_2D
, 1));
1582 EXPECT_EQ(level2
, GetLevelInfo(restored_texture
.get(), GL_TEXTURE_2D
, 2));
1583 texture
= restored_texture
->texture();
1584 EXPECT_EQ(64U + 16U + 4U, texture
->estimated_size());
1586 EXPECT_FALSE(texture
->GetLevelSize(GL_TEXTURE_2D
, 3, &w
, &h
, nullptr));
1588 // However the old texture ref still exists if it was referenced somewhere.
1589 EXPECT_EQ(1024U + 256U + 64U + 16U + 4U,
1590 texture2_
->texture()->estimated_size());
1593 TEST_F(ProduceConsumeTextureTest
, ProduceConsumeClearRectangle
) {
1594 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_RECTANGLE_ARB
);
1595 Texture
* texture
= texture_ref_
->texture();
1596 EXPECT_EQ(static_cast<GLenum
>(GL_TEXTURE_RECTANGLE_ARB
), texture
->target());
1597 LevelInfo
level0(GL_TEXTURE_RECTANGLE_ARB
, GL_RGBA
, 1, 1, 1, 0,
1598 GL_UNSIGNED_BYTE
, gfx::Rect());
1599 SetLevelInfo(texture_ref_
.get(), 0, level0
);
1600 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture
));
1601 Texture
* produced_texture
= Produce(texture_ref_
.get());
1602 EXPECT_EQ(produced_texture
, texture
);
1603 EXPECT_EQ(static_cast<GLenum
>(GL_TEXTURE_RECTANGLE_ARB
),
1604 produced_texture
->target());
1606 GLuint client_id
= texture2_
->client_id();
1607 manager_
->RemoveTexture(client_id
);
1608 Consume(client_id
, produced_texture
);
1609 scoped_refptr
<TextureRef
> restored_texture
= manager_
->GetTexture(client_id
);
1610 EXPECT_EQ(produced_texture
, restored_texture
->texture());
1612 // See if we can clear the previously uncleared level now.
1614 GetLevelInfo(restored_texture
.get(), GL_TEXTURE_RECTANGLE_ARB
, 0));
1615 EXPECT_CALL(*decoder_
, ClearLevel(_
, _
, _
, _
, _
, _
, _
, _
, _
))
1616 .WillRepeatedly(Return(true));
1617 EXPECT_TRUE(manager_
->ClearTextureLevel(
1618 decoder_
.get(), restored_texture
.get(), GL_TEXTURE_RECTANGLE_ARB
, 0));
1621 TEST_F(ProduceConsumeTextureTest
, ProduceConsumeExternal
) {
1622 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_EXTERNAL_OES
);
1623 Texture
* texture
= texture_ref_
->texture();
1624 EXPECT_EQ(static_cast<GLenum
>(GL_TEXTURE_EXTERNAL_OES
), texture
->target());
1625 LevelInfo
level0(GL_TEXTURE_EXTERNAL_OES
, GL_RGBA
, 1, 1, 1, 0,
1626 GL_UNSIGNED_BYTE
, gfx::Rect());
1627 SetLevelInfo(texture_ref_
.get(), 0, level0
);
1628 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture
));
1629 Texture
* produced_texture
= Produce(texture_ref_
.get());
1630 EXPECT_EQ(produced_texture
, texture
);
1632 GLuint client_id
= texture2_
->client_id();
1633 manager_
->RemoveTexture(client_id
);
1634 Consume(client_id
, produced_texture
);
1635 scoped_refptr
<TextureRef
> restored_texture
= manager_
->GetTexture(client_id
);
1636 EXPECT_EQ(produced_texture
, restored_texture
->texture());
1638 GetLevelInfo(restored_texture
.get(), GL_TEXTURE_EXTERNAL_OES
, 0));
1641 TEST_P(ProduceConsumeTextureTest
, ProduceConsumeTextureWithImage
) {
1642 GLenum target
= GetParam();
1643 manager_
->SetTarget(texture_ref_
.get(), target
);
1644 Texture
* texture
= texture_ref_
->texture();
1645 EXPECT_EQ(static_cast<GLenum
>(target
), texture
->target());
1646 scoped_refptr
<gfx::GLImage
> image(new gfx::GLImageStub
);
1647 manager_
->SetLevelInfo(texture_ref_
.get(), target
, 0, GL_RGBA
, 0, 0, 1, 0,
1648 GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect());
1649 manager_
->SetLevelImage(texture_ref_
.get(), target
, 0, image
.get());
1650 GLuint service_id
= texture
->service_id();
1651 Texture
* produced_texture
= Produce(texture_ref_
.get());
1653 GLuint client_id
= texture2_
->client_id();
1654 manager_
->RemoveTexture(client_id
);
1655 Consume(client_id
, produced_texture
);
1656 scoped_refptr
<TextureRef
> restored_texture
= manager_
->GetTexture(client_id
);
1657 EXPECT_EQ(produced_texture
, restored_texture
->texture());
1658 EXPECT_EQ(service_id
, restored_texture
->service_id());
1659 EXPECT_EQ(image
.get(), restored_texture
->texture()->GetLevelImage(target
, 0));
1662 static const GLenum kTextureTargets
[] = {GL_TEXTURE_2D
, GL_TEXTURE_EXTERNAL_OES
,
1663 GL_TEXTURE_RECTANGLE_ARB
, };
1665 INSTANTIATE_TEST_CASE_P(Target
,
1666 ProduceConsumeTextureTest
,
1667 ::testing::ValuesIn(kTextureTargets
));
1669 TEST_F(ProduceConsumeTextureTest
, ProduceConsumeCube
) {
1670 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_CUBE_MAP
);
1671 Texture
* texture
= texture_ref_
->texture();
1672 EXPECT_EQ(static_cast<GLenum
>(GL_TEXTURE_CUBE_MAP
), texture
->target());
1673 LevelInfo
face0(GL_TEXTURE_CUBE_MAP_POSITIVE_X
, GL_RGBA
, 1, 1, 1, 0,
1674 GL_UNSIGNED_BYTE
, gfx::Rect(1, 1));
1675 LevelInfo
face5(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
, GL_RGBA
, 3, 3, 1, 0,
1676 GL_UNSIGNED_BYTE
, gfx::Rect(1, 1));
1677 SetLevelInfo(texture_ref_
.get(), 0, face0
);
1678 SetLevelInfo(texture_ref_
.get(), 0, face5
);
1679 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture
));
1680 Texture
* produced_texture
= Produce(texture_ref_
.get());
1681 EXPECT_EQ(produced_texture
, texture
);
1683 GLuint client_id
= texture2_
->client_id();
1684 manager_
->RemoveTexture(client_id
);
1685 Consume(client_id
, produced_texture
);
1686 scoped_refptr
<TextureRef
> restored_texture
= manager_
->GetTexture(client_id
);
1687 EXPECT_EQ(produced_texture
, restored_texture
->texture());
1690 GetLevelInfo(restored_texture
.get(), GL_TEXTURE_CUBE_MAP_POSITIVE_X
, 0));
1693 GetLevelInfo(restored_texture
.get(), GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
, 0));
1696 class CountingMemoryTracker
: public MemoryTracker
{
1698 CountingMemoryTracker() {
1699 current_size_
[0] = 0;
1700 current_size_
[1] = 0;
1703 void TrackMemoryAllocatedChange(size_t old_size
,
1705 Pool pool
) override
{
1706 DCHECK_LT(static_cast<size_t>(pool
), arraysize(current_size_
));
1707 current_size_
[pool
] += new_size
- old_size
;
1710 bool EnsureGPUMemoryAvailable(size_t size_needed
) override
{ return true; }
1712 size_t GetSize(Pool pool
) {
1713 DCHECK_LT(static_cast<size_t>(pool
), arraysize(current_size_
));
1714 return current_size_
[pool
];
1718 ~CountingMemoryTracker() override
{}
1720 size_t current_size_
[2];
1721 DISALLOW_COPY_AND_ASSIGN(CountingMemoryTracker
);
1724 class SharedTextureTest
: public GpuServiceTest
{
1726 static const bool kUseDefaultTextures
= false;
1728 SharedTextureTest() : feature_info_(new FeatureInfo()) {}
1730 ~SharedTextureTest() override
{}
1732 void SetUp() override
{
1733 GpuServiceTest::SetUp();
1734 memory_tracker1_
= new CountingMemoryTracker
;
1735 texture_manager1_
.reset(
1736 new TextureManager(memory_tracker1_
.get(),
1737 feature_info_
.get(),
1738 TextureManagerTest::kMaxTextureSize
,
1739 TextureManagerTest::kMaxCubeMapTextureSize
,
1740 TextureManagerTest::kMaxRectangleTextureSize
,
1741 TextureManagerTest::kMax3DTextureSize
,
1742 kUseDefaultTextures
));
1743 memory_tracker2_
= new CountingMemoryTracker
;
1744 texture_manager2_
.reset(
1745 new TextureManager(memory_tracker2_
.get(),
1746 feature_info_
.get(),
1747 TextureManagerTest::kMaxTextureSize
,
1748 TextureManagerTest::kMaxCubeMapTextureSize
,
1749 TextureManagerTest::kMaxRectangleTextureSize
,
1750 TextureManagerTest::kMax3DTextureSize
,
1751 kUseDefaultTextures
));
1752 TestHelper::SetupTextureManagerInitExpectations(
1753 gl_
.get(), "", kUseDefaultTextures
);
1754 texture_manager1_
->Initialize();
1755 TestHelper::SetupTextureManagerInitExpectations(
1756 gl_
.get(), "", kUseDefaultTextures
);
1757 texture_manager2_
->Initialize();
1760 void TearDown() override
{
1761 texture_manager2_
->Destroy(false);
1762 texture_manager2_
.reset();
1763 texture_manager1_
->Destroy(false);
1764 texture_manager1_
.reset();
1765 GpuServiceTest::TearDown();
1769 scoped_refptr
<FeatureInfo
> feature_info_
;
1770 scoped_refptr
<CountingMemoryTracker
> memory_tracker1_
;
1771 scoped_ptr
<TextureManager
> texture_manager1_
;
1772 scoped_refptr
<CountingMemoryTracker
> memory_tracker2_
;
1773 scoped_ptr
<TextureManager
> texture_manager2_
;
1776 TEST_F(SharedTextureTest
, DeleteTextures
) {
1777 scoped_refptr
<TextureRef
> ref1
= texture_manager1_
->CreateTexture(10, 10);
1778 scoped_refptr
<TextureRef
> ref2
=
1779 texture_manager2_
->Consume(20, ref1
->texture());
1780 EXPECT_CALL(*gl_
, DeleteTextures(1, _
))
1783 texture_manager1_
->RemoveTexture(10);
1784 testing::Mock::VerifyAndClearExpectations(gl_
.get());
1786 EXPECT_CALL(*gl_
, DeleteTextures(1, _
))
1788 .RetiresOnSaturation();
1790 texture_manager2_
->RemoveTexture(20);
1791 testing::Mock::VerifyAndClearExpectations(gl_
.get());
1794 TEST_F(SharedTextureTest
, TextureSafetyAccounting
) {
1795 EXPECT_FALSE(texture_manager1_
->HaveUnrenderableTextures());
1796 EXPECT_FALSE(texture_manager1_
->HaveUnsafeTextures());
1797 EXPECT_FALSE(texture_manager1_
->HaveUnclearedMips());
1798 EXPECT_FALSE(texture_manager2_
->HaveUnrenderableTextures());
1799 EXPECT_FALSE(texture_manager2_
->HaveUnsafeTextures());
1800 EXPECT_FALSE(texture_manager2_
->HaveUnclearedMips());
1802 // Newly created texture is renderable.
1803 scoped_refptr
<TextureRef
> ref1
= texture_manager1_
->CreateTexture(10, 10);
1804 EXPECT_FALSE(texture_manager1_
->HaveUnrenderableTextures());
1805 EXPECT_FALSE(texture_manager1_
->HaveUnsafeTextures());
1806 EXPECT_FALSE(texture_manager1_
->HaveUnclearedMips());
1808 // Associate new texture ref to other texture manager, should account for it
1810 scoped_refptr
<TextureRef
> ref2
=
1811 texture_manager2_
->Consume(20, ref1
->texture());
1812 EXPECT_FALSE(texture_manager2_
->HaveUnrenderableTextures());
1813 EXPECT_FALSE(texture_manager2_
->HaveUnsafeTextures());
1814 EXPECT_FALSE(texture_manager2_
->HaveUnclearedMips());
1816 // Make texture renderable but uncleared on one texture manager, should affect
1818 texture_manager1_
->SetTarget(ref1
.get(), GL_TEXTURE_2D
);
1819 EXPECT_TRUE(texture_manager1_
->HaveUnrenderableTextures());
1820 EXPECT_FALSE(texture_manager1_
->HaveUnsafeTextures());
1821 EXPECT_FALSE(texture_manager1_
->HaveUnclearedMips());
1822 EXPECT_TRUE(texture_manager2_
->HaveUnrenderableTextures());
1823 EXPECT_FALSE(texture_manager2_
->HaveUnsafeTextures());
1824 EXPECT_FALSE(texture_manager2_
->HaveUnclearedMips());
1826 texture_manager1_
->SetLevelInfo(ref1
.get(), GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1,
1827 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect());
1828 EXPECT_FALSE(texture_manager1_
->HaveUnrenderableTextures());
1829 EXPECT_TRUE(texture_manager1_
->HaveUnsafeTextures());
1830 EXPECT_TRUE(texture_manager1_
->HaveUnclearedMips());
1831 EXPECT_FALSE(texture_manager2_
->HaveUnrenderableTextures());
1832 EXPECT_TRUE(texture_manager2_
->HaveUnsafeTextures());
1833 EXPECT_TRUE(texture_manager2_
->HaveUnclearedMips());
1835 // Make texture cleared on one texture manager, should affect other one.
1836 texture_manager1_
->SetLevelCleared(ref1
.get(), GL_TEXTURE_2D
, 0, true);
1837 EXPECT_FALSE(texture_manager1_
->HaveUnsafeTextures());
1838 EXPECT_FALSE(texture_manager1_
->HaveUnclearedMips());
1839 EXPECT_FALSE(texture_manager2_
->HaveUnsafeTextures());
1840 EXPECT_FALSE(texture_manager2_
->HaveUnclearedMips());
1842 EXPECT_CALL(*gl_
, DeleteTextures(1, _
))
1844 .RetiresOnSaturation();
1845 texture_manager1_
->RemoveTexture(10);
1846 texture_manager2_
->RemoveTexture(20);
1849 TEST_F(SharedTextureTest
, FBOCompletenessCheck
) {
1850 const GLenum kCompleteValue
= GL_FRAMEBUFFER_COMPLETE
;
1851 FramebufferManager
framebuffer_manager1(
1852 1, 1, ContextGroup::CONTEXT_TYPE_UNDEFINED
);
1853 texture_manager1_
->set_framebuffer_manager(&framebuffer_manager1
);
1854 FramebufferManager
framebuffer_manager2(
1855 1, 1, ContextGroup::CONTEXT_TYPE_UNDEFINED
);
1856 texture_manager2_
->set_framebuffer_manager(&framebuffer_manager2
);
1858 scoped_refptr
<TextureRef
> ref1
= texture_manager1_
->CreateTexture(10, 10);
1859 framebuffer_manager1
.CreateFramebuffer(10, 10);
1860 scoped_refptr
<Framebuffer
> framebuffer1
=
1861 framebuffer_manager1
.GetFramebuffer(10);
1862 framebuffer1
->AttachTexture(
1863 GL_COLOR_ATTACHMENT0
, ref1
.get(), GL_TEXTURE_2D
, 0, 0);
1864 EXPECT_FALSE(framebuffer_manager1
.IsComplete(framebuffer1
.get()));
1865 EXPECT_NE(kCompleteValue
, framebuffer1
->IsPossiblyComplete());
1867 // Make FBO complete in manager 1.
1868 texture_manager1_
->SetTarget(ref1
.get(), GL_TEXTURE_2D
);
1869 texture_manager1_
->SetLevelInfo(ref1
.get(), GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1,
1870 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
1872 EXPECT_EQ(kCompleteValue
, framebuffer1
->IsPossiblyComplete());
1873 framebuffer_manager1
.MarkAsComplete(framebuffer1
.get());
1874 EXPECT_TRUE(framebuffer_manager1
.IsComplete(framebuffer1
.get()));
1876 // Share texture with manager 2.
1877 scoped_refptr
<TextureRef
> ref2
=
1878 texture_manager2_
->Consume(20, ref1
->texture());
1879 framebuffer_manager2
.CreateFramebuffer(20, 20);
1880 scoped_refptr
<Framebuffer
> framebuffer2
=
1881 framebuffer_manager2
.GetFramebuffer(20);
1882 framebuffer2
->AttachTexture(
1883 GL_COLOR_ATTACHMENT0
, ref2
.get(), GL_TEXTURE_2D
, 0, 0);
1884 EXPECT_FALSE(framebuffer_manager2
.IsComplete(framebuffer2
.get()));
1885 EXPECT_EQ(kCompleteValue
, framebuffer2
->IsPossiblyComplete());
1886 framebuffer_manager2
.MarkAsComplete(framebuffer2
.get());
1887 EXPECT_TRUE(framebuffer_manager2
.IsComplete(framebuffer2
.get()));
1889 // Change level for texture, both FBOs should be marked incomplete
1890 texture_manager1_
->SetLevelInfo(ref1
.get(), GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1,
1891 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
1893 EXPECT_FALSE(framebuffer_manager1
.IsComplete(framebuffer1
.get()));
1894 EXPECT_EQ(kCompleteValue
, framebuffer1
->IsPossiblyComplete());
1895 framebuffer_manager1
.MarkAsComplete(framebuffer1
.get());
1896 EXPECT_TRUE(framebuffer_manager1
.IsComplete(framebuffer1
.get()));
1897 EXPECT_FALSE(framebuffer_manager2
.IsComplete(framebuffer2
.get()));
1898 EXPECT_EQ(kCompleteValue
, framebuffer2
->IsPossiblyComplete());
1899 framebuffer_manager2
.MarkAsComplete(framebuffer2
.get());
1900 EXPECT_TRUE(framebuffer_manager2
.IsComplete(framebuffer2
.get()));
1902 EXPECT_CALL(*gl_
, DeleteFramebuffersEXT(1, _
))
1904 .RetiresOnSaturation();
1905 framebuffer_manager1
.RemoveFramebuffer(10);
1906 framebuffer_manager2
.RemoveFramebuffer(20);
1907 EXPECT_CALL(*gl_
, DeleteTextures(1, _
))
1909 .RetiresOnSaturation();
1910 texture_manager1_
->RemoveTexture(10);
1911 texture_manager2_
->RemoveTexture(20);
1914 TEST_F(SharedTextureTest
, Memory
) {
1915 size_t initial_memory1
= memory_tracker1_
->GetSize(MemoryTracker::kUnmanaged
);
1916 size_t initial_memory2
= memory_tracker2_
->GetSize(MemoryTracker::kUnmanaged
);
1918 // Newly created texture is unrenderable.
1919 scoped_refptr
<TextureRef
> ref1
= texture_manager1_
->CreateTexture(10, 10);
1920 texture_manager1_
->SetTarget(ref1
.get(), GL_TEXTURE_2D
);
1921 texture_manager1_
->SetLevelInfo(ref1
.get(), GL_TEXTURE_2D
, 0, GL_RGBA
, 10, 10,
1922 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, gfx::Rect());
1924 EXPECT_LT(0u, ref1
->texture()->estimated_size());
1925 EXPECT_EQ(initial_memory1
+ ref1
->texture()->estimated_size(),
1926 memory_tracker1_
->GetSize(MemoryTracker::kUnmanaged
));
1928 // Associate new texture ref to other texture manager, it doesn't account for
1929 // the texture memory, the first memory tracker still has it.
1930 scoped_refptr
<TextureRef
> ref2
=
1931 texture_manager2_
->Consume(20, ref1
->texture());
1932 EXPECT_EQ(initial_memory1
+ ref1
->texture()->estimated_size(),
1933 memory_tracker1_
->GetSize(MemoryTracker::kUnmanaged
));
1934 EXPECT_EQ(initial_memory2
,
1935 memory_tracker2_
->GetSize(MemoryTracker::kUnmanaged
));
1937 // Delete the texture, memory should go to the remaining tracker.
1938 texture_manager1_
->RemoveTexture(10);
1940 EXPECT_EQ(initial_memory1
,
1941 memory_tracker1_
->GetSize(MemoryTracker::kUnmanaged
));
1942 EXPECT_EQ(initial_memory2
+ ref2
->texture()->estimated_size(),
1943 memory_tracker2_
->GetSize(MemoryTracker::kUnmanaged
));
1945 EXPECT_CALL(*gl_
, DeleteTextures(1, _
))
1947 .RetiresOnSaturation();
1949 texture_manager2_
->RemoveTexture(20);
1950 EXPECT_EQ(initial_memory2
,
1951 memory_tracker2_
->GetSize(MemoryTracker::kUnmanaged
));
1954 TEST_F(SharedTextureTest
, Images
) {
1955 scoped_refptr
<TextureRef
> ref1
= texture_manager1_
->CreateTexture(10, 10);
1956 scoped_refptr
<TextureRef
> ref2
=
1957 texture_manager2_
->Consume(20, ref1
->texture());
1959 texture_manager1_
->SetTarget(ref1
.get(), GL_TEXTURE_2D
);
1960 texture_manager1_
->SetLevelInfo(ref1
.get(), GL_TEXTURE_2D
, 1, GL_RGBA
, 2, 2,
1961 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
1963 EXPECT_FALSE(ref1
->texture()->HasImages());
1964 EXPECT_FALSE(ref2
->texture()->HasImages());
1965 EXPECT_FALSE(texture_manager1_
->HaveImages());
1966 EXPECT_FALSE(texture_manager2_
->HaveImages());
1967 scoped_refptr
<gfx::GLImage
> image1(new gfx::GLImageStub
);
1968 texture_manager1_
->SetLevelImage(ref1
.get(), GL_TEXTURE_2D
, 1, image1
.get());
1969 EXPECT_TRUE(ref1
->texture()->HasImages());
1970 EXPECT_TRUE(ref2
->texture()->HasImages());
1971 EXPECT_TRUE(texture_manager1_
->HaveImages());
1972 EXPECT_TRUE(texture_manager2_
->HaveImages());
1973 scoped_refptr
<gfx::GLImage
> image2(new gfx::GLImageStub
);
1974 texture_manager1_
->SetLevelImage(ref1
.get(), GL_TEXTURE_2D
, 1, image2
.get());
1975 EXPECT_TRUE(ref1
->texture()->HasImages());
1976 EXPECT_TRUE(ref2
->texture()->HasImages());
1977 EXPECT_TRUE(texture_manager1_
->HaveImages());
1978 EXPECT_TRUE(texture_manager2_
->HaveImages());
1979 texture_manager1_
->SetLevelInfo(ref1
.get(), GL_TEXTURE_2D
, 1, GL_RGBA
, 2, 2,
1980 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
1982 EXPECT_FALSE(ref1
->texture()->HasImages());
1983 EXPECT_FALSE(ref2
->texture()->HasImages());
1984 EXPECT_FALSE(texture_manager1_
->HaveImages());
1985 EXPECT_FALSE(texture_manager1_
->HaveImages());
1987 EXPECT_CALL(*gl_
, DeleteTextures(1, _
))
1989 .RetiresOnSaturation();
1990 texture_manager1_
->RemoveTexture(10);
1991 texture_manager2_
->RemoveTexture(20);
1995 class TextureFormatTypeValidationTest
: public TextureManagerTest
{
1997 TextureFormatTypeValidationTest() {}
1998 ~TextureFormatTypeValidationTest() override
{}
2001 void SetupFeatureInfo(const char* gl_extensions
, const char* gl_version
) {
2002 TestHelper::SetupFeatureInfoInitExpectationsWithGLVersion(
2003 gl_
.get(), gl_extensions
, "", gl_version
);
2004 feature_info_
->Initialize();
2007 void ExpectValid(GLenum format
, GLenum type
, GLenum internal_format
) {
2008 EXPECT_TRUE(manager_
->ValidateTextureParameters(
2009 error_state_
.get(), "", format
, type
, internal_format
, 0));
2012 void ExpectInvalid(GLenum format
, GLenum type
, GLenum internal_format
) {
2013 EXPECT_CALL(*error_state_
,
2014 SetGLError(_
, _
, _
, _
, _
))
2016 .RetiresOnSaturation();
2017 EXPECT_FALSE(manager_
->ValidateTextureParameters(
2018 error_state_
.get(), "", format
, type
, internal_format
, 0));
2021 void ExpectInvalidEnum(GLenum format
, GLenum type
, GLenum internal_format
) {
2022 EXPECT_CALL(*error_state_
,
2023 SetGLErrorInvalidEnum(_
, _
, _
, _
, _
))
2025 .RetiresOnSaturation();
2026 EXPECT_FALSE(manager_
->ValidateTextureParameters(
2027 error_state_
.get(), "", format
, type
, internal_format
, 0));
2031 TEST_F(TextureFormatTypeValidationTest
, ES2Basic
) {
2032 SetupFeatureInfo("", "OpenGL ES 2.0");
2034 ExpectValid(GL_ALPHA
, GL_UNSIGNED_BYTE
, GL_ALPHA
);
2035 ExpectValid(GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
, GL_RGB
);
2036 ExpectValid(GL_RGBA
, GL_UNSIGNED_SHORT_4_4_4_4
, GL_RGBA
);
2037 ExpectValid(GL_LUMINANCE
, GL_UNSIGNED_BYTE
, GL_LUMINANCE
);
2038 ExpectValid(GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, GL_LUMINANCE_ALPHA
);
2040 ExpectInvalid(GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, GL_ALPHA
);
2042 // float / half_float.
2043 ExpectInvalidEnum(GL_RGBA
, GL_FLOAT
, GL_RGBA
);
2044 ExpectInvalidEnum(GL_RGBA
, GL_HALF_FLOAT_OES
, GL_RGBA
);
2047 ExpectInvalidEnum(GL_BGRA_EXT
, GL_UNSIGNED_BYTE
, GL_BGRA_EXT
);
2050 ExpectInvalidEnum(GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, GL_DEPTH_COMPONENT
);
2051 ExpectInvalidEnum(GL_DEPTH_STENCIL
, GL_UNSIGNED_INT_24_8
, GL_DEPTH_STENCIL
);
2054 ExpectInvalidEnum(GL_SRGB_EXT
, GL_UNSIGNED_BYTE
, GL_SRGB_EXT
);
2055 ExpectInvalidEnum(GL_SRGB_ALPHA_EXT
, GL_UNSIGNED_BYTE
, GL_SRGB_ALPHA_EXT
);
2058 ExpectInvalidEnum(GL_RGB
, GL_UNSIGNED_BYTE
, GL_RGB8
);
2061 TEST_F(TextureFormatTypeValidationTest
, ES2WithExtBGRA
) {
2062 SetupFeatureInfo("GL_EXT_bgra", "OpenGL ES 2.0");
2064 ExpectValid(GL_BGRA_EXT
, GL_UNSIGNED_BYTE
, GL_BGRA_EXT
);
2067 TEST_F(TextureFormatTypeValidationTest
, ES2WithExtTextureFormatBGRA8888
) {
2068 SetupFeatureInfo("GL_EXT_texture_format_BGRA8888", "OpenGL ES 2.0");
2070 ExpectValid(GL_BGRA_EXT
, GL_UNSIGNED_BYTE
, GL_BGRA_EXT
);
2073 TEST_F(TextureFormatTypeValidationTest
, ES2WithAppleTextureFormatBGRA8888
) {
2074 SetupFeatureInfo("GL_APPLE_texture_format_BGRA8888", "OpenGL ES 2.0");
2076 ExpectValid(GL_BGRA_EXT
, GL_UNSIGNED_BYTE
, GL_BGRA_EXT
);
2079 TEST_F(TextureFormatTypeValidationTest
, ES2WithArbDepth
) {
2080 SetupFeatureInfo("GL_ARB_depth_texture", "OpenGL ES 2.0");
2082 ExpectValid(GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, GL_DEPTH_COMPONENT
);
2083 ExpectValid(GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, GL_DEPTH_COMPONENT
);
2084 ExpectInvalidEnum(GL_DEPTH_STENCIL
, GL_UNSIGNED_INT_24_8
, GL_DEPTH_STENCIL
);
2087 TEST_F(TextureFormatTypeValidationTest
, ES2WithOesDepth
) {
2088 SetupFeatureInfo("GL_OES_depth_texture", "OpenGL ES 2.0");
2090 ExpectValid(GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, GL_DEPTH_COMPONENT
);
2091 ExpectValid(GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, GL_DEPTH_COMPONENT
);
2092 ExpectInvalidEnum(GL_DEPTH_STENCIL
, GL_UNSIGNED_INT_24_8
, GL_DEPTH_STENCIL
);
2095 TEST_F(TextureFormatTypeValidationTest
, ES2WithAngleDepth
) {
2096 SetupFeatureInfo("GL_ANGLE_depth_texture", "OpenGL ES 2.0");
2098 ExpectValid(GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, GL_DEPTH_COMPONENT
);
2099 ExpectValid(GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, GL_DEPTH_COMPONENT
);
2100 ExpectInvalidEnum(GL_DEPTH_STENCIL
, GL_UNSIGNED_INT_24_8
, GL_DEPTH_STENCIL
);
2103 TEST_F(TextureFormatTypeValidationTest
, ES2WithExtPackedDepthStencil
) {
2105 "GL_EXT_packed_depth_stencil GL_ARB_depth_texture", "OpenGL ES 2.0");
2107 ExpectValid(GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, GL_DEPTH_COMPONENT
);
2108 ExpectValid(GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, GL_DEPTH_COMPONENT
);
2109 ExpectValid(GL_DEPTH_STENCIL
, GL_UNSIGNED_INT_24_8
, GL_DEPTH_STENCIL
);
2112 TEST_F(TextureFormatTypeValidationTest
, ES2WithRGWithFloat
) {
2114 "GL_EXT_texture_rg GL_OES_texture_float GL_OES_texture_half_float",
2117 ExpectValid(GL_RED_EXT
, GL_HALF_FLOAT_OES
, GL_RED_EXT
);
2118 ExpectValid(GL_RG_EXT
, GL_HALF_FLOAT_OES
, GL_RG_EXT
);
2119 ExpectValid(GL_RED_EXT
, GL_UNSIGNED_BYTE
, GL_RED_EXT
);
2120 ExpectValid(GL_RG_EXT
, GL_UNSIGNED_BYTE
, GL_RG_EXT
);
2122 ExpectInvalidEnum(GL_RED_EXT
, GL_BYTE
, GL_RED_EXT
);
2123 ExpectInvalidEnum(GL_RG_EXT
, GL_BYTE
, GL_RG_EXT
);
2124 ExpectInvalidEnum(GL_RED_EXT
, GL_SHORT
, GL_RED_EXT
);
2125 ExpectInvalidEnum(GL_RG_EXT
, GL_SHORT
, GL_RG_EXT
);
2128 TEST_F(TextureFormatTypeValidationTest
, ES2WithRGNoFloat
) {
2129 SetupFeatureInfo("GL_ARB_texture_rg", "OpenGL ES 2.0");
2131 ExpectValid(GL_RED_EXT
, GL_UNSIGNED_BYTE
, GL_RED_EXT
);
2132 ExpectValid(GL_RG_EXT
, GL_UNSIGNED_BYTE
, GL_RG_EXT
);
2134 ExpectInvalidEnum(GL_RED_EXT
, GL_HALF_FLOAT_OES
, GL_RED_EXT
);
2135 ExpectInvalidEnum(GL_RG_EXT
, GL_HALF_FLOAT_OES
, GL_RG_EXT
);
2138 TEST_F(TextureFormatTypeValidationTest
, ES2OnTopOfES3
) {
2139 SetupFeatureInfo("", "OpenGL ES 3.0");
2141 ExpectInvalidEnum(GL_RGB
, GL_FLOAT
, GL_RGB
);
2142 ExpectInvalidEnum(GL_RGBA
, GL_FLOAT
, GL_RGBA
);
2143 ExpectInvalidEnum(GL_LUMINANCE
, GL_FLOAT
, GL_LUMINANCE
);
2144 ExpectInvalidEnum(GL_LUMINANCE_ALPHA
, GL_FLOAT
, GL_LUMINANCE_ALPHA
);
2145 ExpectInvalidEnum(GL_ALPHA
, GL_FLOAT
, GL_ALPHA
);
2147 ExpectInvalidEnum(GL_SRGB_EXT
, GL_UNSIGNED_BYTE
, GL_SRGB_EXT
);
2148 ExpectInvalidEnum(GL_SRGB_ALPHA_EXT
, GL_UNSIGNED_BYTE
, GL_SRGB_ALPHA_EXT
);
2151 TEST_F(TextureFormatTypeValidationTest
, ES2WithOesTextureFloat
) {
2152 SetupFeatureInfo("GL_OES_texture_float", "OpenGL ES 2.0");
2154 ExpectValid(GL_RGB
, GL_FLOAT
, GL_RGB
);
2155 ExpectValid(GL_RGBA
, GL_FLOAT
, GL_RGBA
);
2156 ExpectValid(GL_LUMINANCE
, GL_FLOAT
, GL_LUMINANCE
);
2157 ExpectValid(GL_LUMINANCE_ALPHA
, GL_FLOAT
, GL_LUMINANCE_ALPHA
);
2158 ExpectValid(GL_ALPHA
, GL_FLOAT
, GL_ALPHA
);
2160 ExpectInvalidEnum(GL_RGB
, GL_HALF_FLOAT_OES
, GL_RGB
);
2161 ExpectInvalidEnum(GL_RGBA
, GL_HALF_FLOAT_OES
, GL_RGBA
);
2162 ExpectInvalidEnum(GL_LUMINANCE
, GL_HALF_FLOAT_OES
, GL_LUMINANCE
);
2163 ExpectInvalidEnum(GL_LUMINANCE_ALPHA
, GL_HALF_FLOAT_OES
, GL_LUMINANCE_ALPHA
);
2164 ExpectInvalidEnum(GL_ALPHA
, GL_HALF_FLOAT_OES
, GL_ALPHA
);
2167 TEST_F(TextureFormatTypeValidationTest
, ES2WithOesTextureFloatLinear
) {
2169 "GL_OES_texture_float GL_OES_texture_float_linear", "OpenGL ES 2.0");
2171 ExpectValid(GL_RGB
, GL_FLOAT
, GL_RGB
);
2172 ExpectValid(GL_RGBA
, GL_FLOAT
, GL_RGBA
);
2173 ExpectValid(GL_LUMINANCE
, GL_FLOAT
, GL_LUMINANCE
);
2174 ExpectValid(GL_LUMINANCE_ALPHA
, GL_FLOAT
, GL_LUMINANCE_ALPHA
);
2175 ExpectValid(GL_ALPHA
, GL_FLOAT
, GL_ALPHA
);
2177 ExpectInvalidEnum(GL_RGB
, GL_HALF_FLOAT_OES
, GL_RGB
);
2178 ExpectInvalidEnum(GL_RGBA
, GL_HALF_FLOAT_OES
, GL_RGBA
);
2179 ExpectInvalidEnum(GL_LUMINANCE
, GL_HALF_FLOAT_OES
, GL_LUMINANCE
);
2180 ExpectInvalidEnum(GL_LUMINANCE_ALPHA
, GL_HALF_FLOAT_OES
, GL_LUMINANCE_ALPHA
);
2181 ExpectInvalidEnum(GL_ALPHA
, GL_HALF_FLOAT_OES
, GL_ALPHA
);
2184 TEST_F(TextureFormatTypeValidationTest
, ES2WithOesTextureHalfFloat
) {
2185 SetupFeatureInfo("GL_OES_texture_half_float", "OpenGL ES 2.0");
2187 ExpectValid(GL_RGB
, GL_HALF_FLOAT_OES
, GL_RGB
);
2188 ExpectValid(GL_RGBA
, GL_HALF_FLOAT_OES
, GL_RGBA
);
2189 ExpectValid(GL_LUMINANCE
, GL_HALF_FLOAT_OES
, GL_LUMINANCE
);
2190 ExpectValid(GL_LUMINANCE_ALPHA
, GL_HALF_FLOAT_OES
, GL_LUMINANCE_ALPHA
);
2191 ExpectValid(GL_ALPHA
, GL_HALF_FLOAT_OES
, GL_ALPHA
);
2193 ExpectInvalidEnum(GL_RGB
, GL_FLOAT
, GL_RGB
);
2194 ExpectInvalidEnum(GL_RGBA
, GL_FLOAT
, GL_RGBA
);
2195 ExpectInvalidEnum(GL_LUMINANCE
, GL_FLOAT
, GL_LUMINANCE
);
2196 ExpectInvalidEnum(GL_LUMINANCE_ALPHA
, GL_FLOAT
, GL_LUMINANCE_ALPHA
);
2197 ExpectInvalidEnum(GL_ALPHA
, GL_FLOAT
, GL_ALPHA
);
2200 TEST_F(TextureFormatTypeValidationTest
, ES2WithOesTextureHalfFloatLinear
) {
2202 "GL_OES_texture_half_float GL_OES_texture_half_float_linear",
2205 ExpectValid(GL_RGB
, GL_HALF_FLOAT_OES
, GL_RGB
);
2206 ExpectValid(GL_RGBA
, GL_HALF_FLOAT_OES
, GL_RGBA
);
2207 ExpectValid(GL_LUMINANCE
, GL_HALF_FLOAT_OES
, GL_LUMINANCE
);
2208 ExpectValid(GL_LUMINANCE_ALPHA
, GL_HALF_FLOAT_OES
, GL_LUMINANCE_ALPHA
);
2209 ExpectValid(GL_ALPHA
, GL_HALF_FLOAT_OES
, GL_ALPHA
);
2211 ExpectInvalidEnum(GL_RGB
, GL_FLOAT
, GL_RGB
);
2212 ExpectInvalidEnum(GL_RGBA
, GL_FLOAT
, GL_RGBA
);
2213 ExpectInvalidEnum(GL_LUMINANCE
, GL_FLOAT
, GL_LUMINANCE
);
2214 ExpectInvalidEnum(GL_LUMINANCE_ALPHA
, GL_FLOAT
, GL_LUMINANCE_ALPHA
);
2215 ExpectInvalidEnum(GL_ALPHA
, GL_FLOAT
, GL_ALPHA
);
2218 TEST_F(TextureFormatTypeValidationTest
, ES3Basic
) {
2219 SetupFeatureInfo("", "OpenGL ES 3.0");
2220 EXPECT_CALL(*gl_
, GetIntegerv(GL_MAX_COLOR_ATTACHMENTS
, _
))
2221 .WillOnce(SetArgPointee
<1>(8))
2222 .RetiresOnSaturation();
2223 EXPECT_CALL(*gl_
, GetIntegerv(GL_MAX_DRAW_BUFFERS
, _
))
2224 .WillOnce(SetArgPointee
<1>(8))
2225 .RetiresOnSaturation();
2226 feature_info_
->EnableES3Validators();
2228 ExpectValid(GL_ALPHA
, GL_UNSIGNED_BYTE
, GL_ALPHA
);
2229 ExpectValid(GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
, GL_RGB
);
2230 ExpectValid(GL_RGBA
, GL_UNSIGNED_SHORT_4_4_4_4
, GL_RGBA
);
2231 ExpectValid(GL_LUMINANCE
, GL_UNSIGNED_BYTE
, GL_LUMINANCE
);
2232 ExpectValid(GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, GL_LUMINANCE_ALPHA
);
2234 ExpectValid(GL_RG
, GL_BYTE
, GL_RG8_SNORM
);
2235 ExpectValid(GL_RG_INTEGER
, GL_UNSIGNED_INT
, GL_RG32UI
);
2236 ExpectValid(GL_RG_INTEGER
, GL_SHORT
, GL_RG16I
);
2237 ExpectValid(GL_RGB
, GL_UNSIGNED_BYTE
, GL_SRGB8
);
2238 ExpectValid(GL_RGBA
, GL_HALF_FLOAT
, GL_RGBA16F
);
2239 ExpectValid(GL_RGBA
, GL_FLOAT
, GL_RGBA16F
);
2240 ExpectValid(GL_RGBA
, GL_FLOAT
, GL_RGBA32F
);
2242 ExpectValid(GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, GL_DEPTH_COMPONENT16
);
2243 ExpectValid(GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, GL_DEPTH_COMPONENT24
);
2244 ExpectValid(GL_DEPTH_COMPONENT
, GL_FLOAT
, GL_DEPTH_COMPONENT32F
);
2245 ExpectValid(GL_DEPTH_STENCIL
, GL_UNSIGNED_INT_24_8
, GL_DEPTH24_STENCIL8
);
2246 ExpectValid(GL_DEPTH_STENCIL
, GL_FLOAT_32_UNSIGNED_INT_24_8_REV
,
2247 GL_DEPTH32F_STENCIL8
);
2249 ExpectInvalid(GL_RGB_INTEGER
, GL_INT
, GL_RGBA8
);
2252 } // namespace gles2