svga_overlay.h 4.9 KB

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