|
1 /* |
|
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Skinnable image |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <alf/alfconstants.h> |
|
21 #include "alfskinnableimage.h" |
|
22 #include "alf/alfimageloaderutil.h" |
|
23 #include "alf/alftexturemanager.h" |
|
24 #include "alf/alftexture.h" |
|
25 #include "alf/alfenv.h" |
|
26 #include "alfclient.h" |
|
27 |
|
28 #include <uiacceltk/HuiUtil.h> |
|
29 |
|
30 // --------------------------------------------------------------------------- |
|
31 // Constructor |
|
32 // --------------------------------------------------------------------------- |
|
33 // |
|
34 CAlfSkinnableImage::CAlfSkinnableImage(CAlfEnv* aEnv) |
|
35 { |
|
36 iEnv = aEnv; |
|
37 } |
|
38 |
|
39 // --------------------------------------------------------------------------- |
|
40 // Destructor |
|
41 // --------------------------------------------------------------------------- |
|
42 // |
|
43 CAlfSkinnableImage::~CAlfSkinnableImage() |
|
44 { |
|
45 if (Image().HasTexture()) |
|
46 { |
|
47 CAlfTextureManager& oldManager = ImageTextureManager(Image()); |
|
48 oldManager.DecRefcount(iId); |
|
49 } |
|
50 |
|
51 DeleteTexture(); |
|
52 |
|
53 // Remove size observer if needed |
|
54 if (iSkinnedImageUtil) |
|
55 { |
|
56 CAlfTextureManager& manager = ImageTextureManager(iSkinnedImageTextureManagerId); |
|
57 manager.RemoveAutoSizeObserver(iSkinnedImageUtil); |
|
58 } |
|
59 |
|
60 delete iSkinnedImageUtil; |
|
61 } |
|
62 |
|
63 // --------------------------------------------------------------------------- |
|
64 // |
|
65 // --------------------------------------------------------------------------- |
|
66 // |
|
67 |
|
68 void CAlfSkinnableImage::SetImage(const TAlfImage& aImage) |
|
69 { |
|
70 CAlfTextureManager& oldManager = ImageTextureManager(Image()); |
|
71 CAlfTextureManager& newManager = ImageTextureManager(aImage); |
|
72 |
|
73 if (Image().HasTexture()) |
|
74 { |
|
75 oldManager.DecRefcount(iId); |
|
76 } |
|
77 |
|
78 if ( iSkinnedImageUtil ) |
|
79 { |
|
80 oldManager.RemoveAutoSizeObserver(iSkinnedImageUtil); |
|
81 delete iSkinnedImageUtil; |
|
82 iSkinnedImageUtil = NULL; |
|
83 } |
|
84 |
|
85 iImage = aImage; |
|
86 TRAP_IGNORE(CreateTextureL()); // Creates texture from skin id if needed |
|
87 |
|
88 if (Image().HasTexture()) |
|
89 { |
|
90 CAlfTexture* texture = (CAlfTexture*)&Image().Texture(); |
|
91 iId = texture->Id(); |
|
92 newManager.IncRefcount(iId); |
|
93 |
|
94 // If texture does not have content and it has been released because of |
|
95 // ref counting try to restore content. |
|
96 if (!texture->HasContent()) |
|
97 { |
|
98 TInt releaseFlags = texture->ReleaseFlags(); |
|
99 if (releaseFlags & CAlfTexture::EReleaseFromRefCounting) |
|
100 { |
|
101 // Clear release flag |
|
102 releaseFlags &= ~CAlfTexture::EReleaseFromRefCounting; |
|
103 texture->SetReleaseFlags(releaseFlags); |
|
104 |
|
105 // If there are no more release flags, try to restore content. |
|
106 if (!releaseFlags) |
|
107 { |
|
108 if (texture->BitmapProvider()) |
|
109 { |
|
110 TRAP_IGNORE(newManager.UpdateTextureFromBitmapL(iId)) |
|
111 } |
|
112 else |
|
113 { |
|
114 TRAP_IGNORE(newManager.UpdateTextureFromFileL(iId)) |
|
115 } |
|
116 } |
|
117 } |
|
118 } |
|
119 } |
|
120 else |
|
121 { |
|
122 iId = 0; |
|
123 } |
|
124 } |
|
125 |
|
126 // --------------------------------------------------------------------------- |
|
127 // |
|
128 // --------------------------------------------------------------------------- |
|
129 // |
|
130 TAlfImage& CAlfSkinnableImage::Image() |
|
131 { |
|
132 return iImage; |
|
133 } |
|
134 |
|
135 // --------------------------------------------------------------------------- |
|
136 // |
|
137 // --------------------------------------------------------------------------- |
|
138 // |
|
139 void CAlfSkinnableImage::CreateTextureL() |
|
140 { |
|
141 if (iImage.SkinnableImage()) |
|
142 { |
|
143 // old iSkinnedImageUtil should be freed already |
|
144 __ASSERT_DEBUG( !iSkinnedImageUtil, USER_INVARIANT() ); |
|
145 iSkinnedImageUtil = new (ELeave) CAlfAutoSizeImageLoaderUtil; |
|
146 |
|
147 CAlfTextureManager& tm = ImageTextureManager(iImage); |
|
148 |
|
149 // Add size observer if needed |
|
150 if (iImage.TextureFlags() & EAlfTextureFlagAutoSize) |
|
151 { |
|
152 tm.AddAutoSizeObserverL(iSkinnedImageUtil); |
|
153 } |
|
154 |
|
155 CAlfTexture* texture = NULL; |
|
156 iSkinnedImageUtil->SetSize(iImage.PreferredSize(), iImage.PreferredScaleMode()); |
|
157 |
|
158 MAlfBitmapProvider* imageprovider = NULL; |
|
159 if (iImage.AppIconUid() != TUid::Uid(0)) |
|
160 { |
|
161 imageprovider = iSkinnedImageUtil->CreateImageLoaderL(iImage.AppIconUid(), |
|
162 iImage.AppIconType()); |
|
163 } |
|
164 else |
|
165 { |
|
166 imageprovider = iSkinnedImageUtil->CreateImageLoaderL(iImage.SkinID(), |
|
167 *iImage.FallbackFileName(), |
|
168 iImage.FallbackBitmapId(), |
|
169 iImage.FallbackMaskId()); |
|
170 } |
|
171 |
|
172 texture = &tm.CreateTextureL(iImage.PreferredTextureId(), imageprovider, iImage.TextureFlags()); |
|
173 iImage.SetTexture(*texture); |
|
174 |
|
175 // Delete old texture if we managed to create new one |
|
176 if (texture) |
|
177 { |
|
178 // Check that the new one is really a new one, not just reusing old id. |
|
179 if (texture->Id() != iSkinnedImageTextureId || tm.ManagerUid() != iSkinnedImageTextureManagerId) |
|
180 { |
|
181 DeleteTexture(); |
|
182 iSkinnedImageTextureId = texture->Id(); |
|
183 iSkinnedImageTextureManagerId = tm.ManagerUid(); |
|
184 } |
|
185 } |
|
186 } |
|
187 } |
|
188 |
|
189 // --------------------------------------------------------------------------- |
|
190 // This function deletes texture associated to image, but does not delete |
|
191 // the bitmapprovider (it is left to support release/restore). |
|
192 // --------------------------------------------------------------------------- |
|
193 // |
|
194 void CAlfSkinnableImage::DeleteTexture() |
|
195 { |
|
196 if (iSkinnedImageTextureId != 0) |
|
197 { |
|
198 CAlfTextureManager& manager = ImageTextureManager(iSkinnedImageTextureManagerId); |
|
199 const CAlfTexture* oldtexture = manager.Texture(iSkinnedImageTextureId); |
|
200 if (oldtexture && oldtexture->Id() == iSkinnedImageTextureId) |
|
201 { |
|
202 delete oldtexture; |
|
203 iSkinnedImageTextureId = 0; |
|
204 iSkinnedImageTextureManagerId = TUid::Uid(0); |
|
205 } |
|
206 } |
|
207 } |
|
208 |
|
209 // --------------------------------------------------------------------------- |
|
210 // Gets the texturemanager for the texture inside given image. Defaults |
|
211 // to default texture manager. |
|
212 // --------------------------------------------------------------------------- |
|
213 // |
|
214 CAlfTextureManager& CAlfSkinnableImage::ImageTextureManager(const TAlfImage& aImage) |
|
215 { |
|
216 CAlfTextureManager* tm = aImage.PreferredTextureManager(); |
|
217 if (!tm) |
|
218 { |
|
219 tm = &iEnv->TextureManager(); |
|
220 } |
|
221 return *tm; |
|
222 } |
|
223 |
|
224 // --------------------------------------------------------------------------- |
|
225 // Gets the texturemanager based on texturemanager uid. Defaults |
|
226 // to default texture manager. |
|
227 // --------------------------------------------------------------------------- |
|
228 // |
|
229 CAlfTextureManager& CAlfSkinnableImage::ImageTextureManager(TUid aManagerUid) |
|
230 { |
|
231 CAlfTextureManager* tm = &iEnv->TextureManager(); |
|
232 if (iSkinnedImageTextureManagerId != TUid::Uid(0)) |
|
233 { |
|
234 tm = iEnv->SharedTextureManager(aManagerUid); |
|
235 } |
|
236 return *tm; |
|
237 } |
|
238 |