X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=shared%2Futility.h;h=71d7a55a986eeb07b64fc7f08faa3ad932bb905d;hb=38b87ec05860401c3dcbf20d047aa0b55ea5841a;hp=3285b981f4cceaf7172fd13f3cdcdfc9dc5e0853;hpb=ff961cccdcbf1c30b0f53b0da027df855cde2b63;p=platform%2Fcore%2Fuifw%2Fdali-demo.git diff --git a/shared/utility.h b/shared/utility.h index 3285b98..71d7a55 100644 --- a/shared/utility.h +++ b/shared/utility.h @@ -1,8 +1,8 @@ -#ifndef __DALI_DEMO_UTILITY_H__ -#define __DALI_DEMO_UTILITY_H__ +#ifndef DALI_DEMO_UTILITY_H +#define DALI_DEMO_UTILITY_H /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 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. @@ -19,73 +19,65 @@ */ #include -#include -#include -#include +#include +#include +#include +#include namespace DemoHelper { - -Dali::PixelData LoadPixelData( const char* imagePath, - Dali::ImageDimensions size, - Dali::FittingMode::Type fittingMode, - Dali::SamplingMode::Type samplingMode ) +Dali::Texture LoadTexture(const char* imagePath, + Dali::ImageDimensions size = Dali::ImageDimensions(), + Dali::FittingMode::Type fittingMode = Dali::FittingMode::DEFAULT, + Dali::SamplingMode::Type samplingMode = Dali::SamplingMode::DEFAULT, + bool orientationCorrection = true) { - Dali::BitmapLoader loader = Dali::BitmapLoader::New( imagePath, size, fittingMode, samplingMode ); - loader.Load(); - return loader.GetPixelData(); -} + Dali::Devel::PixelBuffer pixelBuffer = LoadImageFromFile(imagePath, size, fittingMode, samplingMode, orientationCorrection); + Dali::Texture texture = Dali::Texture::New(Dali::TextureType::TEXTURE_2D, + pixelBuffer.GetPixelFormat(), + pixelBuffer.GetWidth(), + pixelBuffer.GetHeight()); + Dali::PixelData pixelData = Dali::Devel::PixelBuffer::Convert(pixelBuffer); + texture.Upload(pixelData); -Dali::Atlas LoadImage( const char* imagePath, - Dali::ImageDimensions size = Dali::ImageDimensions(), - Dali::FittingMode::Type fittingMode = Dali::FittingMode::DEFAULT, - Dali::SamplingMode::Type samplingMode = Dali::SamplingMode::DEFAULT ) -{ - Dali::PixelData pixelData = LoadPixelData(imagePath, size, fittingMode, samplingMode); - Dali::Atlas image =Dali:: Atlas::New( pixelData.GetWidth(), pixelData.GetHeight(), pixelData.GetPixelFormat() ); - image.Upload( pixelData, 0u, 0u ); + return texture; +} - return image; +Dali::Texture LoadWindowFillingTexture(Dali::Uint16Pair size, const char* imagePath) +{ + return LoadTexture(imagePath, size, Dali::FittingMode::SCALE_TO_FILL, Dali::SamplingMode::BOX_THEN_LINEAR); } -Dali::Texture LoadTexture( const char* imagePath, - Dali::ImageDimensions size = Dali::ImageDimensions(), - Dali::FittingMode::Type fittingMode = Dali::FittingMode::DEFAULT, - Dali::SamplingMode::Type samplingMode = Dali::SamplingMode::DEFAULT ) +Dali::Geometry CreateTexturedQuad() { - Dali::PixelData pixelData = LoadPixelData(imagePath, size, fittingMode, samplingMode); - Dali::Texture texture = Dali::Texture::New( Dali::TextureType::TEXTURE_2D, - pixelData.GetPixelFormat(), - pixelData.GetWidth(), - pixelData.GetHeight() ); - texture.Upload( pixelData ); + struct Vertex + { + Dali::Vector2 position; + Dali::Vector2 texCoord; + }; - return texture; -} + static const Vertex data[] = {{Dali::Vector2(-0.5f, -0.5f), Dali::Vector2(0.0f, 0.0f)}, + {Dali::Vector2(0.5f, -0.5f), Dali::Vector2(1.0f, 0.0f)}, + {Dali::Vector2(-0.5f, 0.5f), Dali::Vector2(0.0f, 1.0f)}, + {Dali::Vector2(0.5f, 0.5f), Dali::Vector2(1.0f, 1.0f)}}; -/** - * @brief Load an bitmap resource. - * - * If it is required to scaled-down to no more than the stage dimensions, - * uses image scaling mode FittingMode::SCALE_TO_FILL to resize the image at - * load time to cover the entire stage with pixels with no borders, - * and filter mode BOX_THEN_LINEAR to sample the image with - * maximum quality. - */ + Dali::VertexBuffer vertexBuffer; + Dali::Property::Map vertexFormat; + vertexFormat["aPosition"] = Dali::Property::VECTOR2; + vertexFormat["aTexCoord"] = Dali::Property::VECTOR2; -Dali::Atlas LoadStageFillingImage( const char* imagePath ) -{ - Dali::Vector2 stageSize = Dali::Stage::GetCurrent().GetSize(); - return LoadImage( imagePath, Dali::ImageDimensions( stageSize.x, stageSize.y ), Dali::FittingMode::SCALE_TO_FILL, Dali::SamplingMode::BOX_THEN_LINEAR ); -} + //Create a vertex buffer for vertex positions and texture coordinates + vertexBuffer = Dali::VertexBuffer::New(vertexFormat); + vertexBuffer.SetData(data, 4u); -Dali::Texture LoadStageFillingTexture( const char* imagePath ) -{ - Dali::Vector2 stageSize = Dali::Stage::GetCurrent().GetSize(); - return LoadTexture( imagePath, Dali::ImageDimensions( stageSize.x, stageSize.y ), Dali::FittingMode::SCALE_TO_FILL, Dali::SamplingMode::BOX_THEN_LINEAR ); -} + //Create the geometry + Dali::Geometry geometry = Dali::Geometry::New(); + geometry.AddVertexBuffer(vertexBuffer); + geometry.SetType(Dali::Geometry::TRIANGLE_STRIP); -} // DemoHelper + return geometry; +} +} // namespace DemoHelper -#endif // __DALI_DEMO_HELPER_VIEW_H__ +#endif // DALI_DEMO_UTILITY_H