1bf215546Sopenharmony_ci/**************************************************************************
2bf215546Sopenharmony_ci *
3bf215546Sopenharmony_ci * Copyright 2011 Christian König.
4bf215546Sopenharmony_ci * All Rights Reserved.
5bf215546Sopenharmony_ci *
6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the
8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to
11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
12bf215546Sopenharmony_ci * the following conditions:
13bf215546Sopenharmony_ci *
14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the
15bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
16bf215546Sopenharmony_ci * of the Software.
17bf215546Sopenharmony_ci *
18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21bf215546Sopenharmony_ci * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22bf215546Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23bf215546Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24bf215546Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25bf215546Sopenharmony_ci *
26bf215546Sopenharmony_ci **************************************************************************/
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci#ifndef vl_video_buffer_h
29bf215546Sopenharmony_ci#define vl_video_buffer_h
30bf215546Sopenharmony_ci
31bf215546Sopenharmony_ci#include "pipe/p_context.h"
32bf215546Sopenharmony_ci#include "pipe/p_video_codec.h"
33bf215546Sopenharmony_ci
34bf215546Sopenharmony_ci#include "vl_defines.h"
35bf215546Sopenharmony_ci
36bf215546Sopenharmony_ci/**
37bf215546Sopenharmony_ci * implementation of a planar ycbcr buffer
38bf215546Sopenharmony_ci */
39bf215546Sopenharmony_ci
40bf215546Sopenharmony_ci/* planar buffer for vl data upload and manipulation */
41bf215546Sopenharmony_cistruct vl_video_buffer
42bf215546Sopenharmony_ci{
43bf215546Sopenharmony_ci   struct pipe_video_buffer base;
44bf215546Sopenharmony_ci   unsigned                 num_planes;
45bf215546Sopenharmony_ci   struct pipe_resource     *resources[VL_NUM_COMPONENTS];
46bf215546Sopenharmony_ci   struct pipe_sampler_view *sampler_view_planes[VL_NUM_COMPONENTS];
47bf215546Sopenharmony_ci   struct pipe_sampler_view *sampler_view_components[VL_NUM_COMPONENTS];
48bf215546Sopenharmony_ci   struct pipe_surface      *surfaces[VL_MAX_SURFACES];
49bf215546Sopenharmony_ci};
50bf215546Sopenharmony_ci
51bf215546Sopenharmony_cistatic inline void
52bf215546Sopenharmony_civl_video_buffer_adjust_size(unsigned *width, unsigned *height, unsigned plane,
53bf215546Sopenharmony_ci                            enum pipe_video_chroma_format chroma_format,
54bf215546Sopenharmony_ci                            bool interlaced)
55bf215546Sopenharmony_ci{
56bf215546Sopenharmony_ci   if (interlaced) {
57bf215546Sopenharmony_ci      *height = align(*height, 2) / 2;
58bf215546Sopenharmony_ci   }
59bf215546Sopenharmony_ci   if (plane > 0) {
60bf215546Sopenharmony_ci      if (chroma_format == PIPE_VIDEO_CHROMA_FORMAT_420) {
61bf215546Sopenharmony_ci         *width = align(*width, 2) / 2;
62bf215546Sopenharmony_ci         *height = align(*height, 2) / 2;
63bf215546Sopenharmony_ci      } else if (chroma_format == PIPE_VIDEO_CHROMA_FORMAT_422) {
64bf215546Sopenharmony_ci         *width = align(*width, 2) / 2;
65bf215546Sopenharmony_ci      }
66bf215546Sopenharmony_ci   }
67bf215546Sopenharmony_ci}
68bf215546Sopenharmony_ci
69bf215546Sopenharmony_ci/**
70bf215546Sopenharmony_ci * get subformats for each plane
71bf215546Sopenharmony_ci */
72bf215546Sopenharmony_civoid
73bf215546Sopenharmony_civl_get_video_buffer_formats(struct pipe_screen *screen, enum pipe_format format,
74bf215546Sopenharmony_ci                            enum pipe_format out_format[VL_NUM_COMPONENTS]);
75bf215546Sopenharmony_ci
76bf215546Sopenharmony_ci/**
77bf215546Sopenharmony_ci * get YUV plane order
78bf215546Sopenharmony_ci */
79bf215546Sopenharmony_ciconst unsigned *
80bf215546Sopenharmony_civl_video_buffer_plane_order(enum pipe_format format);
81bf215546Sopenharmony_ci
82bf215546Sopenharmony_ci/**
83bf215546Sopenharmony_ci * get maximum size of video buffers
84bf215546Sopenharmony_ci */
85bf215546Sopenharmony_ciunsigned
86bf215546Sopenharmony_civl_video_buffer_max_size(struct pipe_screen *screen);
87bf215546Sopenharmony_ci
88bf215546Sopenharmony_ci/**
89bf215546Sopenharmony_ci * check if video buffer format is supported for a codec/profile
90bf215546Sopenharmony_ci * can be used as default implementation of screen->is_video_format_supported
91bf215546Sopenharmony_ci */
92bf215546Sopenharmony_cibool
93bf215546Sopenharmony_civl_video_buffer_is_format_supported(struct pipe_screen *screen,
94bf215546Sopenharmony_ci                                    enum pipe_format format,
95bf215546Sopenharmony_ci                                    enum pipe_video_profile profile,
96bf215546Sopenharmony_ci                                    enum pipe_video_entrypoint entrypoint);
97bf215546Sopenharmony_ci
98bf215546Sopenharmony_ci/*
99bf215546Sopenharmony_ci * set the associated data for the given video buffer
100bf215546Sopenharmony_ci */
101bf215546Sopenharmony_civoid
102bf215546Sopenharmony_civl_video_buffer_set_associated_data(struct pipe_video_buffer *vbuf,
103bf215546Sopenharmony_ci                                    struct pipe_video_codec *vcodec,
104bf215546Sopenharmony_ci                                    void *associated_data,
105bf215546Sopenharmony_ci                                    void (*destroy_associated_data)(void *));
106bf215546Sopenharmony_ci
107bf215546Sopenharmony_ci/*
108bf215546Sopenharmony_ci * get the associated data for the given video buffer
109bf215546Sopenharmony_ci */
110bf215546Sopenharmony_civoid *
111bf215546Sopenharmony_civl_video_buffer_get_associated_data(struct pipe_video_buffer *vbuf,
112bf215546Sopenharmony_ci                                    struct pipe_video_codec *vcodec);
113bf215546Sopenharmony_ci
114bf215546Sopenharmony_ci/**
115bf215546Sopenharmony_ci * fill a resource template for the given plane
116bf215546Sopenharmony_ci */
117bf215546Sopenharmony_civoid
118bf215546Sopenharmony_civl_video_buffer_template(struct pipe_resource *templ,
119bf215546Sopenharmony_ci                         const struct pipe_video_buffer *templat,
120bf215546Sopenharmony_ci                         enum pipe_format resource_format,
121bf215546Sopenharmony_ci                         unsigned depth, unsigned array_size,
122bf215546Sopenharmony_ci                         unsigned usage, unsigned plane,
123bf215546Sopenharmony_ci                         enum pipe_video_chroma_format chroma_format);
124bf215546Sopenharmony_ci
125bf215546Sopenharmony_ci/**
126bf215546Sopenharmony_ci * creates a video buffer, can be used as a standard implementation for pipe->create_video_buffer
127bf215546Sopenharmony_ci */
128bf215546Sopenharmony_cistruct pipe_video_buffer *
129bf215546Sopenharmony_civl_video_buffer_create(struct pipe_context *pipe,
130bf215546Sopenharmony_ci                       const struct pipe_video_buffer *templat);
131bf215546Sopenharmony_ci
132bf215546Sopenharmony_ci/**
133bf215546Sopenharmony_ci * extended create function, gets depth, array_size, usage and formats for each plane seperately
134bf215546Sopenharmony_ci */
135bf215546Sopenharmony_cistruct pipe_video_buffer *
136bf215546Sopenharmony_civl_video_buffer_create_ex(struct pipe_context *pipe,
137bf215546Sopenharmony_ci                          const struct pipe_video_buffer *templat,
138bf215546Sopenharmony_ci                          const enum pipe_format resource_formats[VL_NUM_COMPONENTS],
139bf215546Sopenharmony_ci                          unsigned depth, unsigned array_size, unsigned usage,
140bf215546Sopenharmony_ci                          enum pipe_video_chroma_format chroma_format);
141bf215546Sopenharmony_ci
142bf215546Sopenharmony_ci/**
143bf215546Sopenharmony_ci * even more extended create function, provide the pipe_resource for each plane
144bf215546Sopenharmony_ci */
145bf215546Sopenharmony_cistruct pipe_video_buffer *
146bf215546Sopenharmony_civl_video_buffer_create_ex2(struct pipe_context *pipe,
147bf215546Sopenharmony_ci                           const struct pipe_video_buffer *templat,
148bf215546Sopenharmony_ci                           struct pipe_resource *resources[VL_NUM_COMPONENTS]);
149bf215546Sopenharmony_ci
150bf215546Sopenharmony_ci/* Create pipe_video_buffer by using resource_create with planar formats. */
151bf215546Sopenharmony_cistruct pipe_video_buffer *
152bf215546Sopenharmony_civl_video_buffer_create_as_resource(struct pipe_context *pipe,
153bf215546Sopenharmony_ci                                   const struct pipe_video_buffer *tmpl,
154bf215546Sopenharmony_ci                                   const uint64_t *modifiers,
155bf215546Sopenharmony_ci                                   int modifiers_count);
156bf215546Sopenharmony_ci
157bf215546Sopenharmony_ci#endif /* vl_video_buffer_h */
158