svga_overlay.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /* SPDX-License-Identifier: GPL-2.0 OR MIT */
  2. /**********************************************************
  3. * Copyright 2007-2015 VMware, Inc.
  4. *
  5. * Permission is hereby granted, free of charge, to any person
  6. * obtaining a copy of this software and associated documentation
  7. * files (the "Software"), to deal in the Software without
  8. * restriction, including without limitation the rights to use, copy,
  9. * modify, merge, publish, distribute, sublicense, and/or sell copies
  10. * of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be
  14. * included in all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  20. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  21. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. * SOFTWARE.
  24. *
  25. **********************************************************/
  26. /*
  27. * svga_overlay.h --
  28. *
  29. * Definitions for video-overlay support.
  30. */
  31. #ifndef _SVGA_OVERLAY_H_
  32. #define _SVGA_OVERLAY_H_
  33. #include "svga_reg.h"
  34. /*
  35. * Video formats we support
  36. */
  37. #define VMWARE_FOURCC_YV12 0x32315659 /* 'Y' 'V' '1' '2' */
  38. #define VMWARE_FOURCC_YUY2 0x32595559 /* 'Y' 'U' 'Y' '2' */
  39. #define VMWARE_FOURCC_UYVY 0x59565955 /* 'U' 'Y' 'V' 'Y' */
  40. typedef enum {
  41. SVGA_OVERLAY_FORMAT_INVALID = 0,
  42. SVGA_OVERLAY_FORMAT_YV12 = VMWARE_FOURCC_YV12,
  43. SVGA_OVERLAY_FORMAT_YUY2 = VMWARE_FOURCC_YUY2,
  44. SVGA_OVERLAY_FORMAT_UYVY = VMWARE_FOURCC_UYVY,
  45. } SVGAOverlayFormat;
  46. #define SVGA_VIDEO_COLORKEY_MASK 0x00ffffff
  47. #define SVGA_ESCAPE_VMWARE_VIDEO 0x00020000
  48. #define SVGA_ESCAPE_VMWARE_VIDEO_SET_REGS 0x00020001
  49. /* FIFO escape layout:
  50. * Type, Stream Id, (Register Id, Value) pairs */
  51. #define SVGA_ESCAPE_VMWARE_VIDEO_FLUSH 0x00020002
  52. /* FIFO escape layout:
  53. * Type, Stream Id */
  54. typedef
  55. struct SVGAEscapeVideoSetRegs {
  56. struct {
  57. uint32 cmdType;
  58. uint32 streamId;
  59. } header;
  60. /* May include zero or more items. */
  61. struct {
  62. uint32 registerId;
  63. uint32 value;
  64. } items[1];
  65. } SVGAEscapeVideoSetRegs;
  66. typedef
  67. struct SVGAEscapeVideoFlush {
  68. uint32 cmdType;
  69. uint32 streamId;
  70. } SVGAEscapeVideoFlush;
  71. /*
  72. * Struct definitions for the video overlay commands built on
  73. * SVGAFifoCmdEscape.
  74. */
  75. typedef
  76. struct {
  77. uint32 command;
  78. uint32 overlay;
  79. } SVGAFifoEscapeCmdVideoBase;
  80. typedef
  81. struct {
  82. SVGAFifoEscapeCmdVideoBase videoCmd;
  83. } SVGAFifoEscapeCmdVideoFlush;
  84. typedef
  85. struct {
  86. SVGAFifoEscapeCmdVideoBase videoCmd;
  87. struct {
  88. uint32 regId;
  89. uint32 value;
  90. } items[1];
  91. } SVGAFifoEscapeCmdVideoSetRegs;
  92. typedef
  93. struct {
  94. SVGAFifoEscapeCmdVideoBase videoCmd;
  95. struct {
  96. uint32 regId;
  97. uint32 value;
  98. } items[SVGA_VIDEO_NUM_REGS];
  99. } SVGAFifoEscapeCmdVideoSetAllRegs;
  100. /*
  101. *----------------------------------------------------------------------
  102. *
  103. * VMwareVideoGetAttributes --
  104. *
  105. * Computes the size, pitches and offsets for YUV frames.
  106. *
  107. * Results:
  108. * TRUE on success; otherwise FALSE on failure.
  109. *
  110. * Side effects:
  111. * Pitches and offsets for the given YUV frame are put in 'pitches'
  112. * and 'offsets' respectively. They are both optional though.
  113. *
  114. *----------------------------------------------------------------------
  115. */
  116. static inline bool
  117. VMwareVideoGetAttributes(const SVGAOverlayFormat format, /* IN */
  118. uint32 *width, /* IN / OUT */
  119. uint32 *height, /* IN / OUT */
  120. uint32 *size, /* OUT */
  121. uint32 *pitches, /* OUT (optional) */
  122. uint32 *offsets) /* OUT (optional) */
  123. {
  124. int tmp;
  125. *width = (*width + 1) & ~1;
  126. if (offsets) {
  127. offsets[0] = 0;
  128. }
  129. switch (format) {
  130. case VMWARE_FOURCC_YV12:
  131. *height = (*height + 1) & ~1;
  132. *size = (*width) * (*height);
  133. if (pitches) {
  134. pitches[0] = *width;
  135. }
  136. if (offsets) {
  137. offsets[1] = *size;
  138. }
  139. tmp = *width >> 1;
  140. if (pitches) {
  141. pitches[1] = pitches[2] = tmp;
  142. }
  143. tmp *= (*height >> 1);
  144. *size += tmp;
  145. if (offsets) {
  146. offsets[2] = *size;
  147. }
  148. *size += tmp;
  149. break;
  150. case VMWARE_FOURCC_YUY2:
  151. case VMWARE_FOURCC_UYVY:
  152. *size = *width * 2;
  153. if (pitches) {
  154. pitches[0] = *size;
  155. }
  156. *size *= *height;
  157. break;
  158. default:
  159. return false;
  160. }
  161. return true;
  162. }
  163. #endif /* _SVGA_OVERLAY_H_ */