|
1 /* |
|
2 * Copyright (c) 2005 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 the License "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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "minimapgenerator.h" |
|
22 |
|
23 #include <fbs.h> |
|
24 #include <gdi.h> |
|
25 #include <bitstd.h> |
|
26 #include <w32std.h> |
|
27 |
|
28 #include "minimap.h" |
|
29 #include "minimaptimer.h" |
|
30 |
|
31 // EXTERNAL DATA STRUCTURES |
|
32 |
|
33 // EXTERNAL FUNCTION PROTOTYPES |
|
34 |
|
35 // CONSTANTS |
|
36 |
|
37 const TInt KUnscaledBitmapSize = 1024*128; // pixels, = 256kB |
|
38 const TInt KBufferBitmapSize = 1024*256; // pixels, = 512kB |
|
39 const TInt KMaxDocWidth = 1600; // limit the maximum width the minimap covers |
|
40 const TInt KExtraUpdateHeightTop = 100; // hq update this much pixels outsize the view |
|
41 const TInt KExtraUpdateHeightBottom = 300; // hq update this much pixels outsize the view |
|
42 const TInt KExtraLQUpdateHeight = 0; // lq update this much pixels outsize the view |
|
43 |
|
44 // MACROS |
|
45 |
|
46 // LOCAL CONSTANTS AND MACROS |
|
47 |
|
48 // MODULE DATA STRUCTURES |
|
49 #ifdef __OOM__ |
|
50 #include <oom.h> |
|
51 |
|
52 class CMinimapOOMCollector : public CBase, MMemoryCollector |
|
53 { |
|
54 public: |
|
55 CMinimapOOMCollector( CMinimapGenerator* aGenerator ) |
|
56 : iIsCollecting(EFalse), iGenerator( aGenerator ) { MemoryManager::AddCollector( this ); } |
|
57 ~CMinimapOOMCollector() { MemoryManager::RemoveCollector( this ); } |
|
58 TBool IsCollecting() { return iIsCollecting; } |
|
59 |
|
60 TUint Collect(TUint aRequired = 0); |
|
61 void Restore() { iIsCollecting = EFalse; } |
|
62 TOOMPriority Priority() { return EOOM_PriorityLow; } |
|
63 |
|
64 private: |
|
65 TBool iIsCollecting; |
|
66 CMinimapGenerator* iGenerator; |
|
67 }; |
|
68 |
|
69 TUint CMinimapOOMCollector::Collect( TUint /*aRequired*/ ) |
|
70 { |
|
71 iIsCollecting = ETrue; |
|
72 iGenerator->CollectMemory(); |
|
73 return 0; |
|
74 } |
|
75 #endif |
|
76 |
|
77 // LOCAL FUNCTION PROTOTYPES |
|
78 |
|
79 // FORWARD DECLARATIONS |
|
80 |
|
81 // ============================= LOCAL FUNCTIONS =============================== |
|
82 |
|
83 TInt StartAsyncUpdateCb( |
|
84 TAny* aPtr ) |
|
85 { |
|
86 TRAP_IGNORE(static_cast<CMinimapGenerator*>(aPtr)->StartAsyncBufferUpdateL()); |
|
87 return EFalse; |
|
88 } |
|
89 |
|
90 // ============================ MEMBER FUNCTIONS =============================== |
|
91 |
|
92 // ----------------------------------------------------------------------------- |
|
93 // CMinimapGenerator::CMinimapGenerator |
|
94 // C++ default constructor can NOT contain any code, that |
|
95 // might leave. |
|
96 // ----------------------------------------------------------------------------- |
|
97 // |
|
98 CMinimapGenerator::CMinimapGenerator(CMinimap& aMinimap) |
|
99 : iMinimap(&aMinimap) |
|
100 { |
|
101 } |
|
102 |
|
103 // ----------------------------------------------------------------------------- |
|
104 // CMinimapGenerator::ConstructL |
|
105 // Symbian 2nd phase constructor can leave. |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 void CMinimapGenerator::ConstructL() |
|
109 { |
|
110 iScaler = CMinimapScaler::NewL(*this); |
|
111 iAsyncUpdateStarted = CIdle::NewL(CActive::EPriorityIdle); |
|
112 #ifdef __OOM__ |
|
113 iOOMCollector = new (ELeave) CMinimapOOMCollector( this ); |
|
114 #endif |
|
115 } |
|
116 |
|
117 // ----------------------------------------------------------------------------- |
|
118 // CMinimapGenerator::NewL |
|
119 // Two-phased constructor. |
|
120 // ----------------------------------------------------------------------------- |
|
121 // |
|
122 CMinimapGenerator* CMinimapGenerator::NewL(CMinimap& aMinimap) |
|
123 { |
|
124 CMinimapGenerator* self = new( ELeave ) CMinimapGenerator(aMinimap); |
|
125 |
|
126 CleanupStack::PushL( self ); |
|
127 self->ConstructL(); |
|
128 CleanupStack::Pop(); |
|
129 |
|
130 return self; |
|
131 } |
|
132 |
|
133 |
|
134 // Destructor |
|
135 CMinimapGenerator::~CMinimapGenerator() |
|
136 { |
|
137 DeleteUnscaledBitmap(); |
|
138 DeleteBufferBitmap(); |
|
139 delete iScaler; |
|
140 delete iAsyncUpdateStarted; |
|
141 iValidLQRegion.Close(); |
|
142 iValidHQRegion.Close(); |
|
143 iVisitedRegion.Close(); |
|
144 #ifdef __OOM__ |
|
145 delete iOOMCollector; |
|
146 #endif |
|
147 } |
|
148 |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 // CMinimapGenerator::ScalingCompletedL |
|
152 // |
|
153 // This callback is called when a scaling operation completes |
|
154 // ----------------------------------------------------------------------------- |
|
155 // |
|
156 void CMinimapGenerator::ScalingCompletedL(CFbsBitmap& aResult, const TRect& aTargetRect) |
|
157 { |
|
158 if (!iBufferBitmap) |
|
159 { |
|
160 return; |
|
161 } |
|
162 TRect target(aTargetRect); |
|
163 TRect bufrect(BufferRect()); |
|
164 // maybe the buffer has been scrolled out while scaling was going on? |
|
165 if (target.Intersects(bufrect)) |
|
166 { |
|
167 // update the valid reqion |
|
168 iValidHQRegion.AddRect(target); |
|
169 iValidHQRegion.ClipRect(bufrect); |
|
170 iValidHQRegion.Tidy(); |
|
171 |
|
172 // blit the newly scaled area to correct position in buffer |
|
173 target.Move(-iBufferPos); |
|
174 iBufferBitmapGc->BitBlt(target.iTl, &aResult); |
|
175 } |
|
176 // search for next stripe to update |
|
177 TBool more = StartAsyncBufferUpdateL(); |
|
178 |
|
179 // delete unscaled bitmap if nothing more to do |
|
180 if (!more && !iKeepsBitmaps) |
|
181 { |
|
182 DeleteUnscaledBitmap(); |
|
183 } |
|
184 |
|
185 // signal the update |
|
186 iMinimap->Callback().ScaledPageChanged(iMinimap->Rect(), !more /*aReady*/, EFalse); |
|
187 } |
|
188 |
|
189 // ----------------------------------------------------------------------------- |
|
190 // CMinimapGenerator::Invalidate |
|
191 // |
|
192 // |
|
193 // ----------------------------------------------------------------------------- |
|
194 // |
|
195 void CMinimapGenerator::Invalidate() |
|
196 { |
|
197 TSize docSize(iMinimap->Callback().DocumentSize()); |
|
198 // if doc width changes, assume larger changes and invalidate low quality buffer too |
|
199 if (docSize.iWidth!=iDocSize.iWidth || (!iMinimap->IsDocumentComplete() && iMinimap->FullScreenMode())) |
|
200 { |
|
201 iValidLQRegion.Clear(); |
|
202 // iVisitedRegion.Clear(); |
|
203 } |
|
204 iDocSize = docSize; |
|
205 // otherwise only invalidate high quality areas to avoid lq<->hq flicker |
|
206 iValidHQRegion.Clear(); |
|
207 } |
|
208 |
|
209 // ----------------------------------------------------------------------------- |
|
210 // CMinimapGenerator::UpdateL |
|
211 // |
|
212 // |
|
213 // ----------------------------------------------------------------------------- |
|
214 // |
|
215 void CMinimapGenerator::UpdateL(TBool aScrolling) |
|
216 { |
|
217 TBool changes = FastBufferUpdateL(); |
|
218 |
|
219 if( !iMinimap->LowQuality() ) |
|
220 { |
|
221 if (changes && iScaler->IsActive()) |
|
222 { |
|
223 // FastBufferUpdateL uses the same bitmap, scaling op is no longer valid, have to cancel |
|
224 iScaler->Cancel(); |
|
225 } |
|
226 // if scaler is already active no need to restart it |
|
227 if (iMinimap->IsDocumentComplete() && !iAsyncUpdateStarted->IsActive() |
|
228 #ifdef __OOM__ |
|
229 && !iOOMCollector->IsCollecting() |
|
230 #endif |
|
231 ) |
|
232 { |
|
233 iAsyncUpdateStarted->Start(TCallBack( &StartAsyncUpdateCb, this)); |
|
234 } |
|
235 } |
|
236 |
|
237 if (changes) |
|
238 { |
|
239 iMinimap->Callback().ScaledPageChanged(iMinimap->Rect(), ETrue, aScrolling); |
|
240 } |
|
241 } |
|
242 |
|
243 // ----------------------------------------------------------------------------- |
|
244 // CMinimapGenerator::ScrollL |
|
245 // |
|
246 // |
|
247 // ----------------------------------------------------------------------------- |
|
248 // |
|
249 void CMinimapGenerator::ScrollL() |
|
250 { |
|
251 CalcBufferPosition(); |
|
252 } |
|
253 |
|
254 // ----------------------------------------------------------------------------- |
|
255 // CMinimapGenerator::Clear |
|
256 // |
|
257 // |
|
258 // ----------------------------------------------------------------------------- |
|
259 // |
|
260 void CMinimapGenerator::Clear() |
|
261 { |
|
262 iScaler->Cancel(); |
|
263 iValidLQRegion.Clear(); |
|
264 iValidHQRegion.Clear(); |
|
265 iVisitedRegion.Clear(); |
|
266 if (iBufferBitmapGc) |
|
267 { |
|
268 iBufferBitmapGc->Clear(); |
|
269 } |
|
270 if (iUnscaledBitmapGc) |
|
271 { |
|
272 iUnscaledBitmapGc->Clear(); |
|
273 } |
|
274 iBufferPos = TPoint(0,0); |
|
275 iDocSize = TSize(); |
|
276 } |
|
277 |
|
278 // ----------------------------------------------------------------------------- |
|
279 // CMinimapGenerator::CalcBufferPosition |
|
280 // |
|
281 // |
|
282 // ----------------------------------------------------------------------------- |
|
283 // |
|
284 void CMinimapGenerator::CalcBufferPosition() |
|
285 { |
|
286 if (!iBufferBitmap) |
|
287 { |
|
288 return; |
|
289 } |
|
290 TRect vpr(iMinimap->ViewportOnMinimap()); |
|
291 TPoint vpc(vpr.Center()); |
|
292 TRect bufrect(BufferRect()); |
|
293 TSize bufsize(bufrect.Size()); |
|
294 TPoint newPos(bufrect.iTl); |
|
295 TSize mmdocSize(iMinimap->FromDocCoords(iDocSize)); |
|
296 |
|
297 // check if view is outside center 1/3 of the buffer |
|
298 if (vpc.iY<iBufferPos.iY+bufsize.iHeight/3 || |
|
299 vpc.iY>iBufferPos.iY+bufsize.iHeight*2/3 ) |
|
300 { |
|
301 // recalc new pos |
|
302 newPos.iY = vpc.iY - bufsize.iHeight/2; |
|
303 if (newPos.iY+bufsize.iHeight>mmdocSize.iHeight) |
|
304 newPos.iY=mmdocSize.iHeight-bufsize.iHeight; |
|
305 if (newPos.iY<0) |
|
306 newPos.iY=0; |
|
307 } |
|
308 |
|
309 // scroll the buffer if needed |
|
310 TInt scrollAmount = newPos.iY-iBufferPos.iY; |
|
311 if (scrollAmount!=0) |
|
312 { |
|
313 // check if we need to move bitmap |
|
314 if (scrollAmount>0 && scrollAmount<bufsize.iHeight) |
|
315 { |
|
316 // scroll buffer down |
|
317 TRect from (TPoint(0,scrollAmount), TSize(bufsize.iWidth, bufsize.iHeight-scrollAmount)); |
|
318 // copy area that remains in buffer to a new position |
|
319 iBufferBitmapGc->CopyRect(TPoint(0,-scrollAmount), from); |
|
320 } |
|
321 else if (scrollAmount<0 && (-scrollAmount)<bufsize.iHeight) |
|
322 { |
|
323 // scroll buffer up |
|
324 TRect from (TPoint(0,0), TSize(bufsize.iWidth, bufsize.iHeight+scrollAmount)); |
|
325 // copy area that remains in buffer to a new position |
|
326 iBufferBitmapGc->CopyRect(TPoint(0,-scrollAmount), from); |
|
327 } |
|
328 // invalidate the areas that are out from the buffer due to scrolling |
|
329 iValidLQRegion.ClipRect(bufrect); |
|
330 iValidHQRegion.ClipRect(bufrect); |
|
331 } |
|
332 iBufferPos = newPos; |
|
333 } |
|
334 |
|
335 |
|
336 // ----------------------------------------------------------------------------- |
|
337 // CMinimapGenerator::FastBufferUpdate |
|
338 // |
|
339 // |
|
340 // ----------------------------------------------------------------------------- |
|
341 // |
|
342 TBool CMinimapGenerator::FastBufferUpdateL() |
|
343 { |
|
344 if (!CheckAndCreateBitmapsL()) |
|
345 { |
|
346 return EFalse; |
|
347 } |
|
348 |
|
349 TBool changes(EFalse); |
|
350 |
|
351 TRect vp(iMinimap->ViewportOnMinimap()); |
|
352 TRect bufrect(BufferRect()); |
|
353 TSize unscaledSize(iUnscaledBitmap->SizeInPixels()); |
|
354 |
|
355 TSize targetSize(iMinimap->FromDocCoords(unscaledSize)); |
|
356 |
|
357 // divide to unscaled bitmap height stripes |
|
358 TInt ypos = ((vp.iTl.iY - KExtraLQUpdateHeight)/targetSize.iHeight)*targetSize.iHeight; |
|
359 TInt yend(vp.iBr.iY + KExtraLQUpdateHeight); |
|
360 if (ypos<0) |
|
361 { |
|
362 ypos = 0; |
|
363 } |
|
364 if (yend>bufrect.iBr.iY) |
|
365 { |
|
366 yend = bufrect.iBr.iY; |
|
367 } |
|
368 // loop over the view area, checking if this stripe needs an update |
|
369 while (ypos<yend) |
|
370 { |
|
371 TRect target(TPoint(0,ypos),targetSize); |
|
372 TRect from(iMinimap->ToDocCoords(target).iTl,unscaledSize); |
|
373 |
|
374 // check if this area is already valid |
|
375 RRegion tempR; |
|
376 tempR.AddRect(target); |
|
377 tempR.ClipRect(bufrect); |
|
378 tempR.SubRegion(iValidLQRegion); |
|
379 tempR.SubRegion(iValidHQRegion); |
|
380 if (!tempR.IsEmpty()) |
|
381 { |
|
382 // mark area valid |
|
383 iValidLQRegion.AddRect(target); |
|
384 iValidLQRegion.ClipRect(bufrect); |
|
385 iValidLQRegion.Tidy(); |
|
386 |
|
387 // if not, get the bitmap from client |
|
388 iMinimap->Callback().DrawDocumentPart(*iUnscaledBitmapGc,iUnscaledBitmap,from); |
|
389 // scale down |
|
390 target.Move(-iBufferPos); |
|
391 iBufferBitmapGc->DrawBitmap(target,iUnscaledBitmap,TRect(unscaledSize)); |
|
392 |
|
393 changes = ETrue; |
|
394 } |
|
395 tempR.Close(); |
|
396 |
|
397 ypos += targetSize.iHeight; |
|
398 } |
|
399 return changes; |
|
400 } |
|
401 |
|
402 // ----------------------------------------------------------------------------- |
|
403 // CMinimapGenerator::StartAsyncBufferUpdateL |
|
404 // |
|
405 // |
|
406 // ----------------------------------------------------------------------------- |
|
407 // |
|
408 TBool CMinimapGenerator::StartAsyncBufferUpdateL() |
|
409 { |
|
410 |
|
411 if (!CheckAndCreateBitmapsL()) |
|
412 { |
|
413 return EFalse; |
|
414 } |
|
415 |
|
416 TRect vp(iMinimap->ViewportOnMinimap()); |
|
417 TRect bufrect(BufferRect()); |
|
418 TSize unscaledSize(iUnscaledBitmap->SizeInPixels()); |
|
419 |
|
420 TSize targetSize(iMinimap->FromDocCoords(unscaledSize)); |
|
421 |
|
422 // divide to unscaled bitmap height stripes |
|
423 TInt ypos(((vp.iTl.iY - KExtraUpdateHeightTop)/targetSize.iHeight)*targetSize.iHeight); |
|
424 TInt yend(vp.iBr.iY + KExtraUpdateHeightBottom); |
|
425 if (ypos<bufrect.iTl.iY) |
|
426 { |
|
427 ypos = bufrect.iTl.iY; |
|
428 } |
|
429 if (yend>bufrect.iBr.iY) |
|
430 { |
|
431 yend = bufrect.iBr.iY; |
|
432 } |
|
433 // loop over the view area, searching for a stripe that needs an update |
|
434 while (ypos<yend) |
|
435 { |
|
436 // update this area |
|
437 TRect target(TPoint(0,ypos),targetSize); |
|
438 // from here |
|
439 TRect from(iMinimap->ToDocCoords(target).iTl,unscaledSize); |
|
440 |
|
441 // check if this area is already valid in high quality region |
|
442 RRegion tempR; |
|
443 tempR.AddRect(target); |
|
444 tempR.ClipRect(bufrect); |
|
445 tempR.SubRegion(iValidHQRegion); |
|
446 if (!tempR.IsEmpty()) |
|
447 { |
|
448 tempR.Close(); |
|
449 // if not, get the bitmap from client |
|
450 iMinimap->Callback().DrawDocumentPart(*iUnscaledBitmapGc,iUnscaledBitmap,from); |
|
451 // scale asynchronously |
|
452 iScaler->StartScalingL(*iUnscaledBitmap,target); |
|
453 // update started, get out |
|
454 return ETrue; |
|
455 } |
|
456 tempR.Close(); |
|
457 |
|
458 ypos += targetSize.iHeight; |
|
459 } |
|
460 // nothing to do |
|
461 return EFalse; |
|
462 } |
|
463 |
|
464 // ----------------------------------------------------------------------------- |
|
465 // CMinimapGenerator::CheckAndCreateBitmapsL |
|
466 // |
|
467 // |
|
468 // ----------------------------------------------------------------------------- |
|
469 // |
|
470 TBool CMinimapGenerator::CheckAndCreateBitmapsL() |
|
471 { |
|
472 #ifdef __OOM__ |
|
473 if( iOOMCollector->IsCollecting() ) return EFalse; |
|
474 #endif |
|
475 TSize docSize(iDocSize); |
|
476 // minmap won't cover ridiculously wide document fully in horizontal |
|
477 // direction to avoid stripes from getting too wide/low |
|
478 if (docSize.iWidth > KMaxDocWidth) |
|
479 { |
|
480 docSize.iWidth = KMaxDocWidth; |
|
481 } |
|
482 TSize mmdocSize(iMinimap->FromDocCoords(docSize)); |
|
483 TSize bufsize; |
|
484 TSize unscaledsize; |
|
485 if (mmdocSize.iWidth!=0 && docSize.iWidth!=0) |
|
486 { |
|
487 bufsize = TSize(mmdocSize.iWidth, Min(mmdocSize.iHeight,KBufferBitmapSize/mmdocSize.iWidth)); |
|
488 unscaledsize = TSize(docSize.iWidth, Min(docSize.iHeight,KUnscaledBitmapSize/docSize.iWidth)); |
|
489 if (!iUnscaledBitmap || unscaledsize != iUnscaledBitmap->SizeInPixels()) |
|
490 { |
|
491 // cancel scaling since we might delete the bitmap |
|
492 iScaler->Cancel(); |
|
493 } |
|
494 } |
|
495 TRAPD(err, |
|
496 if (iMinimap->CheckAndCreateBitmapL(bufsize,iBufferBitmap,iBufferBitmapDevice,iBufferBitmapGc)) |
|
497 { |
|
498 iMinimap->CheckAndCreateBitmapL(unscaledsize,iUnscaledBitmap,iUnscaledBitmapDevice,iUnscaledBitmapGc); |
|
499 } |
|
500 ) |
|
501 |
|
502 if( err != KErrNone ) |
|
503 { |
|
504 DeleteUnscaledBitmap(); |
|
505 DeleteBufferBitmap(); |
|
506 } |
|
507 |
|
508 return iBufferBitmap!=0 && iUnscaledBitmap!=0; |
|
509 } |
|
510 |
|
511 |
|
512 |
|
513 // ----------------------------------------------------------------------------- |
|
514 // CMinimapGenerator::DeleteUnscaledBitmap |
|
515 // |
|
516 // |
|
517 // ----------------------------------------------------------------------------- |
|
518 // |
|
519 void CMinimapGenerator::DeleteUnscaledBitmap() |
|
520 { |
|
521 delete iUnscaledBitmapGc; |
|
522 delete iUnscaledBitmapDevice; |
|
523 delete iUnscaledBitmap; |
|
524 iUnscaledBitmapGc = 0; |
|
525 iUnscaledBitmapDevice = 0; |
|
526 iUnscaledBitmap = 0; |
|
527 } |
|
528 |
|
529 // ----------------------------------------------------------------------------- |
|
530 // CMinimapGenerator::DeleteBufferBitmap |
|
531 // |
|
532 // |
|
533 // ----------------------------------------------------------------------------- |
|
534 // |
|
535 void CMinimapGenerator::DeleteBufferBitmap() |
|
536 { |
|
537 delete iBufferBitmapGc; |
|
538 delete iBufferBitmapDevice; |
|
539 delete iBufferBitmap; |
|
540 iBufferBitmapGc = 0; |
|
541 iBufferBitmapDevice = 0; |
|
542 iBufferBitmap = 0; |
|
543 } |
|
544 |
|
545 // ----------------------------------------------------------------------------- |
|
546 // CMinimapGenerator::BufferRect |
|
547 // |
|
548 // |
|
549 // ----------------------------------------------------------------------------- |
|
550 // |
|
551 TRect CMinimapGenerator::BufferRect() const |
|
552 { |
|
553 return TRect(iBufferPos, iBufferBitmap->SizeInPixels()); |
|
554 } |
|
555 |
|
556 |
|
557 // ----------------------------------------------------------------------------- |
|
558 // CMinimapGenerator::SetKeepsBitmaps |
|
559 // |
|
560 // |
|
561 // ----------------------------------------------------------------------------- |
|
562 // |
|
563 void CMinimapGenerator::SetKeepsBitmaps(TBool aKeepsBitmaps) |
|
564 { |
|
565 iKeepsBitmaps = aKeepsBitmaps; |
|
566 // delete bitmap if no scaling active |
|
567 if (!iKeepsBitmaps && !iScaler->IsActive()) |
|
568 { |
|
569 DeleteUnscaledBitmap(); |
|
570 } |
|
571 } |
|
572 |
|
573 |
|
574 // ----------------------------------------------------------------------------- |
|
575 // CMinimapGenerator::KeepsBitmaps |
|
576 // |
|
577 // |
|
578 // ----------------------------------------------------------------------------- |
|
579 // |
|
580 TBool CMinimapGenerator::KeepsBitmaps() const |
|
581 { |
|
582 return iKeepsBitmaps; |
|
583 } |
|
584 |
|
585 |
|
586 // ----------------------------------------------------------------------------- |
|
587 // CMinimapGenerator::DrawT |
|
588 // |
|
589 // Template to support both CWindowGc and CFbsBitGc |
|
590 // ----------------------------------------------------------------------------- |
|
591 // |
|
592 template<class GC> void CMinimapGenerator::DrawT(GC& aGc, const TRect& aTo) const |
|
593 { |
|
594 if (!iBufferBitmap) |
|
595 { |
|
596 return; |
|
597 } |
|
598 |
|
599 TRect vp(iMinimap->ViewportOnMinimap()); |
|
600 |
|
601 TRect from(vp.iTl-iBufferPos, aTo.Size()); |
|
602 from.Intersection(TRect(iBufferBitmap->SizeInPixels())); |
|
603 |
|
604 if (aTo.Size()!=from.Size()) |
|
605 { |
|
606 aGc.SetBrushColor(TRgb(0xff,0xff,0xff)); |
|
607 aGc.SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
608 aGc.SetPenStyle(CGraphicsContext::ENullPen); |
|
609 aGc.DrawRect(aTo); |
|
610 } |
|
611 |
|
612 if (!from.IsEmpty()) |
|
613 { |
|
614 aGc.BitBlt(aTo.iTl, iBufferBitmap, from); |
|
615 } |
|
616 } |
|
617 |
|
618 // ----------------------------------------------------------------------------- |
|
619 // CMinimapGenerator::Draw |
|
620 // |
|
621 // |
|
622 // ----------------------------------------------------------------------------- |
|
623 // |
|
624 void CMinimapGenerator::Draw(CFbsBitGc& aGc, const TRect& aTo) const |
|
625 { |
|
626 DrawT(aGc,aTo); |
|
627 } |
|
628 |
|
629 // ----------------------------------------------------------------------------- |
|
630 // CMinimapGenerator::Draw |
|
631 // |
|
632 // |
|
633 // ----------------------------------------------------------------------------- |
|
634 // |
|
635 void CMinimapGenerator::Draw(CWindowGc& aGc, const TRect& aTo) const |
|
636 { |
|
637 DrawT(aGc,aTo); |
|
638 } |
|
639 |
|
640 // ----------------------------------------------------------------------------- |
|
641 // CMinimapGenerator::DrawColoringMaskT |
|
642 // |
|
643 // Template to support both CWindowGc and CFbsBitGc |
|
644 // ----------------------------------------------------------------------------- |
|
645 // |
|
646 template<class GC> void CMinimapGenerator::DrawColoringMaskT(GC& aGc, const TRect& aMinimapViewportOnDoc) const |
|
647 { |
|
648 RRegion temp; |
|
649 temp.Copy(iVisitedRegion); |
|
650 temp.ClipRect(aMinimapViewportOnDoc); |
|
651 aGc.SetBrushColor(TRgb(0, 0, 0)); |
|
652 |
|
653 for(TInt i = 0; i<temp.Count(); i++) |
|
654 { |
|
655 TRect vp(temp[i]); |
|
656 TRect minimapVp(iMinimap->ViewportOnDocument()); |
|
657 vp.Move(-minimapVp.iTl); //make vp relative to minimapVp |
|
658 TRect res = iMinimap->FromDocCoords(vp); //translate vp to mmap coords |
|
659 // borders |
|
660 res.Move(1,1); |
|
661 // so that view area is within the indicator |
|
662 res.Grow(1,1); |
|
663 |
|
664 aGc.DrawRect(res); |
|
665 } |
|
666 temp.Close(); |
|
667 } |
|
668 |
|
669 |
|
670 // ----------------------------------------------------------------------------- |
|
671 // CMinimapGenerator::DrawColoringMask |
|
672 // |
|
673 // |
|
674 // ----------------------------------------------------------------------------- |
|
675 // |
|
676 void CMinimapGenerator::DrawColoringMask(CFbsBitGc& aGc, const TRect& aMinimapViewportOnDoc) const |
|
677 { |
|
678 DrawColoringMaskT(aGc,aMinimapViewportOnDoc); |
|
679 } |
|
680 |
|
681 |
|
682 // ----------------------------------------------------------------------------- |
|
683 // CMinimapGenerator::DrawColoringMask |
|
684 // |
|
685 // |
|
686 // ----------------------------------------------------------------------------- |
|
687 // |
|
688 void CMinimapGenerator::DrawColoringMask(CWindowGc& aGc, const TRect& aMinimapViewportOnDoc) const |
|
689 { |
|
690 DrawColoringMaskT(aGc,aMinimapViewportOnDoc); |
|
691 } |
|
692 |
|
693 // ----------------------------------------------------------------------------- |
|
694 // CMinimapGenerator::VisitArea |
|
695 // |
|
696 // |
|
697 // ----------------------------------------------------------------------------- |
|
698 // |
|
699 void CMinimapGenerator::VisitArea(const TRect &aArea) |
|
700 { |
|
701 iVisitedRegion.AddRect(aArea); |
|
702 iVisitedRegion.Tidy(); |
|
703 } |
|
704 |
|
705 // ----------------------------------------------------------------------------- |
|
706 // CMinimap::ScaledPage |
|
707 // |
|
708 // Scaled Page |
|
709 // ----------------------------------------------------------------------------- |
|
710 // |
|
711 CFbsBitmap* CMinimapGenerator::ScaledPage() const |
|
712 { |
|
713 return iBufferBitmap; |
|
714 } |
|
715 |
|
716 #ifdef __OOM__ |
|
717 TBool CMinimapGenerator::IsCollectingMemory() |
|
718 { |
|
719 return iOOMCollector->IsCollecting(); |
|
720 } |
|
721 |
|
722 void CMinimapGenerator::CollectMemory() |
|
723 { |
|
724 if( iScaler->IsActive() ) iScaler->Cancel(); |
|
725 DeleteUnscaledBitmap(); |
|
726 DeleteBufferBitmap(); |
|
727 |
|
728 iMinimap->DeleteMinimapBitmap(); |
|
729 } |
|
730 #endif |
|
731 |
|
732 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
733 |
|
734 |
|
735 // End of File |