/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
#include <dali-test-suite-utils.h>
-#include <dali/devel-api/images/pixel-data-devel.h>
#include <dali/devel-api/rendering/texture-devel.h>
#include <dali/public-api/dali-core.h>
#include <test-native-image.h>
test_return_value = TET_PASS;
}
-Texture CreateTexture(TextureType::Type type, Pixel::Format format, int width, int height)
-{
- Texture texture = Texture::New(type, format, width, height);
-
- int bufferSize = width * height * Pixel::GetBytesPerPixel(format);
- uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(bufferSize));
- PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, format, PixelData::FREE);
- texture.Upload(pixelData, 0u, 0u, 0u, 0u, width, height);
- return texture;
-}
-
int UtcDaliTextureNew01(void)
{
TestApplication application;
//Upload part of the texture
callStack.Reset();
- bufferSize = width * height * 2;
+ bufferSize = width * height;
buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
- PixelData pixelDataSubImage = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
+ PixelData pixelDataSubImage = PixelData::New(buffer, bufferSize, width / 2, height / 2, Pixel::RGBA8888, PixelData::FREE);
texture.Upload(pixelDataSubImage, 0u, 0u, width / 2, height / 2, width / 2, height / 2);
application.SendNotification();
application.Render();
bufferSize = widthMipmap1 * heightMipmap1 * 4;
buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
- PixelData pixelDataMipmap1 = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
+ PixelData pixelDataMipmap1 = PixelData::New(buffer, bufferSize, widthMipmap1, heightMipmap1, Pixel::RGBA8888, PixelData::FREE);
texture.Upload(pixelDataMipmap1, 0u, 1u, 0u, 0u, widthMipmap1, heightMipmap1);
application.SendNotification();
application.Render();
bufferSize = widthMipmap1 * heightMipmap1 * 4;
buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
- PixelData pixelDataMipmap1 = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
+ PixelData pixelDataMipmap1 = PixelData::New(buffer, bufferSize, widthMipmap1, heightMipmap1, Pixel::RGBA8888, PixelData::FREE);
texture.Upload(pixelDataMipmap1, CubeMapLayer::NEGATIVE_X, 1u, 0u, 0u, widthMipmap1, heightMipmap1);
application.SendNotification();
application.Render();
//Upload part of the texture
callStack.Reset();
- bufferSize = width * height * 2;
+ bufferSize = width * height;
buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
- PixelData pixelDataSubImage = PixelData::New(buffer, bufferSize, width, height, COMPRESSED_PIXEL_FORMATS[index], PixelData::FREE);
+ PixelData pixelDataSubImage = PixelData::New(buffer, bufferSize, width / 2, height / 2, COMPRESSED_PIXEL_FORMATS[index], PixelData::FREE);
texture.Upload(pixelDataSubImage, 0u, 0u, width / 2, height / 2, width / 2, height / 2);
application.SendNotification();
application.Render();
END_TEST;
}
+int UtcDaliTextureUploadSubPixelData01(void)
+{
+ TestApplication application;
+
+ //Create the texture
+ unsigned int width(64);
+ unsigned int height(64);
+ Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
+
+ application.GetGlAbstraction().EnableTextureCallTrace(true);
+
+ application.SendNotification();
+ application.Render();
+
+ TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
+
+ //Upload data to the texture
+ callStack.Reset();
+
+ uint32_t bufferWidth = width * 2;
+ uint32_t bufferHeight = height * 2;
+ uint32_t bufferXOffset = width;
+ uint32_t bufferYOffset = height;
+
+ unsigned int bufferSize(bufferWidth * bufferHeight * 4);
+ unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
+ PixelData pixelData = PixelData::New(buffer, bufferSize, bufferWidth, bufferHeight, Pixel::RGBA8888, PixelData::FREE);
+ DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height);
+ application.SendNotification();
+ application.Render();
+
+ //TexImage2D should be called to upload the data
+ {
+ std::stringstream out;
+ out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
+ DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
+ }
+
+ //Upload part of the texture
+ callStack.Reset();
+ DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width / 2, height / 2, 0u, 0u, width / 2, height / 2, width / 2, height / 2);
+ application.SendNotification();
+ application.Render();
+
+ //TexSubImage2D should be called to upload the data
+ {
+ std::stringstream out;
+ out << GL_TEXTURE_2D << ", " << 0u << ", " << width / 2 << ", " << height / 2 << ", " << width / 2 << ", " << height / 2;
+ DALI_TEST_CHECK(callStack.FindMethodAndParams("TexSubImage2D", out.str().c_str()));
+ }
+
+ END_TEST;
+}
+
+int UtcDaliTextureUploadSubPixelData02(void)
+{
+ TestApplication application;
+
+ //Create the texture
+ unsigned int width(64);
+ unsigned int height(64);
+ Texture texture = CreateTexture(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
+
+ application.GetGlAbstraction().EnableTextureCallTrace(true);
+
+ application.SendNotification();
+ application.Render();
+
+ TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
+
+ tet_infoline("TexImage2D should be called six times with a null pointer to reserve storage for the six textures of the cube map");
+ for(unsigned int i(0); i < 6; ++i)
+ {
+ std::stringstream out;
+ out << GL_TEXTURE_CUBE_MAP_POSITIVE_X + i << ", " << 0u << ", " << width << ", " << height;
+ DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
+ }
+
+ uint32_t bufferWidth = width * 2;
+ uint32_t bufferHeight = height * 2;
+ uint32_t bufferXOffset = width;
+ uint32_t bufferYOffset = height;
+
+ unsigned int bufferSize(bufferWidth * bufferHeight * 4);
+ unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
+ PixelData pixelData = PixelData::New(buffer, bufferSize, bufferWidth, bufferHeight, Pixel::RGBA8888, PixelData::FREE);
+
+ //Upload data to the POSITIVE_X face of the texture
+ {
+ callStack.Reset();
+
+ DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::POSITIVE_X, 0u, 0u, 0u, width, height);
+ application.SendNotification();
+ application.Render();
+
+ //TexImage2D should be called to upload the data to the POSITIVE_X face
+ {
+ std::stringstream out;
+ out << GL_TEXTURE_CUBE_MAP_POSITIVE_X << ", " << 0u << ", " << width << ", " << height;
+ DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
+ }
+ }
+
+ //Upload data to the NEGATIVE_X face of the texture
+ {
+ callStack.Reset();
+
+ DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::NEGATIVE_X, 0u, 0u, 0u, width, height);
+ application.SendNotification();
+ application.Render();
+
+ //TexImage2D should be called to upload the data to the NEGATIVE_X face
+ {
+ std::stringstream out;
+ out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X << ", " << 0u << ", " << width << ", " << height;
+ DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
+ }
+ }
+
+ //Upload data to the POSITIVE_Y face of the texture
+ {
+ callStack.Reset();
+ DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::POSITIVE_Y, 0u, 0u, 0u, width, height);
+ application.SendNotification();
+ application.Render();
+
+ //TexImage2D should be called to upload the data to the POSITIVE_Y face
+ {
+ std::stringstream out;
+ out << GL_TEXTURE_CUBE_MAP_POSITIVE_Y << ", " << 0u << ", " << width << ", " << height;
+ DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
+ }
+ }
+
+ //Upload data to the NEGATIVE_Y face of the texture
+ {
+ callStack.Reset();
+ DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::NEGATIVE_Y, 0u, 0u, 0u, width, height);
+ application.SendNotification();
+ application.Render();
+
+ //TexImage2D should be called to upload the data to the NEGATIVE_Y face
+ {
+ std::stringstream out;
+ out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Y << ", " << 0u << ", " << width << ", " << height;
+ DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
+ }
+ }
+
+ //Upload data to the POSITIVE_Z face of the texture
+ {
+ callStack.Reset();
+ DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::POSITIVE_Z, 0u, 0u, 0u, width, height);
+ application.SendNotification();
+ application.Render();
+
+ //TexImage2D should be called to upload the data to the POSITIVE_Z face
+ {
+ std::stringstream out;
+ out << GL_TEXTURE_CUBE_MAP_POSITIVE_Z << ", " << 0u << ", " << width << ", " << height;
+ DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
+ }
+ }
+
+ //Upload data to the NEGATIVE_Z face of the texture
+ {
+ callStack.Reset();
+ DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::NEGATIVE_Z, 0u, 0u, 0u, width, height);
+ application.SendNotification();
+ application.Render();
+
+ //TexImage2D should be called to upload the data to the NEGATIVE_Z face
+ {
+ std::stringstream out;
+ out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Z << ", " << 0u << ", " << width << ", " << height;
+ DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
+ }
+ }
+
+ END_TEST;
+}
+
int UtcDaliTextureUploadPixelFormats(void)
{
TestApplication application;
Pixel::BGRA8888,
Pixel::DEPTH_UNSIGNED_INT,
Pixel::DEPTH_FLOAT,
- Pixel::DEPTH_STENCIL};
+ Pixel::DEPTH_STENCIL,
+ Pixel::RGB16F,
+ Pixel::RGB32F,
+ Pixel::R11G11B10F,
+ Pixel::CHROMINANCE_U,
+ Pixel::CHROMINANCE_V};
for(auto format : formats)
{
- tet_infoline("Creating a Texure with an alpha channel");
+ tet_infoline("Creating a Texure with a new or recent format");
Texture texture = CreateTexture(TextureType::TEXTURE_2D, format, width, height);
application.SendNotification();
int UtcDaliTextureGenerateMipmaps(void)
{
-#ifdef OLD_GRAPHICS_TEST
TestApplication application;
unsigned int width(64);
unsigned int height(64);
out << GL_TEXTURE_CUBE_MAP;
DALI_TEST_CHECK(callStack.FindMethodAndParams("GenerateMipmap", out.str().c_str()));
}
-#else
- DALI_TEST_CHECK(1);
-#endif
END_TEST;
}
std::string fragShader = baseFragShader;
bool applied = DevelTexture::ApplyNativeFragmentShader(nativeTexture, fragShader);
+ std::string fragPrefix = "#extension GL_OES_EGL_image_external:require\n";
+
DALI_TEST_CHECK(applied);
DALI_TEST_CHECK(baseFragShader.compare(fragShader));
+ DALI_TEST_CHECK(fragShader.compare(fragPrefix + baseFragShader) == 0);
DALI_TEST_CHECK(!fragShader.empty());
END_TEST;
}
DALI_TEST_CHECK(!baseFragShader.compare(fragShader));
END_TEST;
}
+
+int UtcDaliTextureGetPixelFormat(void)
+{
+ TestApplication application;
+ uint32_t width(64);
+ uint32_t height(64);
+
+ Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
+ DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
+
+ texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGB888, width, height);
+ DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGB888, TEST_LOCATION);
+
+ texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::L8, width, height);
+ DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::L8, TEST_LOCATION);
+
+ texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::CHROMINANCE_U, width, height);
+ DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::CHROMINANCE_U, TEST_LOCATION);
+
+ END_TEST;
+}
+
+int utcDaliTexturePartialUpdate01(void)
+{
+ TestApplication application(
+ TestApplication::DEFAULT_SURFACE_WIDTH,
+ TestApplication::DEFAULT_SURFACE_HEIGHT,
+ TestApplication::DEFAULT_HORIZONTAL_DPI,
+ TestApplication::DEFAULT_VERTICAL_DPI,
+ true,
+ true);
+
+ tet_infoline("Check the damaged rect with partial update and texture change");
+
+ const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
+
+ std::vector<Rect<int32_t>> damagedRects;
+ Rect<int32_t> clippingRect;
+
+ Geometry geometry = CreateQuadGeometry();
+ Shader shader = Shader::New("vertexSrc", "fragmentSrc");
+ Renderer renderer = Renderer::New(geometry, shader);
+
+ uint32_t width(4);
+ uint32_t height(4);
+ Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
+ TextureSet textureSet = TextureSet::New();
+ textureSet.SetTexture(0u, texture);
+ renderer.SetTextures(textureSet);
+
+ Actor actor = Actor::New();
+ actor.AddRenderer(renderer);
+
+ actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+ actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
+ actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
+ application.GetScene().Add(actor);
+
+ damagedRects.clear();
+ application.SendNotification();
+ application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
+ DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
+
+ // Aligned by 16
+ clippingRect = Rect<int32_t>(16, 768, 32, 32); // in screen coordinates
+ DALI_TEST_EQUALS<Rect<int32_t>>(clippingRect, damagedRects[0], TEST_LOCATION);
+ application.RenderWithPartialUpdate(damagedRects, clippingRect);
+ DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
+ DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
+ DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
+ DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
+
+ damagedRects.clear();
+ application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
+ application.RenderWithPartialUpdate(damagedRects, clippingRect);
+
+ // Ensure the damaged rect is empty
+ DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
+
+ // Upload texture
+ uint32_t bufferSize(width * height * 4);
+ uint8_t* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
+ PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
+ texture.Upload(pixelData);
+
+ damagedRects.clear();
+ application.SendNotification();
+ application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
+ DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
+
+ // Aligned by 16
+ clippingRect = Rect<int32_t>(16, 768, 32, 32); // in screen coordinates
+ DALI_TEST_EQUALS<Rect<int32_t>>(clippingRect, damagedRects[0], TEST_LOCATION);
+ application.RenderWithPartialUpdate(damagedRects, clippingRect);
+ DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
+ DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
+ DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
+ DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
+
+ damagedRects.clear();
+ application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
+ application.RenderWithPartialUpdate(damagedRects, clippingRect);
+
+ // Ensure the damaged rect is empty
+ DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
+
+ END_TEST;
+}
+
+int utcDaliTexturePartialUpdate02(void)
+{
+ TestApplication application(
+ TestApplication::DEFAULT_SURFACE_WIDTH,
+ TestApplication::DEFAULT_SURFACE_HEIGHT,
+ TestApplication::DEFAULT_HORIZONTAL_DPI,
+ TestApplication::DEFAULT_VERTICAL_DPI,
+ true,
+ true);
+
+ tet_infoline("Check the damaged rect with partial update and texture change");
+
+ const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
+
+ std::vector<Rect<int32_t>> damagedRects;
+ Rect<int32_t> clippingRect;
+
+ Geometry geometry = CreateQuadGeometry();
+ Shader shader = Shader::New("vertexSrc", "fragmentSrc");
+ Renderer renderer = Renderer::New(geometry, shader);
+
+ uint32_t width(4);
+ uint32_t height(4);
+ Texture texture1 = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
+ Texture texture2 = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
+ TextureSet textureSet = TextureSet::New();
+ textureSet.SetTexture(0u, texture1);
+ renderer.SetTextures(textureSet);
+
+ Actor actor = Actor::New();
+ actor.AddRenderer(renderer);
+
+ actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+ actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
+ actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
+ application.GetScene().Add(actor);
+
+ damagedRects.clear();
+ application.SendNotification();
+ application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
+ DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
+
+ // Aligned by 16
+ clippingRect = Rect<int32_t>(16, 768, 32, 32); // in screen coordinates, includes 3 last frames updates
+ DALI_TEST_EQUALS<Rect<int32_t>>(clippingRect, damagedRects[0], TEST_LOCATION);
+ application.RenderWithPartialUpdate(damagedRects, clippingRect);
+ DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
+ DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
+ DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
+ DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
+
+ damagedRects.clear();
+ application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
+ application.RenderWithPartialUpdate(damagedRects, clippingRect);
+
+ // Ensure the damaged rect is empty
+ DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
+
+ // Set another texture
+ textureSet.SetTexture(0u, texture2);
+
+ damagedRects.clear();
+ application.SendNotification();
+ application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
+ DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
+
+ // Aligned by 16
+ clippingRect = Rect<int32_t>(16, 768, 32, 32); // in screen coordinates, includes 3 last frames updates
+ DALI_TEST_EQUALS<Rect<int32_t>>(clippingRect, damagedRects[0], TEST_LOCATION);
+ application.RenderWithPartialUpdate(damagedRects, clippingRect);
+ DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
+ DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
+ DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
+ DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
+
+ damagedRects.clear();
+ application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
+ application.RenderWithPartialUpdate(damagedRects, clippingRect);
+
+ // Ensure the damaged rect is empty
+ DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
+
+ END_TEST;
+}