]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/HiiDatabaseDxe/ImageEx.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdeModulePkg / Universal / HiiDatabaseDxe / ImageEx.c
CommitLineData
101a1122
RN
1/** @file\r
2Implementation for EFI_HII_IMAGE_EX_PROTOCOL.\r
3\r
4\r
5Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
9d510e61 6SPDX-License-Identifier: BSD-2-Clause-Patent\r
101a1122
RN
7\r
8**/\r
9\r
101a1122
RN
10#include "HiiDatabase.h"\r
11\r
12/**\r
13 The prototype of this extension function is the same with EFI_HII_IMAGE_PROTOCOL.NewImage().\r
14 This protocol invokes EFI_HII_IMAGE_PROTOCOL.NewImage() implicitly.\r
15\r
16 @param This A pointer to the EFI_HII_IMAGE_EX_PROTOCOL instance.\r
17 @param PackageList Handle of the package list where this image will\r
18 be added.\r
19 @param ImageId On return, contains the new image id, which is\r
20 unique within PackageList.\r
21 @param Image Points to the image.\r
22\r
23 @retval EFI_SUCCESS The new image was added successfully.\r
24 @retval EFI_NOT_FOUND The PackageList could not be found.\r
25 @retval EFI_OUT_OF_RESOURCES Could not add the image due to lack of resources.\r
26 @retval EFI_INVALID_PARAMETER Image is NULL or ImageId is NULL.\r
27**/\r
28EFI_STATUS\r
29EFIAPI\r
30HiiNewImageEx (\r
1436aea4
MK
31 IN CONST EFI_HII_IMAGE_EX_PROTOCOL *This,\r
32 IN EFI_HII_HANDLE PackageList,\r
33 OUT EFI_IMAGE_ID *ImageId,\r
34 IN CONST EFI_IMAGE_INPUT *Image\r
101a1122
RN
35 )\r
36{\r
1436aea4 37 HII_DATABASE_PRIVATE_DATA *Private;\r
101a1122
RN
38\r
39 Private = HII_IMAGE_EX_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r
40 return HiiNewImage (&Private->HiiImage, PackageList, ImageId, Image);\r
41}\r
42\r
43/**\r
44 Return the information about the image, associated with the package list.\r
45 The prototype of this extension function is the same with EFI_HII_IMAGE_PROTOCOL.GetImage().\r
46\r
47 This function is similar to EFI_HII_IMAGE_PROTOCOL.GetImage().The difference is that\r
48 this function will locate all EFI_HII_IMAGE_DECODER_PROTOCOL instances installed in the\r
49 system if the decoder of the certain image type is not supported by the\r
50 EFI_HII_IMAGE_EX_PROTOCOL. The function will attempt to decode the image to the\r
51 EFI_IMAGE_INPUT using the first EFI_HII_IMAGE_DECODER_PROTOCOL instance that\r
52 supports the requested image type.\r
53\r
54 @param This A pointer to the EFI_HII_IMAGE_EX_PROTOCOL instance.\r
55 @param PackageList The package list in the HII database to search for the\r
56 specified image.\r
57 @param ImageId The image's id, which is unique within PackageList.\r
58 @param Image Points to the image.\r
59\r
60 @retval EFI_SUCCESS The new image was returned successfully.\r
61 @retval EFI_NOT_FOUND The image specified by ImageId is not available. The specified\r
62 PackageList is not in the Database.\r
63 @retval EFI_INVALID_PARAMETER Image was NULL or ImageId was 0.\r
64 @retval EFI_OUT_OF_RESOURCES The bitmap could not be retrieved because there\r
65 was not enough memory.\r
66\r
67**/\r
68EFI_STATUS\r
69EFIAPI\r
70HiiGetImageEx (\r
1436aea4
MK
71 IN CONST EFI_HII_IMAGE_EX_PROTOCOL *This,\r
72 IN EFI_HII_HANDLE PackageList,\r
73 IN EFI_IMAGE_ID ImageId,\r
74 OUT EFI_IMAGE_INPUT *Image\r
101a1122
RN
75 )\r
76{\r
1436aea4 77 HII_DATABASE_PRIVATE_DATA *Private;\r
101a1122
RN
78\r
79 Private = HII_IMAGE_EX_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r
80 return IGetImage (&Private->DatabaseList, PackageList, ImageId, Image, FALSE);\r
81}\r
82\r
101a1122
RN
83/**\r
84 Change the information about the image.\r
85\r
86 Same with EFI_HII_IMAGE_PROTOCOL.SetImage(),this protocol invokes\r
87 EFI_HII_IMAGE_PROTOCOL.SetImage()implicitly.\r
88\r
89 @param This A pointer to the EFI_HII_IMAGE_EX_PROTOCOL instance.\r
90 @param PackageList The package list containing the images.\r
91 @param ImageId The image's id, which is unique within PackageList.\r
92 @param Image Points to the image.\r
93\r
94 @retval EFI_SUCCESS The new image was successfully updated.\r
95 @retval EFI_NOT_FOUND The image specified by ImageId is not in the\r
96 database. The specified PackageList is not in\r
97 the database.\r
98 @retval EFI_INVALID_PARAMETER The Image was NULL, the ImageId was 0 or\r
99 the Image->Bitmap was NULL.\r
100\r
101**/\r
102EFI_STATUS\r
103EFIAPI\r
104HiiSetImageEx (\r
1436aea4
MK
105 IN CONST EFI_HII_IMAGE_EX_PROTOCOL *This,\r
106 IN EFI_HII_HANDLE PackageList,\r
107 IN EFI_IMAGE_ID ImageId,\r
108 IN CONST EFI_IMAGE_INPUT *Image\r
101a1122
RN
109 )\r
110{\r
1436aea4
MK
111 HII_DATABASE_PRIVATE_DATA *Private;\r
112\r
101a1122
RN
113 Private = HII_IMAGE_EX_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r
114 return HiiSetImage (&Private->HiiImage, PackageList, ImageId, Image);\r
115}\r
116\r
101a1122
RN
117/**\r
118 Renders an image to a bitmap or to the display.\r
119\r
120 The prototype of this extension function is the same with\r
121 EFI_HII_IMAGE_PROTOCOL.DrawImage(). This protocol invokes\r
122 EFI_HII_IMAGE_PROTOCOL.DrawImage() implicitly.\r
123\r
124 @param This A pointer to the EFI_HII_IMAGE_EX_PROTOCOL instance.\r
125 @param Flags Describes how the image is to be drawn.\r
126 @param Image Points to the image to be displayed.\r
127 @param Blt If this points to a non-NULL on entry, this points\r
128 to the image, which is Width pixels wide and\r
129 Height pixels high. The image will be drawn onto\r
130 this image and EFI_HII_DRAW_FLAG_CLIP is implied.\r
131 If this points to a NULL on entry, then a buffer\r
132 will be allocated to hold the generated image and\r
133 the pointer updated on exit. It is the caller's\r
134 responsibility to free this buffer.\r
135 @param BltX Specifies the offset from the left and top edge of\r
136 the output image of the first pixel in the image.\r
137 @param BltY Specifies the offset from the left and top edge of\r
138 the output image of the first pixel in the image.\r
139\r
140 @retval EFI_SUCCESS The image was successfully drawn.\r
141 @retval EFI_OUT_OF_RESOURCES Unable to allocate an output buffer for Blt.\r
142 @retval EFI_INVALID_PARAMETER The Image or Blt was NULL.\r
143\r
144**/\r
145EFI_STATUS\r
146EFIAPI\r
147HiiDrawImageEx (\r
1436aea4
MK
148 IN CONST EFI_HII_IMAGE_EX_PROTOCOL *This,\r
149 IN EFI_HII_DRAW_FLAGS Flags,\r
150 IN CONST EFI_IMAGE_INPUT *Image,\r
151 IN OUT EFI_IMAGE_OUTPUT **Blt,\r
152 IN UINTN BltX,\r
153 IN UINTN BltY\r
101a1122
RN
154 )\r
155{\r
1436aea4
MK
156 HII_DATABASE_PRIVATE_DATA *Private;\r
157\r
101a1122
RN
158 Private = HII_IMAGE_EX_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r
159 return HiiDrawImage (&Private->HiiImage, Flags, Image, Blt, BltX, BltY);\r
160}\r
161\r
101a1122
RN
162/**\r
163 Renders an image to a bitmap or the screen containing the contents of the specified\r
164 image.\r
165\r
166 This function is similar to EFI_HII_IMAGE_PROTOCOL.DrawImageId(). The difference is that\r
167 this function will locate all EFI_HII_IMAGE_DECODER_PROTOCOL instances installed in the\r
168 system if the decoder of the certain image type is not supported by the\r
169 EFI_HII_IMAGE_EX_PROTOCOL. The function will attempt to decode the image to the\r
170 EFI_IMAGE_INPUT using the first EFI_HII_IMAGE_DECODER_PROTOCOL instance that\r
171 supports the requested image type.\r
172\r
173 @param This A pointer to the EFI_HII_IMAGE_EX_PROTOCOL instance.\r
174 @param Flags Describes how the image is to be drawn.\r
175 @param PackageList The package list in the HII database to search for\r
176 the specified image.\r
177 @param ImageId The image's id, which is unique within PackageList.\r
178 @param Blt If this points to a non-NULL on entry, this points\r
179 to the image, which is Width pixels wide and\r
180 Height pixels high. The image will be drawn onto\r
181 this image and EFI_HII_DRAW_FLAG_CLIP is implied.\r
182 If this points to a NULL on entry, then a buffer\r
183 will be allocated to hold the generated image\r
184 and the pointer updated on exit. It is the caller's\r
185 responsibility to free this buffer.\r
186 @param BltX Specifies the offset from the left and top edge of\r
187 the output image of the first pixel in the image.\r
188 @param BltY Specifies the offset from the left and top edge of\r
189 the output image of the first pixel in the image.\r
190\r
191 @retval EFI_SUCCESS The image was successfully drawn.\r
192 @retval EFI_OUT_OF_RESOURCES Unable to allocate an output buffer for Blt.\r
193 @retval EFI_INVALID_PARAMETER The Blt was NULL or ImageId was 0.\r
194 @retval EFI_NOT_FOUND The image specified by ImageId is not in the database.\r
195 The specified PackageList is not in the database.\r
196\r
197**/\r
198EFI_STATUS\r
199EFIAPI\r
200HiiDrawImageIdEx (\r
1436aea4
MK
201 IN CONST EFI_HII_IMAGE_EX_PROTOCOL *This,\r
202 IN EFI_HII_DRAW_FLAGS Flags,\r
203 IN EFI_HII_HANDLE PackageList,\r
204 IN EFI_IMAGE_ID ImageId,\r
205 IN OUT EFI_IMAGE_OUTPUT **Blt,\r
206 IN UINTN BltX,\r
207 IN UINTN BltY\r
101a1122
RN
208 )\r
209{\r
1436aea4
MK
210 EFI_STATUS Status;\r
211 EFI_IMAGE_INPUT Image;\r
101a1122
RN
212\r
213 //\r
214 // Check input parameter.\r
215 //\r
1436aea4 216 if ((This == NULL) || (Blt == NULL)) {\r
101a1122
RN
217 return EFI_INVALID_PARAMETER;\r
218 }\r
219\r
220 //\r
221 // Get the specified Image.\r
222 //\r
223 Status = HiiGetImageEx (This, PackageList, ImageId, &Image);\r
224 if (EFI_ERROR (Status)) {\r
225 return Status;\r
226 }\r
227\r
228 //\r
229 // Draw this image.\r
230 //\r
231 Status = HiiDrawImageEx (This, Flags, &Image, Blt, BltX, BltY);\r
232 if (Image.Bitmap != NULL) {\r
233 FreePool (Image.Bitmap);\r
234 }\r
1436aea4 235\r
101a1122
RN
236 return Status;\r
237}\r
238\r
239/**\r
240 Return the first HII image decoder instance which supports the DecoderName.\r
241\r
242 @param BlockType The image block type.\r
243\r
244 @retval Pointer to the HII image decoder instance.\r
245**/\r
246EFI_HII_IMAGE_DECODER_PROTOCOL *\r
247LocateHiiImageDecoder (\r
1436aea4 248 UINT8 BlockType\r
101a1122
RN
249 )\r
250{\r
1436aea4
MK
251 EFI_STATUS Status;\r
252 EFI_HII_IMAGE_DECODER_PROTOCOL *Decoder;\r
253 EFI_HANDLE *Handles;\r
254 UINTN HandleNum;\r
255 UINTN Index;\r
256 EFI_GUID *DecoderNames;\r
257 UINT16 NumberOfDecoderName;\r
258 UINT16 DecoderNameIndex;\r
259 EFI_GUID *DecoderName;\r
101a1122
RN
260\r
261 switch (BlockType) {\r
1436aea4
MK
262 case EFI_HII_IIBT_IMAGE_JPEG:\r
263 DecoderName = &gEfiHiiImageDecoderNameJpegGuid;\r
264 break;\r
101a1122 265\r
1436aea4
MK
266 case EFI_HII_IIBT_IMAGE_PNG:\r
267 DecoderName = &gEfiHiiImageDecoderNamePngGuid;\r
268 break;\r
101a1122 269\r
1436aea4
MK
270 default:\r
271 ASSERT (FALSE);\r
272 return NULL;\r
101a1122
RN
273 }\r
274\r
275 Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiHiiImageDecoderProtocolGuid, NULL, &HandleNum, &Handles);\r
276 if (EFI_ERROR (Status)) {\r
277 return NULL;\r
278 }\r
1436aea4 279\r
101a1122 280 for (Index = 0; Index < HandleNum; Index++) {\r
1436aea4 281 Status = gBS->HandleProtocol (Handles[Index], &gEfiHiiImageDecoderProtocolGuid, (VOID **)&Decoder);\r
101a1122
RN
282 if (EFI_ERROR (Status)) {\r
283 continue;\r
284 }\r
285\r
286 Status = Decoder->GetImageDecoderName (Decoder, &DecoderNames, &NumberOfDecoderName);\r
287 if (EFI_ERROR (Status)) {\r
288 continue;\r
289 }\r
1436aea4 290\r
101a1122
RN
291 for (DecoderNameIndex = 0; DecoderNameIndex < NumberOfDecoderName; DecoderNameIndex++) {\r
292 if (CompareGuid (DecoderName, &DecoderNames[DecoderNameIndex])) {\r
293 return Decoder;\r
294 }\r
295 }\r
296 }\r
297\r
298 return NULL;\r
299}\r
300\r
301/**\r
302 This function returns the image information to EFI_IMAGE_OUTPUT. Only the width\r
303 and height are returned to the EFI_IMAGE_OUTPUT instead of decoding the image\r
304 to the buffer. This function is used to get the geometry of the image. This function\r
305 will try to locate all of the EFI_HII_IMAGE_DECODER_PROTOCOL installed on the\r
306 system if the decoder of image type is not supported by the EFI_HII_IMAGE_EX_PROTOCOL.\r
307\r
308 @param This A pointer to the EFI_HII_IMAGE_EX_PROTOCOL instance.\r
309 @param PackageList Handle of the package list where this image will\r
310 be searched.\r
311 @param ImageId The image's id, which is unique within PackageList.\r
312 @param Image Points to the image.\r
313\r
314 @retval EFI_SUCCESS The new image was returned successfully.\r
315 @retval EFI_NOT_FOUND The image specified by ImageId is not in the\r
316 database. The specified PackageList is not in the database.\r
317 @retval EFI_BUFFER_TOO_SMALL The buffer specified by ImageSize is too small to\r
318 hold the image.\r
319 @retval EFI_INVALID_PARAMETER The Image was NULL or the ImageId was 0.\r
320 @retval EFI_OUT_OF_RESOURCES The bitmap could not be retrieved because there\r
321 was not enough memory.\r
322\r
323**/\r
324EFI_STATUS\r
325EFIAPI\r
326HiiGetImageInfo (\r
1436aea4
MK
327 IN CONST EFI_HII_IMAGE_EX_PROTOCOL *This,\r
328 IN EFI_HII_HANDLE PackageList,\r
329 IN EFI_IMAGE_ID ImageId,\r
330 OUT EFI_IMAGE_OUTPUT *Image\r
101a1122
RN
331 )\r
332{\r
1436aea4
MK
333 EFI_STATUS Status;\r
334 HII_DATABASE_PRIVATE_DATA *Private;\r
335 HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageListNode;\r
336 HII_IMAGE_PACKAGE_INSTANCE *ImagePackage;\r
337 EFI_HII_IMAGE_BLOCK *CurrentImageBlock;\r
338 EFI_HII_IMAGE_DECODER_PROTOCOL *Decoder;\r
339 EFI_HII_IMAGE_DECODER_IMAGE_INFO_HEADER *ImageInfo;\r
340\r
341 if ((Image == NULL) || (ImageId == 0)) {\r
101a1122
RN
342 return EFI_INVALID_PARAMETER;\r
343 }\r
344\r
1436aea4 345 Private = HII_IMAGE_EX_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r
101a1122
RN
346 PackageListNode = LocatePackageList (&Private->DatabaseList, PackageList);\r
347 if (PackageListNode == NULL) {\r
348 return EFI_NOT_FOUND;\r
349 }\r
1436aea4 350\r
101a1122
RN
351 ImagePackage = PackageListNode->ImagePkg;\r
352 if (ImagePackage == NULL) {\r
353 return EFI_NOT_FOUND;\r
354 }\r
355\r
356 //\r
357 // Find the image block specified by ImageId\r
358 //\r
359 CurrentImageBlock = GetImageIdOrAddress (ImagePackage->ImageBlock, &ImageId);\r
4558491f
RN
360 if (CurrentImageBlock == NULL) {\r
361 return EFI_NOT_FOUND;\r
362 }\r
363\r
101a1122 364 switch (CurrentImageBlock->BlockType) {\r
1436aea4
MK
365 case EFI_HII_IIBT_IMAGE_JPEG:\r
366 case EFI_HII_IIBT_IMAGE_PNG:\r
367 Decoder = LocateHiiImageDecoder (CurrentImageBlock->BlockType);\r
368 if (Decoder == NULL) {\r
369 return EFI_UNSUPPORTED;\r
370 }\r
371\r
372 //\r
373 // Use the common block code since the definition of two structures is the same.\r
374 //\r
375 ASSERT (OFFSET_OF (EFI_HII_IIBT_JPEG_BLOCK, Data) == OFFSET_OF (EFI_HII_IIBT_PNG_BLOCK, Data));\r
376 ASSERT (\r
377 sizeof (((EFI_HII_IIBT_JPEG_BLOCK *)CurrentImageBlock)->Data) ==\r
378 sizeof (((EFI_HII_IIBT_PNG_BLOCK *)CurrentImageBlock)->Data)\r
379 );\r
380 ASSERT (OFFSET_OF (EFI_HII_IIBT_JPEG_BLOCK, Size) == OFFSET_OF (EFI_HII_IIBT_PNG_BLOCK, Size));\r
381 ASSERT (\r
382 sizeof (((EFI_HII_IIBT_JPEG_BLOCK *)CurrentImageBlock)->Size) ==\r
383 sizeof (((EFI_HII_IIBT_PNG_BLOCK *)CurrentImageBlock)->Size)\r
384 );\r
385 Status = Decoder->GetImageInfo (\r
386 Decoder,\r
387 ((EFI_HII_IIBT_JPEG_BLOCK *)CurrentImageBlock)->Data,\r
388 ((EFI_HII_IIBT_JPEG_BLOCK *)CurrentImageBlock)->Size,\r
389 &ImageInfo\r
390 );\r
391\r
392 //\r
393 // Spec requires to use the first capable image decoder instance.\r
394 // The first image decoder instance may fail to decode the image.\r
395 //\r
396 if (!EFI_ERROR (Status)) {\r
397 Image->Height = ImageInfo->ImageHeight;\r
398 Image->Width = ImageInfo->ImageWidth;\r
399 Image->Image.Bitmap = NULL;\r
400 FreePool (ImageInfo);\r
401 }\r
402\r
403 return Status;\r
404\r
405 case EFI_HII_IIBT_IMAGE_1BIT_TRANS:\r
406 case EFI_HII_IIBT_IMAGE_4BIT_TRANS:\r
407 case EFI_HII_IIBT_IMAGE_8BIT_TRANS:\r
408 case EFI_HII_IIBT_IMAGE_1BIT:\r
409 case EFI_HII_IIBT_IMAGE_4BIT:\r
410 case EFI_HII_IIBT_IMAGE_8BIT:\r
411 //\r
412 // Use the common block code since the definition of these structures is the same.\r
413 //\r
414 Image->Width = ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_1BIT_BLOCK *)CurrentImageBlock)->Bitmap.Width);\r
415 Image->Height = ReadUnaligned16 (&((EFI_HII_IIBT_IMAGE_1BIT_BLOCK *)CurrentImageBlock)->Bitmap.Height);\r
101a1122 416 Image->Image.Bitmap = NULL;\r
1436aea4 417 return EFI_SUCCESS;\r
101a1122 418\r
1436aea4
MK
419 case EFI_HII_IIBT_IMAGE_24BIT_TRANS:\r
420 case EFI_HII_IIBT_IMAGE_24BIT:\r
421 Image->Width = ReadUnaligned16 ((VOID *)&((EFI_HII_IIBT_IMAGE_24BIT_BLOCK *)CurrentImageBlock)->Bitmap.Width);\r
422 Image->Height = ReadUnaligned16 ((VOID *)&((EFI_HII_IIBT_IMAGE_24BIT_BLOCK *)CurrentImageBlock)->Bitmap.Height);\r
423 Image->Image.Bitmap = NULL;\r
424 return EFI_SUCCESS;\r
425\r
426 default:\r
427 return EFI_NOT_FOUND;\r
101a1122
RN
428 }\r
429}\r