|
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 "Accelhard.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 "_WININC.H" |
|
28 |
|
29 LOCAL_D const TGraphicsAcceleratorCaps HardwareAcceleratorCapabilities = |
|
30 { |
|
31 sizeof(TGraphicsAcceleratorCaps), //TInt iStructureSize; // The size of this class |
|
32 1, //TInt iVersion; // == 1 to specify current API |
|
33 0, //Tint iVendorUid; // Optional ID |
|
34 1<<EColor256, //iDisplayModes; |
|
35 0, //iClipping; |
|
36 TGraphicsAcceleratorCaps::EMaskBitmapMatchingDisplayMode, //iMaskType; |
|
37 0, //iTransparency; |
|
38 0, //iAlphaChannel; |
|
39 TGraphicsAcceleratorCaps::EAlphaBitmapGray256, //iAlphaBitmap; |
|
40 (TUint)TGraphicsAcceleratorCaps::EPatternSizeAny, //iPatternSizes; |
|
41 TGraphicsAcceleratorCaps::EPatternMatchingDisplayMode, //iPattern; |
|
42 0, //iPolygon; |
|
43 {TGraphicsAcceleratorCaps::EOrientationCapNormal,0,0,0} //iReserved[0] is used for supported orientations, iReserved[1]-iReserved[3] are reserved; |
|
44 }; |
|
45 |
|
46 // |
|
47 // CHardwareGraphicsAccelerator |
|
48 // |
|
49 |
|
50 /** |
|
51 Allocates and constructs an instance of a derived class and initialises its |
|
52 capabilities. |
|
53 |
|
54 @param aBitmap The hardware bitmap for the accelerator to draw to. |
|
55 @return Pointer to the initialised graphics accelerator object. |
|
56 @see TGraphicsAcceleratorCaps::iDisplayModes |
|
57 @leave KErrNoMemory There is no memory to allocate the graphics accelerator |
|
58 KErrNotSupported There is no graphics accelerator supporting the display mode given by the bitmap parameter |
|
59 */ |
|
60 EXPORT_C CHardwareGraphicsAccelerator* CHardwareGraphicsAccelerator::NewL(RHardwareBitmap aBitmap) |
|
61 { |
|
62 TAcceleratedBitmapInfo hwBitmapInfo; |
|
63 aBitmap.GetInfo(hwBitmapInfo); |
|
64 |
|
65 switch(hwBitmapInfo.iDisplayMode) |
|
66 { |
|
67 case EColor256: |
|
68 return CColor256HardwareGraphicsAccelerator::NewL(aBitmap); |
|
69 default: |
|
70 User::Leave(KErrNotSupported); |
|
71 return NULL; |
|
72 } |
|
73 } |
|
74 |
|
75 /** |
|
76 Gets the generic capabilities of the accelerator, including which display modes |
|
77 are supported for the bitmap passed to NewL(). |
|
78 |
|
79 Generic capabilities apply to all hardware graphics accelerators on the device. |
|
80 The function is static, so it can be used to find out the capabilities of |
|
81 graphics accelerators before deciding on whether or not to create one. |
|
82 |
|
83 The CGraphicsAccelerator::Capabilities() function provides information about |
|
84 the capabilities of a particular graphics accelerator. |
|
85 |
|
86 As capabilities may vary depending on the display mode of a bitmap, this method |
|
87 should indicate as supported any features which are only available in some |
|
88 display modes. |
|
89 @return Generic capabilities for hardware graphics accelerators. |
|
90 */ |
|
91 EXPORT_C const TGraphicsAcceleratorCaps* CHardwareGraphicsAccelerator::GenericCapabilities() |
|
92 { |
|
93 return &HardwareAcceleratorCapabilities; |
|
94 } |
|
95 |
|
96 // |
|
97 // CColor256HardwareGraphicsAccelerator |
|
98 // |
|
99 |
|
100 CColor256HardwareGraphicsAccelerator* CColor256HardwareGraphicsAccelerator::NewL(RHardwareBitmap aBitmap) |
|
101 { |
|
102 CColor256HardwareGraphicsAccelerator* self = new (ELeave) CColor256HardwareGraphicsAccelerator; |
|
103 CleanupStack::PushL(self); |
|
104 self->ConstructL(aBitmap); |
|
105 CleanupStack::Pop(); |
|
106 return(self); |
|
107 } |
|
108 |
|
109 void CColor256HardwareGraphicsAccelerator::ConstructL(RHardwareBitmap aBitmap) |
|
110 { |
|
111 CHardwareGraphicsAcceleratorBase::ConstructL(aBitmap); |
|
112 iCaps = &HardwareAcceleratorCapabilities; // We only do Color256 |
|
113 //Some explanations about "-aBitmap.iHandle - 1" expression. |
|
114 //Before "Multiple screens" update aBitmap.iHandle with value -1 meant that the related |
|
115 //RHardwareBitmap object is a screen bitmap. Positive aBitmap.iHandle values - it was |
|
116 //an in-memory RHardwareBitmap object. |
|
117 //After "Multiple screens" update, the meaning of aBitmap.iHandle's value is: |
|
118 // - Positive value - in-memory hardware bitmap; |
|
119 // - Negative value - screen number: "-1" - screen 0, "-2" - screen 1, "-3" - screen 2, ...; |
|
120 if (aBitmap.iHandle < 0) |
|
121 { |
|
122 iScreenNo = -aBitmap.iHandle - 1; |
|
123 } |
|
124 } |
|
125 |
|
126 TUint32 CColor256HardwareGraphicsAccelerator::FillValue(TRgb aColor) |
|
127 { |
|
128 TUint32 value = aColor.Color256(); |
|
129 value |= value<<8; |
|
130 value |= value<<16; |
|
131 return value; |
|
132 } |
|
133 |
|
134 void CColor256HardwareGraphicsAccelerator::DoUpdateScreen(const TRect& aRect) |
|
135 { |
|
136 TInt lx = aRect.iTl.iX & ~3; |
|
137 TInt rx = (aRect.iBr.iX + 3) & ~3; |
|
138 |
|
139 TUint8* srcePtr = iBitmapInfo.iAddress+iBitmapInfo.iLinePitch*aRect.iTl.iY+lx; |
|
140 TUint8* srcePtrLimit = srcePtr + rx - lx; |
|
141 |
|
142 TInt linePitch = iBitmapInfo.iLinePitch; |
|
143 |
|
144 RWindows* window = ::WindowHandler(iScreenNo); |
|
145 for(TInt row = aRect.iTl.iY; row < aRect.iBr.iY; row++) |
|
146 { |
|
147 TUint8* tempSrcePtr = srcePtr; |
|
148 TUint8* destPixel = window->PixelAddress(lx,row); |
|
149 TRgb pixelColor; |
|
150 |
|
151 if(window->iPalette) |
|
152 { |
|
153 while (tempSrcePtr < srcePtrLimit) |
|
154 { |
|
155 pixelColor = window->iPalette[*tempSrcePtr++]; |
|
156 destPixel[0] = TUint8(pixelColor.Blue()); |
|
157 destPixel[1] = TUint8(pixelColor.Green()); |
|
158 destPixel[2] = TUint8(pixelColor.Red()); |
|
159 destPixel += 3; |
|
160 } |
|
161 } |
|
162 else |
|
163 { |
|
164 while (tempSrcePtr < srcePtrLimit) |
|
165 { |
|
166 pixelColor = TRgb::Color256(*tempSrcePtr++); |
|
167 destPixel[0] = TUint8(pixelColor.Blue()); |
|
168 destPixel[1] = TUint8(pixelColor.Green()); |
|
169 destPixel[2] = TUint8(pixelColor.Red()); |
|
170 destPixel += 3; |
|
171 } |
|
172 } |
|
173 |
|
174 srcePtr += linePitch; |
|
175 srcePtrLimit += linePitch; |
|
176 } |
|
177 |
|
178 RRegion region; |
|
179 region.AddRect(aRect); |
|
180 window->Update(region,window->iEpocBitmapSize); |
|
181 region.Close(); |
|
182 } |
|
183 |
|
184 void CColor256HardwareGraphicsAccelerator::DoFillRect(const TRect& aRect,TUint32 aFillValue) |
|
185 { |
|
186 //Lock(); |
|
187 |
|
188 TUint32* ptr = (TUint32*)iBitmapInfo.iAddress; |
|
189 TUint32* ptrLimit; |
|
190 TUint32 leftMask; |
|
191 TUint32 rightMask; |
|
192 TInt ptrPitch; |
|
193 TInt pitch; |
|
194 TInt height; |
|
195 |
|
196 { |
|
197 TInt yStart = aRect.iTl.iY; |
|
198 TInt yEnd = aRect.iBr.iY; |
|
199 |
|
200 if(yStart<0) |
|
201 goto error; |
|
202 if(yStart>=yEnd) |
|
203 goto error; |
|
204 if(yEnd>iBitmapInfo.iSize.iHeight) |
|
205 goto error; |
|
206 |
|
207 ptr = (TUint32*)((TUint8*)ptr+yStart*iBitmapInfo.iLinePitch); |
|
208 height = yEnd-yStart; |
|
209 } |
|
210 |
|
211 { |
|
212 TInt xStart = aRect.iTl.iX; |
|
213 TInt xEnd = aRect.iBr.iX; |
|
214 |
|
215 if(xStart<0) |
|
216 goto error; |
|
217 if(xStart>=xEnd) |
|
218 goto error; |
|
219 if(xEnd>iBitmapInfo.iSize.iWidth) |
|
220 goto error; |
|
221 |
|
222 xStart <<= iBitmapInfo.iPixelShift; |
|
223 xEnd <<= iBitmapInfo.iPixelShift; |
|
224 |
|
225 leftMask = ~((1<<(xStart&0x1F))-1); |
|
226 rightMask = (1<<(xEnd&0x1F))-1; |
|
227 |
|
228 xStart >>= 5; |
|
229 xEnd = (xEnd-1)>>5; |
|
230 ptrLimit = ptr+xEnd; |
|
231 ptr += xStart; |
|
232 |
|
233 pitch = iBitmapInfo.iLinePitch; |
|
234 ptrPitch = pitch-((TInt)ptrLimit-(TInt)ptr); |
|
235 } |
|
236 |
|
237 if((ptr==ptrLimit) && (leftMask!=0xFFFFFFFF)) // all pixels in a line are in the same word |
|
238 { |
|
239 if((leftMask != 0) && (rightMask !=0)) |
|
240 leftMask &= rightMask; |
|
241 else if(rightMask != 0) |
|
242 leftMask = rightMask; |
|
243 |
|
244 aFillValue &= leftMask; |
|
245 do |
|
246 { |
|
247 TUint32 pixels = *ptr; |
|
248 pixels &= ~ leftMask; |
|
249 pixels |= aFillValue; |
|
250 *(ptr) = pixels; |
|
251 ptr = (TUint32*)((TUint8*)ptr+ptrPitch); |
|
252 } |
|
253 while(--height); |
|
254 } |
|
255 else if((leftMask==0xFFFFFFFF)&&(rightMask==0)) // all pixels in a line fit into whole words |
|
256 { |
|
257 do |
|
258 { |
|
259 while(ptr<ptrLimit) |
|
260 *(ptr++) = aFillValue; |
|
261 *ptr = aFillValue; |
|
262 |
|
263 ptr = (TUint32*)((TUint8*)ptr+ptrPitch); |
|
264 ptrLimit = (TUint32*)((TUint8*)ptrLimit+pitch); |
|
265 } |
|
266 while(--height); |
|
267 } |
|
268 else if(leftMask==0xFFFFFFFF) // first pixel starts on a word boundary but last doesn't |
|
269 { |
|
270 do |
|
271 { |
|
272 while(ptr<ptrLimit) |
|
273 *(ptr++) = aFillValue; |
|
274 |
|
275 TUint32 pixels = *ptr; |
|
276 pixels &= ~ rightMask; |
|
277 pixels |= aFillValue&rightMask; |
|
278 *ptr = pixels; |
|
279 |
|
280 ptr = (TUint32*)((TUint8*)ptr+ptrPitch); |
|
281 ptrLimit = (TUint32*)((TUint8*)ptrLimit+pitch); |
|
282 } |
|
283 while(--height); |
|
284 } |
|
285 else if(rightMask==0) // last pixel lies on a word boundary but first doesn't |
|
286 { |
|
287 do |
|
288 { |
|
289 TUint32 pixels = *ptr; |
|
290 pixels &= ~ leftMask; |
|
291 pixels |= aFillValue&leftMask; |
|
292 *(ptr++) = pixels; |
|
293 |
|
294 while(ptr<ptrLimit) |
|
295 *(ptr++) = aFillValue; |
|
296 *ptr = aFillValue; |
|
297 |
|
298 ptr = (TUint32*)((TUint8*)ptr+ptrPitch); |
|
299 ptrLimit = (TUint32*)((TUint8*)ptrLimit+pitch); |
|
300 } |
|
301 while(--height); |
|
302 } |
|
303 else // both last and first pixels in a line don't lie on a word boundary |
|
304 { |
|
305 do |
|
306 { |
|
307 TUint32 pixels = *ptr; |
|
308 pixels &= ~ leftMask; |
|
309 pixels |= aFillValue&leftMask; |
|
310 *(ptr++) = pixels; |
|
311 |
|
312 while(ptr<ptrLimit) |
|
313 *(ptr++) = aFillValue; |
|
314 |
|
315 pixels = *ptr; |
|
316 pixels &= ~ rightMask; |
|
317 pixels |= aFillValue&rightMask; |
|
318 *ptr = pixels; |
|
319 |
|
320 ptr = (TUint32*)((TUint8*)ptr+ptrPitch); |
|
321 ptrLimit = (TUint32*)((TUint8*)ptrLimit+pitch); |
|
322 } |
|
323 while(--height); |
|
324 } |
|
325 |
|
326 //Unlock(); |
|
327 return; |
|
328 error: |
|
329 // Unlock(); |
|
330 GraphicsAcceleratorPanic(EGraphicsAcceleratorAttemptedDrawOutsideBitmap); |
|
331 } |
|
332 |
|
333 TInt CColor256HardwareGraphicsAccelerator::DoFilledRectWithPattern(const TRect& aRect,TGopFillPattern aPattern) |
|
334 { |
|
335 if(aPattern.iBitmap.Type() != TAcceleratedBitmapSpec::EHardwareBitmap) |
|
336 return KErrNotSupported; |
|
337 |
|
338 TInt handle = aPattern.iBitmap.Handle(); |
|
339 RHardwareBitmap aBitmap(handle); |
|
340 |
|
341 TAcceleratedBitmapInfo patternBitmapInfo; |
|
342 aBitmap.GetInfo(patternBitmapInfo); |
|
343 |
|
344 if(patternBitmapInfo.iDisplayMode != EColor256) |
|
345 return KErrNotSupported; |
|
346 |
|
347 //point to the first pixel of a row |
|
348 TUint8* ptrPattern8 = (TUint8*)patternBitmapInfo.iAddress; |
|
349 //point to the last pixels of a row |
|
350 TUint8* ptrLimitPattern8 = ptrPattern8 + (patternBitmapInfo.iSize.iWidth - 1); |
|
351 //current pixel to copy |
|
352 TUint8* ptrCurrentPixelPattern8 = ptrPattern8; |
|
353 TInt pitchPattern = patternBitmapInfo.iLinePitch; |
|
354 //point to the last pixel of the pattern bitmap |
|
355 TUint8* ptrEndPattern8 = ptrLimitPattern8 + pitchPattern * (patternBitmapInfo.iSize.iHeight - 1); |
|
356 TInt xOffsetPattern = 0; |
|
357 TInt difOrigins = 0; |
|
358 |
|
359 TUint8* ptr8 = (TUint8*)iBitmapInfo.iAddress; |
|
360 TUint8* ptrLimit8; |
|
361 TInt ptrPitch; |
|
362 TInt pitch; |
|
363 TInt height; |
|
364 |
|
365 { |
|
366 TInt yStart = aRect.iTl.iY; |
|
367 TInt yEnd = aRect.iBr.iY; |
|
368 |
|
369 if(yStart<0) |
|
370 goto error; |
|
371 if(yStart>=yEnd) |
|
372 goto error; |
|
373 if(yEnd>iBitmapInfo.iSize.iHeight) |
|
374 goto error; |
|
375 |
|
376 ptr8 = ptr8+yStart*iBitmapInfo.iLinePitch; |
|
377 height = yEnd-yStart; |
|
378 } |
|
379 |
|
380 { |
|
381 TInt xStart = aRect.iTl.iX; |
|
382 TInt xEnd = aRect.iBr.iX; |
|
383 |
|
384 if(xStart<0) |
|
385 goto error; |
|
386 if(xStart>=xEnd) |
|
387 goto error; |
|
388 if(xEnd>iBitmapInfo.iSize.iWidth) |
|
389 goto error; |
|
390 |
|
391 ptrLimit8 = ptr8 + xEnd; |
|
392 ptr8 += xStart; |
|
393 |
|
394 pitch = iBitmapInfo.iLinePitch; |
|
395 ptrPitch = pitch-((TInt)ptrLimit8-(TInt)ptr8); |
|
396 } |
|
397 |
|
398 difOrigins = (aRect.iTl.iX - aPattern.iOrigin.iX) % patternBitmapInfo.iSize.iWidth; |
|
399 if(difOrigins < 0) |
|
400 { |
|
401 ptrCurrentPixelPattern8 = ptrLimitPattern8 + difOrigins + 1; |
|
402 xOffsetPattern = patternBitmapInfo.iSize.iWidth + difOrigins; |
|
403 } |
|
404 if(difOrigins > 0) |
|
405 { |
|
406 ptrCurrentPixelPattern8 = ptrPattern8 + difOrigins; |
|
407 xOffsetPattern = difOrigins; |
|
408 } |
|
409 |
|
410 difOrigins = (aRect.iTl.iY - aPattern.iOrigin.iY) % patternBitmapInfo.iSize.iHeight; |
|
411 if(difOrigins < 0) |
|
412 { |
|
413 TInt totalPitch = pitchPattern*(patternBitmapInfo.iSize.iHeight + difOrigins); |
|
414 ptrCurrentPixelPattern8 += totalPitch; |
|
415 ptrPattern8 += totalPitch ; |
|
416 ptrLimitPattern8 += totalPitch; |
|
417 } |
|
418 if(difOrigins > 0) |
|
419 { |
|
420 TInt totalPitch = (pitchPattern * (difOrigins)); |
|
421 ptrCurrentPixelPattern8 += totalPitch; |
|
422 ptrPattern8 += totalPitch; |
|
423 ptrLimitPattern8 += totalPitch; |
|
424 } |
|
425 |
|
426 do |
|
427 { |
|
428 while(ptr8<ptrLimit8) |
|
429 { |
|
430 if(ptrCurrentPixelPattern8 == ptrLimitPattern8) |
|
431 { |
|
432 *ptr8 = *ptrCurrentPixelPattern8; |
|
433 ptr8++; |
|
434 ptrCurrentPixelPattern8 = ptrPattern8; |
|
435 } |
|
436 else |
|
437 *(ptr8++) = *(ptrCurrentPixelPattern8++); |
|
438 } |
|
439 //check if on the last row |
|
440 if(ptrLimitPattern8 == ptrEndPattern8) |
|
441 { |
|
442 ptrPattern8 = (TUint8*)patternBitmapInfo.iAddress; |
|
443 ptrLimitPattern8 = ptrPattern8 + patternBitmapInfo.iSize.iWidth - 1; |
|
444 ptrCurrentPixelPattern8 = ptrPattern8 + xOffsetPattern; |
|
445 } |
|
446 else |
|
447 { |
|
448 ptrPattern8 += pitchPattern; |
|
449 ptrLimitPattern8 += pitchPattern; |
|
450 ptrCurrentPixelPattern8 = ptrPattern8 + xOffsetPattern; |
|
451 } |
|
452 |
|
453 ptr8 = ptr8+ptrPitch; |
|
454 ptrLimit8= ptrLimit8+pitch; |
|
455 } |
|
456 while(--height); |
|
457 |
|
458 return KErrNone; |
|
459 error: |
|
460 GraphicsAcceleratorPanic(EGraphicsAcceleratorAttemptedDrawOutsideBitmap); |
|
461 return KErrNone; // Will not be executed but prevents compiler warnings |
|
462 } |
|
463 |
|
464 void CColor256HardwareGraphicsAccelerator::DoInvertRect(const TRect& aRect) |
|
465 { |
|
466 //Lock(); |
|
467 |
|
468 TUint32* ptr = (TUint32*)iBitmapInfo.iAddress; |
|
469 TUint32* ptrLimit; |
|
470 TUint32 leftMask; |
|
471 TUint32 rightMask; |
|
472 TInt ptrPitch; |
|
473 TInt pitch; |
|
474 TInt height; |
|
475 |
|
476 { |
|
477 TInt yStart = aRect.iTl.iY; |
|
478 TInt yEnd = aRect.iBr.iY; |
|
479 |
|
480 if(yStart<0) |
|
481 goto error; |
|
482 if(yStart>=yEnd) |
|
483 goto error; |
|
484 if(yEnd>iBitmapInfo.iSize.iHeight) |
|
485 goto error; |
|
486 |
|
487 ptr = (TUint32*)((TUint8*)ptr+yStart*iBitmapInfo.iLinePitch); |
|
488 height = yEnd-yStart; |
|
489 } |
|
490 |
|
491 { |
|
492 TInt xStart = aRect.iTl.iX; |
|
493 TInt xEnd = aRect.iBr.iX; |
|
494 |
|
495 if(xStart<0) |
|
496 goto error; |
|
497 if(xStart>=xEnd) |
|
498 goto error; |
|
499 if(xEnd>iBitmapInfo.iSize.iWidth) |
|
500 goto error; |
|
501 |
|
502 xStart <<= iBitmapInfo.iPixelShift; |
|
503 xEnd <<= iBitmapInfo.iPixelShift; |
|
504 |
|
505 leftMask = ~((1<<(xStart&0x1F))-1); |
|
506 rightMask = (1<<(xEnd&0x1F))-1; |
|
507 |
|
508 xStart >>= 5; |
|
509 xEnd = (xEnd-1)>>5; |
|
510 ptrLimit = ptr+xEnd; |
|
511 ptr += xStart; |
|
512 |
|
513 pitch = iBitmapInfo.iLinePitch; |
|
514 ptrPitch = pitch-((TInt)ptrLimit-(TInt)ptr); |
|
515 } |
|
516 |
|
517 TUint32 pixelsInverted; |
|
518 if((ptr==ptrLimit) && (leftMask!=0xFFFFFFFF)) // all pixels in a line are in the same word |
|
519 { |
|
520 if((leftMask != 0) && (rightMask !=0)) |
|
521 leftMask &= rightMask; |
|
522 else if(rightMask != 0) |
|
523 leftMask = rightMask; |
|
524 |
|
525 do |
|
526 { |
|
527 TUint32 pixels = *ptr; |
|
528 pixelsInverted = ~ pixels; |
|
529 |
|
530 pixels &= ~ leftMask; |
|
531 pixelsInverted &= leftMask; |
|
532 |
|
533 pixels |= pixelsInverted; |
|
534 *(ptr) = pixels; |
|
535 ptr = (TUint32*)((TUint8*)ptr+ptrPitch); |
|
536 } |
|
537 while(--height); |
|
538 } |
|
539 else if((leftMask==0xFFFFFFFF)&&(rightMask==0)) // all pixels in a line fit into whole words |
|
540 { |
|
541 do |
|
542 { |
|
543 while(ptr<ptrLimit) |
|
544 { |
|
545 *(ptr++) = ~(*(ptr)) ; |
|
546 } |
|
547 *ptr = ~(*(ptr)); |
|
548 |
|
549 ptr = (TUint32*)((TUint8*)ptr+ptrPitch); |
|
550 ptrLimit = (TUint32*)((TUint8*)ptrLimit+pitch); |
|
551 } |
|
552 while(--height); |
|
553 } |
|
554 else if(leftMask==0xFFFFFFFF) // first pixel starts on a word boundary but last doesn't |
|
555 { |
|
556 do |
|
557 { |
|
558 while(ptr<ptrLimit) |
|
559 { |
|
560 *(ptr++) = ~(*(ptr)) ; |
|
561 } |
|
562 |
|
563 TUint32 pixels = *ptr; |
|
564 pixelsInverted = ~pixels; |
|
565 pixels &= ~ rightMask; |
|
566 pixels |= (pixelsInverted & rightMask); |
|
567 *ptr = pixels; |
|
568 |
|
569 ptr = (TUint32*)((TUint8*)ptr+ptrPitch); |
|
570 ptrLimit = (TUint32*)((TUint8*)ptrLimit+pitch); |
|
571 } |
|
572 while(--height); |
|
573 } |
|
574 else if(rightMask==0) // last pixel lies on a word boundary but first doesn't |
|
575 { |
|
576 do |
|
577 { |
|
578 TUint32 pixels = *ptr; |
|
579 pixelsInverted = ~pixels; |
|
580 pixels &= ~ leftMask; |
|
581 pixels |= (pixelsInverted & leftMask); |
|
582 *(ptr++) = pixels; |
|
583 |
|
584 while(ptr<ptrLimit) |
|
585 { |
|
586 *(ptr++) = ~(*(ptr)) ; |
|
587 } |
|
588 *ptr = ~(*(ptr)); |
|
589 |
|
590 ptr = (TUint32*)((TUint8*)ptr+ptrPitch); |
|
591 ptrLimit = (TUint32*)((TUint8*)ptrLimit+pitch); |
|
592 } |
|
593 while(--height); |
|
594 } |
|
595 else // both last and first pixels in a line don't lie on a word boundary |
|
596 { |
|
597 do |
|
598 { |
|
599 TUint32 pixels = *ptr; |
|
600 pixelsInverted = ~pixels; |
|
601 pixels &= ~ leftMask; |
|
602 pixels |= (pixelsInverted & leftMask); |
|
603 *(ptr++) = pixels; |
|
604 |
|
605 while(ptr<ptrLimit) |
|
606 { |
|
607 *(ptr++) = ~(*(ptr)); |
|
608 } |
|
609 |
|
610 pixels = *ptr; |
|
611 pixelsInverted = ~pixels; |
|
612 pixels &= ~ rightMask; |
|
613 pixels |= (pixelsInverted & rightMask); |
|
614 *ptr = pixels; |
|
615 |
|
616 ptr = (TUint32*)((TUint8*)ptr+ptrPitch); |
|
617 ptrLimit = (TUint32*)((TUint8*)ptrLimit+pitch); |
|
618 } |
|
619 while(--height); |
|
620 } |
|
621 |
|
622 return; |
|
623 error: |
|
624 GraphicsAcceleratorPanic(EGraphicsAcceleratorAttemptedDrawOutsideBitmap); |
|
625 } |
|
626 |
|
627 void CColor256HardwareGraphicsAccelerator::DoFadeRect(const TRect& aRect,const TGopFadeParams aFade) |
|
628 { |
|
629 |
|
630 TUint8* ptr8 = (TUint8*)iBitmapInfo.iAddress; |
|
631 TUint8* prtLimit8; |
|
632 TInt ptrPitch; |
|
633 TInt pitch; |
|
634 TInt height; |
|
635 |
|
636 TInt scale = aFade.iScale; |
|
637 TInt offset = aFade.iOffset; |
|
638 |
|
639 TRgb color; |
|
640 |
|
641 { |
|
642 TInt yStart = aRect.iTl.iY; |
|
643 TInt yEnd = aRect.iBr.iY; |
|
644 |
|
645 if(yStart<0) |
|
646 goto error; |
|
647 if(yStart>=yEnd) |
|
648 goto error; |
|
649 if(yEnd>iBitmapInfo.iSize.iHeight) |
|
650 goto error; |
|
651 |
|
652 ptr8 = (ptr8 + yStart*iBitmapInfo.iLinePitch); |
|
653 height = yEnd-yStart; |
|
654 } |
|
655 |
|
656 { |
|
657 TInt xStart = aRect.iTl.iX; |
|
658 TInt xEnd = aRect.iBr.iX; |
|
659 |
|
660 if(xStart<0) |
|
661 goto error; |
|
662 if(xStart>=xEnd) |
|
663 goto error; |
|
664 if(xEnd>iBitmapInfo.iSize.iWidth) |
|
665 goto error; |
|
666 |
|
667 prtLimit8 = ptr8 + (xEnd); |
|
668 ptr8 += xStart; |
|
669 pitch = iBitmapInfo.iLinePitch; |
|
670 ptrPitch = pitch-((TInt)prtLimit8-(TInt)ptr8); |
|
671 } |
|
672 |
|
673 do |
|
674 { |
|
675 while(ptr8<prtLimit8) |
|
676 { |
|
677 TUint8 index = *ptr8; |
|
678 color = TRgb::Color256(index); |
|
679 |
|
680 TInt32 value = color.Internal(); |
|
681 |
|
682 TInt b = (((value & 0x000000ff) * scale) >> 8) + offset; |
|
683 TInt g = (((value & 0x0000ff00) * scale) >> 16) + offset; |
|
684 //the multiplication by scale can overflow into the sign bit, so we shift down in two steps |
|
685 TInt r = ((((value & 0x00ff0000) >> 16) * scale) >> 8) + offset; |
|
686 |
|
687 color = TRgb(r,g,b); |
|
688 *(ptr8++) = (TUint8)color.Color256(); |
|
689 } |
|
690 |
|
691 ptr8 = ptr8+ptrPitch; |
|
692 prtLimit8 = prtLimit8+pitch; |
|
693 } |
|
694 while(--height); |
|
695 |
|
696 //Unlock(); |
|
697 return; |
|
698 error: |
|
699 //Unlock(); |
|
700 GraphicsAcceleratorPanic(EGraphicsAcceleratorAttemptedDrawOutsideBitmap); |
|
701 } |
|
702 |
|
703 TInt CColor256HardwareGraphicsAccelerator::DoBitBlt(const TPoint& aDestination,const TAcceleratedBitmapSpec& aSourceBitmapSpec,const TRect& aSourceRect) |
|
704 { |
|
705 if(aSourceBitmapSpec.Type() != TAcceleratedBitmapSpec::EHardwareBitmap) |
|
706 return KErrNotSupported; |
|
707 |
|
708 TInt handle = aSourceBitmapSpec.Handle(); |
|
709 RHardwareBitmap sourceBitmap(handle); |
|
710 |
|
711 TAcceleratedBitmapInfo sourceBitmapInfo; |
|
712 sourceBitmap.GetInfo(sourceBitmapInfo); |
|
713 |
|
714 if(sourceBitmapInfo.iDisplayMode != EColor256) |
|
715 return KErrNotSupported; |
|
716 |
|
717 TUint32* ptrSource32 = (TUint32*)sourceBitmapInfo.iAddress; |
|
718 TUint32* prtLimitSource32; |
|
719 |
|
720 TUint32* ptrDest32 = (TUint32*)iBitmapInfo.iAddress; |
|
721 TUint32* ptrLimitDest32; |
|
722 |
|
723 TUint8* ptrSource8 = (TUint8*)ptrSource32; |
|
724 TUint8* prtLimitSource8; |
|
725 |
|
726 TUint8* ptrDest8 = (TUint8*)ptrDest32; |
|
727 TUint8* ptrLimitDest8; |
|
728 |
|
729 |
|
730 TInt ySourceStart = aSourceRect.iTl.iY; |
|
731 TInt ySourceEnd = aSourceRect.iBr.iY; |
|
732 TInt xSourceStart = aSourceRect.iTl.iX; |
|
733 TInt xSourceEnd = aSourceRect.iBr.iX; |
|
734 |
|
735 TInt yDestStart; |
|
736 TInt yDestEnd; |
|
737 TInt xDestStart; |
|
738 TInt xDestEnd; |
|
739 |
|
740 TUint32 leftMask; |
|
741 TUint32 rightMask; |
|
742 |
|
743 TInt ptrPitchSource; |
|
744 TInt pitchSource; |
|
745 TInt ptrPitchDest; |
|
746 TInt pitchDest; |
|
747 |
|
748 TInt height; |
|
749 |
|
750 |
|
751 TRect area(aSourceRect); //final area from aSourceRect to blit |
|
752 TRect destRect(aSourceRect.Size()); |
|
753 |
|
754 //aSource |
|
755 if(ySourceStart<0) |
|
756 goto error; |
|
757 if(ySourceStart>=ySourceEnd) |
|
758 goto error; |
|
759 if(ySourceEnd>sourceBitmapInfo.iSize.iHeight) |
|
760 goto error; |
|
761 |
|
762 if(xSourceStart<0) |
|
763 goto error; |
|
764 if(xSourceStart>=xSourceEnd) |
|
765 goto error; |
|
766 if(xSourceEnd>sourceBitmapInfo.iSize.iWidth) |
|
767 goto error; |
|
768 |
|
769 destRect.Move(aDestination); |
|
770 if(!destRect.Intersects(TRect(iBitmapInfo.iSize))) |
|
771 return KErrNone; |
|
772 |
|
773 //save parameters |
|
774 yDestStart = destRect.iTl.iY; |
|
775 yDestEnd = destRect.iBr.iY; |
|
776 xDestStart = destRect.iTl.iX; |
|
777 xDestEnd = destRect.iBr.iX; |
|
778 |
|
779 destRect.Intersection(TRect(iBitmapInfo.iSize)); |
|
780 |
|
781 ySourceStart += destRect.iTl.iY - yDestStart; |
|
782 ySourceEnd += destRect.iBr.iY - yDestEnd; |
|
783 xSourceStart += destRect.iTl.iX - xDestStart; |
|
784 xSourceEnd += destRect.iBr.iX - xDestEnd; |
|
785 |
|
786 yDestStart = destRect.iTl.iY; |
|
787 yDestEnd = destRect.iBr.iY; |
|
788 xDestStart = destRect.iTl.iX; |
|
789 xDestEnd = destRect.iBr.iX; |
|
790 |
|
791 area.SetRect(xSourceStart,ySourceStart,xSourceEnd,ySourceEnd); |
|
792 height = ySourceEnd - ySourceStart; |
|
793 |
|
794 |
|
795 if(!((xSourceStart&0x1F) == (xDestStart&0x1F))) // source and dest are not aligned |
|
796 { |
|
797 ptrSource8 = (ptrSource8 + ySourceStart*sourceBitmapInfo.iLinePitch); |
|
798 prtLimitSource8 = ptrSource8 + (xSourceEnd); |
|
799 ptrSource8 += xSourceStart; |
|
800 |
|
801 ptrDest8 = (ptrDest8 + yDestStart*iBitmapInfo.iLinePitch); |
|
802 ptrLimitDest8 = ptrDest8 + (xDestEnd); |
|
803 ptrDest8 += xDestStart; |
|
804 |
|
805 pitchSource = sourceBitmapInfo.iLinePitch; |
|
806 ptrPitchSource = pitchSource -((TInt)prtLimitSource8 - (TInt)ptrSource8); |
|
807 |
|
808 pitchDest = iBitmapInfo.iLinePitch; |
|
809 ptrPitchDest = pitchDest - ((TInt)ptrLimitDest8 - (TInt)ptrDest8); |
|
810 |
|
811 do |
|
812 { |
|
813 while(ptrSource8<prtLimitSource8) |
|
814 *(ptrDest8++) = *(ptrSource8++); |
|
815 |
|
816 ptrSource8 = ptrSource8+ptrPitchSource; |
|
817 prtLimitSource8 = prtLimitSource8+pitchSource; |
|
818 ptrDest8 = ptrDest8+ptrPitchDest; |
|
819 ptrLimitDest8 = ptrLimitDest8+pitchDest; |
|
820 } |
|
821 while(--height); |
|
822 } |
|
823 else |
|
824 { |
|
825 //distances in bit from the left edge |
|
826 xSourceStart <<= sourceBitmapInfo.iPixelShift; |
|
827 xSourceEnd <<= sourceBitmapInfo.iPixelShift; |
|
828 xDestStart <<= iBitmapInfo.iPixelShift; |
|
829 xDestEnd <<= iBitmapInfo.iPixelShift; |
|
830 |
|
831 ptrSource32 = (TUint32*)((TUint8*)ptrSource32 + ySourceStart*sourceBitmapInfo.iLinePitch); |
|
832 ptrDest32 = (TUint32*)((TUint8*)ptrDest32 + destRect.iTl.iY*iBitmapInfo.iLinePitch); |
|
833 |
|
834 leftMask = ~((1<<(xSourceStart&0x1F))-1); |
|
835 rightMask = (1<<(xSourceEnd&0x1F))-1; |
|
836 |
|
837 xSourceStart >>= 5; |
|
838 xSourceEnd = (xSourceEnd-1) >> 5; |
|
839 xDestStart >>= 5; |
|
840 xDestEnd = (xDestEnd-1) >> 5; |
|
841 |
|
842 prtLimitSource32 = ptrSource32 + xSourceEnd; |
|
843 ptrSource32 += xSourceStart; |
|
844 ptrLimitDest32 = ptrDest32 + xDestEnd; |
|
845 ptrDest32 += xDestStart; |
|
846 |
|
847 pitchSource = sourceBitmapInfo.iLinePitch; |
|
848 ptrPitchSource = pitchSource -((TInt)prtLimitSource32 - (TInt)ptrSource32); |
|
849 pitchDest = iBitmapInfo.iLinePitch; |
|
850 ptrPitchDest = pitchDest - ((TInt)ptrLimitDest32 - (TInt)ptrDest32); |
|
851 |
|
852 if((ptrSource32==prtLimitSource32) && (leftMask!=0xFFFFFFFF)) // all pixels in a line are in the same word |
|
853 { |
|
854 if((leftMask != 0) && (rightMask !=0)) |
|
855 leftMask &= rightMask; |
|
856 else if(rightMask != 0) |
|
857 leftMask = rightMask; |
|
858 do |
|
859 { |
|
860 TInt pixelsSource = *ptrSource32; |
|
861 TInt pixelsDest = *ptrDest32; |
|
862 pixelsSource &= leftMask; |
|
863 pixelsDest &= ~ leftMask; |
|
864 pixelsDest |= pixelsSource; |
|
865 *(ptrDest32) = pixelsDest; |
|
866 ptrSource32 = (TUint32*)((TUint8*)ptrSource32+ptrPitchSource); |
|
867 ptrDest32 = (TUint32*)((TUint8*)ptrDest32+ptrPitchDest); |
|
868 } |
|
869 while(--height); |
|
870 } |
|
871 else if((leftMask==0xFFFFFFFF)&&(rightMask==0)) // all pixels in a line fit into whole words |
|
872 { |
|
873 do |
|
874 { |
|
875 while(ptrSource32<prtLimitSource32) |
|
876 *(ptrDest32++) = *(ptrSource32++); |
|
877 *ptrDest32 = *ptrSource32; |
|
878 |
|
879 ptrSource32 = (TUint32*)((TUint8*)ptrSource32+ptrPitchSource); |
|
880 prtLimitSource32 = (TUint32*)((TUint8*)prtLimitSource32+pitchSource); |
|
881 ptrDest32 = (TUint32*)((TUint8*)ptrDest32+ptrPitchDest); |
|
882 ptrLimitDest32 = (TUint32*)((TUint8*)ptrLimitDest32+pitchDest); |
|
883 } |
|
884 while(--height); |
|
885 } |
|
886 else if(leftMask==0xFFFFFFFF) // first pixel starts on a word boundary but last doesn't |
|
887 { |
|
888 do |
|
889 { |
|
890 while(ptrSource32<prtLimitSource32) |
|
891 *(ptrDest32++) = *(ptrSource32++); |
|
892 |
|
893 TInt pixelsSource = *ptrSource32; |
|
894 TInt pixelsDest = *ptrDest32; |
|
895 pixelsSource &= rightMask; |
|
896 pixelsDest &= ~ rightMask; |
|
897 pixelsDest |= pixelsSource; |
|
898 *ptrDest32 = pixelsDest; |
|
899 |
|
900 ptrSource32 = (TUint32*)((TUint8*)ptrSource32+ptrPitchSource); |
|
901 prtLimitSource32 = (TUint32*)((TUint8*)prtLimitSource32+pitchSource); |
|
902 ptrDest32 = (TUint32*)((TUint8*)ptrDest32+ptrPitchDest); |
|
903 ptrLimitDest32 = (TUint32*)((TUint8*)ptrLimitDest32+pitchDest); |
|
904 } |
|
905 while(--height); |
|
906 } |
|
907 else if(rightMask==0) // last pixel lies on a word boundary but first doesn't |
|
908 { |
|
909 do |
|
910 { |
|
911 TInt pixelsSource = *ptrSource32; |
|
912 TInt pixelsDest = *ptrDest32; |
|
913 pixelsSource &= leftMask; |
|
914 pixelsDest &= ~ leftMask; |
|
915 pixelsDest |= pixelsSource; |
|
916 *(ptrDest32++) = pixelsDest; |
|
917 ptrSource32++; |
|
918 |
|
919 while(ptrSource32<prtLimitSource32) |
|
920 *(ptrDest32++) = *(ptrSource32++); |
|
921 *ptrDest32 = *ptrSource32; |
|
922 |
|
923 ptrSource32 = (TUint32*)((TUint8*)ptrSource32+ptrPitchSource); |
|
924 prtLimitSource32 = (TUint32*)((TUint8*)prtLimitSource32+pitchSource); |
|
925 ptrDest32 = (TUint32*)((TUint8*)ptrDest32+ptrPitchDest); |
|
926 ptrLimitDest32 = (TUint32*)((TUint8*)ptrLimitDest32+pitchDest); |
|
927 } |
|
928 while(--height); |
|
929 } |
|
930 else // both last and first pixels in a line don't lie on a word boundary |
|
931 { |
|
932 do |
|
933 { |
|
934 TInt pixelsSource = *ptrSource32; |
|
935 TInt pixelsDest = *ptrDest32; |
|
936 pixelsSource &= leftMask; |
|
937 pixelsDest &= ~ leftMask; |
|
938 pixelsDest |= pixelsSource; |
|
939 *(ptrDest32++) = pixelsDest; |
|
940 ptrSource32++; |
|
941 |
|
942 while(ptrSource32<prtLimitSource32) |
|
943 *(ptrDest32++) = *(ptrSource32++); |
|
944 |
|
945 pixelsSource = *ptrSource32; |
|
946 pixelsDest = *ptrDest32; |
|
947 pixelsSource &= rightMask; |
|
948 pixelsDest &= ~ rightMask; |
|
949 pixelsDest |= pixelsSource; |
|
950 *ptrDest32 = pixelsDest; |
|
951 |
|
952 ptrSource32 = (TUint32*)((TUint8*)ptrSource32+ptrPitchSource); |
|
953 prtLimitSource32 = (TUint32*)((TUint8*)prtLimitSource32+pitchSource); |
|
954 ptrDest32 = (TUint32*)((TUint8*)ptrDest32+ptrPitchDest); |
|
955 ptrLimitDest32 = (TUint32*)((TUint8*)ptrLimitDest32+pitchDest); |
|
956 } |
|
957 while(--height); |
|
958 } |
|
959 } |
|
960 return KErrNone; |
|
961 error: |
|
962 GraphicsAcceleratorPanic(EGraphicsAcceleratorAttemptedDrawOutsideBitmap); |
|
963 return KErrNone; // Will not be executed but prevents compiler warnings |
|
964 } |
|
965 |
|
966 TInt CColor256HardwareGraphicsAccelerator::DoBitBltMasked(const TPoint& aDestination,const TAcceleratedBitmapSpec& aSourceBitmapSpec,const TRect& aSourceRect,const TAcceleratedBitmapSpec& aMaskBitmapSpec) |
|
967 { |
|
968 //Destination Bitmap |
|
969 TUint8* ptrDest8 = (TUint8*)iBitmapInfo.iAddress; |
|
970 TUint8* ptrLimitDest8; |
|
971 |
|
972 //Source Bitmap |
|
973 if(aSourceBitmapSpec.Type() != TAcceleratedBitmapSpec::EHardwareBitmap) |
|
974 return KErrNotSupported; |
|
975 |
|
976 TInt handleSourceBitmap = aSourceBitmapSpec.Handle(); |
|
977 RHardwareBitmap sourceBitmap(handleSourceBitmap); |
|
978 |
|
979 TAcceleratedBitmapInfo sourceBitmapInfo; |
|
980 sourceBitmap.GetInfo(sourceBitmapInfo); |
|
981 |
|
982 TUint8* ptrSource8 = (TUint8*)sourceBitmapInfo.iAddress; |
|
983 TUint8* prtLimitSource8; |
|
984 |
|
985 |
|
986 //Mask Bitmap |
|
987 if(aMaskBitmapSpec.Type() != TAcceleratedBitmapSpec::EHardwareBitmap) |
|
988 return KErrNotSupported; |
|
989 |
|
990 TInt handleMaskBitmap = aMaskBitmapSpec.Handle(); |
|
991 RHardwareBitmap maskBitmap(handleMaskBitmap); |
|
992 |
|
993 TAcceleratedBitmapInfo maskBitmapInfo; |
|
994 maskBitmap.GetInfo(maskBitmapInfo); |
|
995 |
|
996 if((sourceBitmapInfo.iDisplayMode != EColor256) || (maskBitmapInfo.iDisplayMode != EColor256)) |
|
997 return KErrNotSupported; |
|
998 |
|
999 |
|
1000 TUint8* ptrMask8 = (TUint8*)maskBitmapInfo.iAddress; |
|
1001 TUint8* ptrLimitMask8; |
|
1002 |
|
1003 |
|
1004 TInt ySourceStart = aSourceRect.iTl.iY; |
|
1005 TInt ySourceEnd = aSourceRect.iBr.iY; |
|
1006 TInt xSourceStart = aSourceRect.iTl.iX; |
|
1007 TInt xSourceEnd = aSourceRect.iBr.iX; |
|
1008 |
|
1009 TInt yDestStart; |
|
1010 TInt yDestEnd; |
|
1011 TInt xDestStart; |
|
1012 TInt xDestEnd; |
|
1013 |
|
1014 TInt ptrPitchSource; |
|
1015 TInt pitchSource; |
|
1016 TInt ptrPitchDest; |
|
1017 TInt pitchDest; |
|
1018 TInt ptrPitchMask; |
|
1019 TInt pitchMask; |
|
1020 |
|
1021 TInt height; |
|
1022 |
|
1023 TRect area(aSourceRect); //final area from aSourceRect to blit |
|
1024 TRect destRect(aSourceRect.Size()); |
|
1025 |
|
1026 if(sourceBitmapInfo.iSize != maskBitmapInfo.iSize) |
|
1027 return KErrNotSupported; |
|
1028 |
|
1029 //aSource |
|
1030 if(ySourceStart<0) |
|
1031 goto error; |
|
1032 if(ySourceStart>=ySourceEnd) |
|
1033 goto error; |
|
1034 if(ySourceEnd>sourceBitmapInfo.iSize.iHeight) |
|
1035 goto error; |
|
1036 |
|
1037 if(xSourceStart<0) |
|
1038 goto error; |
|
1039 if(xSourceStart>=xSourceEnd) |
|
1040 goto error; |
|
1041 if(xSourceEnd>sourceBitmapInfo.iSize.iWidth) |
|
1042 goto error; |
|
1043 |
|
1044 |
|
1045 destRect.Move(aDestination); |
|
1046 if(!destRect.Intersects(TRect(iBitmapInfo.iSize))) |
|
1047 return KErrNone; |
|
1048 |
|
1049 //save parameters |
|
1050 yDestStart = destRect.iTl.iY; |
|
1051 yDestEnd = destRect.iBr.iY; |
|
1052 xDestStart = destRect.iTl.iX; |
|
1053 xDestEnd = destRect.iBr.iX; |
|
1054 |
|
1055 destRect.Intersection(TRect(iBitmapInfo.iSize)); |
|
1056 |
|
1057 ySourceStart += destRect.iTl.iY - yDestStart; |
|
1058 ySourceEnd += destRect.iBr.iY - yDestEnd; |
|
1059 xSourceStart += destRect.iTl.iX - xDestStart; |
|
1060 xSourceEnd += destRect.iBr.iX - xDestEnd; |
|
1061 |
|
1062 yDestStart = destRect.iTl.iY; |
|
1063 yDestEnd = destRect.iBr.iY; |
|
1064 xDestStart = destRect.iTl.iX; |
|
1065 xDestEnd = destRect.iBr.iX; |
|
1066 |
|
1067 area.SetRect(xSourceStart,ySourceStart,xSourceEnd,ySourceEnd); |
|
1068 height = ySourceEnd - ySourceStart; |
|
1069 |
|
1070 //Source Bitmap |
|
1071 ptrSource8 = (ptrSource8 + ySourceStart*sourceBitmapInfo.iLinePitch); |
|
1072 prtLimitSource8 = ptrSource8 + (xSourceEnd); |
|
1073 ptrSource8 += xSourceStart; |
|
1074 |
|
1075 pitchSource = sourceBitmapInfo.iLinePitch; |
|
1076 ptrPitchSource = pitchSource -((TInt)prtLimitSource8 - (TInt)ptrSource8); |
|
1077 |
|
1078 //Destination Bitmap |
|
1079 ptrDest8 = (ptrDest8 + yDestStart*iBitmapInfo.iLinePitch); |
|
1080 ptrLimitDest8 = ptrDest8 + (xDestEnd); |
|
1081 ptrDest8 += xDestStart; |
|
1082 |
|
1083 pitchDest = iBitmapInfo.iLinePitch; |
|
1084 ptrPitchDest = pitchDest - ((TInt)ptrLimitDest8 - (TInt)ptrDest8); |
|
1085 |
|
1086 //Mask Bitmap |
|
1087 ptrMask8 = (ptrMask8 + ySourceStart*maskBitmapInfo.iLinePitch); |
|
1088 ptrLimitMask8 = ptrMask8 + (xSourceEnd); |
|
1089 ptrMask8 += xSourceStart; |
|
1090 |
|
1091 pitchMask = maskBitmapInfo.iLinePitch; |
|
1092 ptrPitchMask = pitchMask -((TInt)ptrLimitMask8 - (TInt)ptrMask8); |
|
1093 |
|
1094 do |
|
1095 { |
|
1096 while(ptrSource8<prtLimitSource8) |
|
1097 { |
|
1098 *ptrDest8 = (TUint8)((*ptrSource8 & (~(*ptrMask8))) | (*ptrDest8 & *ptrMask8)); |
|
1099 ptrMask8++; |
|
1100 ptrDest8++; |
|
1101 ptrSource8++; |
|
1102 } |
|
1103 |
|
1104 ptrSource8 = ptrSource8+ptrPitchSource; |
|
1105 prtLimitSource8 = prtLimitSource8+pitchSource; |
|
1106 ptrDest8 = ptrDest8+ptrPitchDest; |
|
1107 ptrLimitDest8 = ptrLimitDest8+pitchDest; |
|
1108 ptrMask8 = ptrMask8+ptrPitchMask; |
|
1109 ptrLimitMask8 = ptrLimitMask8+pitchMask; |
|
1110 } |
|
1111 while(--height); |
|
1112 |
|
1113 |
|
1114 return KErrNone; |
|
1115 error: |
|
1116 GraphicsAcceleratorPanic(EGraphicsAcceleratorAttemptedDrawOutsideBitmap); |
|
1117 return KErrNone; // Will not be executed but prevents compiler warnings |
|
1118 } |
|
1119 |
|
1120 TInt CColor256HardwareGraphicsAccelerator::DoBitBltAlphaBitmap(const TPoint& aDestination,const TAcceleratedBitmapSpec& aSourceBitmapSpec,const TRect& aSourceRect,const TAcceleratedBitmapSpec& aAlphaBitmapSpec) |
|
1121 { |
|
1122 |
|
1123 //Destination Bitmap |
|
1124 TUint8* ptrDest8 = (TUint8*)iBitmapInfo.iAddress; |
|
1125 TUint8* ptrLimitDest8; |
|
1126 |
|
1127 //Source Bitmap |
|
1128 if(aSourceBitmapSpec.Type() != TAcceleratedBitmapSpec::EHardwareBitmap) |
|
1129 return KErrNotSupported; |
|
1130 |
|
1131 TInt handleSourceBitmap = aSourceBitmapSpec.Handle(); |
|
1132 RHardwareBitmap sourceBitmap(handleSourceBitmap); |
|
1133 |
|
1134 TAcceleratedBitmapInfo sourceBitmapInfo; |
|
1135 sourceBitmap.GetInfo(sourceBitmapInfo); |
|
1136 |
|
1137 TUint8* ptrSource8 = (TUint8*)sourceBitmapInfo.iAddress; |
|
1138 TUint8* prtLimitSource8; |
|
1139 |
|
1140 //Alpha Bitmap |
|
1141 if(aAlphaBitmapSpec.Type() != TAcceleratedBitmapSpec::EHardwareBitmap) |
|
1142 return KErrNotSupported; |
|
1143 |
|
1144 TInt handleAlphaBitmap = aAlphaBitmapSpec.Handle(); |
|
1145 RHardwareBitmap alphaBitmap(handleAlphaBitmap); |
|
1146 |
|
1147 TAcceleratedBitmapInfo alphaBitmapInfo; |
|
1148 alphaBitmap.GetInfo(alphaBitmapInfo); |
|
1149 |
|
1150 if((sourceBitmapInfo.iDisplayMode != EColor256) || (alphaBitmapInfo.iDisplayMode != EGray256)) |
|
1151 return KErrNotSupported; |
|
1152 |
|
1153 |
|
1154 TUint8* ptrAlpha8 = (TUint8*)alphaBitmapInfo.iAddress; |
|
1155 TUint8* ptrLimitAlpha8; |
|
1156 |
|
1157 TInt ySourceStart = aSourceRect.iTl.iY; |
|
1158 TInt ySourceEnd = aSourceRect.iBr.iY; |
|
1159 TInt xSourceStart = aSourceRect.iTl.iX; |
|
1160 TInt xSourceEnd = aSourceRect.iBr.iX; |
|
1161 |
|
1162 TInt yDestStart; |
|
1163 TInt yDestEnd; |
|
1164 TInt xDestStart; |
|
1165 TInt xDestEnd; |
|
1166 |
|
1167 TInt ptrPitchSource; |
|
1168 TInt pitchSource; |
|
1169 TInt ptrPitchDest; |
|
1170 TInt pitchDest; |
|
1171 TInt ptrPitchAlpha; |
|
1172 TInt pitchAlpha; |
|
1173 |
|
1174 TInt height; |
|
1175 |
|
1176 TRect area(aSourceRect); //final area from aSourceRect to blit |
|
1177 TRect destRect(aSourceRect.Size()); |
|
1178 |
|
1179 TRgb color; |
|
1180 |
|
1181 if(sourceBitmapInfo.iSize != alphaBitmapInfo.iSize) |
|
1182 return KErrNotSupported; |
|
1183 |
|
1184 //aSource |
|
1185 if(ySourceStart<0) |
|
1186 goto error; |
|
1187 if(ySourceStart>=ySourceEnd) |
|
1188 goto error; |
|
1189 if(ySourceEnd>sourceBitmapInfo.iSize.iHeight) |
|
1190 goto error; |
|
1191 |
|
1192 if(xSourceStart<0) |
|
1193 goto error; |
|
1194 if(xSourceStart>=xSourceEnd) |
|
1195 goto error; |
|
1196 if(xSourceEnd>sourceBitmapInfo.iSize.iWidth) |
|
1197 goto error; |
|
1198 |
|
1199 |
|
1200 destRect.Move(aDestination); |
|
1201 if(!destRect.Intersects(TRect(iBitmapInfo.iSize))) |
|
1202 return KErrNone; |
|
1203 |
|
1204 //save parameters |
|
1205 yDestStart = destRect.iTl.iY; |
|
1206 yDestEnd = destRect.iBr.iY; |
|
1207 xDestStart = destRect.iTl.iX; |
|
1208 xDestEnd = destRect.iBr.iX; |
|
1209 |
|
1210 destRect.Intersection(TRect(iBitmapInfo.iSize)); |
|
1211 |
|
1212 ySourceStart += destRect.iTl.iY - yDestStart; |
|
1213 ySourceEnd += destRect.iBr.iY - yDestEnd; |
|
1214 xSourceStart += destRect.iTl.iX - xDestStart; |
|
1215 xSourceEnd += destRect.iBr.iX - xDestEnd; |
|
1216 |
|
1217 yDestStart = destRect.iTl.iY; |
|
1218 yDestEnd = destRect.iBr.iY; |
|
1219 xDestStart = destRect.iTl.iX; |
|
1220 xDestEnd = destRect.iBr.iX; |
|
1221 |
|
1222 area.SetRect(xSourceStart,ySourceStart,xSourceEnd,ySourceEnd); |
|
1223 height = ySourceEnd - ySourceStart; |
|
1224 |
|
1225 //Source Bitmap |
|
1226 ptrSource8 = (ptrSource8 + ySourceStart*sourceBitmapInfo.iLinePitch); |
|
1227 prtLimitSource8 = ptrSource8 + (xSourceEnd); |
|
1228 ptrSource8 += xSourceStart; |
|
1229 |
|
1230 pitchSource = sourceBitmapInfo.iLinePitch; |
|
1231 ptrPitchSource = pitchSource -((TInt)prtLimitSource8 - (TInt)ptrSource8); |
|
1232 |
|
1233 //Destination Bitmap |
|
1234 ptrDest8 = (ptrDest8 + yDestStart*iBitmapInfo.iLinePitch); |
|
1235 ptrLimitDest8 = ptrDest8 + (xDestEnd); |
|
1236 ptrDest8 += xDestStart; |
|
1237 |
|
1238 pitchDest = iBitmapInfo.iLinePitch; |
|
1239 ptrPitchDest = pitchDest - ((TInt)ptrLimitDest8 - (TInt)ptrDest8); |
|
1240 |
|
1241 //Alpha Bitmap |
|
1242 ptrAlpha8 = (ptrAlpha8 + ySourceStart*alphaBitmapInfo.iLinePitch); |
|
1243 ptrLimitAlpha8 = ptrAlpha8 + (xSourceEnd); |
|
1244 ptrAlpha8 += xSourceStart; |
|
1245 |
|
1246 pitchAlpha = alphaBitmapInfo.iLinePitch; |
|
1247 ptrPitchAlpha = pitchAlpha -((TInt)ptrLimitAlpha8 - (TInt)ptrAlpha8); |
|
1248 |
|
1249 do |
|
1250 { |
|
1251 while(ptrSource8<prtLimitSource8) |
|
1252 { |
|
1253 //Source color information |
|
1254 TUint8 index = *ptrSource8; |
|
1255 color = TRgb::Color256(index); |
|
1256 TUint32 value = color.Internal(); |
|
1257 TInt blueSource = (value & 0x000000ff); |
|
1258 TInt greenSource = (value & 0x0000ff00) >> 8; |
|
1259 TInt redSource = (value & 0x00ff0000) >> 16; |
|
1260 |
|
1261 //Dest color information |
|
1262 index= *ptrDest8; |
|
1263 color = TRgb::Color256(index); |
|
1264 value = color.Internal(); |
|
1265 TInt blueDest = (value & 0x000000ff); |
|
1266 TInt greenDest = (value & 0x0000ff00) >> 8; |
|
1267 TInt redDest= (value & 0x00ff0000) >> 16; |
|
1268 |
|
1269 TInt inverseMask = 255 - *ptrAlpha8; |
|
1270 |
|
1271 redDest = ((redSource * (*ptrAlpha8) + redSource) + (redDest * inverseMask + redDest)) >> 8; |
|
1272 greenDest = ((greenSource * (*ptrAlpha8) + greenSource) + (greenDest * inverseMask + greenDest)) >> 8; |
|
1273 blueDest = ((blueSource * (*ptrAlpha8) + blueSource) + (blueDest * inverseMask + blueDest)) >> 8; |
|
1274 |
|
1275 color = TRgb(redDest,greenDest,blueDest); |
|
1276 *ptrDest8 = TUint8(color.Color256()); |
|
1277 |
|
1278 ptrAlpha8++; |
|
1279 ptrDest8++; |
|
1280 ptrSource8++; |
|
1281 } |
|
1282 |
|
1283 ptrSource8 = ptrSource8+ptrPitchSource; |
|
1284 prtLimitSource8 = prtLimitSource8+pitchSource; |
|
1285 ptrDest8 = ptrDest8+ptrPitchDest; |
|
1286 ptrLimitDest8 = ptrLimitDest8+pitchDest; |
|
1287 ptrAlpha8 = ptrAlpha8+ptrPitchAlpha; |
|
1288 ptrLimitAlpha8 = ptrLimitAlpha8+pitchAlpha; |
|
1289 } |
|
1290 while(--height); |
|
1291 |
|
1292 |
|
1293 return KErrNone; |
|
1294 error: |
|
1295 GraphicsAcceleratorPanic(EGraphicsAcceleratorAttemptedDrawOutsideBitmap); |
|
1296 return KErrNone; // Will not be executed but prevents compiler warnings |
|
1297 } |
|
1298 |
|
1299 TInt CColor256HardwareGraphicsAccelerator::DoAlphaBlendTwoBitmaps(const TPoint& aDestination,const TAcceleratedBitmapSpec& aSrceBitmapSpec1,const TAcceleratedBitmapSpec& aSrceBitmapSpec2,const TRect& aSourceRect,const TPoint& aSrcPt2,const TAcceleratedBitmapSpec& aAlphaBitmapSpec,const TPoint& aAlphaPt) |
|
1300 { |
|
1301 //Destination Bitmap |
|
1302 TUint8* ptrDest8 = (TUint8*)iBitmapInfo.iAddress; |
|
1303 |
|
1304 // First Source Bitmap |
|
1305 if(aSrceBitmapSpec1.Type() != TAcceleratedBitmapSpec::EHardwareBitmap) |
|
1306 return KErrNotSupported; |
|
1307 |
|
1308 TInt handleSourceBitmap1 = aSrceBitmapSpec1.Handle(); |
|
1309 RHardwareBitmap sourceBitmap1(handleSourceBitmap1); |
|
1310 |
|
1311 TAcceleratedBitmapInfo sourceBitmap1Info; |
|
1312 sourceBitmap1.GetInfo(sourceBitmap1Info); |
|
1313 |
|
1314 TUint8* ptrSourceOne8 = (TUint8*)sourceBitmap1Info.iAddress; |
|
1315 |
|
1316 // Second Source Bitmap |
|
1317 if(aSrceBitmapSpec2.Type() != TAcceleratedBitmapSpec::EHardwareBitmap) |
|
1318 return KErrNotSupported; |
|
1319 |
|
1320 TInt handleSourceBitmap2 = aSrceBitmapSpec2.Handle(); |
|
1321 RHardwareBitmap sourceBitmap2(handleSourceBitmap2); |
|
1322 |
|
1323 TAcceleratedBitmapInfo sourceBitmap2Info; |
|
1324 sourceBitmap2.GetInfo(sourceBitmap2Info); |
|
1325 |
|
1326 TUint8* ptrSourceTwo8 = (TUint8*)sourceBitmap2Info.iAddress; |
|
1327 |
|
1328 //Alpha Bitmap |
|
1329 if(aAlphaBitmapSpec.Type() != TAcceleratedBitmapSpec::EHardwareBitmap) |
|
1330 return KErrNotSupported; |
|
1331 |
|
1332 TInt handleAlphaBitmap = aAlphaBitmapSpec.Handle(); |
|
1333 RHardwareBitmap alphaBitmap(handleAlphaBitmap); |
|
1334 |
|
1335 TAcceleratedBitmapInfo alphaBitmapInfo; |
|
1336 alphaBitmap.GetInfo(alphaBitmapInfo); |
|
1337 |
|
1338 if((sourceBitmap1Info.iDisplayMode != EColor256) || (sourceBitmap2Info.iDisplayMode != EColor256) || (alphaBitmapInfo.iDisplayMode != EGray256)) |
|
1339 return KErrNotSupported; |
|
1340 |
|
1341 TUint8* ptrAlpha8 = (TUint8*)alphaBitmapInfo.iAddress; |
|
1342 |
|
1343 TRect destRect(aSourceRect.Size()); |
|
1344 |
|
1345 if((sourceBitmap1Info.iSize != alphaBitmapInfo.iSize) && (sourceBitmap2Info.iSize != alphaBitmapInfo.iSize)) |
|
1346 return KErrNotSupported; |
|
1347 |
|
1348 // Check bounds on the source rectangle |
|
1349 if(aSourceRect.iTl.iY<0) |
|
1350 goto error; |
|
1351 if(aSourceRect.iTl.iY>=aSourceRect.iBr.iY) |
|
1352 goto error; |
|
1353 if(aSourceRect.iBr.iY>sourceBitmap1Info.iSize.iHeight) |
|
1354 goto error; |
|
1355 if(aSourceRect.iTl.iX<0) |
|
1356 goto error; |
|
1357 if(aSourceRect.iTl.iX>=aSourceRect.iBr.iX) |
|
1358 goto error; |
|
1359 if(aSourceRect.iBr.iX>sourceBitmap1Info.iSize.iWidth) |
|
1360 goto error; |
|
1361 |
|
1362 // Find writeable area of the destination rectangle |
|
1363 destRect.Move(aDestination); |
|
1364 if(!destRect.Intersects(TRect(iBitmapInfo.iSize))) |
|
1365 return KErrNone; |
|
1366 destRect.Intersection(TRect(iBitmapInfo.iSize)); |
|
1367 |
|
1368 // Iterate through the pixels and blend to the destination |
|
1369 TInt srceY = aSourceRect.iTl.iY; |
|
1370 TInt src2Y = aSrcPt2.iY; |
|
1371 TInt srcaY = aAlphaPt.iY; |
|
1372 TInt destY = destRect.iTl.iY; |
|
1373 while (destY < destRect.iBr.iY) |
|
1374 { |
|
1375 TInt srceX = aSourceRect.iTl.iX; |
|
1376 TInt src2X = aSrcPt2.iX; |
|
1377 TInt destX = destRect.iTl.iX; |
|
1378 TInt srcaX = aAlphaPt.iX; |
|
1379 |
|
1380 while (destX < destRect.iBr.iX) |
|
1381 { |
|
1382 // First Source color information |
|
1383 TUint8 index = ptrSourceOne8[srceY*sourceBitmap1Info.iLinePitch+srceX]; |
|
1384 TRgb color = TRgb::Color256(index); |
|
1385 TUint32 value = color.Internal(); |
|
1386 TInt blueSource1 = (value & 0x000000ff); |
|
1387 TInt greenSource1 = (value & 0x0000ff00) >> 8; |
|
1388 TInt redSource1 = (value & 0x00ff0000) >> 16; |
|
1389 |
|
1390 // Second Source color information |
|
1391 index = ptrSourceTwo8[src2Y*sourceBitmap2Info.iLinePitch+src2X]; |
|
1392 color = TRgb::Color256(index); |
|
1393 value = color.Internal(); |
|
1394 TInt blueSource2 = (value & 0x000000ff); |
|
1395 TInt greenSource2 = (value & 0x0000ff00) >> 8; |
|
1396 TInt redSource2 = (value & 0x00ff0000) >> 16; |
|
1397 |
|
1398 TUint8 alpha = ptrAlpha8[srcaY*alphaBitmapInfo.iLinePitch+srcaX]; |
|
1399 TInt inverseMask = 255 - alpha; |
|
1400 |
|
1401 // Blend |
|
1402 TInt redDest = ((alpha * (redSource1 - redSource2)) >> 8) + redSource2; |
|
1403 TInt greenDest = ((alpha * (greenSource1 - greenSource2)) >> 8) + greenSource2; |
|
1404 TInt blueDest = ((alpha * (blueSource1 - blueSource2)) >> 8) + blueSource2; |
|
1405 |
|
1406 color = TRgb(redDest,greenDest,blueDest); |
|
1407 ptrDest8[destY*iBitmapInfo.iLinePitch+destX] = TUint8(color.Color256()); |
|
1408 |
|
1409 ++srceX; |
|
1410 ++src2X; |
|
1411 ++destX; |
|
1412 ++srcaX; |
|
1413 } |
|
1414 |
|
1415 ++srceY; |
|
1416 ++destY; |
|
1417 ++src2Y; |
|
1418 ++srcaY; |
|
1419 } |
|
1420 |
|
1421 return KErrNone; |
|
1422 error: |
|
1423 GraphicsAcceleratorPanic(EGraphicsAcceleratorAttemptedDrawOutsideBitmap); |
|
1424 return KErrNone; // Will not be executed but prevents compiler warnings |
|
1425 } |
|
1426 |
|
1427 TInt CColor256HardwareGraphicsAccelerator::DoAlphaBlendOneBitmap(const TPoint& aDestination,const TAcceleratedBitmapSpec& aSrceBitmapSpec,const TRect& aSourceRect,const TAcceleratedBitmapSpec& aAlphaBitmapSpec,const TPoint& aAlphaPt) |
|
1428 { |
|
1429 //Destination Bitmap |
|
1430 TUint8* ptrDest8 = (TUint8*)iBitmapInfo.iAddress; |
|
1431 |
|
1432 // Source Bitmap |
|
1433 if(aSrceBitmapSpec.Type() != TAcceleratedBitmapSpec::EHardwareBitmap) |
|
1434 return KErrNotSupported; |
|
1435 |
|
1436 TInt handleSourceBitmap = aSrceBitmapSpec.Handle(); |
|
1437 RHardwareBitmap sourceBitmap(handleSourceBitmap); |
|
1438 |
|
1439 TAcceleratedBitmapInfo sourceBitmapInfo; |
|
1440 sourceBitmap.GetInfo(sourceBitmapInfo); |
|
1441 |
|
1442 TUint8* ptrSource8 = (TUint8*)sourceBitmapInfo.iAddress; |
|
1443 |
|
1444 //Alpha Bitmap |
|
1445 if(aAlphaBitmapSpec.Type() != TAcceleratedBitmapSpec::EHardwareBitmap) |
|
1446 return KErrNotSupported; |
|
1447 |
|
1448 TInt handleAlphaBitmap = aAlphaBitmapSpec.Handle(); |
|
1449 RHardwareBitmap alphaBitmap(handleAlphaBitmap); |
|
1450 |
|
1451 TAcceleratedBitmapInfo alphaBitmapInfo; |
|
1452 alphaBitmap.GetInfo(alphaBitmapInfo); |
|
1453 |
|
1454 if((sourceBitmapInfo.iDisplayMode != EColor256) || (alphaBitmapInfo.iDisplayMode != EGray256)) |
|
1455 return KErrNotSupported; |
|
1456 |
|
1457 TUint8* ptrAlpha8 = (TUint8*)alphaBitmapInfo.iAddress; |
|
1458 |
|
1459 TRect destRect(aSourceRect.Size()); |
|
1460 |
|
1461 if(sourceBitmapInfo.iSize != alphaBitmapInfo.iSize) |
|
1462 return KErrNotSupported; |
|
1463 |
|
1464 // Check bounds on the source rectangle |
|
1465 if(aSourceRect.iTl.iY<0) |
|
1466 goto error; |
|
1467 if(aSourceRect.iTl.iY>=aSourceRect.iBr.iY) |
|
1468 goto error; |
|
1469 if(aSourceRect.iBr.iY>sourceBitmapInfo.iSize.iHeight) |
|
1470 goto error; |
|
1471 if(aSourceRect.iTl.iX<0) |
|
1472 goto error; |
|
1473 if(aSourceRect.iTl.iX>=aSourceRect.iBr.iX) |
|
1474 goto error; |
|
1475 if(aSourceRect.iBr.iX>sourceBitmapInfo.iSize.iWidth) |
|
1476 goto error; |
|
1477 |
|
1478 // Find writeable area of the destination rectangle |
|
1479 destRect.Move(aDestination); |
|
1480 if(!destRect.Intersects(TRect(iBitmapInfo.iSize))) |
|
1481 return KErrNone; |
|
1482 destRect.Intersection(TRect(iBitmapInfo.iSize)); |
|
1483 |
|
1484 // Iterate through the pixels and blend to the destination |
|
1485 TInt srceY = aSourceRect.iTl.iY; |
|
1486 TInt srcaY = aAlphaPt.iY; |
|
1487 TInt destY = destRect.iTl.iY; |
|
1488 while (destY < destRect.iBr.iY) |
|
1489 { |
|
1490 TInt srceX = aSourceRect.iTl.iX; |
|
1491 TInt destX = destRect.iTl.iX; |
|
1492 TInt srcaX = aAlphaPt.iX; |
|
1493 |
|
1494 while (destX < destRect.iBr.iX) |
|
1495 { |
|
1496 // First Source color information |
|
1497 TUint8 index = ptrSource8[srceY*sourceBitmapInfo.iLinePitch+srceX]; |
|
1498 TRgb color = TRgb::Color256(index); |
|
1499 TUint32 value = color.Internal(); |
|
1500 TInt blueSource = (value & 0x000000ff); |
|
1501 TInt greenSource = (value & 0x0000ff00) >> 8; |
|
1502 TInt redSource = (value & 0x00ff0000) >> 16; |
|
1503 |
|
1504 // Second Source color information |
|
1505 index = ptrDest8[destY*iBitmapInfo.iLinePitch+destX]; |
|
1506 color = TRgb::Color256(index); |
|
1507 value = color.Internal(); |
|
1508 TInt blueDest = (value & 0x000000ff); |
|
1509 TInt greenDest = (value & 0x0000ff00) >> 8; |
|
1510 TInt redDest = (value & 0x00ff0000) >> 16; |
|
1511 |
|
1512 TUint8 alpha = ptrAlpha8[srcaY*alphaBitmapInfo.iLinePitch+srcaX]; |
|
1513 TInt inverseMask = 255 - alpha; |
|
1514 |
|
1515 // Blend |
|
1516 redDest = ((alpha * (redSource - redDest)) >> 8) + redDest; |
|
1517 greenDest = ((alpha * (greenSource - greenDest)) >> 8) + greenDest; |
|
1518 blueDest = ((alpha * (blueSource - blueDest)) >> 8) + blueDest; |
|
1519 |
|
1520 color = TRgb(redDest,greenDest,blueDest); |
|
1521 ptrDest8[destY*iBitmapInfo.iLinePitch+destX] = TUint8(color.Color256()); |
|
1522 |
|
1523 ++srceX; |
|
1524 ++destX; |
|
1525 ++srcaX; |
|
1526 } |
|
1527 |
|
1528 ++srceY; |
|
1529 ++destY; |
|
1530 ++srcaY; |
|
1531 } |
|
1532 |
|
1533 return KErrNone; |
|
1534 error: |
|
1535 GraphicsAcceleratorPanic(EGraphicsAcceleratorAttemptedDrawOutsideBitmap); |
|
1536 return KErrNone; // Will not be executed but prevents compiler warnings |
|
1537 } |
|
1538 |
|
1539 // |
|
1540 // CHardwareGraphicsAcceleratorBase |
|
1541 // |
|
1542 |
|
1543 void CHardwareGraphicsAcceleratorBase::ConstructL(RHardwareBitmap aBitmap) |
|
1544 { |
|
1545 aBitmap.GetInfo(iBitmapInfo); |
|
1546 iIsScreen = (aBitmap.iHandle < 0)?1:0; |
|
1547 } |
|
1548 |
|
1549 const TGraphicsAcceleratorCaps* CHardwareGraphicsAcceleratorBase::Capabilities() |
|
1550 { |
|
1551 return iCaps; |
|
1552 } |
|
1553 |
|
1554 TInt CHardwareGraphicsAcceleratorBase::Operation(const TGraphicsOperation& aOperation) |
|
1555 { |
|
1556 switch(aOperation.Function()) |
|
1557 { |
|
1558 case TGraphicsOperation::EFilledRect: |
|
1559 { |
|
1560 const TGopFilledRect& op = *(const TGopFilledRect*)&aOperation; |
|
1561 DoFillRect(op.iRect,FillValue(op.iColor)); |
|
1562 UpdateScreen(op.iRect); |
|
1563 return KErrNone; |
|
1564 } |
|
1565 case TGraphicsOperation::EFilledRectWithPattern: |
|
1566 { |
|
1567 const TGopFilledRectWithPattern& op = *(const TGopFilledRectWithPattern*)&aOperation; |
|
1568 TInt error = DoFilledRectWithPattern(op.iRect,op.iPattern); |
|
1569 if(error==KErrNone) |
|
1570 UpdateScreen(op.iRect); |
|
1571 return error; |
|
1572 } |
|
1573 case TGraphicsOperation::EInvertRect: |
|
1574 { |
|
1575 const TGopInvertRect& op = *(const TGopInvertRect*)&aOperation; |
|
1576 DoInvertRect(op.iRect); |
|
1577 UpdateScreen(op.iRect); |
|
1578 return KErrNone; |
|
1579 } |
|
1580 case TGraphicsOperation::EFadeRect: |
|
1581 { |
|
1582 const TGopFadeRect& op = *(const TGopFadeRect*)&aOperation; |
|
1583 DoFadeRect(op.iRect,op.iFade); |
|
1584 UpdateScreen(op.iRect); |
|
1585 return KErrNone; |
|
1586 } |
|
1587 case TGraphicsOperation::EBitBlt: |
|
1588 { |
|
1589 const TGopBitBlt& op = *(const TGopBitBlt*)&aOperation; |
|
1590 TInt error = DoBitBlt(op.iDestination,op.iSourceBitmap,op.iSourceRect); |
|
1591 if(error==KErrNone) |
|
1592 { |
|
1593 TRect rect(op.iSourceRect.Size()); |
|
1594 rect.Move(op.iDestination); |
|
1595 UpdateScreen(rect); |
|
1596 } |
|
1597 return error; |
|
1598 } |
|
1599 case TGraphicsOperation::EBitBltMasked: |
|
1600 { |
|
1601 const TGopBitBltMasked& op = *(const TGopBitBltMasked*)&aOperation; |
|
1602 TInt error = DoBitBltMasked(op.iDestination,op.iSourceBitmap,op.iSourceRect,op.iMask); |
|
1603 if(error==KErrNone) |
|
1604 { |
|
1605 TRect rect(op.iSourceRect.Size()); |
|
1606 rect.Move(op.iDestination); |
|
1607 UpdateScreen(rect); |
|
1608 } |
|
1609 return error; |
|
1610 } |
|
1611 case TGraphicsOperation::EBitBltTransparent: |
|
1612 case TGraphicsOperation::EBitBltAlphaChannel: |
|
1613 case TGraphicsOperation::EBitBltAlphaBitmap: |
|
1614 { |
|
1615 const TGopBitBltAlphaBitmap& op = *(const TGopBitBltAlphaBitmap*)&aOperation; |
|
1616 TInt error = DoBitBltAlphaBitmap(op.iDestination,op.iSourceBitmap,op.iSourceRect,op.iAlphaBitmap); |
|
1617 if(error==KErrNone) |
|
1618 { |
|
1619 TRect rect(op.iSourceRect.Size()); |
|
1620 rect.Move(op.iDestination); |
|
1621 UpdateScreen(rect); |
|
1622 } |
|
1623 return error; |
|
1624 } |
|
1625 case TGraphicsOperation::EAlphaBlendTwoBitmaps: |
|
1626 { |
|
1627 const TGopAlphaBlendTwoBitmaps& op = *(const TGopAlphaBlendTwoBitmaps*)&aOperation; |
|
1628 TInt error = DoAlphaBlendTwoBitmaps(op.iDestination,op.iSourceBmp1,op.iSourceBmp2,op.iSourceRect,op.iSrcPt2,op.iAlphaBmp,op.iAlphaPt); |
|
1629 if(error==KErrNone) |
|
1630 { |
|
1631 TRect rect(op.iSourceRect.Size()); |
|
1632 rect.Move(op.iDestination); |
|
1633 UpdateScreen(rect); |
|
1634 } |
|
1635 return error; |
|
1636 } |
|
1637 case TGraphicsOperation::EAlphaBlendOneBitmap: |
|
1638 { |
|
1639 const TGopAlphaBlendOneBitmap& op = *(const TGopAlphaBlendOneBitmap*)&aOperation; |
|
1640 TInt error = DoAlphaBlendOneBitmap(op.iDestination,op.iSourceBmp,op.iSourceRect,op.iAlphaBmp,op.iAlphaPt); |
|
1641 if(error==KErrNone) |
|
1642 { |
|
1643 TRect rect(op.iSourceRect.Size()); |
|
1644 rect.Move(op.iDestination); |
|
1645 UpdateScreen(rect); |
|
1646 } |
|
1647 return error; |
|
1648 } |
|
1649 case TGraphicsOperation::EFilledRectUsingDrawMode: |
|
1650 case TGraphicsOperation::EScaledBitBlt: |
|
1651 case TGraphicsOperation::EScaledBitBltMasked: |
|
1652 case TGraphicsOperation::EScaledBitBltTransparent: |
|
1653 case TGraphicsOperation::EScaledBitBltAlphaChannel: |
|
1654 case TGraphicsOperation::EScaledBitBltAlphaBitmap: |
|
1655 case TGraphicsOperation::EFilledPolygon: |
|
1656 case TGraphicsOperation::EFilledPolygonWithPattern: |
|
1657 default: |
|
1658 return KErrNotSupported; |
|
1659 } |
|
1660 } |
|
1661 |
|
1662 TInt CHardwareGraphicsAcceleratorBase::Operation(const TGraphicsOperation& aOperation,TInt /*aNumClipRects*/,TRect* /*aClipRects*/) |
|
1663 { |
|
1664 switch(aOperation.Function()) |
|
1665 { |
|
1666 case TGraphicsOperation::EFilledRect: |
|
1667 case TGraphicsOperation::EFilledRectUsingDrawMode: |
|
1668 case TGraphicsOperation::EFilledRectWithPattern: |
|
1669 case TGraphicsOperation::EInvertRect: |
|
1670 case TGraphicsOperation::EFadeRect: |
|
1671 case TGraphicsOperation::EBitBlt: |
|
1672 case TGraphicsOperation::EBitBltMasked: |
|
1673 case TGraphicsOperation::EBitBltTransparent: |
|
1674 case TGraphicsOperation::EBitBltAlphaChannel: |
|
1675 case TGraphicsOperation::EBitBltAlphaBitmap: |
|
1676 case TGraphicsOperation::EScaledBitBlt: |
|
1677 case TGraphicsOperation::EScaledBitBltMasked: |
|
1678 case TGraphicsOperation::EScaledBitBltTransparent: |
|
1679 case TGraphicsOperation::EScaledBitBltAlphaChannel: |
|
1680 case TGraphicsOperation::EScaledBitBltAlphaBitmap: |
|
1681 case TGraphicsOperation::EFilledPolygon: |
|
1682 case TGraphicsOperation::EFilledPolygonWithPattern: |
|
1683 default: |
|
1684 return KErrNotSupported; |
|
1685 } |
|
1686 } |
|
1687 |
|
1688 TInt CHardwareGraphicsAcceleratorBase::Operation(TDes8& aBuffer) |
|
1689 { |
|
1690 //Lock(); |
|
1691 |
|
1692 TInt error = KErrNone; |
|
1693 TGraphicsOperation* gop = (TGraphicsOperation*) aBuffer.Ptr(); |
|
1694 TGraphicsOperation* limit = (TGraphicsOperation*) ((TUint8*)gop+aBuffer.Length()); |
|
1695 |
|
1696 while(gop<limit) |
|
1697 { |
|
1698 error = Operation(*gop); |
|
1699 if(error!=KErrNone) |
|
1700 break; |
|
1701 gop = gop->Next(); |
|
1702 } |
|
1703 |
|
1704 //Unlock(); |
|
1705 |
|
1706 if(error==KErrNone) |
|
1707 { |
|
1708 __ASSERT_ALWAYS(gop==limit,GraphicsAcceleratorPanic(EGraphicsAcceleratorPanicInvalidOperationBuffer)); |
|
1709 } |
|
1710 else |
|
1711 { |
|
1712 aBuffer.SetLength((TUint8*)gop-aBuffer.Ptr()); |
|
1713 } |
|
1714 |
|
1715 return error; |
|
1716 } |
|
1717 |
|
1718 TInt CHardwareGraphicsAcceleratorBase::Operation(TDes8& aBuffer,TInt aNumClipRects,TRect* aClipRects) |
|
1719 { |
|
1720 //Lock(); |
|
1721 |
|
1722 TInt error = KErrNone; |
|
1723 TGraphicsOperation* gop = (TGraphicsOperation*) aBuffer.Ptr(); |
|
1724 TGraphicsOperation* limit = (TGraphicsOperation*) ((TUint8*)gop+aBuffer.Length()); |
|
1725 |
|
1726 while(gop<limit) |
|
1727 { |
|
1728 error = Operation(*gop,aNumClipRects,aClipRects); |
|
1729 if(error!=KErrNone) |
|
1730 break; |
|
1731 gop = gop->Next(); |
|
1732 } |
|
1733 |
|
1734 //Unlock(); |
|
1735 |
|
1736 if(error==KErrNone) |
|
1737 { |
|
1738 __ASSERT_ALWAYS(gop==limit,GraphicsAcceleratorPanic(EGraphicsAcceleratorPanicInvalidOperationBuffer)); |
|
1739 } |
|
1740 else |
|
1741 { |
|
1742 aBuffer.SetLength((TUint8*)gop-aBuffer.Ptr()); |
|
1743 } |
|
1744 |
|
1745 return error; |
|
1746 } |
|
1747 |
|
1748 // Empty implementations |
|
1749 void CHardwareGraphicsAcceleratorBase::Reserved_1() {}; |
|
1750 void CHardwareGraphicsAcceleratorBase::Reserved_2() {}; |
|
1751 void CHardwareGraphicsAcceleratorBase::Reserved_3() {}; |
|
1752 void CHardwareGraphicsAcceleratorBase::Reserved_4() {}; |
|
1753 |
|
1754 // |
|
1755 // Misc |
|
1756 // |
|
1757 |
|
1758 GLREF_C void GraphicsAcceleratorPanic(TGraphicsAcceleratorPanic aPanicCode) |
|
1759 { |
|
1760 _LIT(KSCDVGraphicsAcceleratorPanicCategory,"Graphics Accelerator"); |
|
1761 User::Panic(KSCDVGraphicsAcceleratorPanicCategory,aPanicCode); |
|
1762 } |
|
1763 |