diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2016-06-09 05:54:08 -0400 |
---|---|---|
committer | Daniel Vetter <daniel.vetter@ffwll.ch> | 2016-06-09 05:58:50 -0400 |
commit | ae4df11a0f538b83781cf120a78dde32b0070600 (patch) | |
tree | 067437f27abe6dffa923cd154dba58f547fefa65 | |
parent | 081e9c0f8b5f88758376f50310d60d0dc4ace9e0 (diff) |
drm: Move format-related helpers to drm_fourcc.c
The drm_crtc.c file is a mess, making the ABI documentation confusing
since all functions are in the same bag. Split the format-related
helpers to a new drm_fourcc.c file.
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/1465466048-2020-1-git-send-email-laurent.pinchart@ideasonboard.com
-rw-r--r-- | Documentation/DocBook/gpu.tmpl | 5 | ||||
-rw-r--r-- | drivers/gpu/drm/Makefile | 2 | ||||
-rw-r--r-- | drivers/gpu/drm/drm_crtc.c | 289 | ||||
-rw-r--r-- | drivers/gpu/drm/drm_fourcc.c | 320 | ||||
-rw-r--r-- | include/drm/drmP.h | 1 | ||||
-rw-r--r-- | include/drm/drm_crtc.h | 9 | ||||
-rw-r--r-- | include/drm/drm_fourcc.h | 37 |
7 files changed, 364 insertions, 299 deletions
diff --git a/Documentation/DocBook/gpu.tmpl b/Documentation/DocBook/gpu.tmpl index dac18b4ff090..89585ad69a4b 100644 --- a/Documentation/DocBook/gpu.tmpl +++ b/Documentation/DocBook/gpu.tmpl | |||
@@ -1018,6 +1018,11 @@ int max_width, max_height;</synopsis> | |||
1018 | </para> | 1018 | </para> |
1019 | </sect2> | 1019 | </sect2> |
1020 | <sect2> | 1020 | <sect2> |
1021 | <title>DRM Format Handling</title> | ||
1022 | !Iinclude/drm/drm_fourcc.h | ||
1023 | !Edrivers/gpu/drm/drm_fourcc.c | ||
1024 | </sect2> | ||
1025 | <sect2> | ||
1021 | <title>Dumb Buffer Objects</title> | 1026 | <title>Dumb Buffer Objects</title> |
1022 | <para> | 1027 | <para> |
1023 | The KMS API doesn't standardize backing storage object creation and | 1028 | The KMS API doesn't standardize backing storage object creation and |
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile index be43afb08c69..aa24af35c068 100644 --- a/drivers/gpu/drm/Makefile +++ b/drivers/gpu/drm/Makefile | |||
@@ -8,7 +8,7 @@ drm-y := drm_auth.o drm_bufs.o drm_cache.o \ | |||
8 | drm_lock.o drm_memory.o drm_drv.o drm_vm.o \ | 8 | drm_lock.o drm_memory.o drm_drv.o drm_vm.o \ |
9 | drm_scatter.o drm_pci.o \ | 9 | drm_scatter.o drm_pci.o \ |
10 | drm_platform.o drm_sysfs.o drm_hashtab.o drm_mm.o \ | 10 | drm_platform.o drm_sysfs.o drm_hashtab.o drm_mm.o \ |
11 | drm_crtc.o drm_modes.o drm_edid.o \ | 11 | drm_crtc.o drm_fourcc.o drm_modes.o drm_edid.o \ |
12 | drm_info.o drm_debugfs.o drm_encoder_slave.o \ | 12 | drm_info.o drm_debugfs.o drm_encoder_slave.o \ |
13 | drm_trace_points.o drm_global.o drm_prime.o \ | 13 | drm_trace_points.o drm_global.o drm_prime.o \ |
14 | drm_rect.o drm_vma_manager.o drm_flip_work.o \ | 14 | drm_rect.o drm_vma_manager.o drm_flip_work.o \ |
diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c index df91dfe506eb..aeb5d9e087fc 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c | |||
@@ -239,37 +239,6 @@ const char *drm_get_subpixel_order_name(enum subpixel_order order) | |||
239 | } | 239 | } |
240 | EXPORT_SYMBOL(drm_get_subpixel_order_name); | 240 | EXPORT_SYMBOL(drm_get_subpixel_order_name); |
241 | 241 | ||
242 | static char printable_char(int c) | ||
243 | { | ||
244 | return isascii(c) && isprint(c) ? c : '?'; | ||
245 | } | ||
246 | |||
247 | /** | ||
248 | * drm_get_format_name - return a string for drm fourcc format | ||
249 | * @format: format to compute name of | ||
250 | * | ||
251 | * Note that the buffer used by this function is globally shared and owned by | ||
252 | * the function itself. | ||
253 | * | ||
254 | * FIXME: This isn't really multithreading safe. | ||
255 | */ | ||
256 | const char *drm_get_format_name(uint32_t format) | ||
257 | { | ||
258 | static char buf[32]; | ||
259 | |||
260 | snprintf(buf, sizeof(buf), | ||
261 | "%c%c%c%c %s-endian (0x%08x)", | ||
262 | printable_char(format & 0xff), | ||
263 | printable_char((format >> 8) & 0xff), | ||
264 | printable_char((format >> 16) & 0xff), | ||
265 | printable_char((format >> 24) & 0x7f), | ||
266 | format & DRM_FORMAT_BIG_ENDIAN ? "big" : "little", | ||
267 | format); | ||
268 | |||
269 | return buf; | ||
270 | } | ||
271 | EXPORT_SYMBOL(drm_get_format_name); | ||
272 | |||
273 | /* | 242 | /* |
274 | * Internal function to assign a slot in the object idr and optionally | 243 | * Internal function to assign a slot in the object idr and optionally |
275 | * register the object into the idr. | 244 | * register the object into the idr. |
@@ -5503,264 +5472,6 @@ int drm_mode_destroy_dumb_ioctl(struct drm_device *dev, | |||
5503 | } | 5472 | } |
5504 | 5473 | ||
5505 | /** | 5474 | /** |
5506 | * drm_fb_get_bpp_depth - get the bpp/depth values for format | ||
5507 | * @format: pixel format (DRM_FORMAT_*) | ||
5508 | * @depth: storage for the depth value | ||
5509 | * @bpp: storage for the bpp value | ||
5510 | * | ||
5511 | * This only supports RGB formats here for compat with code that doesn't use | ||
5512 | * pixel formats directly yet. | ||
5513 | */ | ||
5514 | void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth, | ||
5515 | int *bpp) | ||
5516 | { | ||
5517 | switch (format) { | ||
5518 | case DRM_FORMAT_C8: | ||
5519 | case DRM_FORMAT_RGB332: | ||
5520 | case DRM_FORMAT_BGR233: | ||
5521 | *depth = 8; | ||
5522 | *bpp = 8; | ||
5523 | break; | ||
5524 | case DRM_FORMAT_XRGB1555: | ||
5525 | case DRM_FORMAT_XBGR1555: | ||
5526 | case DRM_FORMAT_RGBX5551: | ||
5527 | case DRM_FORMAT_BGRX5551: | ||
5528 | case DRM_FORMAT_ARGB1555: | ||
5529 | case DRM_FORMAT_ABGR1555: | ||
5530 | case DRM_FORMAT_RGBA5551: | ||
5531 | case DRM_FORMAT_BGRA5551: | ||
5532 | *depth = 15; | ||
5533 | *bpp = 16; | ||
5534 | break; | ||
5535 | case DRM_FORMAT_RGB565: | ||
5536 | case DRM_FORMAT_BGR565: | ||
5537 | *depth = 16; | ||
5538 | *bpp = 16; | ||
5539 | break; | ||
5540 | case DRM_FORMAT_RGB888: | ||
5541 | case DRM_FORMAT_BGR888: | ||
5542 | *depth = 24; | ||
5543 | *bpp = 24; | ||
5544 | break; | ||
5545 | case DRM_FORMAT_XRGB8888: | ||
5546 | case DRM_FORMAT_XBGR8888: | ||
5547 | case DRM_FORMAT_RGBX8888: | ||
5548 | case DRM_FORMAT_BGRX8888: | ||
5549 | *depth = 24; | ||
5550 | *bpp = 32; | ||
5551 | break; | ||
5552 | case DRM_FORMAT_XRGB2101010: | ||
5553 | case DRM_FORMAT_XBGR2101010: | ||
5554 | case DRM_FORMAT_RGBX1010102: | ||
5555 | case DRM_FORMAT_BGRX1010102: | ||
5556 | case DRM_FORMAT_ARGB2101010: | ||
5557 | case DRM_FORMAT_ABGR2101010: | ||
5558 | case DRM_FORMAT_RGBA1010102: | ||
5559 | case DRM_FORMAT_BGRA1010102: | ||
5560 | *depth = 30; | ||
5561 | *bpp = 32; | ||
5562 | break; | ||
5563 | case DRM_FORMAT_ARGB8888: | ||
5564 | case DRM_FORMAT_ABGR8888: | ||
5565 | case DRM_FORMAT_RGBA8888: | ||
5566 | case DRM_FORMAT_BGRA8888: | ||
5567 | *depth = 32; | ||
5568 | *bpp = 32; | ||
5569 | break; | ||
5570 | default: | ||
5571 | DRM_DEBUG_KMS("unsupported pixel format %s\n", | ||
5572 | drm_get_format_name(format)); | ||
5573 | *depth = 0; | ||
5574 | *bpp = 0; | ||
5575 | break; | ||
5576 | } | ||
5577 | } | ||
5578 | EXPORT_SYMBOL(drm_fb_get_bpp_depth); | ||
5579 | |||
5580 | /** | ||
5581 | * drm_format_num_planes - get the number of planes for format | ||
5582 | * @format: pixel format (DRM_FORMAT_*) | ||
5583 | * | ||
5584 | * Returns: | ||
5585 | * The number of planes used by the specified pixel format. | ||
5586 | */ | ||
5587 | int drm_format_num_planes(uint32_t format) | ||
5588 | { | ||
5589 | switch (format) { | ||
5590 | case DRM_FORMAT_YUV410: | ||
5591 | case DRM_FORMAT_YVU410: | ||
5592 | case DRM_FORMAT_YUV411: | ||
5593 | case DRM_FORMAT_YVU411: | ||
5594 | case DRM_FORMAT_YUV420: | ||
5595 | case DRM_FORMAT_YVU420: | ||
5596 | case DRM_FORMAT_YUV422: | ||
5597 | case DRM_FORMAT_YVU422: | ||
5598 | case DRM_FORMAT_YUV444: | ||
5599 | case DRM_FORMAT_YVU444: | ||
5600 | return 3; | ||
5601 | case DRM_FORMAT_NV12: | ||
5602 | case DRM_FORMAT_NV21: | ||
5603 | case DRM_FORMAT_NV16: | ||
5604 | case DRM_FORMAT_NV61: | ||
5605 | case DRM_FORMAT_NV24: | ||
5606 | case DRM_FORMAT_NV42: | ||
5607 | return 2; | ||
5608 | default: | ||
5609 | return 1; | ||
5610 | } | ||
5611 | } | ||
5612 | EXPORT_SYMBOL(drm_format_num_planes); | ||
5613 | |||
5614 | /** | ||
5615 | * drm_format_plane_cpp - determine the bytes per pixel value | ||
5616 | * @format: pixel format (DRM_FORMAT_*) | ||
5617 | * @plane: plane index | ||
5618 | * | ||
5619 | * Returns: | ||
5620 | * The bytes per pixel value for the specified plane. | ||
5621 | */ | ||
5622 | int drm_format_plane_cpp(uint32_t format, int plane) | ||
5623 | { | ||
5624 | unsigned int depth; | ||
5625 | int bpp; | ||
5626 | |||
5627 | if (plane >= drm_format_num_planes(format)) | ||
5628 | return 0; | ||
5629 | |||
5630 | switch (format) { | ||
5631 | case DRM_FORMAT_YUYV: | ||
5632 | case DRM_FORMAT_YVYU: | ||
5633 | case DRM_FORMAT_UYVY: | ||
5634 | case DRM_FORMAT_VYUY: | ||
5635 | return 2; | ||
5636 | case DRM_FORMAT_NV12: | ||
5637 | case DRM_FORMAT_NV21: | ||
5638 | case DRM_FORMAT_NV16: | ||
5639 | case DRM_FORMAT_NV61: | ||
5640 | case DRM_FORMAT_NV24: | ||
5641 | case DRM_FORMAT_NV42: | ||
5642 | return plane ? 2 : 1; | ||
5643 | case DRM_FORMAT_YUV410: | ||
5644 | case DRM_FORMAT_YVU410: | ||
5645 | case DRM_FORMAT_YUV411: | ||
5646 | case DRM_FORMAT_YVU411: | ||
5647 | case DRM_FORMAT_YUV420: | ||
5648 | case DRM_FORMAT_YVU420: | ||
5649 | case DRM_FORMAT_YUV422: | ||
5650 | case DRM_FORMAT_YVU422: | ||
5651 | case DRM_FORMAT_YUV444: | ||
5652 | case DRM_FORMAT_YVU444: | ||
5653 | return 1; | ||
5654 | default: | ||
5655 | drm_fb_get_bpp_depth(format, &depth, &bpp); | ||
5656 | return bpp >> 3; | ||
5657 | } | ||
5658 | } | ||
5659 | EXPORT_SYMBOL(drm_format_plane_cpp); | ||
5660 | |||
5661 | /** | ||
5662 | * drm_format_horz_chroma_subsampling - get the horizontal chroma subsampling factor | ||
5663 | * @format: pixel format (DRM_FORMAT_*) | ||
5664 | * | ||
5665 | * Returns: | ||
5666 | * The horizontal chroma subsampling factor for the | ||
5667 | * specified pixel format. | ||
5668 | */ | ||
5669 | int drm_format_horz_chroma_subsampling(uint32_t format) | ||
5670 | { | ||
5671 | switch (format) { | ||
5672 | case DRM_FORMAT_YUV411: | ||
5673 | case DRM_FORMAT_YVU411: | ||
5674 | case DRM_FORMAT_YUV410: | ||
5675 | case DRM_FORMAT_YVU410: | ||
5676 | return 4; | ||
5677 | case DRM_FORMAT_YUYV: | ||
5678 | case DRM_FORMAT_YVYU: | ||
5679 | case DRM_FORMAT_UYVY: | ||
5680 | case DRM_FORMAT_VYUY: | ||
5681 | case DRM_FORMAT_NV12: | ||
5682 | case DRM_FORMAT_NV21: | ||
5683 | case DRM_FORMAT_NV16: | ||
5684 | case DRM_FORMAT_NV61: | ||
5685 | case DRM_FORMAT_YUV422: | ||
5686 | case DRM_FORMAT_YVU422: | ||
5687 | case DRM_FORMAT_YUV420: | ||
5688 | case DRM_FORMAT_YVU420: | ||
5689 | return 2; | ||
5690 | default: | ||
5691 | return 1; | ||
5692 | } | ||
5693 | } | ||
5694 | EXPORT_SYMBOL(drm_format_horz_chroma_subsampling); | ||
5695 | |||
5696 | /** | ||
5697 | * drm_format_vert_chroma_subsampling - get the vertical chroma subsampling factor | ||
5698 | * @format: pixel format (DRM_FORMAT_*) | ||
5699 | * | ||
5700 | * Returns: | ||
5701 | * The vertical chroma subsampling factor for the | ||
5702 | * specified pixel format. | ||
5703 | */ | ||
5704 | int drm_format_vert_chroma_subsampling(uint32_t format) | ||
5705 | { | ||
5706 | switch (format) { | ||
5707 | case DRM_FORMAT_YUV410: | ||
5708 | case DRM_FORMAT_YVU410: | ||
5709 | return 4; | ||
5710 | case DRM_FORMAT_YUV420: | ||
5711 | case DRM_FORMAT_YVU420: | ||
5712 | case DRM_FORMAT_NV12: | ||
5713 | case DRM_FORMAT_NV21: | ||
5714 | return 2; | ||
5715 | default: | ||
5716 | return 1; | ||
5717 | } | ||
5718 | } | ||
5719 | EXPORT_SYMBOL(drm_format_vert_chroma_subsampling); | ||
5720 | |||
5721 | /** | ||
5722 | * drm_format_plane_width - width of the plane given the first plane | ||
5723 | * @width: width of the first plane | ||
5724 | * @format: pixel format | ||
5725 | * @plane: plane index | ||
5726 | * | ||
5727 | * Returns: | ||
5728 | * The width of @plane, given that the width of the first plane is @width. | ||
5729 | */ | ||
5730 | int drm_format_plane_width(int width, uint32_t format, int plane) | ||
5731 | { | ||
5732 | if (plane >= drm_format_num_planes(format)) | ||
5733 | return 0; | ||
5734 | |||
5735 | if (plane == 0) | ||
5736 | return width; | ||
5737 | |||
5738 | return width / drm_format_horz_chroma_subsampling(format); | ||
5739 | } | ||
5740 | EXPORT_SYMBOL(drm_format_plane_width); | ||
5741 | |||
5742 | /** | ||
5743 | * drm_format_plane_height - height of the plane given the first plane | ||
5744 | * @height: height of the first plane | ||
5745 | * @format: pixel format | ||
5746 | * @plane: plane index | ||
5747 | * | ||
5748 | * Returns: | ||
5749 | * The height of @plane, given that the height of the first plane is @height. | ||
5750 | */ | ||
5751 | int drm_format_plane_height(int height, uint32_t format, int plane) | ||
5752 | { | ||
5753 | if (plane >= drm_format_num_planes(format)) | ||
5754 | return 0; | ||
5755 | |||
5756 | if (plane == 0) | ||
5757 | return height; | ||
5758 | |||
5759 | return height / drm_format_vert_chroma_subsampling(format); | ||
5760 | } | ||
5761 | EXPORT_SYMBOL(drm_format_plane_height); | ||
5762 | |||
5763 | /** | ||
5764 | * drm_rotation_simplify() - Try to simplify the rotation | 5475 | * drm_rotation_simplify() - Try to simplify the rotation |
5765 | * @rotation: Rotation to be simplified | 5476 | * @rotation: Rotation to be simplified |
5766 | * @supported_rotations: Supported rotations | 5477 | * @supported_rotations: Supported rotations |
diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c new file mode 100644 index 000000000000..0645c85d5f95 --- /dev/null +++ b/drivers/gpu/drm/drm_fourcc.c | |||
@@ -0,0 +1,320 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2016 Laurent Pinchart <laurent.pinchart@ideasonboard.com> | ||
3 | * | ||
4 | * DRM core format related functions | ||
5 | * | ||
6 | * Permission to use, copy, modify, distribute, and sell this software and its | ||
7 | * documentation for any purpose is hereby granted without fee, provided that | ||
8 | * the above copyright notice appear in all copies and that both that copyright | ||
9 | * notice and this permission notice appear in supporting documentation, and | ||
10 | * that the name of the copyright holders not be used in advertising or | ||
11 | * publicity pertaining to distribution of the software without specific, | ||
12 | * written prior permission. The copyright holders make no representations | ||
13 | * about the suitability of this software for any purpose. It is provided "as | ||
14 | * is" without express or implied warranty. | ||
15 | * | ||
16 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, | ||
17 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO | ||
18 | * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR | ||
19 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, | ||
20 | * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER | ||
21 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE | ||
22 | * OF THIS SOFTWARE. | ||
23 | */ | ||
24 | |||
25 | #include <linux/bug.h> | ||
26 | #include <linux/ctype.h> | ||
27 | #include <linux/export.h> | ||
28 | #include <linux/kernel.h> | ||
29 | |||
30 | #include <drm/drmP.h> | ||
31 | #include <drm/drm_fourcc.h> | ||
32 | |||
33 | static char printable_char(int c) | ||
34 | { | ||
35 | return isascii(c) && isprint(c) ? c : '?'; | ||
36 | } | ||
37 | |||
38 | /** | ||
39 | * drm_get_format_name - return a string for drm fourcc format | ||
40 | * @format: format to compute name of | ||
41 | * | ||
42 | * Note that the buffer used by this function is globally shared and owned by | ||
43 | * the function itself. | ||
44 | * | ||
45 | * FIXME: This isn't really multithreading safe. | ||
46 | */ | ||
47 | const char *drm_get_format_name(uint32_t format) | ||
48 | { | ||
49 | static char buf[32]; | ||
50 | |||
51 | snprintf(buf, sizeof(buf), | ||
52 | "%c%c%c%c %s-endian (0x%08x)", | ||
53 | printable_char(format & 0xff), | ||
54 | printable_char((format >> 8) & 0xff), | ||
55 | printable_char((format >> 16) & 0xff), | ||
56 | printable_char((format >> 24) & 0x7f), | ||
57 | format & DRM_FORMAT_BIG_ENDIAN ? "big" : "little", | ||
58 | format); | ||
59 | |||
60 | return buf; | ||
61 | } | ||
62 | EXPORT_SYMBOL(drm_get_format_name); | ||
63 | |||
64 | /** | ||
65 | * drm_fb_get_bpp_depth - get the bpp/depth values for format | ||
66 | * @format: pixel format (DRM_FORMAT_*) | ||
67 | * @depth: storage for the depth value | ||
68 | * @bpp: storage for the bpp value | ||
69 | * | ||
70 | * This only supports RGB formats here for compat with code that doesn't use | ||
71 | * pixel formats directly yet. | ||
72 | */ | ||
73 | void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth, | ||
74 | int *bpp) | ||
75 | { | ||
76 | switch (format) { | ||
77 | case DRM_FORMAT_C8: | ||
78 | case DRM_FORMAT_RGB332: | ||
79 | case DRM_FORMAT_BGR233: | ||
80 | *depth = 8; | ||
81 | *bpp = 8; | ||
82 | break; | ||
83 | case DRM_FORMAT_XRGB1555: | ||
84 | case DRM_FORMAT_XBGR1555: | ||
85 | case DRM_FORMAT_RGBX5551: | ||
86 | case DRM_FORMAT_BGRX5551: | ||
87 | case DRM_FORMAT_ARGB1555: | ||
88 | case DRM_FORMAT_ABGR1555: | ||
89 | case DRM_FORMAT_RGBA5551: | ||
90 | case DRM_FORMAT_BGRA5551: | ||
91 | *depth = 15; | ||
92 | *bpp = 16; | ||
93 | break; | ||
94 | case DRM_FORMAT_RGB565: | ||
95 | case DRM_FORMAT_BGR565: | ||
96 | *depth = 16; | ||
97 | *bpp = 16; | ||
98 | break; | ||
99 | case DRM_FORMAT_RGB888: | ||
100 | case DRM_FORMAT_BGR888: | ||
101 | *depth = 24; | ||
102 | *bpp = 24; | ||
103 | break; | ||
104 | case DRM_FORMAT_XRGB8888: | ||
105 | case DRM_FORMAT_XBGR8888: | ||
106 | case DRM_FORMAT_RGBX8888: | ||
107 | case DRM_FORMAT_BGRX8888: | ||
108 | *depth = 24; | ||
109 | *bpp = 32; | ||
110 | break; | ||
111 | case DRM_FORMAT_XRGB2101010: | ||
112 | case DRM_FORMAT_XBGR2101010: | ||
113 | case DRM_FORMAT_RGBX1010102: | ||
114 | case DRM_FORMAT_BGRX1010102: | ||
115 | case DRM_FORMAT_ARGB2101010: | ||
116 | case DRM_FORMAT_ABGR2101010: | ||
117 | case DRM_FORMAT_RGBA1010102: | ||
118 | case DRM_FORMAT_BGRA1010102: | ||
119 | *depth = 30; | ||
120 | *bpp = 32; | ||
121 | break; | ||
122 | case DRM_FORMAT_ARGB8888: | ||
123 | case DRM_FORMAT_ABGR8888: | ||
124 | case DRM_FORMAT_RGBA8888: | ||
125 | case DRM_FORMAT_BGRA8888: | ||
126 | *depth = 32; | ||
127 | *bpp = 32; | ||
128 | break; | ||
129 | default: | ||
130 | DRM_DEBUG_KMS("unsupported pixel format %s\n", | ||
131 | drm_get_format_name(format)); | ||
132 | *depth = 0; | ||
133 | *bpp = 0; | ||
134 | break; | ||
135 | } | ||
136 | } | ||
137 | EXPORT_SYMBOL(drm_fb_get_bpp_depth); | ||
138 | |||
139 | /** | ||
140 | * drm_format_num_planes - get the number of planes for format | ||
141 | * @format: pixel format (DRM_FORMAT_*) | ||
142 | * | ||
143 | * Returns: | ||
144 | * The number of planes used by the specified pixel format. | ||
145 | */ | ||
146 | int drm_format_num_planes(uint32_t format) | ||
147 | { | ||
148 | switch (format) { | ||
149 | case DRM_FORMAT_YUV410: | ||
150 | case DRM_FORMAT_YVU410: | ||
151 | case DRM_FORMAT_YUV411: | ||
152 | case DRM_FORMAT_YVU411: | ||
153 | case DRM_FORMAT_YUV420: | ||
154 | case DRM_FORMAT_YVU420: | ||
155 | case DRM_FORMAT_YUV422: | ||
156 | case DRM_FORMAT_YVU422: | ||
157 | case DRM_FORMAT_YUV444: | ||
158 | case DRM_FORMAT_YVU444: | ||
159 | return 3; | ||
160 | case DRM_FORMAT_NV12: | ||
161 | case DRM_FORMAT_NV21: | ||
162 | case DRM_FORMAT_NV16: | ||
163 | case DRM_FORMAT_NV61: | ||
164 | case DRM_FORMAT_NV24: | ||
165 | case DRM_FORMAT_NV42: | ||
166 | return 2; | ||
167 | default: | ||
168 | return 1; | ||
169 | } | ||
170 | } | ||
171 | EXPORT_SYMBOL(drm_format_num_planes); | ||
172 | |||
173 | /** | ||
174 | * drm_format_plane_cpp - determine the bytes per pixel value | ||
175 | * @format: pixel format (DRM_FORMAT_*) | ||
176 | * @plane: plane index | ||
177 | * | ||
178 | * Returns: | ||
179 | * The bytes per pixel value for the specified plane. | ||
180 | */ | ||
181 | int drm_format_plane_cpp(uint32_t format, int plane) | ||
182 | { | ||
183 | unsigned int depth; | ||
184 | int bpp; | ||
185 | |||
186 | if (plane >= drm_format_num_planes(format)) | ||
187 | return 0; | ||
188 | |||
189 | switch (format) { | ||
190 | case DRM_FORMAT_YUYV: | ||
191 | case DRM_FORMAT_YVYU: | ||
192 | case DRM_FORMAT_UYVY: | ||
193 | case DRM_FORMAT_VYUY: | ||
194 | return 2; | ||
195 | case DRM_FORMAT_NV12: | ||
196 | case DRM_FORMAT_NV21: | ||
197 | case DRM_FORMAT_NV16: | ||
198 | case DRM_FORMAT_NV61: | ||
199 | case DRM_FORMAT_NV24: | ||
200 | case DRM_FORMAT_NV42: | ||
201 | return plane ? 2 : 1; | ||
202 | case DRM_FORMAT_YUV410: | ||
203 | case DRM_FORMAT_YVU410: | ||
204 | case DRM_FORMAT_YUV411: | ||
205 | case DRM_FORMAT_YVU411: | ||
206 | case DRM_FORMAT_YUV420: | ||
207 | case DRM_FORMAT_YVU420: | ||
208 | case DRM_FORMAT_YUV422: | ||
209 | case DRM_FORMAT_YVU422: | ||
210 | case DRM_FORMAT_YUV444: | ||
211 | case DRM_FORMAT_YVU444: | ||
212 | return 1; | ||
213 | default: | ||
214 | drm_fb_get_bpp_depth(format, &depth, &bpp); | ||
215 | return bpp >> 3; | ||
216 | } | ||
217 | } | ||
218 | EXPORT_SYMBOL(drm_format_plane_cpp); | ||
219 | |||
220 | /** | ||
221 | * drm_format_horz_chroma_subsampling - get the horizontal chroma subsampling factor | ||
222 | * @format: pixel format (DRM_FORMAT_*) | ||
223 | * | ||
224 | * Returns: | ||
225 | * The horizontal chroma subsampling factor for the | ||
226 | * specified pixel format. | ||
227 | */ | ||
228 | int drm_format_horz_chroma_subsampling(uint32_t format) | ||
229 | { | ||
230 | switch (format) { | ||
231 | case DRM_FORMAT_YUV411: | ||
232 | case DRM_FORMAT_YVU411: | ||
233 | case DRM_FORMAT_YUV410: | ||
234 | case DRM_FORMAT_YVU410: | ||
235 | return 4; | ||
236 | case DRM_FORMAT_YUYV: | ||
237 | case DRM_FORMAT_YVYU: | ||
238 | case DRM_FORMAT_UYVY: | ||
239 | case DRM_FORMAT_VYUY: | ||
240 | case DRM_FORMAT_NV12: | ||
241 | case DRM_FORMAT_NV21: | ||
242 | case DRM_FORMAT_NV16: | ||
243 | case DRM_FORMAT_NV61: | ||
244 | case DRM_FORMAT_YUV422: | ||
245 | case DRM_FORMAT_YVU422: | ||
246 | case DRM_FORMAT_YUV420: | ||
247 | case DRM_FORMAT_YVU420: | ||
248 | return 2; | ||
249 | default: | ||
250 | return 1; | ||
251 | } | ||
252 | } | ||
253 | EXPORT_SYMBOL(drm_format_horz_chroma_subsampling); | ||
254 | |||
255 | /** | ||
256 | * drm_format_vert_chroma_subsampling - get the vertical chroma subsampling factor | ||
257 | * @format: pixel format (DRM_FORMAT_*) | ||
258 | * | ||
259 | * Returns: | ||
260 | * The vertical chroma subsampling factor for the | ||
261 | * specified pixel format. | ||
262 | */ | ||
263 | int drm_format_vert_chroma_subsampling(uint32_t format) | ||
264 | { | ||
265 | switch (format) { | ||
266 | case DRM_FORMAT_YUV410: | ||
267 | case DRM_FORMAT_YVU410: | ||
268 | return 4; | ||
269 | case DRM_FORMAT_YUV420: | ||
270 | case DRM_FORMAT_YVU420: | ||
271 | case DRM_FORMAT_NV12: | ||
272 | case DRM_FORMAT_NV21: | ||
273 | return 2; | ||
274 | default: | ||
275 | return 1; | ||
276 | } | ||
277 | } | ||
278 | EXPORT_SYMBOL(drm_format_vert_chroma_subsampling); | ||
279 | |||
280 | /** | ||
281 | * drm_format_plane_width - width of the plane given the first plane | ||
282 | * @width: width of the first plane | ||
283 | * @format: pixel format | ||
284 | * @plane: plane index | ||
285 | * | ||
286 | * Returns: | ||
287 | * The width of @plane, given that the width of the first plane is @width. | ||
288 | */ | ||
289 | int drm_format_plane_width(int width, uint32_t format, int plane) | ||
290 | { | ||
291 | if (plane >= drm_format_num_planes(format)) | ||
292 | return 0; | ||
293 | |||
294 | if (plane == 0) | ||
295 | return width; | ||
296 | |||
297 | return width / drm_format_horz_chroma_subsampling(format); | ||
298 | } | ||
299 | EXPORT_SYMBOL(drm_format_plane_width); | ||
300 | |||
301 | /** | ||
302 | * drm_format_plane_height - height of the plane given the first plane | ||
303 | * @height: height of the first plane | ||
304 | * @format: pixel format | ||
305 | * @plane: plane index | ||
306 | * | ||
307 | * Returns: | ||
308 | * The height of @plane, given that the height of the first plane is @height. | ||
309 | */ | ||
310 | int drm_format_plane_height(int height, uint32_t format, int plane) | ||
311 | { | ||
312 | if (plane >= drm_format_num_planes(format)) | ||
313 | return 0; | ||
314 | |||
315 | if (plane == 0) | ||
316 | return height; | ||
317 | |||
318 | return height / drm_format_vert_chroma_subsampling(format); | ||
319 | } | ||
320 | EXPORT_SYMBOL(drm_format_plane_height); | ||
diff --git a/include/drm/drmP.h b/include/drm/drmP.h index a4f9babce249..086ad96d7d62 100644 --- a/include/drm/drmP.h +++ b/include/drm/drmP.h | |||
@@ -68,6 +68,7 @@ | |||
68 | 68 | ||
69 | #include <drm/drm_agpsupport.h> | 69 | #include <drm/drm_agpsupport.h> |
70 | #include <drm/drm_crtc.h> | 70 | #include <drm/drm_crtc.h> |
71 | #include <drm/drm_fourcc.h> | ||
71 | #include <drm/drm_global.h> | 72 | #include <drm/drm_global.h> |
72 | #include <drm/drm_hashtab.h> | 73 | #include <drm/drm_hashtab.h> |
73 | #include <drm/drm_mem_util.h> | 74 | #include <drm/drm_mem_util.h> |
diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h index 1a8d66ca677c..7bf065b61316 100644 --- a/include/drm/drm_crtc.h +++ b/include/drm/drm_crtc.h | |||
@@ -2645,15 +2645,6 @@ extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane, | |||
2645 | extern int drm_mode_atomic_ioctl(struct drm_device *dev, | 2645 | extern int drm_mode_atomic_ioctl(struct drm_device *dev, |
2646 | void *data, struct drm_file *file_priv); | 2646 | void *data, struct drm_file *file_priv); |
2647 | 2647 | ||
2648 | extern void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth, | ||
2649 | int *bpp); | ||
2650 | extern int drm_format_num_planes(uint32_t format); | ||
2651 | extern int drm_format_plane_cpp(uint32_t format, int plane); | ||
2652 | extern int drm_format_horz_chroma_subsampling(uint32_t format); | ||
2653 | extern int drm_format_vert_chroma_subsampling(uint32_t format); | ||
2654 | extern int drm_format_plane_width(int width, uint32_t format, int plane); | ||
2655 | extern int drm_format_plane_height(int height, uint32_t format, int plane); | ||
2656 | extern const char *drm_get_format_name(uint32_t format); | ||
2657 | extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev, | 2648 | extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev, |
2658 | unsigned int supported_rotations); | 2649 | unsigned int supported_rotations); |
2659 | extern unsigned int drm_rotation_simplify(unsigned int rotation, | 2650 | extern unsigned int drm_rotation_simplify(unsigned int rotation, |
diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h new file mode 100644 index 000000000000..7f90a396cf2b --- /dev/null +++ b/include/drm/drm_fourcc.h | |||
@@ -0,0 +1,37 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2016 Laurent Pinchart <laurent.pinchart@ideasonboard.com> | ||
3 | * | ||
4 | * Permission to use, copy, modify, distribute, and sell this software and its | ||
5 | * documentation for any purpose is hereby granted without fee, provided that | ||
6 | * the above copyright notice appear in all copies and that both that copyright | ||
7 | * notice and this permission notice appear in supporting documentation, and | ||
8 | * that the name of the copyright holders not be used in advertising or | ||
9 | * publicity pertaining to distribution of the software without specific, | ||
10 | * written prior permission. The copyright holders make no representations | ||
11 | * about the suitability of this software for any purpose. It is provided "as | ||
12 | * is" without express or implied warranty. | ||
13 | * | ||
14 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, | ||
15 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO | ||
16 | * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR | ||
17 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, | ||
18 | * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER | ||
19 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE | ||
20 | * OF THIS SOFTWARE. | ||
21 | */ | ||
22 | #ifndef __DRM_FOURCC_H__ | ||
23 | #define __DRM_FOURCC_H__ | ||
24 | |||
25 | #include <linux/types.h> | ||
26 | #include <uapi/drm/drm_fourcc.h> | ||
27 | |||
28 | void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth, int *bpp); | ||
29 | int drm_format_num_planes(uint32_t format); | ||
30 | int drm_format_plane_cpp(uint32_t format, int plane); | ||
31 | int drm_format_horz_chroma_subsampling(uint32_t format); | ||
32 | int drm_format_vert_chroma_subsampling(uint32_t format); | ||
33 | int drm_format_plane_width(int width, uint32_t format, int plane); | ||
34 | int drm_format_plane_height(int height, uint32_t format, int plane); | ||
35 | const char *drm_get_format_name(uint32_t format); | ||
36 | |||
37 | #endif /* __DRM_FOURCC_H__ */ | ||