#ifndef __DALI_INTERNAL_IMAGE_H__
#define __DALI_INTERNAL_IMAGE_H__
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.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://floralicense.org/license/
-//
-// 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.
-//
+/*
+ * Copyright (c) 2014 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 <string>
// INTERNAL INCLUDES
#include <dali/public-api/images/image.h>
-#include <dali/public-api/images/native-image.h>
#include <dali/public-api/object/base-object.h>
-#include <dali/internal/render/gl-resources/texture.h>
-#include <dali/internal/event/images/image-factory-cache.h>
-#include <dali/internal/event/resources/image-ticket.h>
#include <dali/internal/event/resources/resource-client.h>
#include <dali/internal/event/resources/resource-ticket-observer.h>
namespace Dali
{
-class NativeImage;
-
namespace Internal
{
-typedef Dali::Image::LoadPolicy LoadPolicy;
-typedef Dali::Image::ReleasePolicy ReleasePolicy;
-
class Image;
class ImageFactory;
typedef IntrusivePtr<Image> ImagePtr;
-const LoadPolicy ImageLoadPolicyDefault = Dali::Image::Immediate;
-const ReleasePolicy ImageReleasePolicyDefault = Dali::Image::Never;
-
/**
* Image represents an image resource that can be added to actors etc.
* When the Image object is created, resource loading will be attempted.
*/
class Image : public BaseObject, public ResourceTicketObserver
{
-protected:
-
- /**
- * A reference counted object may only be deleted by calling Unreference()
- */
- virtual ~Image();
-
- /**
- * Constructor
- */
- Image(LoadPolicy loadPol=ImageLoadPolicyDefault, ReleasePolicy releasePol=ImageReleasePolicyDefault);
-
-public:
- /**
- * Creates a pointer to an uninitialized Image object.
- * @return a pointer to a newly created object.
- */
- static Image* New();
-
- /**
- * Creates object and loads image from filesystem
- * the maximum size of the image is limited by GL_MAX_TEXTURE_SIZE
- * @param [in] filename the path of the image on the filesystem
- * @param [in] attributes requested parameters for loading (size, cropping etc.)
- * if width or height is specified as 0, the natural size will be used.
- * @param [in] loadPol controls time of loading a resource from the filesystem (default: load when Image is created).
- * @param [in] releasePol optionally relase memory when image is not visible on screen (default: keep image data until Image object is alive).
- * @return a pointer to a newly created object.
- */
- static Image* New(const std::string& filename,
- const Dali::ImageAttributes& attributes=Dali::ImageAttributes::DEFAULT_ATTRIBUTES,
- LoadPolicy loadPol=ImageLoadPolicyDefault,
- ReleasePolicy releasePol=ImageReleasePolicyDefault);
-
-
-
public:
/**
- * Creates object with already loaded NativeImage
- * the maximum size of the image is limited by GL_MAX_TEXTURE_SIZE
- * @pre nativeImg should be initialised
- * @param [in] nativeImg already initialised NativeImage
- * @param [in] loadPol controls time of loading a resource from the filesystem (default: load when Image is created).
- * @param [in] releasePol optionally relase memory when image is not visible on screen (default: keep image data until Image object is alive).
- * @return a pointer to a newly created object.
- */
- static Image* New(NativeImage& nativeImg,
- LoadPolicy loadPol=ImageLoadPolicyDefault,
- ReleasePolicy releasePol=ImageReleasePolicyDefault);
-
- /**
- * @copydoc Dali::Image::GetLoadingState()
- */
- Dali::LoadingState GetLoadingState() const { return mTicket ? mTicket->GetLoadingState() : ResourceLoading; }
-
- /**
- * @copydoc Dali::Image::GetLoadPolicy()
- */
- LoadPolicy GetLoadPolicy () const { return mLoadPolicy; }
-
- /**
- * @copydoc Dali::Image::GetReleasePolicy()
- */
- ReleasePolicy GetReleasePolicy () const { return mReleasePolicy; }
-
- /**
- * @copydoc Dali::Image::LoadingFinishedSignal()
- */
- Dali::Image::ImageSignalV2& LoadingFinishedSignal() { return mLoadingFinishedV2; }
-
- /**
* @copydoc Dali::Image::UploadedSignal()
*/
- Dali::Image::ImageSignalV2& UploadedSignal() { return mUploadedV2; }
+ Dali::Image::ImageSignalType& UploadedSignal() { return mUploaded; }
/**
* Connects a callback function with the object's signals.
ResourceId GetResourceId() const;
/**
- * Get the attributes of the image.
- * Only to be used after the image has finished loading.
- * (Ticket's LoadingSucceeded callback was called)
- * Reflects the last cached values after a LoadComplete.
- * If requested width or height was 0, they are replaced by concrete dimensions.
- * @return a copy of the attributes
- */
- const Dali::ImageAttributes& GetAttributes() const;
-
- /**
* Get the width of 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.
- * Connect to SignalLoadingFinished or use GetLoadingState to make sure this value is actual.
* @pre image should be loaded
*/
- unsigned int GetWidth() const;
+ virtual unsigned int GetWidth() const;
/**
* Get the height of 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.
- * Connect to SignalLoadingFinished or use GetLoadingState to make sure this value is actual.
* @pre image should be loaded
*/
- unsigned int GetHeight() const;
+ virtual unsigned int GetHeight() const;
/**
- * @copydoc Dali::Image::GetFilename()
+ * Return the natural size of the image.
+ * This is the size that the loaded image will take
*/
- const std::string& GetFilename() const;
-
- /**
- * @copydoc Dali::Image::Reload()
- */
- void Reload();
+ virtual Vector2 GetNaturalSize() const;
public: // From ResourceTicketObserver
*/
virtual void ResourceUploaded(const ResourceTicket& ticket);
+public:
+
/**
- * @copydoc Dali::Internal::ResourceTicketObserver::ResourceSavingSucceeded()
+ * Indicates that the image is used.
*/
- virtual void ResourceSavingSucceeded( const ResourceTicket& ticket );
+ virtual void Connect() {}
/**
- * @copydoc Dali::Internal::ResourceTicketObserver::ResourceSavingFailed()
+ * Indicates that the image is not used anymore.
*/
- virtual void ResourceSavingFailed( const ResourceTicket& ticket );
+ virtual void Disconnect() {}
-public:
+protected:
/**
- * Indicates that the image is used.
+ * A reference counted object may only be deleted by calling Unreference()
*/
- virtual void Connect();
+ virtual ~Image();
/**
- * Indicates that the image is not used anymore.
+ * Constructor, with default parameters
*/
- virtual void Disconnect();
-
-private:
+ Image();
/**
- * Helper method to set new resource ticket. Stops observing current ticket if any, and starts observing
- * the new one or just resets the intrusive pointer.
- * @param[in] ticket pointer to new resource Ticket or NULL.
+ * Second stage initialization
*/
- void SetTicket( ResourceTicket* ticket );
+ void Initialize();
protected:
- unsigned int mWidth;
- unsigned int mHeight;
- ResourceTicketPtr mTicket;
- ImageFactoryCache::RequestPtr mRequest; ///< contains the initially requested attributes for image. Request is reissued when memory was released.
- LoadPolicy mLoadPolicy;
- ReleasePolicy mReleasePolicy;
+ ResourceTicketPtr mTicket; ///< smart pointer to the ticket object that gets completed when load finishes
+
+ mutable unsigned int mWidth; ///< natural width of the image, needs to be mutable for lazy resolving and as the API for GetWidth is const
+ mutable unsigned int mHeight; ///< natural height of the image, needs to be mutable for lazy resolving and as the API for GetHeight is const
- unsigned int mConnectionCount; ///< number of on-stage objects using this image
- ImageFactory& mImageFactory;
+ unsigned int mConnectionCount; ///< number of on-stage objects using this image
private:
- Dali::Image::ImageSignalV2 mLoadingFinishedV2;
- Dali::Image::ImageSignalV2 mUploadedV2;
- // Changes scope, should be at end of class
- DALI_LOG_OBJECT_STRING_DECLARATION;
+ Dali::Image::ImageSignalType mUploaded;
};
} // namespace Internal