X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Fintegration-api%2Fplatform-abstraction.h;h=b9187c8b9ff4e96922eb6bfcda89da988d8bc158;hb=07c2516c65ef56c71df4c9c3a7461781b06cb91b;hp=5f7601efd2d8c771e7edd18158f325e1f8706c38;hpb=63f98c6a1839a4cebdffc66a7462048f9fb0267f;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/integration-api/platform-abstraction.h b/dali/integration-api/platform-abstraction.h index 5f7601e..b9187c8 100644 --- a/dali/integration-api/platform-abstraction.h +++ b/dali/integration-api/platform-abstraction.h @@ -1,8 +1,8 @@ -#ifndef __DALI_INTEGRATION_PLATFORM_ABSTRACTION_H__ -#define __DALI_INTEGRATION_PLATFORM_ABSTRACTION_H__ +#ifndef DALI_INTEGRATION_PLATFORM_ABSTRACTION_H +#define DALI_INTEGRATION_PLATFORM_ABSTRACTION_H /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2019 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,18 +19,20 @@ */ // INTERNAL INCLUDES + #include -#include +#include +#include +#include +#include namespace Dali { namespace Integration { - -class Bitmap; -class DynamicsFactory; - +typedef uint32_t ResourceId; +typedef IntrusivePtr ResourcePointer; /** * PlatformAbstraction is an abstract interface, used by Dali to access platform specific services. @@ -41,80 +43,55 @@ class PlatformAbstraction { public: - virtual ~PlatformAbstraction() {} - - // Dali Lifecycle - - /** - * Get the monotonic time since an unspecified reference point. - * This is used by Dali to calculate time intervals during animations; the interval is - * recalculated when Dali is resumed with Dali::Integration::Core::Resume(). - * Multi-threading note: this method may be called from either the main or rendering thread. - * @param[out] seconds The time in seconds since the reference point. - * @param[out] microSeconds The remainder in microseconds. - */ - virtual void GetTimeMicroseconds(unsigned int& seconds, unsigned int& microSeconds) = 0; - - /** - * Tell the platform abstraction that Dali is ready to pause, such as when the - * application enters a background state. - * Allows background threads to pause their work until Resume() is called. - * This is a good time to release recreatable data such as memory caches - * to cooperate with other apps and reduce the chance of this one being - * force-killed in a low memory situation. - */ - virtual void Suspend() {} ///!ToDo: Make pure virtual once dali-adaptor patch is in place = 0; - - /** - * Tell the platform abstraction that Dali is resuming from a pause, such as - * when it has transitioned from a background state to a foreground one. - * It is time to wake up sleeping background threads and recreate memory - * caches and other temporary data. - */ - virtual void Resume() {} ///!ToDo: Make pure virtual once dali-adaptor patch is in place = 0; - // Resource Loading /** - * Determine the size of an image the resource loaders will provide when given the same - * image attributes. + * @brief Determine the size of an image the resource loaders will provide when + * given the same image loading parameters. + * * This is a synchronous request. * This function is used to determine the size of an image before it has loaded. * @param[in] filename name of the image. - * @param[in] attributes The attributes used to load the image - * @param[out] closestSize Size of the image that will be loaded. - */ - virtual void GetClosestImageSize( const std::string& filename, - const ImageAttributes& attributes, - Vector2& closestSize ) = 0; - - /** - * Determine the size of an image the resource loaders will provide when given the same - * image attributes. + * @param[in] size The requested size for the image. + * @param[in] fittingMode The method to use to map the source image to the desired + * dimensions. + * @param[in] samplingMode The image filter to use if the image needs to be + * downsampled to the requested size. + * @param[in] orientationCorrection Whether to use image metadata to rotate or + * flip the image, e.g., from portrait to landscape. + * @return dimensions that image will have if it is loaded with given parameters. + */ + virtual ImageDimensions GetClosestImageSize( const std::string& filename, + ImageDimensions size = ImageDimensions( 0, 0 ), + FittingMode::Type fittingMode = FittingMode::SHRINK_TO_FIT, + SamplingMode::Type samplingMode = SamplingMode::BOX, + bool orientationCorrection = true) = 0; + + /** + * @brief Determine the size of an image the resource loaders will provide when + * given the same image loading parameters. + * * This is a synchronous request. * This function is used to determine the size of an image before it has loaded. - * @param[in] resourceBuffer A pointer to an encoded image buffer - * @param[in] attributes The attributes used to load the image - * @param[out] closestSize Size of the image that will be loaded. - */ - virtual void GetClosestImageSize( ResourcePointer resourceBuffer, - const ImageAttributes& attributes, - Vector2& closestSize ) = 0; - - /** - * Request a resource from the native filesystem. This is an asynchronous request. - * After this method returns, FillResourceCache() will be called to retrieve the result(s) of the - * resource loading operation. Loading resources in separate worker thread is recommended. - * Multi-threading note: this method will be called from the main thread only i.e. not - * from within the Core::Render() method. - * @param[in] request A unique resource request. This is not guaranteed to survive after LoadResource - * returns; the loading process should take a copy. - */ - virtual void LoadResource(const ResourceRequest& request) = 0; - - /** - * Request a resource from the native filesystem. This is a synchronous request, i.e. - * it will block the main loop whilst executing. It should therefore be used sparingly. + * @param[in] filename name of the image. + * @param[in] size The requested size for the image. + * @param[in] fittingMode The method to use to map the source image to the desired + * dimensions. + * @param[in] samplingMode The image filter to use if the image needs to be + * downsampled to the requested size. + * @param[in] orientationCorrection Whether to use image metadata to rotate or + * flip the image, e.g., from portrait to landscape. + * @return dimensions that image will have if it is loaded with given parameters. + */ + virtual ImageDimensions GetClosestImageSize( ResourcePointer resourceBuffer, + ImageDimensions size = ImageDimensions( 0, 0 ), + FittingMode::Type fittingMode = FittingMode::SHRINK_TO_FIT, + SamplingMode::Type samplingMode = SamplingMode::BOX, + bool orientationCorrection = true) = 0; + + /** + * Request an image from the native filesystem. This is a synchronous request, i.e. + * it will block the main loop whilst executing. * * Multi-threading note: this method will be called from the main thread only i.e. not * from within the Core::Render() method. @@ -122,73 +99,55 @@ public: * @param[in] resourcePath The path to the resource * @return A pointer to a ref-counted resource */ - virtual ResourcePointer LoadResourceSynchronously( const ResourceType& resourceType, const std::string& resourcePath ) = 0; - - /** - * Request that a resource be saved to the native filesystem. - * This is an asynchronous request. - */ - virtual void SaveResource(const ResourceRequest& request) = 0; - /** - * Cancel an ongoing LoadResource() request. - * Multi-threading note: this method will be called from the main thread only i.e. not - * from within the Core::Render() method. - * @param[in] id The ID of the resource to cancel. - * @param[in] typeId The ID type of the resource to cancel. - */ - virtual void CancelLoad(ResourceId id, ResourceTypeId typeId) = 0; + virtual ResourcePointer LoadImageSynchronously( const BitmapResourceType& resourceType, const std::string& resourcePath ) = 0; /** - * Query whether any asynchronous LoadResource() requests are ongoing. - * Multi-threading note: this method may be called from either the main or rendering thread. - * @return True if resources are being loaded. + * Decode a buffer of data synchronously. + * @param[in] resourceType The type of resource to load + * @param[in] buffer The decoded data + * @param[in] bufferSize The size of the buffer used by the decoded data. + * + * @return A pointer to the decoded buffer. */ - virtual bool IsLoading() = 0; + virtual BitmapPtr DecodeBuffer( const BitmapResourceType& resourceType, uint8_t * buffer, size_t bufferSize ) = 0; /** - * Retrieve newly loaded resources. - * If no resources have finished loading, then this method returns immediately. - * Multi-threading note: this method will be called from the update thread, from within - * the UpdateManager::Update() method. - * @param[in] cache The resource cache to fill. + * Load a shader binary file into a buffer + * @param[in] filename The shader binary filename to load + * @param[out] buffer A buffer to receive the file. + * @result true if the file is loaded. */ - virtual void GetResources(ResourceCache& cache) = 0; + virtual bool LoadShaderBinaryFile( const std::string& filename, Dali::Vector< uint8_t >& buffer ) const = 0; /** - * Waits for the asynchronous loader threads (if any) to finish. - * This will be only be called before Core destruction; no resource loading requests will be - * made following this method. + * Save a shader binary file to the resource file system. + * @param[in] filename The shader binary filename to save to. + * @param[in] buffer A buffer to write the file from. + * @param[in] numbytes Size of the buffer. + * @result true if the file is saved, else false. */ - virtual void JoinLoaderThreads() = 0; + virtual bool SaveShaderBinaryFile( const std::string& filename, const uint8_t * buffer, uint32_t numBytes ) const = 0; /** - * Sets horizontal and vertical pixels per inch value that is used by the display - * @param[in] dpiHorizontal horizontal dpi value - * @param[in] dpiVertical vertical dpi value + * Sets a callback to occur in the future + * @param[in] milliseconds number of milliseconds to wait until executing the callback + * @param[in] callback function to call when the timer expires + * @result a timer reference ID, to be used for cancelling the timer */ - virtual void SetDpi (unsigned int dpiHorizontal, unsigned int dpiVertical) = 0; + virtual uint32_t StartTimer( uint32_t milliseconds, CallbackBase* callback ) = 0; /** - * Load a file into a buffer - * @param[in] filename The filename to load - * @param[out] buffer A buffer to receive the file. - * @result true if the file is loaded. + * Cancels a running timer + * @param[in] timerId the ID reference returned when the timer was started */ - virtual bool LoadFile( const std::string& filename, std::vector< unsigned char >& buffer ) const = 0; + virtual void CancelTimer ( uint32_t timerId ) = 0; - /** - * Load a file into a buffer - * @param[in] filename The filename to save - * @param[out] buffer A buffer containing some data - * The buffer is implemeneted with a std::vector. The size() member specifies the buffer length. - * @result true if the file is saved. - */ - virtual bool SaveFile(const std::string& filename, std::vector< unsigned char >& buffer) const = 0; +protected: /** - * Get a pointer to the DynamicsFactory. + * Virtual destructor. */ - virtual DynamicsFactory* GetDynamicsFactory() = 0; + virtual ~PlatformAbstraction() {} }; // class PlatformAbstraction @@ -196,4 +155,4 @@ public: } // namespace Dali -#endif // __DALI_INTEGRATION_PLATFORM_ABSTRACTION_H__ +#endif // DALI_INTEGRATION_PLATFORM_ABSTRACTION_H