END_TEST;
}
+int UtcDaliImageViewImageLoadFailure04(void)
+{
+ ToolkitTestApplication application;
+
+ ImageView imageView = ImageView::New("invalidUrl.png");
+ imageView.SetProperty( Actor::Property::SIZE, Vector2( 100.f, 100.f ) );
+ application.GetScene().Add( imageView );
+ application.SendNotification();
+ application.Render(16);
+
+ // loading started, this waits for the loader thread
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
+
+
+ Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
+ DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_S);
+ DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, "invalidBroken.png");
+ DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE, TEST_BROKEN_IMAGE_L);
+
+ ImageView imageView2 = ImageView::New("invalidUrl.png");
+ imageView2.SetProperty( Actor::Property::SIZE, Vector2( 100.f, 100.f ) );
+ application.GetScene().Add( imageView2 );
+
+ std::string brokenUrl;
+ brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL);
+ DALI_TEST_EQUALS( TEST_BROKEN_IMAGE_S, brokenUrl, TEST_LOCATION);
+
+ brokenUrl = DevelStyleManager::GetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE);
+ DALI_TEST_EQUALS( TEST_BROKEN_IMAGE_L, brokenUrl, TEST_LOCATION);
+
+ application.SendNotification();
+ application.Render(16);
+
+ // loading started, this waits for the loader thread
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
+
+
+ DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, "invalidBroken.9.png");
+
+ ImageView imageView3 = ImageView::New("invalidUrl.png");
+ imageView3.SetProperty( Actor::Property::SIZE, Vector2( 100.f, 100.f ) );
+ application.GetScene().Add( imageView3 );
+
+ application.SendNotification();
+ application.Render(16);
+
+ // loading started, this waits for the loader thread
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
+
+ END_TEST;
+}
+
+
namespace
{
${devel_api_src_dir}/transition-effects/cube-transition-fold-effect.cpp
${devel_api_src_dir}/transition-effects/cube-transition-wave-effect.cpp
${devel_api_src_dir}/utility/npatch-utilities.cpp
+ ${devel_api_src_dir}/utility/npatch-helper.cpp
${devel_api_src_dir}/visual-factory/transition-data.cpp
${devel_api_src_dir}/visual-factory/visual-factory.cpp
${devel_api_src_dir}/visual-factory/visual-base.cpp
SET( devel_api_utility_header_files
${devel_api_src_dir}/utility/npatch-utilities.h
+ ${devel_api_src_dir}/utility/npatch-helper.h
)
SET( SOURCES ${SOURCES}
--- /dev/null
+/*
+* Copyright (c) 2021 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.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+
+// CLASS HEADER
+#include <dali-toolkit/devel-api/utility/npatch-helper.h>
+
+// EXTERNAL INCLUDES
+#include <dali/integration-api/debug.h>
+
+namespace Dali
+{
+namespace Toolkit
+{
+namespace NPatchHelper
+{
+namespace
+{
+/**
+ * @brief Creates the geometry formed from the vertices and indices
+ *
+ * @param[in] vertices The vertices to generate the geometry from
+ * @param[in] indices The indices to generate the geometry from
+ * @return The geometry formed from the vertices and indices
+ */
+Geometry GenerateGeometry(const Vector<Vector2>& vertices, const Vector<unsigned short>& indices)
+{
+ Property::Map vertexFormat;
+ vertexFormat["aPosition"] = Property::VECTOR2;
+ VertexBuffer vertexBuffer = VertexBuffer::New(vertexFormat);
+ if(vertices.Size() > 0)
+ {
+ vertexBuffer.SetData(&vertices[0], vertices.Size());
+ }
+
+ // Create the geometry object
+ Geometry geometry = Geometry::New();
+ geometry.AddVertexBuffer(vertexBuffer);
+ if(indices.Size() > 0)
+ {
+ geometry.SetIndexBuffer(&indices[0], indices.Size());
+ }
+
+ return geometry;
+}
+
+/**
+ * @brief Adds the indices to form a quad composed off two triangles where the indices are organised in a grid
+ *
+ * @param[out] indices The indices to add to
+ * @param[in] rowIdx The row index to start the quad
+ * @param[in] nextRowIdx The index to the next row
+ */
+void AddQuadIndices(Vector<unsigned short>& indices, unsigned int rowIdx, unsigned int nextRowIdx)
+{
+ indices.PushBack(rowIdx);
+ indices.PushBack(nextRowIdx + 1);
+ indices.PushBack(rowIdx + 1);
+
+ indices.PushBack(rowIdx);
+ indices.PushBack(nextRowIdx);
+ indices.PushBack(nextRowIdx + 1);
+}
+
+/**
+ * @brief Adds the vertices to create for npatch
+ * @param[out] vertices The vertices to add to
+ * @param[in] x The x value of vector
+ * @param[in] y The y value of vector
+ */
+void AddVertex(Vector<Vector2>& vertices, unsigned int x, unsigned int y)
+{
+ vertices.PushBack(Vector2(x, y));
+}
+
+} // unnamed namespace
+
+Geometry CreateGridGeometry(Uint16Pair gridSize)
+{
+ uint16_t gridWidth = gridSize.GetWidth();
+ uint16_t gridHeight = gridSize.GetHeight();
+
+ // Create vertices
+ Vector<Vector2> vertices;
+ vertices.Reserve((gridWidth + 1) * (gridHeight + 1));
+
+ for(int y = 0; y < gridHeight + 1; ++y)
+ {
+ for(int x = 0; x < gridWidth + 1; ++x)
+ {
+ AddVertex(vertices, x, y);
+ }
+ }
+
+ // Create indices
+ Vector<unsigned short> indices;
+ indices.Reserve(gridWidth * gridHeight * 6);
+
+ unsigned int rowIdx = 0;
+ unsigned int nextRowIdx = gridWidth + 1;
+ for(int y = 0; y < gridHeight; ++y, ++nextRowIdx, ++rowIdx)
+ {
+ for(int x = 0; x < gridWidth; ++x, ++nextRowIdx, ++rowIdx)
+ {
+ AddQuadIndices(indices, rowIdx, nextRowIdx);
+ }
+ }
+
+ return GenerateGeometry(vertices, indices);
+}
+
+Geometry CreateBorderGeometry(Uint16Pair gridSize)
+{
+ uint16_t gridWidth = gridSize.GetWidth();
+ uint16_t gridHeight = gridSize.GetHeight();
+
+ // Create vertices
+ Vector<Vector2> vertices;
+ vertices.Reserve((gridWidth + 1) * (gridHeight + 1));
+
+ //top
+ int y = 0;
+ for(; y < 2; ++y)
+ {
+ for(int x = 0; x < gridWidth + 1; ++x)
+ {
+ AddVertex(vertices, x, y);
+ }
+ }
+
+ for(; y < gridHeight - 1; ++y)
+ {
+ //left
+ AddVertex(vertices, 0, y);
+ AddVertex(vertices, 1, y);
+
+ //right
+ AddVertex(vertices, gridWidth - 1, y);
+ AddVertex(vertices, gridWidth, y);
+ }
+
+ //bottom
+ for(; y < gridHeight + 1; ++y)
+ {
+ for(int x = 0; x < gridWidth + 1; ++x)
+ {
+ AddVertex(vertices, x, y);
+ }
+ }
+
+ // Create indices
+ Vector<unsigned short> indices;
+ indices.Reserve(gridWidth * gridHeight * 6);
+
+ //top
+ unsigned int rowIdx = 0;
+ unsigned int nextRowIdx = gridWidth + 1;
+ for(int x = 0; x < gridWidth; ++x, ++nextRowIdx, ++rowIdx)
+ {
+ AddQuadIndices(indices, rowIdx, nextRowIdx);
+ }
+
+ if(gridHeight > 2)
+ {
+ rowIdx = gridWidth + 1;
+ nextRowIdx = (gridWidth + 1) * 2;
+
+ unsigned increment = gridWidth - 1;
+ if(gridHeight > 3)
+ {
+ increment = 2;
+ //second row left
+ AddQuadIndices(indices, rowIdx, nextRowIdx);
+
+ rowIdx = gridWidth * 2;
+ nextRowIdx = (gridWidth + 1) * 2 + 2;
+ //second row right
+ AddQuadIndices(indices, rowIdx, nextRowIdx);
+
+ //left and right
+ rowIdx = nextRowIdx - 2;
+ nextRowIdx = rowIdx + 4;
+ for(int y = 2; y < 2 * (gridHeight - 3); ++y, rowIdx += 2, nextRowIdx += 2)
+ {
+ AddQuadIndices(indices, rowIdx, nextRowIdx);
+ }
+ }
+
+ //second row left
+ AddQuadIndices(indices, rowIdx, nextRowIdx);
+
+ rowIdx += increment;
+ nextRowIdx += gridWidth - 1;
+ //second row right
+ AddQuadIndices(indices, rowIdx, nextRowIdx);
+ }
+
+ //bottom
+ rowIdx = nextRowIdx - gridWidth + 1;
+ nextRowIdx = rowIdx + gridWidth + 1;
+ for(int x = 0; x < gridWidth; ++x, ++nextRowIdx, ++rowIdx)
+ {
+ AddQuadIndices(indices, rowIdx, nextRowIdx);
+ }
+
+ return GenerateGeometry(vertices, indices);
+}
+
+void RegisterStretchProperties(Renderer& renderer, const char* uniformName, const NPatchUtility::StretchRanges& stretchPixels, uint16_t imageExtent)
+{
+ uint16_t prevEnd = 0;
+ uint16_t prevFix = 0;
+ uint16_t prevStretch = 0;
+ unsigned int i = 1;
+ for(NPatchUtility::StretchRanges::ConstIterator it = stretchPixels.Begin(); it != stretchPixels.End(); ++it, ++i)
+ {
+ uint16_t start = it->GetX();
+ uint16_t end = it->GetY();
+
+ uint16_t fix = prevFix + start - prevEnd;
+ uint16_t stretch = prevStretch + end - start;
+
+ std::stringstream uniform;
+ uniform << uniformName << "[" << i << "]";
+ renderer.RegisterProperty(uniform.str(), Vector2(fix, stretch));
+
+ prevEnd = end;
+ prevFix = fix;
+ prevStretch = stretch;
+ }
+
+ {
+ prevFix += imageExtent - prevEnd;
+ std::stringstream uniform;
+ uniform << uniformName << "[" << i << "]";
+ renderer.RegisterProperty(uniform.str(), Vector2(prevFix, prevStretch));
+ }
+}
+
+void ApplyTextureAndUniforms(Renderer& renderer, const Internal::NPatchData* data)
+{
+ TextureSet textureSet;
+ textureSet = data->GetTextures();
+
+ if(data->GetStretchPixelsX().Size() == 1 && data->GetStretchPixelsY().Size() == 1)
+ {
+ //special case for 9 patch
+ Uint16Pair stretchX = data->GetStretchPixelsX()[0];
+ Uint16Pair stretchY = data->GetStretchPixelsY()[0];
+
+ uint16_t stretchWidth = (stretchX.GetY() >= stretchX.GetX()) ? stretchX.GetY() - stretchX.GetX() : 0;
+ uint16_t stretchHeight = (stretchY.GetY() >= stretchY.GetX()) ? stretchY.GetY() - stretchY.GetX() : 0;
+
+ renderer.RegisterProperty("uFixed[0]", Vector2::ZERO);
+ renderer.RegisterProperty("uFixed[1]", Vector2(stretchX.GetX(), stretchY.GetX()));
+ renderer.RegisterProperty("uFixed[2]", Vector2(data->GetCroppedWidth() - stretchWidth, data->GetCroppedHeight() - stretchHeight));
+ renderer.RegisterProperty("uStretchTotal", Vector2(stretchWidth, stretchHeight));
+ }
+ else
+ {
+ renderer.RegisterProperty("uNinePatchFactorsX[0]", Vector2::ZERO);
+ renderer.RegisterProperty("uNinePatchFactorsY[0]", Vector2::ZERO);
+
+ RegisterStretchProperties(renderer, "uNinePatchFactorsX", data->GetStretchPixelsX(), data->GetCroppedWidth());
+ RegisterStretchProperties(renderer, "uNinePatchFactorsY", data->GetStretchPixelsY(), data->GetCroppedHeight());
+ }
+}
+
+} // namespace NPatchHelper
+
+} // namespace Toolkit
+
+} // namespace Dali
--- /dev/null
+#ifndef DALI_TOOLKIT_NPATCH_HELPER_H
+#define DALI_TOOLKIT_NPATCH_HELPER_H
+
+/*
+ * Copyright (c) 2021 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/math/uint-16-pair.h>
+#include <dali/public-api/rendering/geometry.h>
+#include <dali/devel-api/rendering/renderer-devel.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/public-api/dali-toolkit-common.h>
+#include <dali-toolkit/internal/visuals/npatch-data.h>
+
+namespace Dali
+{
+namespace Toolkit
+{
+namespace NPatchHelper
+{
+/**
+ * The list that includes stretch pixel ranges
+ */
+using StretchRanges = Dali::Vector<Uint16Pair>;
+
+/**
+ * @brief Creates a Npatch Geometry object
+ *
+ * @param[in] gridSize The gridSize for creating a geometry
+ * @return The Geometry for NPatch
+ */
+DALI_TOOLKIT_API Geometry CreateGridGeometry(Uint16Pair gridSize);
+
+/**
+ * @brief Creates a geometry with the border only for the grid size to be used by this visuals' shaders
+ * e.g. a 5x4 grid would create a geometry that would look like:
+ *
+ * ---------------------
+ * | /| /| /| /| /|
+ * |/ |/ |/ |/ |/ |
+ * ---------------------
+ * | /| | /|
+ * |/ | |/ |
+ * ----- -----
+ * | /| | /|
+ * |/ | |/ |
+ * ---------------------
+ * | /| /| /| /| /|
+ * |/ |/ |/ |/ |/ |
+ * ---------------------
+ *
+ * @param[in] gridSize The grid size of the solid geometry to create
+ * @return Returns the created geometry for the grid size
+ */
+DALI_TOOLKIT_API Geometry CreateBorderGeometry(Uint16Pair gridSize);
+
+
+/**
+ * @brief Registers a properties for Stretch Ranges
+ *
+ * @param[in,out] renderer The renderer for broken image
+ * @param[in] uniformName The name of the uniform
+ * @param[in] stretchPixels The stretchable pixels in the cropped image space
+ * @param[in] imageExtent The imageExtent
+ */
+void RegisterStretchProperties(Renderer& renderer, const char* uniformName, const NPatchUtility::StretchRanges& stretchPixels, uint16_t imageExtent);
+
+/**
+ * @brief Apply a texture and uniforms
+ *
+ * @param[in,out] renderer The renderer for broken image
+ * @param[in] data The pointer of npatch-data
+ */
+void ApplyTextureAndUniforms(Renderer& renderer, const Internal::NPatchData* data);
+
+} // namespace NPatchUtility
+
+} // namespace Toolkit
+
+} // namespace Dali
+
+#endif // DALI_TOOLKIT_NPATCH_HELPER_H
#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
#include <dali-toolkit/internal/visuals/image-visual-shader-factory.h>
#include <dali-toolkit/internal/visuals/npatch-loader.h>
+#include <dali-toolkit/devel-api/utility/npatch-helper.h>
#include <dali-toolkit/internal/visuals/rendering-addon.h>
#include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
#include <dali-toolkit/internal/visuals/visual-base-impl.h>
{
namespace Internal
{
-namespace
-{
-/**
- * @brief Creates the geometry formed from the vertices and indices
- *
- * @param[in] vertices The vertices to generate the geometry from
- * @param[in] indices The indices to generate the geometry from
- * @return The geometry formed from the vertices and indices
- */
-Geometry GenerateGeometry(const Vector<Vector2>& vertices, const Vector<unsigned short>& indices)
-{
- Property::Map vertexFormat;
- vertexFormat["aPosition"] = Property::VECTOR2;
- VertexBuffer vertexBuffer = VertexBuffer::New(vertexFormat);
- if(vertices.Size() > 0)
- {
- vertexBuffer.SetData(&vertices[0], vertices.Size());
- }
-
- // Create the geometry object
- Geometry geometry = Geometry::New();
- geometry.AddVertexBuffer(vertexBuffer);
- if(indices.Size() > 0)
- {
- geometry.SetIndexBuffer(&indices[0], indices.Size());
- }
-
- return geometry;
-}
-
-/**
- * @brief Adds the indices to form a quad composed off two triangles where the indices are organised in a grid
- *
- * @param[out] indices The indices to add to
- * @param[in] rowIdx The row index to start the quad
- * @param[in] nextRowIdx The index to the next row
- */
-void AddQuadIndices(Vector<unsigned short>& indices, unsigned int rowIdx, unsigned int nextRowIdx)
-{
- indices.PushBack(rowIdx);
- indices.PushBack(nextRowIdx + 1);
- indices.PushBack(rowIdx + 1);
-
- indices.PushBack(rowIdx);
- indices.PushBack(nextRowIdx);
- indices.PushBack(nextRowIdx + 1);
-}
-
-void AddVertex(Vector<Vector2>& vertices, unsigned int x, unsigned int y)
-{
- vertices.PushBack(Vector2(x, y));
-}
-
-void RegisterStretchProperties(Renderer& renderer, const char* uniformName, const NPatchUtility::StretchRanges& stretchPixels, uint16_t imageExtent)
-{
- uint16_t prevEnd = 0;
- uint16_t prevFix = 0;
- uint16_t prevStretch = 0;
- unsigned int i = 1;
- for(NPatchUtility::StretchRanges::ConstIterator it = stretchPixels.Begin(); it != stretchPixels.End(); ++it, ++i)
- {
- uint16_t start = it->GetX();
- uint16_t end = it->GetY();
-
- uint16_t fix = prevFix + start - prevEnd;
- uint16_t stretch = prevStretch + end - start;
-
- std::stringstream uniform;
- uniform << uniformName << "[" << i << "]";
- renderer.RegisterProperty(uniform.str(), Vector2(fix, stretch));
-
- prevEnd = end;
- prevFix = fix;
- prevStretch = stretch;
- }
-
- {
- prevFix += imageExtent - prevEnd;
- std::stringstream uniform;
- uniform << uniformName << "[" << i << "]";
- renderer.RegisterProperty(uniform.str(), Vector2(prevFix, prevStretch));
- }
-}
-
-} //unnamed namespace
/////////////////NPatchVisual////////////////
Uint16Pair gridSize(2 * data->GetStretchPixelsX().Size() + 1, 2 * data->GetStretchPixelsY().Size() + 1);
if(!data->GetRenderingMap())
{
- geometry = !mBorderOnly ? CreateGridGeometry(gridSize) : CreateBorderGeometry(gridSize);
+ geometry = !mBorderOnly ? NPatchHelper::CreateGridGeometry(gridSize) : NPatchHelper::CreateBorderGeometry(gridSize);
}
else
{
uint32_t elementCount[2];
- geometry = !mBorderOnly ? RenderingAddOn::Get().CreateGeometryGrid(data->GetRenderingMap(), gridSize, elementCount) : CreateBorderGeometry(gridSize);
+ geometry = !mBorderOnly ? RenderingAddOn::Get().CreateGeometryGrid(data->GetRenderingMap(), gridSize, elementCount) : NPatchHelper::CreateBorderGeometry(gridSize);
if(mImpl->mRenderer)
{
RenderingAddOn::Get().SubmitRenderTask(mImpl->mRenderer, data->GetRenderingMap());
if(mLoader.GetNPatchData(mId, data) && data->GetLoadingState() == NPatchData::LoadingState::LOAD_COMPLETE)
{
textureSet = data->GetTextures();
-
- if(data->GetStretchPixelsX().Size() == 1 && data->GetStretchPixelsY().Size() == 1)
- {
- //special case for 9 patch
- Uint16Pair stretchX = data->GetStretchPixelsX()[0];
- Uint16Pair stretchY = data->GetStretchPixelsY()[0];
-
- uint16_t stretchWidth = (stretchX.GetY() >= stretchX.GetX()) ? stretchX.GetY() - stretchX.GetX() : 0;
- uint16_t stretchHeight = (stretchY.GetY() >= stretchY.GetX()) ? stretchY.GetY() - stretchY.GetX() : 0;
-
- mImpl->mRenderer.RegisterProperty("uFixed[0]", Vector2::ZERO);
- mImpl->mRenderer.RegisterProperty("uFixed[1]", Vector2(stretchX.GetX(), stretchY.GetX()));
- mImpl->mRenderer.RegisterProperty("uFixed[2]", Vector2(data->GetCroppedWidth() - stretchWidth, data->GetCroppedHeight() - stretchHeight));
- mImpl->mRenderer.RegisterProperty("uStretchTotal", Vector2(stretchWidth, stretchHeight));
- }
- else
- {
- mImpl->mRenderer.RegisterProperty("uNinePatchFactorsX[0]", Vector2::ZERO);
- mImpl->mRenderer.RegisterProperty("uNinePatchFactorsY[0]", Vector2::ZERO);
-
- RegisterStretchProperties(mImpl->mRenderer, "uNinePatchFactorsX", data->GetStretchPixelsX(), data->GetCroppedWidth());
- RegisterStretchProperties(mImpl->mRenderer, "uNinePatchFactorsY", data->GetStretchPixelsY(), data->GetCroppedHeight());
- }
+ NPatchHelper::ApplyTextureAndUniforms(mImpl->mRenderer, data);
}
else
{
{
if(DALI_LIKELY(VisualFactoryCache::NINE_PATCH_GEOMETRY == subType))
{
- geometry = CreateGridGeometry(Uint16Pair(3, 3));
+ geometry = NPatchHelper::CreateGridGeometry(Uint16Pair(3, 3));
}
else if(VisualFactoryCache::NINE_PATCH_BORDER_GEOMETRY == subType)
{
- geometry = CreateBorderGeometry(Uint16Pair(3, 3));
+ geometry = NPatchHelper::CreateBorderGeometry(Uint16Pair(3, 3));
}
mFactoryCache.SaveGeometry(subType, geometry);
}
return geometry;
}
-Geometry NPatchVisual::CreateGridGeometry(Uint16Pair gridSize)
-{
- uint16_t gridWidth = gridSize.GetWidth();
- uint16_t gridHeight = gridSize.GetHeight();
-
- // Create vertices
- Vector<Vector2> vertices;
- vertices.Reserve((gridWidth + 1) * (gridHeight + 1));
-
- for(int y = 0; y < gridHeight + 1; ++y)
- {
- for(int x = 0; x < gridWidth + 1; ++x)
- {
- AddVertex(vertices, x, y);
- }
- }
-
- // Create indices
- Vector<unsigned short> indices;
- indices.Reserve(gridWidth * gridHeight * 6);
-
- unsigned int rowIdx = 0;
- unsigned int nextRowIdx = gridWidth + 1;
- for(int y = 0; y < gridHeight; ++y, ++nextRowIdx, ++rowIdx)
- {
- for(int x = 0; x < gridWidth; ++x, ++nextRowIdx, ++rowIdx)
- {
- AddQuadIndices(indices, rowIdx, nextRowIdx);
- }
- }
-
- return GenerateGeometry(vertices, indices);
-}
-
-Geometry NPatchVisual::CreateBorderGeometry(Uint16Pair gridSize)
-{
- uint16_t gridWidth = gridSize.GetWidth();
- uint16_t gridHeight = gridSize.GetHeight();
-
- // Create vertices
- Vector<Vector2> vertices;
- vertices.Reserve((gridWidth + 1) * (gridHeight + 1));
-
- //top
- int y = 0;
- for(; y < 2; ++y)
- {
- for(int x = 0; x < gridWidth + 1; ++x)
- {
- AddVertex(vertices, x, y);
- }
- }
-
- for(; y < gridHeight - 1; ++y)
- {
- //left
- AddVertex(vertices, 0, y);
- AddVertex(vertices, 1, y);
-
- //right
- AddVertex(vertices, gridWidth - 1, y);
- AddVertex(vertices, gridWidth, y);
- }
-
- //bottom
- for(; y < gridHeight + 1; ++y)
- {
- for(int x = 0; x < gridWidth + 1; ++x)
- {
- AddVertex(vertices, x, y);
- }
- }
-
- // Create indices
- Vector<unsigned short> indices;
- indices.Reserve(gridWidth * gridHeight * 6);
-
- //top
- unsigned int rowIdx = 0;
- unsigned int nextRowIdx = gridWidth + 1;
- for(int x = 0; x < gridWidth; ++x, ++nextRowIdx, ++rowIdx)
- {
- AddQuadIndices(indices, rowIdx, nextRowIdx);
- }
-
- if(gridHeight > 2)
- {
- rowIdx = gridWidth + 1;
- nextRowIdx = (gridWidth + 1) * 2;
-
- unsigned increment = gridWidth - 1;
- if(gridHeight > 3)
- {
- increment = 2;
- //second row left
- AddQuadIndices(indices, rowIdx, nextRowIdx);
-
- rowIdx = gridWidth * 2;
- nextRowIdx = (gridWidth + 1) * 2 + 2;
- //second row right
- AddQuadIndices(indices, rowIdx, nextRowIdx);
-
- //left and right
- rowIdx = nextRowIdx - 2;
- nextRowIdx = rowIdx + 4;
- for(int y = 2; y < 2 * (gridHeight - 3); ++y, rowIdx += 2, nextRowIdx += 2)
- {
- AddQuadIndices(indices, rowIdx, nextRowIdx);
- }
- }
-
- //second row left
- AddQuadIndices(indices, rowIdx, nextRowIdx);
-
- rowIdx += increment;
- nextRowIdx += gridWidth - 1;
- //second row right
- AddQuadIndices(indices, rowIdx, nextRowIdx);
- }
-
- //bottom
- rowIdx = nextRowIdx - gridWidth + 1;
- nextRowIdx = rowIdx + gridWidth + 1;
- for(int x = 0; x < gridWidth; ++x, ++nextRowIdx, ++rowIdx)
- {
- AddQuadIndices(indices, rowIdx, nextRowIdx);
- }
-
- return GenerateGeometry(vertices, indices);
-}
-
void NPatchVisual::SetResource()
{
const NPatchData* data;
#include <dali-toolkit/internal/visuals/image-atlas-manager.h>
#include <dali-toolkit/internal/visuals/svg/svg-visual.h>
#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
+#include <dali-toolkit/devel-api/utility/npatch-helper.h>
#include <dali/integration-api/debug.h>
namespace Dali
{
namespace Internal
{
-namespace
-{
-
-/**
- * @brief Creates the geometry formed from the vertices and indices
- *
- * @param[in] vertices The vertices to generate the geometry from
- * @param[in] indices The indices to generate the geometry from
- * @return The geometry formed from the vertices and indices
- */
-Geometry GenerateGeometry(const Vector<Vector2>& vertices, const Vector<unsigned short>& indices)
-{
- Property::Map vertexFormat;
- vertexFormat["aPosition"] = Property::VECTOR2;
- VertexBuffer vertexBuffer = VertexBuffer::New(vertexFormat);
- if(vertices.Size() > 0)
- {
- vertexBuffer.SetData(&vertices[0], vertices.Size());
- }
-
- // Create the geometry object
- Geometry geometry = Geometry::New();
- geometry.AddVertexBuffer(vertexBuffer);
- if(indices.Size() > 0)
- {
- geometry.SetIndexBuffer(&indices[0], indices.Size());
- }
-
- return geometry;
-}
-
-/**
- * @brief Adds the indices to form a quad composed off two triangles where the indices are organised in a grid
- *
- * @param[out] indices The indices to add to
- * @param[in] rowIdx The row index to start the quad
- * @param[in] nextRowIdx The index to the next row
- */
-void AddQuadIndices(Vector<unsigned short>& indices, unsigned int rowIdx, unsigned int nextRowIdx)
-{
- indices.PushBack(rowIdx);
- indices.PushBack(nextRowIdx + 1);
- indices.PushBack(rowIdx + 1);
-
- indices.PushBack(rowIdx);
- indices.PushBack(nextRowIdx);
- indices.PushBack(nextRowIdx + 1);
-}
-
-/**
- * @brief Adds the vertices to create for npatch
- * @param[out] vertices The vertices to add to
- * @param[in] x The x value of vector
- * @param[in] y The y value of vector
- */
-void AddVertex(Vector<Vector2>& vertices, unsigned int x, unsigned int y)
-{
- vertices.PushBack(Vector2(x, y));
-}
-
-} //unnamed namespace
VisualFactoryCache::VisualFactoryCache(bool preMultiplyOnLoad)
: mSvgRasterizeThread(NULL),
mVectorAnimationManager(),
mPreMultiplyOnLoad(preMultiplyOnLoad),
- mBrokenImageInfoContainer()
+ mBrokenImageInfoContainer(),
+ mDefaultBrokenImageUrl(""),
+ mUseDefaultBrokenImageOnly(true)
{
}
if(!mAtlasManager)
{
mAtlasManager = new ImageAtlasManager();
- if(!mBrokenImageInfoContainer.empty())
- {
- mAtlasManager->SetBrokenImage(mBrokenImageInfoContainer[0].url);
- }
+ mAtlasManager->SetBrokenImage(mDefaultBrokenImageUrl);
}
return mAtlasManager;
return mPreMultiplyOnLoad;
}
-void VisualFactoryCache::SetBrokenImageUrl(const std::vector<std::string>& brokenImageUrlList)
+void VisualFactoryCache::SetBrokenImageUrl(std::string& defaultBrokenUrl, const std::vector<std::string>& brokenImageUrlList)
{
+ mUseDefaultBrokenImageOnly = false;
mBrokenImageInfoContainer.clear();
mBrokenImageInfoContainer.assign(brokenImageUrlList.size(), BrokenImageInfo());
for(unsigned int i = 0; i < brokenImageUrlList.size(); i++)
{
mBrokenImageInfoContainer[i].url = brokenImageUrlList[i];
}
+
+ mDefaultBrokenImageUrl = defaultBrokenUrl;
}
VisualUrl::Type VisualFactoryCache::GetBrokenImageVisualType(int index)
return mBrokenImageInfoContainer[index].visualType;
}
-Geometry VisualFactoryCache::CreateNPatchGeometry(Uint16Pair gridSize)
-{
- uint16_t gridWidth = gridSize.GetWidth();
- uint16_t gridHeight = gridSize.GetHeight();
-
- // Create vertices
- Vector<Vector2> vertices;
- vertices.Reserve((gridWidth + 1) * (gridHeight + 1));
-
- for(int y = 0; y < gridHeight + 1; ++y)
- {
- for(int x = 0; x < gridWidth + 1; ++x)
- {
- AddVertex(vertices, x, y);
- }
- }
-
- // Create indices
- Vector<unsigned short> indices;
- indices.Reserve(gridWidth * gridHeight * 6);
-
- unsigned int rowIdx = 0;
- unsigned int nextRowIdx = gridWidth + 1;
- for(int y = 0; y < gridHeight; ++y, ++nextRowIdx, ++rowIdx)
- {
- for(int x = 0; x < gridWidth; ++x, ++nextRowIdx, ++rowIdx)
- {
- AddQuadIndices(indices, rowIdx, nextRowIdx);
- }
- }
-
- return GenerateGeometry(vertices, indices);
-}
-
Geometry VisualFactoryCache::GetNPatchGeometry(int index)
{
Geometry geometry;
geometry = GetGeometry(VisualFactoryCache::NINE_PATCH_GEOMETRY);
if(!geometry)
{
- geometry = CreateNPatchGeometry(Uint16Pair(3,3));
+ geometry = NPatchHelper::CreateGridGeometry(Uint16Pair(3,3));
SaveGeometry(VisualFactoryCache::NINE_PATCH_GEOMETRY, geometry);
}
}
else if(data->GetStretchPixelsX().Size() > 0 || data->GetStretchPixelsY().Size() > 0)
{
Uint16Pair gridSize(2 * data->GetStretchPixelsX().Size() + 1, 2 * data->GetStretchPixelsY().Size() + 1);
- geometry = CreateNPatchGeometry(gridSize);
+ geometry = NPatchHelper::CreateGridGeometry(gridSize);
}
}
else
geometry = GetGeometry(VisualFactoryCache::NINE_PATCH_GEOMETRY);
if(!geometry)
{
- geometry = CreateNPatchGeometry(Uint16Pair(3,3));
+ geometry = NPatchHelper::CreateGridGeometry(Uint16Pair(3,3));
SaveGeometry(VisualFactoryCache::NINE_PATCH_GEOMETRY, geometry);
}
}
yStretchCount = data->GetStretchPixelsY().Count();
}
- if(DALI_LIKELY((xStretchCount == 0 && yStretchCount == 0)))
+ if(DALI_LIKELY((xStretchCount == 0 && yStretchCount == 0) || (xStretchCount == 1 && yStretchCount == 1)))
{
shader = GetShader(VisualFactoryCache::NINE_PATCH_SHADER);
if(DALI_UNLIKELY(!shader))
return shader;
}
-void VisualFactoryCache::RegisterStretchProperties(Renderer& renderer, const char* uniformName, const NPatchUtility::StretchRanges& stretchPixels, uint16_t imageExtent)
-{
- uint16_t prevEnd = 0;
- uint16_t prevFix = 0;
- uint16_t prevStretch = 0;
- unsigned int i = 1;
- for(NPatchUtility::StretchRanges::ConstIterator it = stretchPixels.Begin(); it != stretchPixels.End(); ++it, ++i)
- {
- uint16_t start = it->GetX();
- uint16_t end = it->GetY();
-
- uint16_t fix = prevFix + start - prevEnd;
- uint16_t stretch = prevStretch + end - start;
-
- std::stringstream uniform;
- uniform << uniformName << "[" << i << "]";
- renderer.RegisterProperty(uniform.str(), Vector2(fix, stretch));
-
- prevEnd = end;
- prevFix = fix;
- prevStretch = stretch;
- }
-
- {
- prevFix += imageExtent - prevEnd;
- std::stringstream uniform;
- uniform << uniformName << "[" << i << "]";
- renderer.RegisterProperty(uniform.str(), Vector2(prevFix, prevStretch));
- }
-}
-
void VisualFactoryCache::ApplyTextureAndUniforms(Renderer& renderer, int index)
{
const NPatchData* data;
if(mNPatchLoader.GetNPatchData(mBrokenImageInfoContainer[index].npatchId, data) && data->GetLoadingState() == NPatchData::LoadingState::LOAD_COMPLETE)
{
textureSet = data->GetTextures();
- mBrokenImageInfoContainer[index].texture = data->GetTextures().GetTexture(0);
-
- if(data->GetStretchPixelsX().Size() == 1 && data->GetStretchPixelsY().Size() == 1)
- {
- //special case for 9 patch
- Uint16Pair stretchX = data->GetStretchPixelsX()[0];
- Uint16Pair stretchY = data->GetStretchPixelsY()[0];
-
- uint16_t stretchWidth = (stretchX.GetY() >= stretchX.GetX()) ? stretchX.GetY() - stretchX.GetX() : 0;
- uint16_t stretchHeight = (stretchY.GetY() >= stretchY.GetX()) ? stretchY.GetY() - stretchY.GetX() : 0;
-
- renderer.RegisterProperty("uFixed[0]", Vector2::ZERO);
- renderer.RegisterProperty("uFixed[1]", Vector2(stretchX.GetX(), stretchY.GetX()));
- renderer.RegisterProperty("uFixed[2]", Vector2(data->GetCroppedWidth() - stretchWidth, data->GetCroppedHeight() - stretchHeight));
- renderer.RegisterProperty("uStretchTotal", Vector2(stretchWidth, stretchHeight));
- }
- else
- {
- renderer.RegisterProperty("uNinePatchFactorsX[0]", Vector2::ZERO);
- renderer.RegisterProperty("uNinePatchFactorsY[0]", Vector2::ZERO);
-
- RegisterStretchProperties(renderer, "uNinePatchFactorsX", data->GetStretchPixelsX(), data->GetCroppedWidth());
- RegisterStretchProperties(renderer, "uNinePatchFactorsY", data->GetStretchPixelsY(), data->GetCroppedHeight());
- }
+ mBrokenImageInfoContainer[index].texture = textureSet.GetTexture(0);
+ NPatchHelper::ApplyTextureAndUniforms(renderer, data);
renderer.SetTextures(textureSet);
}
}
void VisualFactoryCache::UpdateBrokenImageRenderer(Renderer& renderer, const Vector2& size)
{
+
+ bool useDefaultBrokenImage = false;
+ if(mBrokenImageInfoContainer.size() == 0)
+ {
+ useDefaultBrokenImage = true;
+ }
+
// Load Information for broken image
- for(uint32_t index = 0; index < mBrokenImageInfoContainer.size(); index++)
+ for(uint32_t index = 0; (index < mBrokenImageInfoContainer.size()) && !useDefaultBrokenImage; index++)
{
if(mBrokenImageInfoContainer[index].width == 0 && mBrokenImageInfoContainer[index].height == 0)
{
}
else
{
- DALI_LOG_ERROR("Can't update renderer for broken image. maybe image loading is failed [path:%s] \n",mBrokenImageInfoContainer[index].url.c_str());
+ DALI_LOG_ERROR("Can't update renderer for broken image. maybe image loading is failed [index:%d] [path:%s] \n",index, mBrokenImageInfoContainer[index].url.c_str());
+ useDefaultBrokenImage = true;
}
}
else
{
- GetBrokenVisualImage(index);
+ if(!GetBrokenVisualImage(index))
+ {
+ DALI_LOG_ERROR("Can't update renderer for broken image. maybe image loading is failed [index:%d] [path:%s] \n",index, mBrokenImageInfoContainer[index].url.c_str());
+ useDefaultBrokenImage = true;
+ }
}
}
}
}
+ if(!mUseDefaultBrokenImageOnly && useDefaultBrokenImage)
+ {
+ // Clear broken info
+ mBrokenImageInfoContainer.clear();
+
+ // assign for broken image
+ const int defaultBrokenIndex = 0;
+ mBrokenImageInfoContainer.assign(1, BrokenImageInfo());
+ mBrokenImageInfoContainer[defaultBrokenIndex].url = mDefaultBrokenImageUrl;
+ VisualUrl visualUrl(mBrokenImageInfoContainer[defaultBrokenIndex].url);
+ mBrokenImageInfoContainer[defaultBrokenIndex].visualType = visualUrl.GetType();
+ mUseDefaultBrokenImageOnly = true;
+ }
+
// Set Texutre to renderer
int brokenIndex = GetProperBrokenImageIndex(size);
if(GetBrokenImageVisualType(brokenIndex) == VisualUrl::N_PATCH)
{
// Sets the default broken type
int32_t returnIndex = 0;
- if((size.width == 0 || size.height == 0))
+ if((size.width == 0 || size.height == 0) || mUseDefaultBrokenImageOnly )
{
// To do : Need to add observer about size
return returnIndex;
* @brief Set an image to be used when a visual has failed to correctly render
* @param[in] brokenImageUrlList The broken image url list
*/
- void SetBrokenImageUrl(const std::vector<std::string>& brokenImageUrlList);
+ void SetBrokenImageUrl(std::string& defaultBrokenUrl, const std::vector<std::string>& brokenImageUrlList);
/**
* @brief Update the broken image Renderer object
void ApplyTextureAndUniforms(Renderer& renderer, int index);
/**
- * @brief Creates a Npatch Geometry object
- *
- * @param[in] gridSize The gridSize for creating a geometry
- * @return The Geometry for NPatch
- */
- Geometry CreateNPatchGeometry(Uint16Pair gridSize);
-
- /**
* @brief Gets a geometry for npatch image
*
* @param[in] index the index of broken image
Shader GetNPatchShader(int index);
/**
- * @brief Registers a properties for Stretch Ranges
- *
- * @param[in,out] renderer The renderer for broken image
- * @param[in] uniformName The name of the uniform
- * @param[in] stretchPixels The stretchable pixels in the cropped image space
- * @param[in] imageExtent The imageExtent
- */
- void RegisterStretchProperties(Renderer& renderer, const char* uniformName, const NPatchUtility::StretchRanges& stretchPixels, uint16_t imageExtent);
-
- /**
* @brief Returns a broken image type
* @param[in] index BrokenImage index
* @return The broken image type.
std::unique_ptr<VectorAnimationManager> mVectorAnimationManager;
bool mPreMultiplyOnLoad;
std::vector<BrokenImageInfo> mBrokenImageInfoContainer;
+ std::string mDefaultBrokenImageUrl;
+ bool mUseDefaultBrokenImageOnly;
};
} // namespace Internal
if(styleManager)
{
customBrokenImageUrlList = Toolkit::DevelStyleManager::GetBrokenImageUrlList(styleManager);
- if(customBrokenImageUrlList.size() == 0)
- {
- Property::Map config = Toolkit::DevelStyleManager::GetConfigurations(styleManager);
- config["brokenImageUrl"].Get(brokenImageUrl);
- customBrokenImageUrlList.push_back(brokenImageUrl);
- }
- mFactoryCache->SetBrokenImageUrl(customBrokenImageUrlList);
- }
- else
- {
- // Set default image
- customBrokenImageUrlList.push_back(brokenImageUrl);
- mFactoryCache->SetBrokenImageUrl(customBrokenImageUrlList);
+ Property::Map config = Toolkit::DevelStyleManager::GetConfigurations(styleManager);
+ config["brokenImageUrl"].Get(brokenImageUrl);
}
+
+ // Add default image
+ mFactoryCache->SetBrokenImageUrl(brokenImageUrl, customBrokenImageUrlList);
}
Internal::VisualFactoryCache& VisualFactory::GetFactoryCache()