+int UtcDaliNativeImageTexture02(void)
+{
+ TestApplication application;
+ tet_infoline("UtcDaliNativeImageTexture02 - test error on TargetTexture");
+
+ TestNativeImagePointer imageInterface = TestNativeImage::New(16, 16);
+ imageInterface->mTargetTextureError = 1u;
+ {
+ Texture texture = Texture::New(*(imageInterface.Get()));
+ Actor actor = CreateRenderableActor(texture, "", "");
+ application.GetScene().Add(actor);
+
+ DALI_TEST_CHECK(texture);
+
+ application.SendNotification();
+ application.Render(16);
+
+ // Expect 2 attempts to create the texture - once when adding the texture
+ // to the scene-graph, and again since that failed, during the Bind.
+ // The second one succeeds (TargetTexture only errors once)
+ DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 2, TEST_LOCATION);
+ DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 1, TEST_LOCATION);
+
+ UnparentAndReset(actor);
+
+ application.SendNotification();
+ application.Render(16);
+ }
+ application.SendNotification();
+ application.Render(16);
+
+ // Expect that there are no further calls to create/destroy resource
+ DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 2, TEST_LOCATION);
+ DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 2, TEST_LOCATION);
+
+ END_TEST;
+}
+
+int UtcDaliTextureGenerateMipmapsNegative(void)
+{
+ TestApplication application;
+ Dali::Texture instance;
+ try
+ {
+ instance.GenerateMipmaps();
+ DALI_TEST_CHECK(false); // Should not get here
+ }
+ catch(...)
+ {
+ DALI_TEST_CHECK(true); // We expect an assert
+ }
+ END_TEST;
+}
+
+int UtcDaliTextureUploadNegative01(void)
+{
+ TestApplication application;
+ Dali::Texture instance;
+ try
+ {
+ Dali::PixelData arg1;
+ instance.Upload(arg1);
+ DALI_TEST_CHECK(false); // Should not get here
+ }
+ catch(...)
+ {
+ DALI_TEST_CHECK(true); // We expect an assert
+ }
+ END_TEST;
+}
+
+int UtcDaliTextureUploadNegative02(void)
+{
+ TestApplication application;
+ Dali::Texture instance;
+ try
+ {
+ Dali::PixelData arg1;
+ unsigned int arg2(0u);
+ unsigned int arg3(0u);
+ unsigned int arg4(0u);
+ unsigned int arg5(0u);
+ unsigned int arg6(0u);
+ unsigned int arg7(0u);
+ instance.Upload(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
+ DALI_TEST_CHECK(false); // Should not get here
+ }
+ catch(...)
+ {
+ DALI_TEST_CHECK(true); // We expect an assert
+ }
+ END_TEST;
+}
+
+int UtcDaliTextureGetWidthNegative(void)
+{
+ TestApplication application;
+ Dali::Texture instance;
+ try
+ {
+ instance.GetWidth();
+ DALI_TEST_CHECK(false); // Should not get here
+ }
+ catch(...)
+ {
+ DALI_TEST_CHECK(true); // We expect an assert
+ }
+ END_TEST;
+}
+
+int UtcDaliTextureGetHeightNegative(void)
+{
+ TestApplication application;
+ Dali::Texture instance;
+ try
+ {
+ instance.GetHeight();
+ DALI_TEST_CHECK(false); // Should not get here
+ }
+ catch(...)
+ {
+ DALI_TEST_CHECK(true); // We expect an assert
+ }
+ END_TEST;
+}
+
+int UtcDaliTextureCheckNativeP(void)
+{
+ TestApplication application;
+ TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
+ Texture nativeTexture = Texture::New(*testNativeImage);
+
+ DALI_TEST_CHECK(nativeTexture);
+ DALI_TEST_CHECK(DevelTexture::IsNative(nativeTexture));
+ END_TEST;
+}
+
+int UtcDaliTextureCheckNativeN1(void)
+{
+ TestApplication application;
+ unsigned int width(64);
+ unsigned int height(64);
+ Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
+
+ DALI_TEST_CHECK(texture);
+ DALI_TEST_CHECK(!DevelTexture::IsNative(texture));
+ END_TEST;
+}
+
+int UtcDaliTextureCheckNativeN2(void)
+{
+ TestApplication application;
+ Texture texture;
+ try
+ {
+ bool native = DevelTexture::IsNative(texture);
+ DALI_TEST_CHECK(native != native);
+ }
+ catch(...)
+ {
+ DALI_TEST_CHECK(true);
+ }
+ END_TEST;
+}
+
+int UtcDaliTextureApplyFragShaderP1(void)
+{
+ TestApplication application;
+ TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
+ Texture nativeTexture = Texture::New(*testNativeImage);
+ DALI_TEST_CHECK(nativeTexture);
+
+ const std::string baseFragShader =
+ "varying mediump vec4 uColor;\n"
+ "void main(){\n"
+ " gl_FragColor=uColor;\n"
+ "}\n";
+ 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;
+}
+
+int UtcDaliTextureApplyFragShaderP2(void)
+{
+ TestApplication application;
+ TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
+ Texture nativeTexture = Texture::New(*testNativeImage);
+ DALI_TEST_CHECK(nativeTexture);
+
+ const std::string baseFragShader =
+ "varying mediump vec4 uColor;\n"
+ "varying vec2 vTexCoord;\n"
+ "uniform sampler2D uNative;\n"
+ "void main(){\n"
+ " gl_FragColor=uColor*texture2D(uNative, vTexCoord);\n"
+ "}\n";
+ std::string fragShader = baseFragShader;
+ bool applied = DevelTexture::ApplyNativeFragmentShader(nativeTexture, fragShader);
+
+ DALI_TEST_CHECK(applied);
+ DALI_TEST_CHECK(baseFragShader.compare(fragShader));
+ DALI_TEST_CHECK(!fragShader.empty());
+ DALI_TEST_CHECK(fragShader.find("samplerExternalOES") < fragShader.length());
+ END_TEST;
+}
+
+int UtcDaliTextureApplyFragShaderN1(void)
+{
+ TestApplication application;
+ TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
+ Texture nativeTexture = Texture::New(*testNativeImage);
+ DALI_TEST_CHECK(nativeTexture);
+
+ std::string fragShader;
+ bool applied = DevelTexture::ApplyNativeFragmentShader(nativeTexture, fragShader);
+
+ DALI_TEST_CHECK(!applied);
+ DALI_TEST_CHECK(fragShader.empty());
+ END_TEST;
+}
+
+int UtcDaliTextureApplyFragShaderN2(void)
+{
+ TestApplication application;
+ unsigned int width(64);
+ unsigned int height(64);
+ Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
+
+ const std::string baseFragShader =
+ "varying mediump vec4 uColor;\n"
+ "void main(){\n"
+ " gl_FragColor=uColor;\n"
+ "}\n";
+ std::string fragShader = baseFragShader;
+ bool applied = DevelTexture::ApplyNativeFragmentShader(texture, fragShader);
+
+ DALI_TEST_CHECK(!applied);
+ 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;
+}