Path: blob/21.2-virgl/src/gallium/auxiliary/vl/vl_video_buffer.h
4565 views
/**************************************************************************1*2* Copyright 2011 Christian König.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice (including the14* next paragraph) shall be included in all copies or substantial portions15* of the Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS18* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.20* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR21* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,22* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE23* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.24*25**************************************************************************/2627#ifndef vl_video_buffer_h28#define vl_video_buffer_h2930#include "pipe/p_context.h"31#include "pipe/p_video_codec.h"3233#include "vl_defines.h"3435/**36* implementation of a planar ycbcr buffer37*/3839/* planar buffer for vl data upload and manipulation */40struct vl_video_buffer41{42struct pipe_video_buffer base;43unsigned num_planes;44struct pipe_resource *resources[VL_NUM_COMPONENTS];45struct pipe_sampler_view *sampler_view_planes[VL_NUM_COMPONENTS];46struct pipe_sampler_view *sampler_view_components[VL_NUM_COMPONENTS];47struct pipe_surface *surfaces[VL_MAX_SURFACES];48};4950static inline void51vl_video_buffer_adjust_size(unsigned *width, unsigned *height, unsigned plane,52enum pipe_video_chroma_format chroma_format,53bool interlaced)54{55if (interlaced) {56*height = align(*height, 2) / 2;57}58if (plane > 0) {59if (chroma_format == PIPE_VIDEO_CHROMA_FORMAT_420) {60*width = align(*width, 2) / 2;61*height = align(*height, 2) / 2;62} else if (chroma_format == PIPE_VIDEO_CHROMA_FORMAT_422) {63*width = align(*width, 2) / 2;64}65}66}6768/**69* get subformats for each plane70*/71void72vl_get_video_buffer_formats(struct pipe_screen *screen, enum pipe_format format,73enum pipe_format out_format[VL_NUM_COMPONENTS]);7475/**76* get YUV plane order77*/78const unsigned *79vl_video_buffer_plane_order(enum pipe_format format);8081/**82* get maximum size of video buffers83*/84unsigned85vl_video_buffer_max_size(struct pipe_screen *screen);8687/**88* check if video buffer format is supported for a codec/profile89* can be used as default implementation of screen->is_video_format_supported90*/91bool92vl_video_buffer_is_format_supported(struct pipe_screen *screen,93enum pipe_format format,94enum pipe_video_profile profile,95enum pipe_video_entrypoint entrypoint);9697/*98* set the associated data for the given video buffer99*/100void101vl_video_buffer_set_associated_data(struct pipe_video_buffer *vbuf,102struct pipe_video_codec *vcodec,103void *associated_data,104void (*destroy_associated_data)(void *));105106/*107* get the associated data for the given video buffer108*/109void *110vl_video_buffer_get_associated_data(struct pipe_video_buffer *vbuf,111struct pipe_video_codec *vcodec);112113/**114* fill a resource template for the given plane115*/116void117vl_video_buffer_template(struct pipe_resource *templ,118const struct pipe_video_buffer *templat,119enum pipe_format resource_format,120unsigned depth, unsigned array_size,121unsigned usage, unsigned plane,122enum pipe_video_chroma_format chroma_format);123124/**125* creates a video buffer, can be used as a standard implementation for pipe->create_video_buffer126*/127struct pipe_video_buffer *128vl_video_buffer_create(struct pipe_context *pipe,129const struct pipe_video_buffer *templat);130131/**132* extended create function, gets depth, array_size, usage and formats for each plane seperately133*/134struct pipe_video_buffer *135vl_video_buffer_create_ex(struct pipe_context *pipe,136const struct pipe_video_buffer *templat,137const enum pipe_format resource_formats[VL_NUM_COMPONENTS],138unsigned depth, unsigned array_size, unsigned usage,139enum pipe_video_chroma_format chroma_format);140141/**142* even more extended create function, provide the pipe_resource for each plane143*/144struct pipe_video_buffer *145vl_video_buffer_create_ex2(struct pipe_context *pipe,146const struct pipe_video_buffer *templat,147struct pipe_resource *resources[VL_NUM_COMPONENTS]);148149/* Create pipe_video_buffer by using resource_create with planar formats. */150struct pipe_video_buffer *151vl_video_buffer_create_as_resource(struct pipe_context *pipe,152const struct pipe_video_buffer *tmpl,153const uint64_t *modifiers,154int modifiers_count);155156#endif /* vl_video_buffer_h */157158159