1 #ifndef __DALI_INTERNAL_IMAGE_FACTORY_CACHE_H__
2 #define __DALI_INTERNAL_IMAGE_FACTORY_CACHE_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/common/dali-common.h>
23 #include <dali/internal/event/resources/resource-client.h>
24 #include <dali/internal/common/image-attributes.h>
35 namespace ImageFactoryCache
39 * Request contains information about requests made when loading image resources.
44 * @brief Unique ID for image resource requests.
46 * Images are loaded from a string locator (typically a file path) using a set
47 * of ImageAttributes. Each unique pair of string and attributes is mapped to a
48 * unique RequestId value. This ensures multiple Image objects loading the same
49 * image file with the same attributes only generate one resource request and
50 * Core only issues one IO operation to Adaptor to do the load.
52 * @sa Dali::Integration::ResourceId
54 typedef unsigned int RequestId;
56 typedef std::multimap<size_t, RequestId> RequestPathHashMap;
57 typedef std::pair<size_t, RequestId> RequestPathHashPair;
58 typedef std::map<RequestId, Request*> RequestIdMap;
59 typedef std::pair<RequestId, Request*> RequestIdPair;
61 typedef IntrusivePtr<Request> RequestPtr;
64 * The RequestLifetimeObserver observes the lifetime of image requests.
66 class RequestLifetimeObserver
71 * Called when an image request is discarded.
72 * This occurs during the ImageFactoryCache::Request destructor.
73 * @param[in] request The discarded request.
75 virtual void RequestDiscarded( const Request& request ) = 0;
79 * Request is a reference counted object to control the lifetime of elements in ImageFactory's cache.
80 * When no more Image objects reference a request, it gets removed from ImageFactory cache.
82 struct Request : public RefObject
86 * These requests are stored in ImageFactory's cache.
87 * @param [in] observer The object which observes request lifetime.
88 * @param [in] reqId A unique ID for this request.
89 * @param [ib] resId A unique ticket ID.
90 * @param [in] path Url of request.
91 * @param [in] attr Requested ImageAttributes.
93 Request( RequestLifetimeObserver& observer, RequestId reqId, ResourceId resId, const std::string& path, const ImageAttributes *attr );
95 ResourceId resourceId; ///< The Ticket ID. This can be used to acquire details of the loaded resource from ResourceClient.
96 const std::string url; ///< Path to the image resource
97 ImageAttributes* attributes; ///< ImageAttributes that were used
101 * Retrieve the unique ID of this request.
102 * @return The unique ID for this request.
104 RequestId GetId() const;
107 * Called when the RequestLifetimeObserver is being destroyed.
108 * This method should only be called during destruction of the Dali core.
110 void StopLifetimeObservation();
116 Request(); ///< not defined
117 Request(const Request& rhs); ///< not defined
118 Request& operator=(const Request& rhs); ///< not defined
121 RequestId mId; ///< Request id assigned by ImageFactory
122 RequestLifetimeObserver* mLifetimeObserver; ///< reference to the lifetime-observer; not owned
125 typedef std::pair<RequestPathHashMap::iterator, RequestPathHashMap::iterator> RequestPathHashRange;
127 } // namespace ImageFactoryCache
129 } // namespace Internal
133 #endif // __DALI_INTERNAL_IMAGE_FACTORY_CACHE_H__