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