1*c45d927aSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*c45d927aSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*c45d927aSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*c45d927aSAndrew Rist * distributed with this work for additional information 6*c45d927aSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*c45d927aSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*c45d927aSAndrew Rist * "License"); you may not use this file except in compliance 9*c45d927aSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*c45d927aSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*c45d927aSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*c45d927aSAndrew Rist * software distributed under the License is distributed on an 15*c45d927aSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*c45d927aSAndrew Rist * KIND, either express or implied. See the License for the 17*c45d927aSAndrew Rist * specific language governing permissions and limitations 18*c45d927aSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*c45d927aSAndrew Rist *************************************************************/ 21*c45d927aSAndrew Rist 22*c45d927aSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef SD_SLIDESORTER_GENERIC_PAGE_CACHE_HXX 25cdf0e10cSrcweir #define SD_SLIDESORTER_GENERIC_PAGE_CACHE_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "SlideSorter.hxx" 28cdf0e10cSrcweir #include "SlsRequestQueue.hxx" 29cdf0e10cSrcweir #include <boost/scoped_ptr.hpp> 30cdf0e10cSrcweir 31cdf0e10cSrcweir namespace sd { namespace slidesorter { namespace cache { 32cdf0e10cSrcweir 33cdf0e10cSrcweir class BitmapCache; 34cdf0e10cSrcweir class QueueProcessor; 35cdf0e10cSrcweir 36cdf0e10cSrcweir /** This basically is the implementation class for the PageCache class. 37cdf0e10cSrcweir */ 38cdf0e10cSrcweir class GenericPageCache 39cdf0e10cSrcweir { 40cdf0e10cSrcweir public: 41cdf0e10cSrcweir /** The page chache is created with a reference to the SlideSorter and 42cdf0e10cSrcweir thus has access to both view and model. This allows the cache to 43cdf0e10cSrcweir fill itself with requests for all pages or just the visible ones. 44cdf0e10cSrcweir @param rPreviewSize 45cdf0e10cSrcweir The size of the previews is expected in pixel values. 46cdf0e10cSrcweir @param bDoSuperSampling 47cdf0e10cSrcweir When <TRUE/> the previews are rendered larger and then scaled 48cdf0e10cSrcweir down to the requested size to improve image quality. 49cdf0e10cSrcweir */ 50cdf0e10cSrcweir GenericPageCache ( 51cdf0e10cSrcweir const Size& rPreviewSize, 52cdf0e10cSrcweir const bool bDoSuperSampling, 53cdf0e10cSrcweir const SharedCacheContext& rpCacheContext); 54cdf0e10cSrcweir 55cdf0e10cSrcweir ~GenericPageCache (void); 56cdf0e10cSrcweir 57cdf0e10cSrcweir /** Change the size of the preview bitmaps. This may be caused by a 58cdf0e10cSrcweir resize of the slide sorter window or a change of the number of 59cdf0e10cSrcweir columns. 60cdf0e10cSrcweir */ 61cdf0e10cSrcweir void ChangePreviewSize ( 62cdf0e10cSrcweir const Size& rPreviewSize, 63cdf0e10cSrcweir const bool bDoSuperSampling); 64cdf0e10cSrcweir 65cdf0e10cSrcweir /** Request a preview bitmap for the specified page object in the 66cdf0e10cSrcweir specified size. The returned bitmap may be a preview of the preview, 67cdf0e10cSrcweir i.e. either a scaled (up or down) version of a previous preview (of 68cdf0e10cSrcweir the wrong size) or an empty bitmap. In this case a request for the 69cdf0e10cSrcweir generation of a new preview is created and inserted into the request 70cdf0e10cSrcweir queue. When the preview is available the page shape will be told to 71cdf0e10cSrcweir paint itself again. When it then calls this method again if 72cdf0e10cSrcweir receives the correctly sized preview bitmap. 73cdf0e10cSrcweir @param rRequestData 74cdf0e10cSrcweir This data is used to determine the preview. 75cdf0e10cSrcweir @param bResize 76cdf0e10cSrcweir When <TRUE/> then when the available bitmap has not the 77cdf0e10cSrcweir requested size, it is scaled before it is returned. When 78cdf0e10cSrcweir <FALSE/> then the bitmap is returned in the wrong size and it is 79cdf0e10cSrcweir the task of the caller to scale it. 80cdf0e10cSrcweir @return 81cdf0e10cSrcweir Returns a bitmap that is either empty, contains a scaled (up or 82cdf0e10cSrcweir down) version or is the requested bitmap. 83cdf0e10cSrcweir */ 84cdf0e10cSrcweir Bitmap GetPreviewBitmap ( 85cdf0e10cSrcweir const CacheKey aKey, 86cdf0e10cSrcweir const bool bResize); 87cdf0e10cSrcweir Bitmap GetMarkedPreviewBitmap ( 88cdf0e10cSrcweir const CacheKey aKey, 89cdf0e10cSrcweir const bool bResize); 90cdf0e10cSrcweir void SetMarkedPreviewBitmap ( 91cdf0e10cSrcweir const CacheKey aKey, 92cdf0e10cSrcweir const Bitmap& rMarkedBitmap); 93cdf0e10cSrcweir 94cdf0e10cSrcweir /** When the requested preview bitmap does not yet exist or is not 95cdf0e10cSrcweir up-to-date then the rendering of one is scheduled. Otherwise this 96cdf0e10cSrcweir method does nothing. 97cdf0e10cSrcweir @param rRequestData 98cdf0e10cSrcweir This data is used to determine the preview. 99cdf0e10cSrcweir @param bMayBeUpToDate 100cdf0e10cSrcweir This flag helps the method to determine whether an existing 101cdf0e10cSrcweir preview that matches the request is up to date. If the caller 102cdf0e10cSrcweir knows that it is not then by passing <FALSE/> he tells us that we 103cdf0e10cSrcweir do not have to check the up-to-date flag a second time. If 104cdf0e10cSrcweir unsure use <TRUE/>. 105cdf0e10cSrcweir */ 106cdf0e10cSrcweir void RequestPreviewBitmap ( 107cdf0e10cSrcweir const CacheKey aKey, 108cdf0e10cSrcweir const bool bMayBeUpToDate = true); 109cdf0e10cSrcweir 110cdf0e10cSrcweir /** Tell the cache to replace the bitmap associated with the given 111cdf0e10cSrcweir request data with a new one that reflects recent changes in the 112cdf0e10cSrcweir content of the page object. 113cdf0e10cSrcweir @return 114cdf0e10cSrcweir When the key is kown then return <TRUE/>. 115cdf0e10cSrcweir */ 116cdf0e10cSrcweir bool InvalidatePreviewBitmap (const CacheKey aKey); 117cdf0e10cSrcweir 118cdf0e10cSrcweir /** Call this method when a view-object-contact object is being deleted 119cdf0e10cSrcweir and does not need (a) its current bitmap in the cache and (b) a 120cdf0e10cSrcweir requested a new bitmap. 121cdf0e10cSrcweir */ 122cdf0e10cSrcweir void ReleasePreviewBitmap (const CacheKey aKey); 123cdf0e10cSrcweir 124cdf0e10cSrcweir /** Call this method when all preview bitmaps have to be generated anew. 125cdf0e10cSrcweir This is the case when the size of the page objects on the screen has 126cdf0e10cSrcweir changed or when the model has changed. 127cdf0e10cSrcweir */ 128cdf0e10cSrcweir void InvalidateCache (const bool bUpdateCache); 129cdf0e10cSrcweir 130cdf0e10cSrcweir /** With the precious flag you can control whether a bitmap can be 131cdf0e10cSrcweir removed from the cache or reduced in size to make room for other 132cdf0e10cSrcweir bitmaps or is so precious that it will not be touched. A typical 133cdf0e10cSrcweir use is to set the precious flag for the visible pages. 134cdf0e10cSrcweir */ 135cdf0e10cSrcweir void SetPreciousFlag (const CacheKey aKey, const bool bIsPrecious); 136cdf0e10cSrcweir 137cdf0e10cSrcweir void Pause (void); 138cdf0e10cSrcweir void Resume (void); 139cdf0e10cSrcweir 140cdf0e10cSrcweir private: 141cdf0e10cSrcweir ::boost::shared_ptr<BitmapCache> mpBitmapCache; 142cdf0e10cSrcweir 143cdf0e10cSrcweir RequestQueue maRequestQueue; 144cdf0e10cSrcweir 145cdf0e10cSrcweir ::boost::scoped_ptr<QueueProcessor> mpQueueProcessor; 146cdf0e10cSrcweir 147cdf0e10cSrcweir SharedCacheContext mpCacheContext; 148cdf0e10cSrcweir 149cdf0e10cSrcweir /** The current size of preview bitmaps. 150cdf0e10cSrcweir */ 151cdf0e10cSrcweir Size maPreviewSize; 152cdf0e10cSrcweir 153cdf0e10cSrcweir bool mbDoSuperSampling; 154cdf0e10cSrcweir 155cdf0e10cSrcweir /** Both bitmap cache and queue processor are created on demand by this 156cdf0e10cSrcweir method. 157cdf0e10cSrcweir */ 158cdf0e10cSrcweir void ProvideCacheAndProcessor (void); 159cdf0e10cSrcweir }; 160cdf0e10cSrcweir 161cdf0e10cSrcweir 162cdf0e10cSrcweir } } } // end of namespace ::sd::slidesorter::cache 163cdf0e10cSrcweir 164cdf0e10cSrcweir #endif 165