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/memory/scoped_ptr.h"
10 #include "gpu/command_buffer/service/error_state_mock.h"
11 #include "gpu/command_buffer/service/feature_info.h"
12 #include "gpu/command_buffer/service/framebuffer_manager.h"
13 #include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h"
14 #include "gpu/command_buffer/service/gpu_service_test.h"
15 #include "gpu/command_buffer/service/mailbox_manager.h"
16 #include "gpu/command_buffer/service/memory_tracking.h"
17 #include "gpu/command_buffer/service/mocks.h"
18 #include "gpu/command_buffer/service/test_helper.h"
19 #include "testing/gtest/include/gtest/gtest.h"
20 #include "ui/gl/gl_image_stub.h"
21 #include "ui/gl/gl_mock.h"
23 using ::testing::AtLeast
;
24 using ::testing::Pointee
;
25 using ::testing::Return
;
26 using ::testing::SetArgumentPointee
;
27 using ::testing::StrictMock
;
33 class TextureTestHelper
{
35 static bool IsNPOT(const Texture
* texture
) {
36 return texture
->npot();
38 static bool IsTextureComplete(const Texture
* texture
) {
39 return texture
->texture_complete();
41 static bool IsCubeComplete(const Texture
* texture
) {
42 return texture
->cube_complete();
46 class TextureManagerTest
: public GpuServiceTest
{
48 static const GLint kMaxTextureSize
= 16;
49 static const GLint kMaxCubeMapTextureSize
= 8;
50 static const GLint kMaxExternalTextureSize
= 16;
51 static const GLint kMax2dLevels
= 5;
52 static const GLint kMaxCubeMapLevels
= 4;
53 static const GLint kMaxExternalLevels
= 1;
54 static const bool kUseDefaultTextures
= false;
56 TextureManagerTest() : feature_info_(new FeatureInfo()) {}
58 virtual ~TextureManagerTest() {
62 virtual void SetUp() {
63 GpuServiceTest::SetUp();
64 manager_
.reset(new TextureManager(NULL
,
67 kMaxCubeMapTextureSize
,
68 kUseDefaultTextures
));
69 TestHelper::SetupTextureManagerInitExpectations(
70 gl_
.get(), "", kUseDefaultTextures
);
71 manager_
->Initialize();
72 error_state_
.reset(new ::testing::StrictMock
<gles2::MockErrorState
>());
75 virtual void TearDown() {
76 manager_
->Destroy(false);
78 GpuServiceTest::TearDown();
82 TextureRef
* texture_ref
, GLenum pname
, GLint value
, GLenum error
) {
83 TestHelper::SetTexParameteriWithExpectations(
84 gl_
.get(), error_state_
.get(), manager_
.get(),
85 texture_ref
, pname
, value
, error
);
88 scoped_refptr
<FeatureInfo
> feature_info_
;
89 scoped_ptr
<TextureManager
> manager_
;
90 scoped_ptr
<MockErrorState
> error_state_
;
93 // GCC requires these declarations, but MSVC requires they not be present
95 const GLint
TextureManagerTest::kMaxTextureSize
;
96 const GLint
TextureManagerTest::kMaxCubeMapTextureSize
;
97 const GLint
TextureManagerTest::kMaxExternalTextureSize
;
98 const GLint
TextureManagerTest::kMax2dLevels
;
99 const GLint
TextureManagerTest::kMaxCubeMapLevels
;
100 const GLint
TextureManagerTest::kMaxExternalLevels
;
103 TEST_F(TextureManagerTest
, Basic
) {
104 const GLuint kClient1Id
= 1;
105 const GLuint kService1Id
= 11;
106 const GLuint kClient2Id
= 2;
107 EXPECT_FALSE(manager_
->HaveUnrenderableTextures());
108 EXPECT_FALSE(manager_
->HaveUnsafeTextures());
109 EXPECT_FALSE(manager_
->HaveUnclearedMips());
110 // Check we can create texture.
111 manager_
->CreateTexture(kClient1Id
, kService1Id
);
112 // Check texture got created.
113 scoped_refptr
<TextureRef
> texture
= manager_
->GetTexture(kClient1Id
);
114 ASSERT_TRUE(texture
.get() != NULL
);
115 EXPECT_EQ(kService1Id
, texture
->service_id());
116 EXPECT_EQ(kClient1Id
, texture
->client_id());
117 EXPECT_EQ(texture
->texture(), manager_
->GetTextureForServiceId(
118 texture
->service_id()));
119 // Check we get nothing for a non-existent texture.
120 EXPECT_TRUE(manager_
->GetTexture(kClient2Id
) == NULL
);
121 // Check trying to a remove non-existent textures does not crash.
122 manager_
->RemoveTexture(kClient2Id
);
123 // Check that it gets deleted when the last reference is released.
124 EXPECT_CALL(*gl_
, DeleteTextures(1, ::testing::Pointee(kService1Id
)))
126 .RetiresOnSaturation();
127 // Check we can't get the texture after we remove it.
128 manager_
->RemoveTexture(kClient1Id
);
129 EXPECT_TRUE(manager_
->GetTexture(kClient1Id
) == NULL
);
130 EXPECT_EQ(0u, texture
->client_id());
133 TEST_F(TextureManagerTest
, SetParameter
) {
134 const GLuint kClient1Id
= 1;
135 const GLuint kService1Id
= 11;
136 // Check we can create texture.
137 manager_
->CreateTexture(kClient1Id
, kService1Id
);
138 // Check texture got created.
139 TextureRef
* texture_ref
= manager_
->GetTexture(kClient1Id
);
140 ASSERT_TRUE(texture_ref
!= NULL
);
141 Texture
* texture
= texture_ref
->texture();
142 manager_
->SetTarget(texture_ref
, GL_TEXTURE_2D
);
143 SetParameter(texture_ref
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
, GL_NO_ERROR
);
144 EXPECT_EQ(static_cast<GLenum
>(GL_NEAREST
), texture
->min_filter());
145 SetParameter(texture_ref
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
, GL_NO_ERROR
);
146 EXPECT_EQ(static_cast<GLenum
>(GL_NEAREST
), texture
->mag_filter());
147 SetParameter(texture_ref
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
, GL_NO_ERROR
);
148 EXPECT_EQ(static_cast<GLenum
>(GL_CLAMP_TO_EDGE
), texture
->wrap_s());
149 SetParameter(texture_ref
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
, GL_NO_ERROR
);
150 EXPECT_EQ(static_cast<GLenum
>(GL_CLAMP_TO_EDGE
), texture
->wrap_t());
151 SetParameter(texture_ref
, GL_TEXTURE_MAX_ANISOTROPY_EXT
, 1, GL_NO_ERROR
);
152 SetParameter(texture_ref
, GL_TEXTURE_MAX_ANISOTROPY_EXT
, 2, GL_NO_ERROR
);
154 texture_ref
, GL_TEXTURE_MIN_FILTER
, GL_CLAMP_TO_EDGE
, GL_INVALID_ENUM
);
155 EXPECT_EQ(static_cast<GLenum
>(GL_NEAREST
), texture
->min_filter());
157 texture_ref
, GL_TEXTURE_MAG_FILTER
, GL_CLAMP_TO_EDGE
, GL_INVALID_ENUM
);
158 EXPECT_EQ(static_cast<GLenum
>(GL_NEAREST
), texture
->min_filter());
159 SetParameter(texture_ref
, GL_TEXTURE_WRAP_S
, GL_NEAREST
, GL_INVALID_ENUM
);
160 EXPECT_EQ(static_cast<GLenum
>(GL_CLAMP_TO_EDGE
), texture
->wrap_s());
161 SetParameter(texture_ref
, GL_TEXTURE_WRAP_T
, GL_NEAREST
, GL_INVALID_ENUM
);
162 EXPECT_EQ(static_cast<GLenum
>(GL_CLAMP_TO_EDGE
), texture
->wrap_t());
163 SetParameter(texture_ref
, GL_TEXTURE_MAX_ANISOTROPY_EXT
, 0, GL_INVALID_VALUE
);
166 TEST_F(TextureManagerTest
, UseDefaultTexturesTrue
) {
167 bool use_default_textures
= true;
168 scoped_refptr
<FeatureInfo
> feature_info(new FeatureInfo());
170 TestHelper::SetupTextureManagerInitExpectations(
171 gl_
.get(), "GL_ANGLE_texture_usage", use_default_textures
);
172 TextureManager
manager(NULL
,
175 kMaxCubeMapTextureSize
,
176 use_default_textures
);
177 manager
.Initialize();
179 EXPECT_TRUE(manager
.GetDefaultTextureInfo(GL_TEXTURE_2D
) != NULL
);
180 EXPECT_TRUE(manager
.GetDefaultTextureInfo(GL_TEXTURE_CUBE_MAP
) != NULL
);
182 // TODO(vmiura): Test GL_TEXTURE_EXTERNAL_OES & GL_TEXTURE_RECTANGLE_ARB.
184 manager
.Destroy(false);
187 TEST_F(TextureManagerTest
, UseDefaultTexturesFalse
) {
188 bool use_default_textures
= false;
189 TestHelper::SetupTextureManagerInitExpectations(
190 gl_
.get(), "GL_ANGLE_texture_usage", use_default_textures
);
191 TextureManager
manager(NULL
,
194 kMaxCubeMapTextureSize
,
195 use_default_textures
);
196 manager
.Initialize();
198 EXPECT_TRUE(manager
.GetDefaultTextureInfo(GL_TEXTURE_2D
) == NULL
);
199 EXPECT_TRUE(manager
.GetDefaultTextureInfo(GL_TEXTURE_CUBE_MAP
) == NULL
);
201 // TODO(vmiura): Test GL_TEXTURE_EXTERNAL_OES & GL_TEXTURE_RECTANGLE_ARB.
203 manager
.Destroy(false);
206 TEST_F(TextureManagerTest
, TextureUsageExt
) {
207 TestHelper::SetupTextureManagerInitExpectations(
208 gl_
.get(), "GL_ANGLE_texture_usage", kUseDefaultTextures
);
209 TextureManager
manager(NULL
,
212 kMaxCubeMapTextureSize
,
213 kUseDefaultTextures
);
214 manager
.Initialize();
215 const GLuint kClient1Id
= 1;
216 const GLuint kService1Id
= 11;
217 // Check we can create texture.
218 manager
.CreateTexture(kClient1Id
, kService1Id
);
219 // Check texture got created.
220 TextureRef
* texture_ref
= manager
.GetTexture(kClient1Id
);
221 ASSERT_TRUE(texture_ref
!= NULL
);
222 TestHelper::SetTexParameteriWithExpectations(
223 gl_
.get(), error_state_
.get(), &manager
, texture_ref
,
224 GL_TEXTURE_USAGE_ANGLE
, GL_FRAMEBUFFER_ATTACHMENT_ANGLE
, GL_NO_ERROR
);
225 EXPECT_EQ(static_cast<GLenum
>(GL_FRAMEBUFFER_ATTACHMENT_ANGLE
),
226 texture_ref
->texture()->usage());
227 manager
.Destroy(false);
230 TEST_F(TextureManagerTest
, Destroy
) {
231 const GLuint kClient1Id
= 1;
232 const GLuint kService1Id
= 11;
233 TestHelper::SetupTextureManagerInitExpectations(
234 gl_
.get(), "", kUseDefaultTextures
);
235 TextureManager
manager(NULL
,
238 kMaxCubeMapTextureSize
,
239 kUseDefaultTextures
);
240 manager
.Initialize();
241 // Check we can create texture.
242 manager
.CreateTexture(kClient1Id
, kService1Id
);
243 // Check texture got created.
244 TextureRef
* texture
= manager
.GetTexture(kClient1Id
);
245 ASSERT_TRUE(texture
!= NULL
);
246 EXPECT_CALL(*gl_
, DeleteTextures(1, ::testing::Pointee(kService1Id
)))
248 .RetiresOnSaturation();
249 TestHelper::SetupTextureManagerDestructionExpectations(
250 gl_
.get(), "", kUseDefaultTextures
);
251 manager
.Destroy(true);
252 // Check that resources got freed.
253 texture
= manager
.GetTexture(kClient1Id
);
254 ASSERT_TRUE(texture
== NULL
);
257 TEST_F(TextureManagerTest
, MaxValues
) {
258 // Check we get the right values for the max sizes.
259 EXPECT_EQ(kMax2dLevels
, manager_
->MaxLevelsForTarget(GL_TEXTURE_2D
));
260 EXPECT_EQ(kMaxCubeMapLevels
,
261 manager_
->MaxLevelsForTarget(GL_TEXTURE_CUBE_MAP
));
262 EXPECT_EQ(kMaxCubeMapLevels
,
263 manager_
->MaxLevelsForTarget(GL_TEXTURE_CUBE_MAP_POSITIVE_X
));
264 EXPECT_EQ(kMaxCubeMapLevels
,
265 manager_
->MaxLevelsForTarget(GL_TEXTURE_CUBE_MAP_NEGATIVE_X
));
266 EXPECT_EQ(kMaxCubeMapLevels
,
267 manager_
->MaxLevelsForTarget(GL_TEXTURE_CUBE_MAP_POSITIVE_Y
));
268 EXPECT_EQ(kMaxCubeMapLevels
,
269 manager_
->MaxLevelsForTarget(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
));
270 EXPECT_EQ(kMaxCubeMapLevels
,
271 manager_
->MaxLevelsForTarget(GL_TEXTURE_CUBE_MAP_POSITIVE_Z
));
272 EXPECT_EQ(kMaxCubeMapLevels
,
273 manager_
->MaxLevelsForTarget(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
));
274 EXPECT_EQ(kMaxExternalLevels
,
275 manager_
->MaxLevelsForTarget(GL_TEXTURE_EXTERNAL_OES
));
276 EXPECT_EQ(kMaxTextureSize
, manager_
->MaxSizeForTarget(GL_TEXTURE_2D
));
277 EXPECT_EQ(kMaxCubeMapTextureSize
,
278 manager_
->MaxSizeForTarget(GL_TEXTURE_CUBE_MAP
));
279 EXPECT_EQ(kMaxCubeMapTextureSize
,
280 manager_
->MaxSizeForTarget(GL_TEXTURE_CUBE_MAP_POSITIVE_X
));
281 EXPECT_EQ(kMaxCubeMapTextureSize
,
282 manager_
->MaxSizeForTarget(GL_TEXTURE_CUBE_MAP_NEGATIVE_X
));
283 EXPECT_EQ(kMaxCubeMapTextureSize
,
284 manager_
->MaxSizeForTarget(GL_TEXTURE_CUBE_MAP_POSITIVE_Y
));
285 EXPECT_EQ(kMaxCubeMapTextureSize
,
286 manager_
->MaxSizeForTarget(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
));
287 EXPECT_EQ(kMaxCubeMapTextureSize
,
288 manager_
->MaxSizeForTarget(GL_TEXTURE_CUBE_MAP_POSITIVE_Z
));
289 EXPECT_EQ(kMaxCubeMapTextureSize
,
290 manager_
->MaxSizeForTarget(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
));
291 EXPECT_EQ(kMaxExternalTextureSize
,
292 manager_
->MaxSizeForTarget(GL_TEXTURE_EXTERNAL_OES
));
295 TEST_F(TextureManagerTest
, ValidForTarget
) {
297 EXPECT_TRUE(manager_
->ValidForTarget(
298 GL_TEXTURE_2D
, 0, kMaxTextureSize
, kMaxTextureSize
, 1));
299 EXPECT_TRUE(manager_
->ValidForTarget(
300 GL_TEXTURE_2D
, kMax2dLevels
- 1, 1, 1, 1));
301 EXPECT_FALSE(manager_
->ValidForTarget(
302 GL_TEXTURE_2D
, kMax2dLevels
- 1, 1, 2, 1));
303 EXPECT_FALSE(manager_
->ValidForTarget(
304 GL_TEXTURE_2D
, kMax2dLevels
- 1, 2, 1, 1));
305 // check level out of range.
306 EXPECT_FALSE(manager_
->ValidForTarget(
307 GL_TEXTURE_2D
, kMax2dLevels
, kMaxTextureSize
, 1, 1));
309 EXPECT_FALSE(manager_
->ValidForTarget(
310 GL_TEXTURE_2D
, kMax2dLevels
, kMaxTextureSize
, 1, 2));
311 // Check NPOT width on level 0
312 EXPECT_TRUE(manager_
->ValidForTarget(GL_TEXTURE_2D
, 0, 5, 2, 1));
313 // Check NPOT height on level 0
314 EXPECT_TRUE(manager_
->ValidForTarget(GL_TEXTURE_2D
, 0, 2, 5, 1));
315 // Check NPOT width on level 1
316 EXPECT_FALSE(manager_
->ValidForTarget(GL_TEXTURE_2D
, 1, 5, 2, 1));
317 // Check NPOT height on level 1
318 EXPECT_FALSE(manager_
->ValidForTarget(GL_TEXTURE_2D
, 1, 2, 5, 1));
321 EXPECT_TRUE(manager_
->ValidForTarget(
322 GL_TEXTURE_CUBE_MAP
, 0,
323 kMaxCubeMapTextureSize
, kMaxCubeMapTextureSize
, 1));
324 EXPECT_TRUE(manager_
->ValidForTarget(
325 GL_TEXTURE_CUBE_MAP
, kMaxCubeMapLevels
- 1, 1, 1, 1));
326 EXPECT_FALSE(manager_
->ValidForTarget(
327 GL_TEXTURE_CUBE_MAP
, kMaxCubeMapLevels
- 1, 2, 2, 1));
328 // check level out of range.
329 EXPECT_FALSE(manager_
->ValidForTarget(
330 GL_TEXTURE_CUBE_MAP
, kMaxCubeMapLevels
,
331 kMaxCubeMapTextureSize
, 1, 1));
333 EXPECT_FALSE(manager_
->ValidForTarget(
334 GL_TEXTURE_CUBE_MAP
, kMaxCubeMapLevels
,
335 kMaxCubeMapTextureSize
, 1, 1));
337 EXPECT_FALSE(manager_
->ValidForTarget(
338 GL_TEXTURE_CUBE_MAP
, kMaxCubeMapLevels
,
339 kMaxCubeMapTextureSize
, 1, 2));
341 for (GLint level
= 0; level
< kMax2dLevels
; ++level
) {
342 EXPECT_TRUE(manager_
->ValidForTarget(
343 GL_TEXTURE_2D
, level
, kMaxTextureSize
>> level
, 1, 1));
344 EXPECT_TRUE(manager_
->ValidForTarget(
345 GL_TEXTURE_2D
, level
, 1, kMaxTextureSize
>> level
, 1));
346 EXPECT_FALSE(manager_
->ValidForTarget(
347 GL_TEXTURE_2D
, level
, (kMaxTextureSize
>> level
) + 1, 1, 1));
348 EXPECT_FALSE(manager_
->ValidForTarget(
349 GL_TEXTURE_2D
, level
, 1, (kMaxTextureSize
>> level
) + 1, 1));
352 for (GLint level
= 0; level
< kMaxCubeMapLevels
; ++level
) {
353 EXPECT_TRUE(manager_
->ValidForTarget(
354 GL_TEXTURE_CUBE_MAP
, level
,
355 kMaxCubeMapTextureSize
>> level
,
356 kMaxCubeMapTextureSize
>> level
,
358 EXPECT_FALSE(manager_
->ValidForTarget(
359 GL_TEXTURE_CUBE_MAP
, level
,
360 (kMaxCubeMapTextureSize
>> level
) * 2,
361 (kMaxCubeMapTextureSize
>> level
) * 2,
366 TEST_F(TextureManagerTest
, ValidForTargetNPOT
) {
367 TestHelper::SetupFeatureInfoInitExpectations(
368 gl_
.get(), "GL_OES_texture_npot");
369 scoped_refptr
<FeatureInfo
> feature_info(new FeatureInfo());
370 feature_info
->Initialize();
371 TextureManager
manager(NULL
,
374 kMaxCubeMapTextureSize
,
375 kUseDefaultTextures
);
376 // Check NPOT width on level 0
377 EXPECT_TRUE(manager
.ValidForTarget(GL_TEXTURE_2D
, 0, 5, 2, 1));
378 // Check NPOT height on level 0
379 EXPECT_TRUE(manager
.ValidForTarget(GL_TEXTURE_2D
, 0, 2, 5, 1));
380 // Check NPOT width on level 1
381 EXPECT_TRUE(manager
.ValidForTarget(GL_TEXTURE_2D
, 1, 5, 2, 1));
382 // Check NPOT height on level 1
383 EXPECT_TRUE(manager
.ValidForTarget(GL_TEXTURE_2D
, 1, 2, 5, 1));
384 manager
.Destroy(false);
387 class TextureTestBase
: public GpuServiceTest
{
389 static const GLint kMaxTextureSize
= 16;
390 static const GLint kMaxCubeMapTextureSize
= 8;
391 static const GLint kMax2dLevels
= 5;
392 static const GLint kMaxCubeMapLevels
= 4;
393 static const GLuint kClient1Id
= 1;
394 static const GLuint kService1Id
= 11;
395 static const bool kUseDefaultTextures
= false;
398 : feature_info_(new FeatureInfo()) {
400 virtual ~TextureTestBase() {
405 void SetUpBase(MemoryTracker
* memory_tracker
, std::string extensions
) {
406 GpuServiceTest::SetUp();
407 if (!extensions
.empty()) {
408 TestHelper::SetupFeatureInfoInitExpectations(gl_
.get(),
410 feature_info_
->Initialize();
413 manager_
.reset(new TextureManager(memory_tracker
,
416 kMaxCubeMapTextureSize
,
417 kUseDefaultTextures
));
418 decoder_
.reset(new ::testing::StrictMock
<gles2::MockGLES2Decoder
>());
419 error_state_
.reset(new ::testing::StrictMock
<gles2::MockErrorState
>());
420 manager_
->CreateTexture(kClient1Id
, kService1Id
);
421 texture_ref_
= manager_
->GetTexture(kClient1Id
);
422 ASSERT_TRUE(texture_ref_
.get() != NULL
);
425 virtual void TearDown() {
426 if (texture_ref_
.get()) {
427 // If it's not in the manager then setting texture_ref_ to NULL will
428 // delete the texture.
429 if (!texture_ref_
->client_id()) {
430 // Check that it gets deleted when the last reference is released.
432 DeleteTextures(1, ::testing::Pointee(texture_ref_
->service_id())))
434 .RetiresOnSaturation();
438 manager_
->Destroy(false);
440 GpuServiceTest::TearDown();
444 TextureRef
* texture_ref
, GLenum pname
, GLint value
, GLenum error
) {
445 TestHelper::SetTexParameteriWithExpectations(
446 gl_
.get(), error_state_
.get(), manager_
.get(),
447 texture_ref
, pname
, value
, error
);
450 scoped_ptr
<MockGLES2Decoder
> decoder_
;
451 scoped_ptr
<MockErrorState
> error_state_
;
452 scoped_refptr
<FeatureInfo
> feature_info_
;
453 scoped_ptr
<TextureManager
> manager_
;
454 scoped_refptr
<TextureRef
> texture_ref_
;
457 class TextureTest
: public TextureTestBase
{
459 virtual void SetUp() {
460 SetUpBase(NULL
, std::string());
464 class TextureMemoryTrackerTest
: public TextureTestBase
{
466 virtual void SetUp() {
467 mock_memory_tracker_
= new StrictMock
<MockMemoryTracker
>();
468 SetUpBase(mock_memory_tracker_
.get(), std::string());
471 scoped_refptr
<MockMemoryTracker
> mock_memory_tracker_
;
474 #define EXPECT_MEMORY_ALLOCATION_CHANGE(old_size, new_size, pool) \
475 EXPECT_CALL(*mock_memory_tracker_.get(), \
476 TrackMemoryAllocatedChange(old_size, new_size, pool)) \
477 .Times(1).RetiresOnSaturation()
479 TEST_F(TextureTest
, Basic
) {
480 Texture
* texture
= texture_ref_
->texture();
481 EXPECT_EQ(0u, texture
->target());
482 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture
));
483 EXPECT_FALSE(TextureTestHelper::IsCubeComplete(texture
));
484 EXPECT_FALSE(manager_
->CanGenerateMipmaps(texture_ref_
.get()));
485 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture
));
486 EXPECT_EQ(0, texture
->num_uncleared_mips());
487 EXPECT_TRUE(manager_
->CanRender(texture_ref_
.get()));
488 EXPECT_TRUE(texture
->SafeToRenderFrom());
489 EXPECT_FALSE(texture
->IsImmutable());
490 EXPECT_EQ(static_cast<GLenum
>(GL_NEAREST_MIPMAP_LINEAR
),
491 texture
->min_filter());
492 EXPECT_EQ(static_cast<GLenum
>(GL_LINEAR
), texture
->mag_filter());
493 EXPECT_EQ(static_cast<GLenum
>(GL_REPEAT
), texture
->wrap_s());
494 EXPECT_EQ(static_cast<GLenum
>(GL_REPEAT
), texture
->wrap_t());
495 EXPECT_FALSE(manager_
->HaveUnrenderableTextures());
496 EXPECT_FALSE(manager_
->HaveUnsafeTextures());
497 EXPECT_EQ(0u, texture
->estimated_size());
500 TEST_F(TextureTest
, SetTargetTexture2D
) {
501 Texture
* texture
= texture_ref_
->texture();
502 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_2D
);
503 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture
));
504 EXPECT_FALSE(TextureTestHelper::IsCubeComplete(texture
));
505 EXPECT_FALSE(manager_
->CanGenerateMipmaps(texture_ref_
.get()));
506 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture
));
507 EXPECT_FALSE(manager_
->CanRender(texture_ref_
.get()));
508 EXPECT_TRUE(texture
->SafeToRenderFrom());
509 EXPECT_FALSE(texture
->IsImmutable());
512 TEST_F(TextureTest
, SetTargetTextureExternalOES
) {
513 Texture
* texture
= texture_ref_
->texture();
514 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_EXTERNAL_OES
);
515 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture
));
516 EXPECT_FALSE(TextureTestHelper::IsCubeComplete(texture
));
517 EXPECT_FALSE(manager_
->CanGenerateMipmaps(texture_ref_
.get()));
518 EXPECT_TRUE(TextureTestHelper::IsNPOT(texture
));
519 EXPECT_TRUE(manager_
->CanRender(texture_ref_
.get()));
520 EXPECT_TRUE(texture
->SafeToRenderFrom());
521 EXPECT_TRUE(texture
->IsImmutable());
524 TEST_F(TextureTest
, ZeroSizeCanNotRender
) {
525 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_2D
);
526 EXPECT_FALSE(manager_
->CanRender(texture_ref_
.get()));
527 manager_
->SetLevelInfo(texture_ref_
.get(),
538 EXPECT_TRUE(manager_
->CanRender(texture_ref_
.get()));
539 manager_
->SetLevelInfo(texture_ref_
.get(),
550 EXPECT_FALSE(manager_
->CanRender(texture_ref_
.get()));
553 TEST_F(TextureTest
, EstimatedSize
) {
554 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_2D
);
555 manager_
->SetLevelInfo(texture_ref_
.get(),
566 EXPECT_EQ(8u * 4u * 4u, texture_ref_
->texture()->estimated_size());
567 manager_
->SetLevelInfo(texture_ref_
.get(),
578 EXPECT_EQ(8u * 4u * 4u * 2u, texture_ref_
->texture()->estimated_size());
581 TEST_F(TextureMemoryTrackerTest
, EstimatedSize
) {
582 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_2D
);
583 EXPECT_MEMORY_ALLOCATION_CHANGE(0, 128, MemoryTracker::kUnmanaged
);
584 manager_
->SetLevelInfo(texture_ref_
.get(),
595 EXPECT_MEMORY_ALLOCATION_CHANGE(128, 0, MemoryTracker::kUnmanaged
);
596 EXPECT_MEMORY_ALLOCATION_CHANGE(0, 256, MemoryTracker::kUnmanaged
);
597 manager_
->SetLevelInfo(texture_ref_
.get(),
608 // Add expectation for texture deletion.
609 EXPECT_MEMORY_ALLOCATION_CHANGE(256, 0, MemoryTracker::kUnmanaged
);
610 EXPECT_MEMORY_ALLOCATION_CHANGE(0, 0, MemoryTracker::kUnmanaged
);
613 TEST_F(TextureMemoryTrackerTest
, SetParameterPool
) {
614 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_2D
);
615 EXPECT_MEMORY_ALLOCATION_CHANGE(0, 128, MemoryTracker::kUnmanaged
);
616 manager_
->SetLevelInfo(texture_ref_
.get(),
627 EXPECT_MEMORY_ALLOCATION_CHANGE(128, 0, MemoryTracker::kUnmanaged
);
628 EXPECT_MEMORY_ALLOCATION_CHANGE(0, 128, MemoryTracker::kManaged
);
629 SetParameter(texture_ref_
.get(),
630 GL_TEXTURE_POOL_CHROMIUM
,
631 GL_TEXTURE_POOL_MANAGED_CHROMIUM
,
633 // Add expectation for texture deletion.
634 EXPECT_MEMORY_ALLOCATION_CHANGE(128, 0, MemoryTracker::kManaged
);
635 EXPECT_MEMORY_ALLOCATION_CHANGE(0, 0, MemoryTracker::kUnmanaged
);
636 EXPECT_MEMORY_ALLOCATION_CHANGE(0, 0, MemoryTracker::kManaged
);
639 TEST_F(TextureTest
, POT2D
) {
640 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_2D
);
641 Texture
* texture
= texture_ref_
->texture();
642 EXPECT_EQ(static_cast<GLenum
>(GL_TEXTURE_2D
), texture
->target());
643 // Check Setting level 0 to POT
644 manager_
->SetLevelInfo(texture_ref_
.get(),
655 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture
));
656 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture
));
657 EXPECT_FALSE(manager_
->CanRender(texture_ref_
.get()));
658 EXPECT_EQ(0, texture
->num_uncleared_mips());
659 EXPECT_TRUE(manager_
->HaveUnrenderableTextures());
660 // Set filters to something that will work with a single mip.
662 texture_ref_
.get(), GL_TEXTURE_MIN_FILTER
, GL_LINEAR
, GL_NO_ERROR
);
663 EXPECT_TRUE(manager_
->CanRender(texture_ref_
.get()));
664 EXPECT_FALSE(manager_
->HaveUnrenderableTextures());
666 SetParameter(texture_ref_
.get(),
667 GL_TEXTURE_MIN_FILTER
,
668 GL_LINEAR_MIPMAP_LINEAR
,
670 EXPECT_TRUE(manager_
->HaveUnrenderableTextures());
672 EXPECT_TRUE(manager_
->CanGenerateMipmaps(texture_ref_
.get()));
674 EXPECT_TRUE(manager_
->MarkMipmapsGenerated(texture_ref_
.get()));
675 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture
));
676 EXPECT_TRUE(manager_
->CanRender(texture_ref_
.get()));
677 EXPECT_FALSE(manager_
->HaveUnrenderableTextures());
679 manager_
->SetLevelInfo(texture_ref_
.get(),
690 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture
));
691 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture
));
692 EXPECT_TRUE(manager_
->CanGenerateMipmaps(texture_ref_
.get()));
693 EXPECT_FALSE(manager_
->CanRender(texture_ref_
.get()));
694 EXPECT_TRUE(manager_
->HaveUnrenderableTextures());
695 // Set a level past the number of mips that would get generated.
696 manager_
->SetLevelInfo(texture_ref_
.get(),
707 EXPECT_TRUE(manager_
->CanGenerateMipmaps(texture_ref_
.get()));
709 EXPECT_TRUE(manager_
->MarkMipmapsGenerated(texture_ref_
.get()));
710 EXPECT_TRUE(manager_
->CanRender(texture_ref_
.get()));
711 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture
));
712 EXPECT_FALSE(manager_
->HaveUnrenderableTextures());
715 TEST_F(TextureMemoryTrackerTest
, MarkMipmapsGenerated
) {
716 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_2D
);
717 EXPECT_MEMORY_ALLOCATION_CHANGE(0, 64, MemoryTracker::kUnmanaged
);
718 manager_
->SetLevelInfo(texture_ref_
.get(),
729 EXPECT_MEMORY_ALLOCATION_CHANGE(64, 0, MemoryTracker::kUnmanaged
);
730 EXPECT_MEMORY_ALLOCATION_CHANGE(0, 84, MemoryTracker::kUnmanaged
);
731 EXPECT_TRUE(manager_
->MarkMipmapsGenerated(texture_ref_
.get()));
732 EXPECT_MEMORY_ALLOCATION_CHANGE(84, 0, MemoryTracker::kUnmanaged
);
733 EXPECT_MEMORY_ALLOCATION_CHANGE(0, 0, MemoryTracker::kUnmanaged
);
736 TEST_F(TextureTest
, UnusedMips
) {
737 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_2D
);
738 Texture
* texture
= texture_ref_
->texture();
739 EXPECT_EQ(static_cast<GLenum
>(GL_TEXTURE_2D
), texture
->target());
740 // Set level zero to large size.
741 manager_
->SetLevelInfo(texture_ref_
.get(),
752 EXPECT_TRUE(manager_
->MarkMipmapsGenerated(texture_ref_
.get()));
753 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture
));
754 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture
));
755 EXPECT_TRUE(manager_
->CanRender(texture_ref_
.get()));
756 EXPECT_FALSE(manager_
->HaveUnrenderableTextures());
757 // Set level zero to large smaller (levels unused mips)
758 manager_
->SetLevelInfo(texture_ref_
.get(),
769 EXPECT_TRUE(manager_
->MarkMipmapsGenerated(texture_ref_
.get()));
770 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture
));
771 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture
));
772 EXPECT_TRUE(manager_
->CanRender(texture_ref_
.get()));
773 EXPECT_FALSE(manager_
->HaveUnrenderableTextures());
774 // Set an unused level to some size
775 manager_
->SetLevelInfo(texture_ref_
.get(),
786 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture
));
787 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture
));
788 EXPECT_TRUE(manager_
->CanRender(texture_ref_
.get()));
789 EXPECT_FALSE(manager_
->HaveUnrenderableTextures());
792 TEST_F(TextureTest
, NPOT2D
) {
793 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_2D
);
794 Texture
* texture
= texture_ref_
->texture();
795 EXPECT_EQ(static_cast<GLenum
>(GL_TEXTURE_2D
), texture
->target());
796 // Check Setting level 0 to NPOT
797 manager_
->SetLevelInfo(texture_ref_
.get(),
808 EXPECT_TRUE(TextureTestHelper::IsNPOT(texture
));
809 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture
));
810 EXPECT_FALSE(manager_
->CanGenerateMipmaps(texture_ref_
.get()));
811 EXPECT_FALSE(manager_
->CanRender(texture_ref_
.get()));
812 EXPECT_TRUE(manager_
->HaveUnrenderableTextures());
814 texture_ref_
.get(), GL_TEXTURE_MIN_FILTER
, GL_LINEAR
, GL_NO_ERROR
);
815 EXPECT_FALSE(manager_
->CanRender(texture_ref_
.get()));
816 EXPECT_TRUE(manager_
->HaveUnrenderableTextures());
818 texture_ref_
.get(), GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
, GL_NO_ERROR
);
819 EXPECT_FALSE(manager_
->CanRender(texture_ref_
.get()));
820 EXPECT_TRUE(manager_
->HaveUnrenderableTextures());
822 texture_ref_
.get(), GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
, GL_NO_ERROR
);
823 EXPECT_TRUE(manager_
->CanRender(texture_ref_
.get()));
824 EXPECT_FALSE(manager_
->HaveUnrenderableTextures());
826 manager_
->SetLevelInfo(texture_ref_
.get(),
837 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture
));
838 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture
));
839 EXPECT_TRUE(manager_
->CanGenerateMipmaps(texture_ref_
.get()));
840 EXPECT_FALSE(manager_
->HaveUnrenderableTextures());
843 TEST_F(TextureTest
, NPOT2DNPOTOK
) {
844 TestHelper::SetupFeatureInfoInitExpectations(
845 gl_
.get(), "GL_OES_texture_npot");
846 scoped_refptr
<FeatureInfo
> feature_info(new FeatureInfo());
847 feature_info
->Initialize();
848 TextureManager
manager(NULL
,
851 kMaxCubeMapTextureSize
,
852 kUseDefaultTextures
);
853 manager
.CreateTexture(kClient1Id
, kService1Id
);
854 TextureRef
* texture_ref
= manager
.GetTexture(kClient1Id
);
855 ASSERT_TRUE(texture_ref
!= NULL
);
856 Texture
* texture
= texture_ref
->texture();
858 manager
.SetTarget(texture_ref
, GL_TEXTURE_2D
);
859 EXPECT_EQ(static_cast<GLenum
>(GL_TEXTURE_2D
), texture
->target());
860 // Check Setting level 0 to NPOT
861 manager
.SetLevelInfo(texture_ref
,
862 GL_TEXTURE_2D
, 0, GL_RGBA
, 4, 5, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, true);
863 EXPECT_TRUE(TextureTestHelper::IsNPOT(texture
));
864 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture
));
865 EXPECT_TRUE(manager
.CanGenerateMipmaps(texture_ref
));
866 EXPECT_FALSE(manager
.CanRender(texture_ref
));
867 EXPECT_TRUE(manager
.HaveUnrenderableTextures());
868 EXPECT_TRUE(manager
.MarkMipmapsGenerated(texture_ref
));
869 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture
));
870 EXPECT_TRUE(manager
.CanRender(texture_ref
));
871 EXPECT_FALSE(manager
.HaveUnrenderableTextures());
872 manager
.Destroy(false);
875 TEST_F(TextureTest
, POTCubeMap
) {
876 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_CUBE_MAP
);
877 Texture
* texture
= texture_ref_
->texture();
878 EXPECT_EQ(static_cast<GLenum
>(GL_TEXTURE_CUBE_MAP
), texture
->target());
879 // Check Setting level 0 each face to POT
880 manager_
->SetLevelInfo(texture_ref_
.get(),
881 GL_TEXTURE_CUBE_MAP_POSITIVE_X
,
891 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture
));
892 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture
));
893 EXPECT_FALSE(TextureTestHelper::IsCubeComplete(texture
));
894 EXPECT_FALSE(manager_
->CanGenerateMipmaps(texture_ref_
.get()));
895 EXPECT_FALSE(manager_
->CanRender(texture_ref_
.get()));
896 EXPECT_TRUE(manager_
->HaveUnrenderableTextures());
897 manager_
->SetLevelInfo(texture_ref_
.get(),
898 GL_TEXTURE_CUBE_MAP_NEGATIVE_X
,
908 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture
));
909 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture
));
910 EXPECT_FALSE(TextureTestHelper::IsCubeComplete(texture
));
911 EXPECT_FALSE(manager_
->CanGenerateMipmaps(texture_ref_
.get()));
912 EXPECT_FALSE(manager_
->CanRender(texture_ref_
.get()));
913 EXPECT_TRUE(manager_
->HaveUnrenderableTextures());
914 manager_
->SetLevelInfo(texture_ref_
.get(),
915 GL_TEXTURE_CUBE_MAP_POSITIVE_Y
,
925 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture
));
926 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture
));
927 EXPECT_FALSE(TextureTestHelper::IsCubeComplete(texture
));
928 EXPECT_FALSE(manager_
->CanGenerateMipmaps(texture_ref_
.get()));
929 EXPECT_FALSE(manager_
->CanRender(texture_ref_
.get()));
930 EXPECT_TRUE(manager_
->HaveUnrenderableTextures());
931 manager_
->SetLevelInfo(texture_ref_
.get(),
932 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
,
942 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture
));
943 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture
));
944 EXPECT_FALSE(TextureTestHelper::IsCubeComplete(texture
));
945 EXPECT_FALSE(manager_
->CanRender(texture_ref_
.get()));
946 EXPECT_FALSE(manager_
->CanGenerateMipmaps(texture_ref_
.get()));
947 EXPECT_TRUE(manager_
->HaveUnrenderableTextures());
948 manager_
->SetLevelInfo(texture_ref_
.get(),
949 GL_TEXTURE_CUBE_MAP_POSITIVE_Z
,
959 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture
));
960 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture
));
961 EXPECT_FALSE(TextureTestHelper::IsCubeComplete(texture
));
962 EXPECT_FALSE(manager_
->CanGenerateMipmaps(texture_ref_
.get()));
963 EXPECT_FALSE(manager_
->CanRender(texture_ref_
.get()));
964 EXPECT_TRUE(manager_
->HaveUnrenderableTextures());
965 manager_
->SetLevelInfo(texture_ref_
.get(),
966 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
,
976 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture
));
977 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture
));
978 EXPECT_TRUE(TextureTestHelper::IsCubeComplete(texture
));
979 EXPECT_TRUE(manager_
->CanGenerateMipmaps(texture_ref_
.get()));
980 EXPECT_FALSE(manager_
->CanRender(texture_ref_
.get()));
981 EXPECT_TRUE(manager_
->HaveUnrenderableTextures());
984 EXPECT_TRUE(manager_
->MarkMipmapsGenerated(texture_ref_
.get()));
985 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture
));
986 EXPECT_TRUE(TextureTestHelper::IsCubeComplete(texture
));
987 EXPECT_TRUE(manager_
->CanRender(texture_ref_
.get()));
988 EXPECT_FALSE(manager_
->HaveUnrenderableTextures());
991 manager_
->SetLevelInfo(texture_ref_
.get(),
992 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
,
1002 EXPECT_FALSE(TextureTestHelper::IsNPOT(texture
));
1003 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture
));
1004 EXPECT_TRUE(TextureTestHelper::IsCubeComplete(texture
));
1005 EXPECT_TRUE(manager_
->CanGenerateMipmaps(texture_ref_
.get()));
1006 // Set a level past the number of mips that would get generated.
1007 manager_
->SetLevelInfo(texture_ref_
.get(),
1008 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
,
1018 EXPECT_TRUE(manager_
->CanGenerateMipmaps(texture_ref_
.get()));
1020 EXPECT_TRUE(manager_
->MarkMipmapsGenerated(texture_ref_
.get()));
1021 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture
));
1022 EXPECT_TRUE(TextureTestHelper::IsCubeComplete(texture
));
1025 TEST_F(TextureTest
, GetLevelSize
) {
1026 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_2D
);
1027 manager_
->SetLevelInfo(texture_ref_
.get(),
1039 GLsizei height
= -1;
1040 Texture
* texture
= texture_ref_
->texture();
1041 EXPECT_FALSE(texture
->GetLevelSize(GL_TEXTURE_2D
, -1, &width
, &height
));
1042 EXPECT_FALSE(texture
->GetLevelSize(GL_TEXTURE_2D
, 1000, &width
, &height
));
1043 EXPECT_FALSE(texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
));
1044 EXPECT_TRUE(texture
->GetLevelSize(GL_TEXTURE_2D
, 1, &width
, &height
));
1045 EXPECT_EQ(4, width
);
1046 EXPECT_EQ(5, height
);
1047 manager_
->RemoveTexture(kClient1Id
);
1048 EXPECT_TRUE(texture
->GetLevelSize(GL_TEXTURE_2D
, 1, &width
, &height
));
1049 EXPECT_EQ(4, width
);
1050 EXPECT_EQ(5, height
);
1053 TEST_F(TextureTest
, GetLevelType
) {
1054 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_2D
);
1055 manager_
->SetLevelInfo(texture_ref_
.get(),
1068 Texture
* texture
= texture_ref_
->texture();
1069 EXPECT_FALSE(texture
->GetLevelType(GL_TEXTURE_2D
, -1, &type
, &format
));
1070 EXPECT_FALSE(texture
->GetLevelType(GL_TEXTURE_2D
, 1000, &type
, &format
));
1071 EXPECT_FALSE(texture
->GetLevelType(GL_TEXTURE_2D
, 0, &type
, &format
));
1072 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 1, &type
, &format
));
1073 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
1074 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), format
);
1075 manager_
->RemoveTexture(kClient1Id
);
1076 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 1, &type
, &format
));
1077 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
1078 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), format
);
1081 TEST_F(TextureTest
, ValidForTexture
) {
1082 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_2D
);
1083 manager_
->SetLevelInfo(texture_ref_
.get(),
1095 Texture
* texture
= texture_ref_
->texture();
1096 EXPECT_FALSE(texture
->ValidForTexture(
1097 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
,
1098 1, 0, 0, 4, 5, GL_UNSIGNED_BYTE
));
1100 EXPECT_FALSE(texture
->ValidForTexture(
1101 GL_TEXTURE_2D
, 0, 0, 0, 4, 5, GL_UNSIGNED_BYTE
));
1102 // Check bad xoffset.
1103 EXPECT_FALSE(texture
->ValidForTexture(
1104 GL_TEXTURE_2D
, 1, -1, 0, 4, 5, GL_UNSIGNED_BYTE
));
1105 // Check bad xoffset + width > width.
1106 EXPECT_FALSE(texture
->ValidForTexture(
1107 GL_TEXTURE_2D
, 1, 1, 0, 4, 5, GL_UNSIGNED_BYTE
));
1108 // Check bad yoffset.
1109 EXPECT_FALSE(texture
->ValidForTexture(
1110 GL_TEXTURE_2D
, 1, 0, -1, 4, 5, GL_UNSIGNED_BYTE
));
1111 // Check bad yoffset + height > height.
1112 EXPECT_FALSE(texture
->ValidForTexture(
1113 GL_TEXTURE_2D
, 1, 0, 1, 4, 5, GL_UNSIGNED_BYTE
));
1115 EXPECT_FALSE(texture
->ValidForTexture(
1116 GL_TEXTURE_2D
, 1, 0, 0, 5, 5, GL_UNSIGNED_BYTE
));
1117 // Check bad height.
1118 EXPECT_FALSE(texture
->ValidForTexture(
1119 GL_TEXTURE_2D
, 1, 0, 0, 4, 6, GL_UNSIGNED_BYTE
));
1121 EXPECT_FALSE(texture
->ValidForTexture(
1122 GL_TEXTURE_2D
, 1, 0, 0, 4, 5, GL_UNSIGNED_SHORT_4_4_4_4
));
1123 // Check valid full size
1124 EXPECT_TRUE(texture
->ValidForTexture(
1125 GL_TEXTURE_2D
, 1, 0, 0, 4, 5, GL_UNSIGNED_BYTE
));
1126 // Check valid particial size.
1127 EXPECT_TRUE(texture
->ValidForTexture(
1128 GL_TEXTURE_2D
, 1, 1, 1, 2, 3, GL_UNSIGNED_BYTE
));
1129 manager_
->RemoveTexture(kClient1Id
);
1130 EXPECT_TRUE(texture
->ValidForTexture(
1131 GL_TEXTURE_2D
, 1, 0, 0, 4, 5, GL_UNSIGNED_BYTE
));
1134 TEST_F(TextureTest
, FloatNotLinear
) {
1135 TestHelper::SetupFeatureInfoInitExpectations(
1136 gl_
.get(), "GL_OES_texture_float");
1137 scoped_refptr
<FeatureInfo
> feature_info(new FeatureInfo());
1138 feature_info
->Initialize();
1139 TextureManager
manager(NULL
,
1142 kMaxCubeMapTextureSize
,
1143 kUseDefaultTextures
);
1144 manager
.CreateTexture(kClient1Id
, kService1Id
);
1145 TextureRef
* texture_ref
= manager
.GetTexture(kClient1Id
);
1146 ASSERT_TRUE(texture_ref
!= NULL
);
1147 manager
.SetTarget(texture_ref
, GL_TEXTURE_2D
);
1148 Texture
* texture
= texture_ref
->texture();
1149 EXPECT_EQ(static_cast<GLenum
>(GL_TEXTURE_2D
), texture
->target());
1150 manager
.SetLevelInfo(texture_ref
,
1151 GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 1, 0, GL_RGBA
, GL_FLOAT
, true);
1152 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture
));
1153 TestHelper::SetTexParameteriWithExpectations(
1154 gl_
.get(), error_state_
.get(), &manager
,
1155 texture_ref
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
, GL_NO_ERROR
);
1156 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture
));
1157 TestHelper::SetTexParameteriWithExpectations(
1158 gl_
.get(), error_state_
.get(), &manager
, texture_ref
,
1159 GL_TEXTURE_MIN_FILTER
, GL_NEAREST_MIPMAP_NEAREST
, GL_NO_ERROR
);
1160 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture
));
1161 manager
.Destroy(false);
1164 TEST_F(TextureTest
, FloatLinear
) {
1165 TestHelper::SetupFeatureInfoInitExpectations(
1166 gl_
.get(), "GL_OES_texture_float GL_OES_texture_float_linear");
1167 scoped_refptr
<FeatureInfo
> feature_info(new FeatureInfo());
1168 feature_info
->Initialize();
1169 TextureManager
manager(NULL
,
1172 kMaxCubeMapTextureSize
,
1173 kUseDefaultTextures
);
1174 manager
.CreateTexture(kClient1Id
, kService1Id
);
1175 TextureRef
* texture_ref
= manager
.GetTexture(kClient1Id
);
1176 ASSERT_TRUE(texture_ref
!= NULL
);
1177 manager
.SetTarget(texture_ref
, GL_TEXTURE_2D
);
1178 Texture
* texture
= texture_ref
->texture();
1179 EXPECT_EQ(static_cast<GLenum
>(GL_TEXTURE_2D
), texture
->target());
1180 manager
.SetLevelInfo(texture_ref
,
1181 GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 1, 0, GL_RGBA
, GL_FLOAT
, true);
1182 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture
));
1183 manager
.Destroy(false);
1186 TEST_F(TextureTest
, HalfFloatNotLinear
) {
1187 TestHelper::SetupFeatureInfoInitExpectations(
1188 gl_
.get(), "GL_OES_texture_half_float");
1189 scoped_refptr
<FeatureInfo
> feature_info(new FeatureInfo());
1190 feature_info
->Initialize();
1191 TextureManager
manager(NULL
,
1194 kMaxCubeMapTextureSize
,
1195 kUseDefaultTextures
);
1196 manager
.CreateTexture(kClient1Id
, kService1Id
);
1197 TextureRef
* texture_ref
= manager
.GetTexture(kClient1Id
);
1198 ASSERT_TRUE(texture_ref
!= NULL
);
1199 manager
.SetTarget(texture_ref
, GL_TEXTURE_2D
);
1200 Texture
* texture
= texture_ref
->texture();
1201 EXPECT_EQ(static_cast<GLenum
>(GL_TEXTURE_2D
), texture
->target());
1202 manager
.SetLevelInfo(texture_ref
,
1203 GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 1, 0, GL_RGBA
, GL_HALF_FLOAT_OES
, true);
1204 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture
));
1205 TestHelper::SetTexParameteriWithExpectations(
1206 gl_
.get(), error_state_
.get(), &manager
,
1207 texture_ref
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
, GL_NO_ERROR
);
1208 EXPECT_FALSE(TextureTestHelper::IsTextureComplete(texture
));
1209 TestHelper::SetTexParameteriWithExpectations(
1210 gl_
.get(), error_state_
.get(), &manager
, texture_ref
,
1211 GL_TEXTURE_MIN_FILTER
, GL_NEAREST_MIPMAP_NEAREST
, GL_NO_ERROR
);
1212 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture
));
1213 manager
.Destroy(false);
1216 TEST_F(TextureTest
, HalfFloatLinear
) {
1217 TestHelper::SetupFeatureInfoInitExpectations(
1218 gl_
.get(), "GL_OES_texture_half_float GL_OES_texture_half_float_linear");
1219 scoped_refptr
<FeatureInfo
> feature_info(new FeatureInfo());
1220 feature_info
->Initialize();
1221 TextureManager
manager(NULL
,
1224 kMaxCubeMapTextureSize
,
1225 kUseDefaultTextures
);
1226 manager
.CreateTexture(kClient1Id
, kService1Id
);
1227 TextureRef
* texture_ref
= manager
.GetTexture(kClient1Id
);
1228 ASSERT_TRUE(texture_ref
!= NULL
);
1229 manager
.SetTarget(texture_ref
, GL_TEXTURE_2D
);
1230 Texture
* texture
= texture_ref
->texture();
1231 EXPECT_EQ(static_cast<GLenum
>(GL_TEXTURE_2D
), texture
->target());
1232 manager
.SetLevelInfo(texture_ref
,
1233 GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 1, 0, GL_RGBA
, GL_HALF_FLOAT_OES
, true);
1234 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture
));
1235 manager
.Destroy(false);
1238 TEST_F(TextureTest
, EGLImageExternal
) {
1239 TestHelper::SetupFeatureInfoInitExpectations(
1240 gl_
.get(), "GL_OES_EGL_image_external");
1241 scoped_refptr
<FeatureInfo
> feature_info(new FeatureInfo());
1242 feature_info
->Initialize();
1243 TextureManager
manager(NULL
,
1246 kMaxCubeMapTextureSize
,
1247 kUseDefaultTextures
);
1248 manager
.CreateTexture(kClient1Id
, kService1Id
);
1249 TextureRef
* texture_ref
= manager
.GetTexture(kClient1Id
);
1250 ASSERT_TRUE(texture_ref
!= NULL
);
1251 manager
.SetTarget(texture_ref
, GL_TEXTURE_EXTERNAL_OES
);
1252 Texture
* texture
= texture_ref
->texture();
1253 EXPECT_EQ(static_cast<GLenum
>(GL_TEXTURE_EXTERNAL_OES
), texture
->target());
1254 EXPECT_FALSE(manager
.CanGenerateMipmaps(texture_ref
));
1255 manager
.Destroy(false);
1258 TEST_F(TextureTest
, DepthTexture
) {
1259 TestHelper::SetupFeatureInfoInitExpectations(
1260 gl_
.get(), "GL_ANGLE_depth_texture");
1261 scoped_refptr
<FeatureInfo
> feature_info(new FeatureInfo());
1262 feature_info
->Initialize();
1263 TextureManager
manager(NULL
,
1266 kMaxCubeMapTextureSize
,
1267 kUseDefaultTextures
);
1268 manager
.CreateTexture(kClient1Id
, kService1Id
);
1269 TextureRef
* texture_ref
= manager
.GetTexture(kClient1Id
);
1270 ASSERT_TRUE(texture_ref
!= NULL
);
1271 manager
.SetTarget(texture_ref
, GL_TEXTURE_2D
);
1272 manager
.SetLevelInfo(
1273 texture_ref
, GL_TEXTURE_2D
, 0, GL_DEPTH_COMPONENT
, 4, 4, 1, 0,
1274 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, false);
1275 EXPECT_FALSE(manager
.CanGenerateMipmaps(texture_ref
));
1276 manager
.Destroy(false);
1279 TEST_F(TextureTest
, SafeUnsafe
) {
1280 static const GLuint kClient2Id
= 2;
1281 static const GLuint kService2Id
= 12;
1282 static const GLuint kClient3Id
= 3;
1283 static const GLuint kService3Id
= 13;
1284 EXPECT_FALSE(manager_
->HaveUnclearedMips());
1285 Texture
* texture
= texture_ref_
->texture();
1286 EXPECT_EQ(0, texture
->num_uncleared_mips());
1287 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_2D
);
1288 manager_
->SetLevelInfo(texture_ref_
.get(),
1299 EXPECT_FALSE(texture
->SafeToRenderFrom());
1300 EXPECT_TRUE(manager_
->HaveUnsafeTextures());
1301 EXPECT_TRUE(manager_
->HaveUnclearedMips());
1302 EXPECT_EQ(1, texture
->num_uncleared_mips());
1303 manager_
->SetLevelCleared(texture_ref_
.get(), GL_TEXTURE_2D
, 0, true);
1304 EXPECT_TRUE(texture
->SafeToRenderFrom());
1305 EXPECT_FALSE(manager_
->HaveUnsafeTextures());
1306 EXPECT_FALSE(manager_
->HaveUnclearedMips());
1307 EXPECT_EQ(0, texture
->num_uncleared_mips());
1308 manager_
->SetLevelInfo(texture_ref_
.get(),
1319 EXPECT_FALSE(texture
->SafeToRenderFrom());
1320 EXPECT_TRUE(manager_
->HaveUnsafeTextures());
1321 EXPECT_TRUE(manager_
->HaveUnclearedMips());
1322 EXPECT_EQ(1, texture
->num_uncleared_mips());
1323 manager_
->SetLevelCleared(texture_ref_
.get(), GL_TEXTURE_2D
, 1, true);
1324 EXPECT_TRUE(texture
->SafeToRenderFrom());
1325 EXPECT_FALSE(manager_
->HaveUnsafeTextures());
1326 EXPECT_FALSE(manager_
->HaveUnclearedMips());
1327 EXPECT_EQ(0, texture
->num_uncleared_mips());
1328 manager_
->SetLevelInfo(texture_ref_
.get(),
1339 manager_
->SetLevelInfo(texture_ref_
.get(),
1350 EXPECT_FALSE(texture
->SafeToRenderFrom());
1351 EXPECT_TRUE(manager_
->HaveUnsafeTextures());
1352 EXPECT_TRUE(manager_
->HaveUnclearedMips());
1353 EXPECT_EQ(2, texture
->num_uncleared_mips());
1354 manager_
->SetLevelCleared(texture_ref_
.get(), GL_TEXTURE_2D
, 0, true);
1355 EXPECT_FALSE(texture
->SafeToRenderFrom());
1356 EXPECT_TRUE(manager_
->HaveUnsafeTextures());
1357 EXPECT_TRUE(manager_
->HaveUnclearedMips());
1358 EXPECT_EQ(1, texture
->num_uncleared_mips());
1359 manager_
->SetLevelCleared(texture_ref_
.get(), GL_TEXTURE_2D
, 1, true);
1360 EXPECT_TRUE(texture
->SafeToRenderFrom());
1361 EXPECT_FALSE(manager_
->HaveUnsafeTextures());
1362 EXPECT_FALSE(manager_
->HaveUnclearedMips());
1363 EXPECT_EQ(0, texture
->num_uncleared_mips());
1364 manager_
->SetLevelInfo(texture_ref_
.get(),
1375 EXPECT_FALSE(texture
->SafeToRenderFrom());
1376 EXPECT_TRUE(manager_
->HaveUnsafeTextures());
1377 EXPECT_TRUE(manager_
->HaveUnclearedMips());
1378 EXPECT_EQ(1, texture
->num_uncleared_mips());
1379 manager_
->MarkMipmapsGenerated(texture_ref_
.get());
1380 EXPECT_TRUE(texture
->SafeToRenderFrom());
1381 EXPECT_FALSE(manager_
->HaveUnsafeTextures());
1382 EXPECT_FALSE(manager_
->HaveUnclearedMips());
1383 EXPECT_EQ(0, texture
->num_uncleared_mips());
1385 manager_
->CreateTexture(kClient2Id
, kService2Id
);
1386 scoped_refptr
<TextureRef
> texture_ref2(
1387 manager_
->GetTexture(kClient2Id
));
1388 ASSERT_TRUE(texture_ref2
.get() != NULL
);
1389 manager_
->SetTarget(texture_ref2
.get(), GL_TEXTURE_2D
);
1390 EXPECT_FALSE(manager_
->HaveUnsafeTextures());
1391 EXPECT_FALSE(manager_
->HaveUnclearedMips());
1392 Texture
* texture2
= texture_ref2
->texture();
1393 EXPECT_EQ(0, texture2
->num_uncleared_mips());
1394 manager_
->SetLevelInfo(texture_ref2
.get(),
1405 EXPECT_FALSE(manager_
->HaveUnsafeTextures());
1406 EXPECT_FALSE(manager_
->HaveUnclearedMips());
1407 EXPECT_EQ(0, texture2
->num_uncleared_mips());
1408 manager_
->SetLevelInfo(texture_ref2
.get(),
1419 EXPECT_TRUE(manager_
->HaveUnsafeTextures());
1420 EXPECT_TRUE(manager_
->HaveUnclearedMips());
1421 EXPECT_EQ(1, texture2
->num_uncleared_mips());
1423 manager_
->CreateTexture(kClient3Id
, kService3Id
);
1424 scoped_refptr
<TextureRef
> texture_ref3(
1425 manager_
->GetTexture(kClient3Id
));
1426 ASSERT_TRUE(texture_ref3
.get() != NULL
);
1427 manager_
->SetTarget(texture_ref3
.get(), GL_TEXTURE_2D
);
1428 manager_
->SetLevelInfo(texture_ref3
.get(),
1439 EXPECT_TRUE(manager_
->HaveUnsafeTextures());
1440 EXPECT_TRUE(manager_
->HaveUnclearedMips());
1441 Texture
* texture3
= texture_ref3
->texture();
1442 EXPECT_EQ(1, texture3
->num_uncleared_mips());
1443 manager_
->SetLevelCleared(texture_ref2
.get(), GL_TEXTURE_2D
, 0, true);
1444 EXPECT_TRUE(manager_
->HaveUnsafeTextures());
1445 EXPECT_TRUE(manager_
->HaveUnclearedMips());
1446 EXPECT_EQ(0, texture2
->num_uncleared_mips());
1447 manager_
->SetLevelCleared(texture_ref3
.get(), GL_TEXTURE_2D
, 0, true);
1448 EXPECT_FALSE(manager_
->HaveUnsafeTextures());
1449 EXPECT_FALSE(manager_
->HaveUnclearedMips());
1450 EXPECT_EQ(0, texture3
->num_uncleared_mips());
1452 manager_
->SetLevelInfo(texture_ref2
.get(),
1463 manager_
->SetLevelInfo(texture_ref3
.get(),
1474 EXPECT_TRUE(manager_
->HaveUnsafeTextures());
1475 EXPECT_TRUE(manager_
->HaveUnclearedMips());
1476 EXPECT_EQ(1, texture2
->num_uncleared_mips());
1477 EXPECT_EQ(1, texture3
->num_uncleared_mips());
1478 manager_
->RemoveTexture(kClient3Id
);
1479 EXPECT_TRUE(manager_
->HaveUnsafeTextures());
1480 EXPECT_TRUE(manager_
->HaveUnclearedMips());
1481 manager_
->RemoveTexture(kClient2Id
);
1482 EXPECT_TRUE(manager_
->HaveUnsafeTextures());
1483 EXPECT_TRUE(manager_
->HaveUnclearedMips());
1484 EXPECT_CALL(*gl_
, DeleteTextures(1, ::testing::Pointee(kService2Id
)))
1486 .RetiresOnSaturation();
1487 texture_ref2
= NULL
;
1488 EXPECT_TRUE(manager_
->HaveUnsafeTextures());
1489 EXPECT_TRUE(manager_
->HaveUnclearedMips());
1490 EXPECT_CALL(*gl_
, DeleteTextures(1, ::testing::Pointee(kService3Id
)))
1492 .RetiresOnSaturation();
1493 texture_ref3
= NULL
;
1494 EXPECT_FALSE(manager_
->HaveUnsafeTextures());
1495 EXPECT_FALSE(manager_
->HaveUnclearedMips());
1498 TEST_F(TextureTest
, ClearTexture
) {
1499 EXPECT_CALL(*decoder_
, ClearLevel(_
, _
, _
, _
, _
, _
, _
, _
, _
, _
))
1500 .WillRepeatedly(Return(true));
1501 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_2D
);
1502 manager_
->SetLevelInfo(texture_ref_
.get(),
1513 manager_
->SetLevelInfo(texture_ref_
.get(),
1524 Texture
* texture
= texture_ref_
->texture();
1525 EXPECT_FALSE(texture
->SafeToRenderFrom());
1526 EXPECT_TRUE(manager_
->HaveUnsafeTextures());
1527 EXPECT_TRUE(manager_
->HaveUnclearedMips());
1528 EXPECT_EQ(2, texture
->num_uncleared_mips());
1529 manager_
->ClearRenderableLevels(decoder_
.get(), texture_ref_
.get());
1530 EXPECT_TRUE(texture
->SafeToRenderFrom());
1531 EXPECT_FALSE(manager_
->HaveUnsafeTextures());
1532 EXPECT_FALSE(manager_
->HaveUnclearedMips());
1533 EXPECT_EQ(0, texture
->num_uncleared_mips());
1534 manager_
->SetLevelInfo(texture_ref_
.get(),
1545 manager_
->SetLevelInfo(texture_ref_
.get(),
1556 EXPECT_FALSE(texture
->SafeToRenderFrom());
1557 EXPECT_TRUE(manager_
->HaveUnsafeTextures());
1558 EXPECT_TRUE(manager_
->HaveUnclearedMips());
1559 EXPECT_EQ(2, texture
->num_uncleared_mips());
1560 manager_
->ClearTextureLevel(
1561 decoder_
.get(), texture_ref_
.get(), GL_TEXTURE_2D
, 0);
1562 EXPECT_FALSE(texture
->SafeToRenderFrom());
1563 EXPECT_TRUE(manager_
->HaveUnsafeTextures());
1564 EXPECT_TRUE(manager_
->HaveUnclearedMips());
1565 EXPECT_EQ(1, texture
->num_uncleared_mips());
1566 manager_
->ClearTextureLevel(
1567 decoder_
.get(), texture_ref_
.get(), GL_TEXTURE_2D
, 1);
1568 EXPECT_TRUE(texture
->SafeToRenderFrom());
1569 EXPECT_FALSE(manager_
->HaveUnsafeTextures());
1570 EXPECT_FALSE(manager_
->HaveUnclearedMips());
1571 EXPECT_EQ(0, texture
->num_uncleared_mips());
1574 TEST_F(TextureTest
, UseDeletedTexture
) {
1575 static const GLuint kClient2Id
= 2;
1576 static const GLuint kService2Id
= 12;
1577 // Make the default texture renderable
1578 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_2D
);
1579 manager_
->SetLevelInfo(texture_ref_
.get(),
1590 EXPECT_FALSE(manager_
->HaveUnrenderableTextures());
1591 // Make a new texture
1592 manager_
->CreateTexture(kClient2Id
, kService2Id
);
1593 scoped_refptr
<TextureRef
> texture_ref(
1594 manager_
->GetTexture(kClient2Id
));
1595 manager_
->SetTarget(texture_ref
.get(), GL_TEXTURE_2D
);
1596 EXPECT_FALSE(manager_
->CanRender(texture_ref
.get()));
1597 EXPECT_TRUE(manager_
->HaveUnrenderableTextures());
1599 manager_
->RemoveTexture(kClient2Id
);
1600 EXPECT_FALSE(manager_
->CanRender(texture_ref
.get()));
1601 EXPECT_TRUE(manager_
->HaveUnrenderableTextures());
1602 // Check that we can still manipulate it and it effects the manager.
1603 manager_
->SetLevelInfo(texture_ref
.get(),
1614 EXPECT_TRUE(manager_
->CanRender(texture_ref
.get()));
1615 EXPECT_FALSE(manager_
->HaveUnrenderableTextures());
1616 EXPECT_CALL(*gl_
, DeleteTextures(1, ::testing::Pointee(kService2Id
)))
1618 .RetiresOnSaturation();
1622 TEST_F(TextureTest
, GetLevelImage
) {
1623 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_2D
);
1624 manager_
->SetLevelInfo(texture_ref_
.get(),
1635 Texture
* texture
= texture_ref_
->texture();
1636 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 1) == NULL
);
1638 scoped_refptr
<gfx::GLImage
> image(new gfx::GLImageStub
);
1639 manager_
->SetLevelImage(texture_ref_
.get(), GL_TEXTURE_2D
, 1, image
.get());
1640 EXPECT_FALSE(texture
->GetLevelImage(GL_TEXTURE_2D
, 1) == NULL
);
1642 manager_
->SetLevelImage(texture_ref_
.get(), GL_TEXTURE_2D
, 1, NULL
);
1643 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 1) == NULL
);
1644 manager_
->SetLevelImage(texture_ref_
.get(), GL_TEXTURE_2D
, 1, image
.get());
1645 // Image should be reset when SetLevelInfo is called.
1646 manager_
->SetLevelInfo(texture_ref_
.get(),
1657 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 1) == NULL
);
1662 bool InSet(std::set
<std::string
>* string_set
, const std::string
& str
) {
1663 std::pair
<std::set
<std::string
>::iterator
, bool> result
=
1664 string_set
->insert(str
);
1665 return !result
.second
;
1668 } // anonymous namespace
1670 TEST_F(TextureTest
, AddToSignature
) {
1671 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_2D
);
1672 manager_
->SetLevelInfo(texture_ref_
.get(),
1683 std::string signature1
;
1684 std::string signature2
;
1685 manager_
->AddToSignature(texture_ref_
.get(), GL_TEXTURE_2D
, 1, &signature1
);
1687 std::set
<std::string
> string_set
;
1688 EXPECT_FALSE(InSet(&string_set
, signature1
));
1690 // check changing 1 thing makes a different signature.
1691 manager_
->SetLevelInfo(texture_ref_
.get(),
1702 manager_
->AddToSignature(texture_ref_
.get(), GL_TEXTURE_2D
, 1, &signature2
);
1703 EXPECT_FALSE(InSet(&string_set
, signature2
));
1705 // check putting it back makes the same signature.
1706 manager_
->SetLevelInfo(texture_ref_
.get(),
1718 manager_
->AddToSignature(texture_ref_
.get(), GL_TEXTURE_2D
, 1, &signature2
);
1719 EXPECT_EQ(signature1
, signature2
);
1721 // Check setting cleared status does not change signature.
1722 manager_
->SetLevelInfo(texture_ref_
.get(),
1734 manager_
->AddToSignature(texture_ref_
.get(), GL_TEXTURE_2D
, 1, &signature2
);
1735 EXPECT_EQ(signature1
, signature2
);
1737 // Check changing other settings changes signature.
1738 manager_
->SetLevelInfo(texture_ref_
.get(),
1750 manager_
->AddToSignature(texture_ref_
.get(), GL_TEXTURE_2D
, 1, &signature2
);
1751 EXPECT_FALSE(InSet(&string_set
, signature2
));
1753 manager_
->SetLevelInfo(texture_ref_
.get(),
1765 manager_
->AddToSignature(texture_ref_
.get(), GL_TEXTURE_2D
, 1, &signature2
);
1766 EXPECT_FALSE(InSet(&string_set
, signature2
));
1768 manager_
->SetLevelInfo(texture_ref_
.get(),
1780 manager_
->AddToSignature(texture_ref_
.get(), GL_TEXTURE_2D
, 1, &signature2
);
1781 EXPECT_FALSE(InSet(&string_set
, signature2
));
1783 manager_
->SetLevelInfo(texture_ref_
.get(),
1795 manager_
->AddToSignature(texture_ref_
.get(), GL_TEXTURE_2D
, 1, &signature2
);
1796 EXPECT_FALSE(InSet(&string_set
, signature2
));
1798 manager_
->SetLevelInfo(texture_ref_
.get(),
1810 manager_
->AddToSignature(texture_ref_
.get(), GL_TEXTURE_2D
, 1, &signature2
);
1811 EXPECT_FALSE(InSet(&string_set
, signature2
));
1814 manager_
->SetLevelInfo(texture_ref_
.get(),
1826 manager_
->AddToSignature(texture_ref_
.get(), GL_TEXTURE_2D
, 1, &signature2
);
1827 EXPECT_EQ(signature1
, signature2
);
1829 // check changing parameters changes signature.
1831 texture_ref_
.get(), GL_TEXTURE_MIN_FILTER
, GL_NEAREST
, GL_NO_ERROR
);
1833 manager_
->AddToSignature(texture_ref_
.get(), GL_TEXTURE_2D
, 1, &signature2
);
1834 EXPECT_FALSE(InSet(&string_set
, signature2
));
1836 SetParameter(texture_ref_
.get(),
1837 GL_TEXTURE_MIN_FILTER
,
1838 GL_NEAREST_MIPMAP_LINEAR
,
1841 texture_ref_
.get(), GL_TEXTURE_MAG_FILTER
, GL_NEAREST
, GL_NO_ERROR
);
1843 manager_
->AddToSignature(texture_ref_
.get(), GL_TEXTURE_2D
, 1, &signature2
);
1844 EXPECT_FALSE(InSet(&string_set
, signature2
));
1847 texture_ref_
.get(), GL_TEXTURE_MAG_FILTER
, GL_LINEAR
, GL_NO_ERROR
);
1849 texture_ref_
.get(), GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
, GL_NO_ERROR
);
1851 manager_
->AddToSignature(texture_ref_
.get(), GL_TEXTURE_2D
, 1, &signature2
);
1852 EXPECT_FALSE(InSet(&string_set
, signature2
));
1854 SetParameter(texture_ref_
.get(), GL_TEXTURE_WRAP_S
, GL_REPEAT
, GL_NO_ERROR
);
1856 texture_ref_
.get(), GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
, GL_NO_ERROR
);
1858 manager_
->AddToSignature(texture_ref_
.get(), GL_TEXTURE_2D
, 1, &signature2
);
1859 EXPECT_FALSE(InSet(&string_set
, signature2
));
1861 // Check putting it back genenerates the same signature
1862 SetParameter(texture_ref_
.get(), GL_TEXTURE_WRAP_T
, GL_REPEAT
, GL_NO_ERROR
);
1864 manager_
->AddToSignature(texture_ref_
.get(), GL_TEXTURE_2D
, 1, &signature2
);
1865 EXPECT_EQ(signature1
, signature2
);
1867 // Check the set was acutally getting different signatures.
1868 EXPECT_EQ(11u, string_set
.size());
1871 class ProduceConsumeTextureTest
: public TextureTest
,
1872 public ::testing::WithParamInterface
<GLenum
> {
1874 virtual void SetUp() {
1875 TextureTest::SetUpBase(NULL
, "GL_OES_EGL_image_external");
1876 manager_
->CreateTexture(kClient2Id
, kService2Id
);
1877 texture2_
= manager_
->GetTexture(kClient2Id
);
1879 EXPECT_CALL(*decoder_
.get(), GetErrorState())
1880 .WillRepeatedly(Return(error_state_
.get()));
1883 virtual void TearDown() {
1884 if (texture2_
.get()) {
1885 // If it's not in the manager then setting texture2_ to NULL will
1886 // delete the texture.
1887 if (!texture2_
->client_id()) {
1888 // Check that it gets deleted when the last reference is released.
1891 DeleteTextures(1, ::testing::Pointee(texture2_
->service_id())))
1892 .Times(1).RetiresOnSaturation();
1896 TextureTest::TearDown();
1901 LevelInfo(GLenum target
,
1928 bool operator==(const LevelInfo
& other
) const {
1929 return target
== other
.target
&& format
== other
.format
&&
1930 width
== other
.width
&& height
== other
.height
&&
1931 depth
== other
.depth
&& border
== other
.border
&&
1932 type
== other
.type
&& cleared
== other
.cleared
;
1945 void SetLevelInfo(TextureRef
* texture_ref
,
1947 const LevelInfo
& info
) {
1948 manager_
->SetLevelInfo(texture_ref
,
1961 static LevelInfo
GetLevelInfo(const TextureRef
* texture_ref
,
1964 const Texture
* texture
= texture_ref
->texture();
1966 info
.target
= target
;
1967 EXPECT_TRUE(texture
->GetLevelSize(target
, level
, &info
.width
,
1969 EXPECT_TRUE(texture
->GetLevelType(target
, level
, &info
.type
,
1971 info
.cleared
= texture
->IsLevelCleared(target
, level
);
1975 Texture
* Produce(TextureRef
* texture_ref
) {
1976 Texture
* texture
= manager_
->Produce(texture_ref
);
1977 EXPECT_TRUE(texture
!= NULL
);
1981 void Consume(GLuint client_id
, Texture
* texture
) {
1982 EXPECT_TRUE(manager_
->Consume(client_id
, texture
));
1985 scoped_refptr
<TextureRef
> texture2_
;
1988 static const GLuint kClient2Id
;
1989 static const GLuint kService2Id
;
1992 const GLuint
ProduceConsumeTextureTest::kClient2Id
= 2;
1993 const GLuint
ProduceConsumeTextureTest::kService2Id
= 12;
1995 TEST_F(ProduceConsumeTextureTest
, ProduceConsume2D
) {
1996 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_2D
);
1997 Texture
* texture
= texture_ref_
->texture();
1998 EXPECT_EQ(static_cast<GLenum
>(GL_TEXTURE_2D
), texture
->target());
2000 GL_TEXTURE_2D
, GL_RGBA
, 4, 4, 1, 0, GL_UNSIGNED_BYTE
, true);
2001 SetLevelInfo(texture_ref_
.get(), 0, level0
);
2002 EXPECT_TRUE(manager_
->MarkMipmapsGenerated(texture_ref_
.get()));
2003 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture
));
2004 LevelInfo level1
= GetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 1);
2005 LevelInfo level2
= GetLevelInfo(texture_ref_
.get(), GL_TEXTURE_2D
, 2);
2006 Texture
* produced_texture
= Produce(texture_ref_
.get());
2007 EXPECT_EQ(produced_texture
, texture
);
2009 // Make this texture bigger with more levels, and make sure they get
2010 // clobbered correctly during Consume().
2011 manager_
->SetTarget(texture2_
.get(), GL_TEXTURE_2D
);
2015 LevelInfo(GL_TEXTURE_2D
, GL_RGBA
, 16, 16, 1, 0, GL_UNSIGNED_BYTE
, false));
2016 EXPECT_TRUE(manager_
->MarkMipmapsGenerated(texture2_
.get()));
2017 texture
= texture2_
->texture();
2018 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture
));
2019 EXPECT_EQ(1024U + 256U + 64U + 16U + 4U, texture
->estimated_size());
2021 GLuint client_id
= texture2_
->client_id();
2022 manager_
->RemoveTexture(client_id
);
2023 Consume(client_id
, produced_texture
);
2024 scoped_refptr
<TextureRef
> restored_texture
= manager_
->GetTexture(client_id
);
2025 EXPECT_EQ(produced_texture
, restored_texture
->texture());
2026 EXPECT_EQ(level0
, GetLevelInfo(restored_texture
.get(), GL_TEXTURE_2D
, 0));
2027 EXPECT_EQ(level1
, GetLevelInfo(restored_texture
.get(), GL_TEXTURE_2D
, 1));
2028 EXPECT_EQ(level2
, GetLevelInfo(restored_texture
.get(), GL_TEXTURE_2D
, 2));
2029 texture
= restored_texture
->texture();
2030 EXPECT_EQ(64U + 16U + 4U, texture
->estimated_size());
2032 EXPECT_FALSE(texture
->GetLevelSize(GL_TEXTURE_2D
, 3, &w
, &h
));
2034 // However the old texture ref still exists if it was referenced somewhere.
2035 EXPECT_EQ(1024U + 256U + 64U + 16U + 4U,
2036 texture2_
->texture()->estimated_size());
2039 TEST_F(ProduceConsumeTextureTest
, ProduceConsumeClearRectangle
) {
2040 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_RECTANGLE_ARB
);
2041 Texture
* texture
= texture_ref_
->texture();
2042 EXPECT_EQ(static_cast<GLenum
>(GL_TEXTURE_RECTANGLE_ARB
), texture
->target());
2044 GL_TEXTURE_RECTANGLE_ARB
, GL_RGBA
, 1, 1, 1, 0, GL_UNSIGNED_BYTE
, false);
2045 SetLevelInfo(texture_ref_
.get(), 0, level0
);
2046 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture
));
2047 Texture
* produced_texture
= Produce(texture_ref_
.get());
2048 EXPECT_EQ(produced_texture
, texture
);
2049 EXPECT_EQ(static_cast<GLenum
>(GL_TEXTURE_RECTANGLE_ARB
),
2050 produced_texture
->target());
2052 GLuint client_id
= texture2_
->client_id();
2053 manager_
->RemoveTexture(client_id
);
2054 Consume(client_id
, produced_texture
);
2055 scoped_refptr
<TextureRef
> restored_texture
= manager_
->GetTexture(client_id
);
2056 EXPECT_EQ(produced_texture
, restored_texture
->texture());
2058 // See if we can clear the previously uncleared level now.
2060 GetLevelInfo(restored_texture
.get(), GL_TEXTURE_RECTANGLE_ARB
, 0));
2061 EXPECT_CALL(*decoder_
, ClearLevel(_
, _
, _
, _
, _
, _
, _
, _
, _
, _
))
2062 .WillRepeatedly(Return(true));
2063 EXPECT_TRUE(manager_
->ClearTextureLevel(
2064 decoder_
.get(), restored_texture
.get(), GL_TEXTURE_RECTANGLE_ARB
, 0));
2067 TEST_F(ProduceConsumeTextureTest
, ProduceConsumeExternal
) {
2068 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_EXTERNAL_OES
);
2069 Texture
* texture
= texture_ref_
->texture();
2070 EXPECT_EQ(static_cast<GLenum
>(GL_TEXTURE_EXTERNAL_OES
), texture
->target());
2072 GL_TEXTURE_EXTERNAL_OES
, GL_RGBA
, 1, 1, 1, 0, GL_UNSIGNED_BYTE
, false);
2073 SetLevelInfo(texture_ref_
.get(), 0, level0
);
2074 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture
));
2075 Texture
* produced_texture
= Produce(texture_ref_
.get());
2076 EXPECT_EQ(produced_texture
, texture
);
2078 GLuint client_id
= texture2_
->client_id();
2079 manager_
->RemoveTexture(client_id
);
2080 Consume(client_id
, produced_texture
);
2081 scoped_refptr
<TextureRef
> restored_texture
= manager_
->GetTexture(client_id
);
2082 EXPECT_EQ(produced_texture
, restored_texture
->texture());
2084 GetLevelInfo(restored_texture
.get(), GL_TEXTURE_EXTERNAL_OES
, 0));
2087 TEST_P(ProduceConsumeTextureTest
, ProduceConsumeTextureWithImage
) {
2088 GLenum target
= GetParam();
2089 manager_
->SetTarget(texture_ref_
.get(), target
);
2090 Texture
* texture
= texture_ref_
->texture();
2091 EXPECT_EQ(static_cast<GLenum
>(target
), texture
->target());
2092 scoped_refptr
<gfx::GLImage
> image(new gfx::GLImageStub
);
2093 manager_
->SetLevelInfo(texture_ref_
.get(),
2104 manager_
->SetLevelImage(texture_ref_
.get(), target
, 0, image
.get());
2105 GLuint service_id
= texture
->service_id();
2106 Texture
* produced_texture
= Produce(texture_ref_
.get());
2108 GLuint client_id
= texture2_
->client_id();
2109 manager_
->RemoveTexture(client_id
);
2110 Consume(client_id
, produced_texture
);
2111 scoped_refptr
<TextureRef
> restored_texture
= manager_
->GetTexture(client_id
);
2112 EXPECT_EQ(produced_texture
, restored_texture
->texture());
2113 EXPECT_EQ(service_id
, restored_texture
->service_id());
2114 EXPECT_EQ(image
.get(), restored_texture
->texture()->GetLevelImage(target
, 0));
2117 static const GLenum kTextureTargets
[] = {GL_TEXTURE_2D
, GL_TEXTURE_EXTERNAL_OES
,
2118 GL_TEXTURE_RECTANGLE_ARB
, };
2120 INSTANTIATE_TEST_CASE_P(Target
,
2121 ProduceConsumeTextureTest
,
2122 ::testing::ValuesIn(kTextureTargets
));
2124 TEST_F(ProduceConsumeTextureTest
, ProduceConsumeCube
) {
2125 manager_
->SetTarget(texture_ref_
.get(), GL_TEXTURE_CUBE_MAP
);
2126 Texture
* texture
= texture_ref_
->texture();
2127 EXPECT_EQ(static_cast<GLenum
>(GL_TEXTURE_CUBE_MAP
), texture
->target());
2128 LevelInfo
face0(GL_TEXTURE_CUBE_MAP_POSITIVE_X
,
2136 LevelInfo
face5(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
,
2144 SetLevelInfo(texture_ref_
.get(), 0, face0
);
2145 SetLevelInfo(texture_ref_
.get(), 0, face5
);
2146 EXPECT_TRUE(TextureTestHelper::IsTextureComplete(texture
));
2147 Texture
* produced_texture
= Produce(texture_ref_
.get());
2148 EXPECT_EQ(produced_texture
, texture
);
2150 GLuint client_id
= texture2_
->client_id();
2151 manager_
->RemoveTexture(client_id
);
2152 Consume(client_id
, produced_texture
);
2153 scoped_refptr
<TextureRef
> restored_texture
= manager_
->GetTexture(client_id
);
2154 EXPECT_EQ(produced_texture
, restored_texture
->texture());
2157 GetLevelInfo(restored_texture
.get(), GL_TEXTURE_CUBE_MAP_POSITIVE_X
, 0));
2160 GetLevelInfo(restored_texture
.get(), GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
, 0));
2163 class CountingMemoryTracker
: public MemoryTracker
{
2165 CountingMemoryTracker() {
2166 current_size_
[0] = 0;
2167 current_size_
[1] = 0;
2170 virtual void TrackMemoryAllocatedChange(size_t old_size
,
2172 Pool pool
) OVERRIDE
{
2173 DCHECK_LT(static_cast<size_t>(pool
), arraysize(current_size_
));
2174 current_size_
[pool
] += new_size
- old_size
;
2177 virtual bool EnsureGPUMemoryAvailable(size_t size_needed
) OVERRIDE
{
2181 size_t GetSize(Pool pool
) {
2182 DCHECK_LT(static_cast<size_t>(pool
), arraysize(current_size_
));
2183 return current_size_
[pool
];
2187 virtual ~CountingMemoryTracker() {}
2189 size_t current_size_
[2];
2190 DISALLOW_COPY_AND_ASSIGN(CountingMemoryTracker
);
2193 class SharedTextureTest
: public GpuServiceTest
{
2195 static const bool kUseDefaultTextures
= false;
2197 SharedTextureTest() : feature_info_(new FeatureInfo()) {}
2199 virtual ~SharedTextureTest() {
2202 virtual void SetUp() {
2203 GpuServiceTest::SetUp();
2204 memory_tracker1_
= new CountingMemoryTracker
;
2205 texture_manager1_
.reset(
2206 new TextureManager(memory_tracker1_
.get(),
2207 feature_info_
.get(),
2208 TextureManagerTest::kMaxTextureSize
,
2209 TextureManagerTest::kMaxCubeMapTextureSize
,
2210 kUseDefaultTextures
));
2211 memory_tracker2_
= new CountingMemoryTracker
;
2212 texture_manager2_
.reset(
2213 new TextureManager(memory_tracker2_
.get(),
2214 feature_info_
.get(),
2215 TextureManagerTest::kMaxTextureSize
,
2216 TextureManagerTest::kMaxCubeMapTextureSize
,
2217 kUseDefaultTextures
));
2218 TestHelper::SetupTextureManagerInitExpectations(
2219 gl_
.get(), "", kUseDefaultTextures
);
2220 texture_manager1_
->Initialize();
2221 TestHelper::SetupTextureManagerInitExpectations(
2222 gl_
.get(), "", kUseDefaultTextures
);
2223 texture_manager2_
->Initialize();
2226 virtual void TearDown() {
2227 texture_manager2_
->Destroy(false);
2228 texture_manager2_
.reset();
2229 texture_manager1_
->Destroy(false);
2230 texture_manager1_
.reset();
2231 GpuServiceTest::TearDown();
2235 scoped_refptr
<FeatureInfo
> feature_info_
;
2236 scoped_refptr
<CountingMemoryTracker
> memory_tracker1_
;
2237 scoped_ptr
<TextureManager
> texture_manager1_
;
2238 scoped_refptr
<CountingMemoryTracker
> memory_tracker2_
;
2239 scoped_ptr
<TextureManager
> texture_manager2_
;
2242 TEST_F(SharedTextureTest
, DeleteTextures
) {
2243 scoped_refptr
<TextureRef
> ref1
= texture_manager1_
->CreateTexture(10, 10);
2244 scoped_refptr
<TextureRef
> ref2
=
2245 texture_manager2_
->Consume(20, ref1
->texture());
2246 EXPECT_CALL(*gl_
, DeleteTextures(1, _
))
2249 texture_manager1_
->RemoveTexture(10);
2250 testing::Mock::VerifyAndClearExpectations(gl_
.get());
2252 EXPECT_CALL(*gl_
, DeleteTextures(1, _
))
2254 .RetiresOnSaturation();
2256 texture_manager2_
->RemoveTexture(20);
2257 testing::Mock::VerifyAndClearExpectations(gl_
.get());
2260 TEST_F(SharedTextureTest
, TextureSafetyAccounting
) {
2261 EXPECT_FALSE(texture_manager1_
->HaveUnrenderableTextures());
2262 EXPECT_FALSE(texture_manager1_
->HaveUnsafeTextures());
2263 EXPECT_FALSE(texture_manager1_
->HaveUnclearedMips());
2264 EXPECT_FALSE(texture_manager2_
->HaveUnrenderableTextures());
2265 EXPECT_FALSE(texture_manager2_
->HaveUnsafeTextures());
2266 EXPECT_FALSE(texture_manager2_
->HaveUnclearedMips());
2268 // Newly created texture is renderable.
2269 scoped_refptr
<TextureRef
> ref1
= texture_manager1_
->CreateTexture(10, 10);
2270 EXPECT_FALSE(texture_manager1_
->HaveUnrenderableTextures());
2271 EXPECT_FALSE(texture_manager1_
->HaveUnsafeTextures());
2272 EXPECT_FALSE(texture_manager1_
->HaveUnclearedMips());
2274 // Associate new texture ref to other texture manager, should account for it
2276 scoped_refptr
<TextureRef
> ref2
=
2277 texture_manager2_
->Consume(20, ref1
->texture());
2278 EXPECT_FALSE(texture_manager2_
->HaveUnrenderableTextures());
2279 EXPECT_FALSE(texture_manager2_
->HaveUnsafeTextures());
2280 EXPECT_FALSE(texture_manager2_
->HaveUnclearedMips());
2282 // Make texture renderable but uncleared on one texture manager, should affect
2284 texture_manager1_
->SetTarget(ref1
.get(), GL_TEXTURE_2D
);
2285 EXPECT_TRUE(texture_manager1_
->HaveUnrenderableTextures());
2286 EXPECT_FALSE(texture_manager1_
->HaveUnsafeTextures());
2287 EXPECT_FALSE(texture_manager1_
->HaveUnclearedMips());
2288 EXPECT_TRUE(texture_manager2_
->HaveUnrenderableTextures());
2289 EXPECT_FALSE(texture_manager2_
->HaveUnsafeTextures());
2290 EXPECT_FALSE(texture_manager2_
->HaveUnclearedMips());
2292 texture_manager1_
->SetLevelInfo(ref1
.get(),
2303 EXPECT_FALSE(texture_manager1_
->HaveUnrenderableTextures());
2304 EXPECT_TRUE(texture_manager1_
->HaveUnsafeTextures());
2305 EXPECT_TRUE(texture_manager1_
->HaveUnclearedMips());
2306 EXPECT_FALSE(texture_manager2_
->HaveUnrenderableTextures());
2307 EXPECT_TRUE(texture_manager2_
->HaveUnsafeTextures());
2308 EXPECT_TRUE(texture_manager2_
->HaveUnclearedMips());
2310 // Make texture cleared on one texture manager, should affect other one.
2311 texture_manager1_
->SetLevelCleared(ref1
.get(), GL_TEXTURE_2D
, 0, true);
2312 EXPECT_FALSE(texture_manager1_
->HaveUnsafeTextures());
2313 EXPECT_FALSE(texture_manager1_
->HaveUnclearedMips());
2314 EXPECT_FALSE(texture_manager2_
->HaveUnsafeTextures());
2315 EXPECT_FALSE(texture_manager2_
->HaveUnclearedMips());
2317 EXPECT_CALL(*gl_
, DeleteTextures(1, _
))
2319 .RetiresOnSaturation();
2320 texture_manager1_
->RemoveTexture(10);
2321 texture_manager2_
->RemoveTexture(20);
2324 TEST_F(SharedTextureTest
, FBOCompletenessCheck
) {
2325 const GLenum kCompleteValue
= GL_FRAMEBUFFER_COMPLETE
;
2326 FramebufferManager
framebuffer_manager1(1, 1);
2327 texture_manager1_
->set_framebuffer_manager(&framebuffer_manager1
);
2328 FramebufferManager
framebuffer_manager2(1, 1);
2329 texture_manager2_
->set_framebuffer_manager(&framebuffer_manager2
);
2331 scoped_refptr
<TextureRef
> ref1
= texture_manager1_
->CreateTexture(10, 10);
2332 framebuffer_manager1
.CreateFramebuffer(10, 10);
2333 scoped_refptr
<Framebuffer
> framebuffer1
=
2334 framebuffer_manager1
.GetFramebuffer(10);
2335 framebuffer1
->AttachTexture(
2336 GL_COLOR_ATTACHMENT0
, ref1
.get(), GL_TEXTURE_2D
, 0, 0);
2337 EXPECT_FALSE(framebuffer_manager1
.IsComplete(framebuffer1
.get()));
2338 EXPECT_NE(kCompleteValue
, framebuffer1
->IsPossiblyComplete());
2340 // Make FBO complete in manager 1.
2341 texture_manager1_
->SetTarget(ref1
.get(), GL_TEXTURE_2D
);
2342 texture_manager1_
->SetLevelInfo(ref1
.get(),
2353 EXPECT_EQ(kCompleteValue
, framebuffer1
->IsPossiblyComplete());
2354 framebuffer_manager1
.MarkAsComplete(framebuffer1
.get());
2355 EXPECT_TRUE(framebuffer_manager1
.IsComplete(framebuffer1
.get()));
2357 // Share texture with manager 2.
2358 scoped_refptr
<TextureRef
> ref2
=
2359 texture_manager2_
->Consume(20, ref1
->texture());
2360 framebuffer_manager2
.CreateFramebuffer(20, 20);
2361 scoped_refptr
<Framebuffer
> framebuffer2
=
2362 framebuffer_manager2
.GetFramebuffer(20);
2363 framebuffer2
->AttachTexture(
2364 GL_COLOR_ATTACHMENT0
, ref2
.get(), GL_TEXTURE_2D
, 0, 0);
2365 EXPECT_FALSE(framebuffer_manager2
.IsComplete(framebuffer2
.get()));
2366 EXPECT_EQ(kCompleteValue
, framebuffer2
->IsPossiblyComplete());
2367 framebuffer_manager2
.MarkAsComplete(framebuffer2
.get());
2368 EXPECT_TRUE(framebuffer_manager2
.IsComplete(framebuffer2
.get()));
2370 // Change level for texture, both FBOs should be marked incomplete
2371 texture_manager1_
->SetLevelInfo(ref1
.get(),
2382 EXPECT_FALSE(framebuffer_manager1
.IsComplete(framebuffer1
.get()));
2383 EXPECT_EQ(kCompleteValue
, framebuffer1
->IsPossiblyComplete());
2384 framebuffer_manager1
.MarkAsComplete(framebuffer1
.get());
2385 EXPECT_TRUE(framebuffer_manager1
.IsComplete(framebuffer1
.get()));
2386 EXPECT_FALSE(framebuffer_manager2
.IsComplete(framebuffer2
.get()));
2387 EXPECT_EQ(kCompleteValue
, framebuffer2
->IsPossiblyComplete());
2388 framebuffer_manager2
.MarkAsComplete(framebuffer2
.get());
2389 EXPECT_TRUE(framebuffer_manager2
.IsComplete(framebuffer2
.get()));
2391 EXPECT_CALL(*gl_
, DeleteFramebuffersEXT(1, _
))
2393 .RetiresOnSaturation();
2394 framebuffer_manager1
.RemoveFramebuffer(10);
2395 framebuffer_manager2
.RemoveFramebuffer(20);
2396 EXPECT_CALL(*gl_
, DeleteTextures(1, _
))
2398 .RetiresOnSaturation();
2399 texture_manager1_
->RemoveTexture(10);
2400 texture_manager2_
->RemoveTexture(20);
2403 TEST_F(SharedTextureTest
, Memory
) {
2404 size_t initial_memory1
= memory_tracker1_
->GetSize(MemoryTracker::kUnmanaged
);
2405 size_t initial_memory2
= memory_tracker2_
->GetSize(MemoryTracker::kUnmanaged
);
2407 // Newly created texture is unrenderable.
2408 scoped_refptr
<TextureRef
> ref1
= texture_manager1_
->CreateTexture(10, 10);
2409 texture_manager1_
->SetTarget(ref1
.get(), GL_TEXTURE_2D
);
2410 texture_manager1_
->SetLevelInfo(ref1
.get(),
2422 EXPECT_LT(0u, ref1
->texture()->estimated_size());
2423 EXPECT_EQ(initial_memory1
+ ref1
->texture()->estimated_size(),
2424 memory_tracker1_
->GetSize(MemoryTracker::kUnmanaged
));
2426 // Associate new texture ref to other texture manager, it doesn't account for
2427 // the texture memory, the first memory tracker still has it.
2428 scoped_refptr
<TextureRef
> ref2
=
2429 texture_manager2_
->Consume(20, ref1
->texture());
2430 EXPECT_EQ(initial_memory1
+ ref1
->texture()->estimated_size(),
2431 memory_tracker1_
->GetSize(MemoryTracker::kUnmanaged
));
2432 EXPECT_EQ(initial_memory2
,
2433 memory_tracker2_
->GetSize(MemoryTracker::kUnmanaged
));
2435 // Delete the texture, memory should go to the remaining tracker.
2436 texture_manager1_
->RemoveTexture(10);
2438 EXPECT_EQ(initial_memory1
,
2439 memory_tracker1_
->GetSize(MemoryTracker::kUnmanaged
));
2440 EXPECT_EQ(initial_memory2
+ ref2
->texture()->estimated_size(),
2441 memory_tracker2_
->GetSize(MemoryTracker::kUnmanaged
));
2443 EXPECT_CALL(*gl_
, DeleteTextures(1, _
))
2445 .RetiresOnSaturation();
2447 texture_manager2_
->RemoveTexture(20);
2448 EXPECT_EQ(initial_memory2
,
2449 memory_tracker2_
->GetSize(MemoryTracker::kUnmanaged
));
2452 TEST_F(SharedTextureTest
, Images
) {
2453 scoped_refptr
<TextureRef
> ref1
= texture_manager1_
->CreateTexture(10, 10);
2454 scoped_refptr
<TextureRef
> ref2
=
2455 texture_manager2_
->Consume(20, ref1
->texture());
2457 texture_manager1_
->SetTarget(ref1
.get(), GL_TEXTURE_2D
);
2458 texture_manager1_
->SetLevelInfo(ref1
.get(),
2469 EXPECT_FALSE(ref1
->texture()->HasImages());
2470 EXPECT_FALSE(ref2
->texture()->HasImages());
2471 EXPECT_FALSE(texture_manager1_
->HaveImages());
2472 EXPECT_FALSE(texture_manager2_
->HaveImages());
2473 scoped_refptr
<gfx::GLImage
> image1(new gfx::GLImageStub
);
2474 texture_manager1_
->SetLevelImage(ref1
.get(), GL_TEXTURE_2D
, 1, image1
.get());
2475 EXPECT_TRUE(ref1
->texture()->HasImages());
2476 EXPECT_TRUE(ref2
->texture()->HasImages());
2477 EXPECT_TRUE(texture_manager1_
->HaveImages());
2478 EXPECT_TRUE(texture_manager2_
->HaveImages());
2479 scoped_refptr
<gfx::GLImage
> image2(new gfx::GLImageStub
);
2480 texture_manager1_
->SetLevelImage(ref1
.get(), GL_TEXTURE_2D
, 1, image2
.get());
2481 EXPECT_TRUE(ref1
->texture()->HasImages());
2482 EXPECT_TRUE(ref2
->texture()->HasImages());
2483 EXPECT_TRUE(texture_manager1_
->HaveImages());
2484 EXPECT_TRUE(texture_manager2_
->HaveImages());
2485 texture_manager1_
->SetLevelInfo(ref1
.get(),
2496 EXPECT_FALSE(ref1
->texture()->HasImages());
2497 EXPECT_FALSE(ref2
->texture()->HasImages());
2498 EXPECT_FALSE(texture_manager1_
->HaveImages());
2499 EXPECT_FALSE(texture_manager1_
->HaveImages());
2501 EXPECT_CALL(*gl_
, DeleteTextures(1, _
))
2503 .RetiresOnSaturation();
2504 texture_manager1_
->RemoveTexture(10);
2505 texture_manager2_
->RemoveTexture(20);
2508 } // namespace gles2