|
1 // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "GraphicsAccelerator.h" |
|
17 |
|
18 // Windows headers... |
|
19 #define UNICODE |
|
20 #pragma warning( disable : 4201 ) |
|
21 #define WIN32_LEAN_AND_MEAN |
|
22 #define NOSERVICE |
|
23 #include <windows.h> |
|
24 #include <windowsx.h> |
|
25 #pragma warning( default : 4201 ) |
|
26 |
|
27 #include <bitdraw.h> |
|
28 #include "_WININC.H" |
|
29 |
|
30 /** Fills a structure with data which describes the basic details of this bitmap. |
|
31 |
|
32 @param aInfo Bitmap information structure to fill with the details of this bitmap. |
|
33 @return KErrNone if successful, KErrBadHandle if a value has not been assigned to iHandle. */ |
|
34 EXPORT_C TInt RHardwareBitmap::GetInfo(TAcceleratedBitmapInfo& aInfo) const |
|
35 { |
|
36 if(!iHandle) |
|
37 return(KErrBadHandle); |
|
38 |
|
39 // -1 or less refers to the screen. It is the (screen number + 1) actually with "-" sign. |
|
40 if(iHandle <= -1) |
|
41 { |
|
42 RWindows* window = ::WindowHandler(-iHandle - 1); |
|
43 aInfo.iDisplayMode = window->iDisplayMode; |
|
44 aInfo.iAddress = (TUint8*)(window->EpocBitmapBits()); |
|
45 aInfo.iSize = window->iEpocBitmapSize; |
|
46 aInfo.iLinePitch = window->iEpocBitmapLinePitch; |
|
47 aInfo.iPhysicalAddress = 0; |
|
48 switch(aInfo.iDisplayMode) |
|
49 { |
|
50 case ENone: |
|
51 aInfo.iPixelShift = -1; |
|
52 break; |
|
53 case EGray2: |
|
54 aInfo.iPixelShift = 0; |
|
55 break; |
|
56 case EGray4: |
|
57 aInfo.iPixelShift = 1; |
|
58 break; |
|
59 case EGray16: |
|
60 case EColor16: |
|
61 aInfo.iPixelShift = 2; |
|
62 break; |
|
63 case EGray256: |
|
64 case EColor256: |
|
65 aInfo.iPixelShift = 3; |
|
66 break; |
|
67 case EColor4K: |
|
68 case EColor64K: |
|
69 aInfo.iPixelShift = 4; |
|
70 break; |
|
71 case EColor16M: |
|
72 case ERgb: |
|
73 case EColor16MU: |
|
74 aInfo.iPixelShift = 5; |
|
75 break; |
|
76 } |
|
77 } |
|
78 else |
|
79 aInfo = *(TAcceleratedBitmapInfo*)iHandle; // iHandle is really a pointer to a TAcceleratedBitmapInfo |
|
80 |
|
81 return(KErrNone); |
|
82 } |
|
83 |
|
84 /** |
|
85 This method sets the value of iHandle data member. |
|
86 When the iHandle's value is positive - the it is the bitmap address in the memory. |
|
87 When the iHandle's value is negative - it is a screen number reference: |
|
88 "-1" - screen 0, "-2" - screen 1, "-3" - screen 2, ... |
|
89 All that means: negative iHandle values describe the RHardwareBitmap object as a screen |
|
90 bitmap, the screen number can be calculated from iHandle's value. |
|
91 Positive iHandle values describe RHardwareBitmap object as an in-memory bitmap. |
|
92 By default iHandle is initialized with 0, which means - invalid handle and uninitialized |
|
93 RHardwareBitmap object. |
|
94 @param aScreenNo Screen number. |
|
95 @return KErrNone |
|
96 */ |
|
97 EXPORT_C TInt RHardwareBitmap::SetAsScreenReference(TInt aScreenNo) |
|
98 { |
|
99 iHandle = aScreenNo; |
|
100 return KErrNone; |
|
101 } |
|
102 |
|
103 EXPORT_C TInt RHardwareBitmap::Create(TDisplayMode aDisplayMode, TSize aSize, TUid /*aCreatorUid*/) |
|
104 { |
|
105 // Make line pitch different from normal bitmaps, useful for testing purposes. |
|
106 TInt hwWidth = ((aSize.iWidth + 15) / 16) * 16; |
|
107 |
|
108 TInt linePitch; |
|
109 |
|
110 switch(aDisplayMode) |
|
111 { |
|
112 case EColor256: |
|
113 case EGray256: |
|
114 linePitch = hwWidth; |
|
115 break; |
|
116 case EColor64K: |
|
117 case EColor4K: |
|
118 linePitch = hwWidth * 2; |
|
119 break; |
|
120 case EColor16M: |
|
121 linePitch = (((hwWidth * 3) + 11) / 12) * 12; // Multiples of 12 bytes! |
|
122 break; |
|
123 case ERgb: |
|
124 case EColor16MU: |
|
125 linePitch = hwWidth * 4; |
|
126 break; |
|
127 default: |
|
128 return(KErrNotSupported); |
|
129 } |
|
130 |
|
131 TInt memSize = sizeof(TAcceleratedBitmapInfo)+linePitch*aSize.iHeight; |
|
132 |
|
133 TAcceleratedBitmapInfo* bitmap = (TAcceleratedBitmapInfo*)GlobalAllocPtr(GMEM_FIXED,memSize); |
|
134 |
|
135 if(!bitmap) |
|
136 return(KErrNoMemory); |
|
137 |
|
138 bitmap->iDisplayMode = aDisplayMode; |
|
139 bitmap->iAddress = (TUint8*)(bitmap+1); |
|
140 bitmap->iSize = aSize; |
|
141 bitmap->iLinePitch = linePitch; |
|
142 switch(aDisplayMode) |
|
143 { |
|
144 case ENone: |
|
145 bitmap->iPixelShift = -1; |
|
146 break; |
|
147 case EGray2: |
|
148 bitmap->iPixelShift = 0; |
|
149 break; |
|
150 case EGray4: |
|
151 bitmap->iPixelShift = 1; |
|
152 break; |
|
153 case EGray16: |
|
154 case EColor16: |
|
155 bitmap->iPixelShift = 2; |
|
156 break; |
|
157 case EGray256: |
|
158 case EColor256: |
|
159 bitmap->iPixelShift = 3; |
|
160 break; |
|
161 case EColor4K: |
|
162 case EColor64K: |
|
163 bitmap->iPixelShift = 4; |
|
164 break; |
|
165 case EColor16M: |
|
166 case ERgb: |
|
167 case EColor16MU: |
|
168 bitmap->iPixelShift = 5; |
|
169 break; |
|
170 } |
|
171 bitmap->iPhysicalAddress = 0; |
|
172 |
|
173 iHandle = (TInt)bitmap; |
|
174 |
|
175 return(KErrNone); |
|
176 } |
|
177 |
|
178 EXPORT_C void RHardwareBitmap::Destroy() |
|
179 { |
|
180 GlobalFreePtr((void*)iHandle); |
|
181 } |
|
182 |