eeafb5eaa3
TLDR Thumbnails size will be removed from the system. Each thumbnail class is responsible for determining its stored size. Images and other thumbnail types can be scaled up or down within reason without blurring. The thumbnail system uses the concept of context and size organize thumbnails by size based on their intended use. However, most of the thumbnail classes do not respect or use the specified size, which is 16 by 16 pixels and really only usable for small icons. The thumbnails are currently being used in the asset browser tree control, the larger asset browser previews, the material component property asset controls, the material component inspector for the large preview, and other places. Each of these places use completely different sizes, some of which are large and change dynamically. Whenever the thumbnails are painted they are scaled to the desired size. Material and mesh thumbnails were always being captured at 512x512 regardless of what the rest of the thumbnail system said. Source, product, and folder thumbnails would be stored at the original asset size. The loading movie thumbnail was always drawn at 16 by 16 and scale up so it was always blurry. Image thumbnails were always scaled down to 16 by 16 and scale up for larger previews. Rather than worrying about the size of each context, each thumbnail class will store the image at whenever it deems to be a large enough size that can be scaled down when used. This may eliminate the need for multiple thumbnail contexts which are not being used anyway. https://jira.agscollab.com/browse/ATOM-15370
163 lines
6.8 KiB
C++
163 lines
6.8 KiB
C++
/*
|
|
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
* its licensors.
|
|
*
|
|
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
* distribution (the "License"). All use of this software is governed by the License,
|
|
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
*
|
|
*/
|
|
|
|
#include <AzTest/AzTest.h>
|
|
#include <AzCore/UnitTest/TestTypes.h>
|
|
#include <AzToolsFramework/Thumbnails/ThumbnailerComponent.h>
|
|
#include <AzCore/UserSettings/UserSettingsComponent.h>
|
|
#include <AzToolsFramework/Application/ToolsApplication.h>
|
|
#include <AzToolsFramework/Entity/EditorEntityContextComponent.h>
|
|
#include <AzToolsFramework/Entity/EditorEntityHelpers.h>
|
|
#include <AzToolsFramework/UnitTest/ToolsTestApplication.h>
|
|
|
|
namespace UnitTest
|
|
{
|
|
using namespace AzToolsFramework::Thumbnailer;
|
|
|
|
class ThumbnailerTests
|
|
: public ::testing::Test
|
|
, public TraceBusRedirector
|
|
{
|
|
protected:
|
|
void SetUp() override
|
|
{
|
|
m_app.Start(m_descriptor);
|
|
// Without this, the user settings component would sometimes attempt to save
|
|
// changes on shutdown. In some cases this would cause a crash while the unit test
|
|
// was running, because the environment wasn't setup for it to save these settings.
|
|
AZ::UserSettingsComponentRequestBus::Broadcast(&AZ::UserSettingsComponentRequests::DisableSaveOnFinalize);
|
|
|
|
TraceBusRedirector::BusConnect();
|
|
|
|
AZStd::string entityName("test");
|
|
AZ::EntityId testEntityId;
|
|
AzToolsFramework::EditorEntityContextRequestBus::BroadcastResult(
|
|
testEntityId,
|
|
&AzToolsFramework::EditorEntityContextRequestBus::Events::CreateNewEditorEntity,
|
|
entityName.c_str());
|
|
|
|
m_testEntity = AzToolsFramework::GetEntityById(testEntityId);
|
|
|
|
ASSERT_TRUE(m_testEntity);
|
|
|
|
AZ::Component* thumbnailerComponent = nullptr;
|
|
AZ::ComponentDescriptorBus::EventResult(thumbnailerComponent, azrtti_typeid<AzToolsFramework::Thumbnailer::ThumbnailerComponent>(), &AZ::ComponentDescriptorBus::Events::CreateComponent);
|
|
|
|
ASSERT_TRUE(thumbnailerComponent);
|
|
|
|
if (m_testEntity->GetState() == AZ::Entity::State::Active)
|
|
{
|
|
m_testEntity->Deactivate();
|
|
}
|
|
|
|
ASSERT_TRUE(m_testEntity->AddComponent(thumbnailerComponent));
|
|
|
|
m_testEntity->Activate();
|
|
}
|
|
|
|
void TearDown() override
|
|
{
|
|
TraceBusRedirector::BusDisconnect();
|
|
|
|
AzToolsFramework::EditorEntityContextRequestBus::Broadcast(
|
|
&AzToolsFramework::EditorEntityContextRequestBus::Events::DestroyEditorEntity,
|
|
m_testEntity->GetId());
|
|
|
|
m_app.Stop();
|
|
}
|
|
|
|
ToolsTestApplication m_app{ "ThumbnailerTests" };
|
|
AZ::ComponentApplication::Descriptor m_descriptor;
|
|
|
|
AZ::Entity* m_testEntity = nullptr;
|
|
};
|
|
|
|
TEST_F(ThumbnailerTests, ThumbnailerComponent_RegisterUnregisterContext)
|
|
{
|
|
constexpr const char* contextName1 = "Context1";
|
|
constexpr const char* contextName2 = "Context2";
|
|
|
|
auto checkHasContext = [](const char* contextName)
|
|
{
|
|
bool hasContext = false;
|
|
AzToolsFramework::Thumbnailer::ThumbnailerRequestBus::BroadcastResult(hasContext, &AzToolsFramework::Thumbnailer::ThumbnailerRequests::HasContext, contextName);
|
|
return hasContext;
|
|
};
|
|
|
|
EXPECT_FALSE(checkHasContext(contextName1));
|
|
EXPECT_FALSE(checkHasContext(contextName2));
|
|
|
|
AzToolsFramework::Thumbnailer::ThumbnailerRequestBus::Broadcast(&AzToolsFramework::Thumbnailer::ThumbnailerRequests::RegisterContext, contextName1);
|
|
|
|
EXPECT_TRUE(checkHasContext(contextName1));
|
|
EXPECT_FALSE(checkHasContext(contextName2));
|
|
|
|
AzToolsFramework::Thumbnailer::ThumbnailerRequestBus::Broadcast(&AzToolsFramework::Thumbnailer::ThumbnailerRequests::RegisterContext, contextName2);
|
|
|
|
EXPECT_TRUE(checkHasContext(contextName1));
|
|
EXPECT_TRUE(checkHasContext(contextName2));
|
|
|
|
AzToolsFramework::Thumbnailer::ThumbnailerRequestBus::Broadcast(&AzToolsFramework::Thumbnailer::ThumbnailerRequests::UnregisterContext, contextName1);
|
|
|
|
EXPECT_FALSE(checkHasContext(contextName1));
|
|
EXPECT_TRUE(checkHasContext(contextName2));
|
|
|
|
AzToolsFramework::Thumbnailer::ThumbnailerRequestBus::Broadcast(&AzToolsFramework::Thumbnailer::ThumbnailerRequests::UnregisterContext, contextName2);
|
|
|
|
EXPECT_FALSE(checkHasContext(contextName1));
|
|
EXPECT_FALSE(checkHasContext(contextName2));
|
|
}
|
|
|
|
TEST_F(ThumbnailerTests, ThumbnailerComponent_Deactivate_ClearTumbnailContexts)
|
|
{
|
|
constexpr const char* contextName1 = "Context1";
|
|
constexpr const char* contextName2 = "Context2";
|
|
|
|
auto checkHasContext = [](const char* contextName)
|
|
{
|
|
bool hasContext = false;
|
|
AzToolsFramework::Thumbnailer::ThumbnailerRequestBus::BroadcastResult(hasContext, &AzToolsFramework::Thumbnailer::ThumbnailerRequests::HasContext, contextName);
|
|
return hasContext;
|
|
};
|
|
|
|
AzToolsFramework::Thumbnailer::ThumbnailerRequestBus::Broadcast(&AzToolsFramework::Thumbnailer::ThumbnailerRequests::RegisterContext, contextName1);
|
|
AzToolsFramework::Thumbnailer::ThumbnailerRequestBus::Broadcast(&AzToolsFramework::Thumbnailer::ThumbnailerRequests::RegisterContext, contextName2);
|
|
|
|
EXPECT_TRUE(checkHasContext(contextName1));
|
|
EXPECT_TRUE(checkHasContext(contextName2));
|
|
|
|
m_testEntity->Deactivate();
|
|
m_testEntity->Activate();
|
|
|
|
EXPECT_FALSE(checkHasContext(contextName1));
|
|
EXPECT_FALSE(checkHasContext(contextName2));
|
|
}
|
|
|
|
TEST_F(ThumbnailerTests, ThumbnailerComponent_RegisterContextTwice_Assert)
|
|
{
|
|
constexpr const char* contextName1 = "Context1";
|
|
|
|
AzToolsFramework::Thumbnailer::ThumbnailerRequestBus::Broadcast(&AzToolsFramework::Thumbnailer::ThumbnailerRequests::RegisterContext, contextName1);
|
|
|
|
AZ_TEST_START_TRACE_SUPPRESSION;
|
|
AzToolsFramework::Thumbnailer::ThumbnailerRequestBus::Broadcast(&AzToolsFramework::Thumbnailer::ThumbnailerRequests::RegisterContext, contextName1);
|
|
AZ_TEST_STOP_TRACE_SUPPRESSION(1);
|
|
}
|
|
|
|
TEST_F(ThumbnailerTests, ThumbnailerComponent_UnregisterUnknownContext_Assert)
|
|
{
|
|
AZ_TEST_START_TRACE_SUPPRESSION;
|
|
AzToolsFramework::Thumbnailer::ThumbnailerRequestBus::Broadcast(&AzToolsFramework::Thumbnailer::ThumbnailerRequests::UnregisterContext, "ContextDoesNotExist");
|
|
AZ_TEST_STOP_TRACE_SUPPRESSION(1);
|
|
}
|
|
} // namespace UnitTest
|