| Index: gpu/command_buffer/service/service_discardable_manager_unittest.cc
|
| diff --git a/gpu/command_buffer/service/service_discardable_manager_unittest.cc b/gpu/command_buffer/service/service_discardable_manager_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..9907fba992805914f0883d8559dd94a884720958
|
| --- /dev/null
|
| +++ b/gpu/command_buffer/service/service_discardable_manager_unittest.cc
|
| @@ -0,0 +1,137 @@
|
| +// Copyright (c) 2017 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "gpu/command_buffer/service/service_discardable_manager.h"
|
| +
|
| +#include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h"
|
| +#include "gpu/command_buffer/service/gpu_service_test.h"
|
| +#include "gpu/command_buffer/service/mailbox_manager.h"
|
| +#include "gpu/command_buffer/service/memory_tracking.h"
|
| +#include "gpu/command_buffer/service/mocks.h"
|
| +#include "gpu/command_buffer/service/test_helper.h"
|
| +#include "gpu/command_buffer/service/texture_manager.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +#include "ui/gl/gl_image_stub.h"
|
| +#include "ui/gl/gl_mock.h"
|
| +#include "ui/gl/gl_switches.h"
|
| +
|
| +using ::testing::Pointee;
|
| +using ::testing::_;
|
| +
|
| +namespace gpu {
|
| +namespace gles2 {
|
| +namespace {
|
| +
|
| +ServiceDiscardableHandle CreateLockedHandleForTesting() {
|
| + const int32_t kHandleLockedStart = 2;
|
| +
|
| + std::unique_ptr<base::SharedMemory> shared_mem(new base::SharedMemory);
|
| + shared_mem->CreateAndMapAnonymous(sizeof(uint32_t));
|
| + scoped_refptr<gpu::Buffer> buffer =
|
| + MakeBufferFromSharedMemory(std::move(shared_mem), sizeof(uint32_t));
|
| + *reinterpret_cast<uint32_t*>(buffer->memory()) = kHandleLockedStart;
|
| +
|
| + return ServiceDiscardableHandle(buffer, 0, 0);
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +class ServiceDiscardableManagerTest : public GpuServiceTest {
|
| + public:
|
| + ServiceDiscardableManagerTest() {}
|
| + ~ServiceDiscardableManagerTest() override {}
|
| +
|
| + protected:
|
| + void SetUp() override {
|
| + GpuServiceTest::SetUp();
|
| + discardable_manager_ = scoped_refptr<ServiceDiscardableManager>(
|
| + new ServiceDiscardableManager());
|
| + decoder_.reset(new MockGLES2Decoder());
|
| + feature_info_ = new FeatureInfo();
|
| + context_group_ = scoped_refptr<ContextGroup>(new ContextGroup(
|
| + gpu_preferences_, NULL, NULL, NULL, NULL, feature_info_, false, nullptr,
|
| + nullptr, GpuFeatureInfo()));
|
| + TestHelper::SetupContextGroupInitExpectations(
|
| + gl_.get(), DisallowedFeatures(), "", "", CONTEXT_TYPE_OPENGLES2, false);
|
| + context_group_->Initialize(decoder_.get(), CONTEXT_TYPE_OPENGLES2,
|
| + DisallowedFeatures());
|
| + texture_manager_ = context_group_->texture_manager();
|
| + }
|
| +
|
| + void TearDown() override {
|
| + context_group_->Destroy(decoder_.get(), false);
|
| + context_group_ = nullptr;
|
| + GpuServiceTest::TearDown();
|
| + }
|
| +
|
| + scoped_refptr<ServiceDiscardableManager> discardable_manager_;
|
| + GpuPreferences gpu_preferences_;
|
| + scoped_refptr<FeatureInfo> feature_info_;
|
| + TextureManager* texture_manager_;
|
| + std::unique_ptr<MockGLES2Decoder> decoder_;
|
| + scoped_refptr<gles2::ContextGroup> context_group_;
|
| +};
|
| +
|
| +TEST_F(ServiceDiscardableManagerTest, BasicUsage) {
|
| + const GLuint kClientId = 1;
|
| + const GLuint kServiceId = 2;
|
| + const size_t texture_size = 64 * 1024 * 1024;
|
| +
|
| + texture_manager_->CreateTexture(kClientId, kServiceId);
|
| + auto handle = CreateLockedHandleForTesting();
|
| +
|
| + discardable_manager_->InsertLockedTexture(kClientId, texture_size,
|
| + context_group_.get(), handle);
|
| + EXPECT_TRUE(
|
| + discardable_manager_->UnlockTexture(kClientId, context_group_.get()));
|
| + discardable_manager_->OnTextureDeleted(kClientId, context_group_.get());
|
| +}
|
| +
|
| +TEST_F(ServiceDiscardableManagerTest, UnlockInvalid) {
|
| + const GLuint kClientId = 1;
|
| + EXPECT_FALSE(
|
| + discardable_manager_->UnlockTexture(kClientId, context_group_.get()));
|
| +}
|
| +
|
| +TEST_F(ServiceDiscardableManagerTest, Limits) {
|
| + const size_t texture_size = 64 * 1024 * 1024;
|
| +
|
| + // Create 4 textures, this should fill up the discardable cache.
|
| + for (int i = 1; i < 5; ++i) {
|
| + texture_manager_->CreateTexture(i, i);
|
| + auto handle = CreateLockedHandleForTesting();
|
| + discardable_manager_->InsertLockedTexture(i, texture_size,
|
| + context_group_.get(), handle);
|
| + }
|
| +
|
| + // Unlock textures in an arbitrary order, 2, 0, 1, 3, in order to test MRU.
|
| + {
|
| + testing::InSequence force_sequence;
|
| + EXPECT_TRUE(discardable_manager_->UnlockTexture(3, context_group_.get()));
|
| + EXPECT_TRUE(discardable_manager_->UnlockTexture(1, context_group_.get()));
|
| + EXPECT_TRUE(discardable_manager_->UnlockTexture(2, context_group_.get()));
|
| + EXPECT_TRUE(discardable_manager_->UnlockTexture(4, context_group_.get()));
|
| + }
|
| +
|
| + // Allocate four more textures - the previous 4 should be evicted / deleted.
|
| + EXPECT_CALL(*gl_, DeleteTextures(1, Pointee(3))).RetiresOnSaturation();
|
| + EXPECT_CALL(*gl_, DeleteTextures(1, Pointee(1))).RetiresOnSaturation();
|
| + EXPECT_CALL(*gl_, DeleteTextures(1, Pointee(2))).RetiresOnSaturation();
|
| + EXPECT_CALL(*gl_, DeleteTextures(1, Pointee(4))).RetiresOnSaturation();
|
| +
|
| + for (int i = 5; i < 9; ++i) {
|
| + texture_manager_->CreateTexture(i, i);
|
| + auto handle = CreateLockedHandleForTesting();
|
| + discardable_manager_->InsertLockedTexture(i, texture_size,
|
| + context_group_.get(), handle);
|
| + }
|
| +
|
| + // Delete these last 4 textures.
|
| + for (int i = 5; i < 9; ++i) {
|
| + discardable_manager_->OnTextureDeleted(i, context_group_.get());
|
| + }
|
| +}
|
| +
|
| +} // namespace gles2
|
| +} // namespace gpu
|
|
|