|
1 /* |
|
2 * Copyright (c) 2006-2007 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: Implementation of CHuiTexture. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "uiacceltk/HuiTexture.h" // Class definition |
|
21 #include "HuiRenderPlugin.h" |
|
22 #include "uiacceltk/HuiEnv.h" |
|
23 #include "uiacceltk/HuiStatic.h" |
|
24 #include "uiacceltk/HuiUtil.h" |
|
25 #include "uiacceltk/HuiPanic.h" |
|
26 #include "HuiRenderSurface.h" |
|
27 #include "uiacceltk/HuiProbe.h" |
|
28 |
|
29 #include "uiacceltk/HuiTextureProcessor.h" |
|
30 |
|
31 #include <e32math.h> |
|
32 |
|
33 const TInt KHuiTextureDefaultPriority = 1; // currenly just != 0 |
|
34 |
|
35 |
|
36 // placeholder |
|
37 EXPORT_C MHuiTexture::~MHuiTexture() |
|
38 { |
|
39 } |
|
40 |
|
41 EXPORT_C CHuiTexture* CHuiTexture::NewL(const THuiTextureHandle* aExistingTexture) |
|
42 { |
|
43 return CHuiStatic::Renderer().CreateTextureL(aExistingTexture); |
|
44 } |
|
45 |
|
46 |
|
47 EXPORT_C CHuiTexture* CHuiTexture::NewLC(const THuiTextureHandle* aExistingTexture) |
|
48 { |
|
49 CHuiTexture* self = CHuiTexture::NewL(aExistingTexture); |
|
50 CleanupStack::PushL(self); |
|
51 return self; |
|
52 } |
|
53 |
|
54 |
|
55 EXPORT_C CHuiTexture::CHuiTexture() |
|
56 { |
|
57 HUI_PROBE_ASSOCIATE_WITH_CURRENT_SESSION |
|
58 HUI_PROBE_REPORT_CONSTRUCTED |
|
59 } |
|
60 |
|
61 |
|
62 EXPORT_C void CHuiTexture::BaseConstructL() |
|
63 { |
|
64 // No name by default. |
|
65 SetImageFileNameL(_L("")); |
|
66 |
|
67 HUI_DEBUG(_L("CHuiTexture::BaseConstructL() - Auto-appending to texture manager.")); |
|
68 |
|
69 // Make the texture automatically owned by the texture manager. |
|
70 CHuiStatic::Env().TextureManager().AppendTextureL(this); |
|
71 iInternalState |= EHuiTextureFlagAddedToTManager; |
|
72 |
|
73 iPriority = KHuiTextureDefaultPriority; |
|
74 } |
|
75 |
|
76 |
|
77 EXPORT_C CHuiTexture::~CHuiTexture() |
|
78 { |
|
79 iContentObservers.Close(); |
|
80 |
|
81 HUI_DEBUG(_L("CHuiTexture::~CHuiTexture() - Auto-removing from texture manager.")); |
|
82 |
|
83 // Remove the texture automatically from the texture manager. |
|
84 if (iInternalState & EHuiTextureFlagAddedToTManager) |
|
85 { |
|
86 CHuiStatic::Env().TextureManager().RemoveTexture(*this); |
|
87 } |
|
88 |
|
89 // NOTE: Do NOT call Reset, or SegSegmentCount(0) from |
|
90 // here since they have pure virtual method calls, |
|
91 // which won't work anymore :( |
|
92 iSegments.Close(); |
|
93 delete iImageFileName; |
|
94 iImageFileName = NULL; |
|
95 iPlaceholder = NULL; |
|
96 iPreferredSizes.Close(); |
|
97 |
|
98 // delete all created shadows |
|
99 ResetShadows(); |
|
100 iShadows.Close(); |
|
101 |
|
102 HUI_PROBE_REPORT_DESTRUCTED |
|
103 } |
|
104 |
|
105 |
|
106 EXPORT_C MHuiSegmentedTexture* CHuiTexture::SegmentedTexture() |
|
107 { |
|
108 return this; |
|
109 } |
|
110 |
|
111 |
|
112 EXPORT_C MHuiShadowedTexture* CHuiTexture::ShadowedTexture() |
|
113 { |
|
114 return this; |
|
115 } |
|
116 |
|
117 |
|
118 EXPORT_C const MHuiSegmentedTexture* CHuiTexture::SegmentedTexture() const |
|
119 { |
|
120 return this; |
|
121 } |
|
122 |
|
123 |
|
124 EXPORT_C const MHuiShadowedTexture* CHuiTexture::ShadowedTexture() const |
|
125 { |
|
126 return this; |
|
127 } |
|
128 |
|
129 |
|
130 TBool CHuiTexture::GetShadowTexture( |
|
131 THuiTextureHandle& aHandle, |
|
132 TInt aBlurDimension ) const |
|
133 { |
|
134 for ( TInt i = 0 ; i < iShadows.Count() ; i++ ) |
|
135 { |
|
136 if ( iShadows[i].iBlurDimension == aBlurDimension ) |
|
137 { |
|
138 aHandle = iShadows[i].iShadowTexture->Handle(); |
|
139 return ETrue; |
|
140 } |
|
141 } |
|
142 return EFalse; |
|
143 } |
|
144 |
|
145 void CHuiTexture::CreateShadowTextureL( |
|
146 TInt aBlurDimension, |
|
147 THuiShadowStyle aStyle ) |
|
148 { |
|
149 // check if the shadow already exists |
|
150 { |
|
151 THuiTextureHandle dummy; |
|
152 if ( GetShadowTexture( dummy, aBlurDimension ) ) |
|
153 { |
|
154 return; |
|
155 } |
|
156 } |
|
157 |
|
158 // shadow not found -> generate one. |
|
159 CHuiTexture* newShadowTexture = CHuiTexture::NewL(); |
|
160 CHuiStatic::Env().TextureManager().RemoveTexture(*newShadowTexture); |
|
161 newShadowTexture->iInternalState &= ~EHuiTextureFlagAddedToTManager; |
|
162 CleanupStack::PushL( newShadowTexture ); |
|
163 newShadowTexture->SetSegmentCountL(1); |
|
164 |
|
165 // blur |
|
166 CHuiTextureProcessor& proc = CHuiStatic::Env().TextureManager().Processor(); |
|
167 |
|
168 THuiTextureHandle shadowHandle = newShadowTexture->Handle(); |
|
169 switch(aStyle) |
|
170 { |
|
171 case EHuiTextureShadowStyleIcon: |
|
172 proc.BlurSegmentedL(*this, shadowHandle, TSize(Size().iWidth/2, Size().iHeight/2), aBlurDimension, |
|
173 CHuiTextureProcessor::EBlurFlagWhite | |
|
174 CHuiTextureProcessor::EBlurFlagAlpha | |
|
175 CHuiTextureProcessor::EBlurFlagExpandEdges); |
|
176 break; |
|
177 |
|
178 case EHuiTextureShadowStyleRasterizedText: |
|
179 proc.BlurSegmentedL(*this, shadowHandle, TSize(Size().iWidth/*/2*/, Size().iHeight/*/2*/), aBlurDimension, |
|
180 CHuiTextureProcessor::EBlurFlagWhite | |
|
181 CHuiTextureProcessor::EBlurFlagAlpha | |
|
182 CHuiTextureProcessor::EBlurFlagExpandEdges); |
|
183 break; |
|
184 |
|
185 default: |
|
186 break; |
|
187 } |
|
188 |
|
189 newShadowTexture->SetSegmentSize(0,shadowHandle.iSize ); |
|
190 newShadowTexture->SetSegmentTextureSize(0,shadowHandle.iTextureSize ); |
|
191 |
|
192 // create item on the array |
|
193 TShadowData newData; |
|
194 newData.iShadowTexture = newShadowTexture; |
|
195 newData.iBlurDimension = aBlurDimension; |
|
196 |
|
197 iShadows.AppendL( newData ); |
|
198 CleanupStack::Pop( newShadowTexture ); |
|
199 } |
|
200 |
|
201 |
|
202 EXPORT_C void CHuiTexture::EnableShadow(TBool aEnable) |
|
203 { |
|
204 if(aEnable) |
|
205 { |
|
206 iInternalState |= EHuiTextureFlagShadowEnabled; |
|
207 } |
|
208 else |
|
209 { |
|
210 iInternalState &= ~EHuiTextureFlagShadowEnabled; |
|
211 |
|
212 // delete all created shadows |
|
213 ResetShadows(); |
|
214 } |
|
215 } |
|
216 |
|
217 |
|
218 EXPORT_C TBool CHuiTexture::IsShadowEnabled() const |
|
219 { |
|
220 return ((iInternalState & EHuiTextureFlagShadowEnabled) != 0); |
|
221 } |
|
222 |
|
223 |
|
224 EXPORT_C void CHuiTexture::SetShadowStyle(THuiShadowStyle aShadowStyle) |
|
225 { |
|
226 iShadowStyle = aShadowStyle; |
|
227 } |
|
228 |
|
229 |
|
230 EXPORT_C THuiShadowStyle CHuiTexture::ShadowStyle() const |
|
231 { |
|
232 return iShadowStyle; |
|
233 } |
|
234 |
|
235 EXPORT_C TBool CHuiTexture::GetShadowTexture(THuiTextureHandle& aHandle) const |
|
236 { |
|
237 // Return the first shadow if generated |
|
238 if ( iShadows.Count() ) |
|
239 { |
|
240 aHandle = iShadows[0].iShadowTexture->Handle(); |
|
241 return ETrue; |
|
242 } |
|
243 return EFalse; |
|
244 } |
|
245 |
|
246 |
|
247 EXPORT_C void CHuiTexture::SetSegmentCountL(TInt aSegmentCount) |
|
248 { |
|
249 // delete old segments (if needed) |
|
250 TInt count = iSegments.Count(); |
|
251 while(count > aSegmentCount) |
|
252 { |
|
253 count--; |
|
254 HUI_DEBUG1(_L("CHuiTexture::SetSegmentCount - Deallocating segment %i"), count); |
|
255 // Deallocate resources associated with segment |
|
256 // NOTE: call to pure virtual method, will not work from the |
|
257 // destructor of this class.. |
|
258 ResetSegment(count); |
|
259 iSegments.Remove(count); |
|
260 } |
|
261 |
|
262 // add new texture segments (if needed) |
|
263 while(count < aSegmentCount) |
|
264 { |
|
265 TSegment seg; |
|
266 User::LeaveIfError(iSegments.Append(seg)); |
|
267 HUI_DEBUG1(_L("CHuiTexture::SetSegmentCount - Creating segment %i"), count); |
|
268 // Create initial segment with texture name etc. |
|
269 InitSegmentL(count); |
|
270 count++; |
|
271 } |
|
272 |
|
273 } |
|
274 |
|
275 |
|
276 EXPORT_C TSize CHuiTexture::Size() const |
|
277 { |
|
278 if(iPlaceholder) |
|
279 { |
|
280 return iPlaceholder->Size(); |
|
281 } |
|
282 return iSize; |
|
283 } |
|
284 |
|
285 |
|
286 EXPORT_C TInt CHuiTexture::SegmentCount() const |
|
287 { |
|
288 if(iPlaceholder) |
|
289 { |
|
290 return iPlaceholder->SegmentCount(); |
|
291 } |
|
292 return iSegments.Count(); |
|
293 } |
|
294 |
|
295 |
|
296 EXPORT_C TUint CHuiTexture::SegmentName(TInt aSegment) const |
|
297 { |
|
298 ASSERT(aSegment < SegmentCount()); |
|
299 if(iPlaceholder) |
|
300 { |
|
301 return iPlaceholder->SegmentName(aSegment); |
|
302 } |
|
303 |
|
304 return iSegments[aSegment].iName; |
|
305 } |
|
306 |
|
307 |
|
308 EXPORT_C TSize CHuiTexture::SegmentSize(TInt aSegment) const |
|
309 { |
|
310 ASSERT(aSegment < SegmentCount()); |
|
311 if(iPlaceholder) |
|
312 { |
|
313 return iPlaceholder->SegmentSize(aSegment); |
|
314 } |
|
315 |
|
316 return iSegments[aSegment].iSize; |
|
317 } |
|
318 |
|
319 |
|
320 EXPORT_C TSize CHuiTexture::SegmentTextureSize(TInt aSegment) const |
|
321 { |
|
322 ASSERT(aSegment < SegmentCount()); |
|
323 if(iPlaceholder) |
|
324 { |
|
325 return iPlaceholder->SegmentTextureSize(aSegment); |
|
326 } |
|
327 |
|
328 return iSegments[aSegment].iTextureSize; |
|
329 } |
|
330 |
|
331 |
|
332 EXPORT_C TPoint CHuiTexture::SegmentOffset(TInt aSegment) const |
|
333 { |
|
334 ASSERT(aSegment < SegmentCount()); |
|
335 if(iPlaceholder) |
|
336 { |
|
337 return iPlaceholder->SegmentOffset(aSegment); |
|
338 } |
|
339 |
|
340 return iSegments[aSegment].iOffset; |
|
341 } |
|
342 |
|
343 |
|
344 EXPORT_C void CHuiTexture::SetSize(const TSize& aSize) |
|
345 { |
|
346 // if there are multiple |
|
347 // segments already defined we have to recalculate (rescale) |
|
348 // the logical sizes and offsets for the individual segments |
|
349 // to match the new logical size |
|
350 if (SegmentCount()>0 && iSize.iWidth > 0 && iSize.iHeight > 0) |
|
351 { |
|
352 for (TInt s = 0; s < SegmentCount(); s++) |
|
353 { |
|
354 TSize oldSize(SegmentSize(s)); |
|
355 TSize newSize(oldSize.iWidth * aSize.iWidth / iSize.iWidth, |
|
356 oldSize.iHeight * aSize.iHeight / iSize.iHeight); |
|
357 TPoint oldOffset(SegmentOffset(s)); |
|
358 TPoint newOffset(oldOffset.iX * aSize.iWidth / iSize.iWidth, |
|
359 oldOffset.iY * aSize.iHeight / iSize.iHeight); |
|
360 SetSegmentSize(s, newSize); |
|
361 SetSegmentOffset(s, newOffset); |
|
362 } |
|
363 } |
|
364 |
|
365 // assign new logical size |
|
366 iSize = aSize; |
|
367 |
|
368 } |
|
369 |
|
370 |
|
371 EXPORT_C void CHuiTexture::SetSegmentName(TInt aSegment, TUint aName) |
|
372 { |
|
373 ASSERT(aSegment < SegmentCount()); |
|
374 iSegments[aSegment].iName = aName; |
|
375 } |
|
376 |
|
377 |
|
378 EXPORT_C void CHuiTexture::SetSegmentSize(TInt aSegment, const TSize& aSegmentSize) |
|
379 { |
|
380 ASSERT(aSegment < SegmentCount()); |
|
381 iSegments[aSegment].iSize = aSegmentSize; |
|
382 } |
|
383 |
|
384 |
|
385 EXPORT_C void CHuiTexture::SetSegmentTextureSize(TInt aSegment, const TSize& aSegmentTextureSize) |
|
386 { |
|
387 ASSERT(aSegment < SegmentCount()); |
|
388 iSegments[aSegment].iTextureSize = aSegmentTextureSize; |
|
389 } |
|
390 |
|
391 |
|
392 EXPORT_C void CHuiTexture::SetSegmentOffset(TInt aSegment, const TPoint& aOffset) |
|
393 { |
|
394 ASSERT(aSegment < SegmentCount()); |
|
395 iSegments[aSegment].iOffset = aOffset; |
|
396 } |
|
397 |
|
398 |
|
399 EXPORT_C void CHuiTexture::SetSkinContent(TBool aSkinContent) |
|
400 { |
|
401 if(aSkinContent) |
|
402 { |
|
403 iInternalState |= EHuiTextureFlagSkinContent; |
|
404 } |
|
405 else |
|
406 { |
|
407 iInternalState &= ~EHuiTextureFlagSkinContent; |
|
408 } |
|
409 |
|
410 } |
|
411 |
|
412 |
|
413 EXPORT_C TBool CHuiTexture::IsSkinContent() const |
|
414 { |
|
415 return ((iInternalState & EHuiTextureFlagSkinContent) != 0); |
|
416 } |
|
417 |
|
418 |
|
419 EXPORT_C void CHuiTexture::Reset() |
|
420 { |
|
421 EnableShadow(EFalse); // deletes the shadow textures |
|
422 RemoveAllSegments(); |
|
423 iActiveSegment = 0; |
|
424 iSize = TSize(0, 0); |
|
425 iPlaceholder = NULL; |
|
426 // We're not resetting the texture name here. |
|
427 // this is intentional since the name may be |
|
428 // used to restore the texture content later on |
|
429 } |
|
430 |
|
431 EXPORT_C void CHuiTexture::ResetShadows() |
|
432 { |
|
433 while ( iShadows.Count() ) |
|
434 { |
|
435 delete iShadows[iShadows.Count()-1].iShadowTexture; |
|
436 iShadows.Remove( iShadows.Count()-1); |
|
437 } |
|
438 } |
|
439 |
|
440 |
|
441 EXPORT_C const TDesC& CHuiTexture::ImageFileName() const |
|
442 { |
|
443 return *iImageFileName; |
|
444 } |
|
445 |
|
446 |
|
447 EXPORT_C TBool CHuiTexture::HasContent() const |
|
448 { |
|
449 return (SegmentCount() > 0); |
|
450 } |
|
451 |
|
452 |
|
453 EXPORT_C TInt CHuiTexture::ClearL(const TSize& aSize, const TRgb& aColor) |
|
454 { |
|
455 // Always assign new logical size |
|
456 SetSize(aSize); |
|
457 |
|
458 // if there are no segments, configure them based on the given size! |
|
459 ASSERT(SegmentCount() != 0 || (aSize.iWidth > 0 && aSize.iHeight > 0)); |
|
460 if(SegmentCount() == 0) |
|
461 { |
|
462 SetupSegmentsL(aSize, aSize); |
|
463 } |
|
464 // clear all segments.. |
|
465 for(TInt segment = 0; segment < SegmentCount(); ++segment) |
|
466 { |
|
467 TRAPD(err, SegmentClearL(segment, EFalse, aColor, 0) ); |
|
468 if(err == KErrNoMemory) |
|
469 { |
|
470 HUI_DEBUG2(_L("CHuiTexture::Clear() - Out of memory trying to clear segment %i from \"%S\"."), |
|
471 segment, &ImageFileName()); |
|
472 return err; |
|
473 } |
|
474 else if(err != KErrNone) |
|
475 { |
|
476 HUI_DEBUG1(_L("CHuiTexture::Clear() - SegmentClearL failed with error code %i."), err); |
|
477 return err; |
|
478 } |
|
479 else |
|
480 { |
|
481 // for PC lint |
|
482 } |
|
483 } |
|
484 // succeeded! |
|
485 return KErrNone; |
|
486 } |
|
487 |
|
488 |
|
489 EXPORT_C TInt CHuiTexture::ClearWithAlphaL(const TSize& aSize, const TRgb& aColor, |
|
490 TUint8 aAlpha) |
|
491 { |
|
492 if(Size()==TSize(0,0)) |
|
493 { |
|
494 SetSize(aSize); |
|
495 } |
|
496 // if there are no segments, configure them based on the given size! |
|
497 ASSERT(SegmentCount() != 0 || (aSize.iWidth > 0 && aSize.iHeight > 0)); |
|
498 if(SegmentCount() == 0) |
|
499 { |
|
500 SetupSegmentsL(aSize, aSize); |
|
501 } |
|
502 // clear all segments.. |
|
503 for (TInt segment = 0; segment < SegmentCount(); ++segment) |
|
504 { |
|
505 TRAPD(err, SegmentClearL(segment, ETrue, aColor, aAlpha) ); |
|
506 if(err == KErrNoMemory) |
|
507 { |
|
508 HUI_DEBUG2(_L("CHuiTexture::ClearWithAlpha() - Out of memory trying to clear segment %i from \"%S\"."), |
|
509 segment, &ImageFileName()); |
|
510 return err; |
|
511 } |
|
512 else if(err != KErrNone) |
|
513 { |
|
514 HUI_DEBUG1(_L("CHuiTexture::ClearWithAlpha() - SegmentClearL failed with error code %i."), err); |
|
515 return err; |
|
516 } |
|
517 else |
|
518 { |
|
519 // for PC lint |
|
520 } |
|
521 } |
|
522 // succeeded! |
|
523 return KErrNone; |
|
524 } |
|
525 |
|
526 /** |
|
527 * Set segment data. |
|
528 */ |
|
529 EXPORT_C void CHuiTexture::SetSegment(TInt aSegment, |
|
530 const TSize & aSize, |
|
531 const TPoint & aOffset, |
|
532 const TSize & aTextureSize) |
|
533 { |
|
534 SetSegmentSize(aSegment, aSize); |
|
535 SetSegmentOffset(aSegment, aOffset); |
|
536 SetSegmentTextureSize(aSegment, aTextureSize); |
|
537 |
|
538 // Note: segment name is assigned by the GL specialization class during InitSegment()! |
|
539 } |
|
540 |
|
541 void CHuiTexture::SetPlaceholder(THuiTextureHandle* aPlaceholder) |
|
542 { |
|
543 iPlaceholder = aPlaceholder; |
|
544 } |
|
545 |
|
546 |
|
547 void CHuiTexture::GenerateBlobL(const TSize& aSize) |
|
548 { |
|
549 SetSize(aSize); |
|
550 // calculate parameters for the segments.. |
|
551 SetupSegmentsL(aSize, aSize); |
|
552 |
|
553 ASSERT(SegmentCount()==1); |
|
554 |
|
555 TSize textureSize = SegmentTextureSize(0); |
|
556 TUint8* buffer = new (ELeave) TUint8[ |
|
557 textureSize.iWidth * textureSize.iHeight * 4]; |
|
558 CleanupStack::PushL( buffer ); |
|
559 |
|
560 /** @todo This is too slow. Just load a pregenerated texture. */ |
|
561 |
|
562 TUint8* ptr = buffer; |
|
563 for(TInt y = 0; y < textureSize.iHeight; y++) |
|
564 { |
|
565 for(TInt x = 0; x < textureSize.iWidth; x++, ptr += 4) |
|
566 { |
|
567 ptr[0] = ptr[1] = ptr[2] = 255; |
|
568 |
|
569 TReal32 dx = TReal32(x) - textureSize.iWidth/2.f; |
|
570 TReal32 dy = TReal32(y) - textureSize.iHeight/2.f; |
|
571 TReal32 src = dx * dx + dy * dy; |
|
572 TReal trg = 0; |
|
573 |
|
574 if(dx != 0 || dy != 0) |
|
575 { |
|
576 Math::Sqrt(trg, src); |
|
577 } |
|
578 |
|
579 trg = trg / (textureSize.iWidth/2.0f); |
|
580 if(trg < 0) |
|
581 { |
|
582 trg = 0; |
|
583 } |
|
584 if(trg > 1) |
|
585 { |
|
586 trg = 1; |
|
587 } |
|
588 |
|
589 ptr[3] = (TInt) ((1 - trg) * 255); |
|
590 } |
|
591 } |
|
592 |
|
593 // Upload the solid color buffer. |
|
594 SegmentUploadL(0, EHuiTextureFormatRgba8888, textureSize, buffer); |
|
595 |
|
596 CleanupStack::PopAndDestroy( buffer ); |
|
597 } |
|
598 |
|
599 |
|
600 void CHuiTexture::SetImageFileNameL(const TDesC& aFileName) |
|
601 { |
|
602 delete iImageFileName; |
|
603 iImageFileName = 0; |
|
604 iImageFileName = aFileName.AllocL(); |
|
605 } |
|
606 |
|
607 |
|
608 void CHuiTexture::UploadDirectL(const CFbsBitmap& aBitmap, const CFbsBitmap* aMaskBitmap, THuiTextureUploadFlags aFlags) |
|
609 { |
|
610 // Setup extension parameters |
|
611 CHuiTexture::TExtParams_UploadDirectL params = {aBitmap, aMaskBitmap, aFlags, 0}; |
|
612 CHuiTexture::TExtParams_UploadDirectL* pparams = ¶ms; |
|
613 |
|
614 // Call extension |
|
615 TextureExtension(KHuiTextureExtUid_UploadDirectL, (TAny**)&pparams); // virtual, deriving classes define the actual implementation |
|
616 |
|
617 // Handle return value |
|
618 User::LeaveIfError(pparams->iLeaveCode); |
|
619 } |
|
620 |
|
621 |
|
622 void CHuiTexture::RemoveAllSegments() |
|
623 { |
|
624 // delete segments |
|
625 TInt count = iSegments.Count(); |
|
626 while(count) |
|
627 { |
|
628 count--; |
|
629 HUI_DEBUG1(_L("CHuiTexture::RemoveAllSegments - Removing segment %i"), count); |
|
630 // Deallocate resources associated with segment |
|
631 // NOTE: call to pure virtual method, will not work from the |
|
632 // destructor of this class.. |
|
633 ResetSegment(count); |
|
634 iSegments.Remove(count); |
|
635 } |
|
636 } |
|
637 |
|
638 |
|
639 EXPORT_C TBool CHuiTexture::TextureChanged() const |
|
640 { |
|
641 return iTextureChanged; |
|
642 } |
|
643 |
|
644 |
|
645 EXPORT_C void CHuiTexture::TextureClearChanged() const |
|
646 { |
|
647 iTextureChanged = EFalse; |
|
648 } |
|
649 |
|
650 |
|
651 EXPORT_C void CHuiTexture::Release() |
|
652 { |
|
653 HUI_DEBUG2(_L("CHuiTexture::Release() - Resetting texture 0x%x (\"%S\")."), |
|
654 this, &ImageFileName()); |
|
655 |
|
656 // Reset the content of the texture. |
|
657 Reset(); |
|
658 |
|
659 // Notify observers. |
|
660 for(TInt i = 0; i < iContentObservers.Count(); ++i) |
|
661 { |
|
662 iContentObservers[i].TextureContentReleased(*this); |
|
663 } |
|
664 |
|
665 HUI_PROBE_REPORT_RELEASED |
|
666 } |
|
667 |
|
668 |
|
669 EXPORT_C void CHuiTexture::RestoreL() |
|
670 { |
|
671 // Tell observers to restore the content of this texture. |
|
672 if (iContentObservers.Count() > 0) |
|
673 { |
|
674 for(TInt i = 0; i < iContentObservers.Count(); ++i) |
|
675 { |
|
676 HUI_DEBUG4(_L("CHuiTexture::RestoreL() - Texture 0x%x requesting restore from content observer 0x%x (%i/%i)."), |
|
677 this, &(iContentObservers[i]), i+1, iContentObservers.Count()); |
|
678 iContentObservers[i].RestoreTextureContentL(*this); |
|
679 } |
|
680 HUI_DEBUG1(_L("CHuiTexture::RestoreL() - Texture 0x%x restored!"), this); |
|
681 } |
|
682 else |
|
683 { |
|
684 HUI_DEBUG1(_L("CHuiTexture::RestoreL() - WARNING! This Texture (0x%x) has no content observers. Unable to Restore at this point."), this); |
|
685 } |
|
686 |
|
687 HUI_PROBE_REPORT_RESTORED |
|
688 } |
|
689 |
|
690 EXPORT_C void CHuiTexture::SetPriority( TInt aPriority ) |
|
691 { |
|
692 iPriority = aPriority; |
|
693 } |
|
694 |
|
695 EXPORT_C TInt CHuiTexture::Priority() const |
|
696 { |
|
697 return iPriority; |
|
698 } |
|
699 |
|
700 HUI_SESSION_OBJECT_IMPL_EXPORT(CHuiTexture, ETypeTexture) |
|
701 |
|
702 EXPORT_C void CHuiTexture::TextureExtension(const TUid& /*aExtensionUid*/, TAny** /*aExtensionParameters*/) |
|
703 { |
|
704 |
|
705 } |
|
706 |
|
707 void CHuiTexture::NotifyPreferredSize(const THuiRealSize& aSize) |
|
708 { |
|
709 // Consider size to be (0,0) if either width or height is zero |
|
710 // to avoid unnecessary change notifications. |
|
711 if (HuiUtil::RealCompare(aSize.iHeight,0,0.5) || HuiUtil::RealCompare(aSize.iWidth,0,0.5)) |
|
712 { |
|
713 iPreferredSizes.Append(THuiRealSize(0,0)); |
|
714 } |
|
715 else |
|
716 { |
|
717 iPreferredSizes.Append(aSize); |
|
718 } |
|
719 } |
|
720 |
|
721 void CHuiTexture::ResetAutoSizeCalculation() |
|
722 { |
|
723 iPreferredSizes.Reset(); |
|
724 iCalculatedPreviousAutoSize = iCalculatedAutoSize; |
|
725 } |
|
726 |
|
727 TBool CHuiTexture::IsAutoSizeCalculationEnabled() const |
|
728 { |
|
729 return iAutoSizeCalculationEnabled; |
|
730 } |
|
731 |
|
732 EXPORT_C void CHuiTexture::EnableAutoSizeCalculation(TBool aEnable) |
|
733 { |
|
734 iAutoSizeCalculationEnabled = aEnable; |
|
735 |
|
736 // Initialize everything |
|
737 iPreferredSizes.Reset(); |
|
738 iCalculatedPreviousAutoSize = THuiRealSize(0,0); |
|
739 iCalculatedAutoSize = THuiRealSize(0,0); |
|
740 |
|
741 // Make sure texturemanager is aware of me |
|
742 if (aEnable) |
|
743 { |
|
744 CHuiStatic::Env().TextureManager().EnableAutoSizeCalculation(ETrue); |
|
745 } |
|
746 } |
|
747 |
|
748 TBool CHuiTexture::CalculatedAutoSizeChanged() const |
|
749 { |
|
750 if (!IsAutoSizeCalculationEnabled() || |
|
751 (HUI_ROUND_FLOAT_TO_INT(iCalculatedAutoSize.iWidth) == HUI_ROUND_FLOAT_TO_INT(iCalculatedPreviousAutoSize.iWidth) && |
|
752 HUI_ROUND_FLOAT_TO_INT(iCalculatedAutoSize.iHeight) == HUI_ROUND_FLOAT_TO_INT(iCalculatedPreviousAutoSize.iHeight))) |
|
753 { |
|
754 return EFalse; |
|
755 } |
|
756 else |
|
757 { |
|
758 return ETrue; |
|
759 } |
|
760 } |
|
761 |
|
762 THuiRealSize CHuiTexture::CalculateAutoSize() |
|
763 { |
|
764 // If only one size, retun it. |
|
765 if (iPreferredSizes.Count() == 1) |
|
766 { |
|
767 iCalculatedAutoSize = iPreferredSizes[0]; |
|
768 } |
|
769 else |
|
770 { |
|
771 // If more sizes reported, then try to report largest one. |
|
772 if (iPreferredSizes.Count()) |
|
773 { |
|
774 iCalculatedAutoSize = iPreferredSizes[0]; |
|
775 TInt autoSizeArea = iCalculatedAutoSize.iWidth * iCalculatedAutoSize.iHeight; |
|
776 for (TInt i=0; i<iPreferredSizes.Count();i++) |
|
777 { |
|
778 if ((iPreferredSizes[i].iWidth * iPreferredSizes[i].iHeight) > autoSizeArea) |
|
779 { |
|
780 iCalculatedAutoSize = iPreferredSizes[i]; |
|
781 autoSizeArea = iPreferredSizes[i].iWidth * iPreferredSizes[i].iHeight; |
|
782 } |
|
783 } |
|
784 } |
|
785 } |
|
786 |
|
787 return iCalculatedAutoSize; |
|
788 } |
|
789 |
|
790 |
|
791 EXPORT_C void CHuiTexture::SetAutoSizeParams(const THuiTextureAutoSizeParams& aParams) |
|
792 { |
|
793 iAutoSizeParams = aParams; |
|
794 } |
|
795 |
|
796 EXPORT_C THuiTextureAutoSizeParams CHuiTexture::AutoSizeParams() const |
|
797 { |
|
798 return iAutoSizeParams; |
|
799 } |
|
800 |
|
801 EXPORT_C void CHuiTexture::SetTextureChanged(TBool aChanged) |
|
802 { |
|
803 if (aChanged && !iTextureChanged) |
|
804 { |
|
805 CHuiEnv& env = CHuiStatic::Env(); |
|
806 env.TextureManager().SetHasChangedTextures(); |
|
807 env.ContinueRefresh(); |
|
808 } |
|
809 |
|
810 iTextureChanged = aChanged; |
|
811 } |
|
812 |
|
813 EXPORT_C void CHuiTexture::SetNvgContent(TBool aNvgContent) |
|
814 { |
|
815 if(aNvgContent) |
|
816 { |
|
817 iInternalState |= EHuiTextureFlagNvgContent; |
|
818 } |
|
819 else |
|
820 { |
|
821 iInternalState &= ~EHuiTextureFlagNvgContent; |
|
822 } |
|
823 } |
|
824 |
|
825 EXPORT_C TBool CHuiTexture::IsNvgContent() const |
|
826 { |
|
827 return ((iInternalState & EHuiTextureFlagNvgContent) != 0); |
|
828 } |
|
829 |
|
830 |
|
831 // End of file |