1 // Copyright 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 "cc/resources/prioritized_resource.h"
9 #include "cc/resources/prioritized_resource_manager.h"
10 #include "cc/resources/resource.h"
11 #include "cc/resources/resource_provider.h"
12 #include "cc/test/fake_output_surface.h"
13 #include "cc/test/fake_output_surface_client.h"
14 #include "cc/test/fake_proxy.h"
15 #include "cc/test/test_shared_bitmap_manager.h"
16 #include "cc/test/tiled_layer_test_common.h"
17 #include "cc/trees/single_thread_proxy.h" // For DebugScopedSetImplThread
18 #include "testing/gtest/include/gtest/gtest.h"
22 class PrioritizedResourceTest
: public testing::Test
{
24 PrioritizedResourceTest()
25 : texture_size_(256, 256),
26 texture_format_(RGBA_8888
),
27 output_surface_(FakeOutputSurface::Create3d()) {
28 DebugScopedSetImplThread
impl_thread(&proxy_
);
29 CHECK(output_surface_
->BindToClient(&output_surface_client_
));
30 shared_bitmap_manager_
.reset(new TestSharedBitmapManager());
31 resource_provider_
= ResourceProvider::Create(
32 output_surface_
.get(), shared_bitmap_manager_
.get(), 0, false, 1,
36 virtual ~PrioritizedResourceTest() {
37 DebugScopedSetImplThread
impl_thread(&proxy_
);
38 resource_provider_
.reset();
41 size_t TexturesMemorySize(size_t texture_count
) {
42 return Resource::MemorySizeBytes(texture_size_
, texture_format_
) *
46 scoped_ptr
<PrioritizedResourceManager
> CreateManager(size_t max_textures
) {
47 scoped_ptr
<PrioritizedResourceManager
> manager
=
48 PrioritizedResourceManager::Create(&proxy_
);
49 manager
->SetMaxMemoryLimitBytes(TexturesMemorySize(max_textures
));
50 return manager
.Pass();
53 bool ValidateTexture(PrioritizedResource
* texture
,
55 ResourceManagerAssertInvariants(texture
->resource_manager());
57 texture
->RequestLate();
58 ResourceManagerAssertInvariants(texture
->resource_manager());
59 DebugScopedSetImplThreadAndMainThreadBlocked
60 impl_thread_and_main_thread_blocked(&proxy_
);
61 bool success
= texture
->can_acquire_backing_texture();
63 texture
->AcquireBackingTexture(resource_provider());
67 void PrioritizeTexturesAndBackings(
68 PrioritizedResourceManager
* resource_manager
) {
69 resource_manager
->PrioritizeTextures();
70 ResourceManagerUpdateBackingsPriorities(resource_manager
);
73 void ResourceManagerUpdateBackingsPriorities(
74 PrioritizedResourceManager
* resource_manager
) {
75 DebugScopedSetImplThreadAndMainThreadBlocked
76 impl_thread_and_main_thread_blocked(&proxy_
);
77 resource_manager
->PushTexturePrioritiesToBackings();
80 ResourceProvider
* resource_provider() { return resource_provider_
.get(); }
82 void ResourceManagerAssertInvariants(
83 PrioritizedResourceManager
* resource_manager
) {
84 DebugScopedSetImplThreadAndMainThreadBlocked
85 impl_thread_and_main_thread_blocked(&proxy_
);
86 resource_manager
->AssertInvariants();
89 bool TextureBackingIsAbovePriorityCutoff(PrioritizedResource
* texture
) {
90 return texture
->backing()->
91 was_above_priority_cutoff_at_last_priority_update();
94 size_t EvictedBackingCount(PrioritizedResourceManager
* resource_manager
) {
95 return resource_manager
->evicted_backings_
.size();
98 std::vector
<unsigned> BackingResources(
99 PrioritizedResourceManager
* resource_manager
) {
100 std::vector
<unsigned> resources
;
101 for (PrioritizedResourceManager::BackingList::iterator it
=
102 resource_manager
->backings_
.begin();
103 it
!= resource_manager
->backings_
.end();
105 resources
.push_back((*it
)->id());
111 const gfx::Size texture_size_
;
112 const ResourceFormat texture_format_
;
113 FakeOutputSurfaceClient output_surface_client_
;
114 scoped_ptr
<OutputSurface
> output_surface_
;
115 scoped_ptr
<SharedBitmapManager
> shared_bitmap_manager_
;
116 scoped_ptr
<ResourceProvider
> resource_provider_
;
121 TEST_F(PrioritizedResourceTest
, RequestTextureExceedingMaxLimit
) {
122 const size_t kMaxTextures
= 8;
123 scoped_ptr
<PrioritizedResourceManager
> resource_manager
=
124 CreateManager(kMaxTextures
);
126 // Create textures for double our memory limit.
127 scoped_ptr
<PrioritizedResource
> textures
[kMaxTextures
* 2];
129 for (size_t i
= 0; i
< kMaxTextures
* 2; ++i
)
131 resource_manager
->CreateTexture(texture_size_
, texture_format_
);
133 // Set decreasing priorities
134 for (size_t i
= 0; i
< kMaxTextures
* 2; ++i
)
135 textures
[i
]->set_request_priority(100 + i
);
137 // Only lower half should be available.
138 PrioritizeTexturesAndBackings(resource_manager
.get());
139 EXPECT_TRUE(ValidateTexture(textures
[0].get(), false));
140 EXPECT_TRUE(ValidateTexture(textures
[7].get(), false));
141 EXPECT_FALSE(ValidateTexture(textures
[8].get(), false));
142 EXPECT_FALSE(ValidateTexture(textures
[15].get(), false));
144 // Set increasing priorities
145 for (size_t i
= 0; i
< kMaxTextures
* 2; ++i
)
146 textures
[i
]->set_request_priority(100 - i
);
148 // Only upper half should be available.
149 PrioritizeTexturesAndBackings(resource_manager
.get());
150 EXPECT_FALSE(ValidateTexture(textures
[0].get(), false));
151 EXPECT_FALSE(ValidateTexture(textures
[7].get(), false));
152 EXPECT_TRUE(ValidateTexture(textures
[8].get(), false));
153 EXPECT_TRUE(ValidateTexture(textures
[15].get(), false));
155 EXPECT_EQ(TexturesMemorySize(kMaxTextures
),
156 resource_manager
->MemoryAboveCutoffBytes());
157 EXPECT_LE(resource_manager
->MemoryUseBytes(),
158 resource_manager
->MemoryAboveCutoffBytes());
159 EXPECT_EQ(TexturesMemorySize(2*kMaxTextures
),
160 resource_manager
->MaxMemoryNeededBytes());
162 DebugScopedSetImplThreadAndMainThreadBlocked
163 impl_thread_and_main_thread_blocked(&proxy_
);
164 resource_manager
->ClearAllMemory(resource_provider());
167 TEST_F(PrioritizedResourceTest
, ChangeMemoryLimits
) {
168 const size_t kMaxTextures
= 8;
169 scoped_ptr
<PrioritizedResourceManager
> resource_manager
=
170 CreateManager(kMaxTextures
);
171 scoped_ptr
<PrioritizedResource
> textures
[kMaxTextures
];
173 for (size_t i
= 0; i
< kMaxTextures
; ++i
) {
175 resource_manager
->CreateTexture(texture_size_
, texture_format_
);
177 for (size_t i
= 0; i
< kMaxTextures
; ++i
)
178 textures
[i
]->set_request_priority(100 + i
);
180 // Set max limit to 8 textures
181 resource_manager
->SetMaxMemoryLimitBytes(TexturesMemorySize(8));
182 PrioritizeTexturesAndBackings(resource_manager
.get());
183 for (size_t i
= 0; i
< kMaxTextures
; ++i
)
184 ValidateTexture(textures
[i
].get(), false);
186 DebugScopedSetImplThreadAndMainThreadBlocked
187 impl_thread_and_main_thread_blocked(&proxy_
);
188 resource_manager
->ReduceMemory(resource_provider());
191 EXPECT_EQ(TexturesMemorySize(8), resource_manager
->MemoryAboveCutoffBytes());
192 EXPECT_LE(resource_manager
->MemoryUseBytes(),
193 resource_manager
->MemoryAboveCutoffBytes());
195 // Set max limit to 5 textures
196 resource_manager
->SetMaxMemoryLimitBytes(TexturesMemorySize(5));
197 PrioritizeTexturesAndBackings(resource_manager
.get());
198 for (size_t i
= 0; i
< kMaxTextures
; ++i
)
199 EXPECT_EQ(ValidateTexture(textures
[i
].get(), false), i
< 5);
201 DebugScopedSetImplThreadAndMainThreadBlocked
202 impl_thread_and_main_thread_blocked(&proxy_
);
203 resource_manager
->ReduceMemory(resource_provider());
206 EXPECT_EQ(TexturesMemorySize(5), resource_manager
->MemoryAboveCutoffBytes());
207 EXPECT_LE(resource_manager
->MemoryUseBytes(),
208 resource_manager
->MemoryAboveCutoffBytes());
209 EXPECT_EQ(TexturesMemorySize(kMaxTextures
),
210 resource_manager
->MaxMemoryNeededBytes());
212 // Set max limit to 4 textures
213 resource_manager
->SetMaxMemoryLimitBytes(TexturesMemorySize(4));
214 PrioritizeTexturesAndBackings(resource_manager
.get());
215 for (size_t i
= 0; i
< kMaxTextures
; ++i
)
216 EXPECT_EQ(ValidateTexture(textures
[i
].get(), false), i
< 4);
218 DebugScopedSetImplThreadAndMainThreadBlocked
219 impl_thread_and_main_thread_blocked(&proxy_
);
220 resource_manager
->ReduceMemory(resource_provider());
223 EXPECT_EQ(TexturesMemorySize(4), resource_manager
->MemoryAboveCutoffBytes());
224 EXPECT_LE(resource_manager
->MemoryUseBytes(),
225 resource_manager
->MemoryAboveCutoffBytes());
226 EXPECT_EQ(TexturesMemorySize(kMaxTextures
),
227 resource_manager
->MaxMemoryNeededBytes());
229 DebugScopedSetImplThreadAndMainThreadBlocked
230 impl_thread_and_main_thread_blocked(&proxy_
);
231 resource_manager
->ClearAllMemory(resource_provider());
234 TEST_F(PrioritizedResourceTest
, ReduceWastedMemory
) {
235 const size_t kMaxTextures
= 20;
236 scoped_ptr
<PrioritizedResourceManager
> resource_manager
=
237 CreateManager(kMaxTextures
);
238 scoped_ptr
<PrioritizedResource
> textures
[kMaxTextures
];
240 for (size_t i
= 0; i
< kMaxTextures
; ++i
) {
242 resource_manager
->CreateTexture(texture_size_
, texture_format_
);
244 for (size_t i
= 0; i
< kMaxTextures
; ++i
)
245 textures
[i
]->set_request_priority(100 + i
);
247 // Set the memory limit to the max number of textures.
248 resource_manager
->SetMaxMemoryLimitBytes(TexturesMemorySize(kMaxTextures
));
249 PrioritizeTexturesAndBackings(resource_manager
.get());
251 // Create backings and textures for all of the textures.
252 for (size_t i
= 0; i
< kMaxTextures
; ++i
) {
253 ValidateTexture(textures
[i
].get(), false);
256 DebugScopedSetImplThreadAndMainThreadBlocked
257 impl_thread_and_main_thread_blocked(&proxy_
);
258 uint8_t image
[4] = {0};
259 textures
[i
]->SetPixels(resource_provider_
.get(),
267 DebugScopedSetImplThreadAndMainThreadBlocked
268 impl_thread_and_main_thread_blocked(&proxy_
);
269 resource_manager
->ReduceMemory(resource_provider());
272 // 20 textures have backings allocated.
273 EXPECT_EQ(TexturesMemorySize(20), resource_manager
->MemoryUseBytes());
275 // Destroy one texture, not enough is wasted to cause cleanup.
276 textures
[0] = scoped_ptr
<PrioritizedResource
>();
277 PrioritizeTexturesAndBackings(resource_manager
.get());
279 DebugScopedSetImplThreadAndMainThreadBlocked
280 impl_thread_and_main_thread_blocked(&proxy_
);
281 resource_manager
->UpdateBackingsState(resource_provider());
282 resource_manager
->ReduceWastedMemory(resource_provider());
284 EXPECT_EQ(TexturesMemorySize(20), resource_manager
->MemoryUseBytes());
286 // Destroy half the textures, leaving behind the backings. Now a cleanup
288 for (size_t i
= 0; i
< kMaxTextures
/ 2; ++i
)
289 textures
[i
] = scoped_ptr
<PrioritizedResource
>();
290 PrioritizeTexturesAndBackings(resource_manager
.get());
292 DebugScopedSetImplThreadAndMainThreadBlocked
293 impl_thread_and_main_thread_blocked(&proxy_
);
294 resource_manager
->UpdateBackingsState(resource_provider());
295 resource_manager
->ReduceWastedMemory(resource_provider());
297 EXPECT_GT(TexturesMemorySize(20), resource_manager
->MemoryUseBytes());
299 DebugScopedSetImplThreadAndMainThreadBlocked
300 impl_thread_and_main_thread_blocked(&proxy_
);
301 resource_manager
->ClearAllMemory(resource_provider());
304 TEST_F(PrioritizedResourceTest
, InUseNotWastedMemory
) {
305 const size_t kMaxTextures
= 20;
306 scoped_ptr
<PrioritizedResourceManager
> resource_manager
=
307 CreateManager(kMaxTextures
);
308 scoped_ptr
<PrioritizedResource
> textures
[kMaxTextures
];
310 for (size_t i
= 0; i
< kMaxTextures
; ++i
) {
312 resource_manager
->CreateTexture(texture_size_
, texture_format_
);
314 for (size_t i
= 0; i
< kMaxTextures
; ++i
)
315 textures
[i
]->set_request_priority(100 + i
);
317 // Set the memory limit to the max number of textures.
318 resource_manager
->SetMaxMemoryLimitBytes(TexturesMemorySize(kMaxTextures
));
319 PrioritizeTexturesAndBackings(resource_manager
.get());
321 // Create backings and textures for all of the textures.
322 for (size_t i
= 0; i
< kMaxTextures
; ++i
) {
323 ValidateTexture(textures
[i
].get(), false);
326 DebugScopedSetImplThreadAndMainThreadBlocked
327 impl_thread_and_main_thread_blocked(&proxy_
);
328 uint8_t image
[4] = {0};
329 textures
[i
]->SetPixels(resource_provider_
.get(),
337 DebugScopedSetImplThreadAndMainThreadBlocked
338 impl_thread_and_main_thread_blocked(&proxy_
);
339 resource_manager
->ReduceMemory(resource_provider());
342 // 20 textures have backings allocated.
343 EXPECT_EQ(TexturesMemorySize(20), resource_manager
->MemoryUseBytes());
345 // Send half the textures to a parent compositor.
346 ResourceProvider::ResourceIdArray to_send
;
347 TransferableResourceArray transferable
;
348 for (size_t i
= 0; i
< kMaxTextures
/ 2; ++i
)
349 to_send
.push_back(textures
[i
]->resource_id());
350 resource_provider_
->PrepareSendToParent(to_send
, &transferable
);
352 // Destroy half the textures, leaving behind the backings. The backings are
353 // sent to a parent compositor though, so they should not be considered wasted
354 // and a cleanup should not happen.
355 for (size_t i
= 0; i
< kMaxTextures
/ 2; ++i
)
356 textures
[i
] = scoped_ptr
<PrioritizedResource
>();
357 PrioritizeTexturesAndBackings(resource_manager
.get());
359 DebugScopedSetImplThreadAndMainThreadBlocked
360 impl_thread_and_main_thread_blocked(&proxy_
);
361 resource_manager
->UpdateBackingsState(resource_provider());
362 resource_manager
->ReduceWastedMemory(resource_provider());
364 EXPECT_EQ(TexturesMemorySize(20), resource_manager
->MemoryUseBytes());
366 // Receive the textures back from the parent compositor. Now a cleanup should
368 ReturnedResourceArray returns
;
369 TransferableResource::ReturnResources(transferable
, &returns
);
370 resource_provider_
->ReceiveReturnsFromParent(returns
);
372 DebugScopedSetImplThreadAndMainThreadBlocked
373 impl_thread_and_main_thread_blocked(&proxy_
);
374 resource_manager
->UpdateBackingsState(resource_provider());
375 resource_manager
->ReduceWastedMemory(resource_provider());
377 EXPECT_GT(TexturesMemorySize(20), resource_manager
->MemoryUseBytes());
379 DebugScopedSetImplThreadAndMainThreadBlocked
380 impl_thread_and_main_thread_blocked(&proxy_
);
381 resource_manager
->ClearAllMemory(resource_provider());
384 TEST_F(PrioritizedResourceTest
, ChangePriorityCutoff
) {
385 const size_t kMaxTextures
= 8;
386 scoped_ptr
<PrioritizedResourceManager
> resource_manager
=
387 CreateManager(kMaxTextures
);
388 scoped_ptr
<PrioritizedResource
> textures
[kMaxTextures
];
390 for (size_t i
= 0; i
< kMaxTextures
; ++i
) {
392 resource_manager
->CreateTexture(texture_size_
, texture_format_
);
394 for (size_t i
= 0; i
< kMaxTextures
; ++i
)
395 textures
[i
]->set_request_priority(100 + i
);
397 // Set the cutoff to drop two textures. Try to request_late on all textures,
398 // and make sure that request_late doesn't work on a texture with equal
399 // priority to the cutoff.
400 resource_manager
->SetMaxMemoryLimitBytes(TexturesMemorySize(8));
401 resource_manager
->SetExternalPriorityCutoff(106);
402 PrioritizeTexturesAndBackings(resource_manager
.get());
403 for (size_t i
= 0; i
< kMaxTextures
; ++i
)
404 EXPECT_EQ(ValidateTexture(textures
[i
].get(), true), i
< 6);
406 DebugScopedSetImplThreadAndMainThreadBlocked
407 impl_thread_and_main_thread_blocked(&proxy_
);
408 resource_manager
->ReduceMemory(resource_provider());
410 EXPECT_EQ(TexturesMemorySize(6), resource_manager
->MemoryAboveCutoffBytes());
411 EXPECT_LE(resource_manager
->MemoryUseBytes(),
412 resource_manager
->MemoryAboveCutoffBytes());
414 // Set the cutoff to drop two more textures.
415 resource_manager
->SetExternalPriorityCutoff(104);
416 PrioritizeTexturesAndBackings(resource_manager
.get());
417 for (size_t i
= 0; i
< kMaxTextures
; ++i
)
418 EXPECT_EQ(ValidateTexture(textures
[i
].get(), false), i
< 4);
420 DebugScopedSetImplThreadAndMainThreadBlocked
421 impl_thread_and_main_thread_blocked(&proxy_
);
422 resource_manager
->ReduceMemory(resource_provider());
424 EXPECT_EQ(TexturesMemorySize(4), resource_manager
->MemoryAboveCutoffBytes());
426 // Do a one-time eviction for one more texture based on priority cutoff
427 resource_manager
->UnlinkAndClearEvictedBackings();
429 DebugScopedSetImplThreadAndMainThreadBlocked
430 impl_thread_and_main_thread_blocked(&proxy_
);
431 resource_manager
->ReduceMemoryOnImplThread(
432 TexturesMemorySize(8), 104, resource_provider());
433 EXPECT_EQ(0u, EvictedBackingCount(resource_manager
.get()));
434 resource_manager
->ReduceMemoryOnImplThread(
435 TexturesMemorySize(8), 103, resource_provider());
436 EXPECT_EQ(1u, EvictedBackingCount(resource_manager
.get()));
438 resource_manager
->UnlinkAndClearEvictedBackings();
439 EXPECT_EQ(TexturesMemorySize(3), resource_manager
->MemoryUseBytes());
441 // Re-allocate the the texture after the one-time drop.
442 PrioritizeTexturesAndBackings(resource_manager
.get());
443 for (size_t i
= 0; i
< kMaxTextures
; ++i
)
444 EXPECT_EQ(ValidateTexture(textures
[i
].get(), false), i
< 4);
446 DebugScopedSetImplThreadAndMainThreadBlocked
447 impl_thread_and_main_thread_blocked(&proxy_
);
448 resource_manager
->ReduceMemory(resource_provider());
450 EXPECT_EQ(TexturesMemorySize(4), resource_manager
->MemoryAboveCutoffBytes());
452 DebugScopedSetImplThreadAndMainThreadBlocked
453 impl_thread_and_main_thread_blocked(&proxy_
);
454 resource_manager
->ClearAllMemory(resource_provider());
457 TEST_F(PrioritizedResourceTest
, EvictingTexturesInParent
) {
458 const size_t kMaxTextures
= 8;
459 scoped_ptr
<PrioritizedResourceManager
> resource_manager
=
460 CreateManager(kMaxTextures
);
461 scoped_ptr
<PrioritizedResource
> textures
[kMaxTextures
];
462 unsigned texture_resource_ids
[kMaxTextures
];
464 for (size_t i
= 0; i
< kMaxTextures
; ++i
) {
466 resource_manager
->CreateTexture(texture_size_
, texture_format_
);
467 textures
[i
]->set_request_priority(100 + i
);
470 PrioritizeTexturesAndBackings(resource_manager
.get());
471 for (size_t i
= 0; i
< kMaxTextures
; ++i
) {
472 EXPECT_TRUE(ValidateTexture(textures
[i
].get(), true));
475 DebugScopedSetImplThreadAndMainThreadBlocked
476 impl_thread_and_main_thread_blocked(&proxy_
);
477 uint8_t image
[4] = {0};
478 textures
[i
]->SetPixels(resource_provider_
.get(),
486 DebugScopedSetImplThreadAndMainThreadBlocked
487 impl_thread_and_main_thread_blocked(&proxy_
);
488 resource_manager
->ReduceMemory(resource_provider());
490 EXPECT_EQ(TexturesMemorySize(8), resource_manager
->MemoryAboveCutoffBytes());
492 for (size_t i
= 0; i
< 8; ++i
)
493 texture_resource_ids
[i
] = textures
[i
]->resource_id();
495 // Evict four textures. It will be the last four.
497 DebugScopedSetImplThreadAndMainThreadBlocked
498 impl_thread_and_main_thread_blocked(&proxy_
);
499 resource_manager
->ReduceMemoryOnImplThread(
500 TexturesMemorySize(4), 200, resource_provider());
502 EXPECT_EQ(4u, EvictedBackingCount(resource_manager
.get()));
504 // The last four backings are evicted.
505 std::vector
<unsigned> remaining
= BackingResources(resource_manager
.get());
506 EXPECT_TRUE(std::find(remaining
.begin(),
508 texture_resource_ids
[0]) != remaining
.end());
509 EXPECT_TRUE(std::find(remaining
.begin(),
511 texture_resource_ids
[1]) != remaining
.end());
512 EXPECT_TRUE(std::find(remaining
.begin(),
514 texture_resource_ids
[2]) != remaining
.end());
515 EXPECT_TRUE(std::find(remaining
.begin(),
517 texture_resource_ids
[3]) != remaining
.end());
519 resource_manager
->UnlinkAndClearEvictedBackings();
520 EXPECT_EQ(TexturesMemorySize(4), resource_manager
->MemoryUseBytes());
522 // Re-allocate the the texture after the eviction.
523 PrioritizeTexturesAndBackings(resource_manager
.get());
524 for (size_t i
= 0; i
< kMaxTextures
; ++i
) {
525 EXPECT_TRUE(ValidateTexture(textures
[i
].get(), true));
528 DebugScopedSetImplThreadAndMainThreadBlocked
529 impl_thread_and_main_thread_blocked(&proxy_
);
530 uint8_t image
[4] = {0};
531 textures
[i
]->SetPixels(resource_provider_
.get(),
539 DebugScopedSetImplThreadAndMainThreadBlocked
540 impl_thread_and_main_thread_blocked(&proxy_
);
541 resource_manager
->ReduceMemory(resource_provider());
543 EXPECT_EQ(TexturesMemorySize(8), resource_manager
->MemoryAboveCutoffBytes());
545 // Send the last two of the textures to a parent compositor.
546 ResourceProvider::ResourceIdArray to_send
;
547 TransferableResourceArray transferable
;
548 for (size_t i
= 6; i
< 8; ++i
)
549 to_send
.push_back(textures
[i
]->resource_id());
550 resource_provider_
->PrepareSendToParent(to_send
, &transferable
);
552 // Set the last two textures to be tied for prioity with the two
553 // before them. Being sent to the parent will break the tie.
554 textures
[4]->set_request_priority(100 + 4);
555 textures
[5]->set_request_priority(100 + 5);
556 textures
[6]->set_request_priority(100 + 4);
557 textures
[7]->set_request_priority(100 + 5);
559 for (size_t i
= 0; i
< 8; ++i
)
560 texture_resource_ids
[i
] = textures
[i
]->resource_id();
562 // Drop all the textures. Now we have backings that can be recycled.
563 for (size_t i
= 0; i
< 8; ++i
)
565 PrioritizeTexturesAndBackings(resource_manager
.get());
567 // The next commit finishes.
569 DebugScopedSetImplThreadAndMainThreadBlocked
570 impl_thread_and_main_thread_blocked(&proxy_
);
571 resource_manager
->UpdateBackingsState(resource_provider());
574 // Evict four textures. It would be the last four again, except that 2 of them
575 // are sent to the parent, so they are evicted last.
577 DebugScopedSetImplThreadAndMainThreadBlocked
578 impl_thread_and_main_thread_blocked(&proxy_
);
579 resource_manager
->ReduceMemoryOnImplThread(
580 TexturesMemorySize(4), 200, resource_provider());
582 EXPECT_EQ(4u, EvictedBackingCount(resource_manager
.get()));
583 // The last 2 backings remain this time.
584 std::vector
<unsigned> remaining
= BackingResources(resource_manager
.get());
585 EXPECT_TRUE(std::find(remaining
.begin(),
587 texture_resource_ids
[6]) == remaining
.end());
588 EXPECT_TRUE(std::find(remaining
.begin(),
590 texture_resource_ids
[7]) == remaining
.end());
592 resource_manager
->UnlinkAndClearEvictedBackings();
593 EXPECT_EQ(TexturesMemorySize(4), resource_manager
->MemoryUseBytes());
595 DebugScopedSetImplThreadAndMainThreadBlocked
596 impl_thread_and_main_thread_blocked(&proxy_
);
597 resource_manager
->ClearAllMemory(resource_provider());
600 TEST_F(PrioritizedResourceTest
, ResourceManagerPartialUpdateTextures
) {
601 const size_t kMaxTextures
= 4;
602 const size_t kNumTextures
= 4;
603 scoped_ptr
<PrioritizedResourceManager
> resource_manager
=
604 CreateManager(kMaxTextures
);
605 scoped_ptr
<PrioritizedResource
> textures
[kNumTextures
];
606 scoped_ptr
<PrioritizedResource
> more_textures
[kNumTextures
];
608 for (size_t i
= 0; i
< kNumTextures
; ++i
) {
610 resource_manager
->CreateTexture(texture_size_
, texture_format_
);
612 resource_manager
->CreateTexture(texture_size_
, texture_format_
);
615 for (size_t i
= 0; i
< kNumTextures
; ++i
)
616 textures
[i
]->set_request_priority(200 + i
);
617 PrioritizeTexturesAndBackings(resource_manager
.get());
619 // Allocate textures which are currently high priority.
620 EXPECT_TRUE(ValidateTexture(textures
[0].get(), false));
621 EXPECT_TRUE(ValidateTexture(textures
[1].get(), false));
622 EXPECT_TRUE(ValidateTexture(textures
[2].get(), false));
623 EXPECT_TRUE(ValidateTexture(textures
[3].get(), false));
625 EXPECT_TRUE(textures
[0]->have_backing_texture());
626 EXPECT_TRUE(textures
[1]->have_backing_texture());
627 EXPECT_TRUE(textures
[2]->have_backing_texture());
628 EXPECT_TRUE(textures
[3]->have_backing_texture());
630 for (size_t i
= 0; i
< kNumTextures
; ++i
)
631 more_textures
[i
]->set_request_priority(100 + i
);
632 PrioritizeTexturesAndBackings(resource_manager
.get());
634 // Textures are now below cutoff.
635 EXPECT_FALSE(ValidateTexture(textures
[0].get(), false));
636 EXPECT_FALSE(ValidateTexture(textures
[1].get(), false));
637 EXPECT_FALSE(ValidateTexture(textures
[2].get(), false));
638 EXPECT_FALSE(ValidateTexture(textures
[3].get(), false));
640 // But they are still valid to use.
641 EXPECT_TRUE(textures
[0]->have_backing_texture());
642 EXPECT_TRUE(textures
[1]->have_backing_texture());
643 EXPECT_TRUE(textures
[2]->have_backing_texture());
644 EXPECT_TRUE(textures
[3]->have_backing_texture());
646 // Higher priority textures are finally needed.
647 EXPECT_TRUE(ValidateTexture(more_textures
[0].get(), false));
648 EXPECT_TRUE(ValidateTexture(more_textures
[1].get(), false));
649 EXPECT_TRUE(ValidateTexture(more_textures
[2].get(), false));
650 EXPECT_TRUE(ValidateTexture(more_textures
[3].get(), false));
652 // Lower priority have been fully evicted.
653 EXPECT_FALSE(textures
[0]->have_backing_texture());
654 EXPECT_FALSE(textures
[1]->have_backing_texture());
655 EXPECT_FALSE(textures
[2]->have_backing_texture());
656 EXPECT_FALSE(textures
[3]->have_backing_texture());
658 DebugScopedSetImplThreadAndMainThreadBlocked
659 impl_thread_and_main_thread_blocked(&proxy_
);
660 resource_manager
->ClearAllMemory(resource_provider());
663 TEST_F(PrioritizedResourceTest
, ResourceManagerPrioritiesAreEqual
) {
664 const size_t kMaxTextures
= 16;
665 scoped_ptr
<PrioritizedResourceManager
> resource_manager
=
666 CreateManager(kMaxTextures
);
667 scoped_ptr
<PrioritizedResource
> textures
[kMaxTextures
];
669 for (size_t i
= 0; i
< kMaxTextures
; ++i
) {
671 resource_manager
->CreateTexture(texture_size_
, texture_format_
);
674 // All 16 textures have the same priority except 2 higher priority.
675 for (size_t i
= 0; i
< kMaxTextures
; ++i
)
676 textures
[i
]->set_request_priority(100);
677 textures
[0]->set_request_priority(99);
678 textures
[1]->set_request_priority(99);
680 // Set max limit to 8 textures
681 resource_manager
->SetMaxMemoryLimitBytes(TexturesMemorySize(8));
682 PrioritizeTexturesAndBackings(resource_manager
.get());
684 // The two high priority textures should be available, others should not.
685 for (size_t i
= 0; i
< 2; ++i
)
686 EXPECT_TRUE(ValidateTexture(textures
[i
].get(), false));
687 for (size_t i
= 2; i
< kMaxTextures
; ++i
)
688 EXPECT_FALSE(ValidateTexture(textures
[i
].get(), false));
689 EXPECT_EQ(TexturesMemorySize(2), resource_manager
->MemoryAboveCutoffBytes());
690 EXPECT_LE(resource_manager
->MemoryUseBytes(),
691 resource_manager
->MemoryAboveCutoffBytes());
693 // Manually reserving textures should only succeed on the higher priority
694 // textures, and on remaining textures up to the memory limit.
695 for (size_t i
= 0; i
< 8; i
++)
696 EXPECT_TRUE(ValidateTexture(textures
[i
].get(), true));
697 for (size_t i
= 9; i
< kMaxTextures
; i
++)
698 EXPECT_FALSE(ValidateTexture(textures
[i
].get(), true));
699 EXPECT_EQ(TexturesMemorySize(8), resource_manager
->MemoryAboveCutoffBytes());
700 EXPECT_LE(resource_manager
->MemoryUseBytes(),
701 resource_manager
->MemoryAboveCutoffBytes());
703 DebugScopedSetImplThreadAndMainThreadBlocked
704 impl_thread_and_main_thread_blocked(&proxy_
);
705 resource_manager
->ClearAllMemory(resource_provider());
708 TEST_F(PrioritizedResourceTest
, ResourceManagerDestroyedFirst
) {
709 scoped_ptr
<PrioritizedResourceManager
> resource_manager
= CreateManager(1);
710 scoped_ptr
<PrioritizedResource
> texture
=
711 resource_manager
->CreateTexture(texture_size_
, texture_format_
);
713 // Texture is initially invalid, but it will become available.
714 EXPECT_FALSE(texture
->have_backing_texture());
716 texture
->set_request_priority(100);
717 PrioritizeTexturesAndBackings(resource_manager
.get());
719 EXPECT_TRUE(ValidateTexture(texture
.get(), false));
720 EXPECT_TRUE(texture
->can_acquire_backing_texture());
721 EXPECT_TRUE(texture
->have_backing_texture());
723 DebugScopedSetImplThreadAndMainThreadBlocked
724 impl_thread_and_main_thread_blocked(&proxy_
);
725 resource_manager
->ClearAllMemory(resource_provider());
727 resource_manager
.reset();
729 EXPECT_FALSE(texture
->can_acquire_backing_texture());
730 EXPECT_FALSE(texture
->have_backing_texture());
733 TEST_F(PrioritizedResourceTest
, TextureMovedToNewManager
) {
734 scoped_ptr
<PrioritizedResourceManager
> resource_manager_one
=
736 scoped_ptr
<PrioritizedResourceManager
> resource_manager_two
=
738 scoped_ptr
<PrioritizedResource
> texture
=
739 resource_manager_one
->CreateTexture(texture_size_
, texture_format_
);
741 // Texture is initially invalid, but it will become available.
742 EXPECT_FALSE(texture
->have_backing_texture());
744 texture
->set_request_priority(100);
745 PrioritizeTexturesAndBackings(resource_manager_one
.get());
747 EXPECT_TRUE(ValidateTexture(texture
.get(), false));
748 EXPECT_TRUE(texture
->can_acquire_backing_texture());
749 EXPECT_TRUE(texture
->have_backing_texture());
751 texture
->SetTextureManager(NULL
);
753 DebugScopedSetImplThreadAndMainThreadBlocked
754 impl_thread_and_main_thread_blocked(&proxy_
);
755 resource_manager_one
->ClearAllMemory(resource_provider());
757 resource_manager_one
.reset();
759 EXPECT_FALSE(texture
->can_acquire_backing_texture());
760 EXPECT_FALSE(texture
->have_backing_texture());
762 texture
->SetTextureManager(resource_manager_two
.get());
764 PrioritizeTexturesAndBackings(resource_manager_two
.get());
766 EXPECT_TRUE(ValidateTexture(texture
.get(), false));
767 EXPECT_TRUE(texture
->can_acquire_backing_texture());
768 EXPECT_TRUE(texture
->have_backing_texture());
770 DebugScopedSetImplThreadAndMainThreadBlocked
771 impl_thread_and_main_thread_blocked(&proxy_
);
772 resource_manager_two
->ClearAllMemory(resource_provider());
775 TEST_F(PrioritizedResourceTest
,
776 RenderSurfacesReduceMemoryAvailableOutsideRootSurface
) {
777 const size_t kMaxTextures
= 8;
778 scoped_ptr
<PrioritizedResourceManager
> resource_manager
=
779 CreateManager(kMaxTextures
);
781 // Half of the memory is taken by surfaces (with high priority place-holder)
782 scoped_ptr
<PrioritizedResource
> render_surface_place_holder
=
783 resource_manager
->CreateTexture(texture_size_
, texture_format_
);
784 render_surface_place_holder
->SetToSelfManagedMemoryPlaceholder(
785 TexturesMemorySize(4));
786 render_surface_place_holder
->set_request_priority(
787 PriorityCalculator::RenderSurfacePriority());
789 // Create textures to fill our memory limit.
790 scoped_ptr
<PrioritizedResource
> textures
[kMaxTextures
];
792 for (size_t i
= 0; i
< kMaxTextures
; ++i
) {
794 resource_manager
->CreateTexture(texture_size_
, texture_format_
);
797 // Set decreasing non-visible priorities outside root surface.
798 for (size_t i
= 0; i
< kMaxTextures
; ++i
)
799 textures
[i
]->set_request_priority(100 + i
);
801 // Only lower half should be available.
802 PrioritizeTexturesAndBackings(resource_manager
.get());
803 EXPECT_TRUE(ValidateTexture(textures
[0].get(), false));
804 EXPECT_TRUE(ValidateTexture(textures
[3].get(), false));
805 EXPECT_FALSE(ValidateTexture(textures
[4].get(), false));
806 EXPECT_FALSE(ValidateTexture(textures
[7].get(), false));
808 // Set increasing non-visible priorities outside root surface.
809 for (size_t i
= 0; i
< kMaxTextures
; ++i
)
810 textures
[i
]->set_request_priority(100 - i
);
812 // Only upper half should be available.
813 PrioritizeTexturesAndBackings(resource_manager
.get());
814 EXPECT_FALSE(ValidateTexture(textures
[0].get(), false));
815 EXPECT_FALSE(ValidateTexture(textures
[3].get(), false));
816 EXPECT_TRUE(ValidateTexture(textures
[4].get(), false));
817 EXPECT_TRUE(ValidateTexture(textures
[7].get(), false));
819 EXPECT_EQ(TexturesMemorySize(4), resource_manager
->MemoryAboveCutoffBytes());
820 EXPECT_EQ(TexturesMemorySize(4),
821 resource_manager
->MemoryForSelfManagedTextures());
822 EXPECT_LE(resource_manager
->MemoryUseBytes(),
823 resource_manager
->MemoryAboveCutoffBytes());
824 EXPECT_EQ(TexturesMemorySize(8),
825 resource_manager
->MaxMemoryNeededBytes());
827 DebugScopedSetImplThreadAndMainThreadBlocked
828 impl_thread_and_main_thread_blocked(&proxy_
);
829 resource_manager
->ClearAllMemory(resource_provider());
832 TEST_F(PrioritizedResourceTest
,
833 RenderSurfacesReduceMemoryAvailableForRequestLate
) {
834 const size_t kMaxTextures
= 8;
835 scoped_ptr
<PrioritizedResourceManager
> resource_manager
=
836 CreateManager(kMaxTextures
);
838 // Half of the memory is taken by surfaces (with high priority place-holder)
839 scoped_ptr
<PrioritizedResource
> render_surface_place_holder
=
840 resource_manager
->CreateTexture(texture_size_
, texture_format_
);
841 render_surface_place_holder
->SetToSelfManagedMemoryPlaceholder(
842 TexturesMemorySize(4));
843 render_surface_place_holder
->set_request_priority(
844 PriorityCalculator::RenderSurfacePriority());
846 // Create textures to fill our memory limit.
847 scoped_ptr
<PrioritizedResource
> textures
[kMaxTextures
];
849 for (size_t i
= 0; i
< kMaxTextures
; ++i
) {
851 resource_manager
->CreateTexture(texture_size_
, texture_format_
);
854 // Set equal priorities.
855 for (size_t i
= 0; i
< kMaxTextures
; ++i
)
856 textures
[i
]->set_request_priority(100);
858 // The first four to be requested late will be available.
859 PrioritizeTexturesAndBackings(resource_manager
.get());
860 for (unsigned i
= 0; i
< kMaxTextures
; ++i
)
861 EXPECT_FALSE(ValidateTexture(textures
[i
].get(), false));
862 for (unsigned i
= 0; i
< kMaxTextures
; i
+= 2)
863 EXPECT_TRUE(ValidateTexture(textures
[i
].get(), true));
864 for (unsigned i
= 1; i
< kMaxTextures
; i
+= 2)
865 EXPECT_FALSE(ValidateTexture(textures
[i
].get(), true));
867 EXPECT_EQ(TexturesMemorySize(4), resource_manager
->MemoryAboveCutoffBytes());
868 EXPECT_EQ(TexturesMemorySize(4),
869 resource_manager
->MemoryForSelfManagedTextures());
870 EXPECT_LE(resource_manager
->MemoryUseBytes(),
871 resource_manager
->MemoryAboveCutoffBytes());
872 EXPECT_EQ(TexturesMemorySize(8),
873 resource_manager
->MaxMemoryNeededBytes());
875 DebugScopedSetImplThreadAndMainThreadBlocked
876 impl_thread_and_main_thread_blocked(&proxy_
);
877 resource_manager
->ClearAllMemory(resource_provider());
880 TEST_F(PrioritizedResourceTest
,
881 WhenRenderSurfaceNotAvailableTexturesAlsoNotAvailable
) {
882 const size_t kMaxTextures
= 8;
883 scoped_ptr
<PrioritizedResourceManager
> resource_manager
=
884 CreateManager(kMaxTextures
);
886 // Half of the memory is taken by surfaces (with high priority place-holder)
887 scoped_ptr
<PrioritizedResource
> render_surface_place_holder
=
888 resource_manager
->CreateTexture(texture_size_
, texture_format_
);
889 render_surface_place_holder
->SetToSelfManagedMemoryPlaceholder(
890 TexturesMemorySize(4));
891 render_surface_place_holder
->set_request_priority(
892 PriorityCalculator::RenderSurfacePriority());
894 // Create textures to fill our memory limit.
895 scoped_ptr
<PrioritizedResource
> textures
[kMaxTextures
];
897 for (size_t i
= 0; i
< kMaxTextures
; ++i
)
899 resource_manager
->CreateTexture(texture_size_
, texture_format_
);
901 // Set 6 visible textures in the root surface, and 2 in a child surface.
902 for (size_t i
= 0; i
< 6; ++i
) {
904 set_request_priority(PriorityCalculator::VisiblePriority(true));
906 for (size_t i
= 6; i
< 8; ++i
) {
908 set_request_priority(PriorityCalculator::VisiblePriority(false));
911 PrioritizeTexturesAndBackings(resource_manager
.get());
913 // Unable to request_late textures in the child surface.
914 EXPECT_FALSE(ValidateTexture(textures
[6].get(), true));
915 EXPECT_FALSE(ValidateTexture(textures
[7].get(), true));
917 // Root surface textures are valid.
918 for (size_t i
= 0; i
< 6; ++i
)
919 EXPECT_TRUE(ValidateTexture(textures
[i
].get(), false));
921 EXPECT_EQ(TexturesMemorySize(6), resource_manager
->MemoryAboveCutoffBytes());
922 EXPECT_EQ(TexturesMemorySize(2),
923 resource_manager
->MemoryForSelfManagedTextures());
924 EXPECT_LE(resource_manager
->MemoryUseBytes(),
925 resource_manager
->MemoryAboveCutoffBytes());
927 DebugScopedSetImplThreadAndMainThreadBlocked
928 impl_thread_and_main_thread_blocked(&proxy_
);
929 resource_manager
->ClearAllMemory(resource_provider());
932 TEST_F(PrioritizedResourceTest
, RequestLateBackingsSorting
) {
933 const size_t kMaxTextures
= 8;
934 scoped_ptr
<PrioritizedResourceManager
> resource_manager
=
935 CreateManager(kMaxTextures
);
936 resource_manager
->SetMaxMemoryLimitBytes(TexturesMemorySize(kMaxTextures
));
938 // Create textures to fill our memory limit.
939 scoped_ptr
<PrioritizedResource
> textures
[kMaxTextures
];
940 for (size_t i
= 0; i
< kMaxTextures
; ++i
)
942 resource_manager
->CreateTexture(texture_size_
, texture_format_
);
944 // Set equal priorities, and allocate backings for all textures.
945 for (size_t i
= 0; i
< kMaxTextures
; ++i
)
946 textures
[i
]->set_request_priority(100);
947 PrioritizeTexturesAndBackings(resource_manager
.get());
948 for (unsigned i
= 0; i
< kMaxTextures
; ++i
)
949 EXPECT_TRUE(ValidateTexture(textures
[i
].get(), false));
951 // Drop the memory limit and prioritize (none will be above the threshold,
952 // but they still have backings because ReduceMemory hasn't been called).
953 resource_manager
->SetMaxMemoryLimitBytes(
954 TexturesMemorySize(kMaxTextures
/ 2));
955 PrioritizeTexturesAndBackings(resource_manager
.get());
957 // Push half of them back over the limit.
958 for (size_t i
= 0; i
< kMaxTextures
; i
+= 2)
959 EXPECT_TRUE(textures
[i
]->RequestLate());
961 // Push the priorities to the backings array and sort the backings array
962 ResourceManagerUpdateBackingsPriorities(resource_manager
.get());
964 // Assert that the backings list be sorted with the below-limit backings
965 // before the above-limit backings.
966 ResourceManagerAssertInvariants(resource_manager
.get());
968 // Make sure that we have backings for all of the textures.
969 for (size_t i
= 0; i
< kMaxTextures
; ++i
)
970 EXPECT_TRUE(textures
[i
]->have_backing_texture());
972 // Make sure that only the request_late textures are above the priority
974 for (size_t i
= 0; i
< kMaxTextures
; i
+= 2)
975 EXPECT_TRUE(TextureBackingIsAbovePriorityCutoff(textures
[i
].get()));
976 for (size_t i
= 1; i
< kMaxTextures
; i
+= 2)
977 EXPECT_FALSE(TextureBackingIsAbovePriorityCutoff(textures
[i
].get()));
979 DebugScopedSetImplThreadAndMainThreadBlocked
980 impl_thread_and_main_thread_blocked(&proxy_
);
981 resource_manager
->ClearAllMemory(resource_provider());
984 TEST_F(PrioritizedResourceTest
, ClearUploadsToEvictedResources
) {
985 const size_t kMaxTextures
= 4;
986 scoped_ptr
<PrioritizedResourceManager
> resource_manager
=
987 CreateManager(kMaxTextures
);
988 resource_manager
->SetMaxMemoryLimitBytes(TexturesMemorySize(kMaxTextures
));
990 // Create textures to fill our memory limit.
991 scoped_ptr
<PrioritizedResource
> textures
[kMaxTextures
];
993 for (size_t i
= 0; i
< kMaxTextures
; ++i
)
995 resource_manager
->CreateTexture(texture_size_
, texture_format_
);
997 // Set equal priorities, and allocate backings for all textures.
998 for (size_t i
= 0; i
< kMaxTextures
; ++i
)
999 textures
[i
]->set_request_priority(100);
1000 PrioritizeTexturesAndBackings(resource_manager
.get());
1001 for (unsigned i
= 0; i
< kMaxTextures
; ++i
)
1002 EXPECT_TRUE(ValidateTexture(textures
[i
].get(), false));
1004 ResourceUpdateQueue queue
;
1005 DebugScopedSetImplThreadAndMainThreadBlocked
1006 impl_thread_and_main_thread_blocked(&proxy_
);
1007 for (size_t i
= 0; i
< kMaxTextures
; ++i
) {
1008 const ResourceUpdate upload
= ResourceUpdate::Create(
1009 textures
[i
].get(), NULL
, gfx::Rect(), gfx::Rect(), gfx::Vector2d());
1010 queue
.AppendFullUpload(upload
);
1013 // Make sure that we have backings for all of the textures.
1014 for (size_t i
= 0; i
< kMaxTextures
; ++i
)
1015 EXPECT_TRUE(textures
[i
]->have_backing_texture());
1017 queue
.ClearUploadsToEvictedResources();
1018 EXPECT_EQ(4u, queue
.FullUploadSize());
1020 resource_manager
->ReduceMemoryOnImplThread(
1021 TexturesMemorySize(1),
1022 PriorityCalculator::AllowEverythingCutoff(),
1023 resource_provider());
1024 queue
.ClearUploadsToEvictedResources();
1025 EXPECT_EQ(1u, queue
.FullUploadSize());
1027 resource_manager
->ReduceMemoryOnImplThread(
1028 0, PriorityCalculator::AllowEverythingCutoff(), resource_provider());
1029 queue
.ClearUploadsToEvictedResources();
1030 EXPECT_EQ(0u, queue
.FullUploadSize());
1033 TEST_F(PrioritizedResourceTest
, UsageStatistics
) {
1034 const size_t kMaxTextures
= 5;
1035 scoped_ptr
<PrioritizedResourceManager
> resource_manager
=
1036 CreateManager(kMaxTextures
);
1037 scoped_ptr
<PrioritizedResource
> textures
[kMaxTextures
];
1039 for (size_t i
= 0; i
< kMaxTextures
; ++i
) {
1041 resource_manager
->CreateTexture(texture_size_
, texture_format_
);
1045 set_request_priority(PriorityCalculator::AllowVisibleOnlyCutoff() - 1);
1047 set_request_priority(PriorityCalculator::AllowVisibleOnlyCutoff());
1048 textures
[2]->set_request_priority(
1049 PriorityCalculator::AllowVisibleAndNearbyCutoff() - 1);
1051 set_request_priority(PriorityCalculator::AllowVisibleAndNearbyCutoff());
1052 textures
[4]->set_request_priority(
1053 PriorityCalculator::AllowVisibleAndNearbyCutoff() + 1);
1055 // Set max limit to 2 textures.
1056 resource_manager
->SetMaxMemoryLimitBytes(TexturesMemorySize(2));
1057 PrioritizeTexturesAndBackings(resource_manager
.get());
1059 // The first two textures should be available, others should not.
1060 for (size_t i
= 0; i
< 2; ++i
)
1061 EXPECT_TRUE(ValidateTexture(textures
[i
].get(), false));
1062 for (size_t i
= 2; i
< kMaxTextures
; ++i
)
1063 EXPECT_FALSE(ValidateTexture(textures
[i
].get(), false));
1065 // Validate the statistics.
1067 DebugScopedSetImplThread
impl_thread(&proxy_
);
1068 EXPECT_EQ(TexturesMemorySize(2), resource_manager
->MemoryUseBytes());
1069 EXPECT_EQ(TexturesMemorySize(1), resource_manager
->MemoryVisibleBytes());
1070 EXPECT_EQ(TexturesMemorySize(3),
1071 resource_manager
->MemoryVisibleAndNearbyBytes());
1074 // Re-prioritize the textures, but do not push the values to backings.
1076 set_request_priority(PriorityCalculator::AllowVisibleOnlyCutoff() - 1);
1078 set_request_priority(PriorityCalculator::AllowVisibleOnlyCutoff() - 1);
1080 set_request_priority(PriorityCalculator::AllowVisibleOnlyCutoff() - 1);
1081 textures
[3]->set_request_priority(
1082 PriorityCalculator::AllowVisibleAndNearbyCutoff() - 1);
1084 set_request_priority(PriorityCalculator::AllowVisibleAndNearbyCutoff());
1085 resource_manager
->PrioritizeTextures();
1087 // Verify that we still see the old values.
1089 DebugScopedSetImplThread
impl_thread(&proxy_
);
1090 EXPECT_EQ(TexturesMemorySize(2), resource_manager
->MemoryUseBytes());
1091 EXPECT_EQ(TexturesMemorySize(1), resource_manager
->MemoryVisibleBytes());
1092 EXPECT_EQ(TexturesMemorySize(3),
1093 resource_manager
->MemoryVisibleAndNearbyBytes());
1096 // Push priorities to backings, and verify we see the new values.
1098 DebugScopedSetImplThreadAndMainThreadBlocked
1099 impl_thread_and_main_thread_blocked(&proxy_
);
1100 resource_manager
->PushTexturePrioritiesToBackings();
1101 EXPECT_EQ(TexturesMemorySize(2), resource_manager
->MemoryUseBytes());
1102 EXPECT_EQ(TexturesMemorySize(3), resource_manager
->MemoryVisibleBytes());
1103 EXPECT_EQ(TexturesMemorySize(4),
1104 resource_manager
->MemoryVisibleAndNearbyBytes());
1107 DebugScopedSetImplThreadAndMainThreadBlocked
1108 impl_thread_and_main_thread_blocked(&proxy_
);
1109 resource_manager
->ClearAllMemory(resource_provider());