|
1 /* |
|
2 * Copyright (c) 2006-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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "HuiVg10TextureManager.h" // Class definition |
|
21 #include "HuiVg10TextureProcessor.h" |
|
22 |
|
23 |
|
24 CHuiVg10TextureManager* CHuiVg10TextureManager::NewL(CHuiEnv& aEnv) |
|
25 { |
|
26 CHuiVg10TextureManager* self = CHuiVg10TextureManager::NewLC(aEnv); |
|
27 CleanupStack::Pop(self); |
|
28 return self; |
|
29 } |
|
30 |
|
31 |
|
32 CHuiVg10TextureManager* CHuiVg10TextureManager::NewLC(CHuiEnv& aEnv) |
|
33 { |
|
34 CHuiVg10TextureManager* self = new (ELeave) CHuiVg10TextureManager(aEnv); |
|
35 CleanupStack::PushL(self); |
|
36 self->ConstructL(); |
|
37 return self; |
|
38 } |
|
39 |
|
40 |
|
41 CHuiVg10TextureManager::CHuiVg10TextureManager(CHuiEnv& aEnv) |
|
42 : CHuiTextureManager(aEnv) |
|
43 { |
|
44 } |
|
45 |
|
46 |
|
47 void CHuiVg10TextureManager::ConstructL() |
|
48 { |
|
49 CHuiTextureManager::BaseConstructL(); |
|
50 |
|
51 // Create a texture processor. |
|
52 CHuiVg10TextureProcessor* proc = CHuiVg10TextureProcessor::NewL(Env()); |
|
53 SetProcessor(proc); // ownership to base class |
|
54 |
|
55 iBitmap16MA = new (ELeave) CFbsBitmap; |
|
56 iBitmap16MA->Create(TSize(1,1), EColor16MA); |
|
57 iBitmap16MU = new (ELeave) CFbsBitmap; |
|
58 iBitmap16MU->Create(TSize(1,1), EColor16MU); |
|
59 iBitmap64K = new (ELeave) CFbsBitmap; |
|
60 iBitmap64K->Create(TSize(1,1), EColor64K); |
|
61 iBitmap256Gray = new (ELeave) CFbsBitmap; |
|
62 iBitmap256Gray->Create(TSize(1,1), EGray256); |
|
63 |
|
64 iBitmapDevice16MA = CFbsBitmapDevice::NewL(iBitmap16MA); |
|
65 iBitmapDevice16MU = CFbsBitmapDevice::NewL(iBitmap16MU); |
|
66 iBitmapDevice64K = CFbsBitmapDevice::NewL(iBitmap64K); |
|
67 iBitmapDevice256Gray = CFbsBitmapDevice::NewL(iBitmap256Gray); |
|
68 } |
|
69 |
|
70 |
|
71 CHuiVg10TextureManager::~CHuiVg10TextureManager() |
|
72 { |
|
73 delete iBitmap16MA; |
|
74 delete iBitmap16MU; |
|
75 delete iBitmap64K; |
|
76 delete iBitmap256Gray; |
|
77 delete iBitmapDevice16MA; |
|
78 delete iBitmapDevice16MU; |
|
79 delete iBitmapDevice64K; |
|
80 delete iBitmapDevice256Gray; |
|
81 delete iBitGc16MA; |
|
82 delete iBitGc16MU; |
|
83 delete iBitGc64K; |
|
84 delete iBitGc256Gray; |
|
85 } |
|
86 |
|
87 CFbsBitmap& CHuiVg10TextureManager::ConvertBitmapL(const CFbsBitmap& aBitmap, TDisplayMode aDisplayMode, TBitmapCopyMode aCopyMode, TSize aNewSize) |
|
88 { |
|
89 TSize newSize = aBitmap.SizeInPixels(); |
|
90 if (aNewSize != TSize(0,0)) |
|
91 { |
|
92 newSize = aNewSize; |
|
93 } |
|
94 |
|
95 // Select the correct Colormode bitmap & device |
|
96 CFbsBitmap* bitmap = NULL; |
|
97 CFbsBitmapDevice* bitmapDevice = NULL; |
|
98 CFbsBitGc* bitGc = NULL; |
|
99 // This is needed for storing the possibly recreated bitGc to a member variable |
|
100 CFbsBitGc** bitGcMemberPtr = NULL; |
|
101 switch(aDisplayMode) |
|
102 { |
|
103 case EColor16MA: |
|
104 bitmap = iBitmap16MA; |
|
105 bitmapDevice = iBitmapDevice16MA; |
|
106 bitGc = iBitGc16MA; |
|
107 bitGcMemberPtr = &iBitGc16MA; |
|
108 break; |
|
109 case EColor16MU: |
|
110 bitmap = iBitmap16MU; |
|
111 bitmapDevice = iBitmapDevice16MU; |
|
112 bitGc = iBitGc16MU; |
|
113 bitGcMemberPtr = &iBitGc16MU; |
|
114 break; |
|
115 case EColor64K: |
|
116 bitmap = iBitmap64K; |
|
117 bitmapDevice = iBitmapDevice64K; |
|
118 bitGc = iBitGc64K; |
|
119 bitGcMemberPtr = &iBitGc64K; |
|
120 break; |
|
121 case EGray256: |
|
122 bitmap = iBitmap256Gray; |
|
123 bitmapDevice = iBitmapDevice256Gray; |
|
124 bitGc = iBitGc256Gray; |
|
125 bitGcMemberPtr = &iBitGc256Gray; |
|
126 break; |
|
127 default: |
|
128 // Not supported! Implement more cases if needed, otherwise this'll leave |
|
129 User::Leave(KErrNotSupported); |
|
130 break; |
|
131 } |
|
132 |
|
133 // No conversion required? |
|
134 if ( aCopyMode == EAllowDuplication && aBitmap.DisplayMode() == aDisplayMode && |
|
135 !aBitmap.IsCompressedInRAM() && newSize == aBitmap.SizeInPixels() ) |
|
136 { |
|
137 // If the bitmap's color mode was already correct & sizes matched, |
|
138 // and bmp isn't rombitmap, no conversion was required and we can return |
|
139 // the same bitmap that was given as a parameter |
|
140 CFbsBitmap& bmp = const_cast<CFbsBitmap&>(aBitmap); |
|
141 return bmp; |
|
142 } |
|
143 |
|
144 // If needed, Resize the bitmap & bitmapDevice to correct dimensions, |
|
145 // instead of recreating them always |
|
146 if (newSize != bitmap->SizeInPixels() || !bitGc) |
|
147 { |
|
148 // Try to resize the bitmap & bmpDevice, leave, if e.g. out of memory |
|
149 User::LeaveIfError(bitmap->Resize(newSize)); |
|
150 |
|
151 delete bitGc; |
|
152 bitGc = 0; |
|
153 *bitGcMemberPtr = 0; |
|
154 |
|
155 User::LeaveIfError(bitmapDevice->Resize(newSize)); |
|
156 |
|
157 // The BitGc has to be created every time separately |
|
158 User::LeaveIfError(bitmapDevice->CreateContext(bitGc)); |
|
159 // Store the newly created context to a correct member variable |
|
160 *bitGcMemberPtr = bitGc; |
|
161 } |
|
162 |
|
163 if (aDisplayMode == EColor16MA && bitGc) |
|
164 { |
|
165 bitGc->SetDrawMode(CGraphicsContext::EDrawModeWriteAlpha); |
|
166 } |
|
167 |
|
168 if (bitGc) |
|
169 { |
|
170 bitGc->BitBlt(TPoint(0, 0), &aBitmap); |
|
171 } |
|
172 return *bitmap; |
|
173 } |
|
174 |
|
175 // End of file |
|
176 |