|
1 /* |
|
2 * Copyright (c) 2008 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: Server side texture manager implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <uiacceltk/HuiEnv.h> |
|
21 #include <uiacceltk/HuiUtil.h> |
|
22 #include "alfsrvtexturemanager.h" |
|
23 #include "alfappsrvsession.h" |
|
24 |
|
25 /** |
|
26 * Granularity of CAlfSrvTextureManager::iClients array. |
|
27 */ |
|
28 const TInt KAlfSrvClientsGranularity = 4; |
|
29 |
|
30 /** |
|
31 * Values for auto size min change. |
|
32 */ |
|
33 const TInt KAlfTextureManagerAutoSizeMinSizeChange[] = |
|
34 { |
|
35 0, |
|
36 4, |
|
37 8, |
|
38 64, |
|
39 128 |
|
40 }; |
|
41 |
|
42 /** |
|
43 * Values for auto size lower threshold (256 = 1.0f). |
|
44 */ |
|
45 const TInt KAlfTetureManagerAutoSizeRelativeThresholdLower[] = |
|
46 { |
|
47 13, // 0.05f |
|
48 26, // .10f |
|
49 64, // .25f |
|
50 128, // .50f |
|
51 256 // 1.0f |
|
52 }; |
|
53 |
|
54 /** |
|
55 * Values for auto size upper threshold (256 = 1.0f). |
|
56 */ |
|
57 const TInt KAlfTetureManagerAutoSizeRelativeThresholdUpper[] = |
|
58 { |
|
59 13, // 0.05f |
|
60 26, // .10f |
|
61 64, // .25f |
|
62 256, // 1.0f |
|
63 25600 // 100.f |
|
64 }; |
|
65 |
|
66 /** |
|
67 * Values for auto size downsize settle threshold. |
|
68 */ |
|
69 const TInt KAlfTextureManagerAutoSizeDownsizeSettleThreshold[] = |
|
70 { |
|
71 0, |
|
72 8, |
|
73 64, |
|
74 128, |
|
75 256 |
|
76 }; |
|
77 |
|
78 /** |
|
79 * If width/height is below this low boundary, then one pixel precision |
|
80 * is used. |
|
81 */ |
|
82 const TInt KAlfSrvTextureManagerAutoSizeLowBoundary = 48; |
|
83 |
|
84 /** |
|
85 * If width/height is above low boundary, but below this high boundary, |
|
86 * then KAlfSrvTextureManagerAutoSizeMiddleRoundTo precision is used. |
|
87 */ |
|
88 const TInt KAlfSrvTextureManagerAutoSizeHighBoundary = 128; |
|
89 |
|
90 /** |
|
91 * Precision used when width/heigth is above low, but below high |
|
92 * boundary. This must be power of two. |
|
93 */ |
|
94 const TInt KAlfSrvTextureManagerAutoSizeMiddleRoundTo = 2; |
|
95 |
|
96 /** |
|
97 * Precision used when width/height is above high boundary. |
|
98 * This must be power of two. |
|
99 */ |
|
100 const TInt KAlfSrvTextureManagerAutoSizeHighRoundTo = 4; |
|
101 |
|
102 // ======== MEMBER FUNCTIONS ======== |
|
103 |
|
104 CAlfSrvTextureManager* CAlfSrvTextureManager::NewL() |
|
105 { |
|
106 CAlfSrvTextureManager* self = new (ELeave) CAlfSrvTextureManager; |
|
107 return self; |
|
108 } |
|
109 |
|
110 CAlfSrvTextureManager::~CAlfSrvTextureManager() |
|
111 { |
|
112 iClients.Close(); |
|
113 iUsedTextures.Close(); |
|
114 } |
|
115 |
|
116 // --------------------------------------------------------------------------- |
|
117 // Starts using CHuiEnv. |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 void CAlfSrvTextureManager::HandleEnvCreateL( CHuiEnv& aEnv ) |
|
121 { |
|
122 iEnv = &aEnv; |
|
123 |
|
124 iEnv->TextureManager(). |
|
125 iTextureAutoSizeObservers.AppendL( *this ); |
|
126 iIsRendererHWA = ( iEnv->Renderer() != EHuiRendererBitgdi ); |
|
127 } |
|
128 |
|
129 // --------------------------------------------------------------------------- |
|
130 // Stops using CHuiEnv. |
|
131 // --------------------------------------------------------------------------- |
|
132 // |
|
133 void CAlfSrvTextureManager::HandleEnvToBeDeleted() |
|
134 { |
|
135 if ( iEnv ) |
|
136 { |
|
137 iEnv->TextureManager(). |
|
138 iTextureAutoSizeObservers.Remove( *this ); |
|
139 iEnv = NULL; |
|
140 } |
|
141 } |
|
142 |
|
143 // --------------------------------------------------------------------------- |
|
144 // This functions converts texture ID used in the client side into id that |
|
145 // can be used in the serverside HuiTextureManager without the textures getting |
|
146 // accidentally shared between apps. |
|
147 // --------------------------------------------------------------------------- |
|
148 // |
|
149 TInt CAlfSrvTextureManager::CreateTextureId( |
|
150 const TProcessId& aClientOwnerId, |
|
151 TInt aClientSideId, |
|
152 TInt aClientSideManagerId, |
|
153 TBool aReUseAnyDeletedId ) |
|
154 { |
|
155 TInt exisitingSharedTextureId = 0; |
|
156 |
|
157 // Look for an existing entry for the id. |
|
158 for(TInt i = 0; i < iUsedTextures.Count(); i++) |
|
159 { |
|
160 if (aClientSideManagerId == 0) |
|
161 { |
|
162 // Normal texture, "private" to client |
|
163 if(iUsedTextures[i].iClientSideId == aClientSideId && |
|
164 iUsedTextures[i].iOwnerId == aClientOwnerId) |
|
165 { |
|
166 // Re-use old id |
|
167 iUsedTextures[i].iReleased = EFalse; |
|
168 return iUsedTextures[i].iServerSideId; |
|
169 } |
|
170 } |
|
171 else |
|
172 { |
|
173 // Shared texture |
|
174 if(iUsedTextures[i].iClientSideId == aClientSideId && |
|
175 iUsedTextures[i].iClientSideManagerId == aClientSideManagerId) |
|
176 { |
|
177 // Re-use old id |
|
178 if (iUsedTextures[i].iOwnerId == aClientOwnerId) |
|
179 { |
|
180 iUsedTextures[i].iReleased = EFalse; |
|
181 return iUsedTextures[i].iServerSideId; |
|
182 } |
|
183 else |
|
184 { |
|
185 exisitingSharedTextureId = iUsedTextures[i].iServerSideId; |
|
186 break; |
|
187 } |
|
188 } |
|
189 } |
|
190 } |
|
191 |
|
192 |
|
193 // Look for an existing deleted entry for the id i.e. recycle deleted texture id. |
|
194 // Only non-shared textures are recycled to keep things more simple and safe. |
|
195 if (aReUseAnyDeletedId && aClientSideManagerId == 0) |
|
196 { |
|
197 for(TInt i = 0; i < iUsedTextures.Count(); i++) |
|
198 { |
|
199 if (iUsedTextures[i].iOwnerId == aClientOwnerId && |
|
200 iUsedTextures[i].iDeleted && |
|
201 iUsedTextures[i].iClientSideManagerId == aClientSideManagerId) |
|
202 { |
|
203 // Re-use old deleted id even if it had different id |
|
204 iUsedTextures[i].iClientSideId = aClientSideId; |
|
205 iUsedTextures[i].iReleased = EFalse; |
|
206 iUsedTextures[i].iDeleted = EFalse; |
|
207 iUsedTextures[i].iSkinChangeCoordinator = EFalse; |
|
208 return iUsedTextures[i].iServerSideId; |
|
209 } |
|
210 } |
|
211 } |
|
212 |
|
213 |
|
214 // No existing entry found, create new one. |
|
215 TUsedTexture usedTexture; |
|
216 usedTexture.iClientSideId = aClientSideId; |
|
217 usedTexture.iClientSideManagerId = aClientSideManagerId; |
|
218 usedTexture.iOwnerId = aClientOwnerId; |
|
219 |
|
220 if (aClientSideManagerId == 0 || !exisitingSharedTextureId) |
|
221 { |
|
222 // Select new id and make sure it is not used |
|
223 ++iNextTextureId; |
|
224 TBool alreadyExists = ETrue; |
|
225 while(alreadyExists) |
|
226 { |
|
227 alreadyExists = EFalse; |
|
228 for(TInt i = 0; i < iUsedTextures.Count(); i++) |
|
229 { |
|
230 if (iUsedTextures[i].iServerSideId == iNextTextureId || iNextTextureId == 0) |
|
231 { |
|
232 iNextTextureId++; |
|
233 alreadyExists = ETrue; |
|
234 break; |
|
235 } |
|
236 } |
|
237 } |
|
238 usedTexture.iServerSideId = iNextTextureId; |
|
239 } |
|
240 else |
|
241 { |
|
242 usedTexture.iServerSideId = exisitingSharedTextureId; |
|
243 } |
|
244 |
|
245 TBool entryAdded = EFalse; |
|
246 for(TInt i = 0; i < iUsedTextures.Count(); i++) |
|
247 { |
|
248 if (iUsedTextures[i].iOwnerId == aClientOwnerId && |
|
249 iUsedTextures[i].iClientSideId == 0 && |
|
250 usedTexture.iClientSideManagerId == 0 && |
|
251 usedTexture.iServerSideId == 0) |
|
252 { |
|
253 entryAdded = ETrue; |
|
254 iUsedTextures[i] = usedTexture; |
|
255 } |
|
256 } |
|
257 |
|
258 if (!entryAdded) |
|
259 { |
|
260 iUsedTextures.Append(usedTexture); |
|
261 } |
|
262 |
|
263 return usedTexture.iServerSideId; |
|
264 } |
|
265 |
|
266 // --------------------------------------------------------------------------- |
|
267 // |
|
268 // |
|
269 // |
|
270 // --------------------------------------------------------------------------- |
|
271 // |
|
272 TInt CAlfSrvTextureManager::ExistingTextureId( |
|
273 const TProcessId& aClientOwnerId, |
|
274 TInt aClientSideId, |
|
275 TInt aClientSideManagerId, |
|
276 TBool aIgnoreOwnerForSharedTextures ) |
|
277 { |
|
278 // Look for an existing entry for the id. |
|
279 for(TInt i = 0; i < iUsedTextures.Count(); i++) |
|
280 { |
|
281 if (aClientSideManagerId == 0) |
|
282 { |
|
283 // Normal texture, "private" to client |
|
284 if(iUsedTextures[i].iClientSideId == aClientSideId && |
|
285 iUsedTextures[i].iOwnerId == aClientOwnerId && |
|
286 iUsedTextures[i].iReleased == EFalse) |
|
287 { |
|
288 return iUsedTextures[i].iServerSideId; |
|
289 } |
|
290 } |
|
291 else |
|
292 { |
|
293 // Shared texture |
|
294 if(iUsedTextures[i].iClientSideId == aClientSideId && |
|
295 iUsedTextures[i].iClientSideManagerId == aClientSideManagerId && |
|
296 iUsedTextures[i].iReleased == EFalse) |
|
297 { |
|
298 if (iUsedTextures[i].iOwnerId == aClientOwnerId || |
|
299 aIgnoreOwnerForSharedTextures) |
|
300 { |
|
301 return iUsedTextures[i].iServerSideId; |
|
302 } |
|
303 } |
|
304 } |
|
305 } |
|
306 |
|
307 // not found |
|
308 return 0; |
|
309 } |
|
310 |
|
311 // --------------------------------------------------------------------------- |
|
312 // |
|
313 // |
|
314 // --------------------------------------------------------------------------- |
|
315 // |
|
316 TInt CAlfSrvTextureManager::ReleaseTextureId( |
|
317 const TProcessId& aClientOwnerId, |
|
318 TInt aClientSideId, |
|
319 TInt aClientSideManagerId ) |
|
320 { |
|
321 TInt sharedTextureReferenceCount = 0; |
|
322 TInt toBeRemovedIndex = KErrNotFound; |
|
323 |
|
324 // Look for an existing entry for the id. |
|
325 for(TInt i = 0; i < iUsedTextures.Count(); i++) |
|
326 { |
|
327 if (aClientSideManagerId == 0) |
|
328 { |
|
329 // Normal texture, "private" to client |
|
330 if(iUsedTextures[i].iClientSideId == aClientSideId && |
|
331 iUsedTextures[i].iOwnerId == aClientOwnerId && |
|
332 iUsedTextures[i].iReleased == EFalse) |
|
333 { |
|
334 toBeRemovedIndex = i; |
|
335 break; |
|
336 } |
|
337 } |
|
338 else |
|
339 { |
|
340 // Shared texture |
|
341 if(iUsedTextures[i].iClientSideId == aClientSideId && |
|
342 iUsedTextures[i].iClientSideManagerId == aClientSideManagerId && |
|
343 iUsedTextures[i].iReleased == EFalse) |
|
344 { |
|
345 if (iUsedTextures[i].iOwnerId == aClientOwnerId) |
|
346 { |
|
347 toBeRemovedIndex = i; |
|
348 } |
|
349 sharedTextureReferenceCount++; |
|
350 } |
|
351 } |
|
352 } |
|
353 |
|
354 if (toBeRemovedIndex != KErrNotFound) |
|
355 { |
|
356 iUsedTextures[toBeRemovedIndex].iReleased = ETrue; |
|
357 iUsedTextures[toBeRemovedIndex].iSkinChangeCoordinator = EFalse; |
|
358 if (sharedTextureReferenceCount > 0) |
|
359 { |
|
360 sharedTextureReferenceCount--; |
|
361 } |
|
362 } |
|
363 |
|
364 return sharedTextureReferenceCount; |
|
365 } |
|
366 |
|
367 // --------------------------------------------------------------------------- |
|
368 // |
|
369 // |
|
370 // --------------------------------------------------------------------------- |
|
371 // |
|
372 TInt CAlfSrvTextureManager::DeleteTextureId( |
|
373 const TProcessId& aClientOwnerId, |
|
374 TInt aClientSideId, |
|
375 TInt aClientSideManagerId ) |
|
376 { |
|
377 TInt sharedTextureReferenceCount = 0; |
|
378 TInt toBeRemovedIndex = KErrNotFound; |
|
379 |
|
380 // Look for an existing entry for the id, it has |
|
381 // to be released. |
|
382 for(TInt i = 0; i < iUsedTextures.Count(); i++) |
|
383 { |
|
384 if (aClientSideManagerId == 0) |
|
385 { |
|
386 // Normal texture, "private" to client |
|
387 if(iUsedTextures[i].iClientSideId == aClientSideId && |
|
388 iUsedTextures[i].iOwnerId == aClientOwnerId && |
|
389 iUsedTextures[i].iReleased) |
|
390 { |
|
391 toBeRemovedIndex = i; |
|
392 break; |
|
393 } |
|
394 } |
|
395 else |
|
396 { |
|
397 // Shared texture |
|
398 if(iUsedTextures[i].iClientSideId == aClientSideId && |
|
399 iUsedTextures[i].iClientSideManagerId == aClientSideManagerId && |
|
400 iUsedTextures[i].iReleased) |
|
401 { |
|
402 if (iUsedTextures[i].iOwnerId == aClientOwnerId) |
|
403 { |
|
404 toBeRemovedIndex = i; |
|
405 } |
|
406 sharedTextureReferenceCount++; |
|
407 } |
|
408 } |
|
409 } |
|
410 |
|
411 if (toBeRemovedIndex != KErrNotFound) |
|
412 { |
|
413 iUsedTextures[toBeRemovedIndex].iDeleted = ETrue; |
|
414 iUsedTextures[toBeRemovedIndex].iSkinChangeCoordinator = EFalse; |
|
415 if (sharedTextureReferenceCount > 0) |
|
416 { |
|
417 sharedTextureReferenceCount--; |
|
418 } |
|
419 } |
|
420 return sharedTextureReferenceCount; |
|
421 } |
|
422 |
|
423 // --------------------------------------------------------------------------- |
|
424 // After skin change event this function determines if given texture content |
|
425 // is valid or not. |
|
426 // |
|
427 // Return value 0 indicates invalid, other valid. |
|
428 // --------------------------------------------------------------------------- |
|
429 // |
|
430 TInt CAlfSrvTextureManager::ValidateSkinForTextureId( |
|
431 const TProcessId& aClientOwnerId, |
|
432 TInt aClientSideId, |
|
433 TInt aClientSideManagerId ) |
|
434 { |
|
435 TInt ownEntryIndex = -1; |
|
436 TInt retVal = 0; |
|
437 |
|
438 // Look for an existing entry for the id. |
|
439 for(TInt i = 0; i < iUsedTextures.Count(); i++) |
|
440 { |
|
441 if (aClientSideManagerId == 0) |
|
442 { |
|
443 // Normal texture, "private" to client |
|
444 if(iUsedTextures[i].iClientSideId == aClientSideId && |
|
445 iUsedTextures[i].iOwnerId == aClientOwnerId && |
|
446 iUsedTextures[i].iReleased == EFalse) |
|
447 { |
|
448 retVal = 0; // Not shared texture, always invalid. |
|
449 break; |
|
450 } |
|
451 } |
|
452 else |
|
453 { |
|
454 // Shared texture |
|
455 if(iUsedTextures[i].iClientSideId == aClientSideId && |
|
456 iUsedTextures[i].iClientSideManagerId == aClientSideManagerId && |
|
457 iUsedTextures[i].iReleased == EFalse) |
|
458 { |
|
459 if (iUsedTextures[i].iOwnerId == aClientOwnerId) |
|
460 { |
|
461 ownEntryIndex = i; |
|
462 } |
|
463 else |
|
464 { |
|
465 if (iUsedTextures[i].iSkinChangeCoordinator) |
|
466 { |
|
467 retVal = 1; // For shared textures, only one entry is invalid to avoid multiple reloads. |
|
468 break; |
|
469 } |
|
470 } |
|
471 } |
|
472 } |
|
473 } |
|
474 |
|
475 if (retVal == 0 && ownEntryIndex != -1) |
|
476 { |
|
477 // This index becomes the one that handles skin change |
|
478 iUsedTextures[ownEntryIndex].iSkinChangeCoordinator = ETrue; |
|
479 } |
|
480 |
|
481 return retVal; |
|
482 } |
|
483 |
|
484 // --------------------------------------------------------------------------- |
|
485 // Destroyes deleted texture ids. |
|
486 // --------------------------------------------------------------------------- |
|
487 // |
|
488 TInt CAlfSrvTextureManager::DestroyDeletedTextureIds(const TProcessId& aOwnerId) |
|
489 { |
|
490 // Look for an existing entry for the id. |
|
491 TInt i = 0; |
|
492 for(i = 0; i < iUsedTextures.Count(); i++) |
|
493 { |
|
494 if (iUsedTextures[i].iDeleted && |
|
495 iUsedTextures[i].iClientSideManagerId == 0 && |
|
496 iUsedTextures[i].iOwnerId == aOwnerId) |
|
497 { |
|
498 iUsedTextures.Remove(i); |
|
499 i = 0; |
|
500 } |
|
501 } |
|
502 |
|
503 return 0; |
|
504 } |
|
505 |
|
506 // --------------------------------------------------------------------------- |
|
507 // Adds client item to iClients array. |
|
508 // --------------------------------------------------------------------------- |
|
509 // |
|
510 void CAlfSrvTextureManager::AddClientL( |
|
511 const TProcessId& aClientOwnerId, |
|
512 MAlfSrvTextureManagerClient& aClient ) |
|
513 { |
|
514 if ( FindClient( aClient ) == KErrNotFound ) |
|
515 { |
|
516 TClientItem item; |
|
517 item.iOwnerId = aClientOwnerId; |
|
518 item.iClient = &aClient; |
|
519 item.iIsMarked = EFalse; |
|
520 |
|
521 iClients.AppendL( item ); |
|
522 } |
|
523 } |
|
524 |
|
525 // --------------------------------------------------------------------------- |
|
526 // Removes client item from iClients array |
|
527 // --------------------------------------------------------------------------- |
|
528 // |
|
529 void CAlfSrvTextureManager::RemoveClient( MAlfSrvTextureManagerClient& aClient ) |
|
530 { |
|
531 TInt pos = FindClient( aClient ); |
|
532 if ( pos != KErrNotFound ) |
|
533 { |
|
534 iClients.Remove( pos ); |
|
535 } |
|
536 } |
|
537 |
|
538 CAlfSrvTextureManager::CAlfSrvTextureManager() |
|
539 : iNextTextureId( 1 ), |
|
540 iUsedTextures( 4 ), |
|
541 iClients( KAlfSrvClientsGranularity ) |
|
542 { |
|
543 } |
|
544 |
|
545 // --------------------------------------------------------------------------- |
|
546 // Finds client side texture id based on server side id. Returns also |
|
547 // owner id so that it's possible to find corresponding session instance. |
|
548 // --------------------------------------------------------------------------- |
|
549 // |
|
550 TBool CAlfSrvTextureManager::FindByTextureId( |
|
551 TInt aServerSideId, |
|
552 TInt& aClientSideId, |
|
553 TProcessId& aOwnerId ) const |
|
554 { |
|
555 TBool found = EFalse; |
|
556 |
|
557 const TInt count = iUsedTextures.Count(); |
|
558 for ( TInt i = 0; i < count; i++ ) |
|
559 { |
|
560 const TUsedTexture& current = iUsedTextures[ i ]; |
|
561 if ( !current.iClientSideManagerId && |
|
562 current.iServerSideId == aServerSideId ) |
|
563 { |
|
564 found = ETrue; |
|
565 aClientSideId = current.iClientSideId; |
|
566 aOwnerId = current.iOwnerId; |
|
567 break; |
|
568 } |
|
569 } |
|
570 |
|
571 return found; |
|
572 } |
|
573 |
|
574 // --------------------------------------------------------------------------- |
|
575 // Finds index of aClient from iClients array |
|
576 // --------------------------------------------------------------------------- |
|
577 // |
|
578 TInt CAlfSrvTextureManager::FindClient( |
|
579 MAlfSrvTextureManagerClient& aClient ) const |
|
580 { |
|
581 TInt pos = KErrNotFound; |
|
582 const TInt count = iClients.Count(); |
|
583 |
|
584 for ( TInt i = 0; i < count; i++ ) |
|
585 { |
|
586 if ( iClients[ i ].iClient == &aClient ) |
|
587 { |
|
588 pos = i; |
|
589 break; |
|
590 } |
|
591 } |
|
592 |
|
593 return pos; |
|
594 } |
|
595 |
|
596 // --------------------------------------------------------------------------- |
|
597 // Finds client interface corresponding to aOwnerId from iClients array |
|
598 // --------------------------------------------------------------------------- |
|
599 // |
|
600 MAlfSrvTextureManagerClient* CAlfSrvTextureManager::FindClientAndMark( |
|
601 const TProcessId& aOwnerId ) |
|
602 { |
|
603 MAlfSrvTextureManagerClient* result = NULL; |
|
604 const TInt count = iClients.Count(); |
|
605 for ( TInt i = 0; i < count; i++ ) |
|
606 { |
|
607 if ( iClients[ i ].iOwnerId == aOwnerId ) |
|
608 { |
|
609 result = iClients[ i ].iClient; |
|
610 iClients[ i ].iIsMarked = ETrue; |
|
611 break; |
|
612 } |
|
613 } |
|
614 |
|
615 return result; |
|
616 } |
|
617 |
|
618 // --------------------------------------------------------------------------- |
|
619 // Inform marked clients of completion of texture size changes. Clear marks. |
|
620 // --------------------------------------------------------------------------- |
|
621 // |
|
622 void CAlfSrvTextureManager::NotifyTextureSizeChangesCompleted() |
|
623 { |
|
624 const TInt count = iClients.Count(); |
|
625 for ( TInt i = 0; i < count; i++ ) |
|
626 { |
|
627 if ( iClients[ i ].iIsMarked ) |
|
628 { |
|
629 iClients[ i ].iIsMarked = EFalse; |
|
630 iClients[ i ].iClient->TextureSizeChangesCompleted(); |
|
631 } |
|
632 } |
|
633 } |
|
634 |
|
635 // --------------------------------------------------------------------------- |
|
636 // Calculates index (currently 0 .. 4) from very low .. very high. |
|
637 // --------------------------------------------------------------------------- |
|
638 // |
|
639 TInt CAlfSrvTextureManager::IndexFromParameter( TInt aValue ) |
|
640 { |
|
641 // Note: this method makes assumptions about |
|
642 // THuiTextureAutoSizeParams. |
|
643 |
|
644 // Now make range positive (0 .. 40). |
|
645 TInt result = aValue - THuiTextureAutoSizeParams::EVeryLow; |
|
646 |
|
647 // Transfer to index (0 .. 4). |
|
648 const TInt KAlfTextureStepSize = 10; |
|
649 result /= KAlfTextureStepSize; |
|
650 |
|
651 // Now make sure that value is in specified range (0 .. 4). |
|
652 return Max( 0, Min( result, 4 ) ); |
|
653 } |
|
654 |
|
655 // --------------------------------------------------------------------------- |
|
656 // Checks if value (=width/height) should be resized. |
|
657 // --------------------------------------------------------------------------- |
|
658 // |
|
659 TBool CAlfSrvTextureManager::CheckIfShouldResize( |
|
660 TInt aCurrentValue, TInt aNewValue, const CHuiTexture& aTexture ) |
|
661 { |
|
662 const THuiTextureAutoSizeParams params = aTexture.AutoSizeParams(); |
|
663 |
|
664 const TInt delta = Abs( aNewValue - aCurrentValue ); |
|
665 TInt minChangeInPixels = |
|
666 KAlfTextureManagerAutoSizeMinSizeChange[ |
|
667 IndexFromParameter( params.MinSizeChange() ) ]; |
|
668 |
|
669 if ( delta < minChangeInPixels ) |
|
670 { |
|
671 // No need to perform complex calculation - no need to resize. |
|
672 return EFalse; |
|
673 } |
|
674 |
|
675 TInt sizeRelativeThreshold = 0; |
|
676 if ( aNewValue < aCurrentValue ) |
|
677 { |
|
678 sizeRelativeThreshold = |
|
679 KAlfTetureManagerAutoSizeRelativeThresholdLower[ |
|
680 IndexFromParameter( params.SizeLowerThreshold() ) ]; |
|
681 } |
|
682 else |
|
683 { |
|
684 sizeRelativeThreshold = |
|
685 KAlfTetureManagerAutoSizeRelativeThresholdUpper[ |
|
686 IndexFromParameter( params.SizeUpperThreshold() ) ]; |
|
687 } |
|
688 |
|
689 TInt downsizeSettleThresholdInPixels = |
|
690 KAlfTextureManagerAutoSizeDownsizeSettleThreshold[ |
|
691 IndexFromParameter( params.DownsizeSettleThreshold() ) ]; |
|
692 |
|
693 // So if size is becoming smaller and icon is already small, |
|
694 // then resize less aggressively. |
|
695 TInt64 threshold = 0; |
|
696 |
|
697 // Calculate 1 * change |
|
698 threshold = aCurrentValue; |
|
699 threshold *= sizeRelativeThreshold; |
|
700 |
|
701 if ( aCurrentValue <= downsizeSettleThresholdInPixels && |
|
702 aNewValue < aCurrentValue ) |
|
703 { |
|
704 // 2 * specified change |
|
705 threshold *= 2; |
|
706 } |
|
707 |
|
708 // 256 = 1.f, so normalize back to integers. |
|
709 threshold /= 256; |
|
710 |
|
711 // Handle overflow |
|
712 if ( threshold > KMaxTInt ) |
|
713 { |
|
714 threshold = KMaxTInt; |
|
715 } |
|
716 |
|
717 const TInt requiredChange = I64INT( threshold ); |
|
718 const TBool result = delta >= requiredChange; |
|
719 return result; |
|
720 } |
|
721 |
|
722 // --------------------------------------------------------------------------- |
|
723 // Checks if resizing is needed. |
|
724 // --------------------------------------------------------------------------- |
|
725 // |
|
726 TBool CAlfSrvTextureManager::CheckIfResizeNeeded( |
|
727 const TSize& aCurrentSize, |
|
728 const TSize& aNewSize, |
|
729 const CHuiTexture& aTexture, |
|
730 TInt& aDeliveryPriority ) |
|
731 { |
|
732 // If new size would become zero size, then don't resize. |
|
733 if ( !aNewSize.iWidth || !aNewSize.iHeight ) |
|
734 { |
|
735 return EFalse; |
|
736 } |
|
737 |
|
738 // Otherwise check if width or height has changed sufficiently. |
|
739 // (also, one possibility would be to check area) |
|
740 const TBool result = |
|
741 CheckIfShouldResize( aCurrentSize.iWidth, aNewSize.iWidth, |
|
742 aTexture ) || |
|
743 CheckIfShouldResize( aCurrentSize.iHeight, aNewSize.iHeight, |
|
744 aTexture ); |
|
745 |
|
746 if ( result ) |
|
747 { |
|
748 if ( aNewSize.iWidth > aCurrentSize.iWidth || |
|
749 aNewSize.iHeight > aCurrentSize.iHeight ) |
|
750 { |
|
751 // If it's becoming larger, let's change immediately. |
|
752 aDeliveryPriority = 0; |
|
753 } |
|
754 else |
|
755 { |
|
756 // If it's becoming smaller, then it's not so urgent. |
|
757 aDeliveryPriority = 1; |
|
758 } |
|
759 } |
|
760 |
|
761 return result; |
|
762 } |
|
763 |
|
764 // --------------------------------------------------------------------------- |
|
765 // Rounds real value to integer. Also HWA can be taken into account. |
|
766 // --------------------------------------------------------------------------- |
|
767 // |
|
768 inline TInt CAlfSrvTextureManager::RoundToInteger( const TReal32& aValue ) const |
|
769 { |
|
770 TInt value = HUI_ROUND_FLOAT_TO_INT( aValue ); |
|
771 if ( value < 0 ) |
|
772 { |
|
773 value = 0; |
|
774 } |
|
775 |
|
776 if ( iIsRendererHWA && |
|
777 ( value > KAlfSrvTextureManagerAutoSizeLowBoundary ) ) |
|
778 { |
|
779 // Select appropriate rounding precision. |
|
780 TInt roundTo = KAlfSrvTextureManagerAutoSizeMiddleRoundTo; |
|
781 if ( value > KAlfSrvTextureManagerAutoSizeHighBoundary ) |
|
782 { |
|
783 roundTo = KAlfSrvTextureManagerAutoSizeHighRoundTo; |
|
784 } |
|
785 |
|
786 const TInt remainder = value & ( roundTo - 1 ); |
|
787 if ( remainder ) |
|
788 { |
|
789 // Round to next multiple of 'roundTo'. |
|
790 value -= remainder; |
|
791 value += roundTo; |
|
792 } |
|
793 } |
|
794 |
|
795 return value; |
|
796 } |
|
797 |
|
798 // --------------------------------------------------------------------------- |
|
799 // Calculates new size if resizing is needed. |
|
800 // --------------------------------------------------------------------------- |
|
801 // |
|
802 TBool CAlfSrvTextureManager::CalculateNewSizeIfResizeNeeded( |
|
803 const CHuiTexture& aTexture, |
|
804 const THuiRealSize& aPreferredSize, |
|
805 const TSize& aCurrentSize, |
|
806 TSize& aNewSize, |
|
807 TInt& aDeliveryPriority ) const |
|
808 { |
|
809 // Calculate preferred size. |
|
810 const TSize preferredSize( |
|
811 RoundToInteger( aPreferredSize.iWidth ), |
|
812 RoundToInteger( aPreferredSize.iHeight ) ); |
|
813 |
|
814 // First, if texture does not have content, then we must resize and |
|
815 // let's then use highest priority. |
|
816 TInt deliveryPriority = -1; |
|
817 TBool result = !aTexture.HasContent(); |
|
818 |
|
819 if ( !result ) |
|
820 { |
|
821 result = |
|
822 CheckIfResizeNeeded( aCurrentSize, preferredSize, aTexture, |
|
823 deliveryPriority ); |
|
824 } |
|
825 |
|
826 if ( result ) |
|
827 { |
|
828 aNewSize = preferredSize; |
|
829 aDeliveryPriority = deliveryPriority; |
|
830 } |
|
831 |
|
832 return result; |
|
833 } |
|
834 |
|
835 // --------------------------------------------------------------------------- |
|
836 // Handles a set of texture preferred properties. |
|
837 // --------------------------------------------------------------------------- |
|
838 // |
|
839 void CAlfSrvTextureManager::HandlePreferredSizeChanged( |
|
840 MAlfSrvTextureManagerClient& aClient, |
|
841 TInt aClientSideTextureId, |
|
842 const CHuiTexture& aTexture, |
|
843 const THuiRealSize& aPreferredSize ) |
|
844 { |
|
845 // Get information about current size from client. |
|
846 TSize currentSize; |
|
847 TBool hasDelivered; |
|
848 TBool ok = aClient.GetTextureSize( |
|
849 aClientSideTextureId, currentSize, hasDelivered ); |
|
850 |
|
851 // Determine new size. |
|
852 TSize newSize; |
|
853 |
|
854 TBool currentSizeIsTextureSize = EFalse; |
|
855 if ( !( ok && hasDelivered ) ) |
|
856 { |
|
857 currentSizeIsTextureSize = ETrue; |
|
858 currentSize = aTexture.Size(); |
|
859 } |
|
860 |
|
861 TInt deliveryPriority = 0; |
|
862 |
|
863 if ( CalculateNewSizeIfResizeNeeded( |
|
864 aTexture, |
|
865 aPreferredSize, |
|
866 currentSize, |
|
867 newSize, |
|
868 deliveryPriority ) ) |
|
869 { |
|
870 // Update size to client |
|
871 aClient.SetTextureSize( |
|
872 aClientSideTextureId, newSize, deliveryPriority ); |
|
873 } |
|
874 else |
|
875 { |
|
876 // If current texture size is acceptable, then |
|
877 // no need to report new size. |
|
878 if ( currentSizeIsTextureSize ) |
|
879 { |
|
880 // Instead, now we can remove the whole texture size. |
|
881 aClient.RemoveTextureSize( aClientSideTextureId ); |
|
882 } |
|
883 } |
|
884 } |
|
885 |
|
886 // --------------------------------------------------------------------------- |
|
887 // Handles one by one texture preferred properties. |
|
888 // --------------------------------------------------------------------------- |
|
889 // |
|
890 TBool CAlfSrvTextureManager::PreferredSizeChanged( |
|
891 const CHuiTexture& aTexture, |
|
892 TInt aServerSideTextureId, |
|
893 const THuiRealSize& aPreferredSize ) |
|
894 { |
|
895 TInt clientSideId = 0; |
|
896 TProcessId ownerId; |
|
897 TBool result = EFalse; |
|
898 |
|
899 // Find corresponding server side texture id |
|
900 if ( FindByTextureId( aServerSideTextureId, clientSideId, ownerId ) ) |
|
901 { |
|
902 // Find client interface |
|
903 MAlfSrvTextureManagerClient* client = FindClientAndMark( ownerId ); |
|
904 if ( client ) |
|
905 { |
|
906 // Decide size |
|
907 HandlePreferredSizeChanged( *client, clientSideId, aTexture, |
|
908 aPreferredSize ); |
|
909 result = ETrue; |
|
910 } |
|
911 } |
|
912 return result; |
|
913 } |
|
914 |
|
915 // --------------------------------------------------------------------------- |
|
916 // Inform all clients of completion. This one also clears marks. |
|
917 // --------------------------------------------------------------------------- |
|
918 // |
|
919 void CAlfSrvTextureManager::PreferredSizeReportCompleted() |
|
920 { |
|
921 NotifyTextureSizeChangesCompleted(); |
|
922 } |