From 30db1d740b360cc46dec051f503c8c20f51141b0 Mon Sep 17 00:00:00 2001 From: Andrew Cox Date: Tue, 31 Mar 2015 15:55:29 +0100 Subject: [PATCH] Cleanup for removal of ImageAttributes from public API Change-Id: Ia2efe9ef0dffe1361f0e6995b0e8134324916a4d Signed-off-by: Andrew Cox --- .../test-platform-abstraction.cpp | 22 ++- .../test-platform-abstraction.h | 23 ++- .../shader-effects/nine-patch-mask-effect.cpp | 12 +- plugins/dali-script-v8/file.list | 2 - .../src/constants/constants-wrapper.cpp | 14 +- plugins/dali-script-v8/src/dali-wrapper.cpp | 2 - .../src/image/image-attributes-api.cpp | 209 --------------------- .../src/image/image-attributes-api.h | 63 ------- .../src/image/image-attributes-wrapper.cpp | 145 -------------- .../src/image/image-attributes-wrapper.h | 85 --------- .../src/image/resource-image-api.cpp | 75 ++++---- .../dali-script-v8/src/image/resource-image-api.h | 1 - 12 files changed, 84 insertions(+), 569 deletions(-) delete mode 100644 plugins/dali-script-v8/src/image/image-attributes-api.cpp delete mode 100644 plugins/dali-script-v8/src/image/image-attributes-api.h delete mode 100644 plugins/dali-script-v8/src/image/image-attributes-wrapper.cpp delete mode 100644 plugins/dali-script-v8/src/image/image-attributes-wrapper.h diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-platform-abstraction.cpp b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-platform-abstraction.cpp index 3d4d1d5..ddf0356 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-platform-abstraction.cpp +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-platform-abstraction.cpp @@ -64,20 +64,26 @@ void TestPlatformAbstraction::Resume() mTrace.PushCall("Resume", ""); } -void TestPlatformAbstraction::GetClosestImageSize( const std::string& filename, - const ImageAttributes& attributes, - Vector2& closestSize) +ImageDimensions TestPlatformAbstraction::GetClosestImageSize( const std::string& filename, + ImageDimensions size, + FittingMode::Type scalingMode, + SamplingMode::Type samplingMode, + bool orientationCorrection ) { - closestSize = mClosestSize; + ImageDimensions closestSize = ImageDimensions( mClosestSize.x, mClosestSize.y ); mTrace.PushCall("GetClosestImageSize", ""); + return closestSize; } -void TestPlatformAbstraction::GetClosestImageSize( Integration::ResourcePointer resourceBuffer, - const ImageAttributes& attributes, - Vector2& closestSize) +ImageDimensions TestPlatformAbstraction::GetClosestImageSize( Integration::ResourcePointer resourceBuffer, + ImageDimensions size, + FittingMode::Type scalingMode, + SamplingMode::Type samplingMode, + bool orientationCorrection ) { - closestSize = mClosestSize; + ImageDimensions closestSize = ImageDimensions( mClosestSize.x, mClosestSize.y ); mTrace.PushCall("GetClosestImageSize", ""); + return closestSize; } /** diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-platform-abstraction.h b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-platform-abstraction.h index a4ec8d3..c3beebe 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-platform-abstraction.h +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-platform-abstraction.h @@ -21,6 +21,7 @@ // EXTERNAL INCLUDES #include #include +#include // INTERNAL INCLUDES #include @@ -97,13 +98,23 @@ public: */ virtual void Resume(); - virtual void GetClosestImageSize( const std::string& filename, - const ImageAttributes& attributes, - Vector2& closestSize); + /** + * @copydoc PlatformAbstraction::GetClosestImageSize() + */ + virtual ImageDimensions GetClosestImageSize( const std::string& filename, + ImageDimensions size, + FittingMode::Type scalingMode, + SamplingMode::Type samplingMode, + bool orientationCorrection ); - virtual void GetClosestImageSize( Integration::ResourcePointer resourceBuffer, - const ImageAttributes& attributes, - Vector2& closestSize); + /** + * @copydoc PlatformAbstraction::GetClosestImageSize() + */ + virtual ImageDimensions GetClosestImageSize( Integration::ResourcePointer resourceBuffer, + ImageDimensions size, + FittingMode::Type scalingMode, + SamplingMode::Type samplingMode, + bool orientationCorrection ); /** * @copydoc PlatformAbstraction::LoadResource() diff --git a/dali-toolkit/public-api/shader-effects/nine-patch-mask-effect.cpp b/dali-toolkit/public-api/shader-effects/nine-patch-mask-effect.cpp index d2b8967..79c8752 100644 --- a/dali-toolkit/public-api/shader-effects/nine-patch-mask-effect.cpp +++ b/dali-toolkit/public-api/shader-effects/nine-patch-mask-effect.cpp @@ -108,19 +108,19 @@ static void DoApply( ImageActor actor, const std::string& maskImage, const Vecto void Apply( ImageActor actor, const std::string& maskImage ) { - Vector2 maskSize = ResourceImage::GetImageSize( maskImage ); + const Uint16Pair maskSize = ResourceImage::GetImageSize( maskImage ); - const float leftRight = (maskSize.width - 1.0f) * 0.5f; - const float topBottom = (maskSize.height - 1.0f) * 0.5f; + const float leftRight = (maskSize.GetWidth() - 1.0f) * 0.5f; + const float topBottom = (maskSize.GetHeight() - 1.0f) * 0.5f; - DoApply( actor, maskImage, maskSize, Vector4( leftRight, topBottom, leftRight, topBottom ) ); + DoApply( actor, maskImage, Vector2( maskSize.GetWidth(), maskSize.GetHeight() ), Vector4( leftRight, topBottom, leftRight, topBottom ) ); } void Apply( ImageActor actor, const std::string& maskImage, const Vector4& maskBorder ) { - Vector2 maskSize = ResourceImage::GetImageSize( maskImage ); + const Uint16Pair maskSize = ResourceImage::GetImageSize( maskImage ); - DoApply( actor, maskImage, maskSize, maskBorder ); + DoApply( actor, maskImage, Vector2( maskSize.GetWidth(), maskSize.GetHeight() ), maskBorder ); } } // namespace NinePatchMaskEffect diff --git a/plugins/dali-script-v8/file.list b/plugins/dali-script-v8/file.list index 91b3661..9dc4293 100644 --- a/plugins/dali-script-v8/file.list +++ b/plugins/dali-script-v8/file.list @@ -27,10 +27,8 @@ script_v8_plugin_src_files = \ $(v8_plugin_dir)/events/pan-gesture-detector-api.cpp \ $(v8_plugin_dir)/events/pan-gesture-detector-wrapper.cpp \ $(v8_plugin_dir)/stage/stage-api.cpp \ - $(v8_plugin_dir)/image/image-attributes-api.cpp \ $(v8_plugin_dir)/shader-effects/shader-effect-api.cpp \ $(v8_plugin_dir)/shader-effects/shader-effect-wrapper.cpp \ - $(v8_plugin_dir)/image/image-attributes-wrapper.cpp \ $(v8_plugin_dir)/image/image-wrapper.cpp \ $(v8_plugin_dir)/image/image-api.cpp \ $(v8_plugin_dir)/image/buffer-image-api.cpp \ diff --git a/plugins/dali-script-v8/src/constants/constants-wrapper.cpp b/plugins/dali-script-v8/src/constants/constants-wrapper.cpp index 9815aa7..4217d98 100644 --- a/plugins/dali-script-v8/src/constants/constants-wrapper.cpp +++ b/plugins/dali-script-v8/src/constants/constants-wrapper.cpp @@ -168,8 +168,18 @@ const IntegerPair EnumTable[] = { "RESOURCE_LOADING_SUCCEEDED", Dali::ResourceLoadingSucceeded }, { "RESOUCE_LOADING_FAILED", Dali::ResourceLoadingFailed }, - - + { "FITTING_MODE_SHRINK_TO_FIT", FittingMode::SHRINK_TO_FIT }, + { "FITTING_MODE_SCALE_TO_FILL", FittingMode::SCALE_TO_FILL }, + { "FITTING_MODE_FIT_WIDTH", FittingMode::FIT_WIDTH }, + { "FITTING_MODE_FIT_HEIGHT", FittingMode::FIT_HEIGHT }, + + { "SAMPLING_MODE_BOX", SamplingMode::BOX }, + { "SAMPLING_MODE_NEAREST", SamplingMode::NEAREST }, + { "SAMPLING_MODE_LINEAR", SamplingMode::LINEAR }, + { "SAMPLING_MODE_BOX_THEN_NEAREST", SamplingMode::BOX_THEN_NEAREST }, + { "SAMPLING_MODE_BOX_THEN_LINEAR", SamplingMode::BOX_THEN_LINEAR }, + { "SAMPLING_MODE_NO_FILTER", SamplingMode::NO_FILTER }, + { "SAMPLING_MODE_DONT_CARE", SamplingMode::DONT_CARE }, { "BLEND_FACTOR_ZERO", BlendingFactor::ZERO }, { "BLEND_FACTOR_ONE", BlendingFactor::ONE }, diff --git a/plugins/dali-script-v8/src/dali-wrapper.cpp b/plugins/dali-script-v8/src/dali-wrapper.cpp index f674551..38231b8 100644 --- a/plugins/dali-script-v8/src/dali-wrapper.cpp +++ b/plugins/dali-script-v8/src/dali-wrapper.cpp @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -72,7 +71,6 @@ const ApiFunction ConstructorFunctionTable[]= { "BufferImage", ImageWrapper::NewImage }, { "NinePatchImage", ImageWrapper::NewImage }, { "FrameBufferImage", ImageWrapper::NewImage }, - { "ImageAttributes", ImageAttributesWrapper::NewImageAttributes }, { "Animation", AnimationWrapper::NewAnimation}, { "ShaderEffect", ShaderEffectWrapper::NewShaderEffect}, { "Builder", BuilderWrapper::NewBuilder}, diff --git a/plugins/dali-script-v8/src/image/image-attributes-api.cpp b/plugins/dali-script-v8/src/image/image-attributes-api.cpp deleted file mode 100644 index 5e7006e..0000000 --- a/plugins/dali-script-v8/src/image/image-attributes-api.cpp +++ /dev/null @@ -1,209 +0,0 @@ -/* - * Copyright (c) 2015 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 "image-attributes-api.h" - -// INTERNAL INCLUDES -#include -#include -#include -#include - -namespace Dali -{ - -namespace V8Plugin -{ - -ImageAttributes ImageAttributesApi::GetImageAttributesFromObject( v8::Isolate* isolate, v8::Local object ) -{ - v8::HandleScope handleScope( isolate); - - if( BaseWrappedObject::IsWrappedType ( isolate, object, BaseWrappedObject::IMAGE_ATTRIBUTES )) - { - v8::Local field = v8::Local::Cast( object->GetInternalField(0) ); - void* ptr = field->Value(); - BaseWrappedObject* wrappedObject = static_cast< BaseWrappedObject *>(ptr); - ImageAttributesWrapper* wrapper = static_cast< ImageAttributesWrapper*>( wrappedObject );; - return wrapper->GetImageAttributes(); - } - else - { - DALI_SCRIPT_EXCEPTION( isolate, "bad image attributes url"); - return ImageAttributes(); - } - -} - -/*************************************** - * IMAGE ATTRIBUTES FUNCTIONS - * - ****************************************/ -ImageAttributes ImageAttributesApi::New( const v8::FunctionCallbackInfo< v8::Value >& args ) -{ - v8::Isolate* isolate = args.GetIsolate(); - // two combinations of constructor - // 1 = no parameters - // 2 = width, height - bool foundParams( false ); - int params[2]; - - V8Utils::ReadIntegerArguments( foundParams, ¶ms[0],2,args,0); - if( !foundParams ) - { - if( args.Length() != 0 ) - { - DALI_SCRIPT_EXCEPTION( isolate, " ImageAttributes::New invalid params"); - return Dali::ImageAttributes(); - } - return Dali::ImageAttributes::New(); - } - else - { - return Dali::ImageAttributes::New( params[0], params[1] ); - } - -} - -ImageAttributes& ImageAttributesApi::GetImageAttributes( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args ) -{ - v8::Local object = args.This(); - v8::Local field = v8::Local::Cast( object->GetInternalField(0) ); - void* ptr = field->Value(); - - ImageAttributesWrapper* wrapper = static_cast< ImageAttributesWrapper *>(ptr); - return wrapper->GetImageAttributes(); -} - -void ImageAttributesApi::SetSize( const v8::FunctionCallbackInfo< v8::Value >& args ) -{ - v8::Isolate* isolate = args.GetIsolate(); - v8::HandleScope handleScope( isolate ); - ImageAttributes& attribs( GetImageAttributes( isolate, args )); - - bool found; - Vector2 size = V8Utils::GetVector2Parameter( PARAMETER_0, found, isolate, args ); - if (!found) - { - DALI_SCRIPT_EXCEPTION( isolate, "invalid size parameter" ); - return; - } - else - { - attribs.SetSize( size ); - } -} - -void ImageAttributesApi::SetScalingMode( const v8::FunctionCallbackInfo< v8::Value >& args ) -{ - v8::Isolate* isolate = args.GetIsolate(); - v8::HandleScope handleScope( isolate ); - ImageAttributes& attribs( GetImageAttributes( isolate, args )); - - bool found(false); - int value = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0); - if( !found ) - { - DALI_SCRIPT_EXCEPTION( isolate, "invalid scaling mode parameter"); - return; - } - if( value!= ImageAttributes::ShrinkToFit || - value!= ImageAttributes::ScaleToFill || - value!= ImageAttributes::FitWidth || - value!= ImageAttributes::FitHeight ) - { - DALI_SCRIPT_EXCEPTION( isolate, "invalid scaling mode parameter"); - return; - } - - attribs.SetScalingMode(static_cast( value) ); -} - -void ImageAttributesApi::SetOrientationCorrection( const v8::FunctionCallbackInfo< v8::Value >& args ) -{ - v8::Isolate* isolate = args.GetIsolate(); - v8::HandleScope handleScope( isolate ); - ImageAttributes& attribs( GetImageAttributes( isolate, args )); - - bool parameterFound(false); - bool value = V8Utils::GetBooleanParameter( PARAMETER_0 , parameterFound, isolate, args ); - - if( !parameterFound ) - { - DALI_SCRIPT_EXCEPTION( isolate, "boolean parameter not found"); - return; - } - attribs.SetOrientationCorrection( value ); -} - -void ImageAttributesApi::GetWidth( const v8::FunctionCallbackInfo< v8::Value >& args ) -{ - v8::Isolate* isolate = args.GetIsolate(); - v8::HandleScope handleScope( isolate ); - ImageAttributes& attribs( GetImageAttributes( isolate, args )); - - args.GetReturnValue().Set( v8::Integer::New( isolate, attribs.GetWidth() ) ); -} - -void ImageAttributesApi::GetHeight( const v8::FunctionCallbackInfo< v8::Value >& args ) -{ - v8::Isolate* isolate = args.GetIsolate(); - v8::HandleScope handleScope( isolate ); - ImageAttributes& attribs( GetImageAttributes( isolate, args )); - - args.GetReturnValue().Set( v8::Integer::New( isolate, attribs.GetHeight() ) ); - -} - -void ImageAttributesApi::GetSize( const v8::FunctionCallbackInfo< v8::Value >& args ) -{ - v8::Isolate* isolate = args.GetIsolate(); - v8::HandleScope handleScope( isolate ); - ImageAttributes& attribs( GetImageAttributes( isolate, args )); - - Vector2 vec( attribs.GetSize() ); - Dali::Property::Value value( vec ); - - v8::Local object = PropertyValueWrapper::WrapDaliProperty( isolate, value); - args.GetReturnValue().Set( object ); -} - -void ImageAttributesApi::GetScalingMode( const v8::FunctionCallbackInfo< v8::Value >& args ) -{ - v8::Isolate* isolate = args.GetIsolate(); - v8::HandleScope handleScope( isolate ); - ImageAttributes& attribs( GetImageAttributes( isolate, args )); - - args.GetReturnValue().Set( v8::Integer::New( isolate, attribs.GetScalingMode() ) ); - -} - -void ImageAttributesApi::GetOrientationCorrection( const v8::FunctionCallbackInfo< v8::Value >& args ) -{ - v8::Isolate* isolate = args.GetIsolate(); - v8::HandleScope handleScope( isolate ); - ImageAttributes& attribs( GetImageAttributes( isolate, args )); - - args.GetReturnValue().Set( v8::Boolean::New( isolate, attribs.GetOrientationCorrection() ) ); - -} - - -} // namespace V8Plugin - -} // namespace Dali diff --git a/plugins/dali-script-v8/src/image/image-attributes-api.h b/plugins/dali-script-v8/src/image/image-attributes-api.h deleted file mode 100644 index c474ef0..0000000 --- a/plugins/dali-script-v8/src/image/image-attributes-api.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef __DALI_V8PLUGIN_IMAGE_ATTRIBUTES_API_H__ -#define __DALI_V8PLUGIN_IMAGE_ATTRIBUTES_API_H__ - -/* - * Copyright (c) 2015 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 -#include - - -namespace Dali -{ - -namespace V8Plugin -{ - -namespace ImageAttributesApi -{ - ImageAttributes& GetImageAttributes( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args ); - - ImageAttributes GetImageAttributesFromObject( v8::Isolate* isolate, v8::Local object ); - - /** - * @brief Creates a new Image Attribute object based on some JavaScript parameters. - * @param[in] args constructor parameters - * @return ImageAttributes - */ - ImageAttributes New( const v8::FunctionCallbackInfo< v8::Value >& args ); - - /** - * ImageAttributes API see image-attributes.h for a description - */ - void SetSize( const v8::FunctionCallbackInfo< v8::Value >& args ); - void SetScalingMode( const v8::FunctionCallbackInfo< v8::Value >& args ); - void SetOrientationCorrection( const v8::FunctionCallbackInfo< v8::Value >& args ); - void GetWidth( const v8::FunctionCallbackInfo< v8::Value >& args ); - void GetHeight( const v8::FunctionCallbackInfo< v8::Value >& args ); - void GetSize( const v8::FunctionCallbackInfo< v8::Value >& args ); - void GetScalingMode( const v8::FunctionCallbackInfo< v8::Value >& args ); - void GetOrientationCorrection( const v8::FunctionCallbackInfo< v8::Value >& args ); - -}; // namespace ImageAttributesApi - -} // namespace V8Plugin - -} // namespace Dali - -#endif // header __DALI_V8PLUGIN_IMAGE_ATTRIBUTES_API_H__ diff --git a/plugins/dali-script-v8/src/image/image-attributes-wrapper.cpp b/plugins/dali-script-v8/src/image/image-attributes-wrapper.cpp deleted file mode 100644 index fa89f79..0000000 --- a/plugins/dali-script-v8/src/image/image-attributes-wrapper.cpp +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (c) 2015 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 "image-attributes-wrapper.h" - -// INTERNAL INCLUDES -#include -#include -#include -#include -#include - -namespace Dali -{ - -namespace V8Plugin -{ - -v8::Persistent ImageAttributesWrapper::mImageAttributesTemplate; - -namespace -{ - -/** - * Contains a list of all functions that can be called - */ -const ApiFunction ImageAttributeFunctionTable[]= -{ - /************************************** - * ImageAttributes API (in order of image-attributes.h) - **************************************/ - { "SetSize", ImageAttributesApi::SetSize }, - { "SetScalingMode", ImageAttributesApi::SetScalingMode }, - { "SetOrientationCorrection", ImageAttributesApi::SetOrientationCorrection }, - { "GetWidth", ImageAttributesApi::GetWidth }, - { "GetHeight", ImageAttributesApi::GetHeight }, - { "GetSize", ImageAttributesApi::GetSize }, - { "GetScalingMode", ImageAttributesApi::GetScalingMode }, - { "GetOrientationCorrection", ImageAttributesApi::GetOrientationCorrection }, -}; - -const unsigned int ImageAttributeFunctionTableCount = sizeof(ImageAttributeFunctionTable)/sizeof(ImageAttributeFunctionTable[0]); -} //un-named space - - -ImageAttributesWrapper::ImageAttributesWrapper( const Dali::ImageAttributes& imageAttributes, GarbageCollectorInterface& gc ) -: BaseWrappedObject( BaseWrappedObject::IMAGE_ATTRIBUTES , gc ) -{ - mImageAttributes = imageAttributes; -} - -v8::Handle ImageAttributesWrapper::WrapImageAttributes(v8::Isolate* isolate, const Dali::ImageAttributes& attributes ) -{ - v8::EscapableHandleScope handleScope( isolate ); - v8::Local objectTemplate; - - objectTemplate = GetImageAttributesTemplate( isolate); - - // create an instance of the template - v8::Local localObject = objectTemplate->NewInstance(); - - // create the ImageAttributes wrapper - ImageAttributesWrapper* pointer = new ImageAttributesWrapper( attributes, Dali::V8Plugin::DaliWrapper::Get().GetDaliGarbageCollector() ); - - // assign the JavaScript object to the wrapper. - pointer->SetJavascriptObject( isolate, localObject ); - - return handleScope.Escape( localObject ); -} - -v8::Local ImageAttributesWrapper::GetImageAttributesTemplate( v8::Isolate* isolate) -{ - v8::EscapableHandleScope handleScope( isolate ); - v8::Local objectTemplate; - - - if( mImageAttributesTemplate.IsEmpty() ) - { - objectTemplate = MakeImageAttributesTemplate( isolate ); - mImageAttributesTemplate.Reset( isolate, objectTemplate ); - } - else - { - // get the object template - objectTemplate = v8::Local::New( isolate, mImageAttributesTemplate ); - } - return handleScope.Escape( objectTemplate ); -} - -v8::Handle ImageAttributesWrapper::MakeImageAttributesTemplate( v8::Isolate* isolate ) -{ - v8::EscapableHandleScope handleScope( isolate ); - - v8::Local objTemplate = v8::ObjectTemplate::New(); - - objTemplate->SetInternalFieldCount( BaseWrappedObject::FIELD_COUNT ); - - // add our function properties - ObjectTemplateHelper::InstallFunctions( isolate, objTemplate, ImageAttributeFunctionTable, ImageAttributeFunctionTableCount ); - - return handleScope.Escape( objTemplate ); -} - -void ImageAttributesWrapper::NewImageAttributes( const v8::FunctionCallbackInfo< v8::Value >& args) -{ - v8::Isolate* isolate = args.GetIsolate(); - v8::HandleScope handleScope( isolate); - - if(!args.IsConstructCall()) - { - DALI_SCRIPT_EXCEPTION(isolate, "ImageAttributes constructor called without 'new'"); - return; - } - - // attribs can be passed by value - Dali::ImageAttributes attribs = ImageAttributesApi::New( args ); - v8::Local localObject = WrapImageAttributes( isolate, attribs ); - args.GetReturnValue().Set( localObject ); -} - - -ImageAttributes& ImageAttributesWrapper::GetImageAttributes() -{ - return mImageAttributes; -} - - -} // namespace V8Plugin - -} // namespace Dali diff --git a/plugins/dali-script-v8/src/image/image-attributes-wrapper.h b/plugins/dali-script-v8/src/image/image-attributes-wrapper.h deleted file mode 100644 index 91511ea..0000000 --- a/plugins/dali-script-v8/src/image/image-attributes-wrapper.h +++ /dev/null @@ -1,85 +0,0 @@ -#ifndef __DALI_V8PLUGIN_IMAGE_ATTRIBUTES_WRAPPER_H__ -#define __DALI_V8PLUGIN_IMAGE_ATTRIBUTES_WRAPPER_H__ - -/* - * Copyright (c) 2015 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 -#include - -// INTERNAL INCLUDES -#include - -namespace Dali -{ - -namespace V8Plugin -{ - - -/** - * An Image Attributes wrapper. - * Provides access to ImageAttributes specific functionality and V8 memory handling. - */ -class ImageAttributesWrapper : public BaseWrappedObject -{ - -public: - - /** - * Constructor - */ - ImageAttributesWrapper( const ImageAttributes& imageAttributes, - GarbageCollectorInterface& gc ); - - /** - * Destructor - */ - virtual ~ImageAttributesWrapper(){}; - - /** - * Constructors - */ - static void NewImageAttributes( const v8::FunctionCallbackInfo< v8::Value >& args); - - /** - * Wraps an image attributes - */ - static v8::Handle WrapImageAttributes(v8::Isolate* isolate, const Dali::ImageAttributes& attributes); - - - // The ImageAttribute ObjectTemplate, we cache templates so we don't have - // keep generating them everytime we want to create an ImageAttribute - static v8::Persistent mImageAttributesTemplate; - - ImageAttributes& GetImageAttributes(); -private: - - // ImageAttributes - ImageAttributes mImageAttributes; - - static v8::Handle MakeImageAttributesTemplate( v8::Isolate* isolate ); - static v8::Local GetImageAttributesTemplate( v8::Isolate* isolate ); - -}; - -} // namespace V8Plugin - -} // namespace Dali - -#endif // header diff --git a/plugins/dali-script-v8/src/image/resource-image-api.cpp b/plugins/dali-script-v8/src/image/resource-image-api.cpp index fe4ff2a..8e7df33 100644 --- a/plugins/dali-script-v8/src/image/resource-image-api.cpp +++ b/plugins/dali-script-v8/src/image/resource-image-api.cpp @@ -18,12 +18,12 @@ // CLASS HEADER #include "resource-image-api.h" +// EXTERNAL INCLUDES +#include + // INTERNAL INCLUDES #include #include -#include -#include - namespace Dali { @@ -51,7 +51,6 @@ ResourceImage ResourceImageApi::GetResourceImage( v8::Isolate* isolate, const v8 * @for ResourceImage * @param {Object} options * @param {String} options.url The URL of the image file to use. - * @param {Object} [option.imageAttributes] image attributes object * @param {Integer} [options.loadPolicy] The LoadPolicy to apply when loading the image resource. * @param {Integer} [options.releasePolicy] optionally release memory when image is not visible on screen. * @return {Object} Image @@ -62,10 +61,12 @@ Image ResourceImageApi::New( const v8::FunctionCallbackInfo< v8::Value >& args ) v8::HandleScope handleScope( isolate ); std::string url; + ImageDimensions dimensions; + FittingMode::Type fittingMode = FittingMode::DEFAULT; + SamplingMode::Type samplingMode = SamplingMode::DEFAULT; + bool orientationCorrection = true; ResourceImage::LoadPolicy loadPolicy( ResourceImage::IMMEDIATE ); Image::ReleasePolicy releasePolicy( Image::NEVER); - ImageAttributes imageAttributes; - bool useImageAttributes = false; v8::Local options( args[0] ); @@ -88,13 +89,37 @@ Image ResourceImageApi::New( const v8::FunctionCallbackInfo< v8::Value >& args ) return Image(); } - v8::Local imageAttribsValue= optionsObject->Get( v8::String::NewFromUtf8( isolate, "imageAttributes" ) ); - if( imageAttribsValue->IsObject() ) + v8::Local widthValue = optionsObject->Get( v8::String::NewFromUtf8( isolate, "width" ) ); + if( widthValue->IsUint32() ) { - imageAttributes = ImageAttributesApi::GetImageAttributesFromObject( isolate, imageAttribsValue->ToObject() ); + const uint32_t width = widthValue->ToUint32()->Value(); + dimensions = ImageDimensions( width, dimensions.GetHeight() ); } + v8::Local heightValue = optionsObject->Get( v8::String::NewFromUtf8( isolate, "height" ) ); + if( heightValue->IsUint32() ) + { + const uint32_t height = heightValue->ToUint32()->Value(); + dimensions = ImageDimensions( dimensions.GetWidth(), height ); + } + v8::Local fittingModeValue = optionsObject->Get( v8::String::NewFromUtf8( isolate, "fittingMode" ) ); + if( fittingModeValue->IsUint32() ) + { + fittingMode = static_cast( fittingModeValue->ToUint32()->Value() ); + } + + v8::Local samplingModeValue = optionsObject->Get( v8::String::NewFromUtf8( isolate, "samplingMode" ) ); + if( samplingModeValue->IsUint32() ) + { + samplingMode = static_cast( samplingModeValue->ToUint32()->Value() ); + } + + v8::Local orientationCorrectionValue = optionsObject->Get( v8::String::NewFromUtf8( isolate, "orientationCorrection" ) ); + if( orientationCorrectionValue->IsBoolean() ) + { + orientationCorrection = orientationCorrectionValue->ToBoolean()->Value(); + } v8::Local releasePolicyValue = optionsObject->Get( v8::String::NewFromUtf8( isolate, "releasePolicy" ) ); if( releasePolicyValue->IsUint32() ) @@ -108,14 +133,7 @@ Image ResourceImageApi::New( const v8::FunctionCallbackInfo< v8::Value >& args ) loadPolicy = static_cast< ResourceImage::LoadPolicy >( loadPolicyValue->ToUint32()->Value()); } - if( useImageAttributes ) - { - return ResourceImage::New( url, imageAttributes, loadPolicy, releasePolicy); - } - else - { - return ResourceImage::New( url, loadPolicy, releasePolicy); - } + return ResourceImage::New( url, loadPolicy, releasePolicy, dimensions, fittingMode, samplingMode, orientationCorrection ); } /** @@ -176,7 +194,6 @@ void ResourceImageApi::GetUrl( const v8::FunctionCallbackInfo< v8::Value >& args /** * Reload the image - * The set ImageAttributes are used when requesting the image again. * @note if Image is offstage and OnDemand policy is set, reload request is ignored. * @method reload * @for ResourceImage @@ -190,28 +207,6 @@ void ResourceImageApi::Reload( const v8::FunctionCallbackInfo< v8::Value >& args image.Reload(); } - -/** - * Return attributes for the image - * Only to be used after the image has finished loading. - * (Ticket's LoadingSucceeded callback was called) - * The returned value will reflect the true image dimensions once the asynchronous loading has finished. - * - * @method getAttributes - * @for ResourceImage - * @return {Object} ImageAttributes - */ -void ResourceImageApi::GetAttributes( const v8::FunctionCallbackInfo< v8::Value >& args ) -{ - v8::Isolate* isolate = args.GetIsolate(); - v8::HandleScope handleScope( isolate ); - - ResourceImage image = GetResourceImage( isolate, args ); - - v8::Local localObject = ImageAttributesWrapper::WrapImageAttributes(isolate, image.GetAttributes()); - - args.GetReturnValue().Set( localObject ); -} } // namespace V8Plugin } // namespace Dali diff --git a/plugins/dali-script-v8/src/image/resource-image-api.h b/plugins/dali-script-v8/src/image/resource-image-api.h index 46d7d13..a9af141 100644 --- a/plugins/dali-script-v8/src/image/resource-image-api.h +++ b/plugins/dali-script-v8/src/image/resource-image-api.h @@ -49,7 +49,6 @@ namespace ResourceImageApi void GetLoadingState( const v8::FunctionCallbackInfo< v8::Value >& args ); void GetUrl( const v8::FunctionCallbackInfo< v8::Value >& args ); void Reload( const v8::FunctionCallbackInfo< v8::Value >& args ); - void GetAttributes( const v8::FunctionCallbackInfo< v8::Value >& args ); }; // namespace ResourceImageApi -- 2.7.4