|
1 /* |
|
2 * Copyright (c) 2009 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "hgvgimagepool.h" |
|
19 #include "trace.h" |
|
20 |
|
21 HgVgImagePool::HgVgImagePool(int numImages, int imgWidth, int imgHeight, bool alpha) |
|
22 { |
|
23 for (int i = 0; i < numImages; i++) |
|
24 { |
|
25 VGImage vgimage = vgCreateImage(alpha ? VG_sARGB_8888 : VG_sRGB_565, |
|
26 imgWidth, imgHeight,VG_IMAGE_QUALITY_NONANTIALIASED); |
|
27 |
|
28 mFreeImages.push_back(vgimage); |
|
29 } |
|
30 } |
|
31 HgVgImagePool::~HgVgImagePool() |
|
32 { |
|
33 QLinkedList<VGImage>::const_iterator it = mUsedImages.begin(); |
|
34 while (it != mUsedImages.end()) |
|
35 { |
|
36 vgDestroyImage((*it)); |
|
37 it++; |
|
38 } |
|
39 |
|
40 QLinkedList<VGImage>::const_iterator it2 = mFreeImages.begin(); |
|
41 while (it2 != mFreeImages.end()) |
|
42 { |
|
43 vgDestroyImage((*it2)); |
|
44 it2++; |
|
45 } |
|
46 |
|
47 } |
|
48 void HgVgImagePool::releaseImage(VGImage image) |
|
49 { |
|
50 if (image == VG_INVALID_HANDLE) |
|
51 return; |
|
52 |
|
53 for (QLinkedList<VGImage>::iterator it = mUsedImages.begin(); |
|
54 it != mUsedImages.end(); ++it) |
|
55 { |
|
56 if ((*it) == image) |
|
57 { |
|
58 mUsedImages.erase(it); |
|
59 break; |
|
60 } |
|
61 } |
|
62 vgClearImage(image, 0, 0, vgGetParameteri(image, VG_IMAGE_WIDTH), vgGetParameteri(image, VG_IMAGE_HEIGHT)); |
|
63 mFreeImages.push_back(image); |
|
64 } |
|
65 |
|
66 VGImage HgVgImagePool::getImage() |
|
67 { |
|
68 FUNC_LOG |
|
69 |
|
70 if (mFreeImages.empty()) |
|
71 { |
|
72 INFO("Hg: Run out of images!"); |
|
73 |
|
74 // if no free images left, use the one which was allocated |
|
75 // longer ago |
|
76 QLinkedList<VGImage>::iterator i = mUsedImages.begin(); |
|
77 VGImage img = *i; |
|
78 mUsedImages.erase(i); |
|
79 mUsedImages.push_back(img); |
|
80 return img; |
|
81 } |
|
82 |
|
83 QLinkedList<VGImage>::iterator i = mFreeImages.begin(); |
|
84 VGImage img = *i; |
|
85 mUsedImages.push_back(img); |
|
86 mFreeImages.erase(i); |
|
87 |
|
88 return img; |
|
89 } |