Add features to download images over http protocol.
[platform/core/uifw/dali-adaptor.git] / platform-abstractions / slp / resource-loader / resource-thread-image.h
index e1a509b..9b5079b 100644 (file)
@@ -1,21 +1,22 @@
 #ifndef __DALI_SLP_PLATFORM_RESOURCE_THREAD_IMAGE_H__
 #define __DALI_SLP_PLATFORM_RESOURCE_THREAD_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.
+ *
+ */
 
 #include <dali/integration-api/resource-cache.h>
 #include <dali/integration-api/resource-types.h>
 namespace Dali
 {
 
-namespace Integration
-{
-namespace Log
-{
-class Filter;
-}
-}
-
 namespace SlpPlatform
 {
 
@@ -42,34 +35,13 @@ public:
    * Constructor
    * @param[in] resourceLoader A reference to the ResourceLoader
    */
-  ResourceThreadImage(ResourceLoader& resourceLoader);
+  ResourceThreadImage(ResourceLoader& resourceLoader, bool forRemoteImage);
 
   /**
    * Destructor
    */
   virtual ~ResourceThreadImage();
 
-  /**
-   * @copydoc ResourceLoader::LoadResourceSynchronously()
-   * Note, this is not threaded, but is called synchronously.
-   */
-  Integration::ResourcePointer LoadResourceSynchronously( const Integration::ResourceType& resourceType, const std::string& resourcePath );
-
-  /**
-   * @copydoc ResourceLoader::GetClosestImageSize()
-   * Note, this is not threaded, but is called synchronously.
-   */
-  void GetClosestImageSize( const std::string& filename,
-                            const ImageAttributes& attributes,
-                            Vector2 &closestSize );
-
-  /**
-   * @copydoc ResourceLoader::GetClosestImageSize()
-   * Note, this is not threaded, but is called synchronously.
-   */
-  void GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
-                            const ImageAttributes& attributes,
-                            Vector2 &closestSize );
 
 private:
   /**
@@ -78,6 +50,11 @@ private:
   virtual void Load(const Integration::ResourceRequest& request);
 
   /**
+   * @copydoc ResourceThreadBase::Download
+   */
+  virtual void Download(const Integration::ResourceRequest& request);
+
+  /**
    * @copydoc ResourceThreadBase::Decode
    */
   virtual void Decode(const Integration::ResourceRequest& request);
@@ -88,27 +65,26 @@ private:
   virtual void Save(const Integration::ResourceRequest& request);
 
   /**
-   * Convert the file stream into in-memory image pixel data and metadata.
-   * @param[in] resourceType The type of resource to convert.
-   * @param[in] path The path to the resource.
-   * @param[in] fp File Pointer. Closed on exit.
-   * @param[out] ptr Pointer to write image data to
-   * @return true on success, false on failure
+   * Download a requested image into a memory buffer.
+   * @param[in] request  The requested resource/file url and attributes
+   * @param[out] dataBuffer  A memory buffer object to be written with downloaded image data.
+   * @param[out] dataSize  The size of the memory buffer.
    */
-  bool ConvertStreamToBitmap( const Integration::ResourceType& resourceType,
-                              std::string path,
-                              FILE * const fp,
-                              Integration::ImageDataPtr& ptr );
+  bool DownloadRemoteImageIntoMemory(const Integration::ResourceRequest& request, Dali::Vector<uint8_t>& dataBuffer, size_t& dataSize);
+
   /**
-   * @brief Common code after a load or decode.
-   *
-   * @param[in] request   The request being attempted.
-   * @param[in] result    Whether the conversion succeeded.
-   * @param[in] imageData The pointer to receive the created image object.
-   * @param[in] msg       Warning message to show on failure.
+   * Load a requested image from a local file.
+   * @param[in] request  The requested resource/file url and attributes
    */
-  void HandleConversionResult( const Integration::ResourceRequest& request, bool result, Integration::ImageDataPtr imageData, const char * const msg );
+  void LoadImageFromLocalFile(const Integration::ResourceRequest& request);
 
+  /**
+   * Decode a requested image from a memory buffer.
+   * @param[in] blobBytes  A pointer to the memory buffer containig the requested image data.
+   * @param[in] blobSize  The size of the memory buffer containing the requested image data.
+   * @param[in] request  The requested resource/file url and attributes
+   */
+  void DecodeImageFromMemory(void* blobBytes, size_t blobSize, const Integration::ResourceRequest& request);
 }; // class ResourceThreadImage
 
 } // namespace SlpPlatform