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